Skip to content

Commit

Permalink
simplify 7zip logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rounk-ctrl committed Sep 17, 2023
1 parent 8291dec commit 4e24953
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 60 deletions.
26 changes: 25 additions & 1 deletion Rectify11Installer/Core/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using KPreisser.UI;
using Microsoft.VisualBasic;
using Microsoft.Win32;
using Rectify11Installer.Pages;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Text;

Expand All @@ -27,7 +29,28 @@ public static bool CheckIfUpdatesPending()
icon: TaskDialogStandardIcon.SecurityErrorRedBar);
return false;
}

public static bool SvExtract(string file, string path)
{
Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.exe") +
" x -o" + Path.Combine(Variables.r11Folder, path) +
" " + Path.Combine(Variables.r11Folder, file), AppWinStyle.Hide, true);
return true;
}
public static bool SvExtract(string file, string path, string folder)
{
Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.exe") +
" x -y " + Path.Combine(Variables.r11Folder, file)
+ " -o\"" + Path.Combine(Variables.r11Folder, path) + "\""
+ " "+ folder, AppWinStyle.Hide, true);
return true;
}
public static bool SvExtract(bool isf, string file, string exe)
{
Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.exe") +
" e -o" + Variables.r11Folder + " "
+ Path.Combine(Variables.r11Folder, file) + " "+exe, AppWinStyle.Hide, true);
return true;
}
public static StringBuilder FinalText()
{
System.ComponentModel.ComponentResourceManager resources = new SingleAssemblyComponentResourceManager(typeof(Strings.Rectify11));
Expand Down Expand Up @@ -83,6 +106,7 @@ public static StringBuilder FinalText()
}
return ok;
}

#endregion
#region Private Methods
private static bool RebootRequired()
Expand Down
106 changes: 48 additions & 58 deletions Rectify11Installer/Core/Installer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ private enum PatchType
#region Public Methods
public async Task<bool> Install(FrmWizard frm)
{
Logger.WriteLine("Preparing Installation");
Logger.WriteLine("──────────────────────");

if (!Directory.Exists(Variables.r11Folder))
{
Directory.CreateDirectory(Variables.r11Folder);
}

Logger.WriteLine("Preparing Installation");
Logger.WriteLine("──────────────────────");

// goofy fix
using var reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE", true)?.CreateSubKey("Rectify11", true);
reg.DeleteValue("x86PendingFiles", false);
Expand Down Expand Up @@ -135,9 +136,10 @@ public async Task<bool> Install(FrmWizard frm)
Logger.WriteLine("Deleting " + Path.Combine(Variables.r11Folder, "themes") + " failed. ", ex);
}
}
await Task.Run(() => Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.exe") +
" x -o" + Path.Combine(Variables.r11Folder, "themes") +
" " + Path.Combine(Variables.r11Folder, "themes.7z"), AppWinStyle.Hide, true));

// extract the 7z
await Task.Run(() => Helper.SvExtract("themes.7z", "themes"));

Logger.WriteLine("Extracted themes.7z");
if (!await Task.Run(() => InstallThemes()))
{
Expand Down Expand Up @@ -213,33 +215,26 @@ await Task.Run(() => Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.ex
}
}
Directory.CreateDirectory(Path.Combine(Variables.r11Folder, "extras"));
/*
await Task.Run(() => Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.exe") +
" x -o" + Path.Combine(Variables.r11Folder, "extras") +
" " + Path.Combine(Variables.r11Folder, "extras.7z"), AppWinStyle.Hide, true));
*/

Logger.WriteLine("Extracted extras.7z");

if (InstallOptions.InstallWallpaper)
{
frm.InstallerProgress = "Installing extras: Wallpapers";

if (Directory.Exists(Path.Combine(Variables.r11Folder, "extras", "wallpapers")))
string path = Path.Combine(Variables.r11Folder, "extras", "wallpapers");
if (Directory.Exists(path))
{
Directory.Delete(Path.Combine(Variables.r11Folder, "extras", "wallpapers"), true);
Directory.Delete(path, true);
}
await Task.Run(() => Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.exe") +
" x -y " + Path.Combine(Variables.r11Folder, "extras.7z")
+ " -o\"" + Path.Combine(Variables.r11Folder, "extras") + "\""
+ " wallpapers", AppWinStyle.Hide, true));

// extract the 7z
await Task.Run(() => Helper.SvExtract("extras.7z", "extras", "wallpapers"));

