Example #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();
                }
            }
        void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            string[] files = e.Argument as string[];

            XCopy.Copy(files[0], files[1], true, true, (o, pce) =>
            {
                worker.ReportProgress(pce.ProgressPercentage, files[0]);
            });

            e.Result = files[1];
        }
Example #3
0
        private void CopyFile(string source, string dest)
        {
            var started = DateTime.Now;

            XCopy.Copy(source, dest, true,
                       true,
                       (prog, total) =>
            {
                if (IsCancelled)
                {
                    return;
                }
                ChangeProgressBarEstimate(prog, total, started, true);
            }, CancellationTokenSource.Token);
        }
Example #4
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();
                }
            }