public static async Task SetupGradle(FullConfig config, string extractFolder) { string gradleZipLoc = Path.Combine(extractFolder, "installUtils", config.Gradle.ZipName); string userFolder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); List <Task> tasks = new List <Task>(); foreach (var extractLocation in config.Gradle.ExtractLocations) { string toFolder = Path.Combine(userFolder, ".gradle", extractLocation, Path.GetFileNameWithoutExtension(config.Gradle.ZipName), config.Gradle.Hash); string toFile = Path.Combine(toFolder, config.Gradle.ZipName); tasks.Add(Task.Factory.StartNew(() => { try { Directory.CreateDirectory(toFolder); } catch (IOException) { } File.Copy(gradleZipLoc, toFile, true); })); } await Task.WhenAll(tasks); }
private void Form1_Load(object sender, EventArgs e) { AppDomain.CurrentDomain.ProcessExit += new EventHandler(AppClosing); if (File.Exists(Application.StartupPath + "\\" + "log.txt")) { File.Delete(Application.StartupPath + "\\" + "log.txt"); } if (File.Exists(Application.StartupPath + "\\" + "exitlog.txt")) { File.Delete(Application.StartupPath + "\\" + "exitlog.txt"); } if (File.Exists(Application.StartupPath + "\\" + "startuplist.txt")) { Char splitter1 = '*'; StreamReader ReadStartup; ReadStartup = new StreamReader(Application.StartupPath + "\\" + "startuplist.txt"); String StartupText; StartupText = ReadStartup.ReadToEnd(); StartupImagesText = StartupText; ReadStartup.Close(); StartupImages = StartupText.Split(splitter1); for (int count = 0; count < StartupImages.Length; count++) { dataGridView2.Rows.Add(StartupImages[count]); } } richTextBox1.AppendText("------------Free Image Mounter------------"); Logs = new StringBuilder(); Logs.Append("------------Free Image Mounter------------"); if (File.Exists(Application.StartupPath + "\\" + "version.txt")) { if (File.Exists(Application.StartupPath + "\\" + "config.ini")) { richTextBox1.AppendText(Environment.NewLine + DateTime.Now + " config.ini is present"); Logs.Append(Environment.NewLine + DateTime.Now + " config.ini is present"); StreamReader ReadConfig; ReadConfig = new StreamReader(Application.StartupPath + "\\" + "config.ini"); String FullConfig; FullConfig = ReadConfig.ReadToEnd(); ReadConfig.Close(); Char Seperation = '&'; split1 = FullConfig.Split(Seperation); Char Seperation2 = ':'; //String[] split2; split2 = split1[0].Split(Seperation2); if (split2[0].Contains("True")) { RunOnStartup = "TRUE"; button4.Text = "Dont run at startup"; } if (split2[0].Contains("False")) { RunOnStartup = "FALSE"; button4.Text = "Run at startup"; } } else { richTextBox1.AppendText(Environment.NewLine + DateTime.Now + " Error: cannot find config.ini"); Logs.Append(Environment.NewLine + DateTime.Now + " Error: cannot find config.ini"); } richTextBox1.AppendText(Environment.NewLine + DateTime.Now + " version.txt is present"); Logs.Append(Environment.NewLine + DateTime.Now + " version.txt is present"); StreamReader CheckVersion; CheckVersion = new StreamReader(Application.StartupPath + "\\" + "version.txt"); String FullFile = CheckVersion.ReadToEnd(); CheckVersion.Close(); richTextBox1.AppendText(Environment.NewLine + DateTime.Now + " Successfully read version.txt"); Logs.Append(Environment.NewLine + DateTime.Now + " Successfully read version.txt"); String[] output1; Char Splitter = ':'; output1 = FullFile.Split(Splitter); CurrentVersion = output1[0]; CurrentVDate = output1[1]; AutoUpdate = output1[2]; LogStatus = output1[3]; if (LogStatus.Contains("true")) { label5.Text = "Logging is currently enabled. The tickbox is to change logging status, regardless of whether it is ticked or not"; richTextBox1.AppendText(Environment.NewLine + DateTime.Now + " Starting to write to log file"); Logs.Append(Environment.NewLine + DateTime.Now + " Starting to write to log file"); timer1.Start(); } else { label5.Text = "Logging is currently disabled. The tickbox is to change logging status, regardless of whether it is ticked or not"; } AutoUpdate.TrimEnd('\r', '\n'); richTextBox1.AppendText(Environment.NewLine + DateTime.Now + " Free Image Mounter v" + CurrentVersion + ", from " + CurrentVDate); Logs.Append(Environment.NewLine + DateTime.Now + " Free Image Mounter v" + CurrentVersion + ", from " + CurrentVDate); //MessageBox.Show(AutoUpdate); if (AutoUpdate.Contains("true")) { richTextBox1.AppendText(Environment.NewLine + DateTime.Now + " Autoupdates enabled"); Logs.Append(Environment.NewLine + DateTime.Now + " Autoupdates enabled"); if (File.Exists(Application.StartupPath + "\\" + "latestversion.txt")) { richTextBox1.AppendText(Environment.NewLine + DateTime.Now + " Found obsolete latestversion.txt"); Logs.Append(Environment.NewLine + DateTime.Now + " Found obsolete latestversion.txt"); File.Delete(Application.StartupPath + "\\" + "latestversion.txt"); richTextBox1.AppendText(Environment.NewLine + DateTime.Now + " Deleted old latestversion.txt"); Logs.Append(Environment.NewLine + DateTime.Now + " Deleted old latestversion.txt"); } // MessageBox.Show("updatesection"); System.Net.NetworkInformation.Ping TestServer = new System.Net.NetworkInformation.Ping(); if (TestServer.Send("89.203.4.93", 300).Status == System.Net.NetworkInformation.IPStatus.Success) { richTextBox1.AppendText(Environment.NewLine + DateTime.Now + " Can successfully ping update server"); Logs.Append(Environment.NewLine + DateTime.Now + " Can successfully ping update server"); // MessageBox.Show("works"); System.Net.WebClient GetLatestInfo = new System.Net.WebClient(); richTextBox1.AppendText(Environment.NewLine + DateTime.Now + " Trying to download update config file"); Logs.Append(Environment.NewLine + DateTime.Now + " Trying to download update config file"); GetLatestInfo.DownloadFile("ftp://89.203.4.93:2048/downloads/isomount/latestversion.txt", "latestversion.txt"); if (File.Exists(Application.StartupPath + "\\" + "latestversion.txt")) { richTextBox1.AppendText(Environment.NewLine + DateTime.Now + " Successfully downloaded update config files"); Logs.Append(Environment.NewLine + DateTime.Now + " Successfully downloaded update config files"); } else { richTextBox1.AppendText(Environment.NewLine + DateTime.Now + " Error in downloading update files, skipping autoupdate"); Logs.Append(Environment.NewLine + DateTime.Now + " Error in downloading update files, skipping autoupdate"); goto EndCheckUpdate; } CheckVersion = new StreamReader(Application.StartupPath + "\\" + "latestversion.txt"); String LatestFile = CheckVersion.ReadToEnd(); CheckVersion.Close(); output1 = LatestFile.Split(Splitter); String LatestVersion = output1[0]; if (LatestVersion == CurrentVersion) { richTextBox1.AppendText(Environment.NewLine + DateTime.Now + " Current version is already up to date"); Logs.Append(Environment.NewLine + DateTime.Now + " Current version is already up to date"); } else { richTextBox1.AppendText(Environment.NewLine + DateTime.Now + " New version found"); Logs.Append(Environment.NewLine + DateTime.Now + " New version found"); DialogResult UpdateResponse = MessageBox.Show("New version, " + output1[0] + ", from " + output1[1] + " found. Update?", "Update available", MessageBoxButtons.YesNoCancel); if (UpdateResponse == DialogResult.Yes) { richTextBox1.AppendText(Environment.NewLine + DateTime.Now + " Starting download app"); Logs.Append(Environment.NewLine + DateTime.Now + " Starting download app"); richTextBox1.AppendText(Environment.NewLine + DateTime.Now + " Update logs are found in update.txt, if enabled"); Logs.Append(Environment.NewLine + DateTime.Now + " Update logs are found in update.txt, if enabled"); Form2 downloadform = new Form2(); downloadform.UpdateProgram(); downloadform.ShowDialog(); } } } else { richTextBox1.AppendText(Environment.NewLine + DateTime.Now + " Cannot ping update server, skipping autoupdate"); Logs.Append(Environment.NewLine + DateTime.Now + " Cannot ping update server, skipping autoupdate"); } } else { richTextBox1.AppendText(Environment.NewLine + DateTime.Now + " Autoupdates disabled"); Logs.Append(Environment.NewLine + DateTime.Now + " Autoupdates disabled"); button3.Text = "Updates disabled"; } EndCheckUpdate :; } else { richTextBox1.AppendText(Environment.NewLine + DateTime.Now + " Error: cannot find version.txt"); Logs.Append(Environment.NewLine + DateTime.Now + " Error: cannot find version.txt"); EndStartup :; MessageBox.Show("Some files cannot be found. The program may run without them however cannot be updated and logs might not work"); DialogResult UpdateResponse = MessageBox.Show("Would you like to download the newest version from online?", "Download latest version", MessageBoxButtons.YesNo); } }
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; }