NewLife/LuckyClover

v1.2 打包压缩时支持-d切换当前目录
大石头 authored at 2025-07-12 10:52:30
25beaa4
Tree
1 Parent(s) a1193b7
Summary: 3 changed files with 26 additions and 4 deletions.
Modified +1 -1
Modified +12 -1
Modified +13 -2
Modified +1 -1
diff --git a/LuckyClover/Properties/launchSettings.json b/LuckyClover/Properties/launchSettings.json
index b06efee..0746069 100644
--- a/LuckyClover/Properties/launchSettings.json
+++ b/LuckyClover/Properties/launchSettings.json
@@ -2,7 +2,7 @@
   "profiles": {
     "LuckyClover": {
       "commandName": "Project",
-      "commandLineArgs": "tar D:\\X\\Stardust\\Bin\\Agent\\aa.tar.gz D:\\X\\Stardust\\Bin\\Agent\\net8.0\\*.exe D:\\X\\Stardust\\Bin\\Agent\\net8.0\\*.dll D:\\X\\Stardust\\Bin\\Agent\\net8.0\\staragent.runtimeconfig.json"
+      "commandLineArgs": "zip aa.zip *.exe *.dll -d ../../../GitCandy/Bin/Web *.pdb appsettings.json *.runtimeconfig.json *.deps.json -r ./runtimes/win-x64/* ./runtimes/linux-x64/"
     }
   }
 }
\ No newline at end of file
Modified +12 -1
diff --git a/LuckyClover/TarCommand.cs b/LuckyClover/TarCommand.cs
index 89f3f6e..9997529 100644
--- a/LuckyClover/TarCommand.cs
+++ b/LuckyClover/TarCommand.cs
@@ -63,6 +63,17 @@ internal class TarCommand
                     recurse = true;
                     continue;
                 }
+                if (args[i] == "-R")
+                {
+                    recurse = false;
+                    continue;
+                }
+                if (args[i] == "-d")
+                {
+                    root = Path.GetFullPath(args[++i]);
+                    Log.WriteLine("当前工作目录 \e[31;1m{0}\e[0m", root);
+                    continue;
+                }
 
                 // 分离路径中的目录和文件掩码
                 var src = args[i];
@@ -79,7 +90,7 @@ internal class TarCommand
                     src = ".";
                 }
 
-                var di = new DirectoryInfo(src);
+                var di = new DirectoryInfo(Path.Combine(root, src));
                 var fullName = di.FullName;
                 Log.WriteLine("压缩目录:\e[32;1m{0}\e[0m 匹配:\e[32;1m{1}\e[0m", fullName, pt);
 
Modified +13 -2
diff --git a/LuckyClover/ZipCommand.cs b/LuckyClover/ZipCommand.cs
index 210509f..dcf3913 100644
--- a/LuckyClover/ZipCommand.cs
+++ b/LuckyClover/ZipCommand.cs
@@ -53,6 +53,17 @@ internal class ZipCommand
                     recurse = true;
                     continue;
                 }
+                if (args[i] == "-R")
+                {
+                    recurse = false;
+                    continue;
+                }
+                if (args[i] == "-d")
+                {
+                    root = Path.GetFullPath(args[++i]);
+                    Log.WriteLine("当前工作目录 \e[31;1m{0}\e[0m", root);
+                    continue;
+                }
 
                 // 分离路径中的目录和文件掩码
                 var src = args[i];
@@ -69,7 +80,7 @@ internal class ZipCommand
                     src = ".";
                 }
 
-                var di = new DirectoryInfo(src);
+                var di = new DirectoryInfo(Path.Combine(root, src));
                 var fullName = di.FullName;
                 Log.WriteLine("压缩目录:\e[32;1m{0}\e[0m 匹配:\e[32;1m{1}\e[0m", fullName, pt);
 
@@ -82,7 +93,7 @@ internal class ZipCommand
                 // 没有匹配项时,该路径作为一个子目录
                 if (String.IsNullOrEmpty(pt))
                 {
-                    fullName = di.Parent.FullName;
+                    //fullName = di.Parent.FullName;
 
                     var length = di.FullName.Length - fullName.Length;
                     var entryName2 = EntryFromPath(di.FullName, fullName.Length, length, true);