|
14 | 14 | using System.IO; |
15 | 15 | using System.Linq; |
16 | 16 | using System.Net; |
| 17 | +using System.Net.Cache; |
17 | 18 | using System.Security.Cryptography; |
18 | 19 | using System.Text; |
19 | 20 | using System.Text.RegularExpressions; |
@@ -162,6 +163,28 @@ private bool Start() |
162 | 163 | return true; |
163 | 164 | } |
164 | 165 |
|
| 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 | + |
165 | 188 | Stop(false, "starting new process"); |
166 | 189 | startTime = Interface.Oxide.Now; |
167 | 190 | 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 |
688 | 711 | { |
689 | 712 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); |
690 | 713 | request.AllowAutoRedirect = true; |
| 714 | + request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); |
691 | 715 |
|
692 | 716 | if (!string.IsNullOrEmpty(md5)) |
693 | 717 | { |
| 718 | + string md5msg = $"Validating checksum with server for {Path.GetFileName(url)} | Local: {md5}"; |
694 | 719 | int md5retries = 0; |
695 | 720 | string servermd5 = null; |
696 | 721 | if (TryDownload(url + ".md5", retries, ref md5retries, null, out byte[] md5data, out int md5code, out bool _, ref servermd5) && md5code == 200) |
697 | 722 | { |
| 723 | + |
698 | 724 | 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 | + |
700 | 733 | if (servermd5.Equals(md5, StringComparison.InvariantCultureIgnoreCase)) |
701 | 734 | { |
| 735 | + md5 = servermd5; |
702 | 736 | newerFound = false; |
| 737 | + md5msg += " | Match!"; |
| 738 | + Log(LogType.Debug, md5msg); |
703 | 739 | return true; |
704 | 740 | } |
| 741 | + |
| 742 | + md5 = servermd5; |
| 743 | + md5msg += " | No Match!"; |
| 744 | + Log(LogType.Warning, md5msg); |
705 | 745 | } |
706 | 746 | else if (lastModified.HasValue) |
707 | 747 | { |
|
0 commit comments