From a8c5f0e89c1854b3adae3aaef5209577586b135d Mon Sep 17 00:00:00 2001 From: JanuarySnow <85711747+JanuarySnow@users.noreply.github.com> Date: Sun, 16 Jul 2023 22:26:45 +0100 Subject: [PATCH] Added detection of existing files in installpath with confirmation dialog ( avoided by overwrite installation tickbox ) (#2369) update changelog added logic to skip past known last install location when preopulating modlist paths code style Co-authored-by: Timothy Baldridge --- CHANGELOG.md | 1 + .../View Models/Installers/InstallerVM.cs | 24 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e7876a7..0b2f57b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ #### Version TBD * Fixed issues related to high RAM usage * The resumable downloads now reserve drive space to write to in advance instead of being managed in system RAM + * Added safety to install path selection, to ensure that no files are deleted that are not intended to be. * Fixed allowing back button during install which can result in multiple install processes * fixed search filter not applying when pressing back button and reaccessing gallery * Added more robust checking for protected location paths and subfolders for the launcher exe and install and download paths diff --git a/Wabbajack.App.Wpf/View Models/Installers/InstallerVM.cs b/Wabbajack.App.Wpf/View Models/Installers/InstallerVM.cs index 7e0f023c..fabf55d0 100644 --- a/Wabbajack.App.Wpf/View Models/Installers/InstallerVM.cs +++ b/Wabbajack.App.Wpf/View Models/Installers/InstallerVM.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; @@ -34,6 +34,7 @@ using Wabbajack.RateLimiter; using Wabbajack.Paths.IO; using Wabbajack.Services.OSIntegrated; using Wabbajack.Util; +using System.Windows.Forms; namespace Wabbajack; @@ -132,6 +133,8 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM public bool ShowNSFWSlides { get; set; } public LogStream LoggerProvider { get; } + + private AbsolutePath LastInstallPath { get; set; } // Command properties @@ -300,6 +303,24 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM { yield return ErrorResponse.Fail("Installing in this folder may overwrite Wabbajack"); } + + if (installPath.ToString().Length != 0 && installPath != LastInstallPath && + !Installer.AutomaticallyOverwrite && + Directory.EnumerateFileSystemEntries(installPath.ToString()).Any()) + { + string message = "There are existing files in the chosen install path, they will be deleted or overwritten (if updating existing modlist), continue?"; + string title = "Files found in install folder"; + MessageBoxButtons buttons = MessageBoxButtons.YesNo; + DialogResult result = MessageBox.Show(message, title, buttons); + if (result == DialogResult.Yes) + { + // everythings fine + } + else + { + Installer.Location.TargetPath = "".ToAbsolutePath(); + } + if (KnownFolders.IsInSpecialFolder(installPath) || KnownFolders.IsInSpecialFolder(downloadPath)) { yield return ErrorResponse.Fail("Can't install a modlist into Windows protected locations - such as Downloads, Documents etc"); @@ -370,6 +391,7 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM if (prevSettings.ModListLocation == path) { ModListLocation.TargetPath = prevSettings.ModListLocation; + LastInstallPath = prevSettings.InstallLocation; Installer.Location.TargetPath = prevSettings.InstallLocation; Installer.DownloadLocation.TargetPath = prevSettings.DownloadLoadction; ModlistMetadata = metadata ?? prevSettings.Metadata;