-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
629 lines (561 loc) · 24.9 KB
/
Copy pathProgram.cs
File metadata and controls
629 lines (561 loc) · 24.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
using BarsTool;
if (args.Length == 0)
{
PrintUsage();
return 1;
}
string command = args[0].ToLowerInvariant();
try
{
return command switch
{
"barslist" => HandleBarsList(args[1..]),
"bars" => HandleBars(args[1..]),
"wav2bfwav" => HandleWav2Bfwav(args[1..]),
"bfwav2wav" => HandleBfwav2Wav(args[1..]),
"wav2bfstm" => HandleWav2Bfstm(args[1..]),
"bfstm2wav" => HandleBfstm2Wav(args[1..]),
"bfstm2bfstp" => HandleBfstm2Bfstp(args[1..]),
_ => PrintUsage()
};
}
catch (Exception ex)
{
Console.Error.WriteLine($"Error: {ex.Message}");
Console.Error.WriteLine(ex.StackTrace);
return 1;
}
static int HandleWav2Bfwav(string[] args)
{
if (args.Length >= 1 && args[0] == "--bulk")
return BulkConvert(args[1..], ".wav", ".bfwav", d => BfwavFile.ConvertFromWav(d));
if (args.Length < 2) { Console.Error.WriteLine("Usage: BarsTool wav2bfwav <input.wav> <output.bfwav>\n BarsTool wav2bfwav --bulk <input_dir> <output_dir>"); return 1; }
byte[] bfwav = BfwavFile.ConvertFromWav(args[0]);
File.WriteAllBytes(args[1], bfwav);
Console.WriteLine($"Converted {args[0]} -> {args[1]} ({bfwav.Length} bytes)");
return 0;
}
static int HandleBfwav2Wav(string[] args)
{
if (args.Length >= 1 && args[0] == "--bulk")
return BulkConvert(args[1..], ".bfwav", ".wav", BfwavFile.ConvertToWav);
if (args.Length < 2) { Console.Error.WriteLine("Usage: BarsTool bfwav2wav <input.bfwav> <output.wav>\n BarsTool bfwav2wav --bulk <input_dir> <output_dir>"); return 1; }
byte[] wavData = BfwavFile.ConvertToWav(File.ReadAllBytes(args[0]));
File.WriteAllBytes(args[1], wavData);
Console.WriteLine($"Converted {args[0]} -> {args[1]} ({wavData.Length} bytes)");
return 0;
}
static int HandleWav2Bfstm(string[] args)
{
if (args.Length >= 1 && args[0] == "--bulk")
return BulkConvert(args[1..], ".wav", ".bfstm", d => BfstmFile.ConvertFromWav(d));
if (args.Length < 2) { Console.Error.WriteLine("Usage: BarsTool wav2bfstm <input.wav> <output.bfstm>\n BarsTool wav2bfstm --bulk <input_dir> <output_dir>"); return 1; }
byte[] bfstm = BfstmFile.ConvertFromWav(File.ReadAllBytes(args[0]));
File.WriteAllBytes(args[1], bfstm);
Console.WriteLine($"Converted {args[0]} -> {args[1]} ({bfstm.Length} bytes)");
return 0;
}
static int HandleBfstm2Wav(string[] args)
{
if (args.Length >= 1 && args[0] == "--bulk")
return BulkConvert(args[1..], ".bfstm", ".wav", BfstmFile.ConvertToWav);
if (args.Length < 2) { Console.Error.WriteLine("Usage: BarsTool bfstm2wav <input.bfstm> <output.wav>\n BarsTool bfstm2wav --bulk <input_dir> <output_dir>"); return 1; }
byte[] wavData = BfstmFile.ConvertToWav(File.ReadAllBytes(args[0]));
File.WriteAllBytes(args[1], wavData);
Console.WriteLine($"Converted {args[0]} -> {args[1]} ({wavData.Length} bytes)");
return 0;
}
static int HandleBfstm2Bfstp(string[] args)
{
if (args.Length >= 1 && args[0] == "--bulk")
return BulkConvert(args[1..], ".bfstm", ".bfstp", BfstmFile.GenerateBfstp);
if (args.Length < 2) { Console.Error.WriteLine("Usage: BarsTool bfstm2bfstp <input.bfstm> <output.bfstp>\n BarsTool bfstm2bfstp --bulk <input_dir> <output_dir>"); return 1; }
byte[] bfstp = BfstmFile.GenerateBfstp(File.ReadAllBytes(args[0]));
File.WriteAllBytes(args[1], bfstp);
Console.WriteLine($"Generated {args[1]} ({bfstp.Length} bytes)");
return 0;
}
static int BulkConvert(string[] args, string srcExt, string dstExt, Func<byte[], byte[]> convert)
{
if (args.Length < 2) { Console.Error.WriteLine($"Usage: --bulk <input_dir> <output_dir>"); return 1; }
string inputDir = args[0], outputDir = args[1];
if (!Directory.Exists(inputDir)) { Console.Error.WriteLine($"Input directory not found: {inputDir}"); return 1; }
Directory.CreateDirectory(outputDir);
var files = Directory.GetFiles(inputDir, "*" + srcExt);
if (files.Length == 0) { Console.Error.WriteLine($"No {srcExt} files found in '{inputDir}'"); return 1; }
int converted = 0;
foreach (string file in files.OrderBy(f => f, StringComparer.OrdinalIgnoreCase))
{
string outName = Path.GetFileNameWithoutExtension(file) + dstExt;
string outPath = Path.Combine(outputDir, outName);
try
{
byte[] dstData = convert(File.ReadAllBytes(file));
File.WriteAllBytes(outPath, dstData);
Console.WriteLine($" {Path.GetFileName(file)} -> {outName}");
converted++;
}
catch (Exception ex)
{
Console.Error.WriteLine($" {Path.GetFileName(file)}: FAILED - {ex.Message}");
}
}
Console.WriteLine($"Converted {converted}/{files.Length} files.");
return 0;
}
static int HandleBarsList(string[] args)
{
if (args.Length == 0) return PrintBarsListUsage();
string sub = args[0].ToLowerInvariant();
switch (sub)
{
case "list":
{
if (args.Length < 2) { Console.Error.WriteLine("Usage: BarsTool barslist list <file.barslist>"); return 1; }
var bl = BarsListFile.Read(args[1]);
Console.WriteLine($"Name: {bl.Name}");
Console.WriteLine($"Version: {bl.Version}");
Console.WriteLine($"Entries ({bl.Entries.Count}):");
foreach (var entry in bl.Entries)
Console.WriteLine($" {entry}");
return 0;
}
case "add":
{
if (args.Length < 3) { Console.Error.WriteLine("Usage: BarsTool barslist add <file.barslist> <name.bars> [name2.bars ...]"); return 1; }
var bl = BarsListFile.Read(args[1]);
for (int i = 2; i < args.Length; i++)
{
string name = args[i];
bl.AddEntry(name);
Console.WriteLine($"Added: {name}");
}
bl.Save(args[1]);
Console.WriteLine($"Saved {args[1]}");
return 0;
}
case "remove":
{
if (args.Length < 3) { Console.Error.WriteLine("Usage: BarsTool barslist remove <file.barslist> <name.bars>"); return 1; }
var bl = BarsListFile.Read(args[1]);
string name = args[2];
if (bl.RemoveEntry(name))
{
bl.Save(args[1]);
Console.WriteLine($"Removed '{name}' from {args[1]}");
}
else
{
Console.Error.WriteLine($"Entry '{name}' not found.");
return 1;
}
return 0;
}
case "create":
{
if (args.Length < 4) { Console.Error.WriteLine("Usage: BarsTool barslist create <output.barslist> --name <name> <entry1.bars> [...]"); return 1; }
string output = args[1];
string? listName = null;
var entries = new List<string>();
for (int i = 2; i < args.Length; i++)
{
if (args[i] == "--name" && i + 1 < args.Length)
listName = args[++i];
else
entries.Add(args[i]);
}
if (listName == null) { Console.Error.WriteLine("--name is required."); return 1; }
var bl = new BarsListFile { Name = listName, Entries = entries };
bl.Save(output);
Console.WriteLine($"Created {output} with {entries.Count} entries.");
return 0;
}
default:
return PrintBarsListUsage();
}
}
static int HandleBars(string[] args)
{
if (args.Length == 0) return PrintBarsUsage();
string sub = args[0].ToLowerInvariant();
switch (sub)
{
case "list":
{
if (args.Length < 2) { Console.Error.WriteLine("Usage: BarsTool bars list <file.bars>"); return 1; }
var bars = BarsFile.Read(args[1]);
Console.WriteLine($"Version: 0x{bars.Version:X4}");
Console.WriteLine($"Assets ({bars.Assets.Count}):");
foreach (var asset in bars.Assets)
{
string audioInfo = "(no audio)";
if (asset.AudioData != null && asset.AudioData.Length >= 4)
{
string audioMagic = System.Text.Encoding.ASCII.GetString(asset.AudioData, 0, 4);
audioInfo = $"{audioMagic}, {asset.AudioData.Length} bytes";
}
int amtaSize = asset.Amta?.BuildNew().Length ?? 0;
Console.WriteLine($" {asset.Name} [0x{asset.Hash:X8}] - AMTA: {amtaSize}B, Audio: {audioInfo}");
}
return 0;
}
case "add":
{
if (args.Length < 3) { Console.Error.WriteLine("Usage: BarsTool bars add <file.bars> [audio|folder ...] [--name <name>] [--stream] [--waves <dir>] [--streams <dir>]"); return 1; }
string barsPath = args[1];
string? explicitName = null;
string? streamsDir = null;
string? wavesDir = null;
bool treatAsStream = false;
var audioPaths = new List<string>();
for (int i = 2; i < args.Length; i++)
{
if (args[i] == "--name" && i + 1 < args.Length)
explicitName = args[++i];
else if (args[i] == "--streams" && i + 1 < args.Length)
streamsDir = args[++i];
else if (args[i] == "--waves" && i + 1 < args.Length)
wavesDir = args[++i];
else if (args[i] == "--stream")
treatAsStream = true;
else
audioPaths.Add(args[i]);
}
var bars = File.Exists(barsPath) ? BarsFile.Read(barsPath) : new BarsFile();
var resolvedPaths = ResolveAudioPaths(audioPaths, treatAsStream);
foreach (string audioPath in resolvedPaths)
{
string assetName = (explicitName != null && resolvedPaths.Count == 1)
? explicitName
: Path.GetFileNameWithoutExtension(audioPath);
string ext = Path.GetExtension(audioPath).ToLowerInvariant();
if (ext == ".bfstm" || ext == ".bfstp" || (treatAsStream && ext == ".wav"))
{
byte[] fileData;
if (ext == ".wav")
{
Console.WriteLine($"Converting {Path.GetFileName(audioPath)} to BFSTM...");
fileData = BfstmFile.ConvertFromWav(File.ReadAllBytes(audioPath));
}
else
fileData = File.ReadAllBytes(audioPath);
if (ext == ".bfstp")
{
bars.AddAudio(assetName, bars.FindAsset(assetName)?.Amta ?? throw new Exception($"BFSTP import requires existing AMTA for '{assetName}'"), fileData);
}
else
{
var info = BfstmFile.ReadInfo(fileData);
byte[] bfstp = BfstmFile.GenerateBfstp(fileData);
var amta = AmtaFile.CreateFromBfstm(assetName, info, fileData);
bars.AddAudio(assetName, amta, bfstp);
}
Console.WriteLine($"Added stream '{assetName}'");
}
else
{
byte[] bfwavData = LoadAsBfwav(audioPath);
var bfwavInfo = BfwavFile.ReadInfo(bfwavData);
var amta = AmtaFile.CreateFromBfwav(assetName, bfwavInfo, bfwavData);
bars.AddAudio(assetName, amta, bfwavData);
Console.WriteLine($"Added '{assetName}'");
}
}
// Process waves directory
if (wavesDir != null)
{
var waveFiles = ResolveAudioPaths([wavesDir], false);
foreach (string wavePath in waveFiles)
{
string assetName = Path.GetFileNameWithoutExtension(wavePath);
byte[] bfwavData = LoadAsBfwav(wavePath);
var bfwavInfo = BfwavFile.ReadInfo(bfwavData);
var amta = AmtaFile.CreateFromBfwav(assetName, bfwavInfo, bfwavData);
bars.AddAudio(assetName, amta, bfwavData);
Console.WriteLine($"Added '{assetName}'");
}
}
// Process streams directory
if (streamsDir != null)
{
var streamFiles = ResolveAudioPaths([streamsDir], true);
foreach (string streamPath in streamFiles)
{
string assetName = Path.GetFileNameWithoutExtension(streamPath);
string ext = Path.GetExtension(streamPath).ToLowerInvariant();
byte[] fileData;
if (ext == ".wav")
{
Console.WriteLine($"Converting {Path.GetFileName(streamPath)} to BFSTM...");
fileData = BfstmFile.ConvertFromWav(File.ReadAllBytes(streamPath));
}
else if (ext == ".bfstm")
{
fileData = File.ReadAllBytes(streamPath);
}
else continue;
var info = BfstmFile.ReadInfo(fileData);
byte[] bfstp = BfstmFile.GenerateBfstp(fileData);
var amta = AmtaFile.CreateFromBfstm(assetName, info, fileData);
bars.AddAudio(assetName, amta, bfstp);
Console.WriteLine($"Added stream '{assetName}'");
}
}
bars.Save(barsPath);
Console.WriteLine($"Saved {barsPath} ({bars.Assets.Count} total assets)");
return 0;
}
case "create":
{
if (args.Length < 2) { Console.Error.WriteLine("Usage: BarsTool bars create <output.bars> [audio|folder ...] [--names n1,n2,...] [--waves <dir>] [--streams <dir>]"); return 1; }
string output = args[1];
var audioPaths = new List<string>();
string[]? names = null;
string? streamsDir = null;
string? wavesDir = null;
for (int i = 2; i < args.Length; i++)
{
if (args[i] == "--names" && i + 1 < args.Length)
names = args[++i].Split(',');
else if (args[i] == "--streams" && i + 1 < args.Length)
streamsDir = args[++i];
else if (args[i] == "--waves" && i + 1 < args.Length)
wavesDir = args[++i];
else
audioPaths.Add(args[i]);
}
var bars = new BarsFile();
var resolvedPaths = ResolveAudioPaths(audioPaths, false);
for (int i = 0; i < resolvedPaths.Count; i++)
{
string audioPath = resolvedPaths[i];
string assetName = (names != null && i < names.Length) ? names[i] : Path.GetFileNameWithoutExtension(audioPath);
string ext = Path.GetExtension(audioPath).ToLowerInvariant();
if (ext == ".bfstm")
{
byte[] bfstmData = File.ReadAllBytes(audioPath);
var info = BfstmFile.ReadInfo(bfstmData);
byte[] bfstp = BfstmFile.GenerateBfstp(bfstmData);
var amta = AmtaFile.CreateFromBfstm(assetName, info, bfstmData);
bars.AddAudio(assetName, amta, bfstp);
Console.WriteLine($"Added stream '{assetName}'");
}
else
{
byte[] bfwavData = LoadAsBfwav(audioPath);
var bfwavInfo = BfwavFile.ReadInfo(bfwavData);
var amta = AmtaFile.CreateFromBfwav(assetName, bfwavInfo, bfwavData);
bars.AddAudio(assetName, amta, bfwavData);
Console.WriteLine($"Added '{assetName}'");
}
}
// Process waves directory
if (wavesDir != null)
{
var waveFiles = ResolveAudioPaths([wavesDir], false);
foreach (string wavePath in waveFiles)
{
string assetName = Path.GetFileNameWithoutExtension(wavePath);
byte[] bfwavData = LoadAsBfwav(wavePath);
var bfwavInfo = BfwavFile.ReadInfo(bfwavData);
var amta = AmtaFile.CreateFromBfwav(assetName, bfwavInfo, bfwavData);
bars.AddAudio(assetName, amta, bfwavData);
Console.WriteLine($"Added '{assetName}'");
}
}
// Process streams directory
if (streamsDir != null)
{
var streamFiles = ResolveAudioPaths([streamsDir], true);
foreach (string streamPath in streamFiles)
{
string assetName = Path.GetFileNameWithoutExtension(streamPath);
string ext = Path.GetExtension(streamPath).ToLowerInvariant();
byte[] fileData;
if (ext == ".wav")
{
Console.WriteLine($"Converting {Path.GetFileName(streamPath)} to BFSTM...");
fileData = BfstmFile.ConvertFromWav(File.ReadAllBytes(streamPath));
}
else if (ext == ".bfstm")
fileData = File.ReadAllBytes(streamPath);
else continue;
var info = BfstmFile.ReadInfo(fileData);
byte[] bfstp = BfstmFile.GenerateBfstp(fileData);
var amta = AmtaFile.CreateFromBfstm(assetName, info, fileData);
bars.AddAudio(assetName, amta, bfstp);
Console.WriteLine($"Added stream '{assetName}'");
}
}
if (bars.Assets.Count == 0) { Console.Error.WriteLine("No audio assets specified. Provide files, --waves, or --streams."); return 1; }
bars.Save(output);
Console.WriteLine($"Created {output} with {bars.Assets.Count} assets.");
return 0;
}
case "remove":
{
if (args.Length < 3) { Console.Error.WriteLine("Usage: BarsTool bars remove <file.bars> <asset_name>"); return 1; }
string barsPath = args[1];
string assetName = args[2];
var bars = BarsFile.Read(barsPath);
if (bars.RemoveAsset(assetName))
{
bars.Save(barsPath);
Console.WriteLine($"Removed '{assetName}' from {barsPath} ({bars.Assets.Count} remaining)");
}
else
{
Console.Error.WriteLine($"Asset '{assetName}' not found in {barsPath}.");
return 1;
}
return 0;
}
case "extract":
{
if (args.Length < 2) { Console.Error.WriteLine("Usage: BarsTool bars extract <file.bars> [--output <dir>] [--wav] [--streams-dir <dir>]"); return 1; }
string barsPath = args[1];
string outputDir = Path.GetFileNameWithoutExtension(barsPath);
bool convertToWav = false;
string? streamsOutDir = null;
for (int i = 2; i < args.Length; i++)
{
if (args[i] == "--output" && i + 1 < args.Length)
outputDir = args[++i];
else if (args[i] == "--wav")
convertToWav = true;
else if (args[i] == "--streams-dir" && i + 1 < args.Length)
streamsOutDir = args[++i];
}
var bars = BarsFile.Read(barsPath);
Directory.CreateDirectory(outputDir);
if (streamsOutDir != null) Directory.CreateDirectory(streamsOutDir);
foreach (var asset in bars.Assets)
{
if (asset.AudioData == null || asset.AudioData.Length == 0) continue;
string audioMagic = asset.AudioData.Length >= 4
? System.Text.Encoding.ASCII.GetString(asset.AudioData, 0, 4) : "";
if (audioMagic == "FSTP" && streamsOutDir != null)
{
File.WriteAllBytes(Path.Combine(streamsOutDir, asset.Name + ".bfstp"), asset.AudioData);
Console.WriteLine($"Extracted: {asset.Name}.bfstp -> {streamsOutDir}");
}
else if (convertToWav && audioMagic == "FWAV")
{
try
{
byte[] wavData = BfwavFile.ConvertToWav(asset.AudioData);
File.WriteAllBytes(Path.Combine(outputDir, asset.Name + ".wav"), wavData);
Console.WriteLine($"Extracted: {asset.Name}.wav");
}
catch (Exception ex)
{
Console.Error.WriteLine($"Failed to convert {asset.Name}: {ex.Message}, saving raw.");
File.WriteAllBytes(Path.Combine(outputDir, asset.Name + ".bfwav"), asset.AudioData);
}
}
else
{
string audioExt = audioMagic switch
{
"FWAV" => ".bfwav",
"FSTP" => ".bfstp",
"BWAV" => ".bwav",
_ => ".bin"
};
File.WriteAllBytes(Path.Combine(outputDir, asset.Name + audioExt), asset.AudioData);
Console.WriteLine($"Extracted: {asset.Name}{audioExt}");
}
}
return 0;
}
default:
return PrintBarsUsage();
}
}
static int PrintUsage()
{
Console.WriteLine("""
BarsTool - Nintendo BARS/BARSLIST audio tool
Usage: BarsTool <command> [options]
Commands:
barslist Manage .barslist (ARSL) files
bars Manage .bars (BARS) files
wav2bfwav Convert WAV to BFWAV (--bulk for folder)
bfwav2wav Convert BFWAV to WAV (--bulk for folder)
wav2bfstm Convert WAV to BFSTM (--bulk for folder)
bfstm2wav Convert BFSTM to WAV (--bulk for folder)
bfstm2bfstp Generate BFSTP from BFSTM (--bulk for folder)
Run 'BarsTool <command>' for more help.
""");
return 1;
}
static int PrintBarsListUsage()
{
Console.WriteLine("""
BarsTool barslist - Manage .barslist (ARSL) files
Subcommands:
list <file.barslist> List entries
add <file.barslist> <name.bars> [name2.bars ...] Add entries
remove <file.barslist> <name.bars> Remove an entry
create <output.barslist> --name <name> <entry1.bars> [...] Create new
""");
return 1;
}
static int PrintBarsUsage()
{
Console.WriteLine("""
BarsTool bars - Manage .bars (BARS) files
Subcommands:
list <file.bars> List assets
add <file.bars> [audio|folder ...] [--name <n>] [--stream] [--waves <dir>] [--streams <dir>]
remove <file.bars> <asset_name> Remove an asset
create <output.bars> [audio|folder ...] [--names n1,n2,...] [--waves <dir>] [--streams <dir>]
extract <file.bars> [--output <dir>] [--wav] [--streams-dir <dir>]
Paths can be .wav, .bfwav, .bfstm files, or folders.
WAV files are auto-converted. BFSTM files generate BFSTP + AMTA.
--waves <dir> Add WAV/BFWAV files from dir as wave assets
--streams <dir> Add BFSTM/WAV files from dir as stream assets
""");
return 1;
}
static List<string> ResolveAudioPaths(List<string> inputs, bool includeStreams)
{
var result = new List<string>();
foreach (string input in inputs)
{
if (Directory.Exists(input))
{
var files = Directory.GetFiles(input, "*.*")
.Where(f =>
{
string ext = Path.GetExtension(f).ToLowerInvariant();
if (ext == ".wav" || ext == ".bfwav") return true;
if (includeStreams && (ext == ".bfstm" || ext == ".bfstp")) return true;
return false;
})
.OrderBy(f => f, StringComparer.OrdinalIgnoreCase)
.ToList();
if (files.Count == 0)
Console.Error.WriteLine($"Warning: no audio files found in '{input}'");
result.AddRange(files);
}
else
{
result.Add(input);
}
}
return result;
}
static byte[] LoadAsBfwav(string audioPath)
{
byte[] audioData = File.ReadAllBytes(audioPath);
string ext = Path.GetExtension(audioPath).ToLowerInvariant();
if (ext == ".wav")
{
Console.WriteLine($"Converting {Path.GetFileName(audioPath)} to BFWAV...");
return BfwavFile.ConvertFromWav(audioData);
}
if (ext == ".bfwav")
return audioData;
throw new InvalidOperationException($"Unsupported audio format: {ext}");
}