From 15bd3253911d5535ed95017c898174158855ca56 Mon Sep 17 00:00:00 2001 From: ccloli Date: Thu, 6 Apr 2023 23:12:20 +0800 Subject: [PATCH] Try moving directory first to reduce time and disk writing --- LegacyInstaller/MainWindow.xaml.cs | 24 ++++++++++++++++-------- LegacyInstaller/Utilities.cs | 5 +++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/LegacyInstaller/MainWindow.xaml.cs b/LegacyInstaller/MainWindow.xaml.cs index 1af73af..c153e7b 100644 --- a/LegacyInstaller/MainWindow.xaml.cs +++ b/LegacyInstaller/MainWindow.xaml.cs @@ -262,14 +262,22 @@ private async Task InstallVersion(Version version) await _steamProcess.Downloader.DownloadDepot(version.ManifestId, FileSystemChanged); // Copy files - this.Dispatcher.Invoke((Action)delegate { installStateLabel.Content = "Copying..."; }); - Directory.CreateDirectory(SelectedVersionInstallDir); - var watcher = new FileSystemWatcher(SelectedVersionInstallDir); - watcher.NotifyFilter = NotifyFilters.Attributes | NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.Security | NotifyFilters.Size; - watcher.IncludeSubdirectories = true; - watcher.EnableRaisingEvents = true; - watcher.Changed += FileSystemChanged; - await Utilities.CopyDirectory(_steamProcess.Downloader.ContentAppDepotDir, SelectedVersionInstallDir); + try + { + this.Dispatcher.Invoke((Action)delegate { installStateLabel.Content = "Moving..."; }); + Utilities.MoveDirectory(_steamProcess.Downloader.ContentAppDepotDir, SelectedVersionInstallDir); + } + catch + { + this.Dispatcher.Invoke((Action)delegate { installStateLabel.Content = "Copying..."; }); + Directory.CreateDirectory(SelectedVersionInstallDir); + var watcher = new FileSystemWatcher(SelectedVersionInstallDir); + watcher.NotifyFilter = NotifyFilters.Attributes | NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.Security | NotifyFilters.Size; + watcher.IncludeSubdirectories = true; + watcher.EnableRaisingEvents = true; + watcher.Changed += FileSystemChanged; + await Utilities.CopyDirectory(_steamProcess.Downloader.ContentAppDepotDir, SelectedVersionInstallDir); + } // Install to steam this.Dispatcher.Invoke((Action)delegate { installStateLabel.Content = "Installing..."; }); diff --git a/LegacyInstaller/Utilities.cs b/LegacyInstaller/Utilities.cs index d2a7b7c..737ed82 100644 --- a/LegacyInstaller/Utilities.cs +++ b/LegacyInstaller/Utilities.cs @@ -30,6 +30,11 @@ public static async Task CopyDirectory(string sourceDir, string targetDir) catch { } } + public static void MoveDirectory(string sourceDir, string targetDir) + { + Directory.Move(sourceDir, targetDir); + } + public static int Search(byte[] src, byte[] pattern) { int maxFirstCharSlot = src.Length - pattern.Length + 1;