From 0f97e4630cc225193ead4a5f8c77dfb337530a2c Mon Sep 17 00:00:00 2001
From: Miepee <38186597+Miepee@users.noreply.github.com>
Date: Tue, 6 Jul 2021 12:33:34 +0200
Subject: [PATCH] Add failsafe in case Save directory doesn't exist
---
.../AM2RLauncher/CrossPlatformOperations.cs | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs b/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs
index 100494d..2d47d4e 100644
--- a/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs
+++ b/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs
@@ -95,7 +95,7 @@ namespace AM2RLauncher
return null;
//this uses the indexer, which means, we can use the variable in order to get the property. Look at LauncherConfigXML for more info
- return launcherConfig[property] != null ? launcherConfig[property].ToString() : null;
+ return launcherConfig[property]?.ToString();
}
return null;
}
@@ -192,16 +192,21 @@ namespace AM2RLauncher
}
///
- /// Opens in a file explorer.
+ /// Opens in a file explorer. Creates the directory if it doesn't exist.
///
/// Path to open.
public static void OpenFolder(string path)
{
- if (currentPlatform.IsWinForms) // We have to replace forward slashes with backslashes here because explorer.exe is picky...
+ // We have to replace forward slashes with backslashes here on windows because explorer.exe is picky...
+ string realPath = currentPlatform.IsWinForms ? Environment.ExpandEnvironmentVariables(path).Replace("/", "\\") : path.Replace("~", Environment.GetEnvironmentVariable("HOME"));
+ if (!Directory.Exists(realPath))
+ Directory.CreateDirectory(realPath);
+
+ if (currentPlatform.IsWinForms)
// And we're using explorer.exe to prevent people from stuffing system commands in here wholesale. That would be bad.
- Process.Start("explorer.exe", Environment.ExpandEnvironmentVariables(path).Replace("/", "\\"));
+ Process.Start("explorer.exe", realPath);
else if (currentPlatform.IsGtk)
- Process.Start("xdg-open", path.Replace("~", Environment.GetEnvironmentVariable("HOME")));
+ Process.Start("xdg-open", realPath);
}
///