Skip to content
Open
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
10 changes: 7 additions & 3 deletions Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,16 @@ private async void StartConversion_Click(object sender, EventArgs e)
LogMessage("Starting clip conversion process...");

var processingSpan = transaction.StartChild("process-clips-async");
var options = new ProcessingClips.ProcessingOptions
{
Mode = ProcessingClips.PatchMode.Null, // You can add UI controls to select this
Placeholder = "REMOVED",
CaseInsensitive = false // Case sensitive by default
};
var result = await clipProcessor.ProcessClipsAsync(
selectedClips,
blockedResources,
ProcessingClips.PatchMode.Null, // You can add UI controls to select this
"REMOVED",
false // Case sensitive by default
options
);
processingSpan.Finish();

Expand Down
41 changes: 30 additions & 11 deletions ProcessingClips.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,11 @@ public async Task<ResourceFileInfo> GetResourceFileInfoAsync()
/// Process multiple clip files with the specified resource patterns
/// </summary>
public async Task<ProcessingResult> ProcessClipsAsync(List<string> clipFilePaths, List<string> blockedResources,
PatchMode mode = PatchMode.Null, string placeholder = "REMOVED", bool caseInsensitive = false)
ProcessingOptions options = null)
{
// Use default options if not provided
options ??= new ProcessingOptions();

var transaction = SentrySdk.GetSpan() ?? SentrySdk.StartTransaction("process-clips", "process");
var result = new ProcessingResult();

Expand All @@ -261,8 +264,8 @@ public async Task<ProcessingResult> ProcessClipsAsync(List<string> clipFilePaths

transaction.SetExtra("total_clips", clipFilePaths.Count);
transaction.SetExtra("blocked_resources", blockedResources.Count);
transaction.SetExtra("patch_mode", mode.ToString());
transaction.SetExtra("case_insensitive", caseInsensitive);
transaction.SetExtra("patch_mode", options.Mode.ToString());
transaction.SetExtra("case_insensitive", options.CaseInsensitive);

if (!clipFilePaths.Any())
{
Expand Down Expand Up @@ -309,7 +312,7 @@ public async Task<ProcessingResult> ProcessClipsAsync(List<string> clipFilePaths
{
OnProgress?.Invoke($"Processing: {Path.GetFileName(clipPath)}");

var fileResult = await ProcessSingleClipAsync(clipPath, blockedResources, mode, placeholder, caseInsensitive);
var fileResult = await ProcessSingleClipAsync(clipPath, blockedResources, options);

result.ProcessedFiles++;
result.TotalPatches += fileResult.PatchCount;
Expand Down Expand Up @@ -364,7 +367,7 @@ public async Task<ProcessingResult> ProcessClipsAsync(List<string> clipFilePaths
/// Process a single clip file
/// </summary>
private async Task<FileProcessingResult> ProcessSingleClipAsync(string clipPath, List<string> blockedResources,
PatchMode mode, string placeholder, bool caseInsensitive)
ProcessingOptions options)
{
var span = SentrySdk.GetSpan()?.StartChild("process-single-clip") ??
SentrySdk.StartTransaction("process-single-clip", "file.process");
Expand Down Expand Up @@ -415,11 +418,12 @@ private async Task<FileProcessingResult> ProcessSingleClipAsync(string clipPath,
var patchSpan = span.StartChild("find-and-patch");
foreach (var resource in blockedResources)
{
var matches = FindPatternMatches(fileData, resource, caseInsensitive);
var matches = FindPatternMatches(fileData, resource, options.CaseInsensitive);

foreach (var match in matches)
{
ApplyPatch(fileData, match.StartIndex, match.Length, mode, placeholder);
var patchOptions = new PatchOptions { Mode = options.Mode, Placeholder = options.Placeholder };
ApplyPatch(fileData, match.StartIndex, match.Length, patchOptions);
result.PatchCount++;
hasChanges = true;

Expand Down Expand Up @@ -628,17 +632,17 @@ private List<AsciiString> ExtractAsciiStrings(byte[] data)
/// <summary>
/// Apply patch to binary data
/// </summary>
private void ApplyPatch(byte[] data, int startIndex, int length, PatchMode mode, string placeholder)
private void ApplyPatch(byte[] data, int startIndex, int length, PatchOptions options)
{
byte[] replacement;

switch (mode)
switch (options.Mode)
{
case PatchMode.Null:
replacement = new byte[length]; // All zeros
break;
case PatchMode.Placeholder:
var placeholderBytes = Encoding.ASCII.GetBytes(placeholder);
var placeholderBytes = Encoding.ASCII.GetBytes(options.Placeholder);
replacement = new byte[length];

// Repeat placeholder to fill the length
Expand All @@ -648,7 +652,7 @@ private void ApplyPatch(byte[] data, int startIndex, int length, PatchMode mode,
}
break;
default:
throw new ArgumentException($"Unknown patch mode: {mode}");
throw new ArgumentException($"Unknown patch mode: {options.Mode}");
}

// Apply the replacement
Expand Down Expand Up @@ -685,6 +689,21 @@ public List<string> GetBackupExecutionFolders()
}
}

// Processing options parameter object
public class ProcessingOptions
{
public PatchMode Mode { get; set; } = PatchMode.Null;
public string Placeholder { get; set; } = "REMOVED";
public bool CaseInsensitive { get; set; } = false;
}

// Patch options parameter object
public class PatchOptions
{
public PatchMode Mode { get; set; }
public string Placeholder { get; set; }
}

// Storage data structure
public class ResourceStorageData
{
Expand Down

This file was deleted.

Binary file removed obj/Debug/net8.0-windows/apphost.exe
Binary file not shown.
25 changes: 0 additions & 25 deletions obj/Debug/net8.0-windows/clip2load.AssemblyInfo.cs

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions obj/Debug/net8.0-windows/clip2load.GlobalUsings.g.cs

This file was deleted.

Binary file removed obj/Debug/net8.0-windows/clip2load.assets.cache
Binary file not shown.
Binary file removed obj/Debug/net8.0-windows/clip2load.clip2load.resources
Binary file not shown.
Empty file.

This file was deleted.

16 changes: 0 additions & 16 deletions obj/Debug/net8.0-windows/clip2load.csproj.FileListAbsolute.txt

This file was deleted.

Binary file not shown.
11 changes: 0 additions & 11 deletions obj/Debug/net8.0-windows/clip2load.designer.deps.json

This file was deleted.

25 changes: 0 additions & 25 deletions obj/Debug/net8.0-windows/clip2load.designer.runtimeconfig.json

This file was deleted.

Binary file removed obj/Debug/net8.0-windows/clip2load.dll
Binary file not shown.
1 change: 0 additions & 1 deletion obj/Debug/net8.0-windows/clip2load.genruntimeconfig.cache

This file was deleted.

Binary file removed obj/Debug/net8.0-windows/clip2load.pdb
Binary file not shown.
Binary file removed obj/Debug/net8.0-windows/ref/clip2load.dll
Binary file not shown.
Binary file removed obj/Debug/net8.0-windows/refint/clip2load.dll
Binary file not shown.

This file was deleted.

Binary file removed obj/Release/net8.0-windows/apphost.exe
Binary file not shown.
25 changes: 0 additions & 25 deletions obj/Release/net8.0-windows/clip2load.AssemblyInfo.cs

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions obj/Release/net8.0-windows/clip2load.GlobalUsings.g.cs

This file was deleted.

Binary file removed obj/Release/net8.0-windows/clip2load.assets.cache
Binary file not shown.
Binary file not shown.
Empty file.

This file was deleted.

16 changes: 0 additions & 16 deletions obj/Release/net8.0-windows/clip2load.csproj.FileListAbsolute.txt

This file was deleted.

Binary file not shown.
11 changes: 0 additions & 11 deletions obj/Release/net8.0-windows/clip2load.designer.deps.json

This file was deleted.

26 changes: 0 additions & 26 deletions obj/Release/net8.0-windows/clip2load.designer.runtimeconfig.json

This file was deleted.

Binary file removed obj/Release/net8.0-windows/clip2load.dll
Binary file not shown.

This file was deleted.

Binary file removed obj/Release/net8.0-windows/clip2load.pdb
Binary file not shown.
Binary file removed obj/Release/net8.0-windows/ref/clip2load.dll
Binary file not shown.
Binary file removed obj/Release/net8.0-windows/refint/clip2load.dll
Binary file not shown.
Loading