Commit 3e861db3 authored by Dick Hollenbeck's avatar Dick Hollenbeck Committed by Wayne Stambaugh

Lock file improvements.

parent da4055ae
...@@ -186,6 +186,7 @@ set( COMMON_SRCS ...@@ -186,6 +186,7 @@ set( COMMON_SRCS
kiway_express.cpp kiway_express.cpp
kiway_holder.cpp kiway_holder.cpp
kiway_player.cpp kiway_player.cpp
lockfile.cpp
msgpanel.cpp msgpanel.cpp
netlist_keywords.cpp netlist_keywords.cpp
newstroke_font.cpp newstroke_font.cpp
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include <math/box2.h> #include <math/box2.h>
#include <wx/fontdlg.h> #include <wx/fontdlg.h>
#include <wx/snglinst.h>
#include <view/view.h> #include <view/view.h>
#include <view/view_controls.h> #include <view/view_controls.h>
#include <gal/graphics_abstraction_layer.h> #include <gal/graphics_abstraction_layer.h>
...@@ -97,6 +98,8 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, ...@@ -97,6 +98,8 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent,
long aStyle, const wxString & aFrameName ) : long aStyle, const wxString & aFrameName ) :
KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ) KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName )
{ {
m_file_checker = NULL;
m_drawToolBar = NULL; m_drawToolBar = NULL;
m_optionsToolBar = NULL; m_optionsToolBar = NULL;
m_gridSelectBox = NULL; m_gridSelectBox = NULL;
...@@ -179,6 +182,25 @@ EDA_DRAW_FRAME::~EDA_DRAW_FRAME() ...@@ -179,6 +182,25 @@ EDA_DRAW_FRAME::~EDA_DRAW_FRAME()
m_currentScreen = NULL; m_currentScreen = NULL;
m_auimgr.UnInit(); m_auimgr.UnInit();
ReleaseFile();
}
void EDA_DRAW_FRAME::ReleaseFile()
{
delete m_file_checker;
m_file_checker = 0;
}
bool EDA_DRAW_FRAME::LockFile( const wxString& aFileName )
{
delete m_file_checker;
m_file_checker = ::LockFile( aFileName );
return bool( m_file_checker );
} }
......
#include <wx/filename.h>
#include <wx/snglinst.h>
wxSingleInstanceChecker* LockFile( const wxString& aFileName )
{
// first make absolute and normalize, to avoid that different lock files
// for the same file can be created
wxFileName fn( aFileName );
fn.MakeAbsolute();
wxString lockFileName = fn.GetFullPath() + wxT( ".lock" );
lockFileName.Replace( wxT( "/" ), wxT( "_" ) );
// We can have filenames coming from Windows, so also convert Windows separator
lockFileName.Replace( wxT( "\\" ), wxT( "_" ) );
wxSingleInstanceChecker* p = new wxSingleInstanceChecker( lockFileName );
if( p->IsAnotherRunning() )
{
delete p;
p = NULL;
}
return p;
}
...@@ -262,7 +262,6 @@ static LANGUAGE_DESCR s_Languages[] = ...@@ -262,7 +262,6 @@ static LANGUAGE_DESCR s_Languages[] =
PGM_BASE::PGM_BASE() PGM_BASE::PGM_BASE()
{ {
m_pgm_checker = NULL; m_pgm_checker = NULL;
m_file_checker = NULL;
m_locale = NULL; m_locale = NULL;
m_common_settings = NULL; m_common_settings = NULL;
...@@ -290,20 +289,10 @@ void PGM_BASE::destroy() ...@@ -290,20 +289,10 @@ void PGM_BASE::destroy()
delete m_pgm_checker; delete m_pgm_checker;
m_pgm_checker = 0; m_pgm_checker = 0;
delete m_file_checker;
m_file_checker = 0;
delete m_locale; delete m_locale;
m_locale = 0; m_locale = 0;
} }
void PGM_BASE::ReleaseFile()
{
// Release the current file marked in use.
delete m_file_checker;
m_file_checker = 0;
}
void PGM_BASE::SetEditorName( const wxString& aFileName ) void PGM_BASE::SetEditorName( const wxString& aFileName )
{ {
...@@ -677,36 +666,3 @@ void PGM_BASE::AddMenuLanguageList( wxMenu* MasterMenu ) ...@@ -677,36 +666,3 @@ void PGM_BASE::AddMenuLanguageList( wxMenu* MasterMenu )
} }
} }
bool PGM_BASE::LockFile( const wxString& aFileName )
{
// first make absolute and normalize, to avoid that different lock files
// for the same file can be created
wxFileName fn( aFileName );
fn.MakeAbsolute();
// semaphore to protect the edition of the file by more than one instance
if( m_file_checker != NULL )
{
// it means that we had an open file and we are opening a different one
delete m_file_checker;
}
wxString lockFileName = fn.GetFullPath() + wxT( ".lock" );
lockFileName.Replace( wxT( "/" ), wxT( "_" ) );
// We can have filenames coming from Windows, so also convert Windows separator
lockFileName.Replace( wxT( "\\" ), wxT( "_" ) );
m_file_checker = new wxSingleInstanceChecker( lockFileName );
if( m_file_checker &&
m_file_checker->IsAnotherRunning() )
{
return false;
}
return true;
}
...@@ -191,7 +191,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in ...@@ -191,7 +191,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
wxASSERT_MSG( wxFileName( fullFileName ).IsAbsolute(), wxASSERT_MSG( wxFileName( fullFileName ).IsAbsolute(),
wxT( "bug in single_top.cpp or project manager." ) ); wxT( "bug in single_top.cpp or project manager." ) );
if( !Pgm().LockFile( fullFileName ) ) if( !LockFile( fullFileName ) )
{ {
wxString msg = wxString::Format( _( wxString msg = wxString::Format( _(
"Schematic file '%s' is already open." ), "Schematic file '%s' is already open." ),
......
...@@ -417,10 +417,9 @@ SCH_EDIT_FRAME::~SCH_EDIT_FRAME() ...@@ -417,10 +417,9 @@ SCH_EDIT_FRAME::~SCH_EDIT_FRAME()
m_undoItem = NULL; m_undoItem = NULL;
g_RootSheet = NULL; g_RootSheet = NULL;
m_findReplaceData = NULL; m_findReplaceData = NULL;
Pgm().ReleaseFile(); // Release the lock on root file
} }
void SCH_EDIT_FRAME::SetRepeatItem( SCH_ITEM* aItem ) void SCH_EDIT_FRAME::SetRepeatItem( SCH_ITEM* aItem )
{ {
// we cannot store a pointer to an item in the display list here since // we cannot store a pointer to an item in the display list here since
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
class wxAboutDialogInfo; class wxAboutDialogInfo;
class SEARCH_STACK; class SEARCH_STACK;
class wxSingleInstanceChecker;
// Flag for special keys // Flag for special keys
...@@ -608,6 +609,13 @@ void SystemDirsAppend( SEARCH_STACK* aSearchStack ); ...@@ -608,6 +609,13 @@ void SystemDirsAppend( SEARCH_STACK* aSearchStack );
*/ */
wxString SearchHelpFileFullPath( const SEARCH_STACK& aSearchStack, const wxString& aBaseName ); wxString SearchHelpFileFullPath( const SEARCH_STACK& aSearchStack, const wxString& aBaseName );
/**
* Function LockFile
* tests to see if aFileName can be locked (is not already locked) and only then
* returns a wxSingleInstanceChecker protecting aFileName. Caller owns the return value.
*/
wxSingleInstanceChecker* LockFile( const wxString& aFileName );
/// Put aPriorityPath in front of all paths in the value of aEnvVar. /// Put aPriorityPath in front of all paths in the value of aEnvVar.
const wxString PrePendPath( const wxString& aEnvVar, const wxString& aPriorityPath ); const wxString PrePendPath( const wxString& aEnvVar, const wxString& aPriorityPath );
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include <wxstruct.h> #include <wxstruct.h>
#include <kiway_player.h> #include <kiway_player.h>
class wxSingleInstanceChecker;
/** /**
* Class EDA_DRAW_FRAME * Class EDA_DRAW_FRAME
...@@ -51,6 +53,9 @@ class EDA_DRAW_FRAME : public KIWAY_PLAYER ...@@ -51,6 +53,9 @@ class EDA_DRAW_FRAME : public KIWAY_PLAYER
EDA_DRAW_PANEL_GAL* m_galCanvas; EDA_DRAW_PANEL_GAL* m_galCanvas;
protected: protected:
wxSingleInstanceChecker* m_file_checker; ///< prevents opening same file multiple times.
EDA_HOTKEY_CONFIG* m_HotkeysZoomAndGridList; EDA_HOTKEY_CONFIG* m_HotkeysZoomAndGridList;
int m_LastGridSizeId; // the command id offset (>= 0) of the last selected grid int m_LastGridSizeId; // the command id offset (>= 0) of the last selected grid
// 0 is for the grid corresponding to // 0 is for the grid corresponding to
...@@ -143,6 +148,20 @@ public: ...@@ -143,6 +148,20 @@ public:
~EDA_DRAW_FRAME(); ~EDA_DRAW_FRAME();
/**
* Function LockFile
* marks a schematic file as being in use. Use ReleaseFile() to undo this.
* @param aFileName = full path to the file.
* @return false if the file was already locked, true otherwise.
*/
bool LockFile( const wxString& aFileName );
/**
* Function ReleaseFile
* Release the current file marked in use. See m_file_checker.
*/
void ReleaseFile();
virtual void SetPageSettings( const PAGE_INFO& aPageSettings ) = 0; virtual void SetPageSettings( const PAGE_INFO& aPageSettings ) = 0;
virtual const PAGE_INFO& GetPageSettings() const = 0; virtual const PAGE_INFO& GetPageSettings() const = 0;
......
...@@ -168,20 +168,6 @@ public: ...@@ -168,20 +168,6 @@ public:
*/ */
VTBL_ENTRY void WritePdfBrowserInfos(); VTBL_ENTRY void WritePdfBrowserInfos();
/**
* Function LockFile
* marks a file as being in use.
* @param aFileName = full path to the file.
* @return false if the file was already locked, true otherwise.
*/
VTBL_ENTRY bool LockFile( const wxString& aFileName );
/**
* Function ReleaseFile
* Release the current file marked in use.
*/
VTBL_ENTRY void ReleaseFile();
/** /**
* Function App * Function App
* returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP, or kicad.exe. * returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP, or kicad.exe.
...@@ -227,9 +213,6 @@ protected: ...@@ -227,9 +213,6 @@ protected:
/// prevents multiple instances of a program from being run at the same time. /// prevents multiple instances of a program from being run at the same time.
wxSingleInstanceChecker* m_pgm_checker; wxSingleInstanceChecker* m_pgm_checker;
/// prevents opening the same file multiple times.
wxSingleInstanceChecker* m_file_checker;
/// Configuration settings common to all KiCad program modules, /// Configuration settings common to all KiCad program modules,
/// like as in $HOME/.kicad_common /// like as in $HOME/.kicad_common
wxConfigBase* m_common_settings; wxConfigBase* m_common_settings;
......
...@@ -117,6 +117,7 @@ class SCH_EDIT_FRAME : public SCH_BASE_FRAME ...@@ -117,6 +117,7 @@ class SCH_EDIT_FRAME : public SCH_BASE_FRAME
private: private:
SCH_SHEET_PATH* m_CurrentSheet; ///< which sheet we are presently working on. SCH_SHEET_PATH* m_CurrentSheet; ///< which sheet we are presently working on.
wxString m_DefaultSchematicFileName; wxString m_DefaultSchematicFileName;
PARAM_CFG_ARRAY m_projectFileParams; PARAM_CFG_ARRAY m_projectFileParams;
PARAM_CFG_ARRAY m_configSettings; PARAM_CFG_ARRAY m_configSettings;
wxPageSetupDialogData m_pageSetupData; wxPageSetupDialogData m_pageSetupData;
......
...@@ -770,11 +770,12 @@ bool DIALOG_PAD_PROPERTIES::padValuesOK() ...@@ -770,11 +770,12 @@ bool DIALOG_PAD_PROPERTIES::padValuesOK()
error_msgs.Add( _( "Error: Connector pads are not on the solder paste layer\n" error_msgs.Add( _( "Error: Connector pads are not on the solder paste layer\n"
"Use SMD pads instead" ) ); "Use SMD pads instead" ) );
// Fall trough // Fall trough
/*
case PAD_SMD: // SMD and Connector pads (One external copper layer only) case PAD_SMD: // SMD and Connector pads (One external copper layer only)
if( padlayers_mask[B_Cu] && padlayers_mask[F_Cu] ) if( padlayers_mask[B_Cu] && padlayers_mask[F_Cu] )
error_msgs.Add( _( "Error: only one copper layer allowed for SMD or Connector pads" ) ); error_msgs.Add( _( "Error: only one copper layer allowed for SMD or Connector pads" ) );
break; break;
*/
} }
if( error_msgs.GetCount() ) if( error_msgs.GetCount() )
......
...@@ -395,7 +395,7 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in ...@@ -395,7 +395,7 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
wxASSERT_MSG( wxFileName( fullFileName ).IsAbsolute(), wxASSERT_MSG( wxFileName( fullFileName ).IsAbsolute(),
wxT( "bug in single_top.cpp or project manager." ) ); wxT( "bug in single_top.cpp or project manager." ) );
if( !Pgm().LockFile( fullFileName ) ) if( !LockFile( fullFileName ) )
{ {
wxString msg = wxString::Format( _( wxString msg = wxString::Format( _(
"PCB file '%s' is already open." ), "PCB file '%s' is already open." ),
......
...@@ -486,8 +486,6 @@ PCB_EDIT_FRAME::~PCB_EDIT_FRAME() ...@@ -486,8 +486,6 @@ PCB_EDIT_FRAME::~PCB_EDIT_FRAME()
m_Macros[i].m_Record.clear(); m_Macros[i].m_Record.clear();
delete m_drc; delete m_drc;
Pgm().ReleaseFile(); // Release the lock on PCB file
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment