Skip to content

Commit

Permalink
Merge pull request #33 from ccloli/feature/move-directory
Browse files Browse the repository at this point in the history
Prefer to move the directory to reduce disk writing
  • Loading branch information
ErisApps authored Jul 1, 2023
2 parents 67deb24 + 15bd325 commit 4f8359e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
24 changes: 16 additions & 8 deletions LegacyInstaller/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

// Create Junction Links for custom levels
if (customLevelsLinkCheckbox.IsChecked.GetValueOrDefault())
Expand Down
5 changes: 5 additions & 0 deletions LegacyInstaller/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4f8359e

Please sign in to comment.