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

Add offline mode to AME Wizard #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
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.
2 changes: 1 addition & 1 deletion TrustedUninstaller.CLI/CLI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -520,4 +520,4 @@ public static async Task PrepareSystemCLI(bool KernelDriverOnly, bool ucpdDisabl
await workTask;
}
}
}
}
21 changes: 10 additions & 11 deletions TrustedUninstaller.Shared/AmeliorationUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static class AmeliorationUtil

public static int GetProgressMaximum(List<ITaskAction> 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();
Expand Down Expand Up @@ -83,7 +83,7 @@ private static bool IsApplicable([CanBeNull] Playbook upgradingFrom, bool? onUpg
}

[CanBeNull]
public static List<ITaskAction> ParseActions(string configPath, List<string> options, string file, [CanBeNull] Playbook upgradingFrom)
public static List<ITaskAction> ParseActions(string configPath, List<string> options, string file, [CanBeNull] Playbook upgradingFrom, bool internetConnected)
{
var returnExceptionMessage = string.Empty;
try
Expand All @@ -94,7 +94,7 @@ public static List<ITaskAction> ParseActions(string configPath, List<string> opt
var configData = File.ReadAllText(Path.Combine(configPath, file));
var task = PlaybookParser.Deserializer.Deserialize<UninstallTask>(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))
Expand All @@ -113,7 +113,7 @@ public static List<ITaskAction> ParseActions(string configPath, List<string> 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))
Expand All @@ -133,7 +133,7 @@ public static List<ITaskAction> ParseActions(string configPath, List<string> opt
throw new FileNotFoundException("Could not find YAML file: " + taskTaskAction.Path);
try
{
list.AddRange(ParseActions(configPath, options, taskTaskAction.Path, upgradingFrom) ?? new List<ITaskAction>());
list.AddRange(ParseActions(configPath, options, taskTaskAction.Path, upgradingFrom, internetConnected) ?? new List<ITaskAction>());
}
catch (Exception e)
{
Expand All @@ -155,7 +155,7 @@ public static List<ITaskAction> ParseActions(string configPath, List<string> opt
throw new FileNotFoundException("Could not find YAML file: " + childTask);
try
{
list.AddRange(ParseActions(configPath, options, childTask, upgradingFrom) ?? new List<ITaskAction>());
list.AddRange(ParseActions(configPath, options, childTask, upgradingFrom, internetConnected) ?? new List<ITaskAction>());
}
catch (Exception e)
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -455,7 +455,7 @@ public virtual void Construct()
}

[InterprocessMethod(Level.TrustedInstaller)]
public static async Task<bool> RunPlaybook(string playbookPath, string playbookName, string playbookVersion, string[] options, string logFolder, InterLink.InterProgress progress, [CanBeNull] InterLink.InterMessageReporter statusReporter, bool useKernelDriver)
public static async Task<bool> 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);
Expand All @@ -471,7 +471,7 @@ public static async Task<bool> RunPlaybook(string playbookPath, string playbookN
if (upgradingFrom != null && (!Playbook.IsUpgradeApplicable(upgradingFrom.Version) && !(upgradingFrom.GetVersionNumber() <= Playbook.GetVersionNumber())))
upgradingFrom = null;

List<ITaskAction> actions = ParseActions($"{Playbook.Path}\\Configuration", AmeliorationUtil.Playbook.Options, File.Exists($"{Playbook.Path}\\Configuration\\main.yml") ? "main.yml" : "custom.yml", upgradingFrom);
List<ITaskAction> 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.");

Expand Down Expand Up @@ -827,4 +827,3 @@ private static bool IsApplicableArch(string arch)
return negative ? !result : result;
}
}
}