Browse Source

Update new PackTool

Justin 3 years ago
parent
commit
52bb588b5c

+ 374 - 105
PackTool/Program.cs

@@ -1,4 +1,5 @@
-using System.IO.Compression;
+using System.Diagnostics;
+using System.IO.Compression;
 
 namespace PackTool
 {
@@ -40,81 +41,55 @@ namespace PackTool
             }
         }
 
-
-        static void Main(string[] args)
+        private static void CopyFiles(string reveiveSource, string copyDest, string repoName, string productName, bool unzip)
         {
-            if(args.Length != 11)
+            var distRootFolder = Environment.GetEnvironmentVariable("DistFolder");
+            if (string.IsNullOrEmpty(distRootFolder))
             {
-                Console.WriteLine("Argument List:");
-                Console.WriteLine("[01] -- RepoName \n\t\t\t\tThe name of the packing repo.");
-
-                Console.WriteLine("[02] -- RepoVersion \n\t\t\t\tThe version of the packing repo.");
-
-                Console.WriteLine("[03] -- Src \n\t\t\t\tThe source of the output file/folder.");
-
-                Console.WriteLine("[04] -- Unzip \n\t\t\t\tUnzip the source while it is a zip file.");
-
-                Console.WriteLine("[05] -- Dest \n\t\t\t\tThe dest folder/file to copy/unzip.");
-
-                Console.WriteLine("[06] -- UpdateVersion \n\t\t\t\tUpdate the version in the project folder.");
-
-                Console.WriteLine("[07] -- ProjectName \n\t\t\t\tThe name of the project(The repo can be one of the sub-project of the project).");
-
-                Console.WriteLine("[08] -- ProjectFolder \n\t\t\t\tThe folder of the project.");
-
-                Console.WriteLine("[09] -- Repack \n\t\t\t\tRepack the project folder which means create a new release file in dist.ius.plus.");
-
-                Console.WriteLine("[10] -- RepackFolder \n\t\t\t\tThe folder to store the repacked files.");
-
-                Console.WriteLine("[11] -- AttachTimestamp \n\t\t\t\tAdd the timestamp on repacked file name.");
-                return;
+                Console.WriteLine("The environment variable [DistFolder] is missing, use default dist folder.");
+                //Using default repackFolder
+                distRootFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Packages");
             }
-
-            var repoName = args[0];
-            var repoVersion = args[1];
-
-            var src = args[2];
-            if(!File.Exists(src) && !Directory.Exists(src))
+            if (!Directory.Exists(distRootFolder))
             {
-                Console.WriteLine("The src args[2] does not exist.");
-                return;
+                Directory.CreateDirectory(distRootFolder);
             }
-            if(!bool.TryParse(args[3], out var unzip))
+            var repoDistFolder = Path.Combine(distRootFolder, repoName, "Dist");
+            if (!Directory.Exists(repoDistFolder))
             {
-                Console.WriteLine("The Unzip args[3] should be a bool value:[true/false]");
-                return;
+                Directory.CreateDirectory(repoDistFolder);
             }
-        
-            var dest = args[4];
-
-            if (!bool.TryParse(args[5], out var updateVersion))
+            var productRootFolder = Environment.GetEnvironmentVariable("ProductFolder");
+            if (string.IsNullOrEmpty(productRootFolder))
             {
-                Console.WriteLine("The UpdateVersion args[5] should be a bool value:[true/false]");
-                return;
+                Console.WriteLine("The environment variable [ProductFolder] is missing, use default product folder.");
+                //Using default repackFolder
+                productRootFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Product");
             }
-
-            var projectName = args[6];
-            var projectFolder = args[7];
-
-            if (!bool.TryParse(args[8], out var repack))
+            if (!Directory.Exists(productRootFolder))
             {
-                Console.WriteLine("The Repack args[8] should be a bool value:[true/false]");
-                return;
+                Directory.CreateDirectory(productRootFolder);
+            }
+            var productFolder = Path.Combine(productRootFolder, productName);
+            if (!Directory.Exists(productFolder))
+            {
+                Directory.CreateDirectory(productFolder);
             }
 
-            var repackFolder = args[9];
+            var source = Path.Combine(repoDistFolder, reveiveSource);
+            var dest = Path.Combine(productFolder, copyDest);
 
-            if (!bool.TryParse(args[10], out var attachTimestamp))
+            if (!File.Exists(source) && !Directory.Exists(source))
             {
-                Console.WriteLine("The AttachTimestamp args[10] should be a bool value:[true/false]");
+                Console.WriteLine($"The received file/s {reveiveSource} can not be found.");
                 return;
             }
 
-            if(File.Exists(src))
+            if (File.Exists(source))
             {
-                if(unzip)
+                if (unzip)
                 {
-                    ZipFile.ExtractToDirectory(src, dest, true);
+                    ZipFile.ExtractToDirectory(source, dest, true);
                 }
                 else
                 {
@@ -127,83 +102,377 @@ namespace PackTool
                             Directory.CreateDirectory(destFolder);
                         }
                     }
-                    File.Copy(src, dest, true);
+                    File.Copy(source, dest, true);
                 }
             }
             else
             {
-                if(!Directory.Exists(dest))
+                if (!Directory.Exists(dest))
                 {
                     Directory.CreateDirectory(dest);
                 }
-                DirectoryCopy(src, dest, true);
+                DirectoryCopy(source, dest, true);
             }
