private static bool BackupProjectForRestore(FwRestoreProjectSettings restoreSettings,
FdoCache existingCache, Form dialogOwner)
{
using (var progressDlg = new ProgressDialogWithTask(dialogOwner))
{
FdoCache cache = existingCache ?? FdoCache.CreateCacheFromExistingData(
new ProjectId(restoreSettings.Settings.FullProjectPath, null),
s_sWsUser, s_ui, FwDirectoryFinder.FdoDirectories, CreateFdoSettings(), progressDlg);
try
{
var backupSettings = new BackupProjectSettings(cache, restoreSettings.Settings, FwDirectoryFinder.DefaultBackupDirectory);
backupSettings.DestinationFolder = FwDirectoryFinder.DefaultBackupDirectory;
backupSettings.AppAbbrev = restoreSettings.FwAppCommandLineAbbrev;
var backupService = new ProjectBackupService(cache, backupSettings);
string backupFile;
if (!backupService.BackupProject(progressDlg, out backupFile))
{
string msg = string.Format(FwCoreDlgs.FwCoreDlgs.ksCouldNotBackupSomeFiles, backupService.FailedFiles.ToString(", ", Path.GetFileName));
if (MessageBox.Show(msg, FwCoreDlgs.FwCoreDlgs.ksWarning, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
File.Delete(backupFile);
}
}
catch (FwBackupException e)
{
if (MessageBox.Show(dialogOwner,
string.Format(FwCoreDlgs.FwCoreDlgs.ksBackupErrorCreatingZipfile, e.ProjectName, e.Message) +
Environment.NewLine + Environment.NewLine + Properties.Resources.ksBackupErrorDuringRestore,
FwCoreDlgs.FwCoreDlgs.ksBackupErrorCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) ==
DialogResult.No)
{
return false;
}
}
finally
{
if (existingCache == null) // We created a new cache so we need to dispose of it
cache.Dispose();
}
}
return true;
}