Skip to content

Commit

Permalink
CFamiTrackerDocIO no longer depends on CSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Mar 14, 2018
1 parent 86f3ba5 commit ac6fb91
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Source/FamiTrackerDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ BOOL CFamiTrackerDoc::SaveDocument(LPCWSTR lpszPathName) const
return FALSE;
}

if (!CFamiTrackerDocIO {DocumentFile}.Save(*GetModule())) { // // //
if (!CFamiTrackerDocIO {DocumentFile, (module_error_level_t)Env.GetSettings()->Version.iErrorLevel}.Save(*GetModule())) { // // //
// The save process failed, delete temp file
DocumentFile.Close();
DeleteFileW(TempFile);
Expand Down Expand Up @@ -434,7 +434,7 @@ BOOL CFamiTrackerDoc::OpenDocument(LPCWSTR lpszPathName)
m_bForceBackup = true;
}
else {
if (!CFamiTrackerDocIO {OpenFile}.Load(*GetModule())) {
if (!CFamiTrackerDocIO {OpenFile, (module_error_level_t)Env.GetSettings()->Version.iErrorLevel}.Load(*GetModule())) {
CStringA msg;
msg.LoadStringW(IDS_FILE_LOAD_ERROR);
OpenFile.RaiseModuleException((LPCSTR)msg);
Expand Down
26 changes: 14 additions & 12 deletions Source/FamiTrackerDocIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "FamiTrackerDocOldIO.h"
#include "DocumentFile.h" // stdafx.h
#include "FamiTrackerModule.h"
#include "Settings.h"
#include "APU/Types.h"
#include "SoundChipSet.h"
#include "ChannelOrder.h"
Expand Down Expand Up @@ -108,8 +107,8 @@ void VisitSequences(const CSequenceManager *manager, F&& f) {

// // // save/load functionality

CFamiTrackerDocIO::CFamiTrackerDocIO(CDocumentFile &file) :
file_(file)
CFamiTrackerDocIO::CFamiTrackerDocIO(CDocumentFile &file, module_error_level_t err_lv) :
file_(file), err_lv_(err_lv)
{
}

Expand Down Expand Up @@ -1414,20 +1413,23 @@ void CFamiTrackerDocIO::SaveBookmarks(const CFamiTrackerModule &modfile, int ver

template <module_error_level_t l>
void CFamiTrackerDocIO::AssertFileData(bool Cond, const std::string &Msg) const {
if (l <= Env.GetSettings()->Version.iErrorLevel && !Cond) {
if (l <= err_lv_ && !Cond) {
CModuleException e = file_.GetException();
e.AppendError(Msg);
throw e;
}
}

template<module_error_level_t l, typename T, typename U, typename V>
T CFamiTrackerDocIO::AssertRange(T Value, U Min, V Max, const std::string &Desc) const try {
return CModuleException::AssertRangeFmt<l>(Value, Min, Max, Desc);
}
catch (CModuleException e) {
file_.SetDefaultFooter(e);
// if (m_pCurrentDocument)
// m_pCurrentDocument->SetDefaultFooter(e);
throw e;
T CFamiTrackerDocIO::AssertRange(T Value, U Min, V Max, const std::string &Desc) const {
if (l <= err_lv_ && !(Value >= Min && Value <= Max)) {
std::string msg = Desc + " out of range: expected ["
+ std::to_string(Min) + ","
+ std::to_string(Max) + "], got "
+ std::to_string(Value);
auto e = CModuleException::WithMessage(msg);
file_.SetDefaultFooter(e);
throw e;
}
return Value;
}
3 changes: 2 additions & 1 deletion Source/FamiTrackerDocIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ enum module_error_level_t : int; // Settings.h

class CFamiTrackerDocIO {
public:
explicit CFamiTrackerDocIO(CDocumentFile &file);
CFamiTrackerDocIO(CDocumentFile &file, module_error_level_t err_lv);

bool Load(CFamiTrackerModule &modfile);
bool Save(const CFamiTrackerModule &modfile);
Expand Down Expand Up @@ -99,6 +99,7 @@ class CFamiTrackerDocIO {
T AssertRange(T Value, U Min, V Max, const std::string &Desc) const;

CDocumentFile &file_;
module_error_level_t err_lv_;

std::vector<COldSequence> m_vTmpSequences; // // //
bool fds_adjust_arps_ = false;
Expand Down

0 comments on commit ac6fb91

Please sign in to comment.