mirror of
https://github.com/Team-Resurgent/Repackinator.git
synced 2026-04-30 10:07:40 -07:00
Added: delegates
This commit is contained in:
@@ -7,15 +7,22 @@ using Resurgent.UtilityBelt.Library.Utilities.XbeModels;
|
||||
|
||||
namespace Repackinator.Shared
|
||||
{
|
||||
public static class Repacker
|
||||
public class Repacker
|
||||
{
|
||||
private static FileStream? LogStream { get; set; }
|
||||
public struct ProgressInfo
|
||||
{
|
||||
|
||||
private static string? TempFolder { get; set; }
|
||||
}
|
||||
|
||||
private static string? SevenZipFile { get; set; }
|
||||
private Action<string>? Logger { get; set; }
|
||||
|
||||
private static GameData[]? GameDataList { get; set; }
|
||||
private Action<ProgressInfo>? Progress { get; set; }
|
||||
|
||||
private string? TempFolder { get; set; }
|
||||
|
||||
private string? SevenZipFile { get; set; }
|
||||
|
||||
private GameData[]? GameDataList { get; set; }
|
||||
|
||||
public enum GroupingEnum
|
||||
{
|
||||
@@ -26,18 +33,16 @@ namespace Repackinator.Shared
|
||||
LetterRegion
|
||||
}
|
||||
|
||||
private static void Log(string message)
|
||||
{
|
||||
Console.WriteLine(message);
|
||||
if (LogStream == null)
|
||||
private void Log(string message)
|
||||
{
|
||||
if (Logger == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var bytes = Encoding.UTF8.GetBytes(message);
|
||||
LogStream.Write(bytes);
|
||||
Logger(message);
|
||||
}
|
||||
|
||||
private static void ProcessFile(string inputFile, string outputPath, GroupingEnum grouping, bool alternate)
|
||||
private void ProcessFile(string inputFile, string outputPath, GroupingEnum grouping, bool alternate)
|
||||
{
|
||||
if (TempFolder == null)
|
||||
{
|
||||
@@ -334,17 +339,12 @@ namespace Repackinator.Shared
|
||||
}
|
||||
}
|
||||
|
||||
public static void StartConversion(string input, string output, string temp, GroupingEnum grouping, bool alternate, string log)
|
||||
public void StartConversion(string input, string output, string temp, GroupingEnum grouping, bool alternate, Action<ProgressInfo>? progress, Action<string> logger)
|
||||
{
|
||||
FileStream? logStream = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(log))
|
||||
{
|
||||
LogStream = File.OpenWrite(log);
|
||||
}
|
||||
|
||||
{
|
||||
Logger = logger;
|
||||
|
||||
GameDataList = GameData.LoadGameData();
|
||||
if (GameDataList == null)
|
||||
{
|
||||
@@ -371,15 +371,11 @@ namespace Repackinator.Shared
|
||||
{
|
||||
ProcessFile(file, output, grouping, alternate);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (logStream != null)
|
||||
{
|
||||
logStream.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger($"Error: {ex}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+26
-1
@@ -1,5 +1,7 @@
|
||||
using Repackinator.Shared;
|
||||
using Mono.Options;
|
||||
using System.Text;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
var shouldShowHelp = false;
|
||||
var input = "";
|
||||
@@ -198,7 +200,30 @@ try
|
||||
groupingValue = Repacker.GroupingEnum.LetterRegion;
|
||||
}
|
||||
|
||||
Repacker.StartConversion(input, output, temp, groupingValue, alternateValue, log);
|
||||
FileStream? logStream = null;
|
||||
if (!string.IsNullOrEmpty(log))
|
||||
{
|
||||
logStream = File.OpenWrite(log);
|
||||
}
|
||||
|
||||
var logger = new Action<string>((message) =>
|
||||
{
|
||||
Console.WriteLine(message);
|
||||
var bytes = Encoding.UTF8.GetBytes(message);
|
||||
if (logStream != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
logStream.Write(bytes);
|
||||
});
|
||||
|
||||
var repacker = new Repacker();
|
||||
repacker.StartConversion(input, output, temp, groupingValue, alternateValue, null, logger);
|
||||
|
||||
if (logStream != null)
|
||||
{
|
||||
logStream.Dispose();
|
||||
}
|
||||
|
||||
Console.WriteLine("Done!");
|
||||
Console.ReadLine();
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = crlf
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
insert_fianl_newline = true
|
||||
Reference in New Issue
Block a user