Skip to content

Commit 60b2389

Browse files
committed
Add --output-name CLI option to configure output filename (#109)
1 parent 96a256f commit 60b2389

File tree

7 files changed

+22
-2
lines changed

7 files changed

+22
-2
lines changed

docs/source/usage/how-to-use.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Available options:
4040
- ``--criticals-file``: Custom criticals config file
4141
- ``--logging-file``: Custom logging config file
4242
- ``--obfuscation-file``: Custom obfuscation config file
43+
- ``-n, --output-name``: Custom output file name (default: same as input)
4344
- ``--no-watermark``: Turn off watermarking
4445
- ``--strong-name-key``: Path to strong name key (.snk) file for assembly signing
4546

@@ -177,9 +178,12 @@ You can use glob patterns (``*``) in base types and method patterns.
177178
178179
{
179180
"Watermark": true,
180-
"OutputDirectoryName": "output"
181+
"OutputDirectoryName": "output",
182+
"OutputFileName": null
181183
}
182184
185+
- ``OutputFileName``: Custom output file name (e.g., ``"Protected.dll"``). When set, uses the exact name ignoring watermark suffix.
186+
183187
Most settings have sensible defaults. You only need to change them if you want something different.
184188

185189
Unity Integration

src/BitMono.CLI/Modules/Options.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,7 @@ internal class Options
3131

3232
[Option("strong-name-key", Required = false, HelpText = "Path to strong name key (.snk) file for assembly signing.")]
3333
public string? StrongNameKey { get; set; }
34+
35+
[Option('n', "output-name", Required = false, HelpText = "Set output file name.")]
36+
public string? OutputName { get; set; }
3437
}

src/BitMono.CLI/Modules/OptionsObfuscationNeedsFactory.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public OptionsObfuscationNeedsFactory(string[] args)
5454
{
5555
obfuscationSettings.StrongNameKeyFile = options.StrongNameKey;
5656
}
57+
58+
if (obfuscationSettings != null && !string.IsNullOrEmpty(options.OutputName))
59+
{
60+
obfuscationSettings.OutputFileName = options.OutputName;
61+
}
5762
}
5863
catch (Exception ex)
5964
{

src/BitMono.Core/Contexts/BitMonoContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class BitMonoContext
66
public string FileName { get; set; }
77
public string OutputDirectoryName { get; set; }
88
public string OutputFile { get; set; }
9+
public string? OutputFileName { get; set; }
910
public List<byte[]> ReferencesData { get; set; }
1011
public bool Watermark { get; set; }
1112
#pragma warning restore CS8618

src/BitMono.Obfuscation/Files/OutputFilePathFactory.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ public static class OutputFilePathFactory
66

77
public static string Create(BitMonoContext context)
88
{
9+
if (!string.IsNullOrEmpty(context.OutputFileName))
10+
{
11+
return Path.Combine(context.OutputDirectoryName, context.OutputFileName);
12+
}
13+
914
var stringBuilder = new StringBuilder();
1015
stringBuilder.Append(Path.GetFileNameWithoutExtension(context.FileName));
1116
if (context.Watermark)

src/BitMono.Obfuscation/Starter/BitMonoContextFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public BitMonoContext Create(string filePath, string outputDirectoryName, Cancel
2323
OutputDirectoryName = outputDirectoryName,
2424
ReferencesData = referencesData,
2525
Watermark = _obfuscationSettings.Watermark,
26-
FileName = fileName
26+
FileName = fileName,
27+
OutputFileName = _obfuscationSettings.OutputFileName
2728
};
2829
}
2930
}

src/BitMono.Shared/Models/ObfuscationSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ public class ObfuscationSettings
2323
public string[]? SpecificNamespaces { get; set; }
2424
public string[]? RandomStrings { get; set; }
2525
public string? StrongNameKeyFile { get; set; }
26+
public string? OutputFileName { get; set; }
2627
}

0 commit comments

Comments
 (0)