From dc4e9a0eb524d6bb752a80b6d7aa6b45b14a2839 Mon Sep 17 00:00:00 2001
From: client_Wu Xijin <364452445@qq.com>
Date: 星期五, 02 十一月 2018 10:06:08 +0800
Subject: [PATCH] 3335 资源打包使用7zip压缩

---
 System/Launch/AssetDeCompressTask.cs.meta |   12 ++++
 Core/GameEngine/Login/Launch.cs           |   28 +++------
 System/Launch/AssetDeCompressTask.cs      |   86 ++++++++++++++++++++++++++++
 3 files changed, 108 insertions(+), 18 deletions(-)

diff --git a/Core/GameEngine/Login/Launch.cs b/Core/GameEngine/Login/Launch.cs
index f9a9bd8..42564e8 100644
--- a/Core/GameEngine/Login/Launch.cs
+++ b/Core/GameEngine/Login/Launch.cs
@@ -188,16 +188,12 @@
                         yield return null;
                     }
 
-                    var files = new List<FileInfo>();
-                    FileExtersion.GetAllDirectoryFileInfos(ResourcesPath.Instance.ExternalStorePath, files);
-                    foreach (var item in files)
+                    progressBuf = progress;
+                    var decompressProgress = AssetDeCompressTask.Decompress(ResourcesPath.Instance.ExternalStorePath);
+                    while (!decompressProgress.done)
                     {
-                        var fullName = item.FullName;
-                        if (fullName.EndsWith(".7z"))
-                        {
-                            SevenZipUtility.DeCompress(fullName, Path.GetDirectoryName(fullName));
-                            File.Delete(fullName);
-                        }
+                        progress = progressBuf + decompressProgress.progress * 0.1f;
+                        yield return null;
                     }
                 }
                 break;
@@ -302,16 +298,12 @@
 
                         LocalSave.SetString("AssetCopyCompleted_IOS", VersionConfig.Get().version);
 
-                        var files = new List<FileInfo>();
-                        FileExtersion.GetAllDirectoryFileInfos(ResourcesPath.Instance.ExternalStorePath, files);
-                        foreach (var item in files)
+                        progressBuf = progress;
+                        var decompressProgress = AssetDeCompressTask.Decompress(ResourcesPath.Instance.ExternalStorePath);
+                        while (!decompressProgress.done)
                         {
-                            var fullName = item.FullName;
-                            if (fullName.EndsWith(".7z"))
-                            {
-                                SevenZipUtility.DeCompress(fullName, Path.GetDirectoryName(fullName));
-                                File.Delete(fullName);
-                            }
+                            progress = progressBuf + decompressProgress.progress * 0.1f;
+                            yield return null;
                         }
                     }
                     break;
diff --git a/System/Launch/AssetDeCompressTask.cs b/System/Launch/AssetDeCompressTask.cs
new file mode 100644
index 0000000..2711aae
--- /dev/null
+++ b/System/Launch/AssetDeCompressTask.cs
@@ -0,0 +1,86 @@
+锘縰sing System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using System.IO;
+using System.Threading;
+
+public class AssetDeCompressTask
+{
+
+    public static DecompressProgress Decompress(string path)
+    {
+        var progress = new DecompressProgress();
+        var files = new List<FileInfo>();
+        FileExtersion.GetAllDirectoryFileInfos(path, files);
+
+        for (var i = files.Count - 1; i >= 0; i--)
+        {
+            var fullName = files[i].FullName;
+            if (fullName.EndsWith(".7z"))
+            {
+                files.RemoveAt(i);
+            }
+        }
+
+        var total = files.Count;
+        if (total == 0)
+        {
+            progress.progress = 1f;
+            progress.done = true;
+            return progress;
+        }
+
+        ThreadPool.QueueUserWorkItem((object a) =>
+        {
+            var index = 0;
+            foreach (var item in files)
+            {
+                var fullName = item.FullName;
+                if (fullName.EndsWith(".7z"))
+                {
+                    SevenZipUtility.DeCompress(fullName, Path.GetDirectoryName(fullName));
+                    File.Delete(fullName);
+                    index++;
+                    progress.progress = index / (float)total;
+                }
+            }
+
+            progress.done = true;
+        });
+
+        return progress;
+    }
+
+    public class DecompressProgress
+    {
+        object progressLock = new object();
+        float m_Progress = 0f;
+        public float progress {
+            get {
+                return m_Progress;
+            }
+            set {
+                lock (progressLock)
+                {
+                    m_Progress = value;
+                }
+            }
+        }
+
+        object doneLock = new object();
+        bool m_Done = false;
+        public bool done {
+            get {
+                return m_Done;
+            }
+            set {
+                lock (doneLock)
+                {
+                    m_Done = value;
+                }
+            }
+        }
+
+    }
+
+}
diff --git a/System/Launch/AssetDeCompressTask.cs.meta b/System/Launch/AssetDeCompressTask.cs.meta
new file mode 100644
index 0000000..4938509
--- /dev/null
+++ b/System/Launch/AssetDeCompressTask.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 2ca4a4bf756f36248be9ddbbf60e835a
+timeCreated: 1541123413
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

--
Gitblit v1.8.0