Protected folder subfolder handling (#2366)

* added more robust protected location checking, for exe and download/install paths

remove debug output and formatting

slight change to trigger rerun of CI

updated changelog

trigger CI re-run

* removed debug code

---------

Co-authored-by: Timothy Baldridge <tbaldridge@gmail.com>
This commit is contained in:
JanuarySnow 2023-07-16 22:22:56 +01:00 committed by GitHub
parent 5ae28e22e3
commit 58f9ea7afc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 6 deletions

View File

@ -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 more robust checking for protected location paths and subfolders for the launcher exe and install and download paths
* Fixed readme double opening when modlist details are prepoulated
* Added a check if Downloadpath is alongside Wabbajack.exe location, to match the install path check that already exists
* Added check for identical download and install paths

View File

@ -300,8 +300,11 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM
{
yield return ErrorResponse.Fail("Installing in this folder may overwrite Wabbajack");
}
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");
}
}
private async Task BeginSlideShow(CancellationToken token)
{

View File

@ -222,11 +222,8 @@ public class MainWindowViewModel : ViewModelBase
try
{
var entryPoint = KnownFolders.EntryPoint;
if (entryPoint.FileName == "Desktop".ToRelativePath()
|| entryPoint.Depth <= 1
|| entryPoint.FileName == "Downloads".ToRelativePath())
if (KnownFolders.IsInSpecialFolder(entryPoint) || entryPoint.Depth <= 1)
{
var msg = MessageBox.Avalonia.MessageBoxManager
.GetMessageBoxStandardWindow(new MessageBoxStandardParams()
{
@ -234,7 +231,7 @@ public class MainWindowViewModel : ViewModelBase
ShowInCenter = true,
ContentTitle = "Wabbajack Launcher: Bad startup path",
ContentMessage =
"Cannot start in the root, Downloads or Desktop folders.\nPlease move Wabbajack to another folder."
"Cannot start in the root of a drive, or protected folder locations such as Downloads, Desktop etc.\nPlease move Wabbajack to another folder."
});
var result = await msg.Show();
Environment.Exit(1);

View File

@ -44,6 +44,48 @@ public static class KnownFolders
}
}
public static bool IsInSpecialFolder(this AbsolutePath candidate)
{
foreach (var val in Enum.GetValues(typeof(Environment.SpecialFolder)))
{
AbsolutePath specialPath = Environment.GetFolderPath((Environment.SpecialFolder)val).ToAbsolutePath();
if ((candidate.ToString().Length > 0 && candidate == specialPath)
|| KnownFolders.IsSubDirectoryOf(candidate.ToString(), specialPath.ToString()))
{
return true;
}
}
return false;
}
public static bool IsSubDirectoryOf(this string candidate, string other)
{
if (candidate.Length == 0) return false;
if (other.Length == 0) return false;
var isChild = false;
try
{
var candidateInfo = new DirectoryInfo(candidate);
var otherInfo = new DirectoryInfo(other);
while (candidateInfo.Parent != null)
{
if (candidateInfo.Parent.FullName == otherInfo.FullName)
{
isChild = true;
break;
}
else candidateInfo = candidateInfo.Parent;
}
}
catch (Exception error)
{
var message = String.Format("Unable to check directories {0} and {1}: {2}", candidate, other, error);
Trace.WriteLine(message);
}
return isChild;
}
public static AbsolutePath AppDataLocal =>
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData).ToAbsolutePath();