public static void Worker() { JobNum = 0; int free = Utility.freeSpaceMB(Utility.GetTempPath()); if (free < 4096) { Logger.WriteLog("Error: Not enough disk space. Please make sure that you have atleast 4GB free space on drive " + Path.GetPathRoot(Utility.GetTempPath()) + ". Currently you only have " + free + "MB available"); return; } if (!Zipping.ExistsInZip(Form1.form.ftf_textbox.Text, "system.sin")) { Logger.WriteLog("Error: system.sin does not exist in file " + Form1.form.ftf_textbox.Text); return; } BackgroundWorker worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.WorkerSupportsCancellation = true; worker.DoWork += (o, _e) => { try { Form1.form.ControlsEnabled(false); if (Form1.form.options_checklist.CheckedItems.Contains("Legacy mode")) { jobs = legacyjobs; } else { jobs = newjobs; } foreach (Action <BackgroundWorker> action in jobs) { if (worker.CancellationPending) { Cancel(worker); _e.Cancel = true; break; } action(worker); } } catch (Exception e) { Logger.WriteLog(e.Message); //Logger.WriteLog(e.StackTrace); } }; worker.ProgressChanged += (o, _e) => { Form1.form.progressBar.Value = _e.ProgressPercentage; }; worker.RunWorkerCompleted += (o, _e) => { Form1.form.ControlsEnabled(true); }; worker.RunWorkerAsync(); }
private static void ExtractAndAdd(BackgroundWorker worker, string name, string extension, string ftffile, string AsFilename = "") { if (Zipping.ExistsInZip(ftffile, name + ".sin") == false) { OnError(name, AsFilename); return; } Zipping.UnzipFile(worker, ftffile, name + ".sin", string.Empty, Utility.GetTempPath(), false); if (File.Exists(Path.Combine(Utility.GetTempPath(), name + ".sin"))) { Logger.WriteLog(" " + name); SinExtract.ExtractSin(worker, Path.Combine(Utility.GetTempPath(), name + ".sin"), Path.Combine(Utility.GetTempPath(), name + extension), false); if (PartitionInfo.ScriptMode == PartitionInfo.Mode.LegacyUUID) { byte[] UUID = PartitionInfo.ReadSinUUID(Path.Combine(Utility.GetTempPath(), name + ".sin")); Utility.ScriptSetUUID(worker, (AsFilename == "" ? name : AsFilename), UUID); } File.Delete(Path.Combine(Utility.GetTempPath(), name + ".sin")); Zipping.AddToZip(worker, Settings.destinationFile, Path.Combine(Utility.GetTempPath(), name + extension), (AsFilename == "" ? name : AsFilename) + extension, false); File.Delete(Path.Combine(Utility.GetTempPath(), name + extension)); } }
private void create_button_Click(object sender, EventArgs e) { if (isWorking) { return; } if (!File.Exists(ftf_textbox.Text)) { Logger.WriteLog("Error: Please specify a valid FTF file"); return; } if (!File.Exists(su_textbox.Text)) { Logger.WriteLog("Error: Please specify a valid SuperSU.zip"); return; } else if (Zipping.ExistsInZip(su_textbox.Text, "updater-script")) { Logger.WriteLog("Info: No updater-script found in SuperSU zip. Are you sure it's a flashable zip?"); } if (!File.Exists(rec_textbox.Text)) { Logger.WriteLog("Info: Not adding recovery"); } else if (Zipping.ExistsInZip(rec_textbox.Text, "updater-script")) { Logger.WriteLog("Info: No updater-script found in Recovery zip. Are you sure it's a flashable zip?"); } if (Settings.saveDialog) { using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.Filter = "Zip Files (*.zip)|*.zip"; if (sfd.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } Settings.destinationFile = sfd.FileName; } } else { Settings.destinationFile = "flashable-prerooted.zip"; } Utility.WriteResourceToFile("PRFCreator.Resources.flashable-prerooted.zip", Settings.destinationFile); if (!File.Exists(Settings.destinationFile)) { Logger.WriteLog("Error: Unable to extract flashable-prerooted.zip from the exe"); return; } Job.Worker(); }
private static string GetModemFilename(string ftffile) { string[] mdms = { "amss_fsg", "amss_fs_3", "modem" }; foreach (string mdm in mdms) { if (Zipping.ExistsInZip(ftffile, mdm + ".sin")) { return(mdm); } } return("modem"); }
private static string GetKernelFilename(string ftffile) { string[] names = { "kernel", "boot" }; foreach (string name in names) { if (Zipping.ExistsInZip(ftffile, name + ".sin")) { return(name); } } //if nothing exists, return kernel anyway so the error message makes sense return("kernel"); }
private static bool ExtractAndAddSin(BackgroundWorker worker, string name, string ftffile, string AsFilename = "") { if (Zipping.ExistsInZip(ftffile, name + ".sin") == false) { OnError(name, AsFilename); return(false); } Zipping.UnzipFile(worker, ftffile, name + ".sin", string.Empty, Utility.GetTempPath(), false); if (File.Exists(Path.Combine(Utility.GetTempPath(), name + ".sin"))) { Logger.WriteLog(" " + name); Zipping.AddToZip(worker, Settings.destinationFile, Path.Combine(Utility.GetTempPath(), name + ".sin"), (AsFilename == "" ? name : AsFilename) + ".sin", false, Ionic.Zlib.CompressionLevel.None); File.Delete(Path.Combine(Utility.GetTempPath(), name + ".sin")); } return(true); }