コード例 #1
0
            public void RestoreSFAR(bool batchRestore, Action signalRestoreCompleted = null)
            {
                bool?restore = batchRestore;

                if (!restore.Value)
                {
                    restore = RestoreConfirmationCallback?.Invoke(FilePath);
                }
                if (restore.HasValue && restore.Value)
                {
                    NamedBackgroundWorker nbw = new NamedBackgroundWorker(@"RestoreSFARThread");
                    nbw.DoWork += (a, b) =>
                    {
                        var backupFile = Path.Combine(BackupService.GetGameBackupPath(target.Game), FilePath);
                        var targetFile = Path.Combine(target.TargetPath, FilePath);
                        Restoring = true;
                        Log.Information($@"Restoring SFAR from backup: {backupFile} {targetFile}");
                        XCopy.Copy(backupFile, targetFile, true, true,
                                   (o, pce) =>
                        {
                            RestoreButtonContent = M3L.GetString(M3L.string_interp_restoringXpercent,
                                                                 pce.ProgressPercentage.ToString());
                        });
                        var unpackedFiles = Directory.GetFiles(DLCDirectory, @"*", SearchOption.AllDirectories);
                        RestoreButtonContent = M3L.GetString(M3L.string_cleaningUp);
                        foreach (var file in unpackedFiles)
                        {
                            if (!file.EndsWith(@".sfar"))
                            {
                                Log.Information(@"Deleting unpacked file: " + file);
                                File.Delete(file);
                            }
                        }

                        Utilities.DeleteEmptySubdirectories(DLCDirectory);
                        RestoreButtonContent = M3L.GetString(M3L.string_restored);
                    };
                    nbw.RunWorkerCompleted += (a, b) =>
                    {
                        if (b.Error != null)
                        {
                            Log.Error($@"Exception occured in {nbw.Name} thread: {b.Error.Message}");
                        }
                        //File.Copy(backupFile, targetFile, true);
                        //if (!batchRestore)
                        //{
                        RevalidateIsModified();
                        //restoreCompletedCallback?.Invoke();
                        //}
                        Restoring = false;
                        signalRestoreCompleted?.Invoke();
                    };
                    startingRestoreCallback?.Invoke();
                    nbw.RunWorkerAsync();
                }
            }
コード例 #2
0
            public void RestoreSFAR(bool batchRestore)
            {
                bool?restore = batchRestore;

                if (!restore.Value)
                {
                    restore = RestoreConfirmationCallback?.Invoke(FilePath);
                }
                if (restore.HasValue && restore.Value)
                {
                    //Todo: Background thread this maybe?
                    NamedBackgroundWorker bw = new NamedBackgroundWorker("RestoreSFARThread");
                    bw.DoWork += (a, b) =>
                    {
                        var backupFile = Path.Combine(Utilities.GetGameBackupPath(target.Game), FilePath);
                        var targetFile = Path.Combine(target.TargetPath, FilePath);
                        Restoring = true;
                        Log.Information("Restoring SFAR from backup: " + backupFile + " => " + targetFile);
                        XCopy.Copy(backupFile, targetFile, true, true, (o, pce) => { RestoreButtonContent = $"Restoring {pce.ProgressPercentage}%"; });
                        var unpackedFiles = Directory.GetFiles(DLCDirectory, "*", SearchOption.AllDirectories);
                        RestoreButtonContent = $"Cleaning up";
                        foreach (var file in unpackedFiles)
                        {
                            if (!file.EndsWith(".sfar"))
                            {
                                Log.Information("Deleting unpacked file: " + file);
                                File.Delete(file);
                            }
                        }
                        Utilities.DeleteEmptySubdirectories(DLCDirectory);
                        RestoreButtonContent = "Restored";
                    };
                    bw.RunWorkerCompleted += (a, b) =>
                    {
                        //File.Copy(backupFile, targetFile, true);
                        //if (!batchRestore)
                        //{
                        RevalidateIsModified();
                        //restoreCompletedCallback?.Invoke();
                        //}
                        Restoring = false;
                    };
                    startingRestoreCallback?.Invoke();
                    bw.RunWorkerAsync();
                }
            }