+        }
 
+        private static void UpdateVersion(string productName, string repoName, string repoVersion)
+        {
+            var productRootFolder = Environment.GetEnvironmentVariable("ProductFolder");
+            if (string.IsNullOrEmpty(productRootFolder))
+            {
+                Console.WriteLine("The environment variable [ProductFolder] is missing, use default product folder.");
+                //Using default repackFolder
+                productRootFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Product");
+            }
+            if (!Directory.Exists(productRootFolder))
+            {
+                Directory.CreateDirectory(productRootFolder);
+            }
+            var productFolder = Path.Combine(productRootFolder, productName);
+            if(!Directory.Exists(productFolder))
+            {
+                Directory.CreateDirectory(productFolder);
+            }
 
-            //Write version info.
-            if (updateVersion)
+            var projectVersionFile = Path.Combine(productFolder, "Versions.txt");
+            var versions = new List<string>();
+            if (File.Exists(projectVersionFile))
             {
-                if (!Directory.Exists(projectFolder))
+                versions = File.ReadLines(projectVersionFile).ToList();
+                bool updated = false;
+                for (var i = 0; i < versions.Count; i++)
                 {
-                    Directory.CreateDirectory(projectFolder);
-                }
-                var projectVersionFile = Path.Combine(projectFolder, "Versions.txt");
-                var versions = new List<string>();
-                if (File.Exists(projectVersionFile))
-                {
-                    versions = File.ReadLines(projectVersionFile).ToList();
-                    bool updated = false;
-                    for (var i = 0; i < versions.Count; i++)
+                    var line = versions[i];
+                    var nameAndVersion = line.Split('=');
+                    var name = nameAndVersion[0];
+                    if (name == repoName)
                     {
-                        var line = versions[i];
-                        var nameAndVersion = line.Split('=');
-                        var name = nameAndVersion[0];
-                        if (name == repoName)
-                        {
-                            versions[i] = repoName + "=" + repoVersion;
-                            File.WriteAllLines(projectVersionFile, versions);
-                            updated = true;
-                            break;
-                        }
-                    }
-                    if (!updated)
-                    {
-                        versions.Add(repoName + "=" + repoVersion);
+                        versions[i] = repoName + "=" + repoVersion;
                         File.WriteAllLines(projectVersionFile, versions);
+                        updated = true;
+                        break;
                     }
                 }
-                else
+                if (!updated)
                 {
                     versions.Add(repoName + "=" + repoVersion);
                     File.WriteAllLines(projectVersionFile, versions);
                 }
             }
+            else
+            {
+                versions.Add(repoName + "=" + repoVersion);
+                File.WriteAllLines(projectVersionFile, versions);
+            }
+        }
+
+        private static void RepackProduct(string productName, bool attachTimestamp)
+        {
+            var productRootFolder = Environment.GetEnvironmentVariable("ProductFolder");
+            if (string.IsNullOrEmpty(productRootFolder))
+            {
+                Console.WriteLine("The environment variable [ProductFolder] is missing, use default product folder.");
+                //Using default repackFolder
+                productRootFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Product");
+            }
+            if (!Directory.Exists(productRootFolder))
+            {
+                Directory.CreateDirectory(productRootFolder);
+            }
+            var productFolder = Path.Combine(productRootFolder, productName);
+            if (!Directory.Exists(productFolder))
+            {
+                Directory.CreateDirectory(productFolder);
+            }
 
-            if (repack)
+            var repackRootFolder = Environment.GetEnvironmentVariable("RepackFolder");
+            if(string.IsNullOrEmpty(repackRootFolder))
+            {
+                Console.WriteLine("The environment variable [RepackFolder] is missing, use default repack folder.");
+                //Using default repackFolder
+                repackRootFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Repack");
+            }
+            if (!Directory.Exists(repackRootFolder))
+            {
+                Directory.CreateDirectory(repackRootFolder);
+            }
+            var repackFolder = Path.Combine(repackRootFolder, productName);
+            if(!Directory.Exists(repackFolder))
             {
-                if (!Directory.Exists(repackFolder))
+                Directory.CreateDirectory(repackFolder);
+            }
+            var repackFilePath = Path.Combine(repackFolder, $"{productName}.zip");
+            if (attachTimestamp)
+            {
+                var timestamp = DateTime.Now.ToString("yyyyMMdd");
+                var buildTime = 1;
+                var formattedBuildTime = buildTime.ToString("D2");
+                repackFilePath = Path.Combine(repackFolder, $"{productName}_{timestamp}.{formattedBuildTime}.zip");
+                while (File.Exists(repackFilePath))
                 {
-                    Directory.CreateDirectory(repackFolder);
+                    buildTime++;
+                    formattedBuildTime = buildTime.ToString("D2");
+                    repackFilePath = Path.Combine(repackFolder, $"{productName}_{timestamp}.{formattedBuildTime}.zip");
                 }
-                var repackFilePath = Path.Combine(repackFolder, $"{projectName}.zip");
-                if(attachTimestamp)
+            }
+            if (File.Exists(repackFilePath))
+            {
+                File.Delete(repackFilePath);
+            }
+            ZipFile.CreateFromDirectory(productFolder, repackFilePath);
+        }
+
+        private static void HandleCopy(Dictionary<string,string> argMap)
+        {
+            //Copy the file/s
+            if (!argMap.TryGetValue("/rs", out var receivedSource))
+            {
+                Console.WriteLine($"The [/rs] - received source argument is missing.");
+                return;
+            }
+            if (!argMap.TryGetValue("/cd", out var extractDest))
+            {
+                Console.WriteLine($"The [/cd] - copy dest argument is missing.");
+                return;
+            }
+            if (!argMap.TryGetValue("/pn", out var productName))
+            {
+                Console.WriteLine($"The [/pn] - product name argument is missing.");
+                return;
+            }
+            if (!argMap.TryGetValue("/rn", out var repoName))
+            {
+                Console.WriteLine($"The [/rn] - repo name argument is missing.");
+                return;
+            }
+            var unzip = false;
+            if (argMap.TryGetValue("/unzip", out var unzipStr))
+            {
+                if (!bool.TryParse(unzipStr, out unzip))
                 {
-                    var timestamp = DateTime.Now.ToString("yyyyMMdd");
-                    var buildTime = 1;
-                    var formattedBuildTime = buildTime.ToString("D2");
-                    repackFilePath = Path.Combine(repackFolder, $"{projectName}_{timestamp}.{formattedBuildTime}.zip");
-                    while(File.Exists(repackFilePath))
-                    {
-                        buildTime++;
-                        formattedBuildTime = buildTime.ToString("D2");
-                        repackFilePath = Path.Combine(repackFolder, $"{projectName}_{timestamp}.{formattedBuildTime}.zip");
-                    }
+                    Console.WriteLine($"The unzip argument {unzipStr} is not a bool value.");
                 }
-                if(File.Exists(repackFilePath))
+            }
+            CopyFiles(receivedSource, extractDest, repoName, productName, unzip);
+        }
+
+        private static void HandleUpdateVersion(Dictionary<string,string> argMap)
+        {
+            //Only update version.
+            if (!argMap.TryGetValue("/pn", out var productName))
+            {
+                Console.WriteLine($"The [/pn] - product name argument is missing.");
+                return;
+            }
+            if (!argMap.TryGetValue("/rn", out var repoName))
+            {
+                Console.WriteLine($"The [/rn] - repo name argument is missing.");
+                return;
+            }
+            if (!argMap.TryGetValue("/rv", out var repoVersion))
+            {
+                Console.WriteLine($"The [/rv] - repo version argument is missing.");
+                return;
+            }
+            UpdateVersion(productName, repoName, repoVersion);
+        }
+
+        private static void HandleRepack(Dictionary<string,string> argMap)
+        {
+            if (!argMap.TryGetValue("/pn", out var productName))
+            {
+                Console.WriteLine($"The [/pn] - product name argument is missing.");
+                return;
+            }
+            var attachTimestamp = true;
+            if (argMap.TryGetValue("/at", out var attachTimestampStr))
+            {
+                if (!bool.TryParse(attachTimestampStr, out attachTimestamp))
+                {
+                    Console.WriteLine($"The attachTimestamp argument {attachTimestampStr} is not a bool value.");
+                }
+            }
+            RepackProduct(productName, attachTimestamp);
+        }
+
+
+        private static void HandleFull(Dictionary<string, string> argMap)
+        {
+            if (!argMap.TryGetValue("/rs", out var receivedSource))
+            {
+                Console.WriteLine($"The [/rs] - received source argument is missing.");
+                return;
+            }
+            if (!argMap.TryGetValue("/cd", out var extractDest))
+            {
+                Console.WriteLine($"The [/cd] - copy dest argument is missing.");
+                return;
+            }
+            if (!argMap.TryGetValue("/pn", out var productName))
+            {
+                Console.WriteLine($"The [/pn] - product name argument is missing.");
+                return;
+            }
+            if (!argMap.TryGetValue("/rn", out var repoName))
+            {
+                Console.WriteLine($"The [/rn] - repo name argument is missing.");
+                return;
+            }
+            if (!argMap.TryGetValue("/rv", out var repoVersion))
+            {
+                Console.WriteLine($"The [/rv] - repo version argument is missing.");
+                return;
+            }
+
+            var unzip = false;
+            if (argMap.TryGetValue("/unzip", out var unzipStr))
+            {
+                if (!bool.TryParse(unzipStr, out unzip))
+                {
+                    Console.WriteLine($"The unzip argument {unzipStr} is not a bool value.");
+                }
+            }
+            CopyFiles(receivedSource, extractDest, repoName, productName, unzip);
+            UpdateVersion(productName, repoName, repoVersion);
+            var attachTimestamp = true;
+            if (argMap.TryGetValue("/at", out var attachTimestampStr))
+            {
+                if (!bool.TryParse(attachTimestampStr, out attachTimestamp))
                 {
-                    File.Delete(repackFilePath);
+                    Console.WriteLine($"The attachTimestamp argument {attachTimestampStr} is not a bool value.");
                 }
-                ZipFile.CreateFromDirectory(projectFolder, repackFilePath);
+            }
+            RepackProduct(productName, attachTimestamp);
+        }
+
+        private static void StartInno(string innoSourceFileName, string setupSource, string productName, string productVersion,string outputDir)
+        {
+            var productRootFolder = Environment.GetEnvironmentVariable("ProductFolder");
+            if (string.IsNullOrEmpty(productRootFolder))
+            {
+                Console.WriteLine("The environment variable [ProductFolder] is missing, use default product folder.");
+                //Using default repackFolder
+                productRootFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Product");
+            }
+            if (!Directory.Exists(productRootFolder))
+            {
+                Directory.CreateDirectory(productRootFolder);
+            }
+            var productFolder = Path.Combine(productRootFolder, productName);
+            if (!Directory.Exists(productFolder))
+            {
+                Directory.CreateDirectory(productFolder);
+            }
+            var innoSourceFilePath = Path.Combine(productFolder, innoSourceFileName);
+            var projectSetupSource = Path.Combine(productFolder, setupSource);
+            var setupOutputDir = Path.Combine(productFolder, outputDir);
+
+            if(!File.Exists(innoSourceFilePath))
+            {
+                Console.WriteLine("The inno setup source file does not exist.");
+                return;
+            }
+            if(!Directory.Exists(projectSetupSource))
+            {
+                Console.WriteLine("The setup project source folder does not exist");
+                return;
+            }
+            if(Directory.GetFiles(projectSetupSource).Length == 0)
+            {
+                Console.WriteLine("No file in setup project source folder.");
+                return;
+            }
+            if (!Directory.Exists(setupOutputDir))
+            {
+                Directory.CreateDirectory(setupOutputDir);
+            }
+            var iscc_argument = $"/dProjectFolder={projectSetupSource} /dSetupAppVersion={productVersion} /dSetupOutputDir={setupOutputDir} {innoSourceFilePath}";
+            Console.WriteLine($"Inno arg: {iscc_argument}");
+            var process = Process.Start(new ProcessStartInfo("ISCC", iscc_argument) { UseShellExecute = true });
+            process?.WaitForExit();
+        }
+
+        private static void HandleInno(Dictionary<string, string> argMap)
+        {
+            if (!argMap.TryGetValue("/pn", out var productName))
+            {
+                Console.WriteLine($"The [/pn] - product name argument is missing.");
+                return;
+            }
+            if (!argMap.TryGetValue("/pv", out var productVersion))
+            {
+                Console.WriteLine($"The [/pv] - product version argument is missing.");
+                return;
+            }
+            if (!argMap.TryGetValue("/ss", out var setupSource))
+            {
+                Console.WriteLine($"The [/ss] - setup source argument is missing.");
+                return;
+            }
+            if (!argMap.TryGetValue("/od", out var outputDir))
+            {
+                Console.WriteLine($"The [/od] - output dir argument is missing.");
+                return;
+            }
+            if (!argMap.TryGetValue("/iss", out var issFile))
+            {
+                Console.WriteLine($"The [/iss] - inno setup source argument is missing.");
+                return;
+            }
+            StartInno(issFile, setupSource, productName, productVersion, outputDir);
+        }
+
+        static void Main(string[] args)
+        {
+            var argMap = new Dictionary<string, string>();
+            foreach (var arg in args)
+            {
+                var nameAndValue = arg.Split('=');
+                if (nameAndValue.Length == 2)
+                {
+                    var name = nameAndValue[0].ToLower();
+                    if (string.IsNullOrEmpty(name))
+                    {
+                        Console.WriteLine("An empty arg name is not acceptable.");
+                        return;
+                    }
+                    if (argMap.ContainsKey(name))
+                    {
+                        Console.WriteLine($"Arg name {name} already exists");
+                        return;
+                    }
+                    argMap.Add(name, nameAndValue[1]);
+                }
+            }
+
+            if (!argMap.TryGetValue("/mode", out var mode))
+            {
+                mode = "full";
+            }
+
+            Console.WriteLine($"Run in {mode} mode.");            
+            switch (mode)
+            {
+                case "full":
+                    //Copy files then pack the files then update the version then pack the files.
+                    HandleFull(argMap);
+                    break;
+                case "copy":
+                    HandleCopy(argMap);
+                    break;
+                case "version":
+                    HandleUpdateVersion(argMap);
+                    break;
+                case "repack":
+                    //Obly Pack the files.
+                    HandleRepack(argMap);
+                    break;
+                case "inno":
+                    HandleInno(argMap);
+                    break;
+                default:
+                    Console.WriteLine($"Not suported mode: {mode}");
+                    break;
             }
         }
     }

