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
This commit is contained in:
parent
b592a4169f
commit
fe5959b625
|
@ -769,23 +769,6 @@ void EDA_BASE_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName )
|
||||||
// the file name.
|
// the file name.
|
||||||
if( response == wxYES )
|
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() ) )
|
if( !wxRenameFile( autoSaveFileName.GetFullPath(), aFileName.GetFullPath() ) )
|
||||||
{
|
{
|
||||||
wxMessageBox( _( "The auto save file could not be renamed to the board file name." ),
|
wxMessageBox( _( "The auto save file could not be renamed to the board file name." ),
|
||||||
|
|
|
@ -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 )
|
bool SETTINGS_MANAGER::loadProjectFile( PROJECT& aProject )
|
||||||
{
|
{
|
||||||
wxFileName fullFn( aProject.GetProjectFullName() );
|
wxFileName fullFn( aProject.GetProjectFullName() );
|
||||||
|
|
|
@ -60,8 +60,7 @@
|
||||||
#include <widgets/infobar.h>
|
#include <widgets/infobar.h>
|
||||||
|
|
||||||
|
|
||||||
bool SCH_EDIT_FRAME::SaveEEFile( SCH_SHEET* aSheet, bool aSaveUnderNewName,
|
bool SCH_EDIT_FRAME::SaveEEFile( SCH_SHEET* aSheet, bool aSaveUnderNewName )
|
||||||
bool aCreateBackupFile )
|
|
||||||
{
|
{
|
||||||
wxString msg;
|
wxString msg;
|
||||||
wxFileName schematicFileName;
|
wxFileName schematicFileName;
|
||||||
|
@ -101,25 +100,6 @@ bool SCH_EDIT_FRAME::SaveEEFile( SCH_SHEET* aSheet, bool aSaveUnderNewName,
|
||||||
if( !IsWritable( schematicFileName ) )
|
if( !IsWritable( schematicFileName ) )
|
||||||
return false;
|
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 );
|
wxFileName tempFile( schematicFileName );
|
||||||
tempFile.SetName( wxT( "." ) + tempFile.GetName() );
|
tempFile.SetName( wxT( "." ) + tempFile.GetName() );
|
||||||
tempFile.SetExt( tempFile.GetExt() + wxT( "$" ) );
|
tempFile.SetExt( tempFile.GetExt() + wxT( "$" ) );
|
||||||
|
@ -764,7 +744,7 @@ bool SCH_EDIT_FRAME::doAutoSave()
|
||||||
|
|
||||||
screens.GetScreen( i )->SetFileName( fn.GetFullPath() );
|
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();
|
screens.GetScreen( i )->SetModify();
|
||||||
else
|
else
|
||||||
autoSaveOk = false;
|
autoSaveOk = false;
|
||||||
|
|
|
@ -580,15 +580,10 @@ public:
|
||||||
* the current screen only.
|
* the current screen only.
|
||||||
* @param aSaveUnderNewName Controls how the file is to be saved;: using previous name
|
* @param aSaveUnderNewName Controls how the file is to be saved;: using previous name
|
||||||
* or under a new 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.
|
* @return True if the file has been saved.
|
||||||
*/
|
*/
|
||||||
bool SaveEEFile( SCH_SHEET* aSheet,
|
bool SaveEEFile( SCH_SHEET* aSheet,
|
||||||
bool aSaveUnderNewName = false,
|
bool aSaveUnderNewName = false );
|
||||||
bool aCreateBackupFile = CREATE_BACKUP_FILE );
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -56,10 +56,6 @@
|
||||||
#define KICAD_MANAGER_FRAME_NAME wxT( "KicadFrame" )
|
#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_ITEM;
|
||||||
class EDA_RECT;
|
class EDA_RECT;
|
||||||
class EDA_DRAW_PANEL_GAL;
|
class EDA_DRAW_PANEL_GAL;
|
||||||
|
|
|
@ -217,11 +217,6 @@ public:
|
||||||
*/
|
*/
|
||||||
bool SaveProject( const wxString& aFullPath = wxEmptyString );
|
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.
|
* 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
|
* Actually it just checks if a file called "kicad_common" exists, because that's probably
|
||||||
|
|
|
@ -248,22 +248,13 @@ bool PCB_EDIT_FRAME::Files_io_from_id( int id )
|
||||||
&& OpenProjectFiles( std::vector<wxString>( 1, fileName ), open_ctl );
|
&& OpenProjectFiles( std::vector<wxString>( 1, fileName ), open_ctl );
|
||||||
}
|
}
|
||||||
|
|
||||||
case ID_MENU_READ_BOARD_BACKUP_FILE:
|
|
||||||
case ID_MENU_RECOVER_BOARD_AUTOSAVE:
|
case ID_MENU_RECOVER_BOARD_AUTOSAVE:
|
||||||
{
|
{
|
||||||
wxFileName currfn = Prj().AbsolutePath( GetBoard()->GetFileName() );
|
wxFileName currfn = Prj().AbsolutePath( GetBoard()->GetFileName() );
|
||||||
wxFileName fn = currfn;
|
wxFileName fn = currfn;
|
||||||
|
|
||||||
if( id == ID_MENU_RECOVER_BOARD_AUTOSAVE )
|
wxString rec_name = GetAutoSaveFilePrefix() + fn.GetName();
|
||||||
{
|
fn.SetName( rec_name );
|
||||||
wxString rec_name = GetAutoSaveFilePrefix() + fn.GetName();
|
|
||||||
fn.SetName( rec_name );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wxString backup_ext = fn.GetExt() + GetBackupSuffix();
|
|
||||||
fn.SetExt( backup_ext );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !fn.FileExists() )
|
if( !fn.FileExists() )
|
||||||
{
|
{
|
||||||
|
@ -272,7 +263,7 @@ bool PCB_EDIT_FRAME::Files_io_from_id( int id )
|
||||||
return false;
|
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 ) )
|
if( !IsOK( this, msg ) )
|
||||||
return false;
|
return false;
|
||||||
|
@ -351,7 +342,7 @@ bool PCB_EDIT_FRAME::Files_io_from_id( int id )
|
||||||
if( id == ID_COPY_BOARD_AS )
|
if( id == ID_COPY_BOARD_AS )
|
||||||
return SavePcbCopy( filename );
|
return SavePcbCopy( filename );
|
||||||
else
|
else
|
||||||
return SavePcbFile( filename, NO_BACKUP_FILE );
|
return SavePcbFile( filename, false );
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -475,7 +466,7 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
|
||||||
if( IsContentModified() )
|
if( IsContentModified() )
|
||||||
{
|
{
|
||||||
if( !HandleUnsavedChanges( this, _( "The current PCB has been modified. Save changes?" ),
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -671,40 +662,7 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wxString PCB_EDIT_FRAME::createBackupFile( const wxString& aFileName )
|
bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool addToHistory )
|
||||||
{
|
|
||||||
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 <xxx>.kicad_pcb to <xxx>.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 )
|
|
||||||
{
|
{
|
||||||
// please, keep it simple. prompting goes elsewhere.
|
// 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 );
|
wxFileName tempFile( aFileName );
|
||||||
tempFile.SetName( wxT( "." ) + tempFile.GetName() );
|
tempFile.SetName( wxT( "." ) + tempFile.GetName() );
|
||||||
tempFile.SetExt( tempFile.GetExt() + wxT( "$" ) );
|
tempFile.SetExt( tempFile.GetExt() + wxT( "$" ) );
|
||||||
|
@ -810,9 +761,8 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF
|
||||||
GetBoard()->SetFileName( pcbFileName.GetFullPath() );
|
GetBoard()->SetFileName( pcbFileName.GetFullPath() );
|
||||||
UpdateTitle();
|
UpdateTitle();
|
||||||
|
|
||||||
// Put the saved file in File History, unless aCreateBackupFile is false (which indicates
|
// Put the saved file in File History if requested
|
||||||
// an autosave -- and we don't want autosave files in the file history).
|
if( addToHistory )
|
||||||
if( aCreateBackupFile )
|
|
||||||
UpdateFileHistory( GetBoard()->GetFileName() );
|
UpdateFileHistory( GetBoard()->GetFileName() );
|
||||||
|
|
||||||
// Delete auto save file on successful save.
|
// Delete auto save file on successful save.
|
||||||
|
@ -823,8 +773,6 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF
|
||||||
if( autoSaveFileName.FileExists() )
|
if( autoSaveFileName.FileExists() )
|
||||||
wxRemoveFile( autoSaveFileName.GetFullPath() );
|
wxRemoveFile( autoSaveFileName.GetFullPath() );
|
||||||
|
|
||||||
if( !!backupFileName )
|
|
||||||
upperTxt.Printf( _( "Backup file: \"%s\"" ), backupFileName );
|
|
||||||
|
|
||||||
lowerTxt.Printf( _( "Wrote board file: \"%s\"" ), pcbFileName.GetFullPath() );
|
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() + ">" );
|
wxLogTrace( traceAutoSave, "Creating auto save file <" + autoSaveFileName.GetFullPath() + ">" );
|
||||||
|
|
||||||
if( SavePcbFile( autoSaveFileName.GetFullPath(), NO_BACKUP_FILE ) )
|
if( SavePcbFile( autoSaveFileName.GetFullPath(), false ) )
|
||||||
{
|
{
|
||||||
GetScreen()->SetModify();
|
GetScreen()->SetModify();
|
||||||
GetBoard()->SetFileName( tmpFileName.GetFullPath() );
|
GetBoard()->SetFileName( tmpFileName.GetFullPath() );
|
||||||
|
|
|
@ -106,11 +106,6 @@ void PCB_EDIT_FRAME::ReCreateMenuBar()
|
||||||
_( "Clear board and get last rescue file automatically saved by Pcbnew" ),
|
_( "Clear board and get last rescue file automatically saved by Pcbnew" ),
|
||||||
rescue_xpm, SELECTION_CONDITIONS::ShowAlways );
|
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
|
// Import submenu
|
||||||
ACTION_MENU* submenuImport = new ACTION_MENU( false );
|
ACTION_MENU* submenuImport = new ACTION_MENU( false );
|
||||||
submenuImport->SetTool( selTool );
|
submenuImport->SetTool( selTool );
|
||||||
|
|
|
@ -109,7 +109,6 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME )
|
||||||
EVT_CLOSE( PCB_EDIT_FRAME::OnCloseWindow )
|
EVT_CLOSE( PCB_EDIT_FRAME::OnCloseWindow )
|
||||||
EVT_SIZE( PCB_EDIT_FRAME::OnSize )
|
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 )
|
EVT_TOOL( ID_MENU_RECOVER_BOARD_AUTOSAVE, PCB_EDIT_FRAME::Files_io )
|
||||||
|
|
||||||
// Menu Files:
|
// Menu Files:
|
||||||
|
|
|
@ -119,8 +119,6 @@ protected:
|
||||||
// The Tool Framework initalization
|
// The Tool Framework initalization
|
||||||
void setupTools();
|
void setupTools();
|
||||||
|
|
||||||
wxString createBackupFile( const wxString& aFileName );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* switches currently used canvas (Cairo / OpenGL).
|
* switches currently used canvas (Cairo / OpenGL).
|
||||||
* It also reinit the layers manager that slightly changes with canvases
|
* It also reinit the layers manager that slightly changes with canvases
|
||||||
|
@ -572,7 +570,6 @@ public:
|
||||||
* Read and write board files
|
* Read and write board files
|
||||||
* @param aId is an event ID ciming from file command events:
|
* @param aId is an event ID ciming from file command events:
|
||||||
* ID_LOAD_FILE
|
* ID_LOAD_FILE
|
||||||
* ID_MENU_READ_BOARD_BACKUP_FILE
|
|
||||||
* ID_MENU_RECOVER_BOARD_AUTOSAVE
|
* ID_MENU_RECOVER_BOARD_AUTOSAVE
|
||||||
* ID_NEW_BOARD
|
* ID_NEW_BOARD
|
||||||
* ID_SAVE_BOARD
|
* ID_SAVE_BOARD
|
||||||
|
@ -605,12 +602,10 @@ public:
|
||||||
*
|
*
|
||||||
* @param aFileName The file name to write or wxEmptyString to prompt user for
|
* @param aFileName The file name to write or wxEmptyString to prompt user for
|
||||||
* file name.
|
* file name.
|
||||||
* @param aCreateBackupFile Creates a back of \a aFileName if true. Helper
|
* @param addToHistory controsl whether or not to add the saved file to the recent file list
|
||||||
* definitions #CREATE_BACKUP_FILE and #NO_BACKUP_FILE
|
|
||||||
* are defined for improved code readability.
|
|
||||||
* @return True if file was saved successfully.
|
* @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
|
* Function SavePcbCopy
|
||||||
|
|
|
@ -78,7 +78,6 @@ enum pcbnew_ids
|
||||||
ID_POPUP_PCB_SELECT_DIFFPAIR16,
|
ID_POPUP_PCB_SELECT_DIFFPAIR16,
|
||||||
ID_POPUP_PCB_SELECT_WIDTH_END_RANGE,
|
ID_POPUP_PCB_SELECT_WIDTH_END_RANGE,
|
||||||
|
|
||||||
ID_MENU_READ_BOARD_BACKUP_FILE,
|
|
||||||
ID_MENU_RECOVER_BOARD_AUTOSAVE,
|
ID_MENU_RECOVER_BOARD_AUTOSAVE,
|
||||||
ID_MENU_ARCHIVE_MODULES_IN_LIBRARY,
|
ID_MENU_ARCHIVE_MODULES_IN_LIBRARY,
|
||||||
ID_MENU_CREATE_LIBRARY_AND_ARCHIVE_MODULES,
|
ID_MENU_CREATE_LIBRARY_AND_ARCHIVE_MODULES,
|
||||||
|
|
Loading…
Reference in New Issue