Skip to content

Commit

Permalink
Add support for the app setings to be contained within the executable…
Browse files Browse the repository at this point in the history
… folder
  • Loading branch information
marticliment committed Jan 19, 2025
1 parent 9379a3b commit 2dbf410
Showing 1 changed file with 64 additions and 53 deletions.
117 changes: 64 additions & 53 deletions src/UniGetUI.Core.Data/CoreData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,6 @@ public static class CoreData
{
private static int? __code_page;
public static int CODE_PAGE { get => __code_page ??= GetCodePage(); }

private static int GetCodePage()
{
try
{
Process p = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "chcp.com",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
}
};
p.Start();
string contents = p.StandardOutput.ReadToEnd();
string purifiedString = "";

foreach (var c in contents.Split(':')[^1].Trim())
{
if (c >= '0' && c <= '9')
{
purifiedString += c;
}
}

return int.Parse(purifiedString);
}
catch (Exception e)
{
Logger.Error(e);
return 0;
}
}

public const string VersionName = "3.1.6-beta1"; // Do not modify this line, use file scripts/apply_versions.py
public const int BuildNumber = 76; // Do not modify this line, use file scripts/apply_versions.py

Expand All @@ -63,16 +27,30 @@ public static HttpClientHandler GenericHttpClientParameters
}
}

private static bool? IS_PORTABLE;

/// <summary>
/// The directory where all the user data is stored. The directory is automatically created if it does not exist.
/// </summary>
public static string UniGetUIDataDirectory
{
get
{
string old_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".wingetui");
string new_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "UniGetUI");
return GetNewDataDirectoryOrMoveOld(old_path, new_path);
if (IS_PORTABLE is null)
IS_PORTABLE = File.Exists(Path.Join(UniGetUIExecutableDirectory, "ForceUniGetUIPortable"));

if (IS_PORTABLE == true)
{
string path = Path.Join(UniGetUIExecutableDirectory, "Settings");
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
return path;
}
else
{
string old_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".wingetui");
string new_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "UniGetUI");
return GetNewDataDirectoryOrMoveOld(old_path, new_path);
}
}
}

Expand All @@ -84,11 +62,7 @@ public static string UniGetUIInstallationOptionsDirectory
get
{
string path = Path.Join(UniGetUIDataDirectory, "InstallationOptions");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}

if (!Directory.Exists(path)) Directory.CreateDirectory(path);
return path;
}
}
Expand All @@ -100,9 +74,9 @@ public static string UniGetUICacheDirectory_Data
{
get
{
string old_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "WingetUI", "CachedData");
string new_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "UniGetUI", "CachedMetadata");
return GetNewDataDirectoryOrMoveOld(old_path, new_path);
string path = Path.Join(UniGetUIDataDirectory, "CachedMetadata");
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
return path;
}
}

Expand All @@ -113,9 +87,9 @@ public static string UniGetUICacheDirectory_Icons
{
get
{
string old_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "WingetUI", "CachedIcons");
string new_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "UniGetUI", "CachedMedia");
return GetNewDataDirectoryOrMoveOld(old_path, new_path);
string path = Path.Join(UniGetUIDataDirectory, "CachedMedia");
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
return path;
}
}

Expand All @@ -126,9 +100,9 @@ public static string UniGetUICacheDirectory_Lang
{
get
{
string old_dir = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "WingetUI", "CachedLangFiles");
string new_dir = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "UniGetUI", "CachedLanguageFiles");
return GetNewDataDirectoryOrMoveOld(old_dir, new_dir);
string path= Path.Join(UniGetUIDataDirectory, "CachedLanguageFiles");
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
return path;
}
}

Expand Down Expand Up @@ -308,5 +282,42 @@ private static string GetNewDataDirectoryOrMoveOld(string old_path, string new_p
TypeInfoResolverChain = { new DefaultJsonTypeInfoResolver() },
WriteIndented = true,
};


private static int GetCodePage()
{
try
{
Process p = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "chcp.com",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
}
};
p.Start();
string contents = p.StandardOutput.ReadToEnd();
string purifiedString = "";

foreach (var c in contents.Split(':')[^1].Trim())
{
if (c >= '0' && c <= '9')
{
purifiedString += c;
}
}

return int.Parse(purifiedString);
}
catch (Exception e)
{
Logger.Error(e);
return 0;
}
}

}
}

0 comments on commit 2dbf410

Please sign in to comment.