Răsfoiți Sursa

Add packtool

Justin 3 ani în urmă
părinte
comite
dfcd0907f5

+ 10 - 0
PackTool/PackTool.csproj

@@ -0,0 +1,10 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net6.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+</Project>

+ 127 - 0
PackTool/Program.cs

@@ -0,0 +1,127 @@
+using System.IO.Compression;
+
+namespace PackTool
+{
+    class Program
+    {
+        private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
+        {
+            // Get the subdirectories for the specified directory.
+            DirectoryInfo dir = new DirectoryInfo(sourceDirName);
+
+            if (!dir.Exists)
+            {
+                throw new DirectoryNotFoundException(
+                    "Source directory does not exist or could not be found: "
+                    + sourceDirName);
+            }
+
+            DirectoryInfo[] dirs = dir.GetDirectories();
+
+            // If the destination directory doesn't exist, create it.       
+            Directory.CreateDirectory(destDirName);
+
+            // Get the files in the directory and copy them to the new location.
+            FileInfo[] files = dir.GetFiles();
+            foreach (FileInfo file in files)
+            {
+                string tempPath = Path.Combine(destDirName, file.Name);
+                file.CopyTo(tempPath, true);
+            }
+
+            // If copying subdirectories, copy them and their contents to new location.
+            if (copySubDirs)
+            {
+                foreach (DirectoryInfo subdir in dirs)
+                {
+                    string tempPath = Path.Combine(destDirName, subdir.Name);
+                    DirectoryCopy(subdir.FullName, tempPath, copySubDirs);
+                }
+            }
+        }
+
+
+        static void Main(string[] args)
+        {
+            var repoName = args[0];
+            var repoVersion = args[1];
+
+            var src = args[2];
+            var unzip = bool.Parse(args[3]);
+            var dest = args[4];
+
+            var projectName = args[5];
+            var projectFolder = args[6];
+
+            var repack = bool.Parse(args[7]);
+            var repackFolder = args[8];
+            var attachTimestamp = bool.Parse(args[9]);
+
+            if(File.Exists(src))
+            {
+                if(unzip)
+                {
+                    ZipFile.ExtractToDirectory(src, dest);
+                }
+                else
+                {
+                    File.Copy(src, dest, true);
+                }
+            }
+            else
+            {
+                if(!Directory.Exists(dest))
+                {
+                    Directory.CreateDirectory(dest);
+                }
+                DirectoryCopy(src, dest, true);
+            }
+            
+
+            //Write version info.
+            if(!Directory.Exists(projectFolder))
+            {
+                Directory.CreateDirectory(projectFolder);
+            }
+            var projectVersionFile = Path.Combine(projectFolder, "Versions.txt");
+            var versions = new List<string>();
+            if(File.Exists(projectVersionFile))
+            {
+                versions = File.ReadLines(projectVersionFile).ToList();
+                for(var i=0;i< versions.Count; i++)
+                {
+                    var line = versions[i];
+                    var nameAndVersion = line.Split('=');
+                    var name = nameAndVersion[0];
+                    var version = nameAndVersion[1];
+                    if(name == repoName && version != repoVersion)
+                    {
+                        versions[i] = repoName + "=" + repoVersion;
+                        File.WriteAllLines(projectVersionFile, versions);
+                        break;
+                    }
+                }
+            }
+            else
+            {
+                versions.Add(repoName + "=" + repoVersion);
+                File.WriteAllLines(projectVersionFile, versions);
+            }
+
+            if (repack)
+            {
+                if (!Directory.Exists(repackFolder))
+                {
+                    Directory.CreateDirectory(repackFolder);
+                }
+                var repackFilePath = Path.Combine(repackFolder, $"{projectName}.zip");
+                if(attachTimestamp)
+                {
+                    var timestamp = DateTime.Now.ToString("yyyyMMddHHmmss");
+                    repackFilePath = Path.Combine(repackFolder, $"{projectName}_{timestamp}.zip");
+                }
+                ZipFile.CreateFromDirectory(projectFolder, repackFilePath);
+            }
+        }
+    }
+}

