1313namespace ModShardPackerReference ;
1414public 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
0 commit comments