Skip to content

Commit 3bfcd5c

Browse files
committed
Improvements to portable settings
1 parent 07b459b commit 3bfcd5c

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

src/UniGetUI.Core.Data/CoreData.cs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public static HttpClientHandler GenericHttpClientParameters
2828
}
2929

3030
private static bool? IS_PORTABLE;
31+
private static string? PORTABLE_PATH;
3132
public static bool IsPortable { get => IS_PORTABLE ?? false; }
3233

3334
public static string? TEST_DataDirectoryOverride { private get; set; }
@@ -45,24 +46,31 @@ public static string UniGetUIDataDirectory
4546
}
4647

4748
if (IS_PORTABLE is null)
49+
{
4850
IS_PORTABLE = File.Exists(Path.Join(UniGetUIExecutableDirectory, "ForceUniGetUIPortable"));
4951

50-
if (IS_PORTABLE is true)
51-
{
52-
string path = Path.Join(UniGetUIExecutableDirectory, "Settings");
53-
try
54-
{
55-
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
56-
var testfilepath = Path.Join(path, "PermissionTestFile");
57-
File.WriteAllText(testfilepath, "https://www.youtube.com/watch?v=dQw4w9WgXcQ");
58-
return path;
59-
}
60-
catch (Exception ex)
52+
if (IS_PORTABLE is true)
6153
{
62-
IS_PORTABLE = false;
63-
Logger.Error($"Could not acces/write path {path}. UniGetUI will NOT be run in portable mode, and User settings will be used instead");
64-
Logger.Error(ex);
54+
string path = Path.Join(UniGetUIExecutableDirectory, "Settings");
55+
try
56+
{
57+
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
58+
var testfilepath = Path.Join(path, "PermissionTestFile");
59+
File.WriteAllText(testfilepath, "https://www.youtube.com/watch?v=dQw4w9WgXcQ");
60+
PORTABLE_PATH = path;
61+
return path;
62+
}
63+
catch (Exception ex)
64+
{
65+
IS_PORTABLE = false;
66+
Logger.Error(
67+
$"Could not acces/write path {path}. UniGetUI will NOT be run in portable mode, and User settings will be used instead");
68+
Logger.Error(ex);
69+
}
6570
}
71+
} else if (IS_PORTABLE is true)
72+
{
73+
return PORTABLE_PATH ?? throw new Exception("This shouldn't be possible");
6674
}
6775

6876
string old_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".wingetui");

0 commit comments

Comments
 (0)