+ 6 - 2
PackTool/Properties/PublishProfiles/FolderProfile.pubxml

@@ -6,9 +6,13 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
   <PropertyGroup>
     <Configuration>Release</Configuration>
     <Platform>Any CPU</Platform>
-    <PublishDir>bin\Release\net6.0\publish\</PublishDir>
+    <PublishDir>bin\Release\net6.0\publish\win-x64\</PublishDir>
     <PublishProtocol>FileSystem</PublishProtocol>
     <TargetFramework>net6.0</TargetFramework>
-    <SelfContained>false</SelfContained>
+    <SelfContained>true</SelfContained>
+    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
+    <PublishSingleFile>True</PublishSingleFile>
+    <PublishReadyToRun>False</PublishReadyToRun>
+    <PublishTrimmed>False</PublishTrimmed>
   </PropertyGroup>
 </Project>

+ 1 - 1
PackTool/Properties/PublishProfiles/FolderProfile.pubxml.user

@@ -4,6 +4,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
 -->
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
-    <History>True|2021-11-12T02:07:18.1869446Z;True|2021-11-12T10:07:00.4300355+08:00;True|2021-11-12T09:15:50.5423048+08:00;True|2021-11-12T09:15:46.7711484+08:00;True|2021-11-12T08:46:22.7243062+08:00;True|2021-11-11T20:37:31.5190040+08:00;True|2021-11-11T20:29:06.2863757+08:00;True|2021-11-11T20:09:35.2068187+08:00;True|2021-11-11T20:07:41.0773244+08:00;True|2021-11-11T20:07:37.8400052+08:00;True|2021-11-11T19:53:34.9129015+08:00;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>
+    <History>True|2021-11-20T05:21:47.0843933Z;True|2021-11-20T13:15:32.4634119+08:00;True|2021-11-20T13:14:15.2956703+08:00;True|2021-11-20T11:19:03.4904121+08:00;True|2021-11-20T11:14:52.6831421+08:00;True|2021-11-20T11:07:29.4192692+08:00;True|2021-11-20T10:33:18.9399931+08:00;True|2021-11-20T10:30:40.5235250+08:00;True|2021-11-20T10:30:23.7578090+08:00;True|2021-11-12T10:07:18.1869446+08:00;True|2021-11-12T10:07:00.4300355+08:00;True|2021-11-12T09:15:50.5423048+08:00;True|2021-11-12T09:15:46.7711484+08:00;True|2021-11-12T08:46:22.7243062+08:00;True|2021-11-11T20:37:31.5190040+08:00;True|2021-11-11T20:29:06.2863757+08:00;True|2021-11-11T20:09:35.2068187+08:00;True|2021-11-11T20:07:41.0773244+08:00;True|2021-11-11T20:07:37.8400052+08:00;True|2021-11-11T19:53:34.9129015+08:00;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>