if (!await Task.Run(() => InstallWallpapers()))
{
Logger.WriteLine("InstallWallpapers() failed.");
return false;
}
Logger.WriteLine("InstallWallpapers() succeeded.");
Directory.Delete(Path.Combine(Variables.r11Folder, "extras", "wallpapers"), true);
Directory.Delete(path, true);
}
if (InstallOptions.InstallASDF)
{
Expand All @@ -249,26 +244,28 @@ await Task.Run(() => Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.ex
await Task.Run(() => Interaction.Shell(Path.Combine(Variables.sys32Folder, "taskkill.exe") + " /f /im AccentColorizer.exe", AppWinStyle.Hide, true));
await Task.Run(() => Interaction.Shell(Path.Combine(Variables.sys32Folder, "taskkill.exe") + " /f /im AccentColorizerEleven.exe", AppWinStyle.Hide, true));
await Task.Run(() => Interaction.Shell(Path.Combine(Variables.sys32Folder, "schtasks.exe") + " /delete /f /tn asdf", AppWinStyle.Hide));
if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), "programs", "startup", "asdf.lnk")))
string path = Path.Combine(GetFolderPath(SpecialFolder.CommonStartMenu), "programs", "startup", "asdf.lnk");
if (File.Exists(path))
{
try
{
File.Delete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), "programs", "startup", "asdf.lnk"));
File.Delete(path);
}
catch
{
File.Move(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), "programs", "startup", "asdf.lnk"), Path.Combine(Path.GetTempPath(), Path.GetTempFileName()));
File.Move(path, Path.Combine(Path.GetTempPath(), Path.GetTempFileName()));
}
}
if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), "programs", "startup", "asdf11.lnk")))
path = Path.Combine(GetFolderPath(SpecialFolder.CommonStartMenu), "programs", "startup", "asdf11.lnk");
if (File.Exists(path))
{
try
{
File.Delete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), "programs", "startup", "asdf11.lnk"));
File.Delete(path);
}
catch
{
File.Move(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), "programs", "startup", "asdf11.lnk"), Path.Combine(Path.GetTempPath(), Path.GetTempFileName()));
File.Move(path, Path.Combine(Path.GetTempPath(), Path.GetTempFileName()));
}
}
try
Expand All @@ -287,10 +284,10 @@ await Task.Run(() => Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.ex
MoveFileEx(Path.Combine(Path.GetTempPath(), name), null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
}
}
await Task.Run(() => Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.exe") +
" x -y " + Path.Combine(Variables.r11Folder, "extras.7z")
+ " -o\"" + Path.Combine(Variables.r11Folder, "extras") + "\""
+ " AccentColorizer", AppWinStyle.Hide, true));

// extract the 7z
await Task.Run(() => Helper.SvExtract("extras.7z", "extras", "AccentColorizer"));

await Task.Run(() => Installasdf());
Logger.WriteLine("Installasdf() succeeded.");
if (!Variables.RestartRequired)
Expand All @@ -306,26 +303,22 @@ await Task.Run(() => Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.ex
{
Directory.Delete(Path.Combine(Variables.r11Folder, "extras", "GadgetPack"), true);
}
await Task.Run(() => Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.exe") +
" x -y " + Path.Combine(Variables.r11Folder, "extras.7z")
+ " -o\"" + Path.Combine(Variables.r11Folder, "extras") + "\""
+ " GadgetPack", AppWinStyle.Hide, true));

// extract the 7z
await Task.Run(() => Helper.SvExtract("extras.7z", "extras", "GadgetPack"));

await Task.Run(() => InstallGadgets());
Logger.WriteLine("InstallGadgets() succeeded.");
Directory.Delete(Path.Combine(Variables.r11Folder, "extras", "GadgetPack"), true);
}
if (InstallOptions.InstallShell)
{
frm.InstallerProgress = "Installing extras: Enhanced context menu";
await Task.Run(() => Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.exe") +
" x -y " + Path.Combine(Variables.r11Folder, "extras.7z")
+ " -o\"" + Path.Combine(Variables.r11Folder, "extras") + "\""
+ " Nilesoft", AppWinStyle.Hide, true));

await Task.Run(() => Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.exe") +
" x -y " + Path.Combine(Variables.r11Folder, "extras.7z")
+ " -o\"" + Path.Combine(Variables.r11Folder, "extras") + "\""
+ " NilesoftArm64", AppWinStyle.Hide, true));

