2
0

ModNet.cs 106 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Net.NetworkInformation;
  8. using System.Runtime.CompilerServices;
  9. using System.Text;
  10. using System.Threading;
  11. using Microsoft.VisualBasic;
  12. using Microsoft.VisualBasic.CompilerServices;
  13. namespace PCL
  14. {
  15. // Token: 0x0200012F RID: 303
  16. [StandardModule]
  17. public sealed class ModNet
  18. {
  19. // Token: 0x06000CF1 RID: 3313 RVA: 0x00055F84 File Offset: 0x00054184
  20. public static int Ping(string Ip, int Timeout = 10000, bool MakeLog = true)
  21. {
  22. PingReply pingReply;
  23. try
  24. {
  25. pingReply = new Ping().Send(Ip);
  26. }
  27. catch (Exception ex)
  28. {
  29. if (MakeLog)
  30. {
  31. ModBase.Log("[Net] Ping " + Ip + " 失败:" + ex.Message, ModBase.LogLevel.Normal, "出现错误");
  32. }
  33. return -1;
  34. }
  35. int result;
  36. if (pingReply.Status == IPStatus.Success)
  37. {
  38. if (MakeLog)
  39. {
  40. ModBase.Log(string.Concat(new string[]
  41. {
  42. "[Net] Ping ",
  43. Ip,
  44. " 结束:",
  45. Conversions.ToString(pingReply.RoundtripTime),
  46. "ms"
  47. }), ModBase.LogLevel.Normal, "出现错误");
  48. }
  49. result = checked((int)pingReply.RoundtripTime);
  50. }
  51. else
  52. {
  53. if (MakeLog)
  54. {
  55. ModBase.Log("[Net] Ping " + Ip + " 失败", ModBase.LogLevel.Normal, "出现错误");
  56. }
  57. result = -1;
  58. }
  59. return result;
  60. }
  61. // Token: 0x06000CF2 RID: 3314 RVA: 0x0005605C File Offset: 0x0005425C
  62. public static string NetGetCodeByClient(string Url, Encoding Encoding, string Accept = "application/json, text/javascript, */*; q=0.01", bool UseBrowserUserAgent = false)
  63. {
  64. int num = 0;
  65. Exception ex = null;
  66. long timeTick = ModBase.GetTimeTick();
  67. checked
  68. {
  69. string result;
  70. try
  71. {
  72. IL_0A:
  73. if (num != 0)
  74. {
  75. if (num != 1)
  76. {
  77. if (ModBase.GetTimeTick() - timeTick <= 5500L)
  78. {
  79. throw ex;
  80. }
  81. Thread.Sleep(500);
  82. result = ModNet.NetGetCodeByClient(Url, Encoding, 4000, Accept, UseBrowserUserAgent);
  83. }
  84. else
  85. {
  86. Thread.Sleep(500);
  87. result = ModNet.NetGetCodeByClient(Url, Encoding, 30000, Accept, UseBrowserUserAgent);
  88. }
  89. }
  90. else
  91. {
  92. result = ModNet.NetGetCodeByClient(Url, Encoding, 10000, Accept, UseBrowserUserAgent);
  93. }
  94. }
  95. catch (Exception ex2)
  96. {
  97. if (num == 0)
  98. {
  99. ex = ex2;
  100. num++;
  101. goto IL_0A;
  102. }
  103. if (num != 1)
  104. {
  105. throw;
  106. }
  107. num++;
  108. goto IL_0A;
  109. }
  110. return result;
  111. }
  112. }
  113. // Token: 0x06000CF3 RID: 3315 RVA: 0x00056114 File Offset: 0x00054314
  114. public static string NetGetCodeByClient(string Url, Encoding Encoding, int Timeout, string Accept, bool UseBrowserUserAgent = false)
  115. {
  116. Url = Conversions.ToString(ModSecret.SecretCdnSign(Url));
  117. ModBase.Log("[Net] 获取客户端网络结果:" + Url + ",最大超时 " + Conversions.ToString(Timeout), ModBase.LogLevel.Normal, "出现错误");
  118. HttpWebResponse httpWebResponse = null;
  119. Stream stream = null;
  120. string result;
  121. try
  122. {
  123. CookieWebClient cookieWebClient = new CookieWebClient
  124. {
  125. Encoding = Encoding,
  126. resolverField = Timeout
  127. };
  128. cookieWebClient.Headers["Accept"] = Accept;
  129. cookieWebClient.Headers["Accept-Language"] = "en-US,en;q=0.5";
  130. cookieWebClient.Headers["X-Requested-With"] = "XMLHttpRequest";
  131. string url = Url;
  132. WebClient webClient = cookieWebClient;
  133. ModSecret.SecretHeadersSign(url, ref webClient, UseBrowserUserAgent);
  134. cookieWebClient = (CookieWebClient)webClient;
  135. result = cookieWebClient.DownloadString(Url);
  136. }
  137. catch (Exception ex)
  138. {
  139. if (ex.GetType().Equals(typeof(WebException)) && ((WebException)ex).Status == 14)
  140. {
  141. throw new TimeoutException("连接服务器超时(" + Url + ")", ex);
  142. }
  143. throw new WebException(string.Concat(new string[]
  144. {
  145. "获取结果失败,",
  146. ex.Message,
  147. "(",
  148. Url,
  149. ")"
  150. }), ex);
  151. }
  152. finally
  153. {
  154. if (!Information.IsNothing(stream))
  155. {
  156. stream.Dispose();
  157. }
  158. if (!Information.IsNothing(httpWebResponse))
  159. {
  160. httpWebResponse.Dispose();
  161. }
  162. }
  163. return result;
  164. }
  165. // Token: 0x06000CF4 RID: 3316 RVA: 0x00056280 File Offset: 0x00054480
  166. public static object NetGetCodeByRequestRetry(string Url, Encoding Encode = null, string Accept = "", bool IsJson = false, string BackupUrl = null, bool UseBrowserUserAgent = false)
  167. {
  168. int num = 0;
  169. Exception ex = null;
  170. long timeTick = ModBase.GetTimeTick();
  171. checked
  172. {
  173. object result;
  174. try
  175. {
  176. IL_0A:
  177. if (num != 0)
  178. {
  179. if (num != 1)
  180. {
  181. if (ModBase.GetTimeTick() - timeTick <= 5500L)
  182. {
  183. throw ex;
  184. }
  185. Thread.Sleep(500);
  186. result = ModNet.NetGetCodeByRequestOnce(BackupUrl ?? Url, Encode, 4000, IsJson, Accept, UseBrowserUserAgent);
  187. }
  188. else
  189. {
  190. Thread.Sleep(500);
  191. result = ModNet.NetGetCodeByRequestOnce(BackupUrl ?? Url, Encode, 30000, IsJson, Accept, UseBrowserUserAgent);
  192. }
  193. }
  194. else
  195. {
  196. result = ModNet.NetGetCodeByRequestOnce(Url, Encode, 10000, IsJson, Accept, UseBrowserUserAgent);
  197. }
  198. }
  199. catch (ThreadInterruptedException ex2)
  200. {
  201. throw;
  202. }
  203. catch (Exception ex3)
  204. {
  205. if (num == 0)
  206. {
  207. ex = ex3;
  208. num++;
  209. goto IL_0A;
  210. }
  211. if (num != 1)
  212. {
  213. throw;
  214. }
  215. num++;
  216. goto IL_0A;
  217. }
  218. return result;
  219. }
  220. }
  221. // Token: 0x06000CF5 RID: 3317 RVA: 0x00056364 File Offset: 0x00054564
  222. public static object NetGetCodeByRequestMultiple(string Url, Encoding Encode = null, string Accept = "", bool IsJson = false)
  223. {
  224. ModNet._Closure$__6-0 CS$<>8__locals1 = new ModNet._Closure$__6-0(CS$<>8__locals1);
  225. CS$<>8__locals1.$VB$Local_Url = Url;
  226. CS$<>8__locals1.$VB$Local_Encode = Encode;
  227. CS$<>8__locals1.$VB$Local_Accept = Accept;
  228. CS$<>8__locals1.$VB$Local_IsJson = IsJson;
  229. List<Thread> list = new List<Thread>();
  230. CS$<>8__locals1.$VB$Local_RequestResult = null;
  231. CS$<>8__locals1.$VB$Local_RequestEx = null;
  232. CS$<>8__locals1.$VB$Local_FailCount = 0;
  233. int num = 1;
  234. checked
  235. {
  236. do
  237. {
  238. Thread thread = new Thread((CS$<>8__locals1.$I0 == null) ? (CS$<>8__locals1.$I0 = delegate()
  239. {
  240. try
  241. {
  242. CS$<>8__locals1.$VB$Local_RequestResult = RuntimeHelpers.GetObjectValue(ModNet.NetGetCodeByRequestOnce(CS$<>8__locals1.$VB$Local_Url, CS$<>8__locals1.$VB$Local_Encode, 30000, CS$<>8__locals1.$VB$Local_IsJson, CS$<>8__locals1.$VB$Local_Accept, false));
  243. }
  244. catch (Exception $VB$Local_RequestEx)
  245. {
  246. CS$<>8__locals1.$VB$Local_FailCount++;
  247. CS$<>8__locals1.$VB$Local_RequestEx = $VB$Local_RequestEx;
  248. }
  249. }) : CS$<>8__locals1.$I0);
  250. thread.Start();
  251. list.Add(thread);
  252. Thread.Sleep(num * 250);
  253. if (CS$<>8__locals1.$VB$Local_RequestResult != null)
  254. {
  255. goto IL_114;
  256. }
  257. num++;
  258. }
  259. while (num <= 4);
  260. while (CS$<>8__locals1.$VB$Local_RequestResult == null)
  261. {
  262. if (CS$<>8__locals1.$VB$Local_FailCount == 4)
  263. {
  264. try
  265. {
  266. try
  267. {
  268. foreach (Thread thread2 in list)
  269. {
  270. if (thread2.IsAlive)
  271. {
  272. thread2.Interrupt();
  273. }
  274. }
  275. }
  276. finally
  277. {
  278. List<Thread>.Enumerator enumerator;
  279. ((IDisposable)enumerator).Dispose();
  280. }
  281. }
  282. catch (Exception ex)
  283. {
  284. }
  285. throw CS$<>8__locals1.$VB$Local_RequestEx;
  286. }
  287. Thread.Sleep(20);
  288. }
  289. IL_114:
  290. try
  291. {
  292. try
  293. {
  294. foreach (Thread thread3 in list)
  295. {
  296. if (thread3.IsAlive)
  297. {
  298. thread3.Interrupt();
  299. }
  300. }
  301. }
  302. finally
  303. {
  304. List<Thread>.Enumerator enumerator2;
  305. ((IDisposable)enumerator2).Dispose();
  306. }
  307. }
  308. catch (Exception ex2)
  309. {
  310. }
  311. return CS$<>8__locals1.$VB$Local_RequestResult;
  312. }
  313. }
  314. // Token: 0x06000CF6 RID: 3318 RVA: 0x0005650C File Offset: 0x0005470C
  315. public static object NetGetCodeByRequestOnce(string Url, Encoding Encode = null, int Timeout = 30000, bool IsJson = false, string Accept = "", bool UseBrowserUserAgent = false)
  316. {
  317. if (ModBase.RunInUi() && !Url.Contains("//127."))
  318. {
  319. throw new Exception("在 UI 线程执行了网络请求");
  320. }
  321. Url = Conversions.ToString(ModSecret.SecretCdnSign(Url));
  322. ModBase.Log(string.Format("[Net] 获取网络结果:{0},超时 {1}ms{2}", Url, Timeout, IsJson ? ",要求 json" : ""), ModBase.LogLevel.Normal, "出现错误");
  323. HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Url);
  324. new List<byte>();
  325. object result;
  326. try
  327. {
  328. if (Url.StartsWithF("https", true))
  329. {
  330. httpWebRequest.ProtocolVersion = HttpVersion.Version11;
  331. }
  332. httpWebRequest.Timeout = Timeout;
  333. httpWebRequest.Accept = Accept;
  334. ModSecret.SecretHeadersSign(Url, ref httpWebRequest, UseBrowserUserAgent);
  335. using (HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse())
  336. {
  337. using (Stream responseStream = httpWebResponse.GetResponseStream())
  338. {
  339. responseStream.ReadTimeout = Timeout;
  340. using (StreamReader streamReader = new StreamReader(responseStream, Encode ?? Encoding.UTF8))
  341. {
  342. string text = streamReader.ReadToEnd();
  343. result = (IsJson ? ModBase.GetJson(text) : text);
  344. }
  345. }
  346. }
  347. }
  348. catch (ThreadInterruptedException ex)
  349. {
  350. throw;
  351. }
  352. catch (Exception ex2)
  353. {
  354. if (ex2 is WebException && ((WebException)ex2).Status == 14)
  355. {
  356. throw new TimeoutException(string.Format("获取结果失败({0},{1},{2})", ((WebException)ex2).Status, ex2.Message, Url), ex2);
  357. }
  358. throw new WebException(string.Format("获取结果失败({0}{1},{2})", (ex2 is WebException) ? (Conversions.ToString(((WebException)ex2).Status) + ",") : "", ex2.Message, Url), ex2);
  359. }
  360. finally
  361. {
  362. httpWebRequest.Abort();
  363. }
  364. return result;
  365. }
  366. // Token: 0x06000CF7 RID: 3319 RVA: 0x00056754 File Offset: 0x00054954
  367. public static string NetGetCodeByDownload(string Url, int Timeout = 45000, bool IsJson = false, bool UseBrowserUserAgent = false)
  368. {
  369. string text = string.Concat(new string[]
  370. {
  371. ModBase.m_DecoratorRepository,
  372. "Cache\\Code\\",
  373. Conversions.ToString(Url.GetHashCode()),
  374. "_",
  375. Conversions.ToString(ModBase.GetUuid())
  376. });
  377. ModNet.LoaderDownload loaderDownload = new ModNet.LoaderDownload("源码获取 " + Conversions.ToString(ModBase.GetUuid()) + "#", new List<ModNet.NetFile>
  378. {
  379. new ModNet.NetFile(new string[]
  380. {
  381. Url
  382. }, text, new ModBase.FileChecker(-1L, -1L, null, true, false)
  383. {
  384. m_RequestError = IsJson
  385. }, UseBrowserUserAgent)
  386. });
  387. string result;
  388. try
  389. {
  390. loaderDownload.WaitForExitTime(Timeout, null, "连接服务器超时(" + Url + ")", null, false);
  391. result = ModBase.ReadFile(text, null);
  392. File.Delete(text);
  393. }
  394. finally
  395. {
  396. loaderDownload.Abort();
  397. }
  398. return result;
  399. }
  400. // Token: 0x06000CF8 RID: 3320 RVA: 0x00056840 File Offset: 0x00054A40
  401. public static string NetGetCodeByDownload(IEnumerable<string> Urls, int Timeout = 45000, bool IsJson = false, bool UseBrowserUserAgent = false)
  402. {
  403. string text = string.Concat(new string[]
  404. {
  405. ModBase.m_DecoratorRepository,
  406. "Cache\\Code\\",
  407. Conversions.ToString(Enumerable.First<string>(Urls).GetHashCode()),
  408. "_",
  409. Conversions.ToString(ModBase.GetUuid())
  410. });
  411. ModNet.LoaderDownload loaderDownload = new ModNet.LoaderDownload("源码获取 " + Conversions.ToString(ModBase.GetUuid()) + "#", new List<ModNet.NetFile>
  412. {
  413. new ModNet.NetFile(Urls, text, new ModBase.FileChecker(-1L, -1L, null, true, false)
  414. {
  415. m_RequestError = IsJson
  416. }, UseBrowserUserAgent)
  417. });
  418. string result;
  419. try
  420. {
  421. loaderDownload.WaitForExitTime(Timeout, null, "连接服务器超时(第一下载源:" + Enumerable.First<string>(Urls) + ")", null, false);
  422. result = ModBase.ReadFile(text, null);
  423. File.Delete(text);
  424. }
  425. finally
  426. {
  427. loaderDownload.Abort();
  428. }
  429. return result;
  430. }
  431. // Token: 0x06000CF9 RID: 3321 RVA: 0x0005692C File Offset: 0x00054B2C
  432. public static void NetDownload(string Url, string LocalFile, bool UseBrowserUserAgent = false)
  433. {
  434. ModBase.Log("[Net] 直接下载文件:" + Url, ModBase.LogLevel.Normal, "出现错误");
  435. try
  436. {
  437. Directory.CreateDirectory(ModBase.GetPathFromFullPath(LocalFile));
  438. File.Delete(LocalFile);
  439. }
  440. catch (Exception ex)
  441. {
  442. throw new WebException("预处理下载文件路径失败(" + LocalFile + ")。", ex);
  443. }
  444. using (WebClient webClient = new WebClient())
  445. {
  446. try
  447. {
  448. WebClient webClient2 = webClient;
  449. ModSecret.SecretHeadersSign(Url, ref webClient2, UseBrowserUserAgent);
  450. webClient.DownloadFile(Url, LocalFile);
  451. }
  452. catch (Exception ex2)
  453. {
  454. File.Delete(LocalFile);
  455. throw new WebException("直接下载文件失败(" + Url + ")。", ex2);
  456. }
  457. }
  458. }
  459. // Token: 0x06000CFA RID: 3322 RVA: 0x000569F4 File Offset: 0x00054BF4
  460. public static string NetRequestRetry(string Url, string Method, object Data, string ContentType, bool DontRetryOnRefused = true, Dictionary<string, string> Headers = null)
  461. {
  462. int num = 0;
  463. Exception ex = null;
  464. long timeTick = ModBase.GetTimeTick();
  465. checked
  466. {
  467. string result;
  468. try
  469. {
  470. IL_0A:
  471. if (num != 0)
  472. {
  473. if (num != 1)
  474. {
  475. if (ModBase.GetTimeTick() - timeTick <= 5500L)
  476. {
  477. throw ex;
  478. }
  479. Thread.Sleep(500);
  480. result = ModNet.NetRequestOnce(Url, Method, RuntimeHelpers.GetObjectValue(Data), ContentType, 4000, Headers, true, false);
  481. }
  482. else
  483. {
  484. Thread.Sleep(500);
  485. result = ModNet.NetRequestOnce(Url, Method, RuntimeHelpers.GetObjectValue(Data), ContentType, 25000, Headers, true, false);
  486. }
  487. }
  488. else
  489. {
  490. result = ModNet.NetRequestOnce(Url, Method, RuntimeHelpers.GetObjectValue(Data), ContentType, 15000, Headers, true, false);
  491. }
  492. }
  493. catch (ThreadInterruptedException ex2)
  494. {
  495. throw;
  496. }
  497. catch (Exception ex3)
  498. {
  499. if (ex3.InnerException != null && ex3.InnerException.Message.Contains("(40") && DontRetryOnRefused)
  500. {
  501. throw;
  502. }
  503. if (num == 0)
  504. {
  505. if (ModBase._TokenRepository)
  506. {
  507. ModBase.Log(ex3, "[Net] 网络请求第一次失败(" + Url + ")", ModBase.LogLevel.Debug, "出现错误");
  508. }
  509. ex = ex3;
  510. num++;
  511. goto IL_0A;
  512. }
  513. if (num != 1)
  514. {
  515. throw;
  516. }
  517. if (ModBase._TokenRepository)
  518. {
  519. ModBase.Log(ex3, "[Net] 网络请求第二次失败(" + Url + ")", ModBase.LogLevel.Debug, "出现错误");
  520. }
  521. num++;
  522. goto IL_0A;
  523. }
  524. return result;
  525. }
  526. }
  527. // Token: 0x06000CFB RID: 3323 RVA: 0x00056B58 File Offset: 0x00054D58
  528. public static object NetRequestMultiple(string Url, string Method, object Data, string ContentType, int RequestCount = 4, Dictionary<string, string> Headers = null, bool MakeLog = true)
  529. {
  530. ModNet._Closure$__12-0 CS$<>8__locals1 = new ModNet._Closure$__12-0(CS$<>8__locals1);
  531. CS$<>8__locals1.$VB$Local_Url = Url;
  532. CS$<>8__locals1.$VB$Local_Method = Method;
  533. CS$<>8__locals1.$VB$Local_Data = Data;
  534. CS$<>8__locals1.$VB$Local_ContentType = ContentType;
  535. CS$<>8__locals1.$VB$Local_Headers = Headers;
  536. CS$<>8__locals1.$VB$Local_MakeLog = MakeLog;
  537. List<Thread> list = new List<Thread>();
  538. CS$<>8__locals1.$VB$Local_RequestResult = null;
  539. CS$<>8__locals1.$VB$Local_RequestEx = null;
  540. CS$<>8__locals1.$VB$Local_FailCount = 0;
  541. checked
  542. {
  543. for (int i = 1; i <= RequestCount; i++)
  544. {
  545. Thread thread = new Thread((CS$<>8__locals1.$I0 == null) ? (CS$<>8__locals1.$I0 = delegate()
  546. {
  547. try
  548. {
  549. CS$<>8__locals1.$VB$Local_RequestResult = ModNet.NetRequestOnce(CS$<>8__locals1.$VB$Local_Url, CS$<>8__locals1.$VB$Local_Method, RuntimeHelpers.GetObjectValue(CS$<>8__locals1.$VB$Local_Data), CS$<>8__locals1.$VB$Local_ContentType, 30000, CS$<>8__locals1.$VB$Local_Headers, CS$<>8__locals1.$VB$Local_MakeLog, false);
  550. }
  551. catch (Exception $VB$Local_RequestEx)
  552. {
  553. CS$<>8__locals1.$VB$Local_FailCount++;
  554. CS$<>8__locals1.$VB$Local_RequestEx = $VB$Local_RequestEx;
  555. }
  556. }) : CS$<>8__locals1.$I0);
  557. thread.Start();
  558. list.Add(thread);
  559. Thread.Sleep(i * 250);
  560. if (CS$<>8__locals1.$VB$Local_RequestResult != null)
  561. {
  562. IL_119:
  563. try
  564. {
  565. foreach (Thread thread2 in list)
  566. {
  567. if (thread2.IsAlive)
  568. {
  569. thread2.Interrupt();
  570. }
  571. }
  572. }
  573. finally
  574. {
  575. List<Thread>.Enumerator enumerator;
  576. ((IDisposable)enumerator).Dispose();
  577. }
  578. return CS$<>8__locals1.$VB$Local_RequestResult;
  579. }
  580. }
  581. while (CS$<>8__locals1.$VB$Local_RequestResult == null)
  582. {
  583. if (CS$<>8__locals1.$VB$Local_FailCount == RequestCount)
  584. {
  585. try
  586. {
  587. foreach (Thread thread3 in list)
  588. {
  589. if (thread3.IsAlive)
  590. {
  591. thread3.Interrupt();
  592. }
  593. }
  594. }
  595. finally
  596. {
  597. List<Thread>.Enumerator enumerator2;
  598. ((IDisposable)enumerator2).Dispose();
  599. }
  600. throw CS$<>8__locals1.$VB$Local_RequestEx;
  601. }
  602. Thread.Sleep(20);
  603. }
  604. goto IL_119;
  605. }
  606. }
  607. // Token: 0x06000CFC RID: 3324 RVA: 0x00056CE0 File Offset: 0x00054EE0
  608. public static string NetRequestOnce(string Url, string Method, byte[] Data, string ContentType, int Timeout = 25000, Dictionary<string, string> Headers = null, bool MakeLog = true, bool UseBrowserUserAgent = false)
  609. {
  610. if (ModBase.RunInUi() && !Url.Contains("//127."))
  611. {
  612. throw new Exception("在 UI 线程执行了网络请求");
  613. }
  614. Url = Conversions.ToString(ModSecret.SecretCdnSign(Url));
  615. if (MakeLog)
  616. {
  617. ModBase.Log(string.Concat(new string[]
  618. {
  619. "[Net] 发起网络请求(",
  620. Method,
  621. ",",
  622. Url,
  623. "),最大超时 ",
  624. Conversions.ToString(Timeout)
  625. }), ModBase.LogLevel.Normal, "出现错误");
  626. }
  627. Stream stream = null;
  628. WebResponse webResponse = null;
  629. string result;
  630. try
  631. {
  632. HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Url);
  633. httpWebRequest.Method = Method;
  634. byte[] array;
  635. if (Data is byte[])
  636. {
  637. array = (byte[])Data;
  638. }
  639. else
  640. {
  641. array = new UTF8Encoding(false).GetBytes(Data.ToString());
  642. }
  643. if (Headers != null)
  644. {
  645. try
  646. {
  647. foreach (KeyValuePair<string, string> keyValuePair in Headers)
  648. {
  649. httpWebRequest.Headers.Add(keyValuePair.Key, keyValuePair.Value);
  650. }
  651. }
  652. finally
  653. {
  654. Dictionary<string, string>.Enumerator enumerator;
  655. ((IDisposable)enumerator).Dispose();
  656. }
  657. }
  658. httpWebRequest.ContentType = ContentType;
  659. httpWebRequest.Timeout = Timeout;
  660. ModSecret.SecretHeadersSign(Url, ref httpWebRequest, UseBrowserUserAgent);
  661. if (Url.StartsWithF("https", true))
  662. {
  663. httpWebRequest.ProtocolVersion = HttpVersion.Version11;
  664. }
  665. if (Operators.CompareString(Method, "POST", false) == 0 || Operators.CompareString(Method, "PUT", false) == 0)
  666. {
  667. httpWebRequest.ContentLength = (long)array.Length;
  668. stream = httpWebRequest.GetRequestStream();
  669. stream.WriteTimeout = Timeout;
  670. stream.ReadTimeout = Timeout;
  671. stream.Write(array, 0, array.Length);
  672. stream.Close();
  673. }
  674. webResponse = httpWebRequest.GetResponse();
  675. stream = webResponse.GetResponseStream();
  676. stream.WriteTimeout = Timeout;
  677. stream.ReadTimeout = Timeout;
  678. using (StreamReader streamReader = new StreamReader(stream))
  679. {
  680. result = streamReader.ReadToEnd();
  681. }
  682. }
  683. catch (ThreadInterruptedException ex)
  684. {
  685. throw;
  686. }
  687. catch (WebException ex2)
  688. {
  689. if (ex2.Status == 14)
  690. {
  691. ex2 = new WebException(string.Format("连接服务器超时,请检查你的网络环境是否良好({0},{1})", ex2.Message, Url), ex2);
  692. }
  693. else
  694. {
  695. string text = "";
  696. try
  697. {
  698. if (ex2.Response == null)
  699. {
  700. ProjectData.ClearProjectError();
  701. }
  702. else
  703. {
  704. stream = ex2.Response.GetResponseStream();
  705. stream.WriteTimeout = Timeout;
  706. stream.ReadTimeout = Timeout;
  707. using (StreamReader streamReader2 = new StreamReader(stream))
  708. {
  709. text = streamReader2.ReadToEnd();
  710. }
  711. }
  712. }
  713. catch (Exception ex3)
  714. {
  715. }
  716. if (Operators.CompareString(text, "", false) == 0)
  717. {
  718. ex2 = new WebException(string.Format("网络请求失败({0},{1},{2})", ex2.Status, ex2.Message, Url), ex2);
  719. }
  720. else
  721. {
  722. ex2 = new ModNet.ResponsedWebException(string.Format("服务器返回错误({0},{1},{2}){3}{4}", new object[]
  723. {
  724. ex2.Status,
  725. ex2.Message,
  726. Url,
  727. "\r\n",
  728. text
  729. }), text, ex2);
  730. }
  731. }
  732. if (MakeLog)
  733. {
  734. ModBase.Log(ex2, "NetRequestOnce 失败", ModBase.LogLevel.Developer, "出现错误");
  735. }
  736. throw ex2;
  737. }
  738. catch (Exception ex4)
  739. {
  740. ex4 = new WebException("网络请求失败(" + Url + ")", ex4);
  741. if (MakeLog)
  742. {
  743. ModBase.Log(ex4, "NetRequestOnce 失败", ModBase.LogLevel.Developer, "出现错误");
  744. }
  745. throw ex4;
  746. }
  747. finally
  748. {
  749. if (stream != null)
  750. {
  751. stream.Dispose();
  752. }
  753. if (webResponse != null)
  754. {
  755. webResponse.Dispose();
  756. }
  757. }
  758. return result;
  759. }
  760. // Token: 0x06000CFD RID: 3325 RVA: 0x000570EC File Offset: 0x000552EC
  761. public static bool HasDownloadingTask(bool IgnoreCustomDownload = false)
  762. {
  763. try
  764. {
  765. foreach (ModLoader.LoaderBase loaderBase in Enumerable.ToList<ModLoader.LoaderBase>(ModLoader.LoaderTaskbar))
  766. {
  767. if (loaderBase.Show && loaderBase.State == ModBase.LoadState.Loading && (!IgnoreCustomDownload || !loaderBase.Name.ToString().Contains("自定义下载")))
  768. {
  769. return true;
  770. }
  771. }
  772. }
  773. finally
  774. {
  775. List<ModLoader.LoaderBase>.Enumerator enumerator;
  776. ((IDisposable)enumerator).Dispose();
  777. }
  778. return false;
  779. }
  780. // Token: 0x0400068A RID: 1674
  781. public static int m_StateTests;
  782. // Token: 0x0400068B RID: 1675
  783. public static long callbackTests = 262144L;
  784. // Token: 0x0400068C RID: 1676
  785. public static long m_TemplateTests = -1L;
  786. // Token: 0x0400068D RID: 1677
  787. public static long m_MethodTests = -1L;
  788. // Token: 0x0400068E RID: 1678
  789. private static readonly object taskTests = RuntimeHelpers.GetObjectValue(new object());
  790. // Token: 0x0400068F RID: 1679
  791. private static long m_ConsumerTests;
  792. // Token: 0x04000690 RID: 1680
  793. public static int _ConfigurationTests = 0;
  794. // Token: 0x04000691 RID: 1681
  795. private static readonly object _GetterTests = RuntimeHelpers.GetObjectValue(new object());
  796. // Token: 0x04000692 RID: 1682
  797. public static ModNet.NetManagerClass tokenTests = new ModNet.NetManagerClass();
  798. // Token: 0x02000130 RID: 304
  799. public class ResponsedWebException : WebException
  800. {
  801. // Token: 0x06000CFE RID: 3326 RVA: 0x000086F0 File Offset: 0x000068F0
  802. [CompilerGenerated]
  803. public string GetMapper()
  804. {
  805. return this._StatusTest;
  806. }
  807. // Token: 0x06000CFF RID: 3327 RVA: 0x000086F8 File Offset: 0x000068F8
  808. [CompilerGenerated]
  809. public void FindMapper(string AutoPropertyValue)
  810. {
  811. this._StatusTest = AutoPropertyValue;
  812. }
  813. // Token: 0x06000D00 RID: 3328 RVA: 0x00008701 File Offset: 0x00006901
  814. public ResponsedWebException(string Message, string Response, Exception InnerException) : base(Message, InnerException)
  815. {
  816. this.FindMapper(Response);
  817. }
  818. // Token: 0x04000693 RID: 1683
  819. [CompilerGenerated]
  820. private string _StatusTest;
  821. }
  822. // Token: 0x02000131 RID: 305
  823. public class NetSource
  824. {
  825. // Token: 0x06000D03 RID: 3331 RVA: 0x00008713 File Offset: 0x00006913
  826. public override string ToString()
  827. {
  828. return this.m_StructTest;
  829. }
  830. // Token: 0x04000694 RID: 1684
  831. public int roleTest;
  832. // Token: 0x04000695 RID: 1685
  833. public string m_StructTest;
  834. // Token: 0x04000696 RID: 1686
  835. public int _PrinterTest;
  836. // Token: 0x04000697 RID: 1687
  837. public Exception _ValTest;
  838. // Token: 0x04000698 RID: 1688
  839. public ModNet.NetThread m_AttrTest;
  840. // Token: 0x04000699 RID: 1689
  841. public bool candidateTest;
  842. }
  843. // Token: 0x02000132 RID: 306
  844. public enum NetState
  845. {
  846. // Token: 0x0400069B RID: 1691
  847. WaitForCheck = -1,
  848. // Token: 0x0400069C RID: 1692
  849. WaitForDownload,
  850. // Token: 0x0400069D RID: 1693
  851. Connect,
  852. // Token: 0x0400069E RID: 1694
  853. Get,
  854. // Token: 0x0400069F RID: 1695
  855. Download,
  856. // Token: 0x040006A0 RID: 1696
  857. Merge,
  858. // Token: 0x040006A1 RID: 1697
  859. WaitForCopy,
  860. // Token: 0x040006A2 RID: 1698
  861. Finish,
  862. // Token: 0x040006A3 RID: 1699
  863. Error
  864. }
  865. // Token: 0x02000133 RID: 307
  866. public enum NetPreDownloadBehaviour
  867. {
  868. // Token: 0x040006A5 RID: 1701
  869. HintWhileExists,
  870. // Token: 0x040006A6 RID: 1702
  871. ExitWhileExistsOrDownloading,
  872. // Token: 0x040006A7 RID: 1703
  873. IgnoreCheck
  874. }
  875. // Token: 0x02000134 RID: 308
  876. public class NetThread : IEnumerable<ModNet.NetThread>
  877. {
  878. // Token: 0x06000D05 RID: 3333 RVA: 0x00057170 File Offset: 0x00055370
  879. public NetThread()
  880. {
  881. this.wrapperTest = 0L;
  882. this.m_BaseTest = ModBase.GetTimeTick();
  883. this.attributeTest = 0L;
  884. this._CodeTest = 0L;
  885. this._PrototypeTest = ModBase.GetTimeTick();
  886. this._AnnotationTest = -1L;
  887. this.infoTest = ModNet.NetState.WaitForDownload;
  888. }
  889. // Token: 0x06000D06 RID: 3334 RVA: 0x0000871B File Offset: 0x0000691B
  890. private IEnumerable<ModNet.NetThread> RestartMapper()
  891. {
  892. ModNet.NetThread.VB$StateMachine_5_get_Next vb$StateMachine_5_get_Next = new ModNet.NetThread.VB$StateMachine_5_get_Next(-2);
  893. vb$StateMachine_5_get_Next.$VB$Me = this;
  894. return vb$StateMachine_5_get_Next;
  895. }
  896. // Token: 0x06000D07 RID: 3335 RVA: 0x0000872B File Offset: 0x0000692B
  897. public IEnumerator<ModNet.NetThread> GetEnumerator()
  898. {
  899. return this.RestartMapper().GetEnumerator();
  900. }
  901. // Token: 0x06000D08 RID: 3336 RVA: 0x0000872B File Offset: 0x0000692B
  902. IEnumerator IEnumerable.IEnumerable_GetEnumerator()
  903. {
  904. return this.RestartMapper().GetEnumerator();
  905. }
  906. // Token: 0x06000D09 RID: 3337 RVA: 0x00008738 File Offset: 0x00006938
  907. public bool InitMapper()
  908. {
  909. return this._ModelTest == 0L && this._AdvisorTest.filterTest == -2L;
  910. }
  911. // Token: 0x06000D0A RID: 3338 RVA: 0x000571E0 File Offset: 0x000553E0
  912. public long AddMapper()
  913. {
  914. object proxyTest = this._AdvisorTest._ProxyTest;
  915. ObjectFlowControl.CheckForSyncLockOnValueType(proxyTest);
  916. checked
  917. {
  918. long result;
  919. lock (proxyTest)
  920. {
  921. if (this.m_QueueTest == null)
  922. {
  923. if (this._AdvisorTest.databaseTest)
  924. {
  925. result = 5368709120L;
  926. }
  927. else
  928. {
  929. result = this._AdvisorTest.filterTest - 1L;
  930. }
  931. }
  932. else
  933. {
  934. result = this.m_QueueTest._ModelTest - 1L;
  935. }
  936. }
  937. return result;
  938. }
  939. }
  940. // Token: 0x06000D0B RID: 3339 RVA: 0x0000875A File Offset: 0x0000695A
  941. public long PublishMapper()
  942. {
  943. return checked(this.AddMapper() - (this._ModelTest + this.wrapperTest) + 1L);
  944. }
  945. // Token: 0x06000D0C RID: 3340 RVA: 0x00057278 File Offset: 0x00055478
  946. public long PatchMapper()
  947. {
  948. checked
  949. {
  950. if (ModBase.GetTimeTick() - this.m_BaseTest > 200L)
  951. {
  952. long num = ModBase.GetTimeTick() - this.m_BaseTest;
  953. this._CodeTest = (long)Math.Round((double)(this.wrapperTest - this.attributeTest) / ((double)num / 1000.0));
  954. this.attributeTest = this.wrapperTest;
  955. ref long ptr = ref this.m_BaseTest;
  956. this.m_BaseTest = ptr + num;
  957. }
  958. return this._CodeTest;
  959. }
  960. }
  961. // Token: 0x06000D0D RID: 3341 RVA: 0x0000877A File Offset: 0x0000697A
  962. public bool ConnectMapper()
  963. {
  964. return this.infoTest == ModNet.NetState.Finish || this.infoTest == ModNet.NetState.Error;
  965. }
  966. // Token: 0x040006A8 RID: 1704
  967. public ModNet.NetFile _AdvisorTest;
  968. // Token: 0x040006A9 RID: 1705
  969. public Thread m_AccountTest;
  970. // Token: 0x040006AA RID: 1706
  971. public ModNet.NetThread m_QueueTest;
  972. // Token: 0x040006AB RID: 1707
  973. public int m_EventTest;
  974. // Token: 0x040006AC RID: 1708
  975. public string _ManagerTest;
  976. // Token: 0x040006AD RID: 1709
  977. public long _ModelTest;
  978. // Token: 0x040006AE RID: 1710
  979. public long wrapperTest;
  980. // Token: 0x040006AF RID: 1711
  981. private long m_BaseTest;
  982. // Token: 0x040006B0 RID: 1712
  983. private long attributeTest;
  984. // Token: 0x040006B1 RID: 1713
  985. private long _CodeTest;
  986. // Token: 0x040006B2 RID: 1714
  987. public long _PrototypeTest;
  988. // Token: 0x040006B3 RID: 1715
  989. public long _AnnotationTest;
  990. // Token: 0x040006B4 RID: 1716
  991. public ModNet.NetState infoTest;
  992. // Token: 0x040006B5 RID: 1717
  993. public ModNet.NetSource Source;
  994. }
  995. // Token: 0x02000136 RID: 310
  996. public class NetFile
  997. {
  998. // Token: 0x06000D18 RID: 3352 RVA: 0x000573A4 File Offset: 0x000555A4
  999. private ModNet.NetSource GetSource(int Id = 0)
  1000. {
  1001. if (Id >= Enumerable.Count<ModNet.NetSource>(this.facadeTest) || Id < 0)
  1002. {
  1003. Id = 0;
  1004. }
  1005. object messageTest = this._MessageTest;
  1006. ObjectFlowControl.CheckForSyncLockOnValueType(messageTest);
  1007. checked
  1008. {
  1009. ModNet.NetSource result;
  1010. lock (messageTest)
  1011. {
  1012. if (!this.IsSourceFailed(false))
  1013. {
  1014. ModNet.NetSource netSource = this.facadeTest[Id];
  1015. while (netSource.candidateTest)
  1016. {
  1017. Id++;
  1018. if (Id >= Enumerable.Count<ModNet.NetSource>(this.facadeTest))
  1019. {
  1020. Id = 0;
  1021. }
  1022. netSource = this.facadeTest[Id];
  1023. }
  1024. result = netSource;
  1025. }
  1026. else if (Enumerable.Any<ModNet.NetSource>(this._MerchantTest))
  1027. {
  1028. result = this._MerchantTest[0];
  1029. }
  1030. else
  1031. {
  1032. result = null;
  1033. }
  1034. }
  1035. return result;
  1036. }
  1037. }
  1038. // Token: 0x06000D19 RID: 3353 RVA: 0x00057458 File Offset: 0x00055658
  1039. public bool IsSourceFailed(bool AllowOnceSource = true)
  1040. {
  1041. checked
  1042. {
  1043. bool result;
  1044. if (AllowOnceSource && Enumerable.Any<ModNet.NetSource>(this._MerchantTest))
  1045. {
  1046. result = false;
  1047. }
  1048. else
  1049. {
  1050. object messageTest = this._MessageTest;
  1051. ObjectFlowControl.CheckForSyncLockOnValueType(messageTest);
  1052. lock (messageTest)
  1053. {
  1054. ModNet.NetSource[] array = this.facadeTest;
  1055. for (int i = 0; i < array.Length; i++)
  1056. {
  1057. if (!array[i].candidateTest)
  1058. {
  1059. return false;
  1060. }
  1061. }
  1062. }
  1063. result = true;
  1064. }
  1065. return result;
  1066. }
  1067. }
  1068. // Token: 0x06000D1A RID: 3354 RVA: 0x000087C2 File Offset: 0x000069C2
  1069. public bool CollectMapper()
  1070. {
  1071. return this.databaseTest || this.filterTest < 262144L;
  1072. }
  1073. // Token: 0x06000D1B RID: 3355 RVA: 0x000574D8 File Offset: 0x000556D8
  1074. public long CreateMapper()
  1075. {
  1076. checked
  1077. {
  1078. if (ModBase.GetTimeTick() - this.m_ContainerTest > 200L)
  1079. {
  1080. long num = ModBase.GetTimeTick() - this.m_ContainerTest;
  1081. this.m_DispatcherTest = (long)Math.Round((double)(this._PoolTest - this.paramsTest) / ((double)num / 1000.0));
  1082. this.paramsTest = this._PoolTest;
  1083. ref long ptr = ref this.m_ContainerTest;
  1084. this.m_ContainerTest = ptr + num;
  1085. }
  1086. return this.m_DispatcherTest;
  1087. }
  1088. }
  1089. // Token: 0x1700020A RID: 522
  1090. // (get) Token: 0x06000D1C RID: 3356 RVA: 0x00057550 File Offset: 0x00055750
  1091. public double Progress
  1092. {
  1093. get
  1094. {
  1095. double result;
  1096. switch (this._ComparatorTest)
  1097. {
  1098. case ModNet.NetState.WaitForCheck:
  1099. result = 0.0;
  1100. break;
  1101. case ModNet.NetState.WaitForDownload:
  1102. result = 0.01;
  1103. break;
  1104. case ModNet.NetState.Connect:
  1105. result = 0.02;
  1106. break;
  1107. case ModNet.NetState.Get:
  1108. result = 0.04;
  1109. break;
  1110. case ModNet.NetState.Download:
  1111. {
  1112. double num = this.databaseTest ? 0.5 : ((double)this._PoolTest / (double)Math.Max(this.filterTest, 1L));
  1113. num = 1.0 - Math.Pow(1.0 - num, 0.9);
  1114. result = num * 0.93 + 0.05;
  1115. break;
  1116. }
  1117. case ModNet.NetState.Merge:
  1118. result = 0.99;
  1119. break;
  1120. case ModNet.NetState.WaitForCopy:
  1121. result = 0.2;
  1122. break;
  1123. case ModNet.NetState.Finish:
  1124. case ModNet.NetState.Error:
  1125. result = 1.0;
  1126. break;
  1127. default:
  1128. throw new ArgumentOutOfRangeException("文件状态未知:" + Conversions.ToString((int)this._ComparatorTest));
  1129. }
  1130. return result;
  1131. }
  1132. }
  1133. // Token: 0x06000D1D RID: 3357 RVA: 0x00057678 File Offset: 0x00055878
  1134. private int StartMapper()
  1135. {
  1136. object obj = this.serviceTest;
  1137. ObjectFlowControl.CheckForSyncLockOnValueType(obj);
  1138. int result;
  1139. lock (obj)
  1140. {
  1141. result = checked((int)Math.Round((this.parameterTest == 0) ? -1.0 : ((double)this.recordTest / (double)this.parameterTest)));
  1142. }
  1143. return result;
  1144. }
  1145. // Token: 0x06000D1E RID: 3358 RVA: 0x000576E4 File Offset: 0x000558E4
  1146. public override bool Equals(object obj)
  1147. {
  1148. ModNet.NetFile netFile = obj as ModNet.NetFile;
  1149. return netFile != null && this.creatorTest == netFile.creatorTest;
  1150. }
  1151. // Token: 0x06000D1F RID: 3359 RVA: 0x0005770C File Offset: 0x0005590C
  1152. public NetFile(IEnumerable<string> Urls, string LocalPath, ModBase.FileChecker Check = null, bool UseBrowserUserAgent = false)
  1153. {
  1154. this._AdapterTest = new ModBase.SafeList<ModNet.LoaderDownload>();
  1155. this.listTest = 0;
  1156. this._MerchantTest = new List<ModNet.NetSource>();
  1157. this.m_AuthenticationTest = null;
  1158. this._AlgoTest = null;
  1159. this._ComparatorTest = ModNet.NetState.WaitForCheck;
  1160. this._MappingTest = new List<Exception>();
  1161. this.filterTest = -2L;
  1162. this.databaseTest = false;
  1163. this._PoolTest = 0L;
  1164. this.customerTest = RuntimeHelpers.GetObjectValue(new object());
  1165. this.m_ContainerTest = ModBase.GetTimeTick();
  1166. this.paramsTest = 0L;
  1167. this.m_DispatcherTest = 0L;
  1168. this.m_ProcessTest = false;
  1169. this.parameterTest = 0;
  1170. this.recordTest = 0L;
  1171. this.serviceTest = RuntimeHelpers.GetObjectValue(new object());
  1172. this.m_InvocationTest = RuntimeHelpers.GetObjectValue(new object());
  1173. this._ProxyTest = RuntimeHelpers.GetObjectValue(new object());
  1174. this._MessageTest = RuntimeHelpers.GetObjectValue(new object());
  1175. this.creatorTest = ModBase.GetUuid();
  1176. List<ModNet.NetSource> list = new List<ModNet.NetSource>();
  1177. int num = 0;
  1178. Urls = Enumerable.ToArray<string>(Enumerable.Distinct<string>(Urls));
  1179. checked
  1180. {
  1181. try
  1182. {
  1183. foreach (string text in Urls)
  1184. {
  1185. list.Add(new ModNet.NetSource
  1186. {
  1187. _PrinterTest = 0,
  1188. m_StructTest = Conversions.ToString(ModSecret.SecretCdnSign(text.Replace("\r", "").Replace("\n", "").Trim())),
  1189. roleTest = num,
  1190. candidateTest = false,
  1191. _ValTest = null
  1192. });
  1193. num++;
  1194. }
  1195. }
  1196. finally
  1197. {
  1198. IEnumerator<string> enumerator;
  1199. if (enumerator != null)
  1200. {
  1201. enumerator.Dispose();
  1202. }
  1203. }
  1204. this.facadeTest = list.ToArray();
  1205. this.m_AuthenticationTest = LocalPath;
  1206. this.m_PageTest = Check;
  1207. this._InterceptorTest = UseBrowserUserAgent;
  1208. this._AlgoTest = ModBase.GetFileNameFromPath(LocalPath);
  1209. }
  1210. }
  1211. // Token: 0x06000D20 RID: 3360 RVA: 0x000578FC File Offset: 0x00055AFC
  1212. public ModNet.NetThread TryBeginThread()
  1213. {
  1214. checked
  1215. {
  1216. ModNet.NetThread result;
  1217. try
  1218. {
  1219. if (ModNet._ConfigurationTests < ModNet.m_StateTests && !this.IsSourceFailed(true))
  1220. {
  1221. if (!this.CollectMapper() || this.m_TokenizerTest == null || this.m_TokenizerTest.infoTest == ModNet.NetState.Error)
  1222. {
  1223. if (this._ComparatorTest < ModNet.NetState.Merge)
  1224. {
  1225. if (this._ComparatorTest != ModNet.NetState.WaitForCheck)
  1226. {
  1227. object invocationTest = this.m_InvocationTest;
  1228. ObjectFlowControl.CheckForSyncLockOnValueType(invocationTest);
  1229. lock (invocationTest)
  1230. {
  1231. if (this._ComparatorTest < ModNet.NetState.Connect)
  1232. {
  1233. this._ComparatorTest = ModNet.NetState.Connect;
  1234. }
  1235. }
  1236. ModNet.NetSource netSource = null;
  1237. object proxyTest = this._ProxyTest;
  1238. ObjectFlowControl.CheckForSyncLockOnValueType(proxyTest);
  1239. Thread thread;
  1240. ModNet.NetThread netThread4;
  1241. lock (proxyTest)
  1242. {
  1243. if (!this.CollectMapper())
  1244. {
  1245. if (!this.IsSourceFailed(false))
  1246. {
  1247. goto IL_16E;
  1248. }
  1249. if (this._MerchantTest[0].m_AttrTest != null && this._MerchantTest[0].m_AttrTest.infoTest != ModNet.NetState.Error)
  1250. {
  1251. return null;
  1252. }
  1253. }
  1254. this.predicateTest = null;
  1255. this.m_TokenizerTest = null;
  1256. ModNet.NetManagerClass tokenTests;
  1257. (tokenTests = ModNet.tokenTests).InterruptMapper(tokenTests.PrintMapper() - this._PoolTest);
  1258. object obj = this.customerTest;
  1259. ObjectFlowControl.CheckForSyncLockOnValueType(obj);
  1260. lock (obj)
  1261. {
  1262. this._PoolTest = 0L;
  1263. }
  1264. this.paramsTest = 0L;
  1265. this._ComparatorTest = ModNet.NetState.Get;
  1266. IL_16E:
  1267. long num;
  1268. if (this.m_TokenizerTest == null)
  1269. {
  1270. num = 0L;
  1271. netSource = this.GetSource(this.listTest);
  1272. this.listTest = netSource.roleTest + 1;
  1273. }
  1274. else
  1275. {
  1276. try
  1277. {
  1278. foreach (ModNet.NetThread netThread in this.m_TokenizerTest)
  1279. {
  1280. if (netThread.infoTest == ModNet.NetState.Error && netThread.PublishMapper() > 0L)
  1281. {
  1282. num = netThread._ModelTest + netThread.wrapperTest;
  1283. netSource = this.GetSource(netThread.Source.roleTest + 1);
  1284. goto IL_30A;
  1285. }
  1286. }
  1287. }
  1288. finally
  1289. {
  1290. IEnumerator<ModNet.NetThread> enumerator;
  1291. if (enumerator != null)
  1292. {
  1293. enumerator.Dispose();
  1294. }
  1295. }
  1296. string structTest = this.GetSource(0).m_StructTest;
  1297. if (structTest.Contains("pcl2-server") || structTest.Contains("mcimirror") || structTest.Contains("github.com") || structTest.Contains("optifine.net") || structTest.Contains("modrinth"))
  1298. {
  1299. return null;
  1300. }
  1301. ModNet.NetThread netThread2 = this.m_TokenizerTest;
  1302. try
  1303. {
  1304. foreach (ModNet.NetThread netThread3 in this.m_TokenizerTest)
  1305. {
  1306. if (netThread3.PublishMapper() > netThread2.PublishMapper())
  1307. {
  1308. netThread2 = netThread3;
  1309. }
  1310. }
  1311. }
  1312. finally
  1313. {
  1314. IEnumerator<ModNet.NetThread> enumerator2;
  1315. if (enumerator2 != null)
  1316. {
  1317. enumerator2.Dispose();
  1318. }
  1319. }
  1320. if (netThread2 == null || netThread2.PublishMapper() < 262144L)
  1321. {
  1322. return null;
  1323. }
  1324. num = (long)Math.Round(unchecked((double)netThread2.AddMapper() - (double)netThread2.PublishMapper() * 0.4));
  1325. netSource = this.GetSource(0);
  1326. }
  1327. IL_30A:
  1328. if ((num > this.filterTest && this.filterTest >= 0L && !this.databaseTest) || num < 0L || Information.IsNothing(netSource))
  1329. {
  1330. return null;
  1331. }
  1332. int uuid = ModBase.GetUuid();
  1333. if (!Enumerable.Any<ModNet.LoaderDownload>(this._AdapterTest))
  1334. {
  1335. return null;
  1336. }
  1337. thread = new Thread(delegate(object a0)
  1338. {
  1339. this.Thread((ModNet.NetThread)a0);
  1340. })
  1341. {
  1342. Name = string.Format("NetTask {0}/{1} Download {2}#", this._AdapterTest[0].Uuid, this.creatorTest, uuid),
  1343. Priority = ThreadPriority.BelowNormal
  1344. };
  1345. netThread4 = new ModNet.NetThread
  1346. {
  1347. m_EventTest = uuid,
  1348. _ModelTest = num,
  1349. m_AccountTest = thread,
  1350. Source = netSource,
  1351. _AdvisorTest = this,
  1352. infoTest = ModNet.NetState.WaitForDownload
  1353. };
  1354. if (!netThread4.InitMapper() && this.m_TokenizerTest != null)
  1355. {
  1356. ModNet.NetThread netThread5 = this.m_TokenizerTest;
  1357. while (netThread5.AddMapper() <= num)
  1358. {
  1359. netThread5 = netThread5.m_QueueTest;
  1360. }
  1361. netThread4.m_QueueTest = netThread5.m_QueueTest;
  1362. netThread5.m_QueueTest = netThread4;
  1363. }
  1364. else
  1365. {
  1366. this.m_TokenizerTest = netThread4;
  1367. }
  1368. }
  1369. object getterTests = ModNet._GetterTests;
  1370. ObjectFlowControl.CheckForSyncLockOnValueType(getterTests);
  1371. lock (getterTests)
  1372. {
  1373. ModNet._ConfigurationTests++;
  1374. }
  1375. object messageTest = this._MessageTest;
  1376. ObjectFlowControl.CheckForSyncLockOnValueType(messageTest);
  1377. lock (messageTest)
  1378. {
  1379. if (this.IsSourceFailed(false))
  1380. {
  1381. this._MerchantTest[0].m_AttrTest = netThread4;
  1382. }
  1383. }
  1384. thread.Start(netThread4);
  1385. return netThread4;
  1386. }
  1387. }
  1388. return null;
  1389. }
  1390. }
  1391. result = null;
  1392. }
  1393. catch (Exception ex)
  1394. {
  1395. ModBase.Log(ex, "尝试开始下载线程失败(" + (this._AlgoTest ?? "Nothing") + ")", ModBase.LogLevel.Hint, "出现错误");
  1396. result = null;
  1397. }
  1398. return result;
  1399. }
  1400. }
  1401. // Token: 0x06000D21 RID: 3361 RVA: 0x00057EF4 File Offset: 0x000560F4
  1402. private void Thread(ModNet.NetThread Info)
  1403. {
  1404. if (ModBase._TokenRepository || Info._ModelTest == 0L)
  1405. {
  1406. ModBase.Log(string.Concat(new string[]
  1407. {
  1408. "[Download] ",
  1409. this._AlgoTest,
  1410. " ",
  1411. Conversions.ToString(Info.m_EventTest),
  1412. "#:开始,起始点 ",
  1413. Conversions.ToString(Info._ModelTest),
  1414. ",",
  1415. Info.Source.m_StructTest
  1416. }), ModBase.LogLevel.Normal, "出现错误");
  1417. }
  1418. Stream stream = null;
  1419. checked
  1420. {
  1421. int num = Math.Min(Math.Max(this.StartMapper(), 6000) * (1 + Info.Source._PrinterTest), 30000);
  1422. Info.infoTest = ModNet.NetState.Connect;
  1423. try
  1424. {
  1425. int num2 = 0;
  1426. long num3;
  1427. if (!this._MerchantTest.Contains(Info.Source) || Info.Equals(Info.Source.m_AttrTest))
  1428. {
  1429. HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Info.Source.m_StructTest);
  1430. if (Info.Source.m_StructTest.StartsWithF("https", true))
  1431. {
  1432. httpWebRequest.ProtocolVersion = HttpVersion.Version11;
  1433. }
  1434. httpWebRequest.Timeout = num;
  1435. httpWebRequest.AddRange(Info._ModelTest);
  1436. ModSecret.SecretHeadersSign(Info.Source.m_StructTest, ref httpWebRequest, this._InterceptorTest);
  1437. num3 = 0L;
  1438. using (HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse())
  1439. {
  1440. if (this._ComparatorTest != ModNet.NetState.Error)
  1441. {
  1442. if (ModBase._TokenRepository && Operators.CompareString(httpWebResponse.ResponseUri.OriginalString, Info.Source.m_StructTest, false) != 0)
  1443. {
  1444. ModBase.Log(string.Format("[Download] {0} {1}#:重定向至 {2}", this._AlgoTest, Info.m_EventTest, httpWebResponse.ResponseUri.OriginalString), ModBase.LogLevel.Normal, "出现错误");
  1445. }
  1446. num3 = httpWebResponse.ContentLength;
  1447. if (num3 == -1L)
  1448. {
  1449. if (this.filterTest <= 1L)
  1450. {
  1451. this.filterTest = -1L;
  1452. this.databaseTest = true;
  1453. ModBase.Log(string.Format("[Download] {0} {1}#:文件大小未知", this._AlgoTest, Info.m_EventTest), ModBase.LogLevel.Normal, "出现错误");
  1454. goto IL_60B;
  1455. }
  1456. if (Info._ModelTest == 0L)
  1457. {
  1458. ModBase.Log(string.Format("[Download] {0} {1}#:文件大小未知,但已从其他下载源获取,不作处理", this._AlgoTest, Info.m_EventTest), ModBase.LogLevel.Normal, "出现错误");
  1459. goto IL_60B;
  1460. }
  1461. ModBase.Log(string.Format("[Download] {0} {1}#:ContentLength 返回了 -1,无法确定是否支持分段下载,视作不支持", this._AlgoTest, Info.m_EventTest), ModBase.LogLevel.Normal, "出现错误");
  1462. }
  1463. else
  1464. {
  1465. if (num3 < 0L)
  1466. {
  1467. throw new Exception("获取片大小失败,结果为 " + Conversions.ToString(num3) + "。");
  1468. }
  1469. if (Info.InitMapper())
  1470. {
  1471. if (this.m_PageTest != null)
  1472. {
  1473. if (num3 < this.m_PageTest.m_ContextError && this.m_PageTest.m_ContextError > 0L)
  1474. {
  1475. throw new Exception(string.Format("文件大小不足,获取结果为 {0},要求至少为 {1}。", num3, this.m_PageTest.m_ContextError));
  1476. }
  1477. if (num3 != this.m_PageTest._ErrorError && this.m_PageTest._ErrorError > 0L)
  1478. {
  1479. throw new Exception(string.Format("文件大小不一致,获取结果为 {0},要求必须为 {1}。", num3, this.m_PageTest._ErrorError));
  1480. }
  1481. }
  1482. this.filterTest = num3;
  1483. this.databaseTest = false;
  1484. ModBase.Log(string.Format("[Download] {0} {1}#:文件大小 {2}({3})", new object[]
  1485. {
  1486. this._AlgoTest,
  1487. Info.m_EventTest,
  1488. num3,
  1489. ModBase.GetString(num3)
  1490. }), ModBase.LogLevel.Normal, "出现错误");
  1491. if (num3 > 52428800L)
  1492. {
  1493. foreach (DriveInfo driveInfo in DriveInfo.GetDrives())
  1494. {
  1495. string text = Enumerable.First<char>(driveInfo.Name).ToString();
  1496. double num4 = unchecked((ModBase.m_DecoratorRepository.StartsWithF(text, false) ? ((double)num3 * 1.1) : 0.0) + (double)(this.m_AuthenticationTest.StartsWithF(text, false) ? checked(num3 + 5242880L) : 0L));
  1497. if ((double)driveInfo.TotalFreeSpace < num4)
  1498. {
  1499. throw new Exception(string.Concat(new string[]
  1500. {
  1501. text,
  1502. " 盘空间不足,无法进行下载。\r\n需要至少 ",
  1503. ModBase.GetString((long)Math.Round(num4)),
  1504. " 空间,但当前仅剩余 ",
  1505. ModBase.GetString(driveInfo.TotalFreeSpace),
  1506. "。",
  1507. ModBase.m_DecoratorRepository.StartsWithF(text, false) ? "\r\n\r\n下载时需要与文件同等大小的空间存放缓存,你可以在设置中调整缓存文件夹的位置。" : ""
  1508. }));
  1509. }
  1510. }
  1511. goto IL_60B;
  1512. }
  1513. goto IL_60B;
  1514. }
  1515. else
  1516. {
  1517. if (this.filterTest < 0L)
  1518. {
  1519. throw new Exception("非首线程运行时,尚未获取文件大小");
  1520. }
  1521. if (Info._ModelTest <= 0L || num3 != this.filterTest)
  1522. {
  1523. if (this.filterTest - Info._ModelTest != num3)
  1524. {
  1525. throw new WebException(string.Format("获取到的分段大小不一致:Range 起始于 {0},预期 ContentLength 为 {1},返回 ContentLength 为 {2},总文件大小 {3}", new object[]
  1526. {
  1527. Info._ModelTest,
  1528. this.filterTest - Info._ModelTest,
  1529. num3,
  1530. this.filterTest
  1531. }));
  1532. }
  1533. goto IL_60B;
  1534. }
  1535. }
  1536. }
  1537. object messageTest = this._MessageTest;
  1538. ObjectFlowControl.CheckForSyncLockOnValueType(messageTest);
  1539. lock (messageTest)
  1540. {
  1541. if (this._MerchantTest.Contains(Info.Source))
  1542. {
  1543. goto IL_AF7;
  1544. }
  1545. this._MerchantTest.Add(Info.Source);
  1546. }
  1547. throw new WebException(string.Format("该下载源不支持分段下载:Range 起始于 {0},预期 ContentLength 为 {1},返回 ContentLength 为 {2},总文件大小 {3}", new object[]
  1548. {
  1549. Info._ModelTest,
  1550. this.filterTest - Info._ModelTest,
  1551. num3,
  1552. this.filterTest
  1553. }));
  1554. IL_60B:
  1555. Info.infoTest = ModNet.NetState.Get;
  1556. object invocationTest = this.m_InvocationTest;
  1557. ObjectFlowControl.CheckForSyncLockOnValueType(invocationTest);
  1558. lock (invocationTest)
  1559. {
  1560. if (this._ComparatorTest < ModNet.NetState.Get)
  1561. {
  1562. this._ComparatorTest = ModNet.NetState.Get;
  1563. }
  1564. }
  1565. if (this.CollectMapper())
  1566. {
  1567. Info._ManagerTest = null;
  1568. this.predicateTest = new Queue<byte>();
  1569. }
  1570. else
  1571. {
  1572. Info._ManagerTest = string.Concat(new string[]
  1573. {
  1574. ModBase.m_DecoratorRepository,
  1575. "Download\\",
  1576. Conversions.ToString(this.creatorTest),
  1577. "_",
  1578. Conversions.ToString(Info.m_EventTest),
  1579. "_",
  1580. Conversions.ToString(ModBase.RandomInteger(0, 999999)),
  1581. ".tmp"
  1582. });
  1583. stream = new FileStream(Info._ManagerTest, FileMode.Create, FileAccess.Write, FileShare.Read);
  1584. }
  1585. using (Stream responseStream = httpWebResponse.GetResponseStream())
  1586. {
  1587. responseStream.ReadTimeout = num;
  1588. if (Conversions.ToBoolean(ModBase.m_IdentifierRepository.Get("SystemDebugDelay", null)))
  1589. {
  1590. System.Threading.Thread.Sleep(ModBase.RandomInteger(50, 3000));
  1591. }
  1592. byte[] array = new byte[16385];
  1593. num2 = responseStream.Read(array, 0, 16384);
  1594. int num5;
  1595. long num6;
  1596. for (;;)
  1597. {
  1598. if (!this.databaseTest)
  1599. {
  1600. if (Info.PublishMapper() <= 0L)
  1601. {
  1602. break;
  1603. }
  1604. }
  1605. if (num2 <= 0 || ModBase._ObserverRepository || this._ComparatorTest >= ModNet.NetState.Merge)
  1606. {
  1607. break;
  1608. }
  1609. if (Info.Source.candidateTest && !Info.Equals(Info.Source.m_AttrTest))
  1610. {
  1611. break;
  1612. }
  1613. while (ModNet.m_TemplateTests > 0L && ModNet.m_MethodTests <= 0L)
  1614. {
  1615. System.Threading.Thread.Sleep(16);
  1616. }
  1617. num5 = (int)(unchecked(this.databaseTest ? ((long)num2) : Math.Min((long)num2, Info.PublishMapper())));
  1618. object taskTests = ModNet.taskTests;
  1619. ObjectFlowControl.CheckForSyncLockOnValueType(taskTests);
  1620. lock (taskTests)
  1621. {
  1622. if (ModNet.m_TemplateTests > 0L)
  1623. {
  1624. ModNet.m_MethodTests -= unchecked((long)num5);
  1625. }
  1626. }
  1627. num6 = ModBase.GetTimeTick() - Info._AnnotationTest;
  1628. if (num6 > 1000000L)
  1629. {
  1630. num6 = 1L;
  1631. }
  1632. if (num5 > 0)
  1633. {
  1634. long ptr2;
  1635. if (Info.wrapperTest == 0L)
  1636. {
  1637. Info.infoTest = ModNet.NetState.Download;
  1638. object invocationTest2 = this.m_InvocationTest;
  1639. ObjectFlowControl.CheckForSyncLockOnValueType(invocationTest2);
  1640. lock (invocationTest2)
  1641. {
  1642. if (this._ComparatorTest < ModNet.NetState.Download)
  1643. {
  1644. this._ComparatorTest = ModNet.NetState.Download;
  1645. }
  1646. }
  1647. object obj = this.serviceTest;
  1648. ObjectFlowControl.CheckForSyncLockOnValueType(obj);
  1649. lock (obj)
  1650. {
  1651. ref int ptr = ref this.parameterTest;
  1652. this.parameterTest = ptr + 1;
  1653. ptr2 = ref this.recordTest;
  1654. this.recordTest = ptr2 + (ModBase.GetTimeTick() - Info._PrototypeTest);
  1655. }
  1656. }
  1657. object obj2 = this.serviceTest;
  1658. ObjectFlowControl.CheckForSyncLockOnValueType(obj2);
  1659. lock (obj2)
  1660. {
  1661. Info.Source._PrinterTest = 0;
  1662. try
  1663. {
  1664. foreach (ModNet.LoaderDownload loaderDownload in this._AdapterTest)
  1665. {
  1666. loaderDownload.FailCount = 0;
  1667. }
  1668. }
  1669. finally
  1670. {
  1671. IEnumerator<ModNet.LoaderDownload> enumerator;
  1672. if (enumerator != null)
  1673. {
  1674. enumerator.Dispose();
  1675. }
  1676. }
  1677. }
  1678. ModNet.NetManagerClass tokenTests;
  1679. (tokenTests = ModNet.tokenTests).InterruptMapper(tokenTests.PrintMapper() + unchecked((long)num5));
  1680. object obj3 = this.customerTest;
  1681. ObjectFlowControl.CheckForSyncLockOnValueType(obj3);
  1682. lock (obj3)
  1683. {
  1684. ptr2 = ref this._PoolTest;
  1685. this._PoolTest = ptr2 + unchecked((long)num5);
  1686. }
  1687. ptr2 = ref Info.wrapperTest;
  1688. Info.wrapperTest = ptr2 + unchecked((long)num5);
  1689. if (this.CollectMapper())
  1690. {
  1691. if (Enumerable.Count<byte>(array) == num5)
  1692. {
  1693. foreach (byte b in array)
  1694. {
  1695. this.predicateTest.Enqueue(b);
  1696. }
  1697. }
  1698. else
  1699. {
  1700. int num7 = num5 - 1;
  1701. for (int k = 0; k <= num7; k++)
  1702. {
  1703. this.predicateTest.Enqueue(array[k]);
  1704. }
  1705. }
  1706. }
  1707. else
  1708. {
  1709. stream.Write(array, 0, num5);
  1710. }
  1711. if (num6 > 1500L && num6 > unchecked((long)num5))
  1712. {
  1713. goto IL_A93;
  1714. }
  1715. Info._AnnotationTest = ModBase.GetTimeTick();
  1716. if (Info.PublishMapper() == 0L && !this.databaseTest)
  1717. {
  1718. break;
  1719. }
  1720. }
  1721. else if (Info._AnnotationTest > 0L && num6 > unchecked((long)num))
  1722. {
  1723. goto IL_AD0;
  1724. }
  1725. num2 = responseStream.Read(array, 0, 16384);
  1726. }
  1727. goto IL_ADB;
  1728. IL_A93:
  1729. throw new TimeoutException(string.Concat(new string[]
  1730. {
  1731. "由于速度过慢断开链接,下载 ",
  1732. Conversions.ToString(num5),
  1733. " B,消耗 ",
  1734. Conversions.ToString(num6),
  1735. " ms。"
  1736. }));
  1737. IL_AD0:
  1738. throw new TimeoutException("操作超时,无数据。");
  1739. IL_ADB:;
  1740. }
  1741. }
  1742. }
  1743. }
  1744. IL_AF7:
  1745. if (this._ComparatorTest != ModNet.NetState.Error && !Info.Source.candidateTest && (Info.PublishMapper() <= 0L || this.databaseTest))
  1746. {
  1747. if (num2 == 0 && Info.PublishMapper() > 0L && !this.databaseTest)
  1748. {
  1749. throw new Exception(string.Format("返回的 ContentLength 过多:ContentLength 为 {0},但获取到的总数据量仅为 {1}(全文件总数据量 {2})", num3, Info.wrapperTest, this._PoolTest));
  1750. }
  1751. Info.infoTest = ModNet.NetState.Finish;
  1752. if (ModBase._TokenRepository)
  1753. {
  1754. ModBase.Log(string.Format("[Download] {0} {1}#:完成,已下载 {2}", this._AlgoTest, Info.m_EventTest, Info.wrapperTest), ModBase.LogLevel.Normal, "出现错误");
  1755. }
  1756. }
  1757. else
  1758. {
  1759. Info.infoTest = ModNet.NetState.Error;
  1760. ModBase.Log(string.Format("[Download] {0} {1}#:中断", this._AlgoTest, Info.m_EventTest), ModBase.LogLevel.Normal, "出现错误");
  1761. }
  1762. }
  1763. catch (Exception ex)
  1764. {
  1765. object obj4 = this.serviceTest;
  1766. ObjectFlowControl.CheckForSyncLockOnValueType(obj4);
  1767. lock (obj4)
  1768. {
  1769. ModNet.NetSource source = Info.Source;
  1770. ref int ptr = ref source._PrinterTest;
  1771. source._PrinterTest = ptr + 1;
  1772. try
  1773. {
  1774. foreach (ModNet.LoaderDownload loaderDownload2 in this._AdapterTest)
  1775. {
  1776. ModNet.LoaderDownload loaderDownload3;
  1777. (loaderDownload3 = loaderDownload2).FailCount = loaderDownload3.FailCount + 1;
  1778. }
  1779. }
  1780. finally
  1781. {
  1782. IEnumerator<ModNet.LoaderDownload> enumerator2;
  1783. if (enumerator2 != null)
  1784. {
  1785. enumerator2.Dispose();
  1786. }
  1787. }
  1788. }
  1789. string text2 = ModBase.GetExceptionSummary(ex).ToLower().Replace(" ", "");
  1790. bool flag9 = text2.Contains("由于连接方在一段时间后没有正确答复或连接的主机没有反应") || text2.Contains("超时") || text2.Contains("timeout") || text2.Contains("timedout");
  1791. ModBase.Log(string.Concat(new string[]
  1792. {
  1793. "[Download] ",
  1794. this._AlgoTest,
  1795. " ",
  1796. Conversions.ToString(Info.m_EventTest),
  1797. flag9 ? ("#:超时(" + Conversions.ToString(unchecked((double)num * 0.001)) + "s)") : ("#:出错," + ModBase.GetExceptionDetail(ex, false))
  1798. }), ModBase.LogLevel.Normal, "出现错误");
  1799. Info.infoTest = ModNet.NetState.Error;
  1800. Info.Source._ValTest = ex;
  1801. if (ex.Message.Contains("该下载源不支持") || ex.Message.Contains("未能解析") || ex.Message.Contains("(404)") || ex.Message.Contains("(502)") || ex.Message.Contains("无返回数据") || ex.Message.Contains("空间不足") || ex.Message.Contains("获取到的分段大小不一致") || (ex.Message.Contains("(403)") && !Info.Source.m_StructTest.ContainsF("bmclapi", false)) || ((double)Info.Source._PrinterTest >= ModBase.MathClamp((double)ModNet.m_StateTests, 5.0, 30.0) && this._PoolTest < 1L) || Info.Source._PrinterTest > ModNet.m_StateTests + 2)
  1802. {
  1803. bool flag10 = false;
  1804. object messageTest2 = this._MessageTest;
  1805. ObjectFlowControl.CheckForSyncLockOnValueType(messageTest2);
  1806. lock (messageTest2)
  1807. {
  1808. if (Info.Source.m_AttrTest != null && Info.Source.m_AttrTest.Equals(Info))
  1809. {
  1810. this._MerchantTest.RemoveAt(0);
  1811. }
  1812. else if (Info.Source.candidateTest)
  1813. {
  1814. goto IL_ECF;
  1815. }
  1816. Info.Source.candidateTest = true;
  1817. flag10 = true;
  1818. IL_ECF:;
  1819. }
  1820. if (flag10)
  1821. {
  1822. ModBase.Log(string.Format("[Download] {0} {1}#:下载源被禁用({2}):{3}", new object[]
  1823. {
  1824. this._AlgoTest,
  1825. Info.m_EventTest,
  1826. Info.Source.roleTest,
  1827. Info.Source.m_StructTest
  1828. }), ModBase.LogLevel.Normal, "出现错误");
  1829. ModBase.Log(ex, "下载源 " + Conversions.ToString(Info.Source.roleTest) + " 已被禁用", (ex.Message.Contains("不支持分段下载") || ex.Message.Contains("(404)") || ex.Message.Contains("(416)")) ? ModBase.LogLevel.Developer : ModBase.LogLevel.Debug, "出现错误");
  1830. if (this.IsSourceFailed(true))
  1831. {
  1832. ModBase.Log("[Download] 文件 " + this._AlgoTest + " 已无可用下载源", ModBase.LogLevel.Normal, "出现错误");
  1833. Exception raiseEx = null;
  1834. object messageTest3 = this._MessageTest;
  1835. ObjectFlowControl.CheckForSyncLockOnValueType(messageTest3);
  1836. lock (messageTest3)
  1837. {
  1838. foreach (ModNet.NetSource netSource in this.facadeTest)
  1839. {
  1840. ModBase.Log("[Download] 已禁用的下载源:" + netSource.m_StructTest, ModBase.LogLevel.Normal, "出现错误");
  1841. if (netSource._ValTest != null)
  1842. {
  1843. raiseEx = netSource._ValTest;
  1844. ModBase.Log(netSource._ValTest, "下载源禁用原因", ModBase.LogLevel.Developer, "出现错误");
  1845. }
  1846. }
  1847. }
  1848. this.Fail(raiseEx);
  1849. }
  1850. else if (ex.Message.Contains("空间不足"))
  1851. {
  1852. this.Fail(ex);
  1853. }
  1854. }
  1855. }
  1856. if (this.filterTest == -2L)
  1857. {
  1858. object proxyTest = this._ProxyTest;
  1859. ObjectFlowControl.CheckForSyncLockOnValueType(proxyTest);
  1860. lock (proxyTest)
  1861. {
  1862. this.m_TokenizerTest = null;
  1863. }
  1864. }
  1865. }
  1866. finally
  1867. {
  1868. if (stream != null)
  1869. {
  1870. stream.Dispose();
  1871. }
  1872. object getterTests = ModNet._GetterTests;
  1873. ObjectFlowControl.CheckForSyncLockOnValueType(getterTests);
  1874. lock (getterTests)
  1875. {
  1876. ModNet._ConfigurationTests--;
  1877. }
  1878. if (((this.filterTest >= 0L && this._PoolTest >= this.filterTest) || (this.filterTest == -1L && this._PoolTest > 0L)) && this._ComparatorTest < ModNet.NetState.Merge)
  1879. {
  1880. this.Merge();
  1881. }
  1882. }
  1883. }
  1884. }
  1885. // Token: 0x06000D22 RID: 3362 RVA: 0x00059214 File Offset: 0x00057414
  1886. private string GetFileNameFromResponse(HttpWebResponse response)
  1887. {
  1888. string text = response.Headers["Content-Disposition"];
  1889. string result;
  1890. if (string.IsNullOrEmpty(text))
  1891. {
  1892. result = null;
  1893. }
  1894. else if (!text.Contains("filename="))
  1895. {
  1896. result = null;
  1897. }
  1898. else
  1899. {
  1900. result = text.AfterLast("filename=", false).Trim(new char[]
  1901. {
  1902. '"',
  1903. ' '
  1904. }).BeforeFirst(";", false);
  1905. }
  1906. return result;
  1907. }
  1908. // Token: 0x06000D23 RID: 3363 RVA: 0x00059280 File Offset: 0x00057480
  1909. private void Merge()
  1910. {
  1911. object invocationTest = this.m_InvocationTest;
  1912. ObjectFlowControl.CheckForSyncLockOnValueType(invocationTest);
  1913. lock (invocationTest)
  1914. {
  1915. if (this._ComparatorTest >= ModNet.NetState.Merge)
  1916. {
  1917. return;
  1918. }
  1919. this._ComparatorTest = ModNet.NetState.Merge;
  1920. }
  1921. int num = 0;
  1922. Stream stream = null;
  1923. BinaryWriter binaryWriter = null;
  1924. checked
  1925. {
  1926. try
  1927. {
  1928. IL_40:
  1929. object proxyTest = this._ProxyTest;
  1930. ObjectFlowControl.CheckForSyncLockOnValueType(proxyTest);
  1931. lock (proxyTest)
  1932. {
  1933. if (File.Exists(this.m_AuthenticationTest))
  1934. {
  1935. File.Delete(this.m_AuthenticationTest);
  1936. }
  1937. new FileInfo(this.m_AuthenticationTest).Directory.Create();
  1938. if (this.CollectMapper())
  1939. {
  1940. if (ModBase._TokenRepository)
  1941. {
  1942. ModBase.Log(string.Format("[Download] {0}:下载结束,从缓存输出文件,长度:", this._AlgoTest) + Conversions.ToString(this.predicateTest.Count), ModBase.LogLevel.Normal, "出现错误");
  1943. }
  1944. stream = new FileStream(this.m_AuthenticationTest, FileMode.Create);
  1945. binaryWriter = new BinaryWriter(stream);
  1946. binaryWriter.Write(this.predicateTest.ToArray());
  1947. binaryWriter.Dispose();
  1948. binaryWriter = null;
  1949. stream.Dispose();
  1950. stream = null;
  1951. }
  1952. else if (this.m_TokenizerTest.wrapperTest == this._PoolTest && this.m_TokenizerTest._ManagerTest != null)
  1953. {
  1954. if (ModBase._TokenRepository)
  1955. {
  1956. ModBase.Log(string.Format("[Download] {0}:下载结束,仅有一个文件,无需合并", this._AlgoTest), ModBase.LogLevel.Normal, "出现错误");
  1957. }
  1958. ModBase.CopyFile(this.m_TokenizerTest._ManagerTest, this.m_AuthenticationTest);
  1959. }
  1960. else
  1961. {
  1962. if (ModBase._TokenRepository)
  1963. {
  1964. ModBase.Log(string.Format("[Download] {0}:下载结束,开始合并文件", this._AlgoTest), ModBase.LogLevel.Normal, "出现错误");
  1965. }
  1966. stream = new FileStream(this.m_AuthenticationTest, FileMode.Create);
  1967. binaryWriter = new BinaryWriter(stream);
  1968. try
  1969. {
  1970. foreach (ModNet.NetThread netThread in this.m_TokenizerTest)
  1971. {
  1972. if (netThread.wrapperTest != 0L && netThread._ManagerTest != null)
  1973. {
  1974. using (FileStream fileStream = new FileStream(netThread._ManagerTest, FileMode.Open, FileAccess.Read, FileShare.Read))
  1975. {
  1976. using (BinaryReader binaryReader = new BinaryReader(fileStream))
  1977. {
  1978. binaryWriter.Write(binaryReader.ReadBytes((int)netThread.wrapperTest));
  1979. }
  1980. }
  1981. }
  1982. }
  1983. }
  1984. finally
  1985. {
  1986. IEnumerator<ModNet.NetThread> enumerator;
  1987. if (enumerator != null)
  1988. {
  1989. enumerator.Dispose();
  1990. }
  1991. }
  1992. binaryWriter.Dispose();
  1993. binaryWriter = null;
  1994. stream.Dispose();
  1995. stream = null;
  1996. }
  1997. if (!this.databaseTest && this.m_PageTest != null)
  1998. {
  1999. if (this.m_PageTest._ErrorError == -1L)
  2000. {
  2001. this.m_PageTest._ErrorError = this.filterTest;
  2002. }
  2003. else if (this.m_PageTest._ErrorError != this.filterTest)
  2004. {
  2005. throw new Exception(string.Format("文件大小不一致:任务要求为 {0} B,网络获取结果为 {1}B", this.m_PageTest._ErrorError, this.filterTest));
  2006. }
  2007. }
  2008. ModBase.FileChecker pageTest = this.m_PageTest;
  2009. string text = (pageTest != null) ? pageTest.Check(this.m_AuthenticationTest) : null;
  2010. if (text != null)
  2011. {
  2012. ModBase.Log(string.Format("[Download] {0} 文件校验失败,下载线程细节:", this._AlgoTest), ModBase.LogLevel.Normal, "出现错误");
  2013. try
  2014. {
  2015. foreach (ModNet.NetThread netThread2 in this.m_TokenizerTest)
  2016. {
  2017. ModBase.Log(string.Format("[Download] {0}#,状态 {1},范围 {2}~{3},完成 {4},剩余 {5}", new object[]
  2018. {
  2019. netThread2.m_EventTest,
  2020. ModBase.GetStringFromEnum(netThread2.infoTest),
  2021. netThread2._ModelTest,
  2022. netThread2._ModelTest + netThread2.wrapperTest,
  2023. netThread2.wrapperTest,
  2024. netThread2.PublishMapper()
  2025. }), ModBase.LogLevel.Normal, "出现错误");
  2026. }
  2027. }
  2028. finally
  2029. {
  2030. IEnumerator<ModNet.NetThread> enumerator2;
  2031. if (enumerator2 != null)
  2032. {
  2033. enumerator2.Dispose();
  2034. }
  2035. }
  2036. throw new Exception(text);
  2037. }
  2038. if (this.CollectMapper())
  2039. {
  2040. this.predicateTest = null;
  2041. }
  2042. else
  2043. {
  2044. try
  2045. {
  2046. foreach (ModNet.NetThread netThread3 in this.m_TokenizerTest)
  2047. {
  2048. if (netThread3._ManagerTest != null)
  2049. {
  2050. File.Delete(netThread3._ManagerTest);
  2051. }
  2052. }
  2053. }
  2054. finally
  2055. {
  2056. IEnumerator<ModNet.NetThread> enumerator3;
  2057. if (enumerator3 != null)
  2058. {
  2059. enumerator3.Dispose();
  2060. }
  2061. }
  2062. }
  2063. this.Finish(true);
  2064. }
  2065. }
  2066. catch (Exception ex)
  2067. {
  2068. ModBase.Log(ex, "合并文件出错(" + this._AlgoTest + ")", ModBase.LogLevel.Debug, "出现错误");
  2069. if (stream != null)
  2070. {
  2071. stream.Dispose();
  2072. stream = null;
  2073. }
  2074. if (binaryWriter != null)
  2075. {
  2076. binaryWriter.Dispose();
  2077. binaryWriter = null;
  2078. }
  2079. if (num <= 3)
  2080. {
  2081. System.Threading.Thread.Sleep(ModBase.RandomInteger(500, 1000));
  2082. num++;
  2083. goto IL_40;
  2084. }
  2085. this.Fail(ex);
  2086. }
  2087. }
  2088. }
  2089. // Token: 0x06000D24 RID: 3364 RVA: 0x000597D8 File Offset: 0x000579D8
  2090. private void Fail(Exception RaiseEx = null)
  2091. {
  2092. object invocationTest = this.m_InvocationTest;
  2093. ObjectFlowControl.CheckForSyncLockOnValueType(invocationTest);
  2094. lock (invocationTest)
  2095. {
  2096. if (this._ComparatorTest >= ModNet.NetState.Finish)
  2097. {
  2098. return;
  2099. }
  2100. if (RaiseEx != null)
  2101. {
  2102. this._MappingTest.Add(RaiseEx);
  2103. }
  2104. this._ComparatorTest = ModNet.NetState.Error;
  2105. }
  2106. this.InterruptAndDelete();
  2107. try
  2108. {
  2109. foreach (ModNet.LoaderDownload loaderDownload in this._AdapterTest)
  2110. {
  2111. loaderDownload.OnFileFail(this);
  2112. }
  2113. }
  2114. finally
  2115. {
  2116. IEnumerator<ModNet.LoaderDownload> enumerator;
  2117. if (enumerator != null)
  2118. {
  2119. enumerator.Dispose();
  2120. }
  2121. }
  2122. }
  2123. // Token: 0x06000D25 RID: 3365 RVA: 0x0005987C File Offset: 0x00057A7C
  2124. public void Abort(ModNet.LoaderDownload CausedByTask)
  2125. {
  2126. this._AdapterTest.Remove(CausedByTask);
  2127. if (!Enumerable.Any<ModNet.LoaderDownload>(this._AdapterTest))
  2128. {
  2129. object invocationTest = this.m_InvocationTest;
  2130. ObjectFlowControl.CheckForSyncLockOnValueType(invocationTest);
  2131. lock (invocationTest)
  2132. {
  2133. if (this._ComparatorTest >= ModNet.NetState.Finish)
  2134. {
  2135. return;
  2136. }
  2137. this._ComparatorTest = ModNet.NetState.Error;
  2138. }
  2139. this.InterruptAndDelete();
  2140. }
  2141. }
  2142. // Token: 0x06000D26 RID: 3366 RVA: 0x000598F0 File Offset: 0x00057AF0
  2143. private void InterruptAndDelete()
  2144. {
  2145. int num;
  2146. int num4;
  2147. object obj;
  2148. try
  2149. {
  2150. IL_00:
  2151. ProjectData.ClearProjectError();
  2152. num = 1;
  2153. IL_07:
  2154. int num2 = 2;
  2155. if (!File.Exists(this.m_AuthenticationTest))
  2156. {
  2157. goto IL_23;
  2158. }
  2159. IL_16:
  2160. num2 = 3;
  2161. File.Delete(this.m_AuthenticationTest);
  2162. IL_23:
  2163. num2 = 4;
  2164. object visitorTest = ModNet.tokenTests.visitorTest;
  2165. ObjectFlowControl.CheckForSyncLockOnValueType(visitorTest);
  2166. lock (visitorTest)
  2167. {
  2168. ModNet.NetManagerClass tokenTests = ModNet.tokenTests;
  2169. ref int ptr = ref tokenTests._CollectionTest;
  2170. tokenTests._CollectionTest = checked(ptr - 1);
  2171. ModBase.Log(string.Format("[Download] {0}:状态 {1},剩余文件 {2}", this._AlgoTest, this._ComparatorTest, ModNet.tokenTests._CollectionTest), ModBase.LogLevel.Normal, "出现错误");
  2172. }
  2173. IL_96:
  2174. goto IL_F9;
  2175. IL_98:
  2176. int num3 = num4 + 1;
  2177. num4 = 0;
  2178. @switch(ICSharpCode.Decompiler.ILAst.ILLabel[], num3);
  2179. IL_BA:
  2180. goto IL_EE;
  2181. IL_BC:
  2182. num4 = num2;
  2183. @switch(ICSharpCode.Decompiler.ILAst.ILLabel[], num);
  2184. IL_CC:;
  2185. }
  2186. catch when (endfilter(obj is Exception & num != 0 & num4 == 0))
  2187. {
  2188. Exception ex = (Exception)obj2;
  2189. goto IL_BC;
  2190. }
  2191. IL_EE:
  2192. throw ProjectData.CreateProjectError(-2146828237);
  2193. IL_F9:
  2194. if (num4 != 0)
  2195. {
  2196. ProjectData.ClearProjectError();
  2197. }
  2198. }
  2199. // Token: 0x06000D27 RID: 3367 RVA: 0x00059A1C File Offset: 0x00057C1C
  2200. public void Finish(bool PrintLog = true)
  2201. {
  2202. object invocationTest = this.m_InvocationTest;
  2203. ObjectFlowControl.CheckForSyncLockOnValueType(invocationTest);
  2204. lock (invocationTest)
  2205. {
  2206. if (this._ComparatorTest >= ModNet.NetState.Finish)
  2207. {
  2208. return;
  2209. }
  2210. this._ComparatorTest = ModNet.NetState.Finish;
  2211. }
  2212. object visitorTest = ModNet.tokenTests.visitorTest;
  2213. ObjectFlowControl.CheckForSyncLockOnValueType(visitorTest);
  2214. lock (visitorTest)
  2215. {
  2216. ModNet.NetManagerClass tokenTests = ModNet.tokenTests;
  2217. ref int ptr = ref tokenTests._CollectionTest;
  2218. tokenTests._CollectionTest = checked(ptr - 1);
  2219. if (PrintLog)
  2220. {
  2221. ModBase.Log("[Download] " + this._AlgoTest + ":已完成,剩余文件 " + Conversions.ToString(ModNet.tokenTests._CollectionTest), ModBase.LogLevel.Normal, "出现错误");
  2222. }
  2223. }
  2224. try
  2225. {
  2226. foreach (ModNet.LoaderDownload loaderDownload in this._AdapterTest)
  2227. {
  2228. loaderDownload.OnFileFinish(this);
  2229. }
  2230. }
  2231. finally
  2232. {
  2233. IEnumerator<ModNet.LoaderDownload> enumerator;
  2234. if (enumerator != null)
  2235. {
  2236. enumerator.Dispose();
  2237. }
  2238. }
  2239. }
  2240. // Token: 0x040006BB RID: 1723
  2241. public ModBase.SafeList<ModNet.LoaderDownload> _AdapterTest;
  2242. // Token: 0x040006BC RID: 1724
  2243. public ModNet.NetSource[] facadeTest;
  2244. // Token: 0x040006BD RID: 1725
  2245. private int listTest;
  2246. // Token: 0x040006BE RID: 1726
  2247. public List<ModNet.NetSource> _MerchantTest;
  2248. // Token: 0x040006BF RID: 1727
  2249. public string m_AuthenticationTest;
  2250. // Token: 0x040006C0 RID: 1728
  2251. public string _AlgoTest;
  2252. // Token: 0x040006C1 RID: 1729
  2253. public ModNet.NetState _ComparatorTest;
  2254. // Token: 0x040006C2 RID: 1730
  2255. public List<Exception> _MappingTest;
  2256. // Token: 0x040006C3 RID: 1731
  2257. public ModNet.NetThread m_TokenizerTest;
  2258. // Token: 0x040006C4 RID: 1732
  2259. public long filterTest;
  2260. // Token: 0x040006C5 RID: 1733
  2261. public bool databaseTest;
  2262. // Token: 0x040006C6 RID: 1734
  2263. private Queue<byte> predicateTest;
  2264. // Token: 0x040006C7 RID: 1735
  2265. public long _PoolTest;
  2266. // Token: 0x040006C8 RID: 1736
  2267. private readonly object customerTest;
  2268. // Token: 0x040006C9 RID: 1737
  2269. public ModBase.FileChecker m_PageTest;
  2270. // Token: 0x040006CA RID: 1738
  2271. public bool _InterceptorTest;
  2272. // Token: 0x040006CB RID: 1739
  2273. private long m_ContainerTest;
  2274. // Token: 0x040006CC RID: 1740
  2275. private long paramsTest;
  2276. // Token: 0x040006CD RID: 1741
  2277. private long m_DispatcherTest;
  2278. // Token: 0x040006CE RID: 1742
  2279. public bool m_ProcessTest;
  2280. // Token: 0x040006CF RID: 1743
  2281. private int parameterTest;
  2282. // Token: 0x040006D0 RID: 1744
  2283. private long recordTest;
  2284. // Token: 0x040006D1 RID: 1745
  2285. public readonly object serviceTest;
  2286. // Token: 0x040006D2 RID: 1746
  2287. public readonly object m_InvocationTest;
  2288. // Token: 0x040006D3 RID: 1747
  2289. public readonly object _ProxyTest;
  2290. // Token: 0x040006D4 RID: 1748
  2291. public readonly object _MessageTest;
  2292. // Token: 0x040006D5 RID: 1749
  2293. public readonly int creatorTest;
  2294. }
  2295. // Token: 0x02000137 RID: 311
  2296. public class LoaderDownload : ModLoader.LoaderBase
  2297. {
  2298. // Token: 0x1700020B RID: 523
  2299. // (get) Token: 0x06000D2A RID: 3370 RVA: 0x00059B2C File Offset: 0x00057D2C
  2300. // (set) Token: 0x06000D2B RID: 3371 RVA: 0x000087ED File Offset: 0x000069ED
  2301. public override double Progress
  2302. {
  2303. get
  2304. {
  2305. double result;
  2306. if (base.State >= ModBase.LoadState.Finished)
  2307. {
  2308. result = 1.0;
  2309. }
  2310. else if (!Enumerable.Any<ModNet.NetFile>(this.Files))
  2311. {
  2312. result = 0.0;
  2313. }
  2314. else
  2315. {
  2316. result = this._Progress;
  2317. }
  2318. return result;
  2319. }
  2320. set
  2321. {
  2322. throw new Exception("文件下载不允许指定进度");
  2323. }
  2324. }
  2325. // Token: 0x1700020C RID: 524
  2326. // (get) Token: 0x06000D2C RID: 3372 RVA: 0x000087F9 File Offset: 0x000069F9
  2327. // (set) Token: 0x06000D2D RID: 3373 RVA: 0x00059B70 File Offset: 0x00057D70
  2328. public int FailCount
  2329. {
  2330. get
  2331. {
  2332. return this._FailCount;
  2333. }
  2334. set
  2335. {
  2336. int num2;
  2337. int num4;
  2338. object obj;
  2339. try
  2340. {
  2341. IL_00:
  2342. int num = 1;
  2343. this._FailCount = value;
  2344. IL_09:
  2345. num = 2;
  2346. if (base.State != ModBase.LoadState.Loading || (double)value < Math.Min(10000.0, Math.Max((double)this.FileRemain * 5.5, (double)ModNet.m_StateTests * 5.5 + 3.0)))
  2347. {
  2348. goto IL_11B;
  2349. }
  2350. IL_5C:
  2351. num = 3;
  2352. ModBase.Log("[Download] 由于同加载器中失败次数过多引发强制失败:连续失败了 " + Conversions.ToString(value) + " 次", ModBase.LogLevel.Debug, "出现错误");
  2353. IL_7E:
  2354. ProjectData.ClearProjectError();
  2355. num2 = 1;
  2356. IL_85:
  2357. num = 5;
  2358. List<Exception> list = new List<Exception>();
  2359. IL_8D:
  2360. num = 6;
  2361. IEnumerator<ModNet.NetFile> enumerator = this.Files.GetEnumerator();
  2362. while (enumerator.MoveNext())
  2363. {
  2364. ModNet.NetFile netFile = enumerator.Current;
  2365. IL_A7:
  2366. num = 7;
  2367. foreach (ModNet.NetSource netSource in netFile.facadeTest)
  2368. {
  2369. IL_BE:
  2370. num = 8;
  2371. if (netSource._ValTest != null)
  2372. {
  2373. IL_C9:
  2374. num = 9;
  2375. list.Add(netSource._ValTest);
  2376. IL_D9:
  2377. num = 10;
  2378. if (list.Count > 10)
  2379. {
  2380. goto IL_111;
  2381. }
  2382. }
  2383. IL_E6:
  2384. num = 12;
  2385. }
  2386. IL_F7:
  2387. num = 13;
  2388. continue;
  2389. IL_111:
  2390. num = 15;
  2391. this.OnFail(list);
  2392. goto IL_11B;
  2393. }
  2394. IL_103:
  2395. num = 14;
  2396. if (enumerator != null)
  2397. {
  2398. enumerator.Dispose();
  2399. goto IL_111;
  2400. }
  2401. goto IL_111;
  2402. IL_11B:
  2403. goto IL_1AD;
  2404. IL_120:
  2405. int num3 = num4 + 1;
  2406. num4 = 0;
  2407. @switch(ICSharpCode.Decompiler.ILAst.ILLabel[], num3);
  2408. IL_16E:
  2409. goto IL_1A2;
  2410. IL_170:
  2411. num4 = num;
  2412. @switch(ICSharpCode.Decompiler.ILAst.ILLabel[], num2);
  2413. IL_180:;
  2414. }
  2415. catch when (endfilter(obj is Exception & num2 != 0 & num4 == 0))
  2416. {
  2417. Exception ex = (Exception)obj2;
  2418. goto IL_170;
  2419. }
  2420. IL_1A2:
  2421. throw ProjectData.CreateProjectError(-2146828237);
  2422. IL_1AD:
  2423. if (num4 != 0)
  2424. {
  2425. ProjectData.ClearProjectError();
  2426. }
  2427. }
  2428. }
  2429. // Token: 0x06000D2E RID: 3374 RVA: 0x00059D50 File Offset: 0x00057F50
  2430. public void RefreshStat()
  2431. {
  2432. double num = 0.0;
  2433. double num2 = 0.0;
  2434. try
  2435. {
  2436. foreach (ModNet.NetFile netFile in this.Files)
  2437. {
  2438. if (netFile.m_ProcessTest)
  2439. {
  2440. num += netFile.Progress * 0.2;
  2441. num2 += 0.2;
  2442. }
  2443. else
  2444. {
  2445. num += netFile.Progress;
  2446. num2 += 1.0;
  2447. }
  2448. }
  2449. }
  2450. finally
  2451. {
  2452. IEnumerator<ModNet.NetFile> enumerator;
  2453. if (enumerator != null)
  2454. {
  2455. enumerator.Dispose();
  2456. }
  2457. }
  2458. if (num2 > 0.0)
  2459. {
  2460. num /= num2;
  2461. }
  2462. if (num < 1.0 && num > 0.0)
  2463. {
  2464. num = 2.0 * Math.Pow(num, 3.0) - 3.0 * Math.Pow(num, 2.0) + 2.0 * num;
  2465. }
  2466. this._Progress = num;
  2467. }
  2468. // Token: 0x06000D2F RID: 3375 RVA: 0x00059E58 File Offset: 0x00058058
  2469. public LoaderDownload(string Name, List<ModNet.NetFile> FileTasks)
  2470. {
  2471. this.FileRemainLock = RuntimeHelpers.GetObjectValue(new object());
  2472. this._Progress = 0.0;
  2473. this._FailCount = 0;
  2474. this.Name = Name;
  2475. this.Files = new ModBase.SafeList<ModNet.NetFile>(FileTasks);
  2476. }
  2477. // Token: 0x06000D30 RID: 3376 RVA: 0x00059EA8 File Offset: 0x000580A8
  2478. public override void Start(object Input = null, bool IsForceRestart = false)
  2479. {
  2480. if (Input != null)
  2481. {
  2482. this.Files = new ModBase.SafeList<ModNet.NetFile>((IEnumerable<ModNet.NetFile>)Input);
  2483. }
  2484. ModBase.SafeList<ModNet.NetFile> safeList = new ModBase.SafeList<ModNet.NetFile>();
  2485. checked
  2486. {
  2487. int num = this.Files.Count - 1;
  2488. int i = 0;
  2489. IL_8D:
  2490. while (i <= num)
  2491. {
  2492. int num2 = i + 1;
  2493. int num3 = this.Files.Count - 1;
  2494. for (int j = num2; j <= num3; j++)
  2495. {
  2496. if (Operators.CompareString(this.Files[i].m_AuthenticationTest, this.Files[j].m_AuthenticationTest, false) == 0)
  2497. {
  2498. IL_89:
  2499. i++;
  2500. goto IL_8D;
  2501. }
  2502. }
  2503. safeList.Add(this.Files[i]);
  2504. goto IL_89;
  2505. }
  2506. this.Files = safeList;
  2507. object fileRemainLock = this.FileRemainLock;
  2508. ObjectFlowControl.CheckForSyncLockOnValueType(fileRemainLock);
  2509. lock (fileRemainLock)
  2510. {
  2511. try
  2512. {
  2513. IEnumerator<ModNet.NetFile> enumerator = this.Files.GetEnumerator();
  2514. while (enumerator.MoveNext())
  2515. {
  2516. if (enumerator.Current._ComparatorTest != ModNet.NetState.Finish)
  2517. {
  2518. ref int ptr = ref this.FileRemain;
  2519. this.FileRemain = ptr + 1;
  2520. }
  2521. }
  2522. }
  2523. finally
  2524. {
  2525. IEnumerator<ModNet.NetFile> enumerator;
  2526. if (enumerator != null)
  2527. {
  2528. enumerator.Dispose();
  2529. }
  2530. }
  2531. }
  2532. base.State = ModBase.LoadState.Loading;
  2533. ModBase.RunInNewThread(delegate
  2534. {
  2535. try
  2536. {
  2537. ModNet.LoaderDownload._Closure$__13-1 CS$<>8__locals1 = new ModNet.LoaderDownload._Closure$__13-1(CS$<>8__locals1);
  2538. CS$<>8__locals1.$VB$Me = this;
  2539. if (!Enumerable.Any<ModNet.NetFile>(this.Files))
  2540. {
  2541. this.OnFinish();
  2542. }
  2543. else
  2544. {
  2545. try
  2546. {
  2547. foreach (ModNet.NetFile netFile in this.Files)
  2548. {
  2549. if (netFile == null)
  2550. {
  2551. throw new ArgumentException("存在空文件请求!");
  2552. }
  2553. foreach (ModNet.NetSource netSource in netFile.facadeTest)
  2554. {
  2555. if (!netSource.m_StructTest.StartsWithF("https://", true) && !netSource.m_StructTest.StartsWithF("http://", true))
  2556. {
  2557. netSource._ValTest = new ArgumentException("输入的下载链接不正确!");
  2558. netSource.candidateTest = true;
  2559. }
  2560. }
  2561. if (netFile.IsSourceFailed(true))
  2562. {
  2563. throw new ArgumentException("输入的下载链接不正确!");
  2564. }
  2565. if (!netFile.m_AuthenticationTest.ToLower().Contains(":\\"))
  2566. {
  2567. throw new ArgumentException("输入的本地文件地址不正确!");
  2568. }
  2569. if (netFile.m_AuthenticationTest.EndsWithF("\\", false))
  2570. {
  2571. throw new ArgumentException("请输入含文件名的完整文件路径!");
  2572. }
  2573. string fullName = new FileInfo(netFile.m_AuthenticationTest).Directory.FullName;
  2574. if (!Directory.Exists(fullName))
  2575. {
  2576. Directory.CreateDirectory(fullName);
  2577. }
  2578. }
  2579. }
  2580. finally
  2581. {
  2582. IEnumerator<ModNet.NetFile> enumerator2;
  2583. if (enumerator2 != null)
  2584. {
  2585. enumerator2.Dispose();
  2586. }
  2587. }
  2588. ModNet.tokenTests.Start(this);
  2589. List<string> list = new List<string>();
  2590. CS$<>8__locals1.$VB$Local_FoldersFinal = new List<string>();
  2591. if (Conversions.ToBoolean(Operators.NotObject(ModBase.m_IdentifierRepository.Get("SystemDebugSkipCopy", null))))
  2592. {
  2593. list.Add(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\.minecraft\\");
  2594. try
  2595. {
  2596. foreach (ModMinecraft.McFolder mcFolder in ModMinecraft.messageTests)
  2597. {
  2598. list.Add(mcFolder.Path);
  2599. }
  2600. }
  2601. finally
  2602. {
  2603. List<ModMinecraft.McFolder>.Enumerator enumerator3;
  2604. ((IDisposable)enumerator3).Dispose();
  2605. }
  2606. list = Enumerable.ToList<string>(Enumerable.Distinct<string>(list));
  2607. try
  2608. {
  2609. foreach (string text in list)
  2610. {
  2611. if (Operators.CompareString(text, ModMinecraft.m_ProxyTests, false) != 0 && Directory.Exists(text))
  2612. {
  2613. CS$<>8__locals1.$VB$Local_FoldersFinal.Add(text);
  2614. }
  2615. }
  2616. }
  2617. finally
  2618. {
  2619. List<string>.Enumerator enumerator4;
  2620. ((IDisposable)enumerator4).Dispose();
  2621. }
  2622. }
  2623. int num4 = (int)Math.Round(Math.Max(5.0, unchecked((double)this.Files.Count / 10.0 + 1.0)));
  2624. List<ModNet.NetFile> list2 = new List<ModNet.NetFile>();
  2625. try
  2626. {
  2627. foreach (ModNet.NetFile item in this.Files)
  2628. {
  2629. list2.Add(item);
  2630. if (list2.Count == num4)
  2631. {
  2632. ModNet.LoaderDownload._Closure$__13-0 CS$<>8__locals2 = new ModNet.LoaderDownload._Closure$__13-0(CS$<>8__locals2);
  2633. CS$<>8__locals2.$VB$NonLocal_$VB$Closure_2 = CS$<>8__locals1;
  2634. CS$<>8__locals2.$VB$Local_FilesToRun = new List<ModNet.NetFile>();
  2635. CS$<>8__locals2.$VB$Local_FilesToRun.AddRange(list2);
  2636. ModBase.RunInNewThread(delegate
  2637. {
  2638. CS$<>8__locals2.$VB$NonLocal_$VB$Closure_2.$VB$Me.StartCopy(CS$<>8__locals2.$VB$Local_FilesToRun, CS$<>8__locals2.$VB$NonLocal_$VB$Closure_2.$VB$Local_FoldersFinal);
  2639. }, "NetTask FileCopy " + Conversions.ToString(this.Uuid), ThreadPriority.Normal);
  2640. list2.Clear();
  2641. }
  2642. }
  2643. }
  2644. finally
  2645. {
  2646. IEnumerator<ModNet.NetFile> enumerator5;
  2647. if (enumerator5 != null)
  2648. {
  2649. enumerator5.Dispose();
  2650. }
  2651. }
  2652. if (Enumerable.Any<ModNet.NetFile>(list2))
  2653. {
  2654. ModNet.LoaderDownload._Closure$__13-2 CS$<>8__locals3 = new ModNet.LoaderDownload._Closure$__13-2(CS$<>8__locals3);
  2655. CS$<>8__locals3.$VB$NonLocal_$VB$Closure_3 = CS$<>8__locals1;
  2656. CS$<>8__locals3.$VB$Local_FilesToRun = new List<ModNet.NetFile>();
  2657. CS$<>8__locals3.$VB$Local_FilesToRun.AddRange(list2);
  2658. ModBase.RunInNewThread(delegate
  2659. {
  2660. CS$<>8__locals3.$VB$NonLocal_$VB$Closure_3.$VB$Me.StartCopy(CS$<>8__locals3.$VB$Local_FilesToRun, CS$<>8__locals3.$VB$NonLocal_$VB$Closure_3.$VB$Local_FoldersFinal);
  2661. }, "NetTask FileCopy " + Conversions.ToString(this.Uuid), ThreadPriority.Normal);
  2662. list2.Clear();
  2663. }
  2664. }
  2665. }
  2666. catch (Exception item2)
  2667. {
  2668. this.OnFail(new List<Exception>
  2669. {
  2670. item2
  2671. });
  2672. }
  2673. }, "NetTask " + Conversions.ToString(this.Uuid) + " Main", ThreadPriority.Normal);
  2674. }
  2675. }
  2676. // Token: 0x06000D31 RID: 3377 RVA: 0x0005A008 File Offset: 0x00058208
  2677. private void StartCopy(List<ModNet.NetFile> Files, List<string> FolderList)
  2678. {
  2679. checked
  2680. {
  2681. try
  2682. {
  2683. if (ModBase._TokenRepository)
  2684. {
  2685. ModBase.Log("[Download] 检查线程分配文件数:" + Conversions.ToString(Files.Count) + ",线程名:" + Thread.CurrentThread.Name, ModBase.LogLevel.Normal, "出现错误");
  2686. }
  2687. List<KeyValuePair<ModNet.NetFile, string>> list = new List<KeyValuePair<ModNet.NetFile, string>>();
  2688. try
  2689. {
  2690. foreach (ModNet.NetFile netFile in Files)
  2691. {
  2692. string text = null;
  2693. if (netFile.m_PageTest != null && ModMinecraft.messageTests != null && ModMinecraft.m_ProxyTests != null && netFile.m_PageTest.m_MockError && netFile.m_AuthenticationTest.StartsWithF(ModMinecraft.m_ProxyTests, false))
  2694. {
  2695. string str = netFile.m_AuthenticationTest.Replace(ModMinecraft.m_ProxyTests, "");
  2696. try
  2697. {
  2698. foreach (string str2 in FolderList)
  2699. {
  2700. string text2 = str2 + str;
  2701. if (netFile.m_PageTest.Check(text2) == null)
  2702. {
  2703. text = text2;
  2704. break;
  2705. }
  2706. }
  2707. }
  2708. finally
  2709. {
  2710. List<string>.Enumerator enumerator2;
  2711. ((IDisposable)enumerator2).Dispose();
  2712. }
  2713. }
  2714. object lockState = this.LockState;
  2715. ObjectFlowControl.CheckForSyncLockOnValueType(lockState);
  2716. lock (lockState)
  2717. {
  2718. if (text != null)
  2719. {
  2720. netFile._ComparatorTest = ModNet.NetState.WaitForCopy;
  2721. netFile.m_ProcessTest = true;
  2722. list.Add(new KeyValuePair<ModNet.NetFile, string>(netFile, text));
  2723. }
  2724. else
  2725. {
  2726. netFile._ComparatorTest = ModNet.NetState.WaitForDownload;
  2727. netFile.m_ProcessTest = false;
  2728. }
  2729. }
  2730. }
  2731. }
  2732. finally
  2733. {
  2734. List<ModNet.NetFile>.Enumerator enumerator;
  2735. ((IDisposable)enumerator).Dispose();
  2736. }
  2737. try
  2738. {
  2739. foreach (KeyValuePair<ModNet.NetFile, string> keyValuePair in list)
  2740. {
  2741. ModNet.NetFile key = keyValuePair.Key;
  2742. object lockState2 = this.LockState;
  2743. ObjectFlowControl.CheckForSyncLockOnValueType(lockState2);
  2744. lock (lockState2)
  2745. {
  2746. if (key._ComparatorTest > ModNet.NetState.WaitForCopy)
  2747. {
  2748. break;
  2749. }
  2750. }
  2751. string value = keyValuePair.Value;
  2752. int num = 0;
  2753. for (;;)
  2754. {
  2755. try
  2756. {
  2757. ModBase.Log("[Download] 复制已存在的文件(" + value + ")", ModBase.LogLevel.Normal, "出现错误");
  2758. ModBase.CopyFile(value, key.m_AuthenticationTest);
  2759. key.Finish(false);
  2760. break;
  2761. }
  2762. catch (Exception ex)
  2763. {
  2764. num++;
  2765. ModBase.Log(ex, string.Format("复制已存在的文件失败,重试第 {2} 次({0} -> {1})", value, key.m_AuthenticationTest, num), ModBase.LogLevel.Debug, "出现错误");
  2766. if (num >= 3)
  2767. {
  2768. key._ComparatorTest = ModNet.NetState.WaitForDownload;
  2769. key.m_ProcessTest = false;
  2770. break;
  2771. }
  2772. Thread.Sleep(200);
  2773. }
  2774. }
  2775. }
  2776. }
  2777. finally
  2778. {
  2779. List<KeyValuePair<ModNet.NetFile, string>>.Enumerator enumerator3;
  2780. ((IDisposable)enumerator3).Dispose();
  2781. }
  2782. }
  2783. catch (Exception ex2)
  2784. {
  2785. ModBase.Log(ex2, "下载已存在文件查找失败", ModBase.LogLevel.Feedback, "出现错误");
  2786. }
  2787. }
  2788. }
  2789. // Token: 0x06000D32 RID: 3378 RVA: 0x0005A368 File Offset: 0x00058568
  2790. public void OnFileFinish(ModNet.NetFile File)
  2791. {
  2792. object fileRemainLock = this.FileRemainLock;
  2793. ObjectFlowControl.CheckForSyncLockOnValueType(fileRemainLock);
  2794. lock (fileRemainLock)
  2795. {
  2796. ref int ptr = ref this.FileRemain;
  2797. this.FileRemain = checked(ptr - 1);
  2798. if (this.FileRemain > 0)
  2799. {
  2800. return;
  2801. }
  2802. }
  2803. this.OnFinish();
  2804. }
  2805. // Token: 0x06000D33 RID: 3379 RVA: 0x0005A3C8 File Offset: 0x000585C8
  2806. public void OnFinish()
  2807. {
  2808. base.RaisePreviewFinish();
  2809. object lockState = this.LockState;
  2810. ObjectFlowControl.CheckForSyncLockOnValueType(lockState);
  2811. lock (lockState)
  2812. {
  2813. if (base.State <= ModBase.LoadState.Loading)
  2814. {
  2815. base.State = ModBase.LoadState.Finished;
  2816. }
  2817. }
  2818. }
  2819. // Token: 0x06000D34 RID: 3380 RVA: 0x0005A420 File Offset: 0x00058620
  2820. public void OnFileFail(ModNet.NetFile File)
  2821. {
  2822. foreach (ModNet.NetSource netSource in File.facadeTest)
  2823. {
  2824. if (!Information.IsNothing(netSource._ValTest))
  2825. {
  2826. File._MappingTest.Add(netSource._ValTest);
  2827. }
  2828. }
  2829. this.OnFail(File._MappingTest);
  2830. }
  2831. // Token: 0x06000D35 RID: 3381 RVA: 0x0005A470 File Offset: 0x00058670
  2832. public void OnFail(List<Exception> ExList)
  2833. {
  2834. object lockState = this.LockState;
  2835. ObjectFlowControl.CheckForSyncLockOnValueType(lockState);
  2836. lock (lockState)
  2837. {
  2838. if (base.State > ModBase.LoadState.Loading)
  2839. {
  2840. return;
  2841. }
  2842. if (ExList == null || !Enumerable.Any<Exception>(ExList))
  2843. {
  2844. ExList = new List<Exception>
  2845. {
  2846. new Exception("未知错误!")
  2847. };
  2848. }
  2849. List<Exception> list = Enumerable.ToList<Exception>(Enumerable.Where<Exception>(ExList, (ModNet.LoaderDownload._Closure$__.$I18-0 == null) ? (ModNet.LoaderDownload._Closure$__.$I18-0 = ((Exception e) => !e.Message.Contains("(404)"))) : ModNet.LoaderDownload._Closure$__.$I18-0));
  2850. base.Error = (Enumerable.Any<Exception>(list) ? list[0] : ExList[0]);
  2851. try
  2852. {
  2853. foreach (ModNet.NetFile netFile in this.Files)
  2854. {
  2855. if (netFile._ComparatorTest == ModNet.NetState.Error)
  2856. {
  2857. base.Error = new Exception("文件下载失败:" + netFile.m_AuthenticationTest + "\r\n" + Enumerable.Select<ModNet.NetSource, string>(netFile.facadeTest, (ModNet.LoaderDownload._Closure$__.$I18-1 == null) ? (ModNet.LoaderDownload._Closure$__.$I18-1 = delegate(ModNet.NetSource s)
  2858. {
  2859. if (s._ValTest != null)
  2860. {
  2861. return s._ValTest.Message + "(" + s.m_StructTest + ")";
  2862. }
  2863. return s.m_StructTest;
  2864. }) : ModNet.LoaderDownload._Closure$__.$I18-1).Join("\r\n"), base.Error);
  2865. break;
  2866. }
  2867. }
  2868. }
  2869. finally
  2870. {
  2871. IEnumerator<ModNet.NetFile> enumerator;
  2872. if (enumerator != null)
  2873. {
  2874. enumerator.Dispose();
  2875. }
  2876. }
  2877. base.State = ModBase.LoadState.Failed;
  2878. }
  2879. try
  2880. {
  2881. foreach (ModNet.NetFile netFile2 in this.Files)
  2882. {
  2883. if (netFile2._ComparatorTest < ModNet.NetState.Merge)
  2884. {
  2885. netFile2._ComparatorTest = ModNet.NetState.Error;
  2886. }
  2887. }
  2888. }
  2889. finally
  2890. {
  2891. IEnumerator<ModNet.NetFile> enumerator2;
  2892. if (enumerator2 != null)
  2893. {
  2894. enumerator2.Dispose();
  2895. }
  2896. }
  2897. List<string> list2 = new List<string>();
  2898. try
  2899. {
  2900. foreach (Exception ex in ExList)
  2901. {
  2902. list2.Add(ModBase.GetExceptionDetail(ex, false));
  2903. }
  2904. }
  2905. finally
  2906. {
  2907. List<Exception>.Enumerator enumerator3;
  2908. ((IDisposable)enumerator3).Dispose();
  2909. }
  2910. ModBase.Log("[Download] " + Enumerable.ToArray<string>(Enumerable.Distinct<string>(list2)).Join("\r\n"), ModBase.LogLevel.Normal, "出现错误");
  2911. }
  2912. // Token: 0x06000D36 RID: 3382 RVA: 0x0005A6D4 File Offset: 0x000588D4
  2913. public override void Abort()
  2914. {
  2915. object lockState = this.LockState;
  2916. ObjectFlowControl.CheckForSyncLockOnValueType(lockState);
  2917. lock (lockState)
  2918. {
  2919. if (base.State >= ModBase.LoadState.Finished)
  2920. {
  2921. return;
  2922. }
  2923. base.State = ModBase.LoadState.Aborted;
  2924. }
  2925. ModBase.Log("[Download] " + this.Name + " 已取消!", ModBase.LogLevel.Normal, "出现错误");
  2926. try
  2927. {
  2928. foreach (ModNet.NetFile netFile in this.Files)
  2929. {
  2930. netFile.Abort(this);
  2931. }
  2932. }
  2933. finally
  2934. {
  2935. IEnumerator<ModNet.NetFile> enumerator;
  2936. if (enumerator != null)
  2937. {
  2938. enumerator.Dispose();
  2939. }
  2940. }
  2941. }
  2942. // Token: 0x040006D6 RID: 1750
  2943. public ModBase.SafeList<ModNet.NetFile> Files;
  2944. // Token: 0x040006D7 RID: 1751
  2945. private int FileRemain;
  2946. // Token: 0x040006D8 RID: 1752
  2947. private readonly object FileRemainLock;
  2948. // Token: 0x040006D9 RID: 1753
  2949. private double _Progress;
  2950. // Token: 0x040006DA RID: 1754
  2951. private int _FailCount;
  2952. }
  2953. // Token: 0x0200013C RID: 316
  2954. public class NetManagerClass
  2955. {
  2956. // Token: 0x06000D45 RID: 3397 RVA: 0x0005ABA4 File Offset: 0x00058DA4
  2957. public NetManagerClass()
  2958. {
  2959. this.initializerTest = new Dictionary<string, ModNet.NetFile>();
  2960. this._SingletonTest = RuntimeHelpers.GetObjectValue(new object());
  2961. this.regTest = new ModBase.SafeList<ModNet.LoaderDownload>();
  2962. this.productTest = 0L;
  2963. this.m_ListenerTest = RuntimeHelpers.GetObjectValue(new object());
  2964. this._CollectionTest = 0;
  2965. this.visitorTest = RuntimeHelpers.GetObjectValue(new object());
  2966. this._ValueTest = 0L;
  2967. this._ObjectTest = new List<long>();
  2968. this.m_BridgeTest = 0L;
  2969. this.reponseTest = ModBase.GetUuid();
  2970. this.m_ExceptionTest = false;
  2971. this.m_UtilsTest = false;
  2972. }
  2973. // Token: 0x06000D46 RID: 3398 RVA: 0x000088E4 File Offset: 0x00006AE4
  2974. public long PrintMapper()
  2975. {
  2976. return this.productTest;
  2977. }
  2978. // Token: 0x06000D47 RID: 3399 RVA: 0x0005AC58 File Offset: 0x00058E58
  2979. public void InterruptMapper(long value)
  2980. {
  2981. object listenerTest = this.m_ListenerTest;
  2982. ObjectFlowControl.CheckForSyncLockOnValueType(listenerTest);
  2983. lock (listenerTest)
  2984. {
  2985. this.productTest = value;
  2986. }
  2987. }
  2988. // Token: 0x06000D48 RID: 3400 RVA: 0x0005ACA0 File Offset: 0x00058EA0
  2989. private void RefreshStat()
  2990. {
  2991. checked
  2992. {
  2993. try
  2994. {
  2995. long num = ModBase.GetTimeTick() - this._GlobalTest;
  2996. ref long ptr = ref this._GlobalTest;
  2997. this._GlobalTest = ptr + num;
  2998. double a = Math.Max(0.0, (double)(this.PrintMapper() - this._ValueTest) / ((double)num / 1000.0));
  2999. this._ObjectTest.Insert(0, (long)Math.Round(a));
  3000. if (this._ObjectTest.Count >= 31)
  3001. {
  3002. this._ObjectTest.RemoveAt(30);
  3003. }
  3004. this._ValueTest = this.PrintMapper();
  3005. long num2 = 0L;
  3006. long num3 = 0L;
  3007. int num4 = this._ObjectTest.Count;
  3008. try
  3009. {
  3010. foreach (long num5 in this._ObjectTest)
  3011. {
  3012. num2 += num5 * unchecked((long)num4);
  3013. num3 += unchecked((long)num4);
  3014. num4--;
  3015. }
  3016. }
  3017. finally
  3018. {
  3019. List<long>.Enumerator enumerator;
  3020. ((IDisposable)enumerator).Dispose();
  3021. }
  3022. this.m_BridgeTest = (long)Math.Round((num3 > 0L) ? ((double)num2 / (double)num3) : 0.0);
  3023. long num6 = 0L;
  3024. if (this._ObjectTest.Count >= 10)
  3025. {
  3026. num6 = (long)Math.Round(unchecked(Enumerable.Average(Enumerable.Take<long>(this._ObjectTest, 10)) * 0.85));
  3027. }
  3028. if (num6 > ModNet.callbackTests)
  3029. {
  3030. ModNet.callbackTests = num6;
  3031. ModBase.Log("[Download] 速度下限已提升到 " + ModBase.GetString(num6), ModBase.LogLevel.Normal, "出现错误");
  3032. }
  3033. try
  3034. {
  3035. foreach (ModNet.LoaderDownload loaderDownload in this.regTest)
  3036. {
  3037. loaderDownload.RefreshStat();
  3038. }
  3039. }
  3040. finally
  3041. {
  3042. IEnumerator<ModNet.LoaderDownload> enumerator2;
  3043. if (enumerator2 != null)
  3044. {
  3045. enumerator2.Dispose();
  3046. }
  3047. }
  3048. }
  3049. catch (Exception ex)
  3050. {
  3051. ModBase.Log(ex, "刷新下载公开属性失败", ModBase.LogLevel.Debug, "出现错误");
  3052. }
  3053. }
  3054. }
  3055. // Token: 0x06000D49 RID: 3401 RVA: 0x0005AECC File Offset: 0x000590CC
  3056. private void StartManager()
  3057. {
  3058. ModNet.NetManagerClass._Closure$__17-0 CS$<>8__locals1 = new ModNet.NetManagerClass._Closure$__17-0(CS$<>8__locals1);
  3059. checked
  3060. {
  3061. if (!this.m_ExceptionTest)
  3062. {
  3063. this.m_ExceptionTest = true;
  3064. CS$<>8__locals1.$VB$Local_ThreadStarter = delegate(int Id)
  3065. {
  3066. try
  3067. {
  3068. for (;;)
  3069. {
  3070. IL_00:
  3071. Thread.Sleep(20);
  3072. object singletonTest = this._SingletonTest;
  3073. ObjectFlowControl.CheckForSyncLockOnValueType(singletonTest);
  3074. List<ModNet.NetFile> list;
  3075. lock (singletonTest)
  3076. {
  3077. if (Id == 0 && this._CollectionTest == 0 && Enumerable.Any<KeyValuePair<string, ModNet.NetFile>>(this.initializerTest))
  3078. {
  3079. this.initializerTest.Clear();
  3080. }
  3081. list = Enumerable.ToList<ModNet.NetFile>(this.initializerTest.Values);
  3082. }
  3083. List<ModNet.NetFile> list2 = new List<ModNet.NetFile>();
  3084. List<ModNet.NetFile> list3 = new List<ModNet.NetFile>();
  3085. try
  3086. {
  3087. foreach (ModNet.NetFile netFile in list)
  3088. {
  3089. if (netFile.creatorTest % 2 != Id)
  3090. {
  3091. if (netFile._ComparatorTest == ModNet.NetState.WaitForDownload)
  3092. {
  3093. list2.Add(netFile);
  3094. }
  3095. else if (netFile._ComparatorTest < ModNet.NetState.Merge)
  3096. {
  3097. list3.Add(netFile);
  3098. }
  3099. }
  3100. }
  3101. }
  3102. finally
  3103. {
  3104. List<ModNet.NetFile>.Enumerator enumerator;
  3105. ((IDisposable)enumerator).Dispose();
  3106. }
  3107. try
  3108. {
  3109. foreach (ModNet.NetFile netFile2 in list2)
  3110. {
  3111. if (ModNet._ConfigurationTests >= ModNet.m_StateTests)
  3112. {
  3113. goto IL_00;
  3114. }
  3115. ModNet.NetThread netThread = netFile2.TryBeginThread();
  3116. if (netThread != null && netThread.Source.m_StructTest.Contains("bmclapi"))
  3117. {
  3118. Thread.Sleep(70);
  3119. }
  3120. }
  3121. }
  3122. finally
  3123. {
  3124. List<ModNet.NetFile>.Enumerator enumerator2;
  3125. ((IDisposable)enumerator2).Dispose();
  3126. }
  3127. if (this.m_BridgeTest < ModNet.callbackTests)
  3128. {
  3129. try
  3130. {
  3131. foreach (ModNet.NetFile netFile3 in list3)
  3132. {
  3133. if (ModNet._ConfigurationTests >= ModNet.m_StateTests)
  3134. {
  3135. break;
  3136. }
  3137. int num = 0;
  3138. int num2 = 0;
  3139. if (netFile3.m_TokenizerTest != null)
  3140. {
  3141. try
  3142. {
  3143. foreach (ModNet.NetThread netThread2 in Enumerable.ToList<ModNet.NetThread>(netFile3.m_TokenizerTest))
  3144. {
  3145. if (netThread2.infoTest < ModNet.NetState.Download)
  3146. {
  3147. num++;
  3148. }
  3149. else if (netThread2.infoTest == ModNet.NetState.Download)
  3150. {
  3151. num2++;
  3152. }
  3153. }
  3154. }
  3155. finally
  3156. {
  3157. List<ModNet.NetThread>.Enumerator enumerator4;
  3158. ((IDisposable)enumerator4).Dispose();
  3159. }
  3160. }
  3161. if (num <= num2)
  3162. {
  3163. ModNet.NetThread netThread3 = netFile3.TryBeginThread();
  3164. if (netThread3 != null && netThread3.Source.m_StructTest.Contains("bmclapi"))
  3165. {
  3166. Thread.Sleep(70);
  3167. }
  3168. }
  3169. }
  3170. }
  3171. finally
  3172. {
  3173. List<ModNet.NetFile>.Enumerator enumerator3;
  3174. ((IDisposable)enumerator3).Dispose();
  3175. }
  3176. }
  3177. }
  3178. }
  3179. catch (Exception ex)
  3180. {
  3181. ModBase.Log(ex, string.Format("下载管理启动线程 {0} 出错", Id), ModBase.LogLevel.Assert, "出现错误");
  3182. }
  3183. };
  3184. ModBase.RunInNewThread(delegate
  3185. {
  3186. CS$<>8__locals1.$VB$Local_ThreadStarter(0);
  3187. }, "NetManager ThreadStarter 0", ThreadPriority.Normal);
  3188. ModBase.RunInNewThread(delegate
  3189. {
  3190. CS$<>8__locals1.$VB$Local_ThreadStarter(1);
  3191. }, "NetManager ThreadStarter 1", ThreadPriority.Normal);
  3192. ModBase.RunInNewThread(delegate
  3193. {
  3194. try
  3195. {
  3196. ModNet.m_ConsumerTests = ModBase.GetTimeTick();
  3197. for (;;)
  3198. {
  3199. long timeTick = ModBase.GetTimeTick();
  3200. long num = timeTick;
  3201. if (ModNet.m_TemplateTests > 0L)
  3202. {
  3203. ModNet.m_MethodTests = (long)Math.Round(unchecked((double)ModNet.m_TemplateTests / 1000.0 * (double)(checked(timeTick - ModNet.m_ConsumerTests))));
  3204. }
  3205. ModNet.m_ConsumerTests = timeTick;
  3206. this.RefreshStat();
  3207. while (ModBase.GetTimeTick() - num < 80L)
  3208. {
  3209. Thread.Sleep(10);
  3210. }
  3211. }
  3212. }
  3213. catch (Exception ex)
  3214. {
  3215. ModBase.Log(ex, "下载管理刷新线程出错", ModBase.LogLevel.Assert, "出现错误");
  3216. }
  3217. }, "NetManager StatRefresher", ThreadPriority.Normal);
  3218. }
  3219. }
  3220. }
  3221. // Token: 0x06000D4A RID: 3402 RVA: 0x0005AF4C File Offset: 0x0005914C
  3222. public void Start(ModNet.LoaderDownload Task)
  3223. {
  3224. this.StartManager();
  3225. if (!this.m_UtilsTest)
  3226. {
  3227. try
  3228. {
  3229. ModBase.DeleteDirectory(ModBase.m_DecoratorRepository + "Download", false);
  3230. }
  3231. catch (Exception ex)
  3232. {
  3233. ModBase.Log(ex, "清理下载缓存失败", ModBase.LogLevel.Debug, "出现错误");
  3234. }
  3235. this.m_UtilsTest = true;
  3236. }
  3237. Directory.CreateDirectory(ModBase.m_DecoratorRepository + "Download");
  3238. object singletonTest = this._SingletonTest;
  3239. ObjectFlowControl.CheckForSyncLockOnValueType(singletonTest);
  3240. checked
  3241. {
  3242. lock (singletonTest)
  3243. {
  3244. int num = Task.Files.Count - 1;
  3245. for (int i = 0; i <= num; i++)
  3246. {
  3247. ModNet.NetFile netFile = Task.Files[i];
  3248. if (this.initializerTest.ContainsKey(netFile.m_AuthenticationTest))
  3249. {
  3250. if (this.initializerTest[netFile.m_AuthenticationTest]._ComparatorTest >= ModNet.NetState.Finish)
  3251. {
  3252. netFile._AdapterTest.Add(Task);
  3253. this.initializerTest[netFile.m_AuthenticationTest] = netFile;
  3254. object obj = this.visitorTest;
  3255. ObjectFlowControl.CheckForSyncLockOnValueType(obj);
  3256. lock (obj)
  3257. {
  3258. ref int ptr = ref this._CollectionTest;
  3259. this._CollectionTest = ptr + 1;
  3260. if (ModBase._TokenRepository)
  3261. {
  3262. ModBase.Log("[Download] " + netFile._AlgoTest + ":已替换列表,剩余文件 " + Conversions.ToString(this._CollectionTest), ModBase.LogLevel.Normal, "出现错误");
  3263. }
  3264. goto IL_215;
  3265. }
  3266. }
  3267. netFile = this.initializerTest[netFile.m_AuthenticationTest];
  3268. netFile._AdapterTest.Add(Task);
  3269. }
  3270. else
  3271. {
  3272. netFile._AdapterTest.Add(Task);
  3273. this.initializerTest.Add(netFile.m_AuthenticationTest, netFile);
  3274. object obj2 = this.visitorTest;
  3275. ObjectFlowControl.CheckForSyncLockOnValueType(obj2);
  3276. lock (obj2)
  3277. {
  3278. ref int ptr = ref this._CollectionTest;
  3279. this._CollectionTest = ptr + 1;
  3280. if (ModBase._TokenRepository)
  3281. {
  3282. ModBase.Log("[Download] " + netFile._AlgoTest + ":已加入列表,剩余文件 " + Conversions.ToString(this._CollectionTest), ModBase.LogLevel.Normal, "出现错误");
  3283. }
  3284. }
  3285. }
  3286. IL_215:
  3287. Task.Files[i] = netFile;
  3288. }
  3289. }
  3290. this.regTest.Add(Task);
  3291. }
  3292. }
  3293. // Token: 0x040006E4 RID: 1764
  3294. public Dictionary<string, ModNet.NetFile> initializerTest;
  3295. // Token: 0x040006E5 RID: 1765
  3296. public readonly object _SingletonTest;
  3297. // Token: 0x040006E6 RID: 1766
  3298. public ModBase.SafeList<ModNet.LoaderDownload> regTest;
  3299. // Token: 0x040006E7 RID: 1767
  3300. private long productTest;
  3301. // Token: 0x040006E8 RID: 1768
  3302. private readonly object m_ListenerTest;
  3303. // Token: 0x040006E9 RID: 1769
  3304. public int _CollectionTest;
  3305. // Token: 0x040006EA RID: 1770
  3306. public readonly object visitorTest;
  3307. // Token: 0x040006EB RID: 1771
  3308. private long _ValueTest;
  3309. // Token: 0x040006EC RID: 1772
  3310. private List<long> _ObjectTest;
  3311. // Token: 0x040006ED RID: 1773
  3312. public long m_BridgeTest;
  3313. // Token: 0x040006EE RID: 1774
  3314. public readonly int reponseTest;
  3315. // Token: 0x040006EF RID: 1775
  3316. private long _GlobalTest;
  3317. // Token: 0x040006F0 RID: 1776
  3318. private bool m_ExceptionTest;
  3319. // Token: 0x040006F1 RID: 1777
  3320. private bool m_UtilsTest;
  3321. }
  3322. }
  3323. }