public static string GetString(string title, string message, string initialText) { StringInputDlg sid = new StringInputDlg(title, message, initialText); sid.ShowDialog(); string ret = sid.getResult(); sid.Dispose(); return(ret); }
/// <summary> /// /// </summary> /// <param name="fileName">the base .lvl file to splice the code into</param> /// <param name="newCode"></param> /// <returns>The file the data was saved to; null on error</returns> public string SpliceInNewCode(string newCode) { string tmpLuaFileName = ".\\_spliceTmp.lua"; File.WriteAllText(tmpLuaFileName, newCode); string result = ScriptSearchForm.RunCommand(Program.Luac, " -s -o tmp.luac " + tmpLuaFileName, true); if (result.Trim() != "") { MessageBox.Show("Error compiling code", result); return(null); } byte[] newLuacCode = File.ReadAllBytes("tmp.luac"); string newLvlFile = StringInputDlg.GetString("new lvl file name", "Save the file as what?>"); if (newLvlFile != null) { try { if (!String.IsNullOrEmpty(ScriptSearchForm.CurrentFile)) { int lastSlash = ScriptSearchForm.CurrentFile.LastIndexOf(Path.DirectorySeparatorChar); if (lastSlash > -1) { newLvlFile = tmpLuaFileName = ScriptSearchForm.CurrentFile.Substring(0, lastSlash + 1) + newLvlFile; } } using (FileStream fs = File.OpenWrite(newLvlFile)) { BinaryWriter bw = new BinaryWriter(fs); bw.BaseStream.Write(mData, 0, (int)(this.BodyStart - 4)); bw.Write(newLuacCode.Length + 1); bw.BaseStream.Write(newLuacCode, 0, newLuacCode.Length); bw.BaseStream.Write(mData, (int)this.BodyEnd, (int)(mData.Length - this.BodyEnd)); bw.Close(); MessageBox.Show("Saved to " + newLvlFile); return(newLvlFile); } } catch (Exception) { MessageBox.Show("Error splicing in new code"); } } return(null); }
private void mExtractAssetButton_Click(object sender, EventArgs e) { string fileName = StringInputDlg.GetString("Extract to File", "File name"); if (fileName != null) { try { AssetListItem item = mAssetListBox.SelectedItem as AssetListItem; File.WriteAllBytes(fileName, item.GetAssetData()); } catch (Exception ex) { MessageBox.Show("Error saving file!", ex.Message); } } }
/// <summary> /// Prompts the user for a string to search for /// </summary> /// <returns>true if the search string was set</returns> public bool SetSearchString() { bool ret = false; if (this.SelectionLength > 0) { SearchString = this.Text.Substring(this.SelectionStart, this.SelectionLength); } string result = StringInputDlg.GetString( "Enter Search String", "Please enter text (or a regex) to search for.", SearchString); if (!result.Equals("")) { SearchString = result; ret = true; } return(ret); }
private static string FindSourceFile(string fileName) { string sourceFile = null; if (fileName != null) { if (sAllLuaFiles == null) { while (!Directory.Exists(Program.BF2_Tools_BaseDir)) { Program.BF2_Tools_BaseDir = StringInputDlg.GetString("Please enter SWBF2 mod tools base directory", "Could not find " + Program.BF2_Tools_BaseDir + ". Please enter base SWBF2 mod tools directory", Program.BF2_Tools_BaseDir); if (String.IsNullOrEmpty(Program.BF2_Tools_BaseDir)) { return(null); } if (!Program.BF2_Tools_BaseDir.EndsWith("\\")) { Program.BF2_Tools_BaseDir += "\\"; } } sAllLuaFiles = new List <string>(); sAllLuaFiles.AddRange(Directory.GetFiles(Program.BF2_Tools_BaseDir + "assets\\", "*.lua", SearchOption.AllDirectories)); sAllLuaFiles.AddRange(Directory.GetFiles(Program.BF2_Tools_BaseDir + "TEMPLATE\\Common\\scripts\\", "*.lua", SearchOption.AllDirectories)); sAllLuaFiles.AddRange(Directory.GetFiles(Program.BF2_Tools_BaseDir + "space_template\\", "*.lua", SearchOption.AllDirectories)); sAllLuaFiles.AddRange(Directory.GetFiles(Program.BF2_Tools_BaseDir + "data\\Common\\scripts\\", "*.lua", SearchOption.AllDirectories)); } string searchFor = fileName.EndsWith(".lua") ? fileName : fileName + ".lua"; foreach (string file in sAllLuaFiles) { if (file.EndsWith(searchFor, StringComparison.InvariantCultureIgnoreCase)) { sourceFile = file; break; } } } return(sourceFile); }
/// <summary> /// Prompt the user for input for a 'set' command /// </summary> /// <param name="input">The input string to operate on</param> /// <returns>empty string on cancel, 'SET' string when successful.</returns> public static string PromptForSetUserInput(string input) { string retVal = ""; string msg = GetPromptUserMesage(input); string location = GetSetLocation(input); while (retVal == "") { StringBuilder rangeMsg = new StringBuilder(25); String userInputValue = ""; int min = 0; int max = 0; //SET(0x2224B, {32TeamNES,28TeamNES PromptUser:Msg="Enter desired quarter length":int(1-15)} ) //SET(0x2224B, {32TeamNES,28TeamNES PromptUser:Msg="Enter desired quarter length":int(0x1-0x15)} ) //SET(0x2224B, {32TeamNES,28TeamNES PromptUser:Msg="Enter name of...":string(len=8)} ) maybe not this one. if (input.IndexOf("int", StringComparison.OrdinalIgnoreCase) > -1 && (GetHexRange(ref min, ref max, input, rangeMsg) || GetDecimalRange(ref min, ref max, input, rangeMsg))) { string rangeMessage = rangeMsg.ToString(); NumberStyles style = rangeMessage.IndexOf('x') > 0 ? NumberStyles.HexNumber : NumberStyles.Integer; string initialText = style == NumberStyles.HexNumber ? "0x" : ""; StringInputDlg dlg = new StringInputDlg(msg, rangeMessage, initialText); int userVal = Int32.MinValue; if (dlg.ShowDialog() == DialogResult.OK) { userInputValue = dlg.getResult(); if (userInputValue.StartsWith("0x")) { userInputValue = userInputValue.Substring(2); } try { userVal = Int32.Parse(userInputValue, style); if (userVal < min || userVal > max) { userVal = Int32.MinValue; throw new Exception("Invalid input."); } } catch (Exception) { ShowError(string.Format( "Error with '{0}'. Value '{1}' is invalid for range {2}", msg, userInputValue, rangeMessage)); } if (userVal > Int32.MinValue) { retVal = string.Format("SET({0}, 0x{1:x})", location, userVal); } } else { retVal = " "; // trigger us to leave the loop } dlg.Dispose(); } else { ShowError("ERROR applying line: " + input); retVal = null; } } return(retVal); }