Skip to content
This repository has been archived by the owner on Jun 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #393 from IcarusTwine/HighDef-UI
Browse files Browse the repository at this point in the history
HD Icon Command
  • Loading branch information
Supamiu authored Apr 13, 2021
2 parents 2f8d2ce + 6426db1 commit 0f19a7a
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
109 changes: 109 additions & 0 deletions SaintCoinach.Cmd/Commands/HDUiCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Tharga.Toolkit.Console;
using Tharga.Toolkit.Console.Command;
using Tharga.Toolkit.Console.Command.Base;

#pragma warning disable CS1998

namespace SaintCoinach.Cmd.Commands {
public class HDUiCommand : ActionCommandBase {
const string UiImagePathFormat = "ui/icon/{0:D3}000{1}/{2:D6}_hr1.tex";
static readonly string[] UiVersions = new string[] {
"",
"/en",
"/ja",
"/fr",
"/de",
"/hq"
};

private ARealmReversed _Realm;

public HDUiCommand(ARealmReversed realm)
: base("uiHD", "Export all, a single, or a range of HD UI icons.") {
_Realm = realm;
}

public override async Task<bool> InvokeAsync(string paramList) {
var min = 0;
var max = 999999;

if (!string.IsNullOrWhiteSpace(paramList)) {
var splitParam = paramList.Split(' ');

if (splitParam.Length == 1) {
if (int.TryParse(splitParam[0], out var parsed))
min = max = parsed;
else {
OutputError("Failed to parse parameters.");
return false;
}
}
else if (splitParam.Length == 2) {
if (!int.TryParse(splitParam[0], out min) || !int.TryParse(splitParam[1], out max)) {
OutputError("Failed to parse parameters.");
return false;
}

if (max < min) {
OutputError("Invalid parameters.");
return false;
}
}
else {
OutputError("Failed to parse parameters.");
return false;
}
}

var count = 0;
for (int i = min; i <= max; ++i) {
try {
count += Process(i);
}
catch (Exception e) {
OutputError("{0:D6}: {1}", i, e.Message);
}
}
OutputInformation("{0} images processed", count);

return true;
}

private int Process(int i) {
var count = 0;
foreach (var v in UiVersions) {
if (Process(i, v))
++count;
}
return count;
}
private bool Process(int i, string version) {
var filePath = string.Format(UiImagePathFormat, i / 1000, version, i);

if (_Realm.Packs.TryGetFile(filePath, out var file)) {
if (file is Imaging.ImageFile imgFile) {
var img = imgFile.GetImage();

var target = new FileInfo(Path.Combine(_Realm.GameVersion, file.Path));
if (!target.Directory.Exists)
target.Directory.Create();
var pngPath = target.FullName.Substring(0, target.FullName.Length - target.Extension.Length) + ".png";
img.Save(pngPath);

return true;
}
else {
OutputError("{0} is not an image.", filePath);
}
}
return false;
}
}
}
1 change: 1 addition & 0 deletions SaintCoinach.Cmd/SaintCoinach.Cmd.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Commands\HDUiCommand.cs" />
<Compile Include="Commands\AllExdCommand.cs" />
<Compile Include="Commands\AllExdRawCommand.cs" />
<Compile Include="Commands\BgmCommand.cs" />
Expand Down

0 comments on commit 0f19a7a

Please sign in to comment.