Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 78 additions & 73 deletions Forms/RSTB/RSTBEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,88 +266,107 @@ private async void UpdateFromModdedRomFs_Click(object sender, EventArgs e)

if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
var moddedRomFsPath = folderBrowserDialog.SelectedPath;
CreateUpdatedRSTBFromModdedRomFs(LoadedFile, folderBrowserDialog.SelectedPath);

var allFiles = Directory.GetFiles(moddedRomFsPath, "*", SearchOption.AllDirectories);
TopMenu.Enabled = true;
statusBar.Visible = false;
statusProgressBar.Visible = false;

PopulateGridView();

List<string> changedFiles = [];
List<string> addedFiles = [];
int skippedFiles = 0;
int removedFiles = 0;
//foreach (DataGridViewRow row in mainDataGridView.Rows)
//{
// var name = row.Cells[0].Value.ToString();

TopMenu.Enabled = false;
// if (changedFiles.Contains(name))
// row.DefaultCellStyle.BackColor = Color.Yellow;

statusLabel.Text = $"";
statusBar.Visible = true;
statusProgressBar.Visible = true;
statusProgressBar.Maximum = allFiles.Length;
statusProgressBar.Value = 0;
// if (addedFiles.Contains(name))
// row.DefaultCellStyle.BackColor = Color.Green;
//}
}
}

var progress = new Progress<(int Index, string FileName)>(value =>
{
statusLabel.Text = $"Getting file size... {value.FileName} ({value.Index}/{allFiles.Length})";
statusProgressBar.Value = value.Index;
});
public async void CreateUpdatedRSTBFromModdedRomFs(ResourceTable rstb, string moddedRomFsPath, bool showResults = true)
{
var allFiles = Directory.GetFiles(moddedRomFsPath, "*", SearchOption.AllDirectories);

List<string> changedFiles = [];
List<string> addedFiles = [];
int skippedFiles = 0;
int removedFiles = 0;

TopMenu.Enabled = false;

statusLabel.Text = $"";
statusBar.Visible = true;
statusProgressBar.Visible = true;
statusProgressBar.Maximum = allFiles.Length;
statusProgressBar.Value = 0;

await Task.Run(() =>
var progress = new Progress<(int Index, string FileName)>(value =>
{
statusLabel.Text = $"Getting file size... {value.FileName} ({value.Index}/{allFiles.Length})";
statusProgressBar.Value = value.Index;
});

await Task.Run(() =>
{
int currentPosition = 1;

foreach (var originalFile in allFiles)
{
int currentPosition = 1;
if (IsDisposed || Disposing) break;

foreach (var originalFile in allFiles)
var path = Path.GetRelativePath(moddedRomFsPath, originalFile).Replace('\\', '/');
if (path == "System/Resource/ResourceSizeTable.srsizetable" || path == "System/Resource/ResourceSizeTable.rsizetable")
{
if (IsDisposed || Disposing) break;

var path = Path.GetRelativePath(moddedRomFsPath, originalFile).Replace('\\', '/');
if (path == "System/Resource/ResourceSizeTable.srsizetable" || path == "System/Resource/ResourceSizeTable.rsizetable")
{
skippedFiles++;
continue;
}
skippedFiles++;
continue;
}

if (path.EndsWith(".byml") && path != "EventFlow/Info/EventFlowInfoProduct.byml")
continue;

if (path.EndsWith(".byml") && path != "EventFlow/Info/EventFlowInfoProduct.byml")
continue;

(progress as IProgress<(int, string)>).Report((currentPosition, path));

if (path.EndsWith(".zs"))
path = path[..^3];
(progress as IProgress<(int, string)>).Report((currentPosition, path));

var fileSize = GetFileSize(originalFile);
if (path.EndsWith(".zs"))
path = path[..^3];

if (fileSize < 0)
{
// remove unsupported file from rstb
if (fileSize == -2)
Console.WriteLine("Unsupported: {0}", path);
var fileSize = GetFileSize(originalFile);

LoadedFile.Dictionary.Remove(path);
removedFiles++;
}
else if (LoadedFile.Dictionary.TryGetValue(path, out var result) && fileSize >= 0 && fileSize != result.FileSize)
{
result.FileSize = (uint) fileSize;
changedFiles.Add(path);
}
if (fileSize < 0)
{
// remove unsupported file from rstb
if (fileSize == -2)
Console.WriteLine("Unsupported: {0}", path);

else if (!LoadedFile.Dictionary.ContainsKey(path) && fileSize >= 0)
{
LoadedFile.AddEntry(new ResourceTable.ResourceTableEntry(path, (uint) fileSize, 0, false));
rstb.Dictionary.Remove(path);
removedFiles++;
}
else if (rstb.Dictionary.TryGetValue(path, out var result) && fileSize >= 0 && fileSize != result.FileSize)
{
result.FileSize = (uint)fileSize;
changedFiles.Add(path);
}

addedFiles.Add(path);
}
else if (!rstb.Dictionary.ContainsKey(path) && fileSize >= 0)
{
rstb.AddEntry(new ResourceTable.ResourceTableEntry(path, (uint)fileSize, 0, false));

currentPosition++;
addedFiles.Add(path);
}

if (IsDisposed || Disposing) return;
currentPosition++;
}

});
if (IsDisposed || Disposing) return;

TopMenu.Enabled = true;
statusBar.Visible = false;
statusProgressBar.Visible = false;
});

if (showResults)
{
if (changedFiles.Count > 0 || addedFiles.Count > 0)
{
MessageBox.Show($"Successfully updated table values!" +
Expand All @@ -358,20 +377,6 @@ await Task.Run(() =>
"\n\nYou need to manually save your file in File > Save as...",
"Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
}


PopulateGridView();

//foreach (DataGridViewRow row in mainDataGridView.Rows)
//{
// var name = row.Cells[0].Value.ToString();

// if (changedFiles.Contains(name))
// row.DefaultCellStyle.BackColor = Color.Yellow;

// if (addedFiles.Contains(name))
// row.DefaultCellStyle.BackColor = Color.Green;
//}
}
}

Expand Down
23 changes: 19 additions & 4 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HeavenTool.Forms.RSTB;
using HeavenTool.Utility.FileTypes.RSTB;
using HeavenTool.Utility.IO;
using Microsoft.Win32.SafeHandles;
using System;
Expand Down Expand Up @@ -103,10 +104,24 @@ public static Form HandleInput(string[] originalArguments)
return bcsvEditor;

case ".srsizetable":
var rstbEditor = new RSTBEditor();
rstbEditor.LoadFile(path);
return rstbEditor;

if (originalArguments.Length >= 2)
{
var rstbEditor = new RSTBEditor();
rstbEditor.LoadFile(path);
rstbEditor.CreateUpdatedRSTBFromModdedRomFs(rstbEditor.LoadedFile, originalArguments[1], false);
string outPath = path;
if (originalArguments.Length >= 3)
outPath = originalArguments[2];
rstbEditor.LoadedFile.SaveTo(outPath, false);
Environment.Exit(0);
return null;
}
else
{
var rstbEditor = new RSTBEditor();
rstbEditor.LoadFile(path);
return rstbEditor;
}
default:
return null;
}
Expand Down
8 changes: 8 additions & 0 deletions Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"Heaven Tool": {
"commandName": "Project",
"commandLineArgs": "C:\\Users\\Ryan\\Documents\\GitHub\\ACNH-Tutorial-Skip\\RSTB_OG\\ResourceSizeTableTest.srsizetable C:\\Users\\Ryan\\AppData\\Roaming\\Ryujinx\\mods\\contents\\01006f8002326000\\romfs"
}
}
}
6 changes: 4 additions & 2 deletions Utility/FileTypes/RSTB/ResourceTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public void UpdateUniques()
/// Save the file
/// </summary>
/// <param name="filePath">File Location</param>
public void SaveTo(string filePath)
public void SaveTo(string filePath, bool showPrompt = true)
{
UpdateUniques();

Expand Down Expand Up @@ -337,7 +337,9 @@ public void SaveTo(string filePath)
memoryStream.Position = 0;
memoryStream.Read(array, 0, array.Length);

var wantToCompress = MessageBox.Show("Do you want to compress the file?", "Compress to Yaz0?", MessageBoxButtons.YesNo);
var wantToCompress = DialogResult.Yes;
if (showPrompt)
wantToCompress = MessageBox.Show("Do you want to compress the file?", "Compress to Yaz0?", MessageBoxButtons.YesNo);
var result = wantToCompress == DialogResult.Yes ? Yaz0CompressionAlgorithm.Compress(array) : new MemoryStream(array);

result.ExportToFile(filePath);
Expand Down