From 981f73c3db7e79e0acf0f135f271b35fda94bb8a Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Tue, 26 Sep 2023 08:57:27 -0400 Subject: [PATCH] detect downloads folder add downloads folder to problem path names, also updated check --- SPTInstaller/Helpers/FileHelper.cs | 48 +++++++++++++++++-- SPTInstaller/SPTInstaller.csproj | 4 +- SPTInstaller/ViewModels/PreChecksViewModel.cs | 4 +- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/SPTInstaller/Helpers/FileHelper.cs b/SPTInstaller/Helpers/FileHelper.cs index 787fd72..4fd5cbc 100644 --- a/SPTInstaller/Helpers/FileHelper.cs +++ b/SPTInstaller/Helpers/FileHelper.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; using System.Reflection; using System.Text.RegularExpressions; using Serilog; @@ -143,13 +144,50 @@ public static class FileHelper } } - public static bool CheckPathForProblemLocations(string path) + private enum PathCheckType { - if (path.ToLower().EndsWith("desktop")) return true; + EndsWith = 0, + Contains = 1, + } - var problemNames = new string[] {"onedrive", "nextcloud", "dropbox", "google" }; + public static bool CheckPathForProblemLocations(string path, out string detectedName) + { + detectedName = ""; - return problemNames.Where(x => path.ToLower().Contains(x)).Count() > 0; + var problemNames = new Dictionary() + { + { "Desktop", PathCheckType.EndsWith }, + { "Downloads", PathCheckType.EndsWith }, + { "OneDrive", PathCheckType.Contains }, + { "NextCloud", PathCheckType.Contains }, + { "DropBox", PathCheckType.Contains }, + { "Google", PathCheckType.Contains }, + }; + + foreach (var name in problemNames) + { + switch (name.Value) + { + case PathCheckType.EndsWith: + if (path.ToLower().EndsWith(name.Key.ToLower())) + { + detectedName = name.Key; + return true; + } + break; + case PathCheckType.Contains: + if (path.ToLower().Contains(name.Key.ToLower())) + { + detectedName = name.Key; + return true; + } + break; + default: + break; + } + } + + return false; } } \ No newline at end of file diff --git a/SPTInstaller/SPTInstaller.csproj b/SPTInstaller/SPTInstaller.csproj index c997265..c739110 100644 --- a/SPTInstaller/SPTInstaller.csproj +++ b/SPTInstaller/SPTInstaller.csproj @@ -9,8 +9,8 @@ icon.ico Assets\icon.ico Debug;Release;TEST - 2.15 - 2.15 + 2.16 + 2.16 diff --git a/SPTInstaller/ViewModels/PreChecksViewModel.cs b/SPTInstaller/ViewModels/PreChecksViewModel.cs index 13aa088..78ef47e 100644 --- a/SPTInstaller/ViewModels/PreChecksViewModel.cs +++ b/SPTInstaller/ViewModels/PreChecksViewModel.cs @@ -110,12 +110,12 @@ public class PreChecksViewModel : ViewModelBase Task.Run(async () => { - if (FileHelper.CheckPathForProblemLocations(InstallPath)) + if (FileHelper.CheckPathForProblemLocations(InstallPath, out var detectedName)) { await Dispatcher.UIThread.InvokeAsync(async () => { Log.Warning("Problem folder detected, confirming install path ..."); - var confirmation = await DialogHost.Show(new ConfirmationDialog($"We suspect you may be installing to your desktop or a cloud synced folder.\nYou might want to consider installing somewhere else to avoid issues.\n\nAre you sure you want to install to this path?\n{InstallPath}")); + var confirmation = await DialogHost.Show(new ConfirmationDialog($"We suspect you may be installing into a problematic folder: {detectedName}.\nYou might want to consider installing somewhere else to avoid issues.\n\nAre you sure you want to install to this path?\n{InstallPath}")); if (confirmation == null || !bool.TryParse(confirmation.ToString(), out var confirm) || !confirm) {