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

Use individual VSCode Zip Files #342

Merged
merged 2 commits into from
Aug 15, 2023
Merged
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
42 changes: 23 additions & 19 deletions WPILibInstaller-Avalonia/ViewModels/VSCodePageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public string SelectText

private string singleDownloadText = "Download for this computer only\n(fastest)";
private string skipVsCodeText = "Skip and don't use VS Code\n(NOT RECOMMENDED)";
private string allDownloadText = "Create VS Code zip to share with\nother computers/OSes for offline\ninstall";
private string selectText = "Select existing VS Code zip for\noffline install on this computer";
private string allDownloadText = "Download VS Code archives to share with\nother computers/OSes for offline\ninstall";
private string selectText = "Select existing VS Code archive for\noffline install on this computer";

public double ProgressBar1
{
Expand Down Expand Up @@ -174,7 +174,18 @@ private async Task SkipVsCodeFunc()

private async Task SelectVsCodeFunc()
{
var file = await programWindow.ShowFilePicker("Select VS Code Installer ZIP", "zip");
var currentPlatform = PlatformUtils.CurrentPlatform;
String extension;

if (currentPlatform == Platform.Linux64)
{
extension = "tar.gz";
}
else
{
extension = "zip";
}
var file = await programWindow.ShowFilePicker("Select VS Code Installer ZIP", extension);
if (file == null)
{
// No need to error, user explicitly canceled.
Expand All @@ -183,19 +194,16 @@ private async Task SelectVsCodeFunc()
try
{
FileStream fs = new FileStream(file, FileMode.Open);
using System.IO.Compression.ZipArchive archive = new System.IO.Compression.ZipArchive(fs);
var currentPlatform = PlatformUtils.CurrentPlatform;
var entry = archive.GetEntry(Model.Platforms[currentPlatform].NameInZip);
MemoryStream ms = new MemoryStream(100000000);
await entry!.Open().CopyToAsync(ms);
await fs.CopyToAsync(ms);
ms.Seek(0, SeekOrigin.Begin);

using var sha = SHA256.Create();
var hash = await sha.ComputeHashAsync(ms);

if (!hash.AsSpan().SequenceEqual(Model.Platforms[currentPlatform].Sha256Hash))
{
bool cont = await CheckIncorrectHash($"VS Code for {currentPlatform}", Convert.ToHexString(Model.Platforms[currentPlatform].Sha256Hash), Convert.ToHexString(hash));
bool cont = await CheckIncorrectHash($"VS Code for {currentPlatform}. File Location {file}", Convert.ToHexString(Model.Platforms[currentPlatform].Sha256Hash), Convert.ToHexString(hash));
if (!cont)
{
throw new InvalidDataException("Invalid hash");
Expand All @@ -216,7 +224,7 @@ private async Task SelectVsCodeFunc()
catch
{
await MessageBoxManager.GetMessageBoxStandardWindow("Error",
"Correct VS Code not found in archive.\nYou must select a VS Code zip downloaded with this tool.",
"You must select a VS Code zip downloaded with this tool.",
icon: MessageBox.Avalonia.Enums.Icon.None).ShowDialog(programWindow.Window);
return;
}
Expand Down Expand Up @@ -263,21 +271,17 @@ private async Task DownloadVsCodeFunc()

var results = await Task.WhenAll(win64, linux64, mac64);

string vscodeFileName = $"WPILib-VSCode-{Model.VSCodeVersion}.zip";

string vscodeName = Path.Join(file, vscodeFileName);

try
{
File.Delete(vscodeName);
File.Delete(Path.Join(file, Model.Platforms[Platform.Win64].NameInZip));
File.Delete(Path.Join(file, Model.Platforms[Platform.Linux64].NameInZip));
File.Delete(Path.Join(file, Model.Platforms[Platform.Mac64].NameInZip));
}
catch
{

}

using var archive = ZipFile.Open(vscodeName, ZipArchiveMode.Create);

MemoryStream? ms = null;

DoneText = "Copying Archives. Please wait.";
Expand All @@ -292,8 +296,7 @@ private async Task DownloadVsCodeFunc()
}
}

var entry = archive.CreateEntry(Model.Platforms[platform].NameInZip);
using var toWriteStream = entry.Open();
using var toWriteStream = new FileStream(Path.Join(file, Model.Platforms[platform].NameInZip), FileMode.OpenOrCreate);
stream.Seek(0, SeekOrigin.Begin);
await stream.CopyToAsync(toWriteStream);
if (platform == currentPlatform)
Expand All @@ -315,7 +318,8 @@ private async Task DownloadVsCodeFunc()
Model.ToExtractArchive = OpenArchive(ms);
}

DoneText = $"Done Downloading. File is named {vscodeFileName} Press Next to continue";
DoneText = "Done Downloading. Press Next to continue";

EnableSelectionButtons = true;
SetLocalForwardVisible(true);
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/vscode.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ apply from: 'scripts/versions.gradle'

def vscodeFile = file("$buildDir/vscodeConfig.json")

def vscodeWindowsZipName = "Windows.zip"
def vscodeLinuxZipName = "Linux.tar.gz"
def vscodeMacZipName = "Mac.zip"
def vscodeWindowsZipName = "VSCode-${vsCodeVersion}-Windows.zip".toString()
def vscodeLinuxZipName = "VSCode-${vsCodeVersion}-Linux.tar.gz".toString()
def vscodeMacZipName = "VSCode-${vsCodeVersion}-Mac.zip".toString()

def vscodeWindowsUrl = "https://update.code.visualstudio.com/${vsCodeVersion}/win32-x64-archive/stable".toString()

Expand Down