Skip to content

Commit 01a225b

Browse files
committed
Fix MD5 validation for compiler download
1 parent 73dc5e4 commit 01a225b

1 file changed

Lines changed: 41 additions & 1 deletion

File tree

src/CompilerService.cs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.IO;
1515
using System.Linq;
1616
using System.Net;
17+
using System.Net.Cache;
1718
using System.Security.Cryptography;
1819
using System.Text;
1920
using System.Text.RegularExpressions;
@@ -162,6 +163,28 @@ private bool Start()
162163
return true;
163164
}
164165

166+
try
167+
{
168+
int attempts = 0;
169+
while (!File.Exists(filePath))
170+
{
171+
attempts++;
172+
if (attempts > 3)
173+
{
174+
throw new IOException($"Compiler failed to download after 3 attempts");
175+
}
176+
177+
Log(LogType.Error, $"Compiler doesn't exist at {filePath}, attempting to download again | Attempt: {attempts} of 3");
178+
Precheck();
179+
Thread.Sleep(100);
180+
}
181+
}
182+
catch (Exception e)
183+
{
184+
Log(LogType.Error, e.Message);
185+
return false;
186+
}
187+
165188
Stop(false, "starting new process");
166189
startTime = Interface.Oxide.Now;
167190
string args = compilerBasicArguments + $" --parent {Process.GetCurrentProcess().Id} -l:file \"{Path.Combine(Interface.Oxide.LogDirectory, $"oxide.compiler_{DateTime.Now:yyyy-MM-dd}.log")}\"";
@@ -688,20 +711,37 @@ private static bool TryDownload(string url, int retries, ref int current, DateTi
688711
{
689712
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
690713
request.AllowAutoRedirect = true;
714+
request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
691715

692716
if (!string.IsNullOrEmpty(md5))
693717
{
718+
string md5msg = $"Validating checksum with server for {Path.GetFileName(url)} | Local: {md5}";
694719
int md5retries = 0;
695720
string servermd5 = null;
696721
if (TryDownload(url + ".md5", retries, ref md5retries, null, out byte[] md5data, out int md5code, out bool _, ref servermd5) && md5code == 200)
697722
{
723+
698724
servermd5 = Encoding.UTF8.GetString(md5data).Trim();
699-
md5 = servermd5;
725+
726+
if (string.IsNullOrEmpty(servermd5))
727+
{
728+
servermd5 = "N/A";
729+
}
730+
731+
md5msg += $" | Server: {servermd5}";
732+
700733
if (servermd5.Equals(md5, StringComparison.InvariantCultureIgnoreCase))
701734
{
735+
md5 = servermd5;
702736
newerFound = false;
737+
md5msg += " | Match!";
738+
Log(LogType.Debug, md5msg);
703739
return true;
704740
}
741+
742+
md5 = servermd5;
743+
md5msg += " | No Match!";
744+
Log(LogType.Warning, md5msg);
705745
}
706746
else if (lastModified.HasValue)
707747
{

0 commit comments

Comments
 (0)