Beispiel #1
0
        public static void PackageMod(string modName, DirectoryInfo extensionDir)
        {
            Console.WriteLine("Packaging mod {0}...", modName);

            var packager = new CatPackager(Steam.Steam.GetXRebirthCatTool().FullName);
            var lua      = new LuaCompiler(LuaCompilerPath);
            var modDir   = Steam.Steam.GetXRebirthModDirectory(modName);

            Console.WriteLine("Fetching content descriptor...");

            var contentDescriptor = extensionDir.GetFiles().SingleOrDefault(fi => fi.Name == "content.xml");

            if (contentDescriptor == null)
            {
                throw new Exception("Mod must have a content.xml");
            }

            var contentDescriptorOutput = string.Format(@"{0}\{1}", modDir.FullName, "content.xml");

            Console.WriteLine("Fetching readMe...");

            var readme       = extensionDir.GetFiles().SingleOrDefault(fi => fi.Name == "README.txt");
            var readmeOutput = string.Format(@"{0}\{1}", modDir.FullName, "README.txt");

            Console.WriteLine("Copying base files...");

            File.Copy(contentDescriptor.FullName, contentDescriptorOutput, true);
            if (readme != null)
            {
                File.Copy(readme.FullName, readmeOutput, true);
            }

            Console.WriteLine("Compiling UI...");

            // TODO: make generic to scan mutliple locations for lua files to compile
            // compile the UI
            var uiFiles       = extensionDir.EnumerateFiles("*.lua", SearchOption.AllDirectories);
            var uiDirectories = uiFiles.Select(f => f.Directory).Distinct(new DirectoryByNameComparer());

            foreach (var uiDir in uiDirectories)
            {
                var outputDir = string.Compare(uiDir.Name, "sources", true) == 0 ? null : uiDir.FullName;
                lua.Compile(uiDir.FullName, outputDir);
            }

            Console.WriteLine("Packaging UI...");

            // package the UI
            packager.Package(extensionDir.FullName, modDir.FullName, "subst_01.cat", @"^.*\.xpl$");

            Console.WriteLine("Packaging Scripts...");

            // package the scripts
            packager.Package(extensionDir.FullName, modDir.FullName, "ext_01.cat", @"^.*(\.xml|\.txt)$", "^.*content.xml$");

            Console.WriteLine("Finished packaging mod!");
        }
    private static void ImplCompileOrCheckLua(List <string> listLua, bool bCheck = false)
    {
        if (listLua.Count == 0)
        {
            EditorUtility.DisplayDialog("Prompt", "You have not select valid lua file, please select the special lua files or folders that need to be processed in the right window of Project.", "OK");
            return;
        }

        int    i;
        string strBytecode;
        string strCompileError;

        int iSuccNum   = 0;
        int iFailedNum = 0;

        float fPercent;

        int iBeginTime = Environment.TickCount;

        EditorUtility.DisplayProgressBar("Progress", "Compiling lua, please wait...", 0.0f);
        for (i = 0; i < listLua.Count; i++)
        {
            // luac -o out.lua 1.lua
            strBytecode = listLua[i].Replace("/Src/", "/Bytecode/");
            strBytecode = strBytecode.Replace(".lua", ".clx");
            //strArg = "\"-o " + strBytecode + " " + listLua[i] + "\"";
            //if ( CompileLua(strWorkPath, strExe, listLua[i], strBytecode, out strCompileError, out strExeError) ==false )
            if (bCheck == false)
            {
                try
                {
                    if (LuaCompiler.DumpingToFile(listLua[i], strBytecode, true, out strCompileError) == false)
                    {
                        iFailedNum += 1;
                        if (!string.IsNullOrEmpty(strCompileError))
                        {
                            //UnityEngine.Debug.LogError("Compile failed: " + listLua[i]);
                            UnityEngine.Debug.LogError("<color=red>[E]: " + strCompileError + "</color>");
                        }
                    }
                    else
                    {
                        iSuccNum += 1;
                        UnityEngine.Debug.Log("<color=#98FB98>[O]: " + listLua[i] + "</color>");
                    }
                }
                catch (Exception e)
                {
                    iFailedNum += 1;

                    //UnityEngine.Debug.LogError("Compile failed: " + listLua[i]);
                    UnityEngine.Debug.LogError("<color=red>[E]: " + listLua[i] + " " + e.Message + "</color>");
                }

                fPercent = (float)(i + 1) / listLua.Count;
                EditorUtility.DisplayProgressBar("Progress", "Compiling lua, please wait...", fPercent);
            }
            else
            {
                try
                {
                    LuaCompiler.CompileFile(listLua[i], out strCompileError);
                    if (!string.IsNullOrEmpty(strCompileError))
                    {
                        iFailedNum += 1;
                        if (!string.IsNullOrEmpty(strCompileError))
                        {
                            //UnityEngine.Debug.LogError("Compile failed: " + listLua[i]);
                            UnityEngine.Debug.LogError("<color=red>[E]: " + strCompileError + "</color>");
                        }
                    }
                    else
                    {
                        iSuccNum += 1;
                        UnityEngine.Debug.Log("<color=#98FB98>[O]: " + listLua[i] + "</color>");
                    }
                }
                catch (Exception e)
                {
                    iFailedNum += 1;

                    //UnityEngine.Debug.LogError("Compile failed: " + listLua[i]);
                    UnityEngine.Debug.LogError("<color=#98FB98>[E]: " + listLua[i] + " " + e.Message + "</color>");
                }

                fPercent = (float)(i + 1) / listLua.Count;
                EditorUtility.DisplayProgressBar("Progress", "Check lua, please wait...", fPercent);
            }
        }
        EditorUtility.ClearProgressBar();
        int iEndTime = Environment.TickCount;

        float  fCostTime = (float)(iEndTime - iBeginTime) * 0.001f;
        string strK      = string.Format("The job has finish, cost time: {0}(s)\n\nSucceed: {1}\nFailed: {2}\n\nPlease see the console for detail", fCostTime.ToString("f2"), iSuccNum, iFailedNum);

        AssetDatabase.Refresh();
        EditorUtility.DisplayDialog("Finish", strK, "OK");
    }