Backup option ignored

Please post about bugs here.
Forum rules
When making a bug report, please try to be as specific as possible. Include information on how to reproduce the bug and an example file if possible.
If the application crashed, please include the generated memory dump file as well.
User avatar
HertzDevil
Posts: 466
Joined: Thu Apr 23, 2015 7:39 pm
Location: Hong Kong SAR
Contact:

Backup option ignored

Postby HertzDevil » Mon Mar 28, 2016 10:42 pm

Since FamiTracker 0.4.0, the "Backup files" option is ignored by the tracker, because CFamiTrackerDoc::DeleteContents(void) always resets the backup flag:

Code: Select all

BOOL CFamiTrackerDoc::OnSaveDocument(LPCTSTR lpszPathName)
{
   if (!m_bFileLoaded)
      return FALSE;
   if ((m_bForceBackup || theApp.GetSettings()->General.bBackups) && !m_bBackupDone) {
      // ...
      m_bBackupDone = true;
   }

The main functions that reset the backup flag are:

Code: Select all

BOOL CFamiTrackerDoc::OpenDocument(LPCTSTR lpszPathName)
{
   m_bBackupDone = false;                             // Note: enables backup
   // ...
   if (!OpenFile.Open(lpszPathName, CFile::modeRead | CFile::shareDenyWrite, &ex)) {
      // ...
      //OnNewDocument();                              // comment sic
      return FALSE;
   }
   if (OpenFile.GetLength() == 0) {
      // Setup default settings
      CreateEmpty();                                  // Note: CreateEmpty should call DeleteContents
      return TRUE;
   }   
   unsigned int iVersion = OpenFile.GetFileVersion();
   if (iVersion < 0x0200) {
      // ...
      if (!OpenDocumentOld(&OpenFile))
         return FALSE;
      // ...
   }
   else if (iVersion >= 0x0200) {                     // Note: equivalent to "else {"
      // ...
      if (!OpenDocumentNew(OpenFile))
         return FALSE;

Code: Select all

BOOL CFamiTrackerDoc::OpenDocumentOld(CFile *pOpenFile)
{
   unsigned int i, c, ReadCount, FileBlock;

   // Delete loaded document
   DeleteContents();

Code: Select all

BOOL CFamiTrackerDoc::OpenDocumentNew(CDocumentFile &DocumentFile)
{
   // returns if m_iFileVersion out of range
   // ...
   // Delete loaded document
   DeleteContents();

Code: Select all

void CFamiTrackerDoc::DeleteContents()
{
   // ...
   m_bBackupDone = true;   // No backup on new modules         // Note: disables backup

Moving the line "m_bBackupDone = false;" to the end of the method shall fix the bug, right before returning TRUE. (As noted above, opening a blank file should call DeleteContents as well, but then there is no need to back up a blank file.)
Constructing Chiptune; Construing 8-Bit. Makes 0CC-FamiTracker and MEGA ZUN.

Join my forum for 0CC-FamiTracker discussion and more

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 1 guest