Refactor autosave prefix into FILEEXT.

This commit is contained in:
Alex Shvartzkop 2024-04-22 03:58:13 +03:00
parent c68e3ceb44
commit 2babd574be
10 changed files with 18 additions and 23 deletions

View File

@ -1366,7 +1366,7 @@ void EDA_BASE_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName )
wxFileName autoSaveFileName = aFileName; wxFileName autoSaveFileName = aFileName;
// Check for auto save file. // Check for auto save file.
autoSaveFileName.SetName( GetAutoSaveFilePrefix() + aFileName.GetName() ); autoSaveFileName.SetName( FILEEXT::AutoSaveFilePrefix + aFileName.GetName() );
wxLogTrace( traceAutoSave, wxLogTrace( traceAutoSave,
wxT( "Checking for auto save file " ) + autoSaveFileName.GetFullPath() ); wxT( "Checking for auto save file " ) + autoSaveFileName.GetFullPath() );
@ -1413,7 +1413,7 @@ void EDA_BASE_FRAME::DeleteAutoSaveFile( const wxFileName& aFileName )
wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) ); wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) );
wxFileName autoSaveFn = aFileName; wxFileName autoSaveFn = aFileName;
autoSaveFn.SetName( GetAutoSaveFilePrefix() + aFileName.GetName() ); autoSaveFn.SetName( FILEEXT::AutoSaveFilePrefix + aFileName.GetName() );
if( autoSaveFn.FileExists() ) if( autoSaveFn.FileExists() )
{ {

View File

@ -125,6 +125,7 @@ wxString AddFileExtListToFilter( const std::vector<std::string>& aExts )
const std::string FILEEXT::BackupFileSuffix( "-bak" ); const std::string FILEEXT::BackupFileSuffix( "-bak" );
const std::string FILEEXT::LockFilePrefix( "~" ); const std::string FILEEXT::LockFilePrefix( "~" );
const std::string FILEEXT::LockFileExtension( "lck" ); const std::string FILEEXT::LockFileExtension( "lck" );
const std::string FILEEXT::AutoSaveFilePrefix( "_autosave-" );
const std::string FILEEXT::KiCadSymbolLibFileExtension( "kicad_sym" ); const std::string FILEEXT::KiCadSymbolLibFileExtension( "kicad_sym" );
const std::string FILEEXT::SchematicSymbolFileExtension( "sym" ); const std::string FILEEXT::SchematicSymbolFileExtension( "sym" );

View File

@ -894,7 +894,7 @@ bool SCH_EDIT_FRAME::saveSchematicFile( SCH_SHEET* aSheet, const wxString& aSave
{ {
// Delete auto save file. // Delete auto save file.
wxFileName autoSaveFileName = schematicFileName; wxFileName autoSaveFileName = schematicFileName;
autoSaveFileName.SetName( GetAutoSaveFilePrefix() + schematicFileName.GetName() ); autoSaveFileName.SetName( FILEEXT::AutoSaveFilePrefix + schematicFileName.GetName() );
if( autoSaveFileName.FileExists() ) if( autoSaveFileName.FileExists() )
{ {
@ -1324,7 +1324,7 @@ bool SCH_EDIT_FRAME::doAutoSave()
tmpFileName = fn = screens.GetScreen( i )->GetFileName(); tmpFileName = fn = screens.GetScreen( i )->GetFileName();
// Auto save file name is the normal file name prefixed with GetAutoSavePrefix(). // Auto save file name is the normal file name prefixed with GetAutoSavePrefix().
fn.SetName( GetAutoSaveFilePrefix() + fn.GetName() ); fn.SetName( FILEEXT::AutoSaveFilePrefix + fn.GetName() );
if( saveSchematicFile( screens.GetSheet( i ), fn.GetFullPath() ) ) if( saveSchematicFile( screens.GetSheet( i ), fn.GetFullPath() ) )
{ {
@ -1554,7 +1554,7 @@ bool SCH_EDIT_FRAME::updateAutoSaveFile()
fn = screens.GetScreen( i )->GetFileName(); fn = screens.GetScreen( i )->GetFileName();
// Auto save file name is the normal file name prefixed with GetAutoSavePrefix(). // Auto save file name is the normal file name prefixed with GetAutoSavePrefix().
fn.SetName( GetAutoSaveFilePrefix() + fn.GetName() ); fn.SetName( FILEEXT::AutoSaveFilePrefix + fn.GetName() );
autoSavedFiles.emplace_back( fn.GetFullPath() ); autoSavedFiles.emplace_back( fn.GetFullPath() );
} }
@ -1643,7 +1643,7 @@ void SCH_EDIT_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName )
wxString tmp = recoveredFn.GetName(); wxString tmp = recoveredFn.GetName();
// Strip "_autosave-" prefix from the auto save file name. // Strip "_autosave-" prefix from the auto save file name.
tmp.Replace( GetAutoSaveFilePrefix(), wxS( "" ), false ); tmp.Replace( FILEEXT::AutoSaveFilePrefix, wxS( "" ), false );
recoveredFn.SetName( tmp ); recoveredFn.SetName( tmp );
wxFileName backupFn = recoveredFn; wxFileName backupFn = recoveredFn;

View File

@ -1072,8 +1072,8 @@ void SCH_EDIT_FRAME::doCloseWindow()
{ {
fn = Prj().AbsolutePath( screen->GetFileName() ); fn = Prj().AbsolutePath( screen->GetFileName() );
// Auto save file name is the normal file name prepended with GetAutoSaveFilePrefix(). // Auto save file name is the normal file name prepended with FILEEXT::AutoSaveFilePrefix.
fn.SetName( GetAutoSaveFilePrefix() + fn.GetName() ); fn.SetName( FILEEXT::AutoSaveFilePrefix + fn.GetName() );
if( fn.IsFileWritable() ) if( fn.IsFileWritable() )
wxRemoveFile( fn.GetFullPath() ); wxRemoveFile( fn.GetFullPath() );

View File

@ -611,14 +611,6 @@ protected:
///< Default style flags used for wxAUI toolbars. ///< Default style flags used for wxAUI toolbars.
static constexpr int KICAD_AUI_TB_STYLE = wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_PLAIN_BACKGROUND; static constexpr int KICAD_AUI_TB_STYLE = wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_PLAIN_BACKGROUND;
/**
* @return the string to prepend to a file name for automatic save.
*/
static wxString GetAutoSaveFilePrefix()
{
return wxT( "_autosave-" );
}
virtual void doReCreateMenuBar() {} virtual void doReCreateMenuBar() {}
/** /**

View File

@ -116,6 +116,7 @@ public:
static const std::string BackupFileSuffix; static const std::string BackupFileSuffix;
static const std::string LockFilePrefix; static const std::string LockFilePrefix;
static const std::string LockFileExtension; static const std::string LockFileExtension;
static const std::string AutoSaveFilePrefix;
static const std::string SchematicSymbolFileExtension; static const std::string SchematicSymbolFileExtension;
static const std::string LegacySymbolLibFileExtension; static const std::string LegacySymbolLibFileExtension;

View File

@ -85,7 +85,8 @@ public:
wxString path( fn.GetPathWithSep() ); wxString path( fn.GetPathWithSep() );
bool exclude = fn.GetName().Contains( "fp-info-cache" ) bool exclude = fn.GetName().Contains( "fp-info-cache" )
|| fn.GetName().StartsWith( "_autosave-" ) || fn.GetExt().Contains( "lck" ); || fn.GetName().StartsWith( FILEEXT::AutoSaveFilePrefix )
|| fn.GetExt().Contains( "lck" );
if( !exclude ) if( !exclude )
m_files.emplace_back( wxFileName( filename ) ); m_files.emplace_back( wxFileName( filename ) );

View File

@ -325,7 +325,7 @@ void PCB_EDIT_FRAME::OnExportSTEP( wxCommandEvent& event )
} }
// Use auto-saved board for export // Use auto-saved board for export
brdFile.SetName( GetAutoSaveFilePrefix() + brdFile.GetName() ); brdFile.SetName( FILEEXT::AutoSaveFilePrefix + brdFile.GetName() );
} }
DIALOG_EXPORT_STEP dlg( this, brdFile.GetFullPath() ); DIALOG_EXPORT_STEP dlg( this, brdFile.GetFullPath() );

View File

@ -291,7 +291,7 @@ bool PCB_EDIT_FRAME::Files_io_from_id( int id )
wxFileName currfn = Prj().AbsolutePath( GetBoard()->GetFileName() ); wxFileName currfn = Prj().AbsolutePath( GetBoard()->GetFileName() );
wxFileName fn = currfn; wxFileName fn = currfn;
wxString rec_name = GetAutoSaveFilePrefix() + fn.GetName(); wxString rec_name = FILEEXT::AutoSaveFilePrefix + fn.GetName();
fn.SetName( rec_name ); fn.SetName( rec_name );
if( !fn.FileExists() ) if( !fn.FileExists() )
@ -1061,7 +1061,7 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool addToHistory,
// Delete auto save file on successful save. // Delete auto save file on successful save.
wxFileName autoSaveFileName = pcbFileName; wxFileName autoSaveFileName = pcbFileName;
autoSaveFileName.SetName( GetAutoSaveFilePrefix() + pcbFileName.GetName() ); autoSaveFileName.SetName( FILEEXT::AutoSaveFilePrefix + pcbFileName.GetName() );
if( autoSaveFileName.FileExists() ) if( autoSaveFileName.FileExists() )
wxRemoveFile( autoSaveFileName.GetFullPath() ); wxRemoveFile( autoSaveFileName.GetFullPath() );
@ -1169,7 +1169,7 @@ bool PCB_EDIT_FRAME::doAutoSave()
wxFileName autoSaveFileName = tmpFileName; wxFileName autoSaveFileName = tmpFileName;
// Auto save file name is the board file name prepended with autosaveFilePrefix string. // Auto save file name is the board file name prepended with autosaveFilePrefix string.
autoSaveFileName.SetName( GetAutoSaveFilePrefix() + autoSaveFileName.GetName() ); autoSaveFileName.SetName( FILEEXT::AutoSaveFilePrefix + autoSaveFileName.GetName() );
if( !autoSaveFileName.IsOk() ) if( !autoSaveFileName.IsOk() )
return false; return false;

View File

@ -1192,8 +1192,8 @@ void PCB_EDIT_FRAME::doCloseWindow()
// Delete the auto save file if it exists. // Delete the auto save file if it exists.
wxFileName fn = GetBoard()->GetFileName(); wxFileName fn = GetBoard()->GetFileName();
// Auto save file name is the normal file name prefixed with 'GetAutoSaveFilePrefix()'. // Auto save file name is the normal file name prefixed with 'FILEEXT::AutoSaveFilePrefix'.
fn.SetName( GetAutoSaveFilePrefix() + fn.GetName() ); fn.SetName( FILEEXT::AutoSaveFilePrefix + fn.GetName() );
// When the auto save feature does not have write access to the board file path, it falls // When the auto save feature does not have write access to the board file path, it falls
// back to a platform specific user temporary file path. // back to a platform specific user temporary file path.