public void ProgressBar(decimal divident, string text) { if (pBarProgress.GetCurrentParent().InvokeRequired) { pBarProgress.GetCurrentParent().BeginInvoke(new dgProgressBar(ProgressBar), new object[] { divident, text }); } else { try { lblProgessBar.Text = text; int temp = (int)(divident * 100); pBarProgress.Value = temp; if (pBarProgress.Value == 100) { pBarProgress.Value = 0; lblProgessBar.Text = "Ready"; } } catch (Exception exception) { global.log.MetroLog.INSTANCE.WriteLine("ERROR: Exception thrown in class: " + this.ToString() + ", METHOD: " + System.Reflection.MethodBase.GetCurrentMethod() + ", EXCEPTION INFORMATION: " + exception.ToString(), LogType.ERROR); } } }
private void SetToolStripProgressBarValue(ToolStripProgressBar toolStripProgressBar, int value) { if (toolStripProgressBar.GetCurrentParent().InvokeRequired) { toolStripProgressBar.GetCurrentParent().Invoke(new Action <ToolStripProgressBar, int>(SetToolStripProgressBarValue), new object[] { toolStripProgressBar, value }); } else { toolStripProgressBar.Value = value; } }
private void SetToolStripProgressBarStyle(ToolStripProgressBar toolStripProgressBar, ProgressBarStyle style) { if (toolStripProgressBar.GetCurrentParent().InvokeRequired) { toolStripProgressBar.GetCurrentParent().Invoke(new Action <ToolStripProgressBar, ProgressBarStyle>(SetToolStripProgressBarStyle), new object[] { toolStripProgressBar, style }); } else { toolStripProgressBar.Style = style; } }
/// <summary> /// Set the progress on the progress bar if it's set. /// </summary> public void UpdateProgressBar(int progress) { if (progressBar != null) { progressBar.GetCurrentParent().Invoke((MethodInvoker) delegate { progressBar.Value = progress; }); } }
public static void UpdateProgressBarMaximum(Form1 form, ToolStripProgressBar ctrl, int value) { if (ctrl.GetCurrentParent().InvokeRequired) { UpdateProgressBarCallBack d = new UpdateProgressBarCallBack(UpdateProgressBarMaximum); form.Invoke(d, new object[] { form, ctrl, value }); } else { ctrl.Maximum = value; } }
public static void SetProgress(int min, int max, int value) { if (pb == null) { return; } pb.GetCurrentParent().BeginInvoke((MethodInvoker) delegate() { pb.Minimum = min; pb.Maximum = max; pb.Value = value; }); Application.DoEvents(); }
public static void UpdateProgressBar(Form1 form, ToolStripProgressBar ctrl, int value) { if (ctrl.GetCurrentParent().InvokeRequired) { UpdateProgressBarCallBack d = new UpdateProgressBarCallBack(UpdateProgressBar); form.Invoke(d, new object[] { form, ctrl, value }); } else { try { ctrl.Value = value; } catch { Console.WriteLine(value); ctrl.Value = ctrl.Maximum; } } }
/// <summary> /// Loads a .mod file from given file and returns a nullable boolean (True, null, False). /// </summary> /// <param name="file">.mod file to load.</param> /// <param name="modCount">REF: Total number of jobs loaded.</param> /// <param name="progbar">ProgressBar to increment/change during method.</param> /// <param name="ExternalCall">If true, certain functions are disabled/automated.</param> /// <returns>True if update is to be done automatically, false if not, and null if user requests to stop loading .mod.</returns> public static bool?LoadDotMod(string file, ref int modCount, ToolStripProgressBar progbar, bool ExternalCall) { bool AutoUpdate = false; // KFreon: Load from file using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read)) { // KFreon: Attempt to get version fs.Seek(0, SeekOrigin.Begin); int versionLength = fs.ReadValueS32(); long countOffset = fs.Seek(0, SeekOrigin.Current); // Just in case string version = ""; int count = -1; string ExecutingVersion = null; bool validVersion = false; if (versionLength > 20) // KFreon: Version is definitely wrong { ExecutingVersion = ""; } else { // KFreon: Do version checking for (int i = 0; i < versionLength; i++) { version += (char)fs.ReadByte(); } // KFreon: Get Executing Version and check validity of read .mod version string vers; ExecutingVersion = GetVersion(version, out vers, out validVersion); version = vers; count = fs.ReadValueS32(); // KFreon: Check if update required if (version != ExecutingVersion) { if (ExternalCall) { AutoUpdate = true; } } else // KFreon: Reset to null to signify success { ExecutingVersion = null; } } // KFreon: Ask what to do about version if (ExecutingVersion != null) //&& !ExternalCall) // Heff: do we want to suppress this for external calls? should they always autoupdate? { // Seems better to keep it the current way, so that users get prompted if they load old .mods. DialogResult dr = MessageBox.Show(Path.GetFileName(file) + " is old and unsupported by this version of ME3Explorer." + Environment.NewLine + "Click Yes to update .mod now, No to continue loading .mod, or Cancel to stop loading .mod", "Ancient .mod detected.", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (dr == System.Windows.Forms.DialogResult.Cancel) { return(null); } else if (dr == System.Windows.Forms.DialogResult.Yes) { AutoUpdate = true; } } /*else if (ExecutingVersion != null) // Heff: could use this for always updating if its an external call: * AutoUpdate = true;*/ // KFreon: Reset stream position if necessary if (!validVersion) { count = versionLength; fs.Seek(countOffset, SeekOrigin.Begin); } // KFreon: Increment progress bar if (progbar != null) { progbar.GetCurrentParent().Invoke(new Action(() => { progbar.Value = 0; progbar.Maximum = count; })); } // KFreon: Read Data DebugOutput.PrintLn("Found " + count + " Jobs", true); modCount += count; for (int i = 0; i < count; i++) { // KFreon: Read name ModMaker.ModJob md = new ModMaker.ModJob(); int len = fs.ReadValueS32(); md.Name = ""; for (int j = 0; j < len; j++) { md.Name += (char)fs.ReadByte(); } // KFreon: Read script len = fs.ReadValueS32(); md.Script = ""; for (int j = 0; j < len; j++) { md.Script += (char)fs.ReadByte(); } // KFreon: Read data len = fs.ReadValueS32(); byte[] buff = fs.ReadBytes(len); md.data = buff; ModMaker.JobList.Add(md); DebugOutput.PrintLn("Add Job \"" + md.Name + "\"", true); if (progbar != null) { progbar.GetCurrentParent().Invoke(new Action(() => progbar.Increment(1))); } } } return(AutoUpdate); }