@@ -30,7 +30,6 @@ internal class CompilerService
3030 private volatile int lastId ;
3131 private volatile bool ready ;
3232 private Core . Libraries . Timer . TimerInstance idleTimer ;
33- private Core . Libraries . Timer . TimerInstance expireTimer ;
3433 private ObjectStreamClient < CompilerMessage > client ;
3534 private string filePath ;
3635 private string remoteName ;
@@ -76,19 +75,15 @@ private void ExpireFileCache()
7675 {
7776 object [ ] toRemove = ArrayPool . Get ( CompilerFile . FileCache . Count ) ;
7877 int index = 0 ;
79- DateTime now = DateTime . Now ;
8078 foreach ( var file in CompilerFile . FileCache )
8179 {
8280 if ( file . Value . KeepCached )
8381 {
8482 continue ;
8583 }
8684
87- if ( now - file . Value . LastRead > TimeSpan . FromMinutes ( 3 ) )
88- {
89- toRemove [ index ] = file . Key ;
90- index ++ ;
91- }
85+ toRemove [ index ] = file . Key ;
86+ index ++ ;
9287 }
9388
9489 for ( int i = 0 ; i < index ; i ++ )
@@ -100,16 +95,10 @@ private void ExpireFileCache()
10095
10196 ArrayPool . Free ( toRemove ) ;
10297
103- if ( CompilerFile . FileCache . Count == 0 )
104- {
105- expireTimer ? . Destroy ( ) ;
106- expireTimer = null ;
107- }
98+ if ( index <= 0 ) return ;
10899
109- if ( index > 0 )
110- {
111- GC . Collect ( ) ;
112- }
100+ Interface . Oxide . LogWarning ( $ "[CSharp] Released { index } cached compiler dependencies, running garbage collection. . .") ;
101+ GC . Collect ( ) ;
113102 }
114103 }
115104
@@ -125,7 +114,6 @@ internal bool Precheck()
125114
126115 private bool Start ( )
127116 {
128- expireTimer = Interface . Oxide . GetLibrary < Core . Libraries . Timer > ( ) . Repeat ( 35 , - 1 , ExpireFileCache ) ;
129117 if ( filePath == null )
130118 {
131119 return false ;
@@ -197,7 +185,7 @@ private bool Start()
197185 client . Error += OnError ;
198186 client . Start ( ) ;
199187 ResetIdleTimer ( ) ;
200- Log ( LogType . Info , $ " Started Oxide.Compiler v{ GetCompilerVersion ( ) } successfully") ;
188+ Interface . Oxide . LogInfo ( $ "[CSharp] Started Oxide.Compiler v{ GetCompilerVersion ( ) } successfully") ;
201189 return true ;
202190 }
203191
@@ -269,6 +257,8 @@ internal void Stop(bool synchronous, string reason)
269257 endedProcess . Close ( ) ;
270258 Log ( LogType . Info , "Released compiler resources" ) ;
271259 }
260+
261+ ExpireFileCache ( ) ;
272262 }
273263
274264 private void OnMessage ( ObjectStreamConnection < CompilerMessage , CompilerMessage > connection , CompilerMessage message )
@@ -414,7 +404,7 @@ private void ResetIdleTimer()
414404 idleTimer . Destroy ( ) ;
415405 }
416406
417- idleTimer = Interface . Oxide . GetLibrary < Core . Libraries . Timer > ( ) . Once ( 120f , ( ) => Stop ( false , "idle shutdown" ) ) ;
407+ idleTimer = Interface . Oxide . GetLibrary < Core . Libraries . Timer > ( ) . Once ( 3600f , ( ) => Stop ( false , "idle shutdown" ) ) ;
418408 }
419409
420410 internal void Compile ( CompilablePlugin [ ] plugins , Action < Compilation > callback )
@@ -572,11 +562,18 @@ private static bool DownloadFile(string url, string path, int retries = 3)
572562 {
573563 md5 = GenerateFileHash ( path ) ;
574564 last = File . GetLastWriteTimeUtc ( path ) ;
575- Log ( LogType . Info , $ "{ fileName } already exists, checking for updates. . .") ;
565+ string msg = $ "[CSharp] Checking for updates for { fileName } | Local MD5: { md5 } ";
566+
567+ if ( last . HasValue )
568+ {
569+ msg += $ " | Last modified: { last . Value : yyyy-MM-dd HH:mm:ss} ";
570+ }
571+
572+ Interface . Oxide . LogInfo ( msg ) ;
576573 }
577574 else
578575 {
579- Interface . Oxide . LogInfo ( $ "Downloading { fileName } . . .") ;
576+ Interface . Oxide . LogInfo ( $ "[CSharp] Downloading { fileName } . . .") ;
580577 }
581578
582579 byte [ ] data ;
@@ -585,23 +582,30 @@ private static bool DownloadFile(string url, string path, int retries = 3)
585582 if ( ! TryDownload ( url , retries , ref retry , last , out data , out code , out newerFound , ref md5 ) )
586583 {
587584 string attemptVerb = retries == 1 ? "attempt" : "attempts" ;
588- Interface . Oxide . LogError ( $ "Failed to download { fileName } after { retry } { attemptVerb } with response code '{ code } ', please manually download it from { url } and save it here { path } ") ;
585+ 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 } ") ;
589586 return false ;
590587 }
591588
592- if ( ! newerFound )
593- {
594- Log ( LogType . Info , $ "Latest version of { fileName } already exists") ;
595- }
596-
597589 if ( data != null )
598590 {
599591 using ( FileStream fs = new FileStream ( path , FileMode . Create , FileAccess . Write , FileShare . None ) )
600592 {
601593 fs . Write ( data , 0 , data . Length ) ;
602594 }
603-
604- Interface . Oxide . LogInfo ( $ "Latest version of { fileName } has been downloaded") ;
595+
596+ if ( newerFound )
597+ {
598+ string checkVerb = md5 != null ? $ "Remote MD5: { md5 } " : "Newer found" ;
599+ Interface . Oxide . LogInfo ( $ "[CSharp] Downloaded newer version of { fileName } | { checkVerb } ") ;
600+ }
601+ else
602+ {
603+ Interface . Oxide . LogInfo ( $ "[CSharp] Downloaded { fileName } ") ;
604+ }
605+ }
606+ else
607+ {
608+ Interface . Oxide . LogInfo ( $ "[CSharp] { fileName } is up to date") ;
605609 }
606610
607611 return true ;
@@ -630,16 +634,19 @@ private static bool TryDownload(string url, int retries, ref int current, DateTi
630634 if ( TryDownload ( url + ".md5" , retries , ref md5retries , null , out byte [ ] md5data , out int md5code , out bool _ , ref servermd5 ) && md5code == 200 )
631635 {
632636 servermd5 = Encoding . UTF8 . GetString ( md5data ) . Trim ( ) ;
633-
634- Log ( LogType . Info , $ "Local MD5: { md5 } Server MD5: { servermd5 } ") ;
635-
637+ md5 = servermd5 ;
636638 if ( servermd5 . Equals ( md5 , StringComparison . InvariantCultureIgnoreCase ) )
637639 {
638- Log ( LogType . Info , $ "MD5 of { url } matches local copy") ;
639640 newerFound = false ;
640641 return true ;
641642 }
642643 }
644+ else if ( lastModified . HasValue )
645+ {
646+ md5 = null ;
647+ Log ( LogType . Warning , $ "Failed to download { url } .md5 after { md5retries } attempts with response code '{ md5code } ', using last modified date instead") ;
648+ request . IfModifiedSince = lastModified . Value ;
649+ }
643650 }
644651 else if ( lastModified . HasValue )
645652 {
0 commit comments