From fe5959b6251cf5d70b08a14e335619267526a6ff Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Fri, 19 Jun 2020 21:06:52 -0400 Subject: [PATCH] Remove the schematic and board backup file system Per discussion on the developers list, this old system no longer provides much value and is seen as annoying by many users. The new save logic should prevent any cases of file corruption on save, which was a major reason for the backup file system existing. Fixes https://gitlab.com/kicad/code/kicad/-/issues/2012 --- common/eda_base_frame.cpp | 17 ------- common/settings/settings_manager.cpp | 6 --- eeschema/files-io.cpp | 24 +--------- eeschema/sch_edit_frame.h | 7 +-- include/eda_base_frame.h | 4 -- include/settings/settings_manager.h | 5 -- pcbnew/files.cpp | 70 ++++------------------------ pcbnew/menubar_pcb_editor.cpp | 5 -- pcbnew/pcb_edit_frame.cpp | 1 - pcbnew/pcb_edit_frame.h | 9 +--- pcbnew/pcbnew_id.h | 1 - 11 files changed, 14 insertions(+), 135 deletions(-) diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index d9a2837a0b..c331339ada 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -769,23 +769,6 @@ void EDA_BASE_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName ) // the file name. if( response == wxYES ) { - // Get the backup file name. - wxFileName backupFileName = aFileName; - backupFileName.SetExt( aFileName.GetExt() + GetBackupSuffix() ); - - // If an old backup file exists, delete it. If an old copy of the file exists, rename - // it to the backup file name - if( aFileName.FileExists() ) - { - // Rename the old file to the backup file name. - if( !wxRenameFile( aFileName.GetFullPath(), backupFileName.GetFullPath(), true ) ) - { - msg.Printf( _( "Could not create backup file \"%s\"" ), - GetChars( backupFileName.GetFullPath() ) ); - wxMessageBox( msg ); - } - } - if( !wxRenameFile( autoSaveFileName.GetFullPath(), aFileName.GetFullPath() ) ) { wxMessageBox( _( "The auto save file could not be renamed to the board file name." ), diff --git a/common/settings/settings_manager.cpp b/common/settings/settings_manager.cpp index 559614b81a..d04bd97ce2 100644 --- a/common/settings/settings_manager.cpp +++ b/common/settings/settings_manager.cpp @@ -761,12 +761,6 @@ bool SETTINGS_MANAGER::SaveProject( const wxString& aFullPath ) } -wxString SETTINGS_MANAGER::GetProjectBackupsPath() const -{ - return Prj().GetProjectPath() + Prj().GetProjectName() + PROJECT_BACKUPS_DIR_SUFFIX; -} - - bool SETTINGS_MANAGER::loadProjectFile( PROJECT& aProject ) { wxFileName fullFn( aProject.GetProjectFullName() ); diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 0eed3cf0a8..0bcb9fe134 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -60,8 +60,7 @@ #include -bool SCH_EDIT_FRAME::SaveEEFile( SCH_SHEET* aSheet, bool aSaveUnderNewName, - bool aCreateBackupFile ) +bool SCH_EDIT_FRAME::SaveEEFile( SCH_SHEET* aSheet, bool aSaveUnderNewName ) { wxString msg; wxFileName schematicFileName; @@ -101,25 +100,6 @@ bool SCH_EDIT_FRAME::SaveEEFile( SCH_SHEET* aSheet, bool aSaveUnderNewName, if( !IsWritable( schematicFileName ) ) return false; - // Create backup if requested - if( aCreateBackupFile && schematicFileName.FileExists() ) - { - wxFileName backupFileName = schematicFileName; - - // Rename the old file to a '-bak' suffixed one: - backupFileName.SetExt( schematicFileName.GetExt() + GetBackupSuffix() ); - - if( backupFileName.FileExists() ) - wxRemoveFile( backupFileName.GetFullPath() ); - - if( !wxCopyFile( schematicFileName.GetFullPath(), backupFileName.GetFullPath() ) ) - { - msg.Printf( _( "Could not save backup of file \"%s\"" ), - schematicFileName.GetFullPath() ); - DisplayError( this, msg ); - } - } - wxFileName tempFile( schematicFileName ); tempFile.SetName( wxT( "." ) + tempFile.GetName() ); tempFile.SetExt( tempFile.GetExt() + wxT( "$" ) ); @@ -764,7 +744,7 @@ bool SCH_EDIT_FRAME::doAutoSave() screens.GetScreen( i )->SetFileName( fn.GetFullPath() ); - if( SaveEEFile( screens.GetSheet( i ), false, NO_BACKUP_FILE ) ) + if( SaveEEFile( screens.GetSheet( i ), false ) ) screens.GetScreen( i )->SetModify(); else autoSaveOk = false; diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index dd4d4f0bab..b15df416ca 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -580,15 +580,10 @@ public: * the current screen only. * @param aSaveUnderNewName Controls how the file is to be saved;: using previous name * or under a new name . - * @param aCreateBackupFile Creates a back of the file associated with \a aScreen - * if true. - * Helper definitions #CREATE_BACKUP_FILE and - * #NO_BACKUP_FILE are defined for improved code readability. * @return True if the file has been saved. */ bool SaveEEFile( SCH_SHEET* aSheet, - bool aSaveUnderNewName = false, - bool aCreateBackupFile = CREATE_BACKUP_FILE ); + bool aSaveUnderNewName = false ); /** diff --git a/include/eda_base_frame.h b/include/eda_base_frame.h index b894a1a6d4..558ed86f87 100644 --- a/include/eda_base_frame.h +++ b/include/eda_base_frame.h @@ -56,10 +56,6 @@ #define KICAD_MANAGER_FRAME_NAME wxT( "KicadFrame" ) -// Readability helper definitions for creating backup files. -#define CREATE_BACKUP_FILE true -#define NO_BACKUP_FILE false - class EDA_ITEM; class EDA_RECT; class EDA_DRAW_PANEL_GAL; diff --git a/include/settings/settings_manager.h b/include/settings/settings_manager.h index 37f773ed1b..06ec611402 100644 --- a/include/settings/settings_manager.h +++ b/include/settings/settings_manager.h @@ -217,11 +217,6 @@ public: */ bool SaveProject( const wxString& aFullPath = wxEmptyString ); - /** - * @return the path to the backups folder for the loaded project - */ - wxString GetProjectBackupsPath() const; - /** * Checks if a given path is probably a valid KiCad configuration directory. * Actually it just checks if a file called "kicad_common" exists, because that's probably diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index f220d55dff..043038e659 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -248,22 +248,13 @@ bool PCB_EDIT_FRAME::Files_io_from_id( int id ) && OpenProjectFiles( std::vector( 1, fileName ), open_ctl ); } - case ID_MENU_READ_BOARD_BACKUP_FILE: case ID_MENU_RECOVER_BOARD_AUTOSAVE: { wxFileName currfn = Prj().AbsolutePath( GetBoard()->GetFileName() ); wxFileName fn = currfn; - if( id == ID_MENU_RECOVER_BOARD_AUTOSAVE ) - { - wxString rec_name = GetAutoSaveFilePrefix() + fn.GetName(); - fn.SetName( rec_name ); - } - else - { - wxString backup_ext = fn.GetExt() + GetBackupSuffix(); - fn.SetExt( backup_ext ); - } + wxString rec_name = GetAutoSaveFilePrefix() + fn.GetName(); + fn.SetName( rec_name ); if( !fn.FileExists() ) { @@ -272,7 +263,7 @@ bool PCB_EDIT_FRAME::Files_io_from_id( int id ) return false; } - msg.Printf( _( "OK to load recovery or backup file \"%s\"" ), fn.GetFullPath() ); + msg.Printf( _( "OK to load recovery file \"%s\"" ), fn.GetFullPath() ); if( !IsOK( this, msg ) ) return false; @@ -351,7 +342,7 @@ bool PCB_EDIT_FRAME::Files_io_from_id( int id ) if( id == ID_COPY_BOARD_AS ) return SavePcbCopy( filename ); else - return SavePcbFile( filename, NO_BACKUP_FILE ); + return SavePcbFile( filename, false ); } return false; } @@ -475,7 +466,7 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in if( IsContentModified() ) { if( !HandleUnsavedChanges( this, _( "The current PCB has been modified. Save changes?" ), - [&]()->bool { return SavePcbFile( GetBoard()->GetFileName(), CREATE_BACKUP_FILE ); } ) ) + [&]()->bool { return SavePcbFile( GetBoard()->GetFileName() ); } ) ) { return false; } @@ -671,40 +662,7 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in } -wxString PCB_EDIT_FRAME::createBackupFile( const wxString& aFileName ) -{ - wxFileName fn = aFileName; - wxFileName backupFileName = aFileName; - - backupFileName.SetExt( fn.GetExt() + GetBackupSuffix() ); - - // If an old backup file exists, delete it. If an old board file exists, - // rename it to the backup file name. - if( fn.FileExists() ) - { - // Remove the old file xxx.kicad_pcb-bak if it exists. - if( backupFileName.FileExists() ) - wxRemoveFile( backupFileName.GetFullPath() ); - - // Copy the current file from .kicad_pcb to .kicad_pcb-bak - if( !wxCopyFile( fn.GetFullPath(), backupFileName.GetFullPath() ) ) - { - wxString msg = wxString::Format( _( - "Warning: unable to create backup file \"%s\"" ), - backupFileName.GetFullPath() ); - DisplayError( NULL, msg ); - } - } - else - { - backupFileName.Clear(); - } - - return backupFileName.GetFullPath(); -} - - -bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupFile ) +bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool addToHistory ) { // please, keep it simple. prompting goes elsewhere. @@ -738,13 +696,6 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF } } - wxString backupFileName; - - if( aCreateBackupFile ) - { - backupFileName = createBackupFile( aFileName ); - } - wxFileName tempFile( aFileName ); tempFile.SetName( wxT( "." ) + tempFile.GetName() ); tempFile.SetExt( tempFile.GetExt() + wxT( "$" ) ); @@ -810,9 +761,8 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF GetBoard()->SetFileName( pcbFileName.GetFullPath() ); UpdateTitle(); - // Put the saved file in File History, unless aCreateBackupFile is false (which indicates - // an autosave -- and we don't want autosave files in the file history). - if( aCreateBackupFile ) + // Put the saved file in File History if requested + if( addToHistory ) UpdateFileHistory( GetBoard()->GetFileName() ); // Delete auto save file on successful save. @@ -823,8 +773,6 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF if( autoSaveFileName.FileExists() ) wxRemoveFile( autoSaveFileName.GetFullPath() ); - if( !!backupFileName ) - upperTxt.Printf( _( "Backup file: \"%s\"" ), backupFileName ); lowerTxt.Printf( _( "Wrote board file: \"%s\"" ), pcbFileName.GetFullPath() ); @@ -920,7 +868,7 @@ bool PCB_EDIT_FRAME::doAutoSave() wxLogTrace( traceAutoSave, "Creating auto save file <" + autoSaveFileName.GetFullPath() + ">" ); - if( SavePcbFile( autoSaveFileName.GetFullPath(), NO_BACKUP_FILE ) ) + if( SavePcbFile( autoSaveFileName.GetFullPath(), false ) ) { GetScreen()->SetModify(); GetBoard()->SetFileName( tmpFileName.GetFullPath() ); diff --git a/pcbnew/menubar_pcb_editor.cpp b/pcbnew/menubar_pcb_editor.cpp index 6939bb96fe..a949580ff6 100644 --- a/pcbnew/menubar_pcb_editor.cpp +++ b/pcbnew/menubar_pcb_editor.cpp @@ -106,11 +106,6 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() _( "Clear board and get last rescue file automatically saved by Pcbnew" ), rescue_xpm, SELECTION_CONDITIONS::ShowAlways ); - fileMenu->AddItem( ID_MENU_READ_BOARD_BACKUP_FILE, - _( "Revert to Last Backup" ), - _( "Clear board and get previous backup version of board" ), - undo_xpm, SELECTION_CONDITIONS::ShowAlways ); - // Import submenu ACTION_MENU* submenuImport = new ACTION_MENU( false ); submenuImport->SetTool( selTool ); diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 529d555ba6..3edaae0cd6 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -109,7 +109,6 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) EVT_CLOSE( PCB_EDIT_FRAME::OnCloseWindow ) EVT_SIZE( PCB_EDIT_FRAME::OnSize ) - EVT_TOOL( ID_MENU_READ_BOARD_BACKUP_FILE, PCB_EDIT_FRAME::Files_io ) EVT_TOOL( ID_MENU_RECOVER_BOARD_AUTOSAVE, PCB_EDIT_FRAME::Files_io ) // Menu Files: diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index 6bc0fc099b..ee26742fc7 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -119,8 +119,6 @@ protected: // The Tool Framework initalization void setupTools(); - wxString createBackupFile( const wxString& aFileName ); - /** * switches currently used canvas (Cairo / OpenGL). * It also reinit the layers manager that slightly changes with canvases @@ -572,7 +570,6 @@ public: * Read and write board files * @param aId is an event ID ciming from file command events: * ID_LOAD_FILE - * ID_MENU_READ_BOARD_BACKUP_FILE * ID_MENU_RECOVER_BOARD_AUTOSAVE * ID_NEW_BOARD * ID_SAVE_BOARD @@ -605,12 +602,10 @@ public: * * @param aFileName The file name to write or wxEmptyString to prompt user for * file name. - * @param aCreateBackupFile Creates a back of \a aFileName if true. Helper - * definitions #CREATE_BACKUP_FILE and #NO_BACKUP_FILE - * are defined for improved code readability. + * @param addToHistory controsl whether or not to add the saved file to the recent file list * @return True if file was saved successfully. */ - bool SavePcbFile( const wxString& aFileName, bool aCreateBackupFile = CREATE_BACKUP_FILE ); + bool SavePcbFile( const wxString& aFileName, bool addToHistory = true ); /** * Function SavePcbCopy diff --git a/pcbnew/pcbnew_id.h b/pcbnew/pcbnew_id.h index d753200b15..1181c1ddbb 100644 --- a/pcbnew/pcbnew_id.h +++ b/pcbnew/pcbnew_id.h @@ -78,7 +78,6 @@ enum pcbnew_ids ID_POPUP_PCB_SELECT_DIFFPAIR16, ID_POPUP_PCB_SELECT_WIDTH_END_RANGE, - ID_MENU_READ_BOARD_BACKUP_FILE, ID_MENU_RECOVER_BOARD_AUTOSAVE, ID_MENU_ARCHIVE_MODULES_IN_LIBRARY, ID_MENU_CREATE_LIBRARY_AND_ARCHIVE_MODULES,