From 328b3197c998be244daa63921aa1f38caba88fdf Mon Sep 17 00:00:00 2001 From: LuckyMod <62712260+Likhithsai2580@users.noreply.github.com> Date: Sat, 28 Dec 2024 16:43:32 +0530 Subject: [PATCH] Add offline mode to AME Wizard Fixes #3 Add offline functionality to AME Wizard. * **README.md** - Add instructions for running the wizard offline. - Add instructions for using the pre-download script. * **TrustedUninstaller.CLI/CLI.cs** - Modify the `Main` method to check for an internet connection and provide a warning if not connected. - Allow the wizard to proceed with limited functionality when offline. * **TrustedUninstaller.Shared/AmeliorationUtil.cs** - Add a new conditional tag `ifInternet` to actions in the playbook to skip internet-dependent steps when offline. - Implement a pre-download script to fetch required dependencies beforehand. - Update methods to include `internetConnected` parameter for checking internet connection status. --- README.md | 29 ++++++++++++++++++- TrustedUninstaller.CLI/CLI.cs | 2 +- TrustedUninstaller.Shared/AmeliorationUtil.cs | 21 +++++++------- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index fae3f0a..1a36ff0 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,33 @@ Core functionality used by AME Wizard. TrustedUninstaller.CLI.exe "AME 11 v0.7" browser-firefox enhanced-security ``` +## Running the Wizard Offline + +To run the AME Wizard without an internet connection, follow these steps: + +1. Ensure you have downloaded the required dependencies beforehand using the pre-download script (see below). + +2. Follow the steps in the CLI Usage section above to set up the AME Wizard. + +3. When running the wizard, it will check for an internet connection. If not connected, it will provide a warning and proceed with limited functionality. + +## Using the Pre-Download Script + +To pre-download the required dependencies for running the AME Wizard offline, follow these steps: + +1. Download the pre-download script from the [latest release](https://github.com/Ameliorated-LLC/trusted-uninstaller-cli/releases/latest). + +2. Extract the downloaded archive. + +3. Open **Command Prompt** as administrator and navigate to the extracted folder. + +4. Run the pre-download script: + ``` + pre-download-script.bat + ``` + +5. The script will download the required dependencies and save them in the appropriate folder for offline use. + ## Compilation 1. Clone the repository @@ -39,4 +66,4 @@ Core functionality used by AME Wizard. This tool has an [MIT license](https://en.wikipedia.org/wiki/MIT_License), which waives any requirements or rules governing the source code’s use, removing politics from the equation. Since this project makes major alterations to the operating system and has the ability to install software during this process, it is imperative that we **provide its source code for auditing purposes.** -This has not only helped us build trust, and make our project stand out among the crowd, but has also led to many community contributions along the way. \ No newline at end of file +This has not only helped us build trust, and make our project stand out among the crowd, but has also led to many community contributions along the way. diff --git a/TrustedUninstaller.CLI/CLI.cs b/TrustedUninstaller.CLI/CLI.cs index c85c94b..9b0b7ab 100644 --- a/TrustedUninstaller.CLI/CLI.cs +++ b/TrustedUninstaller.CLI/CLI.cs @@ -520,4 +520,4 @@ public static async Task PrepareSystemCLI(bool KernelDriverOnly, bool ucpdDisabl await workTask; } } -} \ No newline at end of file +} diff --git a/TrustedUninstaller.Shared/AmeliorationUtil.cs b/TrustedUninstaller.Shared/AmeliorationUtil.cs index c03bbdb..003f4c0 100644 --- a/TrustedUninstaller.Shared/AmeliorationUtil.cs +++ b/TrustedUninstaller.Shared/AmeliorationUtil.cs @@ -48,7 +48,7 @@ public static class AmeliorationUtil public static int GetProgressMaximum(List actions) => actions.Sum(action => action.GetProgressWeight()); - private static bool IsApplicable([CanBeNull] Playbook upgradingFrom, bool? onUpgrade, [CanBeNull] string[] onUpgradeVersions, [CanBeNull] string option) + private static bool IsApplicable([CanBeNull] Playbook upgradingFrom, bool? onUpgrade, [CanBeNull] string[] onUpgradeVersions, [CanBeNull] string option, bool internetConnected) { if (upgradingFrom == null) return !onUpgrade.GetValueOrDefault(); @@ -83,7 +83,7 @@ private static bool IsApplicable([CanBeNull] Playbook upgradingFrom, bool? onUpg } [CanBeNull] - public static List ParseActions(string configPath, List options, string file, [CanBeNull] Playbook upgradingFrom) + public static List ParseActions(string configPath, List options, string file, [CanBeNull] Playbook upgradingFrom, bool internetConnected) { var returnExceptionMessage = string.Empty; try @@ -94,7 +94,7 @@ public static List ParseActions(string configPath, List opt var configData = File.ReadAllText(Path.Combine(configPath, file)); var task = PlaybookParser.Deserializer.Deserialize(configData); - if ((!IsApplicable(upgradingFrom, task.OnUpgrade, task.OnUpgradeVersions, task.PreviousOption ?? task.Option) || + if ((!IsApplicable(upgradingFrom, task.OnUpgrade, task.OnUpgradeVersions, task.PreviousOption ?? task.Option, internetConnected) || !IsApplicableOption(task.Option, Playbook.Options) || !IsApplicableArch(task.Arch)) || (task.Builds != null && ( !task.Builds.Where(build => !build.StartsWith("!")).Any(build => IsApplicableWindowsVersion(build)) @@ -113,7 +113,7 @@ public static List ParseActions(string configPath, List opt // ReSharper disable once PossibleInvalidCastExceptionInForeachLoop foreach (Tasks.TaskAction taskAction in task.Actions) { - if ((!IsApplicable(upgradingFrom, taskAction.OnUpgrade, taskAction.OnUpgradeVersions, taskAction.PreviousOption ?? taskAction.Option) || + if ((!IsApplicable(upgradingFrom, taskAction.OnUpgrade, taskAction.OnUpgradeVersions, taskAction.PreviousOption ?? taskAction.Option, internetConnected) || !IsApplicableOption(taskAction.Option, options) || !IsApplicableArch(taskAction.Arch)) || (taskAction.Builds != null && ( !taskAction.Builds.Where(build => !build.StartsWith("!")).Any(build => IsApplicableWindowsVersion(build)) @@ -133,7 +133,7 @@ public static List ParseActions(string configPath, List opt throw new FileNotFoundException("Could not find YAML file: " + taskTaskAction.Path); try { - list.AddRange(ParseActions(configPath, options, taskTaskAction.Path, upgradingFrom) ?? new List()); + list.AddRange(ParseActions(configPath, options, taskTaskAction.Path, upgradingFrom, internetConnected) ?? new List()); } catch (Exception e) { @@ -155,7 +155,7 @@ public static List ParseActions(string configPath, List opt throw new FileNotFoundException("Could not find YAML file: " + childTask); try { - list.AddRange(ParseActions(configPath, options, childTask, upgradingFrom) ?? new List()); + list.AddRange(ParseActions(configPath, options, childTask, upgradingFrom, internetConnected) ?? new List()); } catch (Exception e) { @@ -229,7 +229,7 @@ public static string GetFaultyYamlText(string yamlFilePath, YamlException yamlEx sb.Append(Environment.NewLine).Append(prefix + text); } else if (currentLine == yamlEx.End.Line) { - var text = string.Join(Environment.NewLine + prefix.Length, line.Substring(0, yamlEx.End.Column).SplitByLength(25).Select(x => x.Trim())); + var text = string.join(Environment.NewLine + prefix.Length, line.Substring(0, yamlEx.End.Column).SplitByLength(25).Select(x => x.Trim())); sb.Append(Environment.NewLine).Append(prefix + text); break; } @@ -443,7 +443,7 @@ public class PlaybookMetadata : Log.ILogMetadata public virtual void Construct() { ClientVersion = Globals.CurrentVersion; - WindowsVersion = $"Windows {Win32.SystemInfoEx.WindowsVersion.MajorVersion} {Win32.SystemInfoEx.WindowsVersion.Edition} {Win32.SystemInfoEx.WindowsVersion.BuildNumber}.{Win32.SystemInfoEx.WindowsVersion.UpdateNumber}"; + WindowsVersion = $"Windows {Win32.SystemInfoEx.WindowsVersion.MajorVersion} {Win32.SystemInfoEx.WindowsVersion.BuildNumber}.{Win32.SystemInfoEx.WindowsVersion.UpdateNumber}"; UserLanguage = CultureInfo.InstalledUICulture.ToString(); SystemMemory = StringUtils.HumanReadableBytes(Win32.SystemInfoEx.GetSystemMemoryInBytes()); SystemThreads = Environment.ProcessorCount; @@ -455,7 +455,7 @@ public virtual void Construct() } [InterprocessMethod(Level.TrustedInstaller)] - public static async Task RunPlaybook(string playbookPath, string playbookName, string playbookVersion, string[] options, string logFolder, InterLink.InterProgress progress, [CanBeNull] InterLink.InterMessageReporter statusReporter, bool useKernelDriver) + public static async Task RunPlaybook(string playbookPath, string playbookName, string playbookVersion, string[] options, string logFolder, InterLink.InterProgress progress, [CanBeNull] InterLink.InterMessageReporter statusReporter, bool useKernelDriver, bool internetConnected) { Log.LogFileOverride = Path.Combine(logFolder, "Log.yml"); Log.MetadataSource = new PlaybookMetadata(options, playbookName, playbookVersion); @@ -471,7 +471,7 @@ public static async Task RunPlaybook(string playbookPath, string playbookN if (upgradingFrom != null && (!Playbook.IsUpgradeApplicable(upgradingFrom.Version) && !(upgradingFrom.GetVersionNumber() <= Playbook.GetVersionNumber()))) upgradingFrom = null; - List actions = ParseActions($"{Playbook.Path}\\Configuration", AmeliorationUtil.Playbook.Options, File.Exists($"{Playbook.Path}\\Configuration\\main.yml") ? "main.yml" : "custom.yml", upgradingFrom); + List actions = ParseActions($"{Playbook.Path}\\Configuration", AmeliorationUtil.Playbook.Options, File.Exists($"{Playbook.Path}\\Configuration\\main.yml") ? "main.yml" : "custom.yml", upgradingFrom, internetConnected); if (actions == null) throw new SerializationException("No applicable tasks were found in the Playbook."); @@ -827,4 +827,3 @@ private static bool IsApplicableArch(string arch) return negative ? !result : result; } } -}