Pcbnew: fix several auto save file issues.

* When Pcbnew is launched in the stand alone mode with no board file command
  line option, the project path is set to the current working directory.  The
  user may not have write access to the current working directory which would
  cause the auto save to generate an error.  If the user does not have write
  access to the current working directory, set the path to a platform specific
  temporary path that the user has write permission.

* When Pcbnew is launched in the stand alone mode with no board file command
  line option, the default BOARD object has no file name.  Set the file name
  to "noname.kicad_pcb" to fix incorrect auto save file name and set the path
  to the user's platform specific document folder.

* Delete orphaned auto save files when closing without saving due to broken
  auto save file generation logic which prepended the file name with "$" rather
  than "_autosave-".

* Fixes: lp:1596382
This commit is contained in:
Wayne Stambaugh 2016-08-11 15:13:47 -04:00 committed by Wayne Stambaugh
parent 5b4542231e
commit ca0aa6c971
3 changed files with 55 additions and 13 deletions

View File

@ -75,6 +75,7 @@ namespace PCB { struct IFACE; } // KIFACE_I is in pcbnew.cpp
*/
#define PCB_EDIT_FRAME_NAME wxT( "PcbFrame" )
class PCB_EDIT_FRAME : public PCB_BASE_EDIT_FRAME
{
friend struct PCB::IFACE;
@ -227,6 +228,13 @@ public:
void OnQuit( wxCommandEvent& event );
/**
* Function GetAutoSaveFilePrefix
*
* @return the string to prepend to a file name for automatic save.
*/
static wxString GetAutoSaveFilePrefix();
/**
* Execute a remote command send by Eeschema via a socket,
* port KICAD_PCB_PORT_SERVICE_NUMBER (currently 4242)

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2011-2015 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2011-2016 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
@ -64,6 +64,12 @@ static const wxChar backupSuffix[] = wxT( "-bak" );
static const wxChar autosavePrefix[] = wxT( "_autosave-" );
wxString PCB_EDIT_FRAME::GetAutoSaveFilePrefix()
{
return wxString( autosavePrefix );
}
/**
* Function AskLoadBoardFileName
* puts up a wxFileDialog asking for a BOARD filename to open.
@ -807,7 +813,7 @@ bool PCB_EDIT_FRAME::SavePcbCopy( const wxString& aFileName )
}
DisplayInfoMessage( this, wxString::Format( _( "Board copied to:\n'%s'" ),
GetChars( pcbFileName.GetFullPath() ) ) );
GetChars( pcbFileName.GetFullPath() ) ) );
return true;
}
@ -815,19 +821,40 @@ bool PCB_EDIT_FRAME::SavePcbCopy( const wxString& aFileName )
bool PCB_EDIT_FRAME::doAutoSave()
{
wxFileName tmpFileName = Prj().AbsolutePath( GetBoard()->GetFileName() );
wxFileName fn = tmpFileName;
wxFileName tmpFileName;
// Auto save file name is the normal file name prepended with
// autosaveFilePrefix string.
fn.SetName( wxString( autosavePrefix ) + fn.GetName() );
if( GetBoard()->GetFileName().IsEmpty() )
{
tmpFileName = wxFileName( wxStandardPaths::Get().GetDocumentsDir(), wxT( "noname" ),
KiCadPcbFileExtension );
GetBoard()->SetFileName( tmpFileName.GetFullPath() );
}
else
{
tmpFileName = Prj().AbsolutePath( GetBoard()->GetFileName() );
}
wxLogTrace( traceAutoSave,
wxT( "Creating auto save file <" + fn.GetFullPath() ) + wxT( ">" ) );
wxFileName autoSaveFileName = tmpFileName;
if( !fn.IsOk() )
// Auto save file name is the board file name prepended with autosaveFilePrefix string.
autoSaveFileName.SetName( wxString( autosavePrefix ) + autoSaveFileName.GetName() );
if( !autoSaveFileName.IsOk() )
return false;
else if( SavePcbFile( fn.GetFullPath(), NO_BACKUP_FILE ) )
// If the board file path is not writable, try writing to a platform specific temp file
// path. If that path isn't writabe, give up.
if( !autoSaveFileName.IsDirWritable() )
{
autoSaveFileName.SetPath( wxFileName::GetTempDir() );
if( !autoSaveFileName.IsOk() || !autoSaveFileName.IsDirWritable() )
return false;
}
wxLogTrace( traceAutoSave, "Creating auto save file <" + autoSaveFileName.GetFullPath() + ">" );
if( SavePcbFile( autoSaveFileName.GetFullPath(), NO_BACKUP_FILE ) )
{
GetScreen()->SetModify();
GetBoard()->SetFileName( tmpFileName.GetFullPath() );

View File

@ -609,8 +609,15 @@ void PCB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
// Delete the auto save file if it exists.
wxFileName fn = GetBoard()->GetFileName();
// Auto save file name is the normal file name prefixed with a '$'.
fn.SetName( wxT( "$" ) + fn.GetName() );
// Auto save file name is the normal file name prefixed with '_autosave'.
fn.SetName( GetAutoSaveFilePrefix() + fn.GetName() );
// 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.
if( !fn.IsOk() || !fn.IsDirWritable() )
fn.SetPath( wxFileName::GetTempDir() );
wxLogTrace( traceAutoSave, "Deleting auto save file <" + fn.GetFullPath() + ">" );
// Remove the auto save file on a normal close of Pcbnew.
if( fn.FileExists() && !wxRemoveFile( fn.GetFullPath() ) )