-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDiff.cs
More file actions
108 lines (94 loc) · 3.58 KB
/
Diff.cs
File metadata and controls
108 lines (94 loc) · 3.58 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
using System.Diagnostics;
using Serilog;
using UndertaleModLib;
using UndertaleModLib.Models;
namespace ModShardDiff;
internal static class MainOperations
{
public static async Task MainCommand(string name, string reference, string? outputFolder)
{
outputFolder ??= Path.Join(Environment.CurrentDirectory, Path.DirectorySeparatorChar.ToString(), "results");
LoggerConfiguration logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.File(string.Format("logs/log_{0}.txt", DateTime.Now.ToString("yyyyMMdd_HHmm")));
Log.Logger = logger.CreateLogger();
Console.WriteLine($"Exporting differences between {name} and {reference} in {outputFolder}.");
Stopwatch stopWatch = new();
stopWatch.Start();
Task<bool> task = FileReader.Diff(name, reference, outputFolder);
try
{
await task;
}
catch(Exception ex)
{
Log.Error(ex, "Something went wrong");
}
if (task.Result)
{
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
string elapsedTime = string.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
Console.WriteLine($"Process failed successfully in {elapsedTime}.");
}
else
{
Console.WriteLine("Failed exporting differences.");
}
await Log.CloseAndFlushAsync();
}
}
internal static class FileReader
{
public static async Task<bool> Diff(string name, string reference, string outputFolder)
{
DirectoryInfo dir = new(outputFolder);
if (dir.Exists) dir.Delete(true);
dir.Create();
if (!File.Exists(name)) throw new FileNotFoundException($"File {name} does not exist.");
if (!File.Exists(reference)) throw new FileNotFoundException($"File {reference} does not exist.");
Task<UndertaleData?> taskName = LoadFile(name);
await taskName;
Task<UndertaleData?> taskRef = LoadFile(reference);
await taskRef;
if (taskName.Result == null || taskRef.Result == null) throw new FormatException($"Cannot load {name} and {outputFolder}.");
DiffUtils.DiffCodes(taskName.Result, taskRef.Result, dir);
DiffUtils.DiffObjects(taskName.Result, taskRef.Result, dir);
DiffUtils.DiffRooms(taskName.Result, taskRef.Result, dir);
DiffUtils.DiffSounds(taskName.Result, taskRef.Result, dir);
DiffUtils.DiffSprites(taskName.Result, taskRef.Result, dir);
DiffUtils.DiffTexturePageItems(taskName.Result, taskRef.Result, dir);
return true;
}
private static UndertaleData? LoadUmt(string filename)
{
UndertaleData? data = null;
using (FileStream stream = new(filename, FileMode.Open, FileAccess.Read))
{
data = UndertaleIO.Read(stream);
}
UndertaleEmbeddedTexture.TexData.ClearSharedStream();
Log.Information(string.Format("Successfully load: {0}.", filename));
return data;
}
public static async Task<UndertaleData?> LoadFile(string filename)
{
UndertaleData? data = null;
// task load a data.win with umt
Task taskLoadDataWinWithUmt = Task.Run(() =>
{
try
{
data = LoadUmt(filename);
}
catch (Exception ex)
{
Log.Error(ex, "Something went wrong");
throw;
}
});
// run
await taskLoadDataWinWithUmt;
return data;
}
}