Exemplo n.º 1
0
 public static void EncryptFiles(string outputPath)
 {
     if (AppDefineConst.IsEncrypted)
     {
         DirectoryInfo rootFolder = new DirectoryInfo(outputPath);
         if (rootFolder.Exists)
         {
             EditorUtility.DisplayProgressBar("Encrypt Asset", "Encrypt Asset...", 0);
             FileInfo[] fileInfos = rootFolder.GetFiles("*.*", SearchOption.AllDirectories);
             if (fileInfos.Length > 0)
             {
                 float delta = 100f / fileInfos.Length;
                 for (int i = 0; i < fileInfos.Length; i++)
                 {
                     FileInfo fileInfo = fileInfos[i];
                     if (fileInfo.Extension == ".meta" || fileInfo.Extension == ".manifest")
                     {
                         continue;
                     }
                     byte[] fileContent = FileUtility.ReadFileBytes(fileInfo.FullName);
                     fileContent = Utility.AESEncrypt(fileContent, AppDefineConst.AssetSecretKey);
                     FileUtility.WriteBytesToFile(fileInfo.FullName, fileContent, fileContent.Length);
                     EditorUtility.DisplayProgressBar("Encrypt Asset", "Encrypt Asset...", (i + 1) * delta);
                 }
                 EditorUtility.ClearProgressBar();
             }
         }
         Debug.LogFormat("<color=#00ee00ff>Asset Encrypt complated! Path:{0}</color>", rootFolder.FullName);
     }
 }