Exemple #1
0
 public static void EncryptFile(System.IO.FileInfo src, DirectoryInfo des)
 {
     try
     {
         if (File.Exists(src.FullName))
         {
             byte[] srcbyte = File.ReadAllBytes(src.FullName);
             byte[] retbyte;
             if (IsEncryptBatch)
             {
                 retbyte = LuaEncrype.Encrypt(srcbyte);
             }
             else
             {
                 retbyte = LuaEncrype.Decrypt(srcbyte);
             }
             string despath = des.FullName + "//" + src.Name;
             File.WriteAllBytes(despath, retbyte);
         }
     }
     catch (Exception e)
     {
         UnityEngine.Debug.LogError("加密文件出错" + e.Message);
     }
 }
Exemple #2
0
        public static void HandleLuaBundle()
        {
            string tempLuaDir = LuaConst.luaTempDir;

            if (Directory.Exists(tempLuaDir))
            {
                Directory.Delete(LuaConst.luaTempDir);
            }
            Directory.CreateDirectory(tempLuaDir);
            string sourceDir = LuaConst.luaDir;

            string[] files = Directory.GetFiles(sourceDir, "*.lua", SearchOption.AllDirectories);
            int      len   = sourceDir.Length;

            if (sourceDir[len - 1] == '/' || sourceDir[len - 1] == '\\')
            {
                --len;
            }
            for (int j = 0; j < files.Length; j++)
            {
                string str  = files[j].Remove(0, len);
                string dest = tempLuaDir + str + ".bytes";
                string dir  = Path.GetDirectoryName(dest);
                Directory.CreateDirectory(dir);
                byte[] srcbyte = File.ReadAllBytes(files[j]);
                byte[] enbyte  = LuaEncrype.Encrypt(srcbyte);
                File.WriteAllBytes(dest, enbyte);
            }
            tempLuaDir = LuaConst.toluaTempDir;
            if (!Directory.Exists(tempLuaDir))
            {
                Directory.CreateDirectory(tempLuaDir);
            }
            sourceDir = LuaConst.toluaDir;
            files     = Directory.GetFiles(sourceDir, "*.lua", SearchOption.AllDirectories);
            len       = sourceDir.Length;

            if (sourceDir[len - 1] == '/' || sourceDir[len - 1] == '\\')
            {
                --len;
            }
            for (int j = 0; j < files.Length; j++)
            {
                string str  = files[j].Remove(0, len);
                string dest = tempLuaDir + str + ".bytes";
                string dir  = Path.GetDirectoryName(dest);
                Directory.CreateDirectory(dir);
                byte[] srcbyte = File.ReadAllBytes(files[j]);
                File.WriteAllBytes(dest, srcbyte);
            }
            AssetDatabase.Refresh();
        }