From 104de8d25d4e51a3a77f86d5ab32c658cd28387c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Climent?= Date: Sat, 8 Feb 2025 23:25:16 +0100 Subject: [PATCH] Fix a hard crash happening when UniGetUI in portable mode does not have write permissions on the settings directory --- src/UniGetUI.Core.Data/CoreData.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/UniGetUI.Core.Data/CoreData.cs b/src/UniGetUI.Core.Data/CoreData.cs index 21a7c6b54..98527c65f 100644 --- a/src/UniGetUI.Core.Data/CoreData.cs +++ b/src/UniGetUI.Core.Data/CoreData.cs @@ -39,11 +39,22 @@ public static string UniGetUIDataDirectory if (IS_PORTABLE is null) IS_PORTABLE = File.Exists(Path.Join(UniGetUIExecutableDirectory, "ForceUniGetUIPortable")); - if (IS_PORTABLE == true) + if (IS_PORTABLE is true) { string path = Path.Join(UniGetUIExecutableDirectory, "Settings"); - if (!Directory.Exists(path)) Directory.CreateDirectory(path); - return path; + try + { + if (!Directory.Exists(path)) Directory.CreateDirectory(path); + var testfilepath = Path.Join(path, "PermissionTestFile"); + File.WriteAllText(testfilepath, "https://www.youtube.com/watch?v=dQw4w9WgXcQ"); + return path; + } + catch (Exception ex) + { + IS_PORTABLE = false; + Logger.Error($"Could not acces/write path {path}. UniGetUI will NOT be run in portable mode, and User settings will be used instead"); + Logger.Error(ex); + } } string old_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".wingetui");