Эх сурвалжийг харах

打包加密fix

# Conflicts:
#	.gitignore
#	GameClient/Assets/Resources/PlayerSettings.asset
guodong 3 жил өмнө
parent
commit
f0228dca1a

+ 2 - 0
.gitignore

@@ -22,3 +22,5 @@
 /GameClient/Assets/StreamingAssets/Bundles_temp.meta
 /GameClient/Assets/StreamingAssets/Bundles_temp
 /GameClient/Assets/Game/CSShare
+/GameClient/Assets/StreamingAssets/Bundles
+/GameClient/BuildlesUnity

+ 41 - 18
GameClient/Assets/Editor/Xasset/Builds/BuildTask.cs

@@ -222,11 +222,11 @@ namespace VEngine.Editor.Builds
                 Debug.LogErrorFormat("Failed to build {0}.", name);
                 return;
             }
-            if (!string.IsNullOrEmpty(GFGGame.LauncherConfig.resKey))
-            {
-                string buildPath = Settings.PlatformBuildPath;
-                CreateEncryptAssets(unityBuildPath, buildPath, manifest, GFGGame.LauncherConfig.resKey);
-            }
+            //if (!string.IsNullOrEmpty(GFGGame.LauncherConfig.resKey))
+            //{
+            //    string buildPath = Settings.PlatformBuildPath;
+            //    CreateEncryptAssets(unityBuildPath, buildPath, manifest, GFGGame.LauncherConfig.resKey);
+            //}
             AfterBuildBundles(bundles, manifest);
         }
 
@@ -236,15 +236,15 @@ namespace VEngine.Editor.Builds
         /// </summary>
         public static void CreateEncryptAssets(string bundlePackagePath, string encryptAssetPath, AssetBundleManifest manifest, string secretKey)
         {
+            if (!Directory.Exists(encryptAssetPath))
+            {
+                Directory.CreateDirectory(encryptAssetPath);
+            }
             string[] assetBundles = manifest.GetAllAssetBundles();
             foreach (string assetBundle in assetBundles)
             {
                 string bundlePath = Path.Combine(bundlePackagePath, assetBundle);
                 byte[] encryptBytes = EncryptHelper.CreateEncryptData(bundlePath, secretKey);
-                if (!Directory.Exists(encryptAssetPath))
-                {
-                    Directory.CreateDirectory(encryptAssetPath);
-                }
                 using (FileStream fs = new FileStream(Path.Combine(encryptAssetPath, assetBundle), FileMode.OpenOrCreate))
                 {
                     fs.SetLength(0);
@@ -253,6 +253,23 @@ namespace VEngine.Editor.Builds
             }
         }
 
+        /// <summary>
+        /// 创建加密的AssetBundle
+        /// </summary>
+        public static void CreateEncryptAsset(string unityBundlesPath, string bundlesPath, string unityBundle, string secretKey)
+        {
+            if (!Directory.Exists(bundlesPath))
+            {
+                Directory.CreateDirectory(bundlesPath);
+            }
+            string unityBundlePath = Path.Combine(unityBundlesPath, unityBundle);
+            byte[] encryptBytes = EncryptHelper.CreateEncryptData(unityBundlePath, secretKey);
+            using (FileStream fs = new FileStream(Path.Combine(bundlesPath, unityBundle), FileMode.OpenOrCreate))
+            {
+                fs.SetLength(0);
+                fs.Write(encryptBytes, 0, encryptBytes.Length);
+            }
+        }
 
         private string GetOriginBundle(string assetBundle)
         {
@@ -286,15 +303,7 @@ namespace VEngine.Editor.Builds
                     {
                         manifestBundle.nameWithAppendHash = assetBundle;
                         manifestBundle.dependencies = Array.ConvertAll(dependencies, input => nameWithBundles[input].id);
-                        var file = Settings.GetBuildPath(assetBundle);
-                        if (File.Exists(file))
-                            using (var stream = File.OpenRead(file))
-                            {
-                                manifestBundle.size = stream.Length;
-                                manifestBundle.crc = Utility.ComputeCRC32(stream);
-                            }
-                        else
-                            Debug.LogErrorFormat("File not found: {0}", file);
+                        
                     }
                     else
                     {
@@ -319,6 +328,20 @@ namespace VEngine.Editor.Builds
                     value.nameWithAppendHash != bundle.nameWithAppendHash)
                 {
                     newFiles.Add(bundle.nameWithAppendHash);
+                    if (!string.IsNullOrEmpty(GFGGame.LauncherConfig.resKey))
+                    {
+                        string buildPath = Settings.PlatformBuildPath;
+                        CreateEncryptAsset(Settings.UnityBuildPath, buildPath, bundle.nameWithAppendHash, GFGGame.LauncherConfig.resKey);
+                    }
+                    var file = Settings.GetBuildPath(bundle.nameWithAppendHash);
+                    if (File.Exists(file))
+                        using (var stream = File.OpenRead(file))
+                        {
+                            bundle.size = stream.Length;
+                            bundle.crc = Utility.ComputeCRC32(stream);
+                        }
+                    else
+                        Debug.LogErrorFormat("File not found: {0}", file);
                     newSize += bundle.size;
                 }
 

+ 1 - 1
GameClient/Assets/Editor/Xasset/Builds/Settings.cs

@@ -42,7 +42,7 @@ namespace VEngine.Editor.Builds
         {
             get
             {
-                var dir = Utility.UnityBuildFolder + $"/{GetPlatformName()}";
+                var dir = Utility.BuildlesUnityFolder + $"/{GetPlatformName()}";
                 if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
 
                 return dir;

+ 4 - 0
GameClient/Assets/Editor/Xasset/MenuItems.cs

@@ -58,6 +58,10 @@ namespace VEngine.Editor
                 if (!Directory.Exists(directory)) return;
                 Directory.Delete(directory, true);
 
+                directory = Settings.UnityBuildPath;
+                if (!Directory.Exists(directory)) return;
+                Directory.Delete(directory, true);
+
                 ClearDownload();
             }
         }

+ 1 - 1
GameClient/Assets/Game/Launcher/LauncherConfig.cs

@@ -47,7 +47,7 @@ namespace GFGGame
             cfgName = "cfg_dev";
 #elif PT_TEMP
             netType = EnumNetType.TEMP;
-            cfgName = "cfg_temp";
+            cfgName = "cfg_temp1";
 #else
             netType = EnumNetType.LOCAL;
             cfgName = "cfg_local";

+ 2 - 2
GameClient/Assets/ThirdParty/Xasset/Runtime/Utilitys/Utility.cs

@@ -6,8 +6,8 @@ namespace VEngine
     public static class Utility
     {
         public static string buildPath = "Bundles";
-        //加密的资源所在的和普通资源同级路径的文件夹名称
-        public static string UnityBuildFolder = "UnityBuildle";
+        //unity原生build出来的AB资源文件夹名称
+        public static string BuildlesUnityFolder = "BuildlesUnity";
 
         public const string unsupportedPlatform = "Unsupported";