From abf22444f9419243eb0b9824230336c875ac087f Mon Sep 17 00:00:00 2001 From: Adison Cavani Date: Sun, 10 Oct 2021 00:07:35 +0200 Subject: [PATCH] Add verbose mode --- .gitignore | 1 + src/ArchiveManager.cs | 11 +++-- src/Program.cs | 103 ++++++++++++++++++++++++++++++------------ src/ProgramOptions.cs | 13 +++++- 4 files changed, 94 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index 4d13c54..5049253 100644 --- a/.gitignore +++ b/.gitignore @@ -332,3 +332,4 @@ ASALocalRun/ # Local History for Visual Studio .localhistory/ +src/Properties/launchSettings.json diff --git a/src/ArchiveManager.cs b/src/ArchiveManager.cs index a7443fa..0f57a72 100644 --- a/src/ArchiveManager.cs +++ b/src/ArchiveManager.cs @@ -4,7 +4,7 @@ namespace DistroGrubThemes { public class ArchiveManager { - public static void CreateTarArchive(string sourceDirectory, string outputFile) + public static void CreateTarArchive(string sourceDirectory, string outputFile, bool verbose) { Chilkat.Tar tar = new Chilkat.Tar { @@ -35,9 +35,12 @@ namespace DistroGrubThemes return; } - Console.ForegroundColor = ConsoleColor.Green; - Console.Write("OK\n"); - Console.ResetColor(); + if (verbose) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.Write("OK\n"); + Console.ResetColor(); + } } } } diff --git a/src/Program.cs b/src/Program.cs index 7510b9d..c696dc1 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -1,7 +1,6 @@ using CommandLine; using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; @@ -19,63 +18,111 @@ namespace DistroGrubThemes static void RunOptions(ProgramOptions opts) { Program program = new Program(); - string path = program.CheckRepoPath(opts.RepositoryPath); - program.UpdateAssets(path); - Console.WriteLine(); - program.UpdateArchive(path); + if (opts.UpdateFonts) + { + program.UpdateFonts(path + @"\font", path + @"\customize", opts.VerboseMode); + } + + if (opts.UpdateIcons) + { + if (opts.VerboseMode) + Console.WriteLine(); + + program.UpdateIcons(path + @"\assets\icons", path + @"\customize", opts.VerboseMode); + } + + if (opts.UpdateArchives) + { + if (opts.VerboseMode) + Console.WriteLine(); + + program.UpdateArchive(path, opts.VerboseMode); + } } - void UpdateArchive(string path) + void UpdateArchive(string path, bool verbose) { + if (!verbose) + Console.Write("Creating .tar archives ... "); + foreach (var directory in DirectoriesDictionary(path + @"\customize", path)) { - Console.Write("Creating " + directory.Value + ".tar archive ... "); - ArchiveManager.CreateTarArchive(directory.Key, path + @"\themes\" + directory.Value + ".tar"); + if (verbose) + Console.Write("Creating " + directory.Value + ".tar archive ... "); + + ArchiveManager.CreateTarArchive(directory.Key, path + @"\themes\" + directory.Value + ".tar", verbose); + } + + if (!verbose) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.Write("OK\n"); + Console.ResetColor(); } } - void UpdateAssets(string path) + void UpdateIcons(string iconsPath, string customizePath, bool verbose) { - UpdateIcons(path + @"\assets\icons", path + @"\customize"); - UpdateFonts(path + @"\font", path + @"\customize"); - } - - void UpdateIcons(string iconsPath, string customizePath) - { - Console.Write("\nUpdating icons ... "); - var icons = FilesArray(iconsPath); + if (!verbose) + Console.Write("Copying icons ... "); foreach (var directory in DirectoriesArray(customizePath)) { - foreach (var icon in icons) + foreach (var icon in FilesArray(iconsPath)) { + if (verbose) + Console.Write("Copying " + icon + " ... "); + File.Copy(iconsPath + @"\" + icon, directory + @"\icons\" + icon, true); + + if (verbose) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.Write("OK\n"); + Console.ResetColor(); + } } } - Console.ForegroundColor = ConsoleColor.Green; - Console.Write("OK\n"); - Console.ResetColor(); + if (!verbose) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.Write("OK\n"); + Console.ResetColor(); + } } - void UpdateFonts(string fontsPath, string customizePath) + void UpdateFonts(string fontsPath, string customizePath, bool verbose) { - Console.Write("Updating fonts ... "); - var fonts = FilesArray(fontsPath); + if (!verbose) + Console.Write("Copying fonts ... "); foreach (var directory in DirectoriesArray(customizePath)) { - foreach (var font in fonts) + foreach (var font in FilesArray(fontsPath)) { + if (verbose) + Console.Write("Copying " + font + " ... "); + File.Copy(fontsPath + @"\" + font, directory + @"\" + font, true); + + if (verbose) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.Write("OK\n"); + Console.ResetColor(); + } } } - Console.ForegroundColor = ConsoleColor.Green; - Console.Write("OK\n"); - Console.ResetColor(); + if (!verbose) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.Write("OK\n"); + Console.ResetColor(); + } } List FilesArray(string folderPath) diff --git a/src/ProgramOptions.cs b/src/ProgramOptions.cs index 643b77e..0d13a8f 100644 --- a/src/ProgramOptions.cs +++ b/src/ProgramOptions.cs @@ -7,7 +7,16 @@ namespace DistroGrubThemes [Option('r', "repository", Required = true, HelpText = "Path to repository.")] public string RepositoryPath { get; set; } - [Option('a', "archive", HelpText = "Create theme archive.")] - public string ArchivedFiles { get; set; } + [Option('a', "archive", HelpText = "Update archives.")] + public bool UpdateArchives { get; set; } + + [Option('f', "fonts", HelpText = "Update fonts.")] + public bool UpdateFonts { get; set; } + + [Option('i', "icons", HelpText = "Update icons.")] + public bool UpdateIcons { get; set; } + + [Option('v', "verbose" , HelpText = "Enable debug messages.")] + public bool VerboseMode { get; set; } } }