Skip to content

Commit

Permalink
Rename project
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchLeaders committed Jun 26, 2024
1 parent 5e987a1 commit 0be45d2
Show file tree
Hide file tree
Showing 15 changed files with 222 additions and 126 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ jobs:
runtime: win-x64

env:
proj: "Totk.ZStdTool"
proj: "TotkZstdTool"

steps:
- uses: actions/checkout@master

- name: Install DotNET
uses: actions/setup-dotnet@v3
with:
dotnet-version: "7.0.x"
dotnet-version: "8.0.x"

- name: Publish Totk ZStd Tool
shell: bash
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ jobs:
runtime: win-x64

env:
proj: "Totk.ZStdTool"
proj: "TotkZstdTool"

steps:
- uses: actions/checkout@master

- name: Install DotNET
uses: actions/setup-dotnet@v3
with:
dotnet-version: "7.0.x"
dotnet-version: "8.0.x"

- name: Publish Totk ZStd Tool
shell: bash
Expand Down
4 changes: 2 additions & 2 deletions ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Totk Decompression/Compression Tool

[![License: AGPL v3](https://img.shields.io/badge/License-AGPL_v3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
[![Downloads](https://img.shields.io/github/downloads/TotkMods/Totk.ZStdTool/total)](https://github.com/TotkMods/Totk.ZStdTool/releases)
[![Downloads](https://img.shields.io/github/downloads/TotkMods/TotkZstdTool/total)](https://github.com/TotkMods/TotkZstdTool/releases)

A simple tool for decompressing and compressing `.zs` files in Totk.

Expand All @@ -18,7 +18,7 @@ A simple tool for decompressing and compressing `.zs` files in Totk.
## Setup

1. Download and install the .NET 7 Runtime.
2. Download the latest release of [Totk zStd Tool](https://github.com/TotkMods/Totk.ZStdTool/releases/latest).
2. Download the latest release of [Totk zStd Tool](https://github.com/TotkMods/TotkZstdTool/releases/latest).
3. Open the application and configure your settings:
- **Game Path**: Specify the path to your Totk game dump (RomFS - not an XCI or NSP file). This field is required.

Expand Down
2 changes: 1 addition & 1 deletion Totk.ZStdTool.sln → TotkZstdTool.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33530.505
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Totk.ZStdTool", "src\Totk.ZStdTool.csproj", "{82E909E6-EDF7-4C14-9F71-4CB1C95467D2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TotkZstdTool", "src\TotkZstdTool.csproj", "{82E909E6-EDF7-4C14-9F71-4CB1C95467D2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
4 changes: 2 additions & 2 deletions src/App.axaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Application x:Class="Totk.ZStdTool.App"
<Application x:Class="TotkZstdTool.App"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Totk.ZStdTool"
xmlns:local="using:TotkZstdTool"
xmlns:sty="using:FluentAvalonia.Styling">
<Application.Styles>
<sty:FluentAvaloniaTheme />
Expand Down
12 changes: 7 additions & 5 deletions src/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Avalonia.VisualTree;
using Totk.ZStdTool.ViewModels;
using Totk.ZStdTool.Views;
using TotkZstdTool.ViewModels;
using TotkZstdTool.Views;

namespace Totk.ZStdTool;
namespace TotkZstdTool;

public partial class App : Application
{
Expand All @@ -19,8 +19,10 @@ public override void Initialize()

public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
desktop.MainWindow = new ShellView {
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new ShellView
{
DataContext = ShellViewModel.Shared,
};

Expand Down
33 changes: 21 additions & 12 deletions src/CommandProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Totk.ZStdTool.Helpers;
using TotkZstdTool.Helpers;

namespace Totk.ZStdTool;
namespace TotkZstdTool;

public static class CommandProcessor
{
Expand All @@ -10,15 +10,18 @@ public static class CommandProcessor
public static void Process(List<string> args)
{
string[] files = args.Where(File.Exists).ToArray();
if (files.Length == args.Count) {
foreach (string file in files) {
if (files.Length == args.Count)
{
foreach (string file in files)
{
ProcessShellInput(file);
}

return;
}

if (args[0].AsFlag() == 'h') {

if (args[0].AsFlag() == 'h')
{
Console.WriteLine("""
Compress a file:
c, compress <file-path> [-o|--output] [-d|--dictionaries] [-h|--help]
Expand All @@ -38,7 +41,8 @@ public static void Process(List<string> args)
.Select((x, i) => (key: x.AsFlag(), value: args[args.IndexOf(x) + 1]))
.ToDictionary(x => x.key, x => x.value);

Action<string, Dictionary<char, string>> command = args[0][0] switch {
Action<string, Dictionary<char, string>> command = args[0][0] switch
{
'c' => Compress,
'd' => Decompress,
_ => throw new NotImplementedException(
Expand All @@ -55,10 +59,12 @@ public static char AsFlag(this string input)

public static void ProcessShellInput(string input)
{
if (input.EndsWith(".zs")) {
if (input.EndsWith(".zs"))
{
Decompress(input, new());
}
else {
else
{
Compress(input, new());
}
}
Expand All @@ -69,11 +75,13 @@ public static void Compress(string input, Dictionary<char, string> flags)
output ??= input + ".zs";

bool useDictionaries = true;
if (flags.TryGetValue('d', out string? useDictionariesArg)) {
if (flags.TryGetValue('d', out string? useDictionariesArg))
{
useDictionaries = useDictionariesArg.ToLower() is not "f" or "false" or "n" or "no";
}

if (Path.GetDirectoryName(output) is string directory && !string.IsNullOrEmpty(directory)) {
if (Path.GetDirectoryName(output) is string directory && !string.IsNullOrEmpty(directory))
{
Directory.CreateDirectory(directory);
}

Expand All @@ -85,7 +93,8 @@ public static void Decompress(string input, Dictionary<char, string> flags)
flags.TryGetValue('o', out string? output);
output ??= Path.ChangeExtension(input, string.Empty);

if (Path.GetDirectoryName(output) is string directory && !string.IsNullOrEmpty(directory)) {
if (Path.GetDirectoryName(output) is string directory && !string.IsNullOrEmpty(directory))
{
Directory.CreateDirectory(directory);
}

Expand Down
77 changes: 51 additions & 26 deletions src/Helpers/BrowserDialog.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Avalonia.Platform.Storage;

namespace Totk.ZStdTool.Helpers;
namespace TotkZstdTool.Helpers;

public enum BrowserMode { OpenFile, OpenFolder, SaveFile }

Expand Down Expand Up @@ -37,8 +37,10 @@ public BrowserDialog(BrowserMode mode, string? title = null, string? filter = nu
_suggestedFileName = suggestedFileName;
_instanceBrowserKey = instanceBrowserKey;

if (instanceBrowserKey != null) {
if (!Stashed.ContainsKey(instanceBrowserKey)) {
if (instanceBrowserKey != null)
{
if (!Stashed.ContainsKey(instanceBrowserKey))
{
Stashed.Add(instanceBrowserKey, new());
}
}
Expand All @@ -61,19 +63,23 @@ public BrowserDialog(BrowserMode mode, string? title = null, string? filter = nu

IStorageProvider StorageProvider = App.VisualRoot!.StorageProvider;

object? result = _mode switch {
BrowserMode.OpenFolder => await StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions() {
object? result = _mode switch
{
BrowserMode.OpenFolder => await StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions()
{
Title = _title,
SuggestedStartLocation = GetLastDirectory(),
AllowMultiple = allowMultiple
}),
BrowserMode.OpenFile => await StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions() {
BrowserMode.OpenFile => await StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions()
{
Title = _title,
SuggestedStartLocation = GetLastDirectory(),
AllowMultiple = allowMultiple,
FileTypeFilter = LoadFileBrowserFilter(_filter)
}),
BrowserMode.SaveFile => await StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions() {
BrowserMode.SaveFile => await StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions()
{
Title = _title,
SuggestedStartLocation = GetLastDirectory(),
FileTypeChoices = LoadFileBrowserFilter(_filter),
Expand All @@ -82,78 +88,97 @@ public BrowserDialog(BrowserMode mode, string? title = null, string? filter = nu
_ => throw new NotImplementedException()
};

if (result is IReadOnlyList<IStorageFolder> folders && folders.Count > 0) {
if (result is IReadOnlyList<IStorageFolder> folders && folders.Count > 0)
{
SetLastDirectory(folders[folders.Count - 1]);
return folders.Select(folder => folder.Path.LocalPath);
}
else if (result is IReadOnlyList<IStorageFile> files && files.Count > 0) {
else if (result is IReadOnlyList<IStorageFile> files && files.Count > 0)
{
SetLastDirectory(await files[files.Count - 1].GetParentAsync());
return files.Select(file => file.Path.LocalPath);
}
else if (result is IStorageFile file) {
else if (result is IStorageFile file)
{
SetLastDirectory(await file.GetParentAsync());
return new string[1] {
file.Path.LocalPath
};
}
else {
else
{
return null;
}
}

internal void SetLastDirectory(IStorageFolder? folder)
{
if (_mode == BrowserMode.SaveFile) {
if (_mode == BrowserMode.SaveFile)
{
LastSaveDirectory = folder;
if (_instanceBrowserKey != null) {
if (_instanceBrowserKey != null)
{
Stashed[_instanceBrowserKey].SaveDirectory = folder;
}
}
else {
else
{
LastOpenDirectory = folder;
if (_instanceBrowserKey != null) {
if (_instanceBrowserKey != null)
{
Stashed[_instanceBrowserKey].OpenDirectory = folder;
}
}
}

internal IStorageFolder? GetLastDirectory()
{
if (_mode == BrowserMode.SaveFile) {
if (_instanceBrowserKey != null) {
if (_mode == BrowserMode.SaveFile)
{
if (_instanceBrowserKey != null)
{
return Stashed[_instanceBrowserKey].SaveDirectory;
}
else {
else
{
return LastSaveDirectory;
}
}
else {
if (_instanceBrowserKey != null) {
else
{
if (_instanceBrowserKey != null)
{
return Stashed[_instanceBrowserKey].OpenDirectory;
}
else {
else
{
return LastOpenDirectory;
}
}
}

internal static FilePickerFileType[] LoadFileBrowserFilter(string? filter = null)
{
if (filter != null) {
try {
if (filter != null)
{
try
{
string[] groups = filter.Split('|');
FilePickerFileType[] types = new FilePickerFileType[groups.Length];

for (int i = 0; i < groups.Length; i++) {
for (int i = 0; i < groups.Length; i++)
{
string[] pair = groups[i].Split(':');
types[i] = new(pair[0]) {
types[i] = new(pair[0])
{
Patterns = pair[1].Split(';')
};
}

return types;
}
catch {
catch
{
throw new FormatException(
$"Could not parse filter arguments '{filter}'.\n" +
$"Example: \"Yaml Files:*.yml;*.yaml|All Files:*.*\"."
Expand Down
Loading

0 comments on commit 0be45d2

Please sign in to comment.