public static void SuspendThreadList(ProcessThreadCollection threads, bool suspend) { int[] threadList = new int[threads.Count]; for (int i = 0; i < threadList.Length; i++) { threadList[i] = threads[i].Id; } IDL.SuspendThreadList(threadList, threadList.Length, suspend ? 1 : 0); }
private void buttonLoad_Click(object sender, EventArgs e) { if (mainForm.ActiveDocument == null) { label_Result.Text = "No active document"; return; } if (mainForm.ActiveDocument.DocumentType != DocumentType.BgData && mainForm.ActiveDocument.DocumentType != DocumentType.ObjectData && mainForm.ActiveDocument.DocumentType != DocumentType.StageData) { label_Result.Text = "Unsupported document type: " + mainForm.ActiveDocument.DocumentType; return; } int result = int.MinValue; try { if (comboBox_Process.SelectedIndex < 0 || (comboBox_DataType.SelectedIndex < 0) || (comboBox_DataType.SelectedIndex == 0 && (comboBox_ObjId.SelectedIndex < 0 || comboBox_ObjType.SelectedIndex < 0)) || (comboBox_DataType.SelectedIndex == 2 && (comboBox_BgId.SelectedIndex < 0))) { return; } string dat = mainForm.ActiveDocument.Scintilla.Text; Process p = procs[comboBox_Process.SelectedIndex]; if (p.HasExited) { RefreshProcessList(); return; } p = Process.GetProcessById(p.Id); // refresh for most up-to-date thread list int[] threads = new int[p.Threads.Count]; for (int i = 0; i < threads.Length; i++) { threads[i] = p.Threads[i].Id; } int suspendResult; var suspend = (int[])threads.Clone(); var resume = (int[])threads.Clone(); try { if ((suspendResult = IDL.SuspendThreadList(suspend, threads.Length, 1)) != 0) { throw new ApplicationException("Process suspending failed: " + p.Id); } Clean(); result = IDL.InstantLoad(dat, dat.Length, p.Id, (DataType)comboBox_DataType.SelectedIndex, comboBox_DataType.SelectedIndex == 0 ? comboBox_ObjId.SelectedIndex : comboBox_DataType.SelectedIndex == 1 ? (-1) : // not to be used comboBox_BgId.SelectedIndex, comboBox_DataType.SelectedIndex == 0 ? (ObjectType)comboBox_ObjType.SelectedIndex : ObjectType.Invalid, this.Handle, logFunc); } finally { IDL.SuspendThreadList(resume, threads.Length, 0); if (result == 0) { label_Result.Text = "Successful"; //SetForegroundWindow(new HandleRef(p, p.MainWindowHandle)); //this.Close(); } else if (result == 1) { label_Result.Text = "Successful (warnings)"; StepCaret(); } else { label_Result.Text = "Error code: " + result; StepCaret(); } } } catch (ApplicationException ex) { MessageBox.Show(ex.ToString(), "Instant Data Loading Error"); } catch (Exception ex) { mainForm.formEventLog.Error(ex, "Instant Data Loading Error"); } }
public void FreshLoad() { DocumentForm doc = mainForm.ActiveDocument; if (doc == null) { return; } comboBox_ObjId.SelectedIndex = -1; comboBox_DataType.SelectedIndex = -1; comboBox_ObjType.SelectedIndex = -1; comboBox_BgId.SelectedIndex = -1; label_Result.Text = ""; RefreshProcessList(); switch (doc.DocumentType) { case DocumentType.ObjectData: comboBox_DataType.SelectedIndex = 0; comboBox_DataType.Enabled = true; break; case DocumentType.StageData: comboBox_DataType.SelectedIndex = 1; comboBox_DataType.Enabled = true; break; case DocumentType.BgData: comboBox_DataType.SelectedIndex = 2; comboBox_DataType.Enabled = true; break; default: label_Result.Text = "Unsupported document type: " + doc.DocumentType.ToString(); comboBox_ObjId.Enabled = false; comboBox_DataType.Enabled = false; comboBox_ObjType.Enabled = false; comboBox_BgId.Enabled = false; break; } string lfDir = Path.GetDirectoryName(Settings.Current.lfPath), dataTxtFile = lfDir + "\\data\\data.txt"; if (!File.Exists(dataTxtFile)) { MessageBox.Show("'data.txt' could not found. Make sure you set 'LF2 Path' correct in the settings menu.", Program.Title); this.Close(); return; } comboBox_BgId.Items.Clear(); comboBox_ObjId.Items.Clear(); DateTime modification = File.GetLastWriteTime(dataTxtFile); if (modification > dataTxtLastModification) { dataTxtFile = File.ReadAllText(dataTxtFile); if (IDL.ReadDataTxt(dataTxtFile, dataTxtFile.Length, out dataTxt.objects, out dataTxt.objCount, out dataTxt.backgrounds, out dataTxt.bgCount, this.Handle) != 0) { return; } dataTxtLastModification = modification; } for (int i = 0; i < dataTxt.objCount; i++) { comboBox_ObjId.Items.Add(string.Format("id: {0} type: {1} file: {2}", dataTxt.objects[i].id, (byte)dataTxt.objects[i].type, dataTxt.objects[i].file)); } for (int i = 0; i < dataTxt.bgCount; i++) { comboBox_BgId.Items.Add(string.Format("id: {0} file: {1}", dataTxt.backgrounds[i].id, dataTxt.backgrounds[i].file)); } for (int i = 0; i < dataTxt.objCount; i++) { if (doc.FilePath != null ? doc.FilePath.EndsWith(dataTxt.objects[i].file, StringComparison.InvariantCultureIgnoreCase) : doc.TabText.EndsWith(dataTxt.objects[i].file, StringComparison.InvariantCultureIgnoreCase)) { comboBox_ObjId.SelectedIndex = i; comboBox_ObjType.SelectedIndex = (int)dataTxt.objects[i].type; comboBox_DataType.SelectedIndex = 0; break; } } for (int i = 0; i < dataTxt.bgCount; i++) { if (doc.FilePath != null ? doc.FilePath.EndsWith(dataTxt.backgrounds[i].file, StringComparison.InvariantCultureIgnoreCase) : doc.TabText.EndsWith(dataTxt.backgrounds[i].file, StringComparison.InvariantCultureIgnoreCase)) { comboBox_BgId.SelectedIndex = i; comboBox_DataType.SelectedIndex = 2; break; } } }