@@ -27,7 +27,7 @@ namespace Oxide.CSharp
2727 internal class CompilerService
2828 {
2929 private readonly Hash < int , Compilation > _compilations ;
30- private readonly Queue < CompilerMessage > _messageQueue = new Queue < CompilerMessage > ( ) ;
30+ private readonly Queue < CompilerMessage > _messageQueue = new ( ) ;
3131 private Process ? _compilerProcess ;
3232 private volatile int _lastId ;
3333 private volatile bool _ready ;
@@ -116,22 +116,24 @@ internal bool Precheck()
116116 "OXIDEMOD"
117117 } ;
118118
119- Extension ? game = Interface . Oxide . GetAllExtensions ( ) . SingleOrDefault ( e => e . IsGameExtension ) ;
120- if ( game != null )
119+ IEnumerable < Extension > extensions = Interface . Oxide . GetAllExtensions ( ) ;
120+
121+ Extension ? gameExtension = extensions . SingleOrDefault ( extension => extension . IsGameExtension ) ;
122+ if ( gameExtension != null )
121123 {
122- string name = game . Name . ToUpperInvariant ( ) ;
123- string branch = game . Branch ? . ToUpperInvariant ( ) ?? "PUBLIC" ;
124+ string name = gameExtension . Name . ToUpperInvariant ( ) ;
125+ string branch = gameExtension . Branch ? . ToUpperInvariant ( ) ?? "PUBLIC" ;
124126 preprocessors . Add ( EscapeSymbolName ( name ) ) ;
125127 preprocessors . Add ( EscapeSymbolName ( name + "_" + branch ) ) ;
126128
127- if ( game . Version != default )
129+ if ( gameExtension . Version != default )
128130 {
129- preprocessors . Add ( EscapeSymbolName ( name + "_" + game . Version ) ) ;
130- preprocessors . Add ( EscapeSymbolName ( name + "_" + game . Version + "_" + branch ) ) ;
131+ preprocessors . Add ( EscapeSymbolName ( name + "_" + gameExtension . Version ) ) ;
132+ preprocessors . Add ( EscapeSymbolName ( name + "_" + gameExtension . Version + "_" + branch ) ) ;
131133 }
132134 }
133135
134- foreach ( Extension extension in Interface . Oxide . GetAllExtensions ( ) )
136+ foreach ( Extension extension in extensions )
135137 {
136138 try
137139 {
@@ -212,9 +214,9 @@ private bool Start()
212214 Thread . Sleep ( 100 ) ;
213215 }
214216 }
215- catch ( Exception e )
217+ catch ( Exception exception )
216218 {
217- Log ( LogType . Error , e . Message ) ;
219+ Log ( LogType . Error , exception . Message ) ;
218220 return false ;
219221 }
220222
@@ -243,11 +245,11 @@ private bool Start()
243245 _compilerProcess . Exited += OnCompilerProcessExited ;
244246 _compilerProcess . Start ( ) ;
245247 }
246- catch ( Exception ex )
248+ catch ( Exception exception )
247249 {
248250 _compilerProcess ? . Dispose ( ) ;
249251 _compilerProcess = null ;
250- Interface . Oxide . LogException ( $ "Exception while starting compiler", ex ) ;
252+ Interface . Oxide . LogException ( $ "Exception while starting compiler", exception ) ;
251253 if ( _filePath . Contains ( "'" ) )
252254 {
253255 Interface . Oxide . LogError ( "Server directory path contains an apostrophe, compiler will not work until path is renamed" ) ;
@@ -257,15 +259,15 @@ private bool Start()
257259 Interface . Oxide . LogError ( "Compiler may not be set as executable; chmod +x or 0744/0755 required" ) ;
258260 }
259261
260- if ( ex . GetBaseException ( ) != ex )
262+ Exception baseException = exception . GetBaseException ( ) ;
263+ if ( baseException != exception )
261264 {
262- Interface . Oxide . LogException ( "BaseException: " , ex . GetBaseException ( ) ) ;
265+ Interface . Oxide . LogException ( "BaseException: " , baseException ) ;
263266 }
264267
265- Win32Exception win32 = ex as Win32Exception ;
266- if ( win32 != null )
268+ if ( exception is Win32Exception win32Exception )
267269 {
268- Interface . Oxide . LogError ( $ "Win32 NativeErrorCode: { win32 . NativeErrorCode } ErrorCode: { win32 . ErrorCode } HelpLink: { win32 . HelpLink } ") ;
270+ Interface . Oxide . LogError ( $ "Win32 NativeErrorCode: { win32Exception . NativeErrorCode } ErrorCode: { win32Exception . ErrorCode } HelpLink: { win32Exception . HelpLink } ") ;
269271 }
270272 }
271273
@@ -308,16 +310,19 @@ private void OnMessageReceived(CompilerMessage message)
308310
309311 if ( message . Errors != null )
310312 {
311- foreach ( CompilerError error in message . Errors )
313+ int errorCount = message . Errors . Count ;
314+ for ( int i = 0 ; i < errorCount ; i ++ )
312315 {
316+ CompilerError error = message . Errors [ i ] ;
313317 Log ( LogType . Error , $ "Compiler error for compilation { compilation . name } : { error . Message } ") ;
314318
315319 CompilablePlugin ? compilablePlugin =
316320 compilation . plugins . SingleOrDefault ( pl => pl . ScriptName == error . File ) ;
317321
318322 if ( compilablePlugin == null )
319323 {
320- Interface . Oxide . LogError ( $ "Unable to resolve script error to { error . File } : { error . Message } ") ;
324+ Interface . Oxide . LogError (
325+ $ "Unable to resolve script error to { error . File } : { error . Message } ") ;
321326 continue ;
322327 }
323328
@@ -327,9 +332,10 @@ private void OnMessageReceived(CompilerMessage message)
327332 string [ ] missingRequirementsArray = missingRequirements . ToArray ( ) ;
328333 if ( missingRequirementsArray . Length > 0 )
329334 {
330- compilablePlugin . CompilerErrors . Add ( $ "Missing dependencies: { string . Join ( "," , missingRequirementsArray ) } ") ;
335+ compilablePlugin . CompilerErrors . Add (
336+ $ "Missing dependencies: { missingRequirementsArray . JoinValues ( ',' ) } ") ;
331337
332- Log ( LogType . Error , $ "[{ error . File } ] Missing dependencies: { string . Join ( "," , missingRequirementsArray ) } ") ;
338+ Log ( LogType . Error , $ "[{ error . File } ] Missing dependencies: { missingRequirementsArray . JoinValues ( ',' ) } ") ;
333339 }
334340 else
335341 {
@@ -341,7 +347,7 @@ private void OnMessageReceived(CompilerMessage message)
341347 }
342348
343349 CompilationResult ? compilationResult = Constants . Serializer . Deserialize < CompilationResult > ( message . Data ) ;
344- if ( compilationResult . Data == null || compilationResult . Data . Length == 0 )
350+ if ( compilationResult ? . Data == null || compilationResult . Data . Length == 0 )
345351 {
346352 compilation . Completed ( ) ;
347353 }
@@ -368,9 +374,9 @@ private void OnMessageReceived(CompilerMessage message)
368374 return ;
369375 }
370376
371- foreach ( CompilablePlugin p in compilation . plugins )
377+ foreach ( CompilablePlugin compilablePlugin in compilation . plugins )
372378 {
373- p . CompilerErrors . Add ( errorMessage ) ;
379+ compilablePlugin . CompilerErrors . Add ( errorMessage ) ;
374380 }
375381
376382 compilation . Completed ( ) ;
@@ -380,6 +386,7 @@ private void OnMessageReceived(CompilerMessage message)
380386 {
381387 string logMessage =
382388 $ "Ready signal received from compiler (Startup took: { Math . Round ( ( Interface . Oxide . Now - _startTime ) * 1000f ) } ms)";
389+
383390 switch ( _messageQueue . Count )
384391 {
385392 case 0 :
@@ -672,19 +679,19 @@ private static bool SetFilePermissions(string filePath)
672679 Log ( LogType . Info , $ "{ name } is executable") ;
673680 }
674681 }
675- catch ( Exception ex )
682+ catch ( Exception exception )
676683 {
677- Interface . Oxide . LogException ( $ "Unable to check { name } for executable permission", ex ) ;
684+ Interface . Oxide . LogException ( $ "Unable to check { name } for executable permission", exception ) ;
678685 }
679686 try
680687 {
681688 Syscall . chmod ( filePath , FilePermissions . S_IRWXU ) ;
682689 Interface . Oxide . LogInfo ( $ "File permissions set for { name } ") ;
683690 return true ;
684691 }
685- catch ( Exception ex )
692+ catch ( Exception exception )
686693 {
687- Interface . Oxide . LogException ( $ "Could not set { filePath } as executable, please set manually", ex ) ;
694+ Interface . Oxide . LogException ( $ "Could not set { filePath } as executable, please set manually", exception ) ;
688695 }
689696
690697 return false ;
@@ -716,10 +723,7 @@ private static bool DownloadFile(string url, string path, int retries = 3)
716723 Interface . Oxide . LogInfo ( $ "[CSharp] Downloading { fileName } . . .") ;
717724 }
718725
719- byte [ ] data ;
720- int code ;
721- bool newerFound ;
722- if ( ! TryDownload ( url , retries , ref retry , last , out data , out code , out newerFound , ref md5 ) )
726+ if ( ! TryDownload ( url , retries , ref retry , last , out byte [ ] data , out int code , out bool newerFound , ref md5 ) )
723727 {
724728 string attemptVerb = retries == 1 ? "attempt" : "attempts" ;
725729 Interface . Oxide . LogError ( $ "[CSharp] Failed to download { fileName } after { retry } { attemptVerb } with response code '{ code } ', please manually download it from { url } and save it here { path } ") ;
@@ -750,9 +754,9 @@ private static bool DownloadFile(string url, string path, int retries = 3)
750754
751755 return true ;
752756 }
753- catch ( Exception e )
757+ catch ( Exception exception )
754758 {
755- Interface . Oxide . LogException ( $ "Unexpected error occurred while trying to download { fileName } , please manually download it from { url } and save it here { path } ", e ) ;
759+ Interface . Oxide . LogException ( $ "Unexpected error occurred while trying to download { fileName } , please manually download it from { url } and save it here { path } ", exception ) ;
756760 return false ;
757761 }
758762 }
0 commit comments