From 5f6661195e3abab67149e2eaca61ac4bf17f9b1f Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期三, 23 八月 2023 15:49:57 +0800
Subject: [PATCH] 修改获取文件大小的方法

---
 DataLoader/CS/Importor.cs |   81 +++++++++++++++++++++++++++++++++++-----
 1 files changed, 71 insertions(+), 10 deletions(-)

diff --git a/DataLoader/CS/Importor.cs b/DataLoader/CS/Importor.cs
index 2424b20..34fd387 100644
--- a/DataLoader/CS/Importor.cs
+++ b/DataLoader/CS/Importor.cs
@@ -2,13 +2,11 @@
 using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
-using System.Data;
 using System.IO;
 using System.Linq;
-using System.Security.Cryptography;
 using System.Text;
 using System.Threading.Tasks;
-using static System.Net.Mime.MediaTypeNames;
+using System.Windows.Documents;
 
 namespace DataLoader.CS
 {
@@ -50,11 +48,15 @@
             ViewData vd = new ViewData();
             vd.ID = viewDatas.Count + 1;
             vd.FilePath = path;
-            vd.Ext = ext;
+            vd.Ext = "." + ext;
             vd.Status = "鍑嗗";
             viewDatas.Add(vd);
 
             SetSysMeta(vd);
+
+            DirectoryInfo di = new DirectoryInfo(vd.FilePath);
+            vd.Meta.name = di.Name;
+            vd.Meta.type = ext;
         }
 
         /// <summary>
@@ -78,6 +80,10 @@
                 viewDatas.Add(vd);
 
                 SetSysMeta(vd);
+
+                FileInfo fi = new FileInfo(vd.FilePath);
+                vd.Meta.name = fi.Name;
+                vd.Meta.type = fi.Extension.ToLower().Replace(".", "");
             }
         }
 
@@ -86,20 +92,17 @@
         /// </summary>
         private static void SetSysMeta(ViewData vd)
         {
-            FileInfo fi = new FileInfo(vd.FilePath);
             SysMeta meta = new SysMeta();
             meta.eventid = Guid.NewGuid().ToString();
             meta.metaid = 0;
             meta.verid = 0;
-            meta.name = fi.Name;
-            meta.type = fi.Extension.ToLower().Replace(".", "");
             meta.guid = null;
             meta.path = vd.FilePath; // *
             meta.sizes = GetFileSizes(vd);
-            meta.tab = null; // *
+            meta.tab = null;
             meta.rows = 0;
             meta.create_user = CommonProp.UserId;
-            //meta.create_time = DateTime.Now;
+            meta.create_time = DateTime.Now;
             meta.bak = null;
             meta.geom = null;
             meta.layer = null;
@@ -113,15 +116,73 @@
             vd.Sizes = meta.sizes;
         }
 
+        /// <summary>
+        /// 鑾峰彇鏂囦欢澶у皬
+        /// </summary>
         private static double GetFileSizes(ViewData vd)
         {
-            //Tools.SizeToMb(fi.Length); // *
+            if (File.Exists(vd.FilePath))
+            {
+                if (vd.Ext == StaticData.SHP)
+                {
+                    List<string> files = GetShpFiles(vd.FilePath);
+                    return GetFileSizes(files.ToArray());
+                }
+                else
+                {
+                    FileInfo fi = new FileInfo(vd.FilePath);
+                    return Tools.SizeToMb(fi.Length);
+                }
+            }
 
+            if (Directory.Exists(vd.FilePath))
+            {
+                string[] files = Directory.GetFiles(vd.FilePath, "*", SearchOption.AllDirectories);
+
+                return GetFileSizes(files);
+            }
 
             return 0;
         }
 
         /// <summary>
+        /// 鑾峰彇鏂囦欢澶у皬
+        /// </summary>
+        private static double GetFileSizes(string[] files)
+        {
+            if (null == files || files.Length == 0) return 0;
+
+            double sizes = 0;
+            foreach (string file in files)
+            {
+                FileInfo fi = new FileInfo(file);
+                sizes += Tools.SizeToMb(fi.Length);
+            }
+
+            return sizes;
+        }
+
+        /// <summary>
+        /// 鑾峰彇SHP鏂囦欢闆嗗悎
+        /// </summary>
+        private static List<string> GetShpFiles(string shpPath)
+        {
+            List<string> files = new List<string>();
+            files.Add(shpPath);
+
+            foreach (string ext in StaticData.SHP_EXT)
+            {
+                string file = shpPath.Replace(".shp", ext);
+                if (File.Exists(file))
+                {
+                    files.Add(file);
+                }
+            }
+
+            return files;
+        }
+
+        /// <summary>
         /// 鏄惁涓篏DB鏂囦欢
         /// </summary>
         private static bool IsGdbFile(string path)

--
Gitblit v1.9.3