+ 18 - 0
PackTool/Properties/PublishProfiles/FolderProfile.pubxml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+https://go.microsoft.com/fwlink/?LinkID=208121. 
+-->
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration>Release</Configuration>
+    <Platform>Any CPU</Platform>
+    <PublishDir>bin\Release\net6.0\publish\win-x64\</PublishDir>
+    <PublishProtocol>FileSystem</PublishProtocol>
+    <TargetFramework>net6.0</TargetFramework>
+    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
+    <SelfContained>true</SelfContained>
+    <PublishSingleFile>True</PublishSingleFile>
+    <PublishReadyToRun>False</PublishReadyToRun>
+    <PublishTrimmed>False</PublishTrimmed>
+  </PropertyGroup>
+</Project>

+ 9 - 0
PackTool/Properties/PublishProfiles/FolderProfile.pubxml.user

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+https://go.microsoft.com/fwlink/?LinkID=208121. 
+-->
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <History>True|2021-11-11T11:53:34.9129015Z;True|2021-11-11T19:47:07.3789470+08:00;True|2021-11-11T19:35:55.0629742+08:00;True|2021-11-11T19:20:10.2529336+08:00;True|2021-11-11T19:08:39.6852088+08:00;</History>
+  </PropertyGroup>
+</Project>

+ 1 - 1
PackageClient/PackageClient.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <OutputType>Exe</OutputType>
-    <TargetFramework>net5.0</TargetFramework>
+    <TargetFramework>net6.0</TargetFramework>
   </PropertyGroup>
 
   <ItemGroup>

+ 1 - 1
PackageInterface/PackageInterface.csproj

@@ -1,7 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
-    <TargetFramework>net5.0</TargetFramework>
+    <TargetFramework>net6.0</TargetFramework>
   </PropertyGroup>
 
 </Project>

+ 11 - 5
PackageManager.sln

@@ -1,13 +1,15 @@
 
 Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-VisualStudioVersion = 16.0.31727.386
+# Visual Studio Version 17
+VisualStudioVersion = 17.0.31903.59
 MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PackageServer", "PackageServer\PackageServer.csproj", "{5CA02056-F81F-4243-973E-E03764479925}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PackageServer", "PackageServer\PackageServer.csproj", "{5CA02056-F81F-4243-973E-E03764479925}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PackageClient", "PackageClient\PackageClient.csproj", "{AC1B9D0F-44FB-47EA-90DE-4AF841872FC8}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PackageClient", "PackageClient\PackageClient.csproj", "{AC1B9D0F-44FB-47EA-90DE-4AF841872FC8}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PackageInterface", "PackageInterface\PackageInterface.csproj", "{F047612F-D2EC-4B5E-94A1-9A26382A1102}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PackageInterface", "PackageInterface\PackageInterface.csproj", "{F047612F-D2EC-4B5E-94A1-9A26382A1102}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PackTool", "PackTool\PackTool.csproj", "{FEDFBBE8-0684-4CB3-A5F6-A70FEF9C8983}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -27,6 +29,10 @@ Global
 		{F047612F-D2EC-4B5E-94A1-9A26382A1102}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{F047612F-D2EC-4B5E-94A1-9A26382A1102}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{F047612F-D2EC-4B5E-94A1-9A26382A1102}.Release|Any CPU.Build.0 = Release|Any CPU
+		{FEDFBBE8-0684-4CB3-A5F6-A70FEF9C8983}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{FEDFBBE8-0684-4CB3-A5F6-A70FEF9C8983}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{FEDFBBE8-0684-4CB3-A5F6-A70FEF9C8983}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{FEDFBBE8-0684-4CB3-A5F6-A70FEF9C8983}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 1 - 1
PackageServer/PackageServer.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <OutputType>Exe</OutputType>
-    <TargetFramework>net5.0</TargetFramework>
+    <TargetFramework>net6.0</TargetFramework>
   </PropertyGroup>
 
   <ItemGroup>