Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Src/Common/FieldWorks/FieldWorks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
using SIL.LCModel.Core.WritingSystems;
using SIL.LCModel.Core.KernelInterfaces;
using SIL.LCModel;
using SIL.LCModel.DomainServices;
using SIL.LCModel.DomainServices.BackupRestore;
using SIL.LCModel.DomainServices.DataMigration;
using SIL.LCModel.Infrastructure;
Expand Down Expand Up @@ -2539,6 +2540,24 @@ internal static void HandleRestoreRequest(Form dialogOwner, FwRestoreProjectSett
private static void RestoreCurrentProject(FwRestoreProjectSettings restoreSettings,
Form dialogOwner)
{
// If the project we are about to restore already exists and is open (its data
// file is locked) in some other program, then block the restore before we overwrite any
// files. Otherwise we would destroy the opened project's data and eventually crash trying to
// reopen the locked project (LT-21913).
// We skip this check when 'this' process is the one that has the project open, since we already
// prompted the user and ExecuteWithAppsShutDown will release our own lock before restoring.
var projectPath = restoreSettings.Settings.FullProjectPath;
var weHaveProjectOpen = s_projectId != null &&
s_projectId.IsSameLocalProject(new ProjectId(projectPath));
if (!weHaveProjectOpen && restoreSettings.Settings.ProjectExists &&
ProjectLockingService.IsProjectLocked(projectPath))
{
MessageBox.Show(dialogOwner,
string.Format(Properties.Resources.ksCannotRestoreProjectInUse, restoreSettings.Settings.ProjectName),
Properties.Resources.ksErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

// When we get here we can safely do the backup of the project because we either
// have no cache (and no other process has this project open), or we are the
// process that has this project open. (FWR-3344)
Expand Down Expand Up @@ -3806,6 +3825,27 @@ private static void ExecuteWithAppsShutDown(Func<ProjectId> action)

s_projectId = projId; // Process needs to know its project
}
catch (StartupException e) when (e.InnerException is LcmFileLockedException)
{
// The action (e.g. a restore) succeeded, but the project could not be reopened
// afterwards because it is now open (and its file locked) in another program
// (LT-21913). This is a safety net for the narrow window where the project gets
// locked after RestoreCurrentProject's up-front check but before we reopen it
// here. Inform the user with a message box rather than crashing with the green
// error-reporting dialog. Any other StartupException is left to propagate so
// that unexpected failures still generate a crash report.
if (s_cache != null)
{
s_cache.Dispose();
s_cache = null;
}
// Dispose the partially-created application so that we end up with no running
// apps (which lets the process shut down cleanly, just as if the action had
// failed or been cancelled).
GracefullyShutDownApp(s_flexApp);
MessageBox.Show(e.Message, Properties.Resources.ksErrorCaption,
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
s_allowFinalShutdown = allowFinalShutdownOrigValue; // mustn't suppress any longer (unless we already were).
Expand Down
9 changes: 9 additions & 0 deletions Src/Common/FieldWorks/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Src/Common/FieldWorks/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ Ensure that this folder is shared and that you have permission to access it.</va
<data name="ksBackupErrorDuringRestore" xml:space="preserve">
<value>Do you want to continue with the restore?</value>
</data>
<data name="ksCannotRestoreProjectInUse" xml:space="preserve">
<value>The project '{0}' cannot be restored because it is currently open in another program. Please close the project everywhere it is open and try the restore again.</value>
<comment>Message shown when a restore is attempted over a project that is still open (and its data file is locked) in another program. {0} is the project name.</comment>
</data>
<data name="ksChangeProjectLocationFailed" xml:space="preserve">
<value>Could not change Projects location</value>
</data>
Expand Down
Loading