-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPacker.cs
More file actions
81 lines (70 loc) · 2.51 KB
/
Packer.cs
File metadata and controls
81 lines (70 loc) · 2.51 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
using System.Diagnostics;
using Serilog;
using ModShardPackerReference;
namespace ModShardPacker;
internal static class MainOperations
{
public static async Task MainCommand(string? name, string packingFolder, string? outputFolder, string? dllFolder, bool isVerbose)
{
dllFolder ??= Environment.CurrentDirectory;
outputFolder ??= packingFolder;
if (isVerbose)
{
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($"Packing {packingFolder} in {outputFolder} using dll from {dllFolder}");
if (Pack(name, packingFolder, outputFolder, dllFolder))
{
Console.WriteLine($"Successfully packed {packingFolder}");
}
else
{
Console.WriteLine($"Failed packing {packingFolder}");
}
await Log.CloseAndFlushAsync();
}
public static bool Pack(string? namePacked, string folderToPack, string outputfolder, string dllfolder)
{
// work around to find the FileVersion of ModShardLauncher.dll for single file publishing
// see: https://github.com/dotnet/runtime/issues/13051
string mslVersion;
try
{
mslVersion = "v" + FileVersionInfo.GetVersionInfo(typeof(ModShardLauncher.Mods.Mod).Assembly.Location).FileVersion;
}
catch(FileNotFoundException ex)
{
Log.Error(ex, "Cannot find the dll of ModShardLauncher");
return false;
}
bool resultPacking = false;
try
{
resultPacking = FilePacker.Pack(
namePacked,
folderToPack,
outputfolder,
dllfolder,
mslVersion,
new Type[2] {typeof(ModShardLauncher.Mods.Mod), typeof(UndertaleModLib.Models.UndertaleCode)}
);
}
catch(Exception ex)
{
if (ex is ArgumentNullException || ex is ArgumentException || ex is IOException || ex is DirectoryNotFoundException)
{
Log.Error(ex.ToString());
}
else
{
Log.Error(ex, "Unexpected error");
}
Console.WriteLine(ex.Message);
Log.Error(ex.ToString());
}
return resultPacking;
}
}