+ 16 - 5
PackageServer/PackageManager.cs

@@ -46,8 +46,15 @@ namespace PackageServer
 
         public void StartTransfer(uint hashCode)
         {
+            if(!Directory.Exists(_transferFolder))
+            {
+                Directory.CreateDirectory(_transferFolder);
+            }
             //Clean the package folder
-            Directory.Delete(_packageFolder, true);
+            if(Directory.Exists(_packageFolder))
+            {
+                Directory.Delete(_packageFolder, true);
+            }
             if(!Directory.Exists(_packageFolder))
             {
                 Directory.CreateDirectory(_packageFolder);
@@ -87,7 +94,10 @@ namespace PackageServer
 
                 //Extract to package folder.
                 ZipFile.ExtractToDirectory(_transferFilePath, _packageFolder, true);
-                File.Delete(_transferFilePath);
+                if (File.Exists(_transferFilePath))
+                {
+                    File.Delete(_transferFilePath);
+                }
                 State = PackageTaskState.Running;
             }
             catch
@@ -177,7 +187,7 @@ namespace PackageServer
             {
                 Directory.CreateDirectory(_transferFolder);
             }
-            _packageFolder = Path.Combine(_packagerFolder, "Package");
+            _packageFolder = Path.Combine(_packagerFolder, "Dist");
             if(!Directory.Exists(_packageFolder))
             {
                 Directory.CreateDirectory(_packageFolder);
@@ -186,9 +196,10 @@ namespace PackageServer
 
         public void StartPackage(string version)
         {
-            if(CurrentTask != null)
+            if (CurrentTask != null)
             {
-                throw new InvalidOperationException("Packager is busy.");
+                CurrentTask.Kill();
+                CurrentTask = null;
             }
             CurrentTask = new PackageTask(version, _transferFolder, _packageFolder);
         }