Disallow exporting to Desktop, Documents, and Downloads

This commit is contained in:
ds5678 2025-03-19 10:26:32 -07:00
parent ab928a7f5b
commit b5b9c2bc94

View File

@ -51,7 +51,7 @@ public static class GameFileLoader
public static void ExportUnityProject(string path)
{
if (IsLoaded)
if (IsLoaded && IsValidExportDirectory(path))
{
Directory.Delete(path, true);
Directory.CreateDirectory(path);
@ -61,7 +61,7 @@ public static class GameFileLoader
public static void ExportPrimaryContent(string path)
{
if (IsLoaded)
if (IsLoaded && IsValidExportDirectory(path))
{
Directory.Delete(path, true);
Directory.CreateDirectory(path);
@ -79,4 +79,20 @@ public static class GameFileLoader
settings.LoadFromDefaultPath();
return settings;
}
private static bool IsValidExportDirectory(string path)
{
if (string.IsNullOrEmpty(path))
{
Logger.Error(LogCategory.Export, "Export path is empty");
return false;
}
string directoryName = Path.GetFileName(path);
if (directoryName is "Desktop" or "Documents" or "Downloads")
{
Logger.Error(LogCategory.Export, $"Export path '{path}' is a system directory");
return false;
}
return true;
}
}