// extract the 7z
await Task.Run(() => Helper.SvExtract("extras.7z", "extras", "Nilesoft"));
await Task.Run(() => Helper.SvExtract("extras.7z", "extras", "NilesoftArm64"));

await Task.Run(InstallShell);
Logger.WriteLine("InstallShell() succeeded.");
try
Expand All @@ -346,10 +339,10 @@ await Task.Run(() => Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.ex
{
Directory.Delete(Path.Combine(Variables.r11Folder, "extras", "userAV"), true);
}
await Task.Run(() => Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.exe") +
" x -y " + Path.Combine(Variables.r11Folder, "extras.7z")
+ " -o\"" + Path.Combine(Variables.r11Folder, "extras") + "\""
+ " userAV", AppWinStyle.Hide, true));

// extract the 7z
await Task.Run(() => Helper.SvExtract("extras.7z", "extras", "userAV"));

await Task.Run(() => InstallUserAvatars());
Logger.WriteLine("InstallUserAvatars() succeeded.");
Directory.Delete(Path.Combine(Variables.r11Folder, "extras", "userAV"), true);
Expand Down Expand Up @@ -394,9 +387,9 @@ await Task.Run(() => Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.ex
LogFile("files.7z", true, ex);
return false;
}
await Task.Run(() => Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.exe") +
" x -o" + Path.Combine(Variables.r11Folder, "files") +
" " + Path.Combine(Variables.r11Folder, "files.7z"), AppWinStyle.Hide, true));

// extract the 7z
await Task.Run(() => Helper.SvExtract("files.7z", "files"));
Logger.WriteLine("Extracted files.7z");

// Get all patches
Expand Down Expand Up @@ -752,13 +745,13 @@ private void Installasdf()
shortcut.Target = Path.Combine(Variables.r11Folder, "extras", "AccentColorizer", "AccentColorizer.exe");
shortcut.WorkingDirectory = @"%windir%\Rectify11\extras\AccentColorizer";
shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal;
shortcut.Save(Path.Combine(GetFolderPath(SpecialFolder.CommonStartMenu), "programs", "startup", "asdf.lnk"));
shortcut.Save(Path.Combine(GetFolderPath(SpecialFolder.CommonStartMenu), "programs", "startup", "Accentcolorizer.lnk"));

using ShellLink asdf11 = new();
asdf11.DisplayMode = ShellLink.LinkDisplayMode.edmNormal;
asdf11.WorkingDirectory = @"%windir%\Rectify11\extras\AccentColorizer";
asdf11.Target = Path.Combine(Variables.r11Folder, "extras", "AccentColorizer", "AccentColorizerEleven.exe");
asdf11.Save(Path.Combine(GetFolderPath(SpecialFolder.CommonStartMenu), "programs", "startup", "asdf11.lnk"));
asdf11.Save(Path.Combine(GetFolderPath(SpecialFolder.CommonStartMenu), "programs", "startup", "Accentcolorizer11.lnk"));
}

/// <summary>
Expand Down Expand Up @@ -1214,16 +1207,13 @@ private bool InstallRuntimes()
if (!File.Exists(Path.Combine(Variables.r11Folder, "vcredist.exe")))
{
Logger.WriteLine("Extracting vcredist.exe from extras.7z");
Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.exe") +
" e -o" + Variables.r11Folder + " "
+ Path.Combine(Variables.r11Folder, "extras.7z") + " vcredist.exe", AppWinStyle.Hide, true);
Helper.SvExtract(true, "extras.7z", "vcredist.exe");
}
if (!File.Exists(Path.Combine(Variables.r11Folder, "core31.exe")))
{
Logger.WriteLine("Extracting core31.exe from extras.7z");
Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.exe") +
" e -o" + Variables.r11Folder + " " + Path.Combine(Variables.r11Folder, "extras.7z") +
" core31.exe", AppWinStyle.Hide, true);
Helper.SvExtract(true, "extras.7z", "core31.exe");

}
Logger.WriteLine("Executing vcredist.exe with arguments /install /quiet /norestart");
ProcessStartInfo vcinfo = new()
Expand Down
2 changes: 1 addition & 1 deletion Rectify11Installer/Pages/ProgressPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private async void NavigationHelper_OnNavigate(object sender, EventArgs e)
NativeMethods.SetCloseButton(frmwiz, false);
Variables.isInstall = true;
Installer installer = new();
Logger.CommitLog();
//Logger.CommitLog();
if (!await installer.Install(frmwiz))
{
Installer.Cleanup();
Expand Down

0 comments on commit 4e24953

Please sign in to comment.