/// <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); }