internal static void HandleRestoreRequest(Form dialogOwner, FwRestoreProjectSettings restoreSettings)
{
s_threadHelper.Invoke(() =>
{
// Determine if we need to start a new process for the restore
if (s_projectId != null && s_projectId.IsSameLocalProject(new ProjectId(restoreSettings.Settings.FullProjectPath, null)))
{
// We need to invoke so that the mediator that processed the restore menu item
// can be safely disposed of (and everything that it holds on to can be released).
// If we don't do this, the memory held in the IdentityMap will stay around because
// of remaining references.
s_threadHelper.InvokeAsync(RestoreCurrentProject, restoreSettings, dialogOwner);
}
else if (!TryFindRestoreHandler(restoreSettings))
{
if (s_projectId == null)
{
// No other FieldWorks process was running that could handle the request.
// However, we don't know what project we are opening yet, so just use the
// restored project as our project. (this happens if restoring from the
// command-line)
RestoreCurrentProject(restoreSettings, dialogOwner);
}
else
{
// No other FieldWorks process was running that could handle the request, so
// start a brand new process for the project.
// Since we know that no other process are running on this project, we can
// safely do a backup using a new cache. (FWR-3344)
if (restoreSettings.Settings.BackupOfExistingProjectRequested &&
!BackupProjectForRestore(restoreSettings, null, dialogOwner))
{
return;
}
RestoreProjectSettings settings = restoreSettings.Settings;
// REVIEW: it might look strange to dispose the return value of OpenProjectWithNewProcess.
// However, that is a Process that gets started, and it is ok to dispose that
// right away if we don't work with the process object. It might be better
// though to change the signature of OpenProjectWithNewProcess to return
// a boolean.
using (OpenProjectWithNewProcess((string)null, settings.ProjectName, null,
restoreSettings.FwAppCommandLineAbbrev,
"-" + FwAppArgs.kRestoreFile, settings.Backup.File,
"-" + FwAppArgs.kRestoreOptions, settings.CommandLineOptions))
{
}
}
}
});
}