public Selector(VsCodeConfig config) { this.config = config; InitializeComponent(); progressBar4.Visible = false; progressBar5.Visible = false; this.selectButton.Text += $"\n({VsCodeFiles.GetFileName(config.VsCodeVersion)})"; }
private async void downloadButton_Click(object sender, EventArgs e) { progressBar4.Visible = true; progressBar5.Visible = true; selectButton.Visible = false; downloadButton.Enabled = false; downloadButton.Text = "Downloading"; var origText = label1.Text; label1.Text = "This window will close when\ndownload finishes."; VsCodeFiles vsf = new VsCodeFiles(config); ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; source?.Cancel(); source = new CancellationTokenSource(); string res = null; try { res = await vsf.DownloadAndZipFiles(progressBar4, progressBar5, config.VsCodeVersion, source.Token); } catch (HttpRequestException) { } if (res == null) { MessageBox.Show("Download Failed. Click button to retry"); downloadButton.Enabled = true; downloadButton.Text = "Download"; label1.Text = origText; return; } ZipLocation = res; this.Close(); }
private async void MainForm_Shown(object sender, EventArgs e) { vscodeButton.Enabled = false; vscodeCheck.Enabled = false; vscodeText.Visible = false; vsCodeFileLabel.Visible = false; this.Enabled = false; if (zipStore == null) { if (debugMode) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Select the installer zip"; var res = ofd.ShowDialog(); if (res == DialogResult.OK) { FileStream fs = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read); zipStore = new ZipFile(fs); zipStore.IsStreamOwner = true; closeZip = true; } else { MessageBox.Show("File Error. Please select a zip file."); Application.Exit(); return; } } else { MessageBox.Show("File Error. Try redownloading the file, and if this error continues contact WPILib support."); Application.Exit(); return; } } // Look for upgrade config. Should always be there. var upgradeEntry = zipStore.FindEntry("installUtils/upgradeConfig.json", true); if (upgradeEntry == -1) { // Error MessageBox.Show("File Error?"); Application.Exit(); return; } string upgradeConfigStr = ""; string fullConfigStr = ""; string vsConfigStr = ""; using (StreamReader reader = new StreamReader(zipStore.GetInputStream(upgradeEntry))) { upgradeConfigStr = await reader.ReadToEndAsync(); upgradeConfig = JsonConvert.DeserializeObject <UpgradeConfig>(upgradeConfigStr, new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Error }); extractionControllers.Add(new ExtractionIgnores(toolsCheck, upgradeConfig.Tools.Folder, false)); extractionControllers.Add(new ExtractionIgnores(wpilibCheck, upgradeConfig.Maven.Folder, false)); var osType = OSLoader.GetOsType(); switch (osType) { case OsType.Linux64: if (upgradeConfig.InstallerType != UpgradeConfig.LinuxInstallerType) { MessageBox.Show("You need the Linux installer for this system"); Application.Exit(); return; } isWindows = false; break; case OsType.MacOs64: if (upgradeConfig.InstallerType != UpgradeConfig.MacInstallerType) { MessageBox.Show("You need the Mac installer for this system"); Application.Exit(); return; } isWindows = false; break; case OsType.Windows64: if (upgradeConfig.InstallerType != UpgradeConfig.Windows64InstallerType) { MessageBox.Show("You need the Windows64 installer for this system"); Application.Exit(); return; } isWindows = true; break; case OsType.Windows32: if (upgradeConfig.InstallerType != UpgradeConfig.Windows32InstallerType) { MessageBox.Show("You need the Windows32 installer for this system"); Application.Exit(); return; } isWindows = true; break; default: MessageBox.Show("Unknown OS type?"); Application.Exit(); return; } } // Look for VS Code config. Should always be there. var vsCodeEntry = zipStore.FindEntry("installUtils/vscodeConfig.json", true); if (vsCodeEntry == -1) { // Error MessageBox.Show("File Error?"); Application.Exit(); return; } using (StreamReader reader = new StreamReader(zipStore.GetInputStream(vsCodeEntry))) { vsConfigStr = await reader.ReadToEndAsync(); vsCodeConfig = JsonConvert.DeserializeObject <VsCodeConfig>(vsConfigStr, new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Error }); } vscodeButton.Enabled = true; // Look for full config. Will not be there on upgrade var fullEntry = zipStore.FindEntry("installUtils/fullConfig.json", true); if (fullEntry == -1) { // Disable any full entry things javaCheck.Enabled = false; javaCheck.Checked = false; cppCheck.Enabled = false; cppCheck.Checked = false; } else { using (StreamReader reader = new StreamReader(zipStore.GetInputStream(fullEntry))) { fullConfigStr = await reader.ReadToEndAsync(); fullConfig = JsonConvert.DeserializeObject <FullConfig>(fullConfigStr, new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Error, }); extractionControllers.Add(new ExtractionIgnores(cppCheck, fullConfig.CppToolchain.Directory, false)); extractionControllers.Add(new ExtractionIgnores(gradleCheck, "installUtils/" + fullConfig.Gradle.ZipName, true)); } var jdkEntry = zipStore.FindEntry("installUtils/jdkConfig.json", true); if (jdkEntry == -1) { // Error MessageBox.Show("File Error?"); Application.Exit(); return; } else { using (StreamReader reader = new StreamReader(zipStore.GetInputStream(jdkEntry))) { var jdkConfigStr = await reader.ReadToEndAsync(); var jdkConfig = JsonConvert.DeserializeObject <JdkConfig>(jdkConfigStr, new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Error, }); extractionControllers.Add(new ExtractionIgnores(javaCheck, jdkConfig.Folder, false)); } } } if (isWindows) { var publicFolder = Environment.GetEnvironmentVariable("PUBLIC"); frcHome = Path.Combine(publicFolder, $"frc{upgradeConfig.FrcYear}"); } else { var userFolder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); frcHome = Path.Combine(userFolder, $"frc{upgradeConfig.FrcYear}"); } VSCodeInstall vsi = new VSCodeInstall(Path.Combine(frcHome, "vscode")); if (!vsi.IsInstalled()) { vsCodeWpiExtCheck.Checked = false; vsCodeWpiExtCheck.Enabled = false; } else { vsCodeWpiExtCheck.Checked = true; vsCodeWpiExtCheck.Enabled = true; } this.vsCodeFileLabel.Text = VsCodeFiles.GetFileName(vsCodeConfig.VsCodeVersion); this.performInstallButton.Enabled = true; this.performInstallButton.Visible = true; this.Enabled = true; }