Пример #1
0
    public static void ExportLuaEx(string dirPath)
    {
        string tmpPath = Path.GetFullPath(Path.Combine(Application.dataPath, "tmp"));

        DirectoryDelete(tmpPath);
        CheckDirectory(tmpPath);

        string[]      include     = new string[] { ".lua", ".cs", ".txt", ".shader", ".py" };
        List <string> exportNames = new List <string>();

        string[] fileList = Directory.GetFiles(dirPath, "*.*", SearchOption.AllDirectories);
        for (int i = 0; i < fileList.Length; i++)
        {
            string fileName = fileList[i];
            string ext      = Path.GetExtension(fileName);
            if (Array.IndexOf <string>(include, ext) != -1)
            {
                string byteFileName = fileName.Replace(dirPath, "");
                if (byteFileName.StartsWith("\\"))
                {
                    byteFileName = byteFileName.Substring(1);
                }
                byteFileName  = byteFileName.Replace("\\", "%").Replace("/", "%").Replace(".", "%");
                byteFileName += ".bytes";
                exportNames.Add("Assets/tmp/" + byteFileName);
                File.Copy(Path.GetFullPath(fileName), Path.Combine(tmpPath, byteFileName), true);
            }
        }

        System.Threading.Thread.Sleep(1000);
        AssetDatabase.Refresh();

        ExportAssetBundle.BuildAssetBundles(exportNames.ToArray(), "Assets/tmp", "luaout.bytes", BuildAssetBundleOptions.DeterministicAssetBundle);

        string strOutputPath = Path.Combine(Application.streamingAssetsPath, PathUtil.Platform);

        CheckDirectory(strOutputPath);

        string luaoutPath = Path.Combine(Application.dataPath, "tmp/luaout.bytes");

        string luaExportPath = Path.GetFullPath(Path.Combine(strOutputPath, "lua_core.u3d"));

        byte[] by      = File.ReadAllBytes(luaoutPath);
        byte[] encrypt = CryptographHelper.Encrypt(by, key, iv);
        File.WriteAllBytes(luaExportPath, encrypt);

        DirectoryDelete(tmpPath);

        Debug.Log(luaExportPath + " export.");

        System.Threading.Thread.Sleep(100);
        AssetDatabase.Refresh();
    }
Пример #2
0
        /// <summary>
        /// 本地存储
        /// </summary>
        public static bool SaveLocalData(string fileName, string saveData)
        {
            string     fullPath = CUtils.PathCombine(CUtils.GetRealPersistentDataPath(), fileName);
            FileStream fs       = new FileStream(fullPath, FileMode.Create);

            if (fs != null)
            {
                byte[] bytes = CryptographHelper.Encrypt(Encoding.UTF8.GetBytes(saveData), key, iv);
                fs.Write(bytes, 0, bytes.Length);
                fs.Flush();
                fs.Close();
                return(true);
            }
            return(false);
        }
