Add updating archives

This commit is contained in:
Adison Cavani 2021-10-09 23:37:09 +02:00
parent 8c2aedad45
commit 7b34c3c0ba
No known key found for this signature in database
GPG key ID: 2C36C61283E73DC9
3 changed files with 69 additions and 5 deletions

39
src/ArchiveManager.cs Normal file
View file

@ -0,0 +1,39 @@
using System;
namespace DistroGrubThemes
{
public class ArchiveManager
{
public static void CreateTarArchive(string sourceDirectory, string outputFile)
{
Chilkat.Tar tar = new Chilkat.Tar
{
WriteFormat = "gnu"
};
// Add a directory tree to be included in the output TAR archive:
bool success = tar.AddDirRoot(sourceDirectory);
if (success != true)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("ERROR\n\n");
Console.Write("error: ");
Console.ResetColor();
Console.Write(tar.LastErrorText + "\n");
return;
}
// Create the TAR archive.
success = tar.WriteTar(outputFile);
if (success != true)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("ERROR\n\n");
Console.Write("error: ");
Console.ResetColor();
Console.Write(tar.LastErrorText + "\n");
return;
}
}
}
}

View file

@ -8,8 +8,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ChilkatDnCore" Version="9.5.0.88" />
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="SharpZipLib" Version="1.3.3" />
</ItemGroup>
</Project>

View file

@ -1,6 +1,7 @@
using CommandLine;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
@ -18,8 +19,25 @@ 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);
}
void UpdateArchive(string path)
{
foreach (var directory in DirectoriesDictionary(path + @"\customize", path))
{
Console.Write("Creating " + directory.Value + ".tar archive ... ");
ArchiveManager.CreateTarArchive(directory.Key, path + @"\themes\" + directory.Value + ".tar");
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("OK\n");
Console.ResetColor();
}
}
void UpdateAssets(string path)
@ -33,7 +51,7 @@ namespace DistroGrubThemes
Console.Write("\nUpdating icons ... ");
var icons = FilesArray(iconsPath);
foreach (var directory in CustomDirectories(customizePath))
foreach (var directory in DirectoriesArray(customizePath))
{
foreach (var icon in icons)
{
@ -51,7 +69,7 @@ namespace DistroGrubThemes
Console.Write("Updating fonts ... ");
var fonts = FilesArray(fontsPath);
foreach (var directory in CustomDirectories(customizePath))
foreach (var directory in DirectoriesArray(customizePath))
{
foreach (var font in fonts)
{
@ -69,9 +87,16 @@ namespace DistroGrubThemes
return new List<string>(Directory.GetFiles(folderPath).Select(Path.GetFileName));
}
string[] CustomDirectories(string customizePath)
string[] DirectoriesArray(string directoryPath)
{
return Directory.GetDirectories(customizePath);
return Directory.GetDirectories(directoryPath);
}
Dictionary<string, string> DirectoriesDictionary(string directoryPath, string repoPath)
{
var dirsArray = Directory.GetDirectories(directoryPath);
return dirsArray.ToDictionary(key => key, value => value.Substring(value.IndexOf(@"customize\") + 10));
}
string CheckRepoPath(string path)