mirror of
https://github.com/WinDurango/WinDurango.UI.git
synced 2026-01-31 00:55:24 +01:00
@@ -233,7 +233,7 @@ namespace WinDurango.UI.Controls
|
||||
|
||||
RightTapped += (sender, e) =>
|
||||
{
|
||||
rcFlyout.ShowAt(sender as FrameworkElement);
|
||||
rcFlyout.ShowAt(sender as FrameworkElement, e.GetPosition(sender as UIElement));
|
||||
};
|
||||
|
||||
startButton.Tapped += async (s, e) =>
|
||||
|
||||
@@ -29,13 +29,13 @@ namespace WinDurango.UI.Utils
|
||||
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (compatible; GitHubAPI/1.0)");
|
||||
}
|
||||
|
||||
public static async Task<bool> UnpatchPackage(Package package, ProgressController controller)
|
||||
public static Task<bool> UnpatchPackage(Package package, ProgressController controller)
|
||||
{
|
||||
installedPackage pkg = App.InstalledPackages.GetPackage(package);
|
||||
if (pkg == null)
|
||||
return false;
|
||||
return Task.FromResult(false);
|
||||
|
||||
return await UnpatchPackage(pkg, controller);
|
||||
return UnpatchPackage(pkg, controller);
|
||||
}
|
||||
|
||||
public static async Task<bool> PatchPackage(Package package, bool forceRedownload,
|
||||
@@ -48,7 +48,8 @@ namespace WinDurango.UI.Utils
|
||||
return await PatchPackage(pkg, forceRedownload, controller);
|
||||
}
|
||||
|
||||
// todo: clean this up
|
||||
|
||||
// Cleaned lil bit
|
||||
public static async Task<bool> PatchPackage(installedPackage package, bool forceRedownload,
|
||||
ProgressController controller)
|
||||
{
|
||||
@@ -59,6 +60,7 @@ namespace WinDurango.UI.Utils
|
||||
|
||||
controller?.Update("Getting latest release", 10);
|
||||
await GetOrReuseRelease(); // don't use the return value since wdRelease is set regardless
|
||||
|
||||
string dlLink = wdRelease.DownloadLink;
|
||||
string relName = wdRelease.Name;
|
||||
string dlPath = $"WinDurangoCore.zip";
|
||||
@@ -81,111 +83,111 @@ namespace WinDurango.UI.Utils
|
||||
|
||||
try
|
||||
{
|
||||
controller?.Update($"Downloading WinDurango {relName}", 20);
|
||||
|
||||
await using Stream httpStream = await httpClient.GetStreamAsync(dlLink);
|
||||
await using FileStream stream = new(archivePath, FileMode.Create, FileAccess.Write, FileShare.None);
|
||||
controller?.Update("Writing release zip", 30);
|
||||
// why so slow?
|
||||
await httpStream.CopyToAsync(stream);
|
||||
|
||||
//controller?.Update("Writing release zip", 30);
|
||||
// Commented ^, as above code does not start the download, the download is done in the httpStream.CopyToAsync function
|
||||
controller?.Update($"Downloading WinDurango {relName}", 30);
|
||||
await httpStream.CopyToAsync(stream, 1048576); // 1MB Buffer
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await controller.Fail(ex.Message, "Failed to download/write zip");
|
||||
await controller!.Fail(ex.Message, "Failed to download/write zip");
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(patchesPath);
|
||||
controller?.Update($"Extracting", 40);
|
||||
controller?.Update("Extracting", 40);
|
||||
ZipFile.ExtractToDirectory(archivePath, patchesPath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await controller.Fail(ex.Message, "Failed to extract");
|
||||
await controller!.Fail(ex.Message, "Failed to extract");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
controller?.Update("Extracting", 50);
|
||||
if (Path.Exists(patchesPath))
|
||||
{
|
||||
DirectoryInfo patchesDir = new(patchesPath);
|
||||
|
||||
FileInfo[] patchFiles = patchesDir.GetFiles("*.dll");
|
||||
float progressPerFile = (90 - 50) / (float)patchFiles.Length;
|
||||
DirectoryInfo packageDir = new(installPath);
|
||||
|
||||
foreach (FileInfo file in patchFiles)
|
||||
{
|
||||
int progress = (int)Math.Round(50 + progressPerFile * Array.IndexOf(patchFiles, file));
|
||||
|
||||
controller?.Update($"Copying {file.Name}", progress);
|
||||
FileInfo oldFile = packageDir.GetFiles("*.dll").FirstOrDefault(f => f.Name == file.Name);
|
||||
if (oldFile != null)
|
||||
{
|
||||
Logger.WriteInformation($"Backing up old {oldFile.Name}");
|
||||
string dllBackup = Path.Combine(installPath, "WDDllBackup", curDate);
|
||||
if (!Path.Exists(dllBackup))
|
||||
Directory.CreateDirectory(dllBackup);
|
||||
|
||||
try
|
||||
{
|
||||
File.Move(oldFile.FullName, Path.Combine(dllBackup, oldFile.Name));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await controller.Fail(e.Message, "Failed to move backed-up file " + oldFile.Name);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!package.OriginalDlls.Contains(Path.Combine(dllBackup, oldFile.Name)))
|
||||
package.OriginalDlls.Add(Path.Combine(dllBackup, oldFile.Name));
|
||||
}
|
||||
|
||||
string patchPath = Path.Combine(installPath, file.Name);
|
||||
if (Path.Exists(Path.Combine(installPath, file.Name)))
|
||||
File.Delete(Path.Combine(installPath, file.Name));
|
||||
|
||||
try
|
||||
{
|
||||
File.Copy(file.FullName, Path.Combine(installPath, file.Name));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await controller.Fail(e.Message, "Failed to copy file " + file.Name);
|
||||
return false;
|
||||
}
|
||||
|
||||
Logger.WriteInformation($"Added {file.Name}");
|
||||
|
||||
if (!package.PatchedDlls.Contains(patchPath))
|
||||
package.PatchedDlls.Add(patchPath);
|
||||
}
|
||||
}
|
||||
else
|
||||
if (!Path.Exists(patchesPath))
|
||||
{
|
||||
Logger.WriteError("How did this happen???? patchDir should exist.");
|
||||
return false;
|
||||
}
|
||||
|
||||
controller?.Update($"Writing patch txt", 93);
|
||||
DirectoryInfo patchesDir = new(patchesPath);
|
||||
|
||||
FileInfo[] patchFiles = patchesDir.GetFiles("*.dll");
|
||||
float progressPerFile = (90 - 50) / (float)patchFiles.Length;
|
||||
DirectoryInfo packageDir = new(installPath);
|
||||
|
||||
foreach (FileInfo file in patchFiles)
|
||||
{
|
||||
int progress = (int)Math.Round(50 + progressPerFile * Array.IndexOf(patchFiles, file));
|
||||
|
||||
controller?.Update($"Copying {file.Name}", progress);
|
||||
FileInfo oldFile = packageDir.GetFiles("*.dll").FirstOrDefault(f => f.Name == file.Name);
|
||||
if (oldFile != null)
|
||||
{
|
||||
Logger.WriteInformation($"Backing up old {oldFile.Name}");
|
||||
string dllBackup = Path.Combine(installPath, "WDDllBackup", curDate);
|
||||
if (!Path.Exists(dllBackup))
|
||||
Directory.CreateDirectory(dllBackup);
|
||||
|
||||
try
|
||||
{
|
||||
File.Move(oldFile.FullName, Path.Combine(dllBackup, oldFile.Name));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await controller!.Fail(e.Message, "Failed to move backed-up file " + oldFile.Name);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!package.OriginalDlls.Contains(Path.Combine(dllBackup, oldFile.Name)))
|
||||
package.OriginalDlls.Add(Path.Combine(dllBackup, oldFile.Name));
|
||||
}
|
||||
|
||||
string patchPath = Path.Combine(installPath, file.Name);
|
||||
if (Path.Exists(Path.Combine(installPath, file.Name)))
|
||||
File.Delete(Path.Combine(installPath, file.Name));
|
||||
|
||||
try
|
||||
{
|
||||
File.Copy(file.FullName, Path.Combine(installPath, file.Name));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await controller!.Fail(e.Message, "Failed to copy file " + file.Name);
|
||||
return false;
|
||||
}
|
||||
|
||||
Logger.WriteInformation($"Added {file.Name}");
|
||||
|
||||
if (!package.PatchedDlls.Contains(patchPath))
|
||||
package.PatchedDlls.Add(patchPath);
|
||||
}
|
||||
|
||||
controller?.Update("Writing patch txt", 93);
|
||||
StringBuilder builder = new();
|
||||
builder.AppendLine($"# This package was patched by WinDurango.UI with WinDurango release \"{relName}\".");
|
||||
builder.AppendLine("# If you want to unpatch manually, delete this file and edit %appdata%\\WinDurango\\UI\\InstalledPackages.json and set IsPatched to false.");
|
||||
builder.AppendLine(
|
||||
"# If you want to unpatch manually, delete this file and edit %appdata%\\WinDurango\\UI\\InstalledPackages.json and set IsPatched to false.");
|
||||
builder.AppendLine("# Format is ReleaseName;VerPacked");
|
||||
builder.AppendLine($"{relName.Replace(";", "-")};{App.VerPacked}");
|
||||
await File.WriteAllTextAsync(Path.Combine(installPath, "installed.txt"), builder.ToString());
|
||||
|
||||
controller?.Update($"Updating package list", 95);
|
||||
controller?.Update("Updating package list", 95);
|
||||
package.IsPatched = true;
|
||||
App.InstalledPackages.UpdatePackage(package);
|
||||
controller?.Update($"Done!", 100);
|
||||
controller?.Update("Done!", 100);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static async Task<bool> UnpatchPackage(installedPackage package,
|
||||
|
||||
public static Task<bool> UnpatchPackage(installedPackage package,
|
||||
ProgressController controller)
|
||||
{
|
||||
controller?.Update($"Unpatching {package.FamilyName}", 0);
|
||||
@@ -198,7 +200,8 @@ namespace WinDurango.UI.Utils
|
||||
float progressPerRemove = (0 - 50) / (float)package.PatchedDlls.Count;
|
||||
foreach (string dll in dlls)
|
||||
{
|
||||
int progress = (int)Math.Round(50 + progressPerRemove * Array.IndexOf(package.PatchedDlls.ToArray(), dll));
|
||||
int progress =
|
||||
(int)Math.Round(50 + progressPerRemove * Array.IndexOf(package.PatchedDlls.ToArray(), dll));
|
||||
controller?.Update($"Removing {dll}", progress);
|
||||
try
|
||||
{
|
||||
@@ -209,7 +212,7 @@ namespace WinDurango.UI.Utils
|
||||
{
|
||||
Logger.WriteError($"Failed to delete {dll}.");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
float progressPerRevert = (98 - 50) / (float)package.OriginalDlls.Count;
|
||||
foreach (string dll in originalDlls)
|
||||
@@ -225,18 +228,18 @@ namespace WinDurango.UI.Utils
|
||||
{
|
||||
Logger.WriteError($"Failed to copy {dll}.");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
package.IsPatched = false;
|
||||
|
||||
controller?.Update($"Removing patched.txt", 99);
|
||||
controller?.Update("Removing patched.txt", 99);
|
||||
if (Path.Exists(Path.Combine(installPath, "installed.txt")))
|
||||
File.Delete(Path.Combine(installPath, "installed.txt"));
|
||||
|
||||
controller?.Update($"Updating package list", 99);
|
||||
controller?.Update("Updating package list", 99);
|
||||
App.InstalledPackages.UpdatePackage(package);
|
||||
controller?.Update($"Done!", 100);
|
||||
return true;
|
||||
controller?.Update("Done!", 100);
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
// don't wanna use all the api shits lol
|
||||
@@ -252,7 +255,7 @@ namespace WinDurango.UI.Utils
|
||||
{
|
||||
GitHubRelease release = new();
|
||||
|
||||
const string url = $"https://api.github.com/repos/WinDurango/WinDurango/releases";
|
||||
const string url = "https://api.github.com/repos/WinDurango/WinDurango/releases";
|
||||
|
||||
HttpResponseMessage response = await httpClient.GetAsync(url);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace WinDurango.UI.Utils
|
||||
public static List<Package> GetXPackages(List<Package> packages)
|
||||
{
|
||||
// first try implementation and it worked hell yeah
|
||||
List<Package> result = new();
|
||||
List<Package> result = [];
|
||||
foreach (Package package in packages)
|
||||
{
|
||||
string installPath = package.InstalledPath;
|
||||
@@ -67,9 +67,9 @@ namespace WinDurango.UI.Utils
|
||||
continue;
|
||||
|
||||
string manifest;
|
||||
using (var stream = File.OpenRead(manifestPath))
|
||||
using (FileStream stream = File.OpenRead(manifestPath))
|
||||
{
|
||||
var reader = new StreamReader(stream);
|
||||
StreamReader reader = new(stream);
|
||||
manifest = reader.ReadToEnd();
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace WinDurango.UI.Utils
|
||||
XElement osName = prerequisites?.Descendants().FirstOrDefault(e => e.Name.LocalName == "OSName");
|
||||
XElement osPackageDependency = dependencies?.Descendants().FirstOrDefault(e => e.Name.LocalName == "OSPackageDependency");
|
||||
|
||||
if ((osName != null && osName.Value.ToLower() == "era") || (osPackageDependency != null && osPackageDependency.Attribute("Name")?.Value == "Microsoft.GameOs"))
|
||||
if ((osName != null && osName.Value.Equals("era", System.StringComparison.InvariantCultureIgnoreCase)) || (osPackageDependency != null && osPackageDependency.Attribute("Name")?.Value == "Microsoft.GameOs"))
|
||||
{
|
||||
result.Add(package);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user