Merge pull request 'impr/path-checks' (#72) from waffle.lord/SPT-AKI-Installer:impr/path-checks into master
Reviewed-on: CWX/SPT-AKI-Installer#72
This commit is contained in:
commit
723ba56cbe
@ -162,54 +162,48 @@ public static class FileHelper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum PathCheckType
|
public static bool CheckPathForProblemLocations(string path, out PathCheck failedCheck)
|
||||||
{
|
{
|
||||||
EndsWith = 0,
|
failedCheck = new();
|
||||||
Contains = 1,
|
|
||||||
DriveRoot = 2
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool CheckPathForProblemLocations(string path, out string detectedName)
|
var problemPaths = new List<PathCheck>()
|
||||||
{
|
|
||||||
detectedName = "";
|
|
||||||
|
|
||||||
var problemNames = new Dictionary<string, PathCheckType>()
|
|
||||||
{
|
{
|
||||||
{ "Documents", PathCheckType.EndsWith },
|
new("Documents", PathCheckType.EndsWith, PathCheckAction.Warn),
|
||||||
{ "Desktop", PathCheckType.Contains },
|
new("Desktop", PathCheckType.EndsWith, PathCheckAction.Deny),
|
||||||
{ "scoped_dir", PathCheckType.Contains },
|
new("Desktop", PathCheckType.Contains, PathCheckAction.Warn),
|
||||||
{ "Downloads", PathCheckType.Contains },
|
new("scoped_dir", PathCheckType.Contains, PathCheckAction.Deny),
|
||||||
{ "OneDrive", PathCheckType.Contains },
|
new("Downloads", PathCheckType.Contains, PathCheckAction.Deny),
|
||||||
{ "NextCloud", PathCheckType.Contains },
|
new("OneDrive", PathCheckType.Contains, PathCheckAction.Deny),
|
||||||
{ "DropBox", PathCheckType.Contains },
|
new("NextCloud", PathCheckType.Contains, PathCheckAction.Deny),
|
||||||
{ "Google", PathCheckType.Contains },
|
new("DropBox", PathCheckType.Contains, PathCheckAction.Deny),
|
||||||
{ "Program Files", PathCheckType.Contains },
|
new("Google", PathCheckType.Contains, PathCheckAction.Deny),
|
||||||
{ "Program Files (x86)", PathCheckType.Contains },
|
new("Program Files", PathCheckType.Contains, PathCheckAction.Deny),
|
||||||
{ "Drive Root", PathCheckType.DriveRoot }
|
new("Program Files (x86", PathCheckType.Contains, PathCheckAction.Deny),
|
||||||
|
new("Drive Root", PathCheckType.DriveRoot, PathCheckAction.Deny)
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (var name in problemNames)
|
foreach (var check in problemPaths)
|
||||||
{
|
{
|
||||||
switch (name.Value)
|
switch (check.CheckType)
|
||||||
{
|
{
|
||||||
case PathCheckType.EndsWith:
|
case PathCheckType.EndsWith:
|
||||||
if (path.ToLower().EndsWith(name.Key.ToLower()))
|
if (path.ToLower().EndsWith(check.Target.ToLower()))
|
||||||
{
|
{
|
||||||
detectedName = name.Key;
|
failedCheck = check;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PathCheckType.Contains:
|
case PathCheckType.Contains:
|
||||||
if (path.ToLower().Contains(name.Key.ToLower()))
|
if (path.ToLower().Contains(check.Target.ToLower()))
|
||||||
{
|
{
|
||||||
detectedName = name.Key;
|
failedCheck = check;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PathCheckType.DriveRoot:
|
case PathCheckType.DriveRoot:
|
||||||
if (Regex.Match(path.ToLower(), @"^\w:(\\|\/)$").Success)
|
if (Regex.Match(path.ToLower(), @"^\w:(\\|\/)$").Success)
|
||||||
{
|
{
|
||||||
detectedName = name.Key;
|
failedCheck = check;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -60,7 +60,7 @@ public class ReleaseCheckTask : InstallerTaskBase
|
|||||||
|
|
||||||
if (comparePatchToAki == null && patchNeedCheck)
|
if (comparePatchToAki == null && patchNeedCheck)
|
||||||
{
|
{
|
||||||
return Result.FromError("No patcher available for your version");
|
return Result.FromError("No patcher available for your version. A patcher is usually created within 24 hours of an EFT update.\nYou can join our discord and watch the dev-webhooks channel for '[SPT-AKI/Downgrade-Patches] Release created' to know when a patcher is available");
|
||||||
}
|
}
|
||||||
|
|
||||||
_data.PatchNeeded = patchNeedCheck;
|
_data.PatchNeeded = patchNeedCheck;
|
||||||
|
32
SPTInstaller/Models/PathCheck.cs
Normal file
32
SPTInstaller/Models/PathCheck.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
namespace SPTInstaller.Models;
|
||||||
|
|
||||||
|
public enum PathCheckType
|
||||||
|
{
|
||||||
|
EndsWith = 0,
|
||||||
|
Contains = 1,
|
||||||
|
DriveRoot = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum PathCheckAction
|
||||||
|
{
|
||||||
|
Warn = 0,
|
||||||
|
Deny = 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PathCheck
|
||||||
|
{
|
||||||
|
public string Target { get; private set; }
|
||||||
|
public PathCheckType CheckType { get; private set; }
|
||||||
|
public PathCheckAction CheckAction { get; private set; }
|
||||||
|
|
||||||
|
public PathCheck()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public PathCheck(string target, PathCheckType checkType, PathCheckAction checkAction)
|
||||||
|
{
|
||||||
|
Target = target;
|
||||||
|
CheckType = checkType;
|
||||||
|
CheckAction = checkAction;
|
||||||
|
}
|
||||||
|
}
|
@ -9,8 +9,8 @@
|
|||||||
<PackageIcon>icon.ico</PackageIcon>
|
<PackageIcon>icon.ico</PackageIcon>
|
||||||
<ApplicationIcon>Assets\icon.ico</ApplicationIcon>
|
<ApplicationIcon>Assets\icon.ico</ApplicationIcon>
|
||||||
<Configurations>Debug;Release;TEST</Configurations>
|
<Configurations>Debug;Release;TEST</Configurations>
|
||||||
<AssemblyVersion>2.55</AssemblyVersion>
|
<AssemblyVersion>2.56</AssemblyVersion>
|
||||||
<FileVersion>2.55</FileVersion>
|
<FileVersion>2.56</FileVersion>
|
||||||
<Company>SPT-AKI</Company>
|
<Company>SPT-AKI</Company>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
@ -164,19 +164,38 @@ public class PreChecksViewModel : ViewModelBase
|
|||||||
|
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
if (FileHelper.CheckPathForProblemLocations(InstallPath, out var detectedName))
|
if (FileHelper.CheckPathForProblemLocations(InstallPath, out var failedCheck ))
|
||||||
{
|
{
|
||||||
await Dispatcher.UIThread.InvokeAsync(async () =>
|
switch (failedCheck.CheckAction)
|
||||||
{
|
|
||||||
Log.Warning("Problem folder detected, confirming install path ...");
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
Log.Information("User declined install path, exiting");
|
case PathCheckAction.Warn:
|
||||||
Environment.Exit(0);
|
{
|
||||||
|
await Dispatcher.UIThread.InvokeAsync(async () =>
|
||||||
|
{
|
||||||
|
Log.Warning("Problem path detected, confirming install path ...");
|
||||||
|
var confirmation = await DialogHost.Show(new ConfirmationDialog(
|
||||||
|
$"We suspect you may be installing into a problematic folder: {failedCheck.Target}.\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)
|
||||||
|
{
|
||||||
|
Log.Information("User declined install path, exiting");
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case PathCheckAction.Deny:
|
||||||
|
{
|
||||||
|
Log.Error("Problem path detected, install denied");
|
||||||
|
NavigateTo(new MessageViewModel(HostScreen, Result.FromError($"We suspect you may be installing into a problematic folder: {failedCheck.Target}.\nWe won't be letting you install here. Please move the installer to another folder.\nSuggestion: a folder under your drive root, such as 'C:\\spt\\'\nDenied Path: {InstallPath}")));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
Log.Information("User accepted install path");
|
Log.Information("User accepted install path");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user