Skip to content

Commit 8f7f5f3

Browse files
committed
[Major] removes reference to UTMTLib, adds error more handling
1 parent 7b53c47 commit 8f7f5f3

4 files changed

Lines changed: 71 additions & 19 deletions

File tree

ModShardPackerReference.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@
2626
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0"/>
2727
</ItemGroup>
2828

29-
<ItemGroup>
30-
<Reference Include="UndertaleModLib">
31-
<HintPath>lib\UndertaleModLib.dll</HintPath>
32-
</Reference>
33-
</ItemGroup>
34-
3529
<PropertyGroup>
3630
<RepositoryUrl>https://github.com/ModShardTeam/ModShardPackerReference</RepositoryUrl>
3731
</PropertyGroup>

ModShardPackerReference.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.002.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModShardPackerReference", "ModShardPackerReference.csproj", "{F7C22641-71DE-406D-AF57-C4432CD07417}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{F7C22641-71DE-406D-AF57-C4432CD07417}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{F7C22641-71DE-406D-AF57-C4432CD07417}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{F7C22641-71DE-406D-AF57-C4432CD07417}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{F7C22641-71DE-406D-AF57-C4432CD07417}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {EE385F3E-12A2-4C02-8D0C-AD9AF8D732D8}
24+
EndGlobalSection
25+
EndGlobal

Packer.cs

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,18 @@
1313
namespace ModShardPackerReference;
1414
public static class FilePacker
1515
{
16-
public static bool Pack(string? namePacked, string folderToPack, string outputfolder, string dllfolder, string frontVersion, Type ModShardLauncherModType)
16+
/// <summary>
17+
/// Pack function
18+
/// </summary>
19+
/// <param name="namePacked"></param>
20+
/// <param name="folderToPack"></param>
21+
/// <param name="outputfolder"></param>
22+
/// <param name="dllfolder"></param>
23+
/// <param name="frontVersion"></param>
24+
/// <param name="neededType"></param>
25+
/// <returns></returns>
26+
/// <exception cref="DirectoryNotFoundException"></exception>
27+
public static bool Pack(string? namePacked, string folderToPack, string outputfolder, string dllfolder, string frontVersion, Type[] neededType)
1728
{
1829
Log.Information("Starting packing {0}", folderToPack);
1930

@@ -108,7 +119,18 @@ public static bool Pack(string? namePacked, string folderToPack, string outputfo
108119
Log.Information("Writting assemblies...");
109120

110121
Log.Information("Starting compilation...");
111-
bool successful = CompileMod(namePacked, folderToPack, dllfolder, ModShardLauncherModType, out byte[] code, out _);
122+
123+
bool successful;
124+
byte[] code;
125+
try
126+
{
127+
successful = CompileMod(namePacked, folderToPack, dllfolder, neededType, out code, out _);
128+
}
129+
catch
130+
{
131+
throw;
132+
}
133+
112134
if (!successful)
113135
{
114136
fs.Close();
@@ -173,7 +195,7 @@ public static List<MetadataReference> GetSystemMetadataReferences()
173195
IEnumerable<string> filteredPath = trustedList.Where(p => required.Exists(r => p.Contains(r)));
174196
return filteredPath.Select(x => MetadataReference.CreateFromFile(x) as MetadataReference).ToList();
175197
}
176-
public static Diagnostic[] RoslynCompile(string name, IEnumerable<string> files, IEnumerable<string> preprocessorSymbols, string dllfolder, Type ModShardLauncherModType, out byte[] code, out byte[] pdb)
198+
public static Diagnostic[] RoslynCompile(string name, IEnumerable<string> files, IEnumerable<string> preprocessorSymbols, string dllfolder, Type[] neededType, out byte[] code, out byte[] pdb)
177199
{
178200
NameSyntax[] qualifiedNames = {
179201
SyntaxFactory.ParseName("System"),
@@ -200,14 +222,16 @@ public static Diagnostic[] RoslynCompile(string name, IEnumerable<string> files,
200222
IEnumerable<MetadataReference> defaultReferences = Directory.GetFiles(dllfolder, "*.dll")
201223
.Select(x => MetadataReference.CreateFromFile(x));
202224

203-
// add more references
204-
Type[] neededType = {
205-
typeof(UndertaleModLib.Models.UndertaleCode),
206-
ModShardLauncherModType
207-
};
208-
defaultReferences = defaultReferences
209-
.Concat(neededType.Select(x => MetadataReference.CreateFromFile(x.Assembly.Location)))
210-
.Concat(GetSystemMetadataReferences());
225+
try
226+
{
227+
defaultReferences = defaultReferences
228+
.Concat(neededType.Select(x => MetadataReference.CreateFromFile(x.Assembly.Location)))
229+
.Concat(GetSystemMetadataReferences());
230+
}
231+
catch
232+
{
233+
throw;
234+
}
211235

212236
IEnumerable<SyntaxTree> src = files.Select(f => SyntaxFactory.ParseSyntaxTree(File.ReadAllText(f), parseOptions, f, Encoding.UTF8));
213237
// update tree before compilation to add needed using
@@ -262,14 +286,23 @@ public static Diagnostic[] RoslynCompile(string name, IEnumerable<string> files,
262286

263287
return results.Diagnostics.ToArray();
264288
}
265-
public static bool CompileMod(string name, string path, string dllfolder, Type ModShardLauncherModType, out byte[] code, out byte[] pdb)
289+
public static bool CompileMod(string name, string path, string dllfolder, Type[] neededType, out byte[] code, out byte[] pdb)
266290
{
267291
IEnumerable<string> files = Directory
268292
.GetFiles(path, "*.cs", SearchOption.AllDirectories)
269293
.Where(file => !IgnoreCompletely(path, file));
270294

271295
Log.Information("Compilation: Gathering files...");
272-
Diagnostic[] result = RoslynCompile(name, files, new[] { "FNA" }, dllfolder, ModShardLauncherModType, out code, out pdb);
296+
297+
Diagnostic[] result = Array.Empty<Diagnostic>();
298+
try
299+
{
300+
result = RoslynCompile(name, files, new[] { "FNA" }, dllfolder, neededType, out code, out pdb);
301+
}
302+
catch
303+
{
304+
throw;
305+
}
273306

274307
Log.Information("Compilation: Gathering results...");
275308

lib/UndertaleModLib.dll

-1000 KB
Binary file not shown.

0 commit comments

Comments
 (0)