Add verbose mode

This commit is contained in:
Adison Cavani 2021-10-10 00:07:35 +02:00
parent 2029db1737
commit abf22444f9
No known key found for this signature in database
GPG key ID: 2C36C61283E73DC9
4 changed files with 94 additions and 34 deletions

1
.gitignore vendored
View file

@ -332,3 +332,4 @@ ASALocalRun/
# Local History for Visual Studio # Local History for Visual Studio
.localhistory/ .localhistory/
src/Properties/launchSettings.json

View file

@ -4,7 +4,7 @@ namespace DistroGrubThemes
{ {
public class ArchiveManager 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 Chilkat.Tar tar = new Chilkat.Tar
{ {
@ -35,9 +35,12 @@ namespace DistroGrubThemes
return; return;
} }
if (verbose)
{
Console.ForegroundColor = ConsoleColor.Green; Console.ForegroundColor = ConsoleColor.Green;
Console.Write("OK\n"); Console.Write("OK\n");
Console.ResetColor(); Console.ResetColor();
} }
} }
}
} }

View file

@ -1,7 +1,6 @@
using CommandLine; using CommandLine;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -19,64 +18,112 @@ namespace DistroGrubThemes
static void RunOptions(ProgramOptions opts) static void RunOptions(ProgramOptions opts)
{ {
Program program = new Program(); Program program = new Program();
string path = program.CheckRepoPath(opts.RepositoryPath); string path = program.CheckRepoPath(opts.RepositoryPath);
program.UpdateAssets(path); if (opts.UpdateFonts)
Console.WriteLine(); {
program.UpdateArchive(path); program.UpdateFonts(path + @"\font", path + @"\customize", opts.VerboseMode);
} }
void UpdateArchive(string path) 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, bool verbose)
{
if (!verbose)
Console.Write("Creating .tar archives ... ");
foreach (var directory in DirectoriesDictionary(path + @"\customize", path)) foreach (var directory in DirectoriesDictionary(path + @"\customize", path))
{ {
if (verbose)
Console.Write("Creating " + directory.Value + ".tar archive ... "); Console.Write("Creating " + directory.Value + ".tar archive ... ");
ArchiveManager.CreateTarArchive(directory.Key, path + @"\themes\" + directory.Value + ".tar");
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"); if (!verbose)
UpdateFonts(path + @"\font", path + @"\customize"); Console.Write("Copying icons ... ");
}
void UpdateIcons(string iconsPath, string customizePath)
{
Console.Write("\nUpdating icons ... ");
var icons = FilesArray(iconsPath);
foreach (var directory in DirectoriesArray(customizePath)) 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); File.Copy(iconsPath + @"\" + icon, directory + @"\icons\" + icon, true);
}
}
if (verbose)
{
Console.ForegroundColor = ConsoleColor.Green; Console.ForegroundColor = ConsoleColor.Green;
Console.Write("OK\n"); Console.Write("OK\n");
Console.ResetColor(); Console.ResetColor();
} }
}
}
void UpdateFonts(string fontsPath, string customizePath) if (!verbose)
{ {
Console.Write("Updating fonts ... "); Console.ForegroundColor = ConsoleColor.Green;
var fonts = FilesArray(fontsPath); Console.Write("OK\n");
Console.ResetColor();
}
}
void UpdateFonts(string fontsPath, string customizePath, bool verbose)
{
if (!verbose)
Console.Write("Copying fonts ... ");
foreach (var directory in DirectoriesArray(customizePath)) foreach (var directory in DirectoriesArray(customizePath))
{ {
foreach (var font in fonts) foreach (var font in FilesArray(fontsPath))
{ {
File.Copy(fontsPath + @"\" + font, directory + @"\" + font, true); if (verbose)
} Console.Write("Copying " + font + " ... ");
}
File.Copy(fontsPath + @"\" + font, directory + @"\" + font, true);
if (verbose)
{
Console.ForegroundColor = ConsoleColor.Green; Console.ForegroundColor = ConsoleColor.Green;
Console.Write("OK\n"); Console.Write("OK\n");
Console.ResetColor(); Console.ResetColor();
} }
}
}
if (!verbose)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("OK\n");
Console.ResetColor();
}
}
List<string> FilesArray(string folderPath) List<string> FilesArray(string folderPath)
{ {

View file

@ -7,7 +7,16 @@ namespace DistroGrubThemes
[Option('r', "repository", Required = true, HelpText = "Path to repository.")] [Option('r', "repository", Required = true, HelpText = "Path to repository.")]
public string RepositoryPath { get; set; } public string RepositoryPath { get; set; }
[Option('a', "archive", HelpText = "Create theme archive.")] [Option('a', "archive", HelpText = "Update archives.")]
public string ArchivedFiles { get; set; } 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; }
} }
} }