@@ -125,17 +125,23 @@ private void DependencyTrace()
125125 TraceRan = true ;
126126 }
127127
128- private static void DownloadCompiler ( WebResponse response , string remoteHash )
128+ private static void DownloadCompiler ( string remoteHash )
129129 {
130130 try
131131 {
132132 Interface . Oxide . LogInfo ( $ "Downloading { FileName } for .cs (C#) plugin compilation") ;
133+ HttpWebRequest request = ( HttpWebRequest ) WebRequest . Create ( $ "https://assets.umod.org/compiler/{ FileName } ") ;
134+ HttpWebResponse response = ( HttpWebResponse ) request . GetResponse ( ) ;
135+ int statusCode = ( int ) response . StatusCode ;
136+ if ( statusCode != 200 )
137+ {
138+ Interface . Oxide . LogWarning ( $ "Status code for compiler download was not okay (code { statusCode } )") ;
139+ }
133140
134- Stream stream = response . GetResponseStream ( ) ;
135141 FileStream fs = new FileStream ( FileName , FileMode . Create , FileAccess . Write , FileShare . None ) ;
142+ Stream stream = response . GetResponseStream ( ) ;
136143 int bufferSize = 10000 ;
137144 byte [ ] buffer = new byte [ bufferSize ] ;
138-
139145 while ( true )
140146 {
141147 int result = stream . Read ( buffer , 0 , bufferSize ) ;
@@ -151,26 +157,26 @@ private static void DownloadCompiler(WebResponse response, string remoteHash)
151157 stream . Close ( ) ;
152158 response . Close ( ) ;
153159
154- if ( downloadRetries >= 3 )
160+ if ( downloadRetries >= 2 )
155161 {
156- Interface . Oxide . LogInfo ( $ "Couldn't download { FileName } ! Please download manually from: https://github.com/OxideMod/Oxide.CSharp/releases/download/latest /{ FileName } ") ;
162+ Interface . Oxide . LogInfo ( $ "Couldn not download { FileName } ! Please download manually from: https://assets.umod.org/compiler /{ FileName } ") ;
157163 return ;
158164 }
159165
160166 string localHash = File . Exists ( BinaryPath ) ? GetHash ( BinaryPath , Algorithms . MD5 ) : "0" ;
161167 if ( remoteHash != localHash )
162168 {
163- Interface . Oxide . LogInfo ( $ "Local hash did not match remote hash for { FileName } , attempting download again") ;
164- UpdateCheck ( ) ;
169+ Interface . Oxide . LogInfo ( $ "Local MD5 hash did not match remote MD5 hash for { FileName } , attempting download again") ;
165170 downloadRetries ++ ;
171+ UpdateCheck ( ) ;
166172 return ;
167173 }
168174
169175 Interface . Oxide . LogInfo ( $ "Download of { FileName } completed successfully") ;
170176 }
171177 catch ( Exception ex )
172178 {
173- Interface . Oxide . LogError ( $ "Couldn't download { FileName } ! Please download manually from: https://github.com/OxideMod/Oxide.CSharp/releases/download/latest /{ FileName } ") ;
179+ Interface . Oxide . LogError ( $ "Could not download { FileName } ! Please download manually from: https://assets.umod.org/compiler /{ FileName } ") ;
174180 Interface . Oxide . LogError ( ex . Message ) ;
175181 }
176182 }
@@ -180,27 +186,36 @@ private static void UpdateCheck()
180186 try
181187 {
182188 string filePath = Path . Combine ( Interface . Oxide . RootDirectory , FileName ) ;
183- HttpWebRequest request = ( HttpWebRequest ) WebRequest . Create ( $ "https://umod-01.nyc3.digitaloceanspaces.com/ { FileName } ") ;
189+ HttpWebRequest request = ( HttpWebRequest ) WebRequest . Create ( $ "https://assets. umod.org/compiler/ { FileName } .md5 ") ;
184190 HttpWebResponse response = ( HttpWebResponse ) request . GetResponse ( ) ;
185191 int statusCode = ( int ) response . StatusCode ;
186192 if ( statusCode != 200 )
187193 {
188- Interface . Oxide . LogWarning ( $ "Status code from download location was not okay (code { statusCode } )") ;
194+ Interface . Oxide . LogWarning ( $ "Status code for compiler update check was not okay (code { statusCode } )") ;
195+ }
196+
197+ string remoteHash = "0" ;
198+ string localHash = "0" ;
199+ Stream stream = response . GetResponseStream ( ) ;
200+ using ( StreamReader reader = new StreamReader ( stream ) )
201+ {
202+ remoteHash = reader . ReadToEnd ( ) . Trim ( ) . ToLowerInvariant ( ) ;
203+ localHash = File . Exists ( filePath ) ? GetHash ( filePath , Algorithms . MD5 ) : "0" ;
204+ Interface . Oxide . LogInfo ( $ "Latest compiler MD5: { remoteHash } ") ;
205+ Interface . Oxide . LogInfo ( $ "Local compiler MD5: { localHash } ") ;
189206 }
207+ stream . Close ( ) ;
208+ response . Close ( ) ;
190209
191- string remoteHash = response . Headers [ HttpResponseHeader . ETag ] . Trim ( '"' ) ;
192- string localHash = File . Exists ( filePath ) ? GetHash ( filePath , Algorithms . MD5 ) : "0" ;
193- Interface . Oxide . LogInfo ( $ "Latest compiler MD5: { remoteHash } ") ;
194- Interface . Oxide . LogInfo ( $ "Local compiler MD5: { localHash } ") ;
195210 if ( remoteHash != localHash )
196211 {
197- Interface . Oxide . LogInfo ( "Compiler hashes did not match, downloading latest" ) ;
198- DownloadCompiler ( response , remoteHash ) ;
212+ Interface . Oxide . LogInfo ( "Compiler MD5 hash did not match, downloading latest" ) ;
213+ DownloadCompiler ( remoteHash ) ;
199214 }
200215 }
201216 catch ( Exception ex )
202217 {
203- Interface . Oxide . LogError ( $ "Couldn't check for update to { FileName } ") ;
218+ Interface . Oxide . LogError ( $ "Could not check for update to { FileName } ") ;
204219 Interface . Oxide . LogError ( ex . Message ) ;
205220 }
206221 }
0 commit comments