From c25f5098eab7112c5e1f91c10b62e7298c2ac8b4 Mon Sep 17 00:00:00 2001 From: Brian Lima Date: Sun, 7 Apr 2024 14:19:00 -0300 Subject: [PATCH] Improve temp image directory handling --- UWPHook/GamesWindow.xaml.cs | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/UWPHook/GamesWindow.xaml.cs b/UWPHook/GamesWindow.xaml.cs index 2309e65..f692efa 100644 --- a/UWPHook/GamesWindow.xaml.cs +++ b/UWPHook/GamesWindow.xaml.cs @@ -59,7 +59,6 @@ namespace UWPHook { // When length is 1, the only argument is the path where the app is installed _ = LauncherAsync(args); // Launches the requested game - } else { @@ -301,10 +300,7 @@ namespace UWPHook Log.Verbose("Detected Game: " + game.ToString()); UInt64 gameId = GenerateSteamGridAppId(appName, appTarget); - if (!Directory.Exists(tmpGridDirectory)) - { - Directory.CreateDirectory(tmpGridDirectory); - } + SafellyCreateTmpGridDirectory(tmpGridDirectory); var gameGridsVertical = api.GetGameGrids(game.Id, "600x900,342x482,660x930"); var gameGridsHorizontal = api.GetGameGrids(game.Id, "460x215,920x430"); @@ -355,6 +351,26 @@ namespace UWPHook } } + private void SafellyCreateTmpGridDirectory(string tmpGridDirectory) + { + if (!Directory.Exists(tmpGridDirectory)) + { + try + { + Directory.CreateDirectory(tmpGridDirectory); + Log.Information("Created directory: " + tmpGridDirectory); + } + catch (Exception exception) + { + Log.Error(exception.Message); + Log.Error(exception.StackTrace); + throw new Exception("UWPHook was not able to create the tmp directory for some reason." + Environment.NewLine + + "You may solve this by manually creating the following folder:" + Environment.NewLine + + tmpGridDirectory); + } + } + } + /// /// Main Task to export the selected games to steam /// @@ -431,10 +447,7 @@ namespace UWPHook { string tmpGridDirectory = Path.GetTempPath() + "UWPHook\\tmp_grid\\"; - if (!Directory.Exists(tmpGridDirectory)) - { - Directory.CreateDirectory(tmpGridDirectory); - } + SafellyCreateTmpGridDirectory(tmpGridDirectory); string[] images = Directory.GetFiles(tmpGridDirectory);