diff --git a/3d-viewer/3d_cache/3d_cache.cpp b/3d-viewer/3d_cache/3d_cache.cpp index fdb2855d8f..a41c727f67 100644 --- a/3d-viewer/3d_cache/3d_cache.cpp +++ b/3d-viewer/3d_cache/3d_cache.cpp @@ -47,6 +47,7 @@ #include "sg/scenegraph.h" #include "plugins/3dapi/ifsg_api.h" +#include // For ExpandEnvVarSubstitutions #include #include #include diff --git a/common/paths.cpp b/common/paths.cpp index 60c82a1ccf..61e1069f0b 100644 --- a/common/paths.cpp +++ b/common/paths.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include diff --git a/common/settings/settings_manager.cpp b/common/settings/settings_manager.cpp index f297419c90..6224f32a16 100644 --- a/common/settings/settings_manager.cpp +++ b/common/settings/settings_manager.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -757,6 +759,15 @@ bool SETTINGS_MANAGER::LoadProject( const wxString& aFullPath, bool aSetActive ) if( m_projects.count( fullPath ) ) return true; + bool readOnly = false; + std::unique_ptr lockFile = ::LockFile( fullPath ); + + if( !lockFile ) + { + wxLogTrace( traceSettings, "Project %s is locked; opening read-only", fullPath ); + readOnly = true; + } + // No MDI yet if( aSetActive && !m_projects.empty() ) { @@ -773,7 +784,12 @@ bool SETTINGS_MANAGER::LoadProject( const wxString& aFullPath, bool aSetActive ) bool success = loadProjectFile( *project ); if( success ) - project->SetReadOnly( project->GetProjectFile().IsReadOnly() ); + { + project->SetReadOnly( readOnly || project->GetProjectFile().IsReadOnly() ); + + if( lockFile ) + m_project_lock.reset( lockFile.release() ); + } m_projects_list.push_back( std::move( project ) ); m_projects[fullPath] = m_projects_list.back().get(); @@ -825,6 +841,9 @@ bool SETTINGS_MANAGER::UnloadProject( PROJECT* aProject, bool aSave ) // Remove the reference in the environment to the previous project wxSetEnv( PROJECT_VAR_NAME, "" ); + // Release lock on the file, in case we had one + m_project_lock = nullptr; + if( m_kiway ) m_kiway->ProjectChanged(); diff --git a/eeschema/dialogs/dialog_plot_schematic.cpp b/eeschema/dialogs/dialog_plot_schematic.cpp index 38a7531892..9166345a5e 100644 --- a/eeschema/dialogs/dialog_plot_schematic.cpp +++ b/eeschema/dialogs/dialog_plot_schematic.cpp @@ -25,6 +25,7 @@ */ #include +#include // For ExpandEnvVarSubstitutions #include #include #include diff --git a/eeschema/dialogs/panel_sym_lib_table.cpp b/eeschema/dialogs/panel_sym_lib_table.cpp index da92e2a175..7613441da9 100644 --- a/eeschema/dialogs/panel_sym_lib_table.cpp +++ b/eeschema/dialogs/panel_sym_lib_table.cpp @@ -22,6 +22,7 @@ #include #include +#include // For ExpandEnvVarSubstitutions #include #include #include diff --git a/include/settings/settings_manager.h b/include/settings/settings_manager.h index 016493c8f3..9690e10324 100644 --- a/include/settings/settings_manager.h +++ b/include/settings/settings_manager.h @@ -22,7 +22,7 @@ #define _SETTINGS_MANAGER_H #include -#include // for wxString hash +#include // for wxString hash #include class COLOR_SETTINGS; @@ -31,6 +31,7 @@ class KIWAY; class PROJECT; class PROJECT_FILE; class REPORTER; +class wxSingleInstanceChecker; class SETTINGS_MANAGER @@ -425,6 +426,9 @@ private: /// Loaded project files, mapped according to project full name std::map m_project_files; + /// Lock for loaded project (expand to multiple once we support MDI) + std::unique_ptr m_project_lock; + static wxString backupDateTimeFormat; };