|
@@ -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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|