Пример #3
0
 static public int Encrypt_s(IntPtr l)
 {
     try {
         System.Byte[] a1;
         checkType(l, 1, out a1);
         System.Byte[] a2;
         checkType(l, 2, out a2);
         System.Byte[] a3;
         checkType(l, 3, out a3);
         var ret = CryptographHelper.Encrypt(a1, a2, a3);
         pushValue(l, ret);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Пример #4
0
        /// <summary>
        /// 本地存储
        /// </summary>
        public static bool SaveLocalData(string fileName, string saveData)
        {
            string   fullPath = CUtils.PathCombine(CUtils.GetRealPersistentDataPath(), fileName);
            FileInfo fileInfo = new FileInfo(fullPath);

            if (!fileInfo.Directory.Exists)
            {
                fileInfo.Directory.Create();
            }
            // if (!fileInfo.Exists) fileInfo.Create();
            using (var sw = fileInfo.OpenWrite())
            {
                byte[] bytes = CryptographHelper.Encrypt(Encoding.UTF8.GetBytes(saveData), key, iv);
                sw.Write(bytes, 0, bytes.Length);
                sw.Flush();
            }

            return(true);
        }
Пример #5
0
    public static void exportLua()
    {
        checkLuaExportPath();
        BuildScript.CheckstreamingAssetsPath();

        string info  = "luac";
        string title = "build lua";

        EditorUtility.DisplayProgressBar(title, info, 0);

        var childrens = AssetDatabase.GetAllAssetPaths().Where(p =>
                                                               (p.StartsWith("Assets/Lua") ||
                                                                p.StartsWith("Assets/Config")) &&
                                                               (p.EndsWith(".lua"))
                                                               ).ToArray();
        string path  = "Assets/Lua/";    //lua path
        string path1 = "Assets/Config/"; //config path
        string root  = Application.dataPath.Replace("Assets", "");

        Debug.Log("luajit path = " + luacPath);
        string crypName = "", fileName = "", outfilePath = "", arg = "";

        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        //refresh directory
        DirectoryDelete(Application.dataPath + OutLuaPath);
        CheckDirectory(Application.dataPath + OutLuaPath);

        float allLen = childrens.Length;
        float i      = 0;

        List <string> exportNames = new List <string>();

        foreach (string file in childrens)
        {
            string filePath = Path.Combine(root, file);
            fileName    = CUtils.GetAssetName(filePath);
            crypName    = file.Replace(path, "").Replace(path1, "").Replace(".lua", "." + Common.LUA_LC_SUFFIX).Replace("\\", "_").Replace("/", "_");
            outfilePath = Application.dataPath + OutLuaPath + crypName;
            exportNames.Add("Assets" + OutLuaPath + crypName);
            sb.Append(fileName);
            sb.Append("=");
            sb.Append(crypName);
            sb.Append("\n");

#if Nlua || UNITY_IPHONE
            arg = "-o " + outfilePath + " " + filePath; // luac
            File.Copy(filePath, outfilePath, true);     // source code copy
#else
            arg = "-b " + filePath + " " + outfilePath; //for jit
            //Debug.Log(arg);
            //System.Diagnostics.Process.Start(luacPath, arg);//jit
            File.Copy(filePath, outfilePath, true);// source code copy
#endif
            i++;
            EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen);
        }
        Debug.Log("lua:" + path + "files=" + childrens.Length + " completed");
        System.Threading.Thread.Sleep(1000);
        AssetDatabase.Refresh();

        EditorUtility.DisplayProgressBar(title, "build lua", 0.99f);
        //u5 打包
        CheckDirectory(Path.Combine(Application.dataPath, OutLuaPath));
        BuildScript.BuildABs(exportNames.ToArray(), "Assets" + OutLuaPath, "luaout.bytes", BuildAssetBundleOptions.DeterministicAssetBundle);

        EditorUtility.DisplayProgressBar(title, "Encrypt lua", 0.99f);
        //Encrypt
        string tarName     = Application.dataPath + OutLuaPath + "luaout.bytes";
        string md5Name     = CUtils.GetRightFileName(Common.LUA_ASSETBUNDLE_FILENAME);
        string realOutPath = Path.Combine(BuildScript.GetOutPutPath(), md5Name);

        byte[] by      = File.ReadAllBytes(tarName);
        byte[] Encrypt = CryptographHelper.Encrypt(by, GetKey(), GetIV());
        File.WriteAllBytes(realOutPath, Encrypt);
        Debug.Log(realOutPath + " export");
        EditorUtility.ClearProgressBar();
    }
Пример #6
0
    public static void exportLua()
    {
        checkLuaExportPath();

        string path = Application.dataPath + "/Lua/"; //AssetDatabase.GetAssetPath(obj).Replace("Assets","");

        List <string> files = getAllChildFiles(path); // Directory.GetFiles(Application.dataPath + path);

        IList <string> childrens = new List <string>();

        foreach (string file in files)
        {
            if (file.EndsWith("lua"))
            {
                childrens.Add(file);
            }
        }
        Debug.Log("luajit path = " + luacPath);
        string crypName = "", fileName = "", outfilePath = "", arg = "";

        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        //refresh directory
        DirectoryDelete(Application.dataPath + OutLuaPath);
        CheckDirectory(Application.dataPath + OutLuaPath);
        //CheckDirectory(Application.dataPath.Replace("Assets","")+outPath);

        List <string> exportNames    = new List <string> ();

        foreach (string filePath in childrens)
        {
            fileName    = CUtils.GetURLFileName(filePath);
            crypName    = filePath.Replace(path, "").Replace(".lua", "." + Common.LUA_LC_SUFFIX).Replace("\\", "_").Replace("/", "_");
            outfilePath = Application.dataPath + OutLuaPath + crypName;
            exportNames.Add("Assets" + OutLuaPath + crypName);
            sb.Append(fileName);
            sb.Append("=");
            sb.Append(crypName);
            sb.Append("\n");

#if Nlua || UNITY_IPHONE
            arg = "-o " + outfilePath + " " + filePath; // luac
            File.Copy(filePath, outfilePath, true);     // source code copy
#else
            arg = "-b " + filePath + " " + outfilePath; //for jit
            //Debug.Log(arg);
            //System.Diagnostics.Process.Start(luacPath, arg);//jit
            File.Copy(filePath, outfilePath, true);// source code copy
#endif
        }
        Debug.Log("lua:" + path + "files=" + files.Count + " completed");
        System.Threading.Thread.Sleep(1000);
        AssetDatabase.Refresh();

        //u5 打包
        string outPath = ExportAssetBundles.GetOutPath();
        CheckDirectory(Application.dataPath.Replace("Assets", "") + outPath);
        ExportAssetBundles.BuildABs(exportNames.ToArray(), "Assets" + OutLuaPath, "luaout.bytes", BuildAssetBundleOptions.CompleteAssets);

        //Encrypt
        string tarName     = Application.dataPath + OutLuaPath + "luaout.bytes";
        string realOutPath = ExportAssetBundles.GetOutPath() + "/font.u3d";
        byte[] by          = File.ReadAllBytes(tarName);
        byte[] Encrypt     = CryptographHelper.Encrypt(by, GetKey(), GetIV());
        File.WriteAllBytes(realOutPath, Encrypt);
        Debug.Log(realOutPath + " export");
    }
Пример #7
0
    //[MenuItem("Hugula/export lua [Assets\\Lua]", false, 12)]
    public static void exportLua()
    {
        checkLuaExportPath();

        string path = Application.dataPath + "/Lua";  //AssetDatabase.GetAssetPath(obj).Replace("Assets","");

        List <string> files = getAllChildFiles(path); // Directory.GetFiles(Application.dataPath + path);

        IList <string> childrens = new List <string>();

        foreach (string file in files)
        {
            if (file.EndsWith("lua"))
            {
                childrens.Add(file);
            }
        }
        Debug.Log("luajit path = " + luacPath);
        string crypName = "", fileName = "", outfilePath = "", arg = "";

        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        DirectoryDelete(Application.dataPath + OutLuaPath);

        foreach (string filePath in childrens)
        {
            fileName = CUtils.GetURLFileName(filePath);
            //crypName=CryptographHelper.CrypfString(fileName);
            crypName    = filePath.Replace(path, "").Replace(".lua", "." + Common.LUA_LC_SUFFIX).Replace("\\", "/");
            outfilePath = Application.dataPath + OutLuaPath + crypName;
            checkLuaChildDirectory(outfilePath);

            sb.Append(fileName);
            sb.Append("=");
            sb.Append(crypName);
            sb.Append("\n");

#if Nlua || UNITY_IPHONE
            arg = "-o " + outfilePath + " " + filePath;
            File.Copy(filePath, outfilePath, true);
#else
            arg = "-b " + filePath + " " + outfilePath;             //for jit
            Debug.Log(arg);

            System.Diagnostics.Process.Start(luacPath, arg);//arg -b hello1.lua hello1.out
#endif
        }
        Debug.Log(sb.ToString());
        Debug.Log("lua:" + path + "files=" + files.Count + " completed");

        System.Threading.Thread.Sleep(1000);
        AssetDatabase.Refresh();

        //打包成assetbundle
        string luaOut = Application.dataPath + OutLuaPath;
        Debug.Log(luaOut);
        List <string>             luafiles       = getAllChildFiles(luaOut + "/", Common.LUA_LC_SUFFIX);
        string                    assetPath      = "Assets" + OutLuaPath;
        List <UnityEngine.Object> res            = new List <Object>();
        string                    relatePathName = "";
        foreach (string name in luafiles)
        {
            relatePathName = name.Replace(luaOut, "");
            string abPath = assetPath + relatePathName;
            Debug.Log(abPath);
            Debug.Log(relatePathName);
            Object txt = AssetDatabase.LoadAssetAtPath(abPath, typeof(TextAsset));
            txt.name = relatePathName.Replace(@"\", @".").Replace("/", "").Replace("." + Common.LUA_LC_SUFFIX, "");
            Debug.Log(txt.name);
            res.Add(txt);
        }

        string   cname   = "/luaout.bytes";
        string   outPath = luaOut;        //ExportAssetBundles.GetOutPath();
        string   tarName = outPath + cname;
        Object[] ress    = res.ToArray();
        Debug.Log(ress.Length);
        ExportAssetBundles.BuildAB(null, ress, tarName, BuildAssetBundleOptions.CompleteAssets);
//         Debug.Log(tarName + " export");
        AssetDatabase.Refresh();

        //Directory.CreateDirectory(luaOut);
        string realOutPath = ExportAssetBundles.GetOutPath() + "/font.u3d";
        byte[] by          = File.ReadAllBytes(tarName);
        Debug.Log(by);
        byte[] Encrypt = CryptographHelper.Encrypt(by, GetKey(), GetIV());

        File.WriteAllBytes(realOutPath, Encrypt);
        Debug.Log(realOutPath + " export");
    }
Пример #8
0
    public static void ExportLua()
    {
        string path = Path.GetFullPath(Path.Combine(Application.dataPath, "Lua"));

        string tmpPath = Path.GetFullPath(Path.Combine(Application.dataPath, "tmp"));

        DirectoryDelete(tmpPath);
        CheckDirectory(tmpPath);

        List <string> sourceFiles = new List <string>();
        List <string> exportNames = new List <string>();

        List <string> files = getAllChildFiles(path, "lua");

        foreach (string filePath in files)
        {
            string file = Path.GetFullPath(filePath);
            if (!file.EndsWith(".lua"))
            {
                continue;
            }
            string byteFileName = file.Replace(path, "");
            if (byteFileName.StartsWith("\\") || byteFileName.StartsWith("/"))
            {
                byteFileName = byteFileName.Substring(1);
            }

            byteFileName = byteFileName.Replace(".lua", ".bytes").Replace("\\", "_").Replace("/", "_");
            exportNames.Add("Assets/tmp/" + byteFileName);
            //File.Copy(file, Path.Combine(tmpPath, byteFileName), true);
            string srcFile = file.Replace(Path.GetFullPath(Application.dataPath), "");
            srcFile = "Assets" + srcFile;
            Debug.Log(srcFile);
            sourceFiles.Add(srcFile);
        }
        //打包config
        string cfgPath = Path.GetFullPath(Path.Combine(Application.dataPath, "Config/config"));

        Debug.Log("Export Lua Path:" + cfgPath);
        List <string> cfgFiles = getAllChildFiles(cfgPath, "lua");

        foreach (string filePath in cfgFiles)
        {
            string file = Path.GetFullPath(filePath);
            if (!file.EndsWith(".lua"))
            {
                continue;
            }
            string byteFileName = file.Replace(cfgPath, "");
            if (byteFileName.StartsWith("\\") || byteFileName.StartsWith("/"))
            {
                byteFileName = byteFileName.Substring(1);
            }
            byteFileName = byteFileName.Replace(".lua", ".bytes").Replace("\\", "_").Replace("/", "_");
            byteFileName = "config_" + byteFileName;
            exportNames.Add("Assets/tmp/" + byteFileName);
            //File.Copy(file, Path.Combine(tmpPath, byteFileName), true);
            string srcFile = file.Replace(Path.GetFullPath(Application.dataPath), "");
            srcFile = "Assets" + srcFile;
            sourceFiles.Add(srcFile);
        }

        System.Threading.Thread.Sleep(1000);
        AssetDatabase.Refresh();

        JITBUILDTYPE jbt = GetLuaJitBuildType(EditorUserBuildSettings.activeBuildTarget);

        SLua.LuajitGen.compileLuaJit(sourceFiles.ToArray(), exportNames.ToArray(), jbt);

        System.Threading.Thread.Sleep(1000);
        AssetDatabase.Refresh();

        ExportAssetBundle.BuildAssetBundles(exportNames.ToArray(), "Assets/tmp", "luaout.bytes", optionsDefault);

        string strOutputPath = Path.Combine(Application.streamingAssetsPath, PathUtil.Platform);

        CheckDirectory(strOutputPath);

        string luaoutPath    = Path.Combine(Application.dataPath, "tmp/luaout.bytes");
        string luaExportPath = Path.GetFullPath(Path.Combine(strOutputPath, "lua.u3d"));

        byte[] by      = File.ReadAllBytes(luaoutPath);
        byte[] encrypt = CryptographHelper.Encrypt(by, KeyVData.Instance.KEY, KeyVData.Instance.IV);
        File.WriteAllBytes(luaExportPath, encrypt);

        DirectoryDelete(tmpPath);

        Debug.Log(luaExportPath + " export.");

        System.Threading.Thread.Sleep(100);
        AssetDatabase.Refresh();
    }