mirror of
https://github.com/AdisonCavani/distro-grub-themes.git
synced 2025-06-04 22:42:34 +02:00
Fix adding files to archive, update to C# 10, update themes
This commit is contained in:
parent
138b1fa224
commit
fcb5774fe1
36 changed files with 163 additions and 132 deletions
|
@ -2,21 +2,52 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace DistroGrubThemes
|
||||
{
|
||||
public static class ArchiveManager
|
||||
{
|
||||
public static void CreateTarArchive(string outputFile, bool verbose)
|
||||
{
|
||||
Stream outStream = File.Create(outputFile);
|
||||
TarArchive.CreateOutputTarArchive(outStream);
|
||||
namespace DistroGrubThemes;
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.Write("OK\n");
|
||||
Console.ResetColor();
|
||||
}
|
||||
public static class ArchiveManager
|
||||
{
|
||||
public static void CreateTarArchive(string sourceDirectory, string outputFile, bool verbose)
|
||||
{
|
||||
Stream outStream = File.Create(outputFile);
|
||||
TarArchive tarArchive = TarArchive.CreateOutputTarArchive(outStream);
|
||||
|
||||
// Case sensitive
|
||||
tarArchive.RootPath = sourceDirectory.Replace('\\', '/');
|
||||
if (tarArchive.RootPath.EndsWith("/"))
|
||||
tarArchive.RootPath = tarArchive.RootPath.Remove(tarArchive.RootPath.Length - 1);
|
||||
|
||||
AddDirectoryFilesToTar(tarArchive, sourceDirectory, true);
|
||||
tarArchive.Close();
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.Write("OK\n");
|
||||
Console.ResetColor();
|
||||
}
|
||||
}
|
||||
|
||||
// Example: https://github.com/icsharpcode/SharpZipLib/wiki/GZip-and-Tar-Samples
|
||||
private static void AddDirectoryFilesToTar(TarArchive tarArchive, string sourceDirectory, bool recurse)
|
||||
{
|
||||
// Optionally, write an entry for the directory itself.
|
||||
// Specify false for recursion here if we will add the directory's files individually.
|
||||
TarEntry tarEntry = TarEntry.CreateEntryFromFile(sourceDirectory);
|
||||
tarArchive.WriteEntry(tarEntry, false);
|
||||
|
||||
// Write each file to the tar.
|
||||
string[] filenames = Directory.GetFiles(sourceDirectory);
|
||||
foreach (string filename in filenames)
|
||||
{
|
||||
tarEntry = TarEntry.CreateEntryFromFile(filename);
|
||||
tarArchive.WriteEntry(tarEntry, true);
|
||||
}
|
||||
|
||||
if (recurse)
|
||||
{
|
||||
string[] directories = Directory.GetDirectories(sourceDirectory);
|
||||
foreach (string directory in directories)
|
||||
AddDirectoryFilesToTar(tarArchive, directory, recurse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<Authors>Adison Cavani</Authors>
|
||||
<Company>Adison Cavani</Company>
|
||||
<LangVersion>10</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
235
src/Program.cs
235
src/Program.cs
|
@ -4,159 +4,158 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace DistroGrubThemes
|
||||
namespace DistroGrubThemes;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
internal class Program
|
||||
static void Main(string[] args)
|
||||
{
|
||||
static void Main(string[] args)
|
||||
var parser = new Parser(with => with.HelpWriter = null);
|
||||
var parserResult = parser.ParseArguments<ProgramOptions>(args);
|
||||
parserResult.WithParsed(options => RunOptions(options)).WithNotParsed(errs => Help.DisplayHelp(parserResult, errs));
|
||||
}
|
||||
|
||||
static void RunOptions(ProgramOptions opts)
|
||||
{
|
||||
Program program = new();
|
||||
string path = program.CheckRepoPath(opts.RepositoryPath);
|
||||
|
||||
if (opts.UpdateFonts)
|
||||
program.UpdateFonts($"{path}\\font", $"{path}\\customize", opts.VerboseMode);
|
||||
|
||||
if (opts.UpdateIcons)
|
||||
{
|
||||
var parser = new Parser(with => with.HelpWriter = null);
|
||||
var parserResult = parser.ParseArguments<ProgramOptions>(args);
|
||||
parserResult.WithParsed(options => RunOptions(options)).WithNotParsed(errs => Help.DisplayHelp(parserResult, errs));
|
||||
if (opts.VerboseMode)
|
||||
Console.WriteLine();
|
||||
|
||||
program.UpdateIcons($"{path}\\assets\\icons", $"{path}\\customize", opts.VerboseMode);
|
||||
}
|
||||
|
||||
static void RunOptions(ProgramOptions opts)
|
||||
if (opts.UpdateArchives)
|
||||
{
|
||||
Program program = new Program();
|
||||
string path = program.CheckRepoPath(opts.RepositoryPath);
|
||||
if (opts.VerboseMode)
|
||||
Console.WriteLine();
|
||||
|
||||
if (opts.UpdateFonts)
|
||||
program.UpdateFonts($"{path}\\font", $"{path}\\customize", opts.VerboseMode);
|
||||
program.UpdateArchive(path, opts.VerboseMode);
|
||||
}
|
||||
}
|
||||
|
||||
if (opts.UpdateIcons)
|
||||
{
|
||||
if (opts.VerboseMode)
|
||||
Console.WriteLine();
|
||||
void UpdateArchive(string path, bool verbose)
|
||||
{
|
||||
if (!verbose)
|
||||
Console.Write("Creating .tar archives ... ");
|
||||
|
||||
program.UpdateIcons($"{path}\\assets\\icons", $"{path}\\customize", opts.VerboseMode);
|
||||
}
|
||||
foreach (var directory in DirectoriesDictionary($"{path}\\customize", path))
|
||||
{
|
||||
if (verbose)
|
||||
Console.Write($"Creating {directory.Value}.tar archive ... ");
|
||||
|
||||
if (opts.UpdateArchives)
|
||||
{
|
||||
if (opts.VerboseMode)
|
||||
Console.WriteLine();
|
||||
|
||||
program.UpdateArchive(path, opts.VerboseMode);
|
||||
}
|
||||
ArchiveManager.CreateTarArchive(directory.Key, $"{path}\\themes\\{directory.Value}.tar", verbose);
|
||||
}
|
||||
|
||||
void UpdateArchive(string path, bool verbose)
|
||||
if (!verbose)
|
||||
{
|
||||
if (!verbose)
|
||||
Console.Write("Creating .tar archives ... ");
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.Write("OK\n");
|
||||
Console.ResetColor();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var directory in DirectoriesDictionary($"{path}\\customize", path))
|
||||
void UpdateIcons(string iconsPath, string customizePath, bool verbose)
|
||||
{
|
||||
if (!verbose)
|
||||
Console.Write("Copying icons ... ");
|
||||
|
||||
foreach (var directory in DirectoriesArray(customizePath))
|
||||
{
|
||||
foreach (var icon in FilesArray(iconsPath))
|
||||
{
|
||||
if (verbose)
|
||||
Console.Write($"Creating {directory.Value}.tar archive ... ");
|
||||
Console.Write($"Copying {icon} ... ");
|
||||
|
||||
ArchiveManager.CreateTarArchive($"{path}\\themes\\{directory.Value}.tar", verbose);
|
||||
}
|
||||
File.Copy($"{iconsPath}\\{icon}", $"{directory}\\icons\\{icon}", true);
|
||||
|
||||
if (!verbose)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.Write("OK\n");
|
||||
Console.ResetColor();
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateIcons(string iconsPath, string customizePath, bool verbose)
|
||||
{
|
||||
if (!verbose)
|
||||
Console.Write("Copying icons ... ");
|
||||
|
||||
foreach (var directory in DirectoriesArray(customizePath))
|
||||
{
|
||||
foreach (var icon in FilesArray(iconsPath))
|
||||
if (verbose)
|
||||
{
|
||||
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, bool verbose)
|
||||
if (!verbose)
|
||||
{
|
||||
if (!verbose)
|
||||
Console.Write("Copying fonts ... ");
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.Write("OK\n");
|
||||
Console.ResetColor();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var directory in DirectoriesArray(customizePath))
|
||||
void UpdateFonts(string fontsPath, string customizePath, bool verbose)
|
||||
{
|
||||
if (!verbose)
|
||||
Console.Write("Copying fonts ... ");
|
||||
|
||||
foreach (var directory in DirectoriesArray(customizePath))
|
||||
{
|
||||
foreach (var font in FilesArray(fontsPath))
|
||||
{
|
||||
foreach (var font in FilesArray(fontsPath))
|
||||
if (verbose)
|
||||
Console.Write($"Copying {font} ... ");
|
||||
|
||||
File.Copy($"{fontsPath}\\{font}", $"{directory}\\{font}", true);
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
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<string> FilesArray(string folderPath)
|
||||
if (!verbose)
|
||||
{
|
||||
return new List<string>(Directory.GetFiles(folderPath).Select(Path.GetFileName));
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.Write("OK\n");
|
||||
Console.ResetColor();
|
||||
}
|
||||
}
|
||||
|
||||
List<string> FilesArray(string folderPath)
|
||||
{
|
||||
return new List<string>(Directory.GetFiles(folderPath).Select(Path.GetFileName));
|
||||
}
|
||||
|
||||
string[] DirectoriesArray(string directoryPath)
|
||||
{
|
||||
return Directory.GetDirectories(directoryPath);
|
||||
}
|
||||
|
||||
Dictionary<string, string> DirectoriesDictionary(string directoryPath, string repoPath)
|
||||
{
|
||||
var dirsArray = Directory.GetDirectories(directoryPath);
|
||||
|
||||
return dirsArray.ToDictionary(key => key, value => value[(value.IndexOf(@"customize\") + 10)..]);
|
||||
}
|
||||
|
||||
string CheckRepoPath(string path)
|
||||
{
|
||||
if (Directory.Exists(path) && path.Contains("distro-grub-themes"))
|
||||
{
|
||||
int index = path.IndexOf("distro-grub-themes") + 18;
|
||||
return path[..index];
|
||||
}
|
||||
|
||||
string[] DirectoriesArray(string directoryPath)
|
||||
else
|
||||
{
|
||||
return Directory.GetDirectories(directoryPath);
|
||||
}
|
||||
|
||||
Dictionary<string, string> DirectoriesDictionary(string directoryPath, string repoPath)
|
||||
{
|
||||
var dirsArray = Directory.GetDirectories(directoryPath);
|
||||
|
||||
return dirsArray.ToDictionary(key => key, value => value[(value.IndexOf(@"customize\") + 10)..]);
|
||||
}
|
||||
|
||||
string CheckRepoPath(string path)
|
||||
{
|
||||
if (Directory.Exists(path) && path.Contains("distro-grub-themes"))
|
||||
{
|
||||
int index = path.IndexOf("distro-grub-themes") + 18;
|
||||
return path[..index];
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.Write("error: ");
|
||||
Console.ResetColor();
|
||||
Console.Write("could not find repository in this path");
|
||||
Environment.Exit(1);
|
||||
return null;
|
||||
}
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.Write("error: ");
|
||||
Console.ResetColor();
|
||||
Console.Write("could not find repository in this path");
|
||||
Environment.Exit(1);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
themes/Solus.tar
BIN
themes/Solus.tar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
themes/aorus.tar
BIN
themes/aorus.tar
Binary file not shown.
BIN
themes/arch.tar
BIN
themes/arch.tar
Binary file not shown.
BIN
themes/arco.tar
BIN
themes/arco.tar
Binary file not shown.
BIN
themes/artix.tar
BIN
themes/artix.tar
Binary file not shown.
BIN
themes/asus.tar
BIN
themes/asus.tar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
themes/hp.tar
BIN
themes/hp.tar
Binary file not shown.
Binary file not shown.
BIN
themes/mate.tar
BIN
themes/mate.tar
Binary file not shown.
BIN
themes/mint.tar
BIN
themes/mint.tar
Binary file not shown.
BIN
themes/mx.tar
BIN
themes/mx.tar
Binary file not shown.
Binary file not shown.
BIN
themes/pop.tar
BIN
themes/pop.tar
Binary file not shown.
BIN
themes/rocky.tar
BIN
themes/rocky.tar
Binary file not shown.
Binary file not shown.
BIN
themes/void.tar
BIN
themes/void.tar
Binary file not shown.
Loading…
Add table
Reference in a new issue