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
kiway_express.cpp
kiway_holder.cpp
kiway_player.cpp
lockfile.cpp
msgpanel.cpp
netlist_keywords.cpp
newstroke_font.cpp
......
......@@ -47,6 +47,7 @@
#include <math/box2.h>
#include <wx/fontdlg.h>
#include <wx/snglinst.h>
#include <view/view.h>
#include <view/view_controls.h>
#include <gal/graphics_abstraction_layer.h>
......@@ -97,6 +98,8 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent,
long aStyle, const wxString & aFrameName ) :
KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName )
{
m_file_checker = NULL;
m_drawToolBar = NULL;
m_optionsToolBar = NULL;
m_gridSelectBox = NULL;
......@@ -179,6 +182,25 @@ EDA_DRAW_FRAME::~EDA_DRAW_FRAME()
m_currentScreen = NULL;
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[] =
PGM_BASE::PGM_BASE()
{
m_pgm_checker = NULL;
m_file_checker = NULL;
m_locale = NULL;
m_common_settings = NULL;
......@@ -290,20 +289,10 @@ void PGM_BASE::destroy()
delete m_pgm_checker;
m_pgm_checker = 0;
delete m_file_checker;
m_file_checker = 0;
delete m_locale;
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 )
{
......@@ -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
wxASSERT_MSG( wxFileName( fullFileName ).IsAbsolute(),
wxT( "bug in single_top.cpp or project manager." ) );
if( !Pgm().LockFile( fullFileName ) )
if( !LockFile( fullFileName ) )
{
wxString msg = wxString::Format( _(
"Schematic file '%s' is already open." ),
......
......@@ -417,10 +417,9 @@ SCH_EDIT_FRAME::~SCH_EDIT_FRAME()
m_undoItem = NULL;
g_RootSheet = NULL;
m_findReplaceData = NULL;
Pgm().ReleaseFile(); // Release the lock on root file
}
void SCH_EDIT_FRAME::SetRepeatItem( SCH_ITEM* aItem )
{
// we cannot store a pointer to an item in the display list here since
......
......@@ -45,6 +45,7 @@
class wxAboutDialogInfo;
class SEARCH_STACK;
class wxSingleInstanceChecker;
// Flag for special keys
......@@ -608,6 +609,13 @@ void SystemDirsAppend( SEARCH_STACK* aSearchStack );
*/
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.
const wxString PrePendPath( const wxString& aEnvVar, const wxString& aPriorityPath );
......
......@@ -28,6 +28,8 @@
#include <wxstruct.h>
#include <kiway_player.h>
class wxSingleInstanceChecker;
/**
* Class EDA_DRAW_FRAME
......@@ -43,14 +45,17 @@ class EDA_DRAW_FRAME : public KIWAY_PLAYER
///< Id of active button on the vertical toolbar.
int m_toolId;
BASE_SCREEN* m_currentScreen; ///< current used SCREEN
BASE_SCREEN* m_currentScreen; ///< current used SCREEN
bool m_snapToGrid; ///< Indicates if cursor should be snapped to grid.
bool m_galCanvasActive; ///< whether to use new GAL engine
bool m_snapToGrid; ///< Indicates if cursor should be snapped to grid.
bool m_galCanvasActive; ///< whether to use new GAL engine
EDA_DRAW_PANEL_GAL* m_galCanvas;
protected:
wxSingleInstanceChecker* m_file_checker; ///< prevents opening same file multiple times.
EDA_HOTKEY_CONFIG* m_HotkeysZoomAndGridList;
int m_LastGridSizeId; // the command id offset (>= 0) of the last selected grid
// 0 is for the grid corresponding to
......@@ -143,6 +148,20 @@ public:
~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 const PAGE_INFO& GetPageSettings() const = 0;
......
......@@ -168,20 +168,6 @@ public:
*/
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
* returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP, or kicad.exe.
......@@ -227,9 +213,6 @@ protected:
/// prevents multiple instances of a program from being run at the same time.
wxSingleInstanceChecker* m_pgm_checker;
/// prevents opening the same file multiple times.
wxSingleInstanceChecker* m_file_checker;
/// Configuration settings common to all KiCad program modules,
/// like as in $HOME/.kicad_common
wxConfigBase* m_common_settings;
......
......@@ -117,6 +117,7 @@ class SCH_EDIT_FRAME : public SCH_BASE_FRAME
private:
SCH_SHEET_PATH* m_CurrentSheet; ///< which sheet we are presently working on.
wxString m_DefaultSchematicFileName;
PARAM_CFG_ARRAY m_projectFileParams;
PARAM_CFG_ARRAY m_configSettings;
wxPageSetupDialogData m_pageSetupData;
......
......@@ -770,11 +770,12 @@ bool DIALOG_PAD_PROPERTIES::padValuesOK()
error_msgs.Add( _( "Error: Connector pads are not on the solder paste layer\n"
"Use SMD pads instead" ) );
// Fall trough
/*
case PAD_SMD: // SMD and Connector pads (One external copper layer only)
if( padlayers_mask[B_Cu] && padlayers_mask[F_Cu] )
error_msgs.Add( _( "Error: only one copper layer allowed for SMD or Connector pads" ) );
break;
*/
}
if( error_msgs.GetCount() )
......
......@@ -395,7 +395,7 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
wxASSERT_MSG( wxFileName( fullFileName ).IsAbsolute(),
wxT( "bug in single_top.cpp or project manager." ) );
if( !Pgm().LockFile( fullFileName ) )
if( !LockFile( fullFileName ) )
{
wxString msg = wxString::Format( _(
"PCB file '%s' is already open." ),
......
......@@ -486,8 +486,6 @@ PCB_EDIT_FRAME::~PCB_EDIT_FRAME()
m_Macros[i].m_Record.clear();
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