-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
154 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Diagnostics; | ||
using System.Text.RegularExpressions; | ||
using CliFx; | ||
using CliFx.Attributes; | ||
using CliFx.Infrastructure; | ||
using StarBreaker.Forge; | ||
|
||
namespace StarBreaker; | ||
|
||
[Command("extract", Description = "Extracts a DataForge binary file into separate xml files")] | ||
public class ExtractCommand : ICommand | ||
{ | ||
[CommandOption("dcb", 'd', Description = "Path to the DataForge binary file")] | ||
public required string DataForgeBinary { get; init; } | ||
|
||
[CommandOption("output", 'o', Description = "Path to the output directory")] | ||
public required string OutputDirectory { get; init; } | ||
|
||
[CommandOption("filter", 'f', Description = "Regex pattern to filter entries")] | ||
public Regex? RegexPattern { get; init; } | ||
|
||
public ValueTask ExecuteAsync(IConsole console) | ||
{ | ||
var bytes = File.ReadAllBytes(DataForgeBinary); | ||
var dataForge = new DataForge(bytes, OutputDirectory); | ||
|
||
console.Output.WriteLine("DataForge loaded."); | ||
console.Output.WriteLine("Exporting..."); | ||
|
||
var sw = Stopwatch.StartNew(); | ||
dataForge.Export(RegexPattern, new ProgressBar(console)); | ||
sw.Stop(); | ||
|
||
console.Output.WriteLine(); | ||
console.Output.WriteLine($"Export completed in {sw.ElapsedMilliseconds}ms."); | ||
|
||
return default; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Diagnostics; | ||
using System.Text.RegularExpressions; | ||
using CliFx; | ||
using CliFx.Attributes; | ||
using CliFx.Infrastructure; | ||
using StarBreaker.Forge; | ||
|
||
namespace StarBreaker; | ||
|
||
[Command("extract-single", Description = "Extracts a DataForge binary file into a single xml")] | ||
public class ExtractSingleCommand : ICommand | ||
{ | ||
[CommandOption("dcb", 'd', Description = "Path to the DataForge binary file")] | ||
public required string DataForgeBinary { get; init; } | ||
|
||
[CommandOption("output", 'o', Description = "Path to the output directory")] | ||
public required string OutputDirectory { get; init; } | ||
|
||
[CommandOption("filter", 'f', Description = "Regex pattern to filter entries")] | ||
public Regex? RegexPattern { get; init; } | ||
|
||
public ValueTask ExecuteAsync(IConsole console) | ||
{ | ||
var bytes = File.ReadAllBytes(DataForgeBinary); | ||
var dataForge = new DataForge(bytes, OutputDirectory); | ||
|
||
console.Output.WriteLine("DataForge loaded."); | ||
console.Output.WriteLine("Exporting..."); | ||
|
||
var sw = Stopwatch.StartNew(); | ||
dataForge.ExportSingle(RegexPattern, new ProgressBar(console)); | ||
sw.Stop(); | ||
|
||
console.Output.WriteLine(); | ||
console.Output.WriteLine($"Export completed in {sw.ElapsedMilliseconds}ms."); | ||
|
||
return default; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,6 @@ | ||
using System.Diagnostics; | ||
using StarBreaker.Forge; | ||
using CliFx; | ||
|
||
namespace StarBreaker; | ||
|
||
public static class Program | ||
{ | ||
private const string dcb = @"C:\Scratch\extract\Game.dcb"; | ||
private const string destDir = @"C:\Scratch\extract\stbr\"; | ||
private static DataForge dataForge = null!; | ||
|
||
public static void Main() | ||
{ | ||
var bytes = File.ReadAllBytes(dcb); | ||
|
||
var sw1 = Stopwatch.StartNew(); | ||
dataForge = new DataForge(bytes, destDir); | ||
Console.WriteLine($"DataForge Constructor took: {sw1.ElapsedMilliseconds}ms"); | ||
|
||
var printed1 = -1; | ||
var exportProgress = new Progress<float>(percent => | ||
{ | ||
if (Math.Abs(percent % 10) < 1) | ||
{ | ||
var part = (int)percent / 10; | ||
if (part > printed1) | ||
{ | ||
printed1 = part; | ||
Console.WriteLine($"Export {percent}%"); | ||
} | ||
} | ||
}); | ||
var sw2 = Stopwatch.StartNew(); | ||
dataForge.Export(null, exportProgress); | ||
Console.WriteLine($"Export took: {sw2.ElapsedMilliseconds}ms"); | ||
|
||
int printed = -1; | ||
var exportProgress1 = new Progress<float>(percent => | ||
{ | ||
if (Math.Abs(percent % 10) < 1) | ||
{ | ||
var part = (int)percent / 10; | ||
if (part > printed) | ||
{ | ||
printed = part; | ||
Console.WriteLine($"ExportSingle {percent}%"); | ||
} | ||
} | ||
}); | ||
var sw = Stopwatch.StartNew(); | ||
dataForge.ExportSingle(null, exportProgress1); | ||
Console.WriteLine($"ExportSingle took: {sw.ElapsedMilliseconds}ms"); | ||
|
||
// foreach (var x in dataForge.ExportEnums()) | ||
// { | ||
// File.WriteAllText(Path.Combine(destDir, Path.ChangeExtension(x.Key, ".txt")), string.Join("\n", x.Value)); | ||
// } | ||
} | ||
} | ||
return await new CliApplicationBuilder() | ||
.AddCommandsFromThisAssembly() | ||
.Build() | ||
.RunAsync(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using CliFx.Infrastructure; | ||
|
||
namespace StarBreaker; | ||
|
||
public class ProgressBar : IProgress<double> | ||
{ | ||
private const int _totalBlocks = 20; | ||
private readonly IConsole _console; | ||
private int? _originalCursorLeft; | ||
private int? _originalCursorTop; | ||
|
||
public ProgressBar(IConsole console) | ||
{ | ||
_console = console; | ||
} | ||
|
||
private void RenderProgress(double progress) | ||
{ | ||
if (_originalCursorLeft != null && _originalCursorTop != null) | ||
{ | ||
_console.CursorLeft = _originalCursorLeft.Value; | ||
_console.CursorTop = _originalCursorTop.Value; | ||
} | ||
else | ||
{ | ||
_originalCursorLeft = _console.CursorLeft; | ||
_originalCursorTop = _console.CursorTop; | ||
} | ||
|
||
var completedBlocks = (int)(progress * _totalBlocks); | ||
var progressBar = new string('#', completedBlocks) + new string('-', _totalBlocks - completedBlocks); | ||
|
||
_console.Output.Write($"[{progressBar}] {progress:P0}"); | ||
} | ||
|
||
public void Report(double progress) | ||
{ | ||
if (!_console.IsOutputRedirected) | ||
{ | ||
RenderProgress(progress); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"profiles": { | ||
"extract": { | ||
"commandName": "Project", | ||
"commandLineArgs": "extract --dcb \"C:\\Scratch\\extract\\Game.dcb\" --output \"C:\\Scratch\\extract\\stbr\" --filter \"^[0-9A-Za-z]{3}[0-9A-Za-z-]\\d{0,21}$\"" | ||
}, | ||
"extract-single": { | ||
"commandName": "Project", | ||
"commandLineArgs": "extract-single --dcb \"C:\\Scratch\\extract\\Game.dcb\" --output \"C:\\Scratch\\extract\\stbr\" --filter \"^[0-9A-Za-z]{3}[0-9A-Za-z-]\\d{0,21}$\"" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters