Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UniGetUI Portable #3203

Merged
merged 3 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
1 change: 1 addition & 0 deletions UniGetUI.iss
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ Source: "unigetui_bin\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion;
Source: "unigetui_bin\*"; DestDir: "{app}"; Flags: createallsubdirs ignoreversion recursesubdirs;
Source: "src\UniGetUI.PackageEngine.Managers.Chocolatey\choco-cli\*"; DestDir: "{userpf}\..\UniGetUI\Chocolatey"; Flags: createallsubdirs ignoreversion recursesubdirs uninsneveruninstall; Tasks: regularinstall\chocoinstall; Check: not CmdLineParamExists('/NoChocolatey');
Source: "InstallerExtras\EnsureWinGet.ps1"; DestDir: "{tmp}"; Flags: deleteafterinstall
Source: "InstallerExtras\ForceUniGetUIPortable"; DestDir: "{app}"; Tasks: portableinstall


[Icons]
Expand Down
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;
}
}

}
}
1 change: 1 addition & 0 deletions src/UniGetUI/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Welcome to UniGetUI Version {CoreData.VersionName}
Logger.ImportantInfo(textart);
Logger.ImportantInfo(" ");
Logger.ImportantInfo($"Build {CoreData.BuildNumber}");
Logger.ImportantInfo($"Data directory {CoreData.UniGetUIDataDirectory}");
Logger.ImportantInfo($"Encoding Code Page set to {CoreData.CODE_PAGE}");

// WinRT single-instance fancy stuff
Expand Down
Loading