From 2a3068258638387359aee369260dd5d50bc39247 Mon Sep 17 00:00:00 2001
From: wanli <wanliofficial@aliyun.com>
Date: Thu, 26 Aug 2021 14:49:31 +0800
Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E6=9B=B4=E6=96=B0utils/epk?=
 =?UTF-8?q?.py?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 backend/controller/apps_manager.py |  2 +-
 backend/utils/epk.py               | 11 ++++++++---
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/backend/controller/apps_manager.py b/backend/controller/apps_manager.py
index c2e9511..c1ec303 100644
--- a/backend/controller/apps_manager.py
+++ b/backend/controller/apps_manager.py
@@ -343,6 +343,6 @@ class AppsManager(object):
             with open(os.sep.join([target_dir, "epk.json"]), "w") as f:
                 json.dump(app.to_dict(exclude=["uuid", "create_at", "update_at", "delete_at"]), f)
 
-            return { 'app_name': app.app_name, 'app_file': "{}.epk".format(app.app_name), 'app_url': parse.urljoin(config['UPLOAD_SERVER'], epk_path) }, "application build {}.".format("success" if app_info else "fail")
+            return { 'app_name': app.app_name, 'app_file': "{}.epk".format(app.app_name), 'file_length': app_info.get("fileLength", 0), 'app_url': parse.urljoin(config['UPLOAD_SERVER'], epk_path) }, "application build {}.".format("success" if app_info else "fail")
 
 appsManager = AppsManager()
diff --git a/backend/utils/epk.py b/backend/utils/epk.py
index 698939f..31560ed 100644
--- a/backend/utils/epk.py
+++ b/backend/utils/epk.py
@@ -65,6 +65,7 @@ class EpkApp(object):
         self._appName = appName
         self._appDir = os.path.abspath(appDir)
         self.algorithm = algorithm
+        self.fileLength = 0
         eprint(sys.argv)
         eprint(appName)
         eprint(appDir)
@@ -106,7 +107,7 @@ class EpkApp(object):
             fsize = jspath.info.size
             fbasename, fext = os.path.splitext(jspath.info.name)
 
-            if fext in ["", ".exe", ".dll", ".nv", ".conf"]:
+            if fext in [".exe", ".dll", ".nv", ".conf"]:
                 continue
 
             finfo = {
@@ -122,6 +123,7 @@ class EpkApp(object):
                 files.insert(0, finfo)
             else:
                 files.append(finfo)
+            
             if fext == ".evue":
                 self.fileMD5(finfo)
 
@@ -143,9 +145,9 @@ class EpkApp(object):
             filecontent = f.read()
 
         newmd5 = self.md5(filecontent)
-        
         with open(md5path, "wb") as f:
             f.write(newmd5)
+
         return newmd5
     
     def sign(self, content):
@@ -187,10 +189,12 @@ class EpkApp(object):
 
         fileBytes += struct.pack("<B", len(_name))
         fileBytes += struct.pack("<%ds" % len(_name), fname.encode("utf-8"))
+
         with open(fpath, "rb") as fc:
             fileContentBytes = fc.read()
             eprint(info["name"])
             eprint(len(fileContentBytes))
+            self.fileLength += len(fileContentBytes)
             fileBytes += struct.pack("<L", len(fileContentBytes))
         
         if fext == "md5":
@@ -250,7 +254,8 @@ class EpkApp(object):
                 "md5": epkmd5Bytes,
                 "raw_crc": hex(crcBytes),
                 "compress_level": level,
-                "buff_length": len(epkFileBytes)
+                "buff_length": len(epkFileBytes),
+                "fileLength": self.fileLength
             }
 
             pprint.pprint(ret)
-- 
2.24.1