-
Notifications
You must be signed in to change notification settings - Fork 36
Refactor InstallPageViewModel and add CLI installer #590
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
Open
SticksDev
wants to merge
8
commits into
wpilibsuite:main
Choose a base branch
from
SticksDev:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8356dc5
refactor to service based installs and add cli support
SticksDev 4864909
add installmode and help
SticksDev 040a489
InstallerFileUtils logging
SticksDev 8ba212a
add vscode offline support
SticksDev 61c0ed6
change output type from WinExe to Exe in project file to allow window…
SticksDev ebbabb1
refactor: use targets to split gui, cli, and common out.
SticksDev 91f6862
chore: format
SticksDev d4139f2
fix: don't ignore build files out of build dir
SticksDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
WPILibInstaller-Avalonia/Interfaces/IArchiveExtractionService.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using WPILibInstaller.Models; | ||
|
|
||
| namespace WPILibInstaller.Interfaces | ||
| { | ||
| public interface IArchiveExtractionService | ||
| { | ||
| Task ExtractArchive(CancellationToken token, string[]? filter, IProgress<InstallProgress>? progress = null); | ||
| Task ExtractJDKAndTools(CancellationToken token, IProgress<InstallProgress>? progress = null); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace WPILibInstaller.Interfaces | ||
| { | ||
| public interface IShortcutService | ||
| { | ||
| Task RunShortcutCreator(CancellationToken token); | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
WPILibInstaller-Avalonia/Interfaces/IToolInstallationService.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| using System; | ||
| using System.Threading.Tasks; | ||
| using WPILibInstaller.Models; | ||
|
|
||
| namespace WPILibInstaller.Interfaces | ||
| { | ||
| public interface IToolInstallationService | ||
| { | ||
| Task RunGradleSetup(IProgress<InstallProgress>? progress = null); | ||
| Task RunToolSetup(IProgress<InstallProgress>? progress = null); | ||
| Task RunCppSetup(IProgress<InstallProgress>? progress = null); | ||
| Task RunMavenMetaDataFixer(IProgress<InstallProgress>? progress = null); | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
WPILibInstaller-Avalonia/Interfaces/IVsCodeInstallationService.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using WPILibInstaller.Models; | ||
|
|
||
| namespace WPILibInstaller.Interfaces | ||
| { | ||
| public interface IVsCodeInstallationService | ||
| { | ||
| Task RunVsCodeSetup(CancellationToken token, IProgress<InstallProgress>? progress = null); | ||
| Task ConfigureVsCodeSettings(); | ||
| Task RunVsCodeExtensionsSetup(IProgress<InstallProgress>? progress = null); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| namespace WPILibInstaller.Models | ||
| { | ||
| /// <summary> | ||
| /// Represents the progress of an installation process, including the percentage completed and a status message. | ||
| /// </summary> | ||
| /// <param name="Percentage">The percentage of the installation that has been completed.</param> | ||
| /// <param name="StatusText">A message describing the current status of the installation.</param> | ||
| public record InstallProgress(int Percentage, string StatusText); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletions
167
WPILibInstaller-Avalonia/Services/ArchiveExtractionService.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| using System; | ||
| using System.Diagnostics; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using MsBox.Avalonia; | ||
| using MsBox.Avalonia.Dto; | ||
| using WPILibInstaller.Interfaces; | ||
| using WPILibInstaller.Models; | ||
|
|
||
|
|
||
| namespace WPILibInstaller.Services | ||
| { | ||
| public class ArchiveExtractionService : IArchiveExtractionService | ||
| { | ||
| private readonly IConfigurationProvider configurationProvider; | ||
| private readonly IProgramWindow programWindow; | ||
|
|
||
| public ArchiveExtractionService(IConfigurationProvider configurationProvider, IProgramWindow programWindow) | ||
| { | ||
| this.configurationProvider = configurationProvider; | ||
| this.programWindow = programWindow; | ||
| } | ||
|
|
||
| public async Task ExtractJDKAndTools(CancellationToken token, IProgress<InstallProgress>? progress = null) | ||
| { | ||
| await ExtractArchive(token, new[] { | ||
| configurationProvider.JdkConfig.Folder + "/", | ||
| configurationProvider.UpgradeConfig.Tools.Folder + "/", | ||
| configurationProvider.AdvantageScopeConfig.Folder + "/", | ||
| configurationProvider.ElasticConfig.Folder + "/", | ||
| "installUtils/", "icons"}, progress); | ||
| } | ||
|
|
||
| public async Task ExtractArchive(CancellationToken token, string[]? filter, IProgress<InstallProgress>? progress = null) | ||
| { | ||
| progress?.Report(new InstallProgress(0, "Starting extraction")); | ||
|
|
||
| if (OperatingSystem.IsWindows()) | ||
| { | ||
| progress?.Report(new InstallProgress(0, "Checking for currently running JDKs")); | ||
| bool foundRunningExe = await Task.Run(() => | ||
| { | ||
| try | ||
| { | ||
| var jdkBinFolder = Path.Join(configurationProvider.InstallDirectory, configurationProvider.JdkConfig.Folder, "bin"); | ||
| var jdkExes = Directory.EnumerateFiles(jdkBinFolder, "*.exe", SearchOption.AllDirectories); | ||
| bool found = false; | ||
| foreach (var exe in jdkExes) | ||
| { | ||
| try | ||
| { | ||
| var name = Path.GetFileNameWithoutExtension(exe)!; | ||
| var pNames = Process.GetProcessesByName(name); | ||
| foreach (var p in pNames) | ||
| { | ||
| if (p.MainModule?.FileName == exe) | ||
| { | ||
| found = true; | ||
| break; | ||
| } | ||
| } | ||
| if (found) | ||
| { | ||
| break; | ||
| } | ||
| } | ||
| catch | ||
| { | ||
| // Do nothing. We don't want this code to break. | ||
| } | ||
| } | ||
| return found; | ||
| } | ||
| catch | ||
| { | ||
| // Do nothing. We don't want this code to break. | ||
| return false; | ||
| } | ||
| }); | ||
| if (foundRunningExe) | ||
| { | ||
| string msg = "Running JDK processes have been found. Installation cannot continue. Please restart your computer, and rerun this installer without running anything else (including VS Code)"; | ||
| await MessageBoxManager.GetMessageBoxStandard(new MessageBoxStandardParams | ||
| { | ||
| ContentTitle = "JDKs Running", | ||
| ContentMessage = msg, | ||
| Icon = MsBox.Avalonia.Enums.Icon.Error, | ||
| ButtonDefinitions = MsBox.Avalonia.Enums.ButtonEnum.Ok | ||
| }).ShowWindowDialogAsync(programWindow.Window); | ||
| throw new InvalidOperationException(msg); | ||
| } | ||
| } | ||
|
|
||
| var archive = configurationProvider.ZipArchive; | ||
|
|
||
| var extractor = archive; | ||
|
|
||
| double totalSize = extractor.TotalUncompressSize; | ||
| long currentSize = 0; | ||
|
|
||
| string intoPath = configurationProvider.InstallDirectory; | ||
|
|
||
| while (extractor.MoveToNextEntry()) | ||
| { | ||
| if (token.IsCancellationRequested) | ||
| { | ||
| return; | ||
| } | ||
| currentSize += extractor.EntrySize; | ||
| if (extractor.EntryIsDirectory) continue; | ||
|
|
||
| var entryName = extractor.EntryKey; | ||
| if (filter != null) | ||
| { | ||
| bool skip = true; | ||
| foreach (var keep in filter) | ||
| { | ||
| if (entryName.StartsWith(keep)) | ||
| { | ||
| skip = false; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (skip) | ||
| { | ||
| continue; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| double currentPercentage = (currentSize / totalSize) * 100; | ||
| if (currentPercentage > 100) currentPercentage = 100; | ||
| if (currentPercentage < 0) currentPercentage = 0; | ||
|
|
||
| progress?.Report(new InstallProgress((int)currentPercentage, "Installing " + entryName)); | ||
|
|
||
| string fullZipToPath = Path.Combine(intoPath, entryName); | ||
| string? directoryName = Path.GetDirectoryName(fullZipToPath); | ||
| if (directoryName?.Length > 0) | ||
| { | ||
| try | ||
| { | ||
| Directory.CreateDirectory(directoryName); | ||
| } | ||
| catch (IOException) | ||
| { | ||
|
|
||
| } | ||
| } | ||
|
|
||
| { | ||
| using FileStream writer = File.Create(fullZipToPath); | ||
| await extractor.CopyToStreamAsync(writer); | ||
| } | ||
|
|
||
| if (extractor.EntryIsExecutable && !OperatingSystem.IsWindows()) | ||
| { | ||
| var currentMode = File.GetUnixFileMode(fullZipToPath); | ||
| File.SetUnixFileMode(fullZipToPath, currentMode | UnixFileMode.GroupExecute | UnixFileMode.UserExecute | UnixFileMode.OtherExecute); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.