Fix adding files to archive, update to C# 10, update themes

This commit is contained in:
Adison Cavani 2021-12-30 23:07:46 +01:00
parent 138b1fa224
commit fcb5774fe1
No known key found for this signature in database
GPG key ID: E823B50BB3E2472D
36 changed files with 163 additions and 132 deletions

View file

@ -2,14 +2,22 @@
using System;
using System.IO;
namespace DistroGrubThemes
{
namespace DistroGrubThemes;
public static class ArchiveManager
{
public static void CreateTarArchive(string outputFile, bool verbose)
public static void CreateTarArchive(string sourceDirectory, string outputFile, bool verbose)
{
Stream outStream = File.Create(outputFile);
TarArchive.CreateOutputTarArchive(outStream);
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)
{
@ -18,5 +26,28 @@ namespace DistroGrubThemes
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);
}
}
}

View file

@ -5,6 +5,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<Authors>Adison Cavani</Authors>
<Company>Adison Cavani</Company>
<LangVersion>10</LangVersion>
</PropertyGroup>
<ItemGroup>

View file

@ -4,8 +4,8 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace DistroGrubThemes
{
namespace DistroGrubThemes;
internal class Program
{
static void Main(string[] args)
@ -17,7 +17,7 @@ namespace DistroGrubThemes
static void RunOptions(ProgramOptions opts)
{
Program program = new Program();
Program program = new();
string path = program.CheckRepoPath(opts.RepositoryPath);
if (opts.UpdateFonts)
@ -50,7 +50,7 @@ namespace DistroGrubThemes
if (verbose)
Console.Write($"Creating {directory.Value}.tar archive ... ");
ArchiveManager.CreateTarArchive($"{path}\\themes\\{directory.Value}.tar", verbose);
ArchiveManager.CreateTarArchive(directory.Key, $"{path}\\themes\\{directory.Value}.tar", verbose);
}
if (!verbose)
@ -159,4 +159,3 @@ namespace DistroGrubThemes
}
}
}
}

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.

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.

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.

Binary file not shown.

Binary file not shown.

Binary file not shown.