Ejemplo n.º 1
0
        public static int LuacCodeSize(string luaSourceFile)
        {
            int    retVal = -1;
            string result = ScriptSearchForm.RunCommand(Program.Luac, " -s -o tmp.luac " + luaSourceFile, true);

            if (result.Length < 10)
            {
                FileInfo info = new FileInfo(".\\tmp.luac");
                retVal = (int)info.Length;
            }
            return(retVal);
        }
Ejemplo n.º 2
0
        /// <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);
        }