MyImage.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. using System;
  2. using System.IO;
  3. using System.Net;
  4. using System.Threading;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using Microsoft.VisualBasic;
  8. using Microsoft.VisualBasic.CompilerServices;
  9. namespace PCL
  10. {
  11. // Token: 0x0200003E RID: 62
  12. public class MyImage : Image
  13. {
  14. // Token: 0x0600014F RID: 335 RVA: 0x00012840 File Offset: 0x00010A40
  15. public MyImage()
  16. {
  17. base.Initialized += delegate(object sender, EventArgs e)
  18. {
  19. this.Load();
  20. };
  21. this.exporter = new TimeSpan(7, 0, 0, 0);
  22. this._Worker = "";
  23. this.m_Server = null;
  24. this._Resolver = "pack://application:,,,/images/Icons/NoIcon.png";
  25. this._Status = null;
  26. }
  27. // Token: 0x17000017 RID: 23
  28. // (get) Token: 0x06000150 RID: 336 RVA: 0x00002CD8 File Offset: 0x00000ED8
  29. // (set) Token: 0x06000151 RID: 337 RVA: 0x00002CEA File Offset: 0x00000EEA
  30. public bool EnableCache
  31. {
  32. get
  33. {
  34. return Conversions.ToBoolean(base.GetValue(MyImage._Importer));
  35. }
  36. set
  37. {
  38. base.SetValue(MyImage._Importer, value);
  39. }
  40. }
  41. // Token: 0x17000018 RID: 24
  42. // (get) Token: 0x06000152 RID: 338 RVA: 0x00002CFD File Offset: 0x00000EFD
  43. // (set) Token: 0x06000153 RID: 339 RVA: 0x00002D05 File Offset: 0x00000F05
  44. public new string Source
  45. {
  46. get
  47. {
  48. return this._Worker;
  49. }
  50. set
  51. {
  52. if (Operators.CompareString(value, "", false) == 0)
  53. {
  54. value = null;
  55. }
  56. if (Operators.CompareString(this._Worker, value, false) != 0)
  57. {
  58. this._Worker = value;
  59. if (base.IsInitialized)
  60. {
  61. this.Load();
  62. }
  63. }
  64. }
  65. }
  66. // Token: 0x17000019 RID: 25
  67. // (get) Token: 0x06000154 RID: 340 RVA: 0x00002D3C File Offset: 0x00000F3C
  68. // (set) Token: 0x06000155 RID: 341 RVA: 0x00002D44 File Offset: 0x00000F44
  69. public string FallbackSource
  70. {
  71. get
  72. {
  73. return this.m_Server;
  74. }
  75. set
  76. {
  77. this.m_Server = value;
  78. }
  79. }
  80. // Token: 0x06000156 RID: 342 RVA: 0x00002D4D File Offset: 0x00000F4D
  81. public string RevertParser()
  82. {
  83. return this._Resolver;
  84. }
  85. // Token: 0x06000157 RID: 343 RVA: 0x00002D55 File Offset: 0x00000F55
  86. public void RunBroadcaster(string value)
  87. {
  88. this._Resolver = value;
  89. }
  90. // Token: 0x06000158 RID: 344 RVA: 0x00002D5E File Offset: 0x00000F5E
  91. public string ManageBroadcaster()
  92. {
  93. return this._Status;
  94. }
  95. // Token: 0x06000159 RID: 345 RVA: 0x0001289C File Offset: 0x00010A9C
  96. public void SetBroadcaster(string value)
  97. {
  98. if (Operators.CompareString(value, "", false) == 0)
  99. {
  100. value = null;
  101. }
  102. if (Operators.CompareString(this._Status, value, false) != 0)
  103. {
  104. this._Status = value;
  105. try
  106. {
  107. MyBitmap Bitmap = (value == null) ? null : new MyBitmap(value);
  108. ModBase.RunInUiWait(delegate()
  109. {
  110. this.Source = Bitmap;
  111. });
  112. }
  113. catch (Exception ex)
  114. {
  115. ModBase.Log(ex, string.Format("加载图片失败({0})", value), ModBase.LogLevel.Debug, "出现错误");
  116. try
  117. {
  118. if (value.StartsWithF(ModBase.m_DecoratorRepository, false) && File.Exists(value))
  119. {
  120. File.Delete(value);
  121. }
  122. }
  123. catch (Exception ex2)
  124. {
  125. }
  126. }
  127. }
  128. }
  129. // Token: 0x0600015A RID: 346 RVA: 0x00012970 File Offset: 0x00010B70
  130. private void Load()
  131. {
  132. MyImage._Closure$__24-0 CS$<>8__locals1 = new MyImage._Closure$__24-0(CS$<>8__locals1);
  133. CS$<>8__locals1.$VB$Me = this;
  134. if (this.Source == null)
  135. {
  136. this.SetBroadcaster(null);
  137. return;
  138. }
  139. if (!this.Source.StartsWithF("http", false))
  140. {
  141. this.SetBroadcaster(this.Source);
  142. return;
  143. }
  144. CS$<>8__locals1.$VB$Local_Url = this.Source;
  145. CS$<>8__locals1.$VB$Local_Retried = false;
  146. CS$<>8__locals1.$VB$Local_TempPath = MyImage.GetTempPath(CS$<>8__locals1.$VB$Local_Url);
  147. CS$<>8__locals1.$VB$Local_TempFile = new FileInfo(CS$<>8__locals1.$VB$Local_TempPath);
  148. CS$<>8__locals1.$VB$Local_EnableCache = this.EnableCache;
  149. if (CS$<>8__locals1.$VB$Local_EnableCache && CS$<>8__locals1.$VB$Local_TempFile.Exists)
  150. {
  151. this.SetBroadcaster(CS$<>8__locals1.$VB$Local_TempPath);
  152. if (DateTime.Now - CS$<>8__locals1.$VB$Local_TempFile.LastWriteTime < this.exporter)
  153. {
  154. return;
  155. }
  156. }
  157. ModBase.RunInNewThread(delegate
  158. {
  159. MyImage._Closure$__24-1 CS$<>8__locals2 = new MyImage._Closure$__24-1(CS$<>8__locals2);
  160. CS$<>8__locals2.$VB$NonLocal_$VB$Closure_2 = CS$<>8__locals1;
  161. CS$<>8__locals2.$VB$Local_TempDownloadingPath = null;
  162. try
  163. {
  164. IL_15:
  165. CS$<>8__locals1.$VB$Me.SetBroadcaster(CS$<>8__locals1.$VB$Me.RevertParser());
  166. CS$<>8__locals2.$VB$Local_TempDownloadingPath = CS$<>8__locals1.$VB$Local_TempPath + Conversions.ToString(ModBase.RandomInteger(0, 10000000));
  167. Directory.CreateDirectory(ModBase.GetPathFromFullPath(CS$<>8__locals1.$VB$Local_TempPath));
  168. using (WebClient webClient = new WebClient())
  169. {
  170. webClient.DownloadFile(CS$<>8__locals1.$VB$Local_Url, CS$<>8__locals2.$VB$Local_TempDownloadingPath);
  171. }
  172. if (Operators.CompareString(CS$<>8__locals1.$VB$Local_Url, CS$<>8__locals1.$VB$Me.Source, false) != 0 && Operators.CompareString(CS$<>8__locals1.$VB$Local_Url, CS$<>8__locals1.$VB$Me.FallbackSource, false) != 0)
  173. {
  174. File.Delete(CS$<>8__locals2.$VB$Local_TempDownloadingPath);
  175. }
  176. else if (CS$<>8__locals1.$VB$Local_EnableCache)
  177. {
  178. if (File.Exists(CS$<>8__locals1.$VB$Local_TempPath))
  179. {
  180. File.Delete(CS$<>8__locals1.$VB$Local_TempPath);
  181. }
  182. FileSystem.Rename(CS$<>8__locals2.$VB$Local_TempDownloadingPath, CS$<>8__locals1.$VB$Local_TempPath);
  183. ModBase.RunInUi((CS$<>8__locals1.$I1 == null) ? (CS$<>8__locals1.$I1 = delegate()
  184. {
  185. CS$<>8__locals1.$VB$Me.SetBroadcaster(CS$<>8__locals1.$VB$Local_TempPath);
  186. }) : CS$<>8__locals1.$I1, false);
  187. }
  188. else
  189. {
  190. ModBase.RunInUiWait(delegate()
  191. {
  192. CS$<>8__locals2.$VB$NonLocal_$VB$Closure_2.$VB$Me.SetBroadcaster(CS$<>8__locals2.$VB$Local_TempDownloadingPath);
  193. });
  194. File.Delete(CS$<>8__locals2.$VB$Local_TempDownloadingPath);
  195. }
  196. }
  197. catch (Exception ex)
  198. {
  199. try
  200. {
  201. if (CS$<>8__locals1.$VB$Local_TempPath != null)
  202. {
  203. File.Delete(CS$<>8__locals1.$VB$Local_TempPath);
  204. }
  205. if (CS$<>8__locals2.$VB$Local_TempDownloadingPath != null)
  206. {
  207. File.Delete(CS$<>8__locals2.$VB$Local_TempDownloadingPath);
  208. }
  209. }
  210. catch (Exception ex2)
  211. {
  212. }
  213. if (!CS$<>8__locals1.$VB$Local_Retried)
  214. {
  215. ModBase.Log(ex, string.Format("下载图片可重试地失败({0})", CS$<>8__locals1.$VB$Local_Url), ModBase.LogLevel.Developer, "出现错误");
  216. CS$<>8__locals1.$VB$Local_Retried = true;
  217. CS$<>8__locals1.$VB$Local_Url = (CS$<>8__locals1.$VB$Me.FallbackSource ?? CS$<>8__locals1.$VB$Me.Source);
  218. if (CS$<>8__locals1.$VB$Local_Url == null)
  219. {
  220. CS$<>8__locals1.$VB$Me.SetBroadcaster(null);
  221. }
  222. else
  223. {
  224. if (CS$<>8__locals1.$VB$Local_Url.StartsWithF("http", false))
  225. {
  226. CS$<>8__locals1.$VB$Local_TempPath = MyImage.GetTempPath(CS$<>8__locals1.$VB$Local_Url);
  227. CS$<>8__locals1.$VB$Local_TempFile = new FileInfo(CS$<>8__locals1.$VB$Local_TempPath);
  228. if (CS$<>8__locals1.$VB$Local_EnableCache && CS$<>8__locals1.$VB$Local_TempFile.Exists)
  229. {
  230. CS$<>8__locals1.$VB$Me.SetBroadcaster(CS$<>8__locals1.$VB$Local_TempPath);
  231. if (DateTime.Now - CS$<>8__locals1.$VB$Local_TempFile.CreationTime < CS$<>8__locals1.$VB$Me.exporter)
  232. {
  233. return;
  234. }
  235. }
  236. if (Operators.CompareString(CS$<>8__locals1.$VB$Me.Source, CS$<>8__locals1.$VB$Local_Url, false) == 0)
  237. {
  238. Thread.Sleep(1000);
  239. }
  240. goto IL_15;
  241. }
  242. CS$<>8__locals1.$VB$Me.SetBroadcaster(CS$<>8__locals1.$VB$Local_Url);
  243. }
  244. }
  245. else
  246. {
  247. ModBase.Log(ex, string.Format("下载图片失败({0})", CS$<>8__locals1.$VB$Local_Url), ModBase.LogLevel.Hint, "出现错误");
  248. }
  249. }
  250. }, "MyImage PicLoader " + Conversions.ToString(ModBase.GetUuid()) + "#", ThreadPriority.BelowNormal);
  251. }
  252. // Token: 0x0600015B RID: 347 RVA: 0x00002D66 File Offset: 0x00000F66
  253. public static string GetTempPath(string Url)
  254. {
  255. return string.Format("{0}MyImage\\{1}.png", ModBase.m_DecoratorRepository, ModBase.GetHash(Url));
  256. }
  257. // Token: 0x04000084 RID: 132
  258. public TimeSpan exporter;
  259. // Token: 0x04000085 RID: 133
  260. public static readonly DependencyProperty _Importer = DependencyProperty.Register("EnableCache", typeof(bool), typeof(MyImage), new PropertyMetadata(true));
  261. // Token: 0x04000086 RID: 134
  262. private string _Worker;
  263. // Token: 0x04000087 RID: 135
  264. public static readonly DependencyProperty connection = DependencyProperty.Register("Source", typeof(string), typeof(MyImage), new PropertyMetadata(delegate(DependencyObject sender, DependencyPropertyChangedEventArgs e)
  265. {
  266. if (sender != null)
  267. {
  268. ((MyImage)sender).Source = e.NewValue.ToString();
  269. }
  270. }));
  271. // Token: 0x04000088 RID: 136
  272. private string m_Server;
  273. // Token: 0x04000089 RID: 137
  274. private string _Resolver;
  275. // Token: 0x0400008A RID: 138
  276. private string _Status;
  277. }
  278. }