Exemple #1
0
        public WaBackup(string filePath, string verificationBuildType, BackupsManager manager, WaBackupsViewModel baseViewModel)
        {
            this.manager = manager;
            this.baseViewModel = baseViewModel;
            FilePath = filePath;
            SetNames(verificationBuildType);

            RestoreCommand = new DelegateCommand(() =>
            {
                try
                {
                    Restore();
                }
                catch (Exception exception)
                {
                    ErrorManager.ShowWarning(exception.Message, exception);
                }
            });

            DeleteCommand = new DelegateCommand(() =>
            {
                try
                {
                    Delete();
                }
                catch (Exception exception)
                {
                    ErrorManager.ShowWarning(exception.Message, exception);
                }
            });
        }
        public WaBackupsViewModel(BuildType buildType)
        {
            if (buildType == BuildType.Stable)
            {
                manager = new StableBackupsManager(this);
            }
            else if (buildType == BuildType.Beta)
            {
                manager = new BetaBackupsManager(this);
            }
            else
            {
                throw new LauncherException("Unknown build type");
            }

            CreateBackupStatus = "Create backup";

            CreateBackupCommand = new AwaitableDelegateCommand(async () =>
            {
                try
                {
                    CreateBackupStatus = "Creating...";
                    makingBackup = true;
                    var t = new Task<WaBackup>(() => manager.CreateBackup());
                    t.Start();
                    var backup = await t;
                    WaBackups.Add(backup);
                }
                catch (Exception exception)
                {
                    App.Logger.LogError("", this, exception);
                    ErrorManager.ShowWarning(exception.Message, exception);
                }
                finally
                {
                    makingBackup = false;
                    CreateBackupStatus = "Create backup";
                    UpdateLastBackupTime();
                }
            }, () => !makingBackup);

            ManageBackupsCommand = new DelegateCommand(() =>
            {
                var ui = new ManageWaBackups(this);
                ui.ShowDialog();
            });

            ImportSettingsCommand = new DelegateCommand(() =>
            {
                // nothing yet
            });

            Title = string.Format("Backups manager ({0})", buildType.ToString());
            RefreshBackups();

            UpdateLastBackupTime();

            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(30);
            timer.Tick += (sender, args) => UpdateLastBackupForDisplay();

            WaBackups.CollectionChanged += (sender, args) => UpdateLastBackupTime();
        }
Exemple #3
0
        public static WaBackup Create(string backupName, string buildType, string sourceDirPath, string targetDirPath, BackupsManager manager, WaBackupsViewModel baseViewModel)
        {
            ValidateName(backupName);

            using (new WurmAssistantGateway(AppContext.WaGatewayErrorMessage))
            {
                using (var tempDirMan = new TempDirManager())
                {
                    var tempDir = tempDirMan.GetHandle();

                    string tempArchiveFilePath = Path.Combine(
                        tempDir.FullName,
                        string.Format("{0}_{1}_{2}.7z",
                            backupName ?? "WurmAssistantBackup",
                            buildType,
                            DateTime.Now.ToStringFormattedForFileEx(highPrecision: true)));

                    var compressor = new SevenZipCompressor()
                    {
                        ArchiveFormat = OutArchiveFormat.SevenZip,
                        CompressionMode = CompressionMode.Create
                    };
                    compressor.CompressDirectory(sourceDirPath, tempArchiveFilePath);

                    var newBackup = new WaBackup(tempArchiveFilePath, buildType, manager, baseViewModel);

                    var targetFile = new FileInfo(newBackup.FilePath);
                    var targetArchiveFile = new FileInfo(Path.Combine(targetDirPath, targetFile.Name));

                    if (targetArchiveFile.Exists)
                    {
                        throw new LauncherException("backup with this file name already exists");
                    }

                    newBackup.MoveInto(targetDirPath);

                    return newBackup;
                }
            }
        }