Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Razmoth committed Jul 19, 2024
1 parent 56da8d4 commit 7bc8f1e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 50 deletions.
4 changes: 2 additions & 2 deletions Audio/Models/Chunks/STID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Audio.Models.Chunks;
public record STID : Chunk
{
public bool IsBankIDToName { get; set; }
public uint StringType { get; set; }
public Dictionary<uint, string> BankIDToName { get; set; }

public STID(Chunk chunk) : base(chunk)
Expand All @@ -16,7 +16,7 @@ public STID(Chunk chunk) : base(chunk)

public new void Parse(BinaryReader reader)
{
IsBankIDToName = Convert.ToBoolean(reader.ReadUInt32());
StringType = reader.ReadUInt32();
var count = reader.ReadInt32();
BankIDToName.EnsureCapacity(count);
for (int i = 0; i < count; i++)
Expand Down
2 changes: 1 addition & 1 deletion Audio/Models/Entries/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public record Entry
public EntryType Type { get; }
public string Source => Package.Path;
public virtual string Location => $"{FolderName}/{Name}";
public virtual string FolderName => Package.FoldersDict[Folder];
public virtual string FolderName => Package.FoldersDict.TryGetValue(Folder, out var name) ? name : "None";

public Entry(EntryType type)
{
Expand Down
101 changes: 54 additions & 47 deletions Audio/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ private void DumpTXTH(Entry entry, string outputPath)
{
using var fs = fileInfo.OpenWrite();
using var writer = new StreamWriter(fs);
writer.WriteLine($"body_file = {Path.GetRelativePath(fileInfo.FullName, entry.Source)}");
writer.WriteLine($"body_file = {entry.Source}");
writer.WriteLine($"subfile_offset = {entry.Offset}");
writer.WriteLine($"subfile_size = {entry.Size}");
writer.WriteLine("subfile_extension = wem");
Expand Down Expand Up @@ -626,81 +626,83 @@ private void GenerateTXTPInternal()
StatusText = "No banks found !!";
return;
}
foreach (var bank in banks)

ProgressHelper.Reset();
for (int i = 0; i < banks.Count; i++)
{
var bank = banks[i];
var outputPath = Path.Combine(banksDir, bank.Location);
DumpEntry(bank, outputPath);
ProgressHelper.Report(i, banks.Count);
}

string txtpDir;

var startInfo = new ProcessStartInfo();
startInfo.FileName = "python";
startInfo.WorkingDirectory = outputDir;
startInfo.UseShellExecute = true;
startInfo.ArgumentList.Add(WWiserPath);
startInfo.ArgumentList.Add(Path.Combine(banksDir, "**/*.bnk"));
startInfo.ArgumentList.Add("-d");
startInfo.ArgumentList.Add("txt");
startInfo.ArgumentList.Add("-g");
startInfo.ArgumentList.Add("-te");
startInfo.ArgumentList.Add("-gra");
if (!AllowBanks)
{
startInfo.ArgumentList.Add("-gbs");
}
if (AllowDupes)
{
startInfo.ArgumentList.Add("-gd");
startInfo.ArgumentList.Add("-gde");
}
startInfo.ArgumentList.Add("-nl");
startInfo.ArgumentList.Add(EventPath);

if (Folders.Any(x => x.IsChecked))
{
foreach (var folder in Folders)
ProgressHelper.Reset();
for (int i = 0; i < Folders.Count; i++)
{
var folder = Folders[i];

if (!folder.IsChecked)
continue;

StatusText = $"Invoking wwiser for language {folder.Name}...";

var txtpDir = Path.Combine(outputDir, "txtp", folder.Name);
txtpDir = Path.Combine(outputDir, "txtp", folder.Name);
Directory.CreateDirectory(Path.GetDirectoryName(txtpDir));

var startInfo = new ProcessStartInfo();
startInfo.FileName = "python";
startInfo.ArgumentList.Add(WWiserPath);
startInfo.ArgumentList.Add(Path.Combine(banksDir, "**/*.bnk"));
startInfo.ArgumentList.Add("-g");
startInfo.ArgumentList.Add("-te");
if (!AllowBanks)
{
startInfo.ArgumentList.Add("-gbs");
}
if (AllowDupes)
{
startInfo.ArgumentList.Add("-gd");
startInfo.ArgumentList.Add("-gde");
}
startInfo.ArgumentList.Add("-nl");
startInfo.ArgumentList.Add(EventPath);
startInfo.ArgumentList.Add("-gl");
startInfo.ArgumentList.Add(folder.Name);
startInfo.ArgumentList.Add("-go");
startInfo.ArgumentList.Add(Path.GetRelativePath(outputDir, txtpDir));
startInfo.WorkingDirectory = outputDir;
startInfo.UseShellExecute = true;

using var process = Process.Start(startInfo);
process.WaitForExit();

if (IsExportAudio)
{
ExportAudio(banks, txtpDir);
}

ProgressHelper.Report(i, Folders.Count);

startInfo.ArgumentList.Remove("-gl");
startInfo.ArgumentList.Remove(folder.Name);
startInfo.ArgumentList.Remove("-go");
startInfo.ArgumentList.Remove(Path.GetRelativePath(outputDir, txtpDir));
}
}
else
{
StatusText = "Invoking wwiser...";

var txtpDir = Path.Combine(outputDir, "txtp");
txtpDir = Path.Combine(outputDir, "txtp");

var startInfo = new ProcessStartInfo();
startInfo.FileName = "python";
startInfo.ArgumentList.Add(WWiserPath);
startInfo.ArgumentList.Add(Path.Combine(banksDir, "**/*.bnk"));
startInfo.ArgumentList.Add("-g");
startInfo.ArgumentList.Add("-te");
if (!AllowBanks)
{
startInfo.ArgumentList.Add("-gbs");
}
if (AllowDupes)
{
startInfo.ArgumentList.Add("-gd");
startInfo.ArgumentList.Add("-gde");
}
startInfo.ArgumentList.Add("-nl");
startInfo.ArgumentList.Add(EventPath);
startInfo.WorkingDirectory = outputDir;
startInfo.UseShellExecute = true;
using var process = Process.Start(startInfo);
process.WaitForExit();

Expand Down Expand Up @@ -736,13 +738,16 @@ private void ExportAudio(List<Bank> banks, string txtpDir)

var files = Directory.GetFiles(txtpDir, "*.txtp");
StatusText = $"Found {files.Length} TXTP, proccessing...";
foreach (var f in files)

ProgressHelper.Reset();
for (int i = 0; i < files.Length; i++)
{
var f = files[i];
var hasTXTH = false;
var lines = File.ReadAllLines(f);
for (int i = 0; i < lines.Length; i++)
for (int j = 0; j < lines.Length; j++)
{
var line = lines[i];
var line = lines[j];

if (line.StartsWith('#'))
break;
Expand All @@ -760,7 +765,7 @@ private void ExportAudio(List<Bank> banks, string txtpDir)
if (EnableTXTH)
{
DumpTXTH(target, outputPath);
lines[i] = line.Replace(".wem", ".wem.txth");
lines[j] = line.Replace(".wem", ".wem.txth");
hasTXTH = true;
}
else
Expand All @@ -775,6 +780,8 @@ private void ExportAudio(List<Bank> banks, string txtpDir)
{
File.WriteAllLines(f, lines);
}

ProgressHelper.Report(i, files.Length);
}
}

Expand Down

0 comments on commit 7bc8f1e

Please sign in to comment.