ModMain.vb 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  1. Imports System.Windows.Interop
  2. Imports System.Windows.Threading
  3. Public Module ModMain
  4. #Region "弹出提示"
  5. ''' <summary>
  6. ''' 提示信息的种类。
  7. ''' 该枚举在自定义事件中使用,是公开 API 的一部分。
  8. ''' </summary>
  9. Public Enum HintType
  10. Blue
  11. Green
  12. Red
  13. End Enum
  14. Private Structure HintMessage
  15. Public Text As String
  16. Public Type As HintType
  17. Public Log As Boolean
  18. End Structure
  19. ''' <summary>
  20. ''' 等待弹出的提示列表。以 {String, HintType, Log As Boolean} 形式存储为数组。
  21. ''' </summary>
  22. Private HintWaiting As SafeList(Of HintMessage) = If(HintWaiting, New SafeList(Of HintMessage))
  23. ''' <summary>
  24. ''' 在窗口左下角弹出提示文本。
  25. ''' </summary>
  26. Public Sub Hint(Text As String, Optional Type As HintType = HintType.Blue, Optional Log As Boolean = True)
  27. If HintWaiting Is Nothing Then HintWaiting = New SafeList(Of HintMessage)
  28. HintWaiting.Add(New HintMessage With {.Text = If(Text, ""), .Type = Type, .Log = Log})
  29. End Sub
  30. Private Sub HintTick()
  31. Try
  32. 'Tag 存储了:{ 是否可以重用, Uuid }
  33. If Not HintWaiting.Any() Then Return
  34. Do While HintWaiting.Any
  35. ''清除空提示
  36. 'If IsNothing(HintWaiting(0)) OrElse IsNothing(HintWaiting(0)(0)) Then
  37. ' HintWaiting.RemoveAt(0)
  38. ' Continue Do
  39. 'End If
  40. Dim CurrentHint = HintWaiting(0)
  41. '去回车
  42. CurrentHint.Text = CurrentHint.Text.Replace(vbCrLf, " ").Replace(vbCr, " ").Replace(vbLf, " ")
  43. '超量提示直接忽略
  44. If FrmMain.PanHint.Children.Count >= 20 Then GoTo EndHint
  45. '检查是否有重复提示
  46. Dim DoubleStack As Border = Nothing
  47. For Each stack As Border In FrmMain.PanHint.Children
  48. If stack.Tag(0) AndAlso CType(stack.Child, TextBlock).Text = CurrentHint.Text Then DoubleStack = stack
  49. Next
  50. '获取渐变颜色
  51. Dim TargetColor0, TargetColor1 As MyColor
  52. Dim Percent As Double = 0.3
  53. Select Case CurrentHint.Type
  54. Case HintType.Blue
  55. TargetColor0 = New MyColor(215, 37, 155, 252)
  56. TargetColor1 = New MyColor(215, 10, 142, 252)
  57. Case HintType.Green
  58. TargetColor0 = New MyColor(215, 33, 177, 33)
  59. TargetColor1 = New MyColor(215, 29, 160, 29)
  60. Case Else 'HintType.Red
  61. TargetColor0 = New MyColor(215, 255, 53, 11)
  62. TargetColor1 = New MyColor(215, 255, 43, 0)
  63. End Select
  64. If Not IsNothing(DoubleStack) Then
  65. '有重复提示,且该提示的进入动画已播放
  66. If Not AniIsRun("Hint Show " & DoubleStack.Tag(1)) Then
  67. AniStop("Hint Hide " & DoubleStack.Tag(1))
  68. Dim Delay As Double = (800 + MathClamp(CurrentHint.Text.Length, 5, 23) * 180) * AniSpeed
  69. AniStart({
  70. AaX(DoubleStack, -12 - DoubleStack.Margin.Left, 50,, New AniEaseOutFluent),
  71. AaX(DoubleStack, -8, 50, 50, New AniEaseInFluent),
  72. AaX(DoubleStack, 8, 50, 100, New AniEaseOutFluent),
  73. AaX(DoubleStack, -8, 50, 150, New AniEaseInFluent),
  74. AaDouble(Sub(i)
  75. Percent += i
  76. Dim Gradient As LinearGradientBrush = DoubleStack.Background
  77. Gradient.GradientStops(0).Color = TargetColor0 * Percent + New MyColor(255, 255, 255) * (1 - Percent)
  78. Gradient.GradientStops(1).Color = TargetColor1 * Percent + New MyColor(255, 255, 255) * (1 - Percent)
  79. End Sub, 0.7, 250),
  80. AaX(DoubleStack, -50, 200, Delay, New AniEaseInFluent),
  81. AaOpacity(DoubleStack, -1, 150, Delay),
  82. AaCode(Sub() DoubleStack.Tag(0) = False, Delay),
  83. AaHeight(DoubleStack, -26, 100,, New AniEaseOutFluent, True),
  84. AaCode(Sub() FrmMain.PanHint.Children.Remove(DoubleStack), , True)
  85. }, "Hint Hide " & DoubleStack.Tag(1))
  86. End If
  87. Else
  88. '准备控件
  89. Dim NewHintControl As New Border With {.Tag = {True, GetUuid()}, .Margin = New Thickness(-70, 0, 20, 0), .Opacity = 0, .Height = 0, .HorizontalAlignment = HorizontalAlignment.Left, .CornerRadius = New CornerRadius(0, 6, 6, 0)}
  90. NewHintControl.Background = New LinearGradientBrush(New GradientStopCollection(New List(Of GradientStop) From {
  91. New GradientStop(TargetColor0 * Percent + New MyColor(255, 255, 255) * (1 - Percent), 0),
  92. New GradientStop(TargetColor1 * Percent + New MyColor(255, 255, 255) * (1 - Percent), 1)}), 90)
  93. NewHintControl.Child = New TextBlock With {.TextTrimming = TextTrimming.CharacterEllipsis, .FontSize = 13, .Text = CurrentHint.Text, .Foreground = New MyColor(255, 255, 255), .Margin = New Thickness(33, 5, 8, 5)}
  94. 'AddHandler NewHintControl.MouseLeftButtonDown, AddressOf HideAllHint
  95. FrmMain.PanHint.Children.Add(NewHintControl)
  96. '控件动画
  97. Dim Animations As New List(Of AniData)
  98. If FrmMain.PanHint.Children.Count > 1 Then
  99. '已有提示
  100. Animations.Add(AaHeight(NewHintControl, 26, 150, , New AniEaseOutFluent))
  101. Else
  102. '是唯一提示
  103. NewHintControl.Height = 26
  104. End If
  105. '开始动画
  106. Animations.AddRange({
  107. AaX(NewHintControl, 30, 400, , New AniEaseOutElastic(AniEasePower.Weak)),
  108. AaX(NewHintControl, 20, 200, , New AniEaseOutFluent),
  109. AaOpacity(NewHintControl, 1, 100),
  110. AaDouble(Sub(i)
  111. Percent += i
  112. Dim Gradient As LinearGradientBrush = NewHintControl.Background
  113. Gradient.GradientStops(0).Color = TargetColor0 * Percent + New MyColor(255, 255, 255) * (1 - Percent)
  114. Gradient.GradientStops(1).Color = TargetColor1 * Percent + New MyColor(255, 255, 255) * (1 - Percent)
  115. End Sub, 0.7, 250, 100)
  116. })
  117. AniStart(Animations, "Hint Show " & NewHintControl.Tag(1))
  118. '结束动画
  119. Dim Delay As Double = (800 + MathClamp(CurrentHint.Text.Length, 5, 23) * 180) * AniSpeed
  120. AniStart({
  121. AaX(NewHintControl, -50, 200, Delay, New AniEaseInFluent),
  122. AaOpacity(NewHintControl, -1, 150, Delay),
  123. AaCode(Sub() NewHintControl.Tag(0) = False, Delay),
  124. AaHeight(NewHintControl, -26, 100,, New AniEaseOutFluent, True),
  125. AaCode(Sub() FrmMain.PanHint.Children.Remove(NewHintControl), , True)
  126. }, "Hint Hide " & NewHintControl.Tag(1))
  127. End If
  128. '结束处理
  129. EndHint:
  130. If CurrentHint.Log Then Log("[UI] 弹出提示:" & CurrentHint.Text)
  131. HintWaiting.RemoveAt(0)
  132. Loop
  133. Catch ex As Exception
  134. Log(ex, "显示弹出提示失败", LogLevel.Normal)
  135. End Try
  136. End Sub
  137. Private Sub HideAllHint()
  138. For Each Control As Border In FrmMain.PanHint.Children
  139. Control.IsHitTestVisible = False
  140. AniStart({
  141. AaX(Control, -50, 200, , New AniEaseInFluent),
  142. AaOpacity(Control, -1, 150, , New AniEaseInFluent),
  143. AaCode(Sub() Control.Tag(0) = False),
  144. AaHeight(Control, -26, 100,, New AniEaseOutFluent, True),
  145. AaCode(Sub() FrmMain.PanHint.Children.Remove(Control), , True)
  146. }, "Hint Hide " & Control.Tag(1))
  147. Next
  148. End Sub
  149. #End Region
  150. #Region "弹窗"
  151. ''' <summary>
  152. ''' 存储弹窗信息的转换器。
  153. ''' </summary>
  154. Public Class MyMsgBoxConverter
  155. Public Type As MyMsgBoxType
  156. Public Title As String
  157. Public Text As String
  158. ''' <summary>
  159. ''' 输入模式:文本框的文本。
  160. ''' 选择模式:需要放进去的 List(Of MyListItem)。
  161. ''' 登录模式:登录步骤 1 中返回的 JSON。
  162. ''' </summary>
  163. Public Content As Object
  164. ''' <summary>
  165. ''' 输入模式:输入验证规则。
  166. ''' </summary>
  167. Public ValidateRules As ObjectModel.Collection(Of Validate)
  168. ''' <summary>
  169. ''' 输入模式:提示文本。
  170. ''' </summary>
  171. Public HintText As String = ""
  172. ''' <summary>
  173. ''' 有多个按钮时,是否给第一个按钮加高亮。
  174. ''' </summary>
  175. Public HighLight As Boolean
  176. Public Button1 As String = "确定"
  177. Public Button2 As String = ""
  178. Public Button3 As String = ""
  179. ''' <summary>
  180. ''' 点击第一个按钮将执行该方法,不关闭弹窗。
  181. ''' </summary>
  182. Public Button1Action As Action = Nothing
  183. ''' <summary>
  184. ''' 点击第二个按钮将执行该方法,不关闭弹窗。
  185. ''' </summary>
  186. Public Button2Action As Action = Nothing
  187. ''' <summary>
  188. ''' 点击第三个按钮将执行该方法,不关闭弹窗。
  189. ''' </summary>
  190. Public Button3Action As Action = Nothing
  191. Public IsWarn As Boolean = False
  192. Public ForceWait As Boolean = False
  193. Public WaitFrame As New DispatcherFrame(True)
  194. ''' <summary>
  195. ''' 弹窗是否已经关闭。
  196. ''' </summary>
  197. Public IsExited As Boolean = False
  198. ''' <summary>
  199. ''' 输入模式:输入的文本。若点击了 非 第一个按钮,则为 Nothing。
  200. ''' 选择模式:点击的按钮编号,从 1 开始。
  201. ''' 登录模式:字符串数组 {AccessToken, RefreshToken} 或一个 Exception。
  202. ''' </summary>
  203. Public Result As Object
  204. End Class
  205. Public Enum MyMsgBoxType
  206. Text
  207. [Select]
  208. Input
  209. Login
  210. End Enum
  211. ''' <summary>
  212. ''' 显示弹窗,返回点击按钮的编号(从 1 开始)。
  213. ''' </summary>
  214. ''' <param name="Title">弹窗的标题。</param>
  215. ''' <param name="Caption">弹窗的内容。</param>
  216. ''' <param name="Button1">显示的第一个按钮,默认为“确定”。</param>
  217. ''' <param name="Button2">显示的第二个按钮,默认为空。</param>
  218. ''' <param name="Button3">显示的第三个按钮,默认为空。</param>
  219. ''' <param name="Button1Action">点击第一个按钮将执行该方法,不关闭弹窗。</param>
  220. ''' <param name="Button2Action">点击第二个按钮将执行该方法,不关闭弹窗。</param>
  221. ''' <param name="Button3Action">点击第三个按钮将执行该方法,不关闭弹窗。</param>
  222. ''' <param name="IsWarn">是否为警告弹窗,若为 True,弹窗配色和背景会变为红色。</param>
  223. Public Function MyMsgBox(Caption As String, Optional Title As String = "提示",
  224. Optional Button1 As String = "确定", Optional Button2 As String = "", Optional Button3 As String = "",
  225. Optional IsWarn As Boolean = False, Optional HighLight As Boolean = True, Optional ForceWait As Boolean = False,
  226. Optional Button1Action As Action = Nothing, Optional Button2Action As Action = Nothing, Optional Button3Action As Action = Nothing) As Integer
  227. '将弹窗列入队列
  228. Dim Converter As New MyMsgBoxConverter With {.Type = MyMsgBoxType.Text, .Button1 = Button1, .Button2 = Button2, .Button3 = Button3, .Text = Caption, .IsWarn = IsWarn, .Title = Title, .HighLight = HighLight, .ForceWait = True, .Button1Action = Button1Action, .Button2Action = Button2Action, .Button3Action = Button3Action}
  229. WaitingMyMsgBox.Add(Converter)
  230. If RunInUi() Then
  231. '若为 UI 线程,立即执行弹窗刻, 避免快速(连点器)点击时多次弹窗
  232. MyMsgBoxTick()
  233. End If
  234. If Button2.Length > 0 OrElse ForceWait Then
  235. '若有多个按钮则开始等待
  236. If FrmMain Is Nothing OrElse FrmMain.PanMsg Is Nothing AndAlso RunInUi() Then
  237. '主窗体尚未加载,用老土的弹窗来替代
  238. WaitingMyMsgBox.Remove(Converter)
  239. If Button2.Length > 0 Then
  240. Dim RawResult As MsgBoxResult = MsgBox(Caption, If(Button3.Length > 0, MsgBoxStyle.YesNoCancel, MsgBoxStyle.YesNo) + If(IsWarn, MsgBoxStyle.Critical, MsgBoxStyle.Question), Title)
  241. Select Case RawResult
  242. Case MsgBoxResult.Yes
  243. Converter.Result = 1
  244. Case MsgBoxResult.No
  245. Converter.Result = 2
  246. Case MsgBoxResult.Cancel
  247. Converter.Result = 3
  248. End Select
  249. Else
  250. MsgBox(Caption, MsgBoxStyle.OkOnly + If(IsWarn, MsgBoxStyle.Critical, MsgBoxStyle.Question), Title)
  251. Converter.Result = 1
  252. End If
  253. Log("[Control] 主窗体加载完成前出现意料外的等待弹窗:" & Button1 & "," & Button2 & "," & Button3, LogLevel.Debug)
  254. Else
  255. Try
  256. FrmMain.DragStop()
  257. ComponentDispatcher.PushModal()
  258. Dispatcher.PushFrame(Converter.WaitFrame)
  259. Finally
  260. ComponentDispatcher.PopModal()
  261. End Try
  262. End If
  263. Log("[Control] 普通弹框返回:" & If(Converter.Result, "null"))
  264. Return Converter.Result
  265. Else
  266. '不进行等待,直接返回
  267. Return 1
  268. End If
  269. End Function
  270. ''' <summary>
  271. ''' 显示输入框并返回输入的文本。若点击第二个按钮,则返回 Nothing。
  272. ''' </summary>
  273. ''' <param name="Title">弹窗的标题。</param>
  274. ''' <param name="ValidateRules">文本框的输入检测。</param>
  275. ''' <param name="Text">弹窗的介绍文本。</param>
  276. ''' <param name="DefaultInput">文本框的默认内容。</param>
  277. ''' <param name="HintText">文本框的提示内容。</param>
  278. ''' <param name="Button1">显示的第一个按钮,默认为“确定”。</param>
  279. ''' <param name="Button2">显示的第二个按钮,默认为“取消”。</param>
  280. ''' <param name="IsWarn">是否为警告弹窗,若为 True,弹窗配色和背景会变为红色。</param>
  281. Public Function MyMsgBoxInput(Title As String, Optional Text As String = "", Optional DefaultInput As String = "", Optional ValidateRules As ObjectModel.Collection(Of Validate) = Nothing, Optional HintText As String = "", Optional Button1 As String = "确定", Optional Button2 As String = "取消", Optional IsWarn As Boolean = False) As String
  282. '将弹窗列入队列
  283. Dim Converter As New MyMsgBoxConverter With {.Text = Text, .HintText = HintText, .Type = MyMsgBoxType.Input, .ValidateRules = If(ValidateRules, New ObjectModel.Collection(Of Validate)), .Button1 = Button1, .Button2 = Button2, .Content = DefaultInput, .IsWarn = IsWarn, .Title = Title}
  284. WaitingMyMsgBox.Add(Converter)
  285. '虽然我也不知道这是啥但是能用就成了 :)
  286. Try
  287. If FrmMain IsNot Nothing Then FrmMain.DragStop()
  288. ComponentDispatcher.PushModal()
  289. Dispatcher.PushFrame(Converter.WaitFrame)
  290. Finally
  291. ComponentDispatcher.PopModal()
  292. End Try
  293. Log("[Control] 输入弹框返回:" & If(Converter.Result, "null"))
  294. Return Converter.Result
  295. End Function
  296. ''' <summary>
  297. ''' 显示选择框并返回选择的第几项(从 0 开始)。若点击第二个按钮,则返回 Nothing。
  298. ''' </summary>
  299. ''' <param name="Title">弹窗的标题。</param>
  300. ''' <param name="Button1">显示的第一个按钮,默认为 “确定”。</param>
  301. ''' <param name="Button2">显示的第二个按钮,默认为空。</param>
  302. ''' <param name="IsWarn">是否为警告弹窗,若为 True,弹窗配色和背景会变为红色。</param>
  303. Public Function MyMsgBoxSelect(Selections As List(Of IMyRadio), Optional Title As String = "提示", Optional Button1 As String = "确定", Optional Button2 As String = "", Optional IsWarn As Boolean = False) As Integer?
  304. '将弹窗列入队列
  305. Dim Converter As New MyMsgBoxConverter With {.Type = MyMsgBoxType.Select, .Button1 = Button1, .Button2 = Button2, .Content = Selections, .IsWarn = IsWarn, .Title = Title}
  306. WaitingMyMsgBox.Add(Converter)
  307. '虽然我也不知道这是啥但是能用就成了 :)
  308. Try
  309. If FrmMain IsNot Nothing Then FrmMain.DragStop()
  310. ComponentDispatcher.PushModal()
  311. Dispatcher.PushFrame(Converter.WaitFrame)
  312. Finally
  313. ComponentDispatcher.PopModal()
  314. End Try
  315. Log("[Control] 选择弹框返回:" & If(Converter.Result, "null"))
  316. Return Converter.Result
  317. End Function
  318. ''' <summary>
  319. ''' 等待显示的弹窗。
  320. ''' </summary>
  321. Public WaitingMyMsgBox As List(Of MyMsgBoxConverter) = If(WaitingMyMsgBox, New List(Of MyMsgBoxConverter))
  322. Public Sub MyMsgBoxTick()
  323. Try
  324. If FrmMain Is Nothing OrElse FrmMain.PanMsg Is Nothing OrElse FrmMain.WindowState = WindowState.Minimized Then Return
  325. If FrmMain.PanMsg.Children.Count > 0 Then
  326. '弹窗中
  327. FrmMain.PanMsg.Visibility = Visibility.Visible
  328. ElseIf WaitingMyMsgBox.Any Then
  329. '没有弹窗,显示一个等待的弹窗
  330. FrmMain.PanMsg.Visibility = Visibility.Visible
  331. Select Case CType(WaitingMyMsgBox(0), MyMsgBoxConverter).Type
  332. Case MyMsgBoxType.Input
  333. FrmMain.PanMsg.Children.Add(New MyMsgInput(WaitingMyMsgBox(0)))
  334. Case MyMsgBoxType.Select
  335. FrmMain.PanMsg.Children.Add(New MyMsgSelect(WaitingMyMsgBox(0)))
  336. Case MyMsgBoxType.Text
  337. FrmMain.PanMsg.Children.Add(New MyMsgText(WaitingMyMsgBox(0)))
  338. Case MyMsgBoxType.Login
  339. FrmMain.PanMsg.Children.Add(New MyMsgLogin(WaitingMyMsgBox(0)))
  340. End Select
  341. WaitingMyMsgBox.RemoveAt(0)
  342. Else
  343. '没有弹窗,没有等待的弹窗
  344. If Not FrmMain.PanMsg.Visibility = Visibility.Collapsed Then FrmMain.PanMsg.Visibility = Visibility.Collapsed
  345. End If
  346. Catch ex As Exception
  347. Log(ex, "处理等待中的弹窗失败", LogLevel.Feedback)
  348. End Try
  349. End Sub
  350. #End Region
  351. #Region "页面声明"
  352. '在最后进行页面声明,避免颜色尚未加载完毕
  353. '窗体声明
  354. Public FrmMain As FormMain
  355. Public FrmStart As SplashScreen
  356. '页面声明(出于单元测试考虑,初始化页面已转入 FormMain 中)
  357. Public FrmLaunchLeft As PageLaunchLeft
  358. Public FrmLaunchRight As PageLaunchRight
  359. Public FrmSelectLeft As PageSelectLeft
  360. Public FrmSelectRight As PageSelectRight
  361. Public FrmSpeedLeft As PageSpeedLeft
  362. Public FrmSpeedRight As PageSpeedRight
  363. '联机页面声明
  364. Public FrmLinkLeft As PageLinkLeft
  365. Public FrmLinkIoi As PageLinkIoi
  366. Public FrmLinkHiper As PageLinkHiper
  367. Public FrmLinkHelp As PageOtherHelpDetail
  368. Public FrmLinkFeedback As PageLinkFeedback
  369. '下载页面声明
  370. Public FrmDownloadLeft As PageDownloadLeft
  371. Public FrmDownloadInstall As PageDownloadInstall
  372. Public FrmDownloadMod As PageDownloadMod
  373. Public FrmDownloadPack As PageDownloadPack
  374. Public FrmDownloadDataPack As PageDownloadDataPack
  375. Public FrmDownloadShader As PageDownloadShader
  376. Public FrmDownloadResourcePack As PageDownloadResourcePack
  377. '设置页面声明
  378. Public FrmSetupLeft As PageSetupLeft
  379. Public FrmSetupLaunch As PageSetupLaunch
  380. Public FrmSetupUI As PageSetupUI
  381. Public FrmSetupSystem As PageSetupSystem
  382. Public FrmSetupLink As PageSetupLink
  383. '其他页面声明
  384. Public FrmOtherLeft As PageOtherLeft
  385. Public FrmOtherHelp As PageOtherHelp
  386. Public FrmOtherAbout As PageOtherAbout
  387. Public FrmOtherTest As PageOtherTest
  388. '登录页面声明
  389. Public FrmLoginLegacy As PageLoginLegacy
  390. Public FrmLoginNide As PageLoginNide
  391. Public FrmLoginNideSkin As PageLoginNideSkin
  392. Public FrmLoginAuth As PageLoginAuth
  393. Public FrmLoginAuthSkin As PageLoginAuthSkin
  394. Public FrmLoginMs As PageLoginMs
  395. Public FrmLoginMsSkin As PageLoginMsSkin
  396. '版本设置页面声明
  397. Public FrmVersionLeft As PageVersionLeft
  398. Public FrmVersionOverall As PageVersionOverall
  399. Public FrmVersionMod As PageVersionMod
  400. Public FrmVersionModDisabled As PageVersionModDisabled
  401. Public FrmVersionSetup As PageVersionSetup
  402. Public FrmVersionExport As PageVersionExport
  403. '资源信息分页声明
  404. Public FrmDownloadCompDetail As PageDownloadCompDetail
  405. #End Region
  406. #Region "帮助"
  407. Public Class HelpEntry
  408. ''' <summary>
  409. ''' 原始信息路径。用于刷新。
  410. ''' </summary>
  411. Public RawPath As String
  412. '基础
  413. ''' <summary>
  414. ''' 显示标题。
  415. ''' </summary>
  416. Public Title As String
  417. ''' <summary>
  418. ''' 显示描述。
  419. ''' </summary>
  420. Public Desc As String
  421. ''' <summary>
  422. ''' 检索关键字。
  423. ''' </summary>
  424. Public Search As String
  425. ''' <summary>
  426. ''' 用于分类的标签列表。
  427. ''' </summary>
  428. Public Types As List(Of String)
  429. '显示(可选)
  430. ''' <summary>
  431. ''' 帮助项的自定义图标。可能为 Nothing。
  432. ''' </summary>
  433. Public Logo As String = Nothing
  434. ''' <summary>
  435. ''' 是否显示在搜索结果。默认为 True。
  436. ''' </summary>
  437. Public ShowInSearch As Boolean = True
  438. ''' <summary>
  439. ''' 是否在公开版的 PCL 中显示(这会影响主页与搜索)。默认为 True。
  440. ''' </summary>
  441. Public ShowInPublic As Boolean = True
  442. ''' <summary>
  443. ''' 是否在快照版的 PCL 中显示(这会影响主页与搜索)。默认为 True。
  444. ''' </summary>
  445. Public ShowInSnapshot As Boolean = True
  446. '动作
  447. ''' <summary>
  448. ''' 是否为 “执行事件”。
  449. ''' </summary>
  450. Public IsEvent As Boolean
  451. Public EventType As CustomEvent.EventType
  452. Public EventData As String
  453. ''' <summary>
  454. ''' 若非执行事件,其对应的 .xaml 本地文件内容。
  455. ''' </summary>
  456. Public XamlContent As String
  457. '转换
  458. ''' <summary>
  459. ''' 从文件初始化 HelpEntry 对象,失败会抛出异常。
  460. ''' </summary>
  461. Public Sub New(FilePath As String)
  462. RawPath = FilePath
  463. Dim JsonData As JObject = GetJson(ArgumentReplace(ReadFile(FilePath), AddressOf EscapeXML))
  464. If JsonData Is Nothing Then Throw New FileNotFoundException("未找到帮助文件:" & FilePath, FilePath)
  465. '加载常规信息
  466. If JsonData("Title") IsNot Nothing Then
  467. Title = JsonData("Title")
  468. Else
  469. Throw New ArgumentException("未找到 Title 项")
  470. End If
  471. Desc = If(JsonData("Description"), "")
  472. Search = If(JsonData("Keywords"), "")
  473. Logo = JsonData("Logo") '为保持 Nothing,不要加 If
  474. ShowInSearch = If(JsonData("ShowInSearch"), ShowInSearch)
  475. ShowInPublic = If(JsonData("ShowInPublic"), ShowInPublic)
  476. ShowInSnapshot = If(JsonData("ShowInSnapshot"), ShowInSnapshot)
  477. Types = New List(Of String)
  478. For Each NameOfType In If(JsonData("Types"), GetJson("[]"))
  479. Types.Add(NameOfType)
  480. Next
  481. '加载事件信息
  482. If If(JsonData("IsEvent"), False) Then
  483. EventType = [Enum].Parse(GetType(CustomEvent.EventType), JsonData("EventType").ToString)
  484. EventData = If(JsonData("EventData"), "")
  485. IsEvent = True
  486. Else
  487. Dim XamlAddress As String = FilePath.ToLower.Replace(".json", ".xaml")
  488. If File.Exists(XamlAddress) Then
  489. XamlContent = ReadFile(XamlAddress)
  490. IsEvent = False
  491. Else
  492. Throw New FileNotFoundException("未找到帮助条目 .json 对应的 .xaml 文件(" & XamlAddress & ")")
  493. End If
  494. End If
  495. End Sub
  496. ''' <summary>
  497. ''' 获取该 HelpEntry 对应的 MyListItem。
  498. ''' </summary>
  499. Public Function ToListItem() As MyListItem
  500. Return SetToListItem(New MyListItem)
  501. End Function
  502. ''' <summary>
  503. ''' 将属性设置入一个现有的 ListItem。
  504. ''' </summary>
  505. Public Function SetToListItem(Item As MyListItem) As MyListItem
  506. Dim Logo As String
  507. If IsEvent Then
  508. If EventType = CustomEvent.EventType.弹出窗口 Then
  509. Logo = PathImage & "Blocks/GrassPath.png"
  510. Else
  511. Logo = PathImage & "Blocks/CommandBlock.png"
  512. End If
  513. Else
  514. Logo = PathImage & "Blocks/Grass.png"
  515. End If
  516. '设置属性
  517. With Item
  518. .SnapsToDevicePixels = True
  519. .Title = Title
  520. .Info = Desc
  521. .Logo = If(Me.Logo, Logo)
  522. .Height = 42
  523. .Type = MyListItem.CheckType.Clickable
  524. .Tag = Me
  525. End With
  526. CustomEventService.SetEventType(Item, CustomEvent.EventType.None) '清空自定义事件属性,它们会被下面的点击事件处理
  527. CustomEventService.SetEventData(Item, Nothing)
  528. '项目的点击事件
  529. AddHandler Item.Click, Sub(sender, e) PageOtherHelp.OnItemClick(sender.Tag)
  530. Return Item
  531. End Function
  532. End Class
  533. Public HelpLoader As New LoaderTask(Of Integer, List(Of HelpEntry))("Help Page", AddressOf HelpLoad,, ThreadPriority.BelowNormal)
  534. Private ReadOnly HelpLoadLock As New Object
  535. ''' <summary>
  536. ''' 初始化帮助列表对象。
  537. ''' </summary>
  538. Private Sub HelpLoad(Loader As LoaderTask(Of Integer, List(Of HelpEntry)))
  539. SyncLock HelpLoadLock '避免重复解压文件导致出错
  540. Try
  541. '解压内置文件
  542. HelpTryExtract()
  543. '遍历文件
  544. Dim FileList As New List(Of String)
  545. Try
  546. Dim IgnoreList As New List(Of String)
  547. '读取自定义文件
  548. If Directory.Exists(Path & "PCL\Help\") Then
  549. For Each File In EnumerateFiles(Path & "PCL\Help\")
  550. Select Case File.Extension.ToLower
  551. Case ".helpignore"
  552. '加载忽略列表
  553. Log("[Help] 发现 .helpignore 文件:" & File.FullName)
  554. For Each Line In ReadFile(File.FullName).Split(vbCrLf.ToCharArray)
  555. Dim RealString As String = Line.BeforeFirst("#").Trim
  556. If String.IsNullOrWhiteSpace(RealString) Then Continue For
  557. IgnoreList.Add(RealString)
  558. If ModeDebug Then Log("[Help] > " & RealString)
  559. Next
  560. Case ".json"
  561. FileList.Add(File.FullName)
  562. End Select
  563. Next
  564. End If
  565. Log("[Help] 已扫描 PCL 文件夹下的帮助文件,目前总计 " & FileList.Count & " 条")
  566. '读取自带文件
  567. For Each File In EnumerateFiles(PathTemp & "Help")
  568. '跳过非 json 文件与以 . 开头的文件夹
  569. If File.Extension.ToLower <> ".json" OrElse File.Directory.FullName.Replace(PathTemp & "Help", "").Contains("\.") Then Continue For
  570. '检查忽略列表
  571. Dim RealPath As String = File.FullName.Replace(PathTemp & "Help\", "")
  572. For Each Ignore In IgnoreList
  573. If RegexCheck(RealPath, Ignore) Then
  574. If ModeDebug Then Log("[Help] 已忽略 " & RealPath & ":" & Ignore)
  575. GoTo NextFile
  576. End If
  577. Next
  578. FileList.Add(File.FullName)
  579. NextFile:
  580. Next
  581. Log("[Help] 已扫描缓存文件夹下的帮助文件,目前总计 " & FileList.Count & " 条")
  582. Catch ex As Exception
  583. Log(ex, "检查帮助文件夹失败", LogLevel.Msgbox)
  584. End Try
  585. If Loader.IsAborted Then Return
  586. '将文件实例化
  587. Dim Dict As New List(Of HelpEntry)
  588. For Each FilePath As String In FileList
  589. Try
  590. Dim Entry As New HelpEntry(FilePath)
  591. Dict.Add(Entry)
  592. If ModeDebug Then Log("[Help] 已加载的帮助条目:" & Entry.Title & " ← " & FilePath)
  593. Catch ex As Exception
  594. Log(ex, "初始化帮助条目失败(" & FilePath & ")", LogLevel.Msgbox)
  595. End Try
  596. Next
  597. '回设
  598. If Not Dict.Any() Then Throw New Exception("未找到可用的帮助;若不需要帮助页面,可以在 设置 → 个性化 → 功能隐藏 中将其隐藏")
  599. If Loader.IsAborted Then Return
  600. Loader.Output = Dict
  601. Catch ex As Exception
  602. Log(ex, "帮助列表初始化失败")
  603. Throw
  604. End Try
  605. End SyncLock
  606. End Sub
  607. ''' <summary>
  608. ''' 尝试解压内置帮助文件。
  609. ''' </summary>
  610. Public Sub HelpTryExtract()
  611. If Setup.Get("SystemHelpVersion") <> VersionCode OrElse Not File.Exists(PathTemp & "Help\启动器\备份设置.xaml") Then
  612. DeleteDirectory(PathTemp & "Help")
  613. Directory.CreateDirectory(PathTemp & "Help")
  614. WriteFile(PathTemp & "Cache\Help.zip", GetResources("Help"))
  615. ExtractFile(PathTemp & "Cache\Help.zip", PathTemp & "Help", Encoding.UTF8)
  616. Setup.Set("SystemHelpVersion", VersionCode)
  617. Log("[Help] 已解压内置帮助文件,目前状态:" & File.Exists(PathTemp & "Help\启动器\备份设置.xaml"), LogLevel.Debug)
  618. End If
  619. End Sub
  620. #End Region
  621. #Region "愚人节"
  622. Public IsAprilEnabled As Boolean = Date.Now.Month = 4 AndAlso Date.Now.Day = 1
  623. Public IsAprilGiveup As Boolean = False
  624. Private AprilSpeed As New Vector(0, 0)
  625. Private AprilIdieCount As Integer = 0, AprilMousePosLast As New Point(0, 0)
  626. Private AprilDistance As Integer = 0
  627. Private Sub TimerFool()
  628. Try
  629. If FrmLaunchLeft Is Nothing OrElse FrmLaunchLeft.AprilPosTrans Is Nothing OrElse FrmMain.lastMouseArg Is Nothing Then Return
  630. If IsAprilGiveup OrElse FrmMain.PageCurrent <> FormMain.PageType.Launch OrElse AniControlEnabled <> 0 OrElse Not FrmLaunchLeft.BtnLaunch.IsLoaded Then Return
  631. '计算是否空闲
  632. Dim MousePos = FrmMain.lastMouseArg.GetPosition(FrmMain)
  633. If MousePos = AprilMousePosLast Then
  634. AprilIdieCount += 1
  635. Else
  636. AprilMousePosLast = MousePos
  637. AprilIdieCount = 0
  638. End If
  639. '计算躲避移动
  640. Dim Direction As Vector
  641. Dim Distance As Double
  642. Dim ButtonWidth = FrmLaunchLeft.BtnLaunch.ActualWidth / 2, ButtonHeight = FrmLaunchLeft.BtnLaunch.ActualHeight / 2
  643. Dim Vec As Vector = FrmMain.lastMouseArg.GetPosition(FrmLaunchLeft.BtnLaunch) - New Vector(ButtonWidth, ButtonHeight)
  644. Dim Dir As New Vector(Vec.X, Vec.Y)
  645. Dir.Normalize()
  646. Direction = -Dir
  647. Distance = New Vector(Math.Max(0, Math.Abs(Vec.X) - ButtonWidth), Math.Max(0, Math.Abs(Vec.Y) - ButtonHeight)).Length
  648. Dim BreathScale = Math.Sin(Timer150Count / 37.5 * Math.PI)
  649. Dim Acc = Math.Max(0, BreathScale * 0.25 - 0.65 - Math.Log((Distance + 0.4) / 200)) * Direction '加速度
  650. '计算回归移动
  651. If AprilIdieCount >= 64 * 5 Then
  652. Dim SafeDist As Vector = FrmMain.lastMouseArg.GetPosition(FrmMain.PanMain) - New Vector(ButtonWidth, FrmMain.PanMain.ActualHeight - ButtonHeight * 3)
  653. Dim Back As New Vector(FrmLaunchLeft.AprilPosTrans.X, FrmLaunchLeft.AprilPosTrans.Y)
  654. If SafeDist.Length > 250 AndAlso Back.Length > 0.4 Then
  655. Acc -= Back * 0.0005
  656. Back.Normalize()
  657. Acc -= Back * 0.15
  658. End If
  659. End If
  660. '回到边界
  661. Dim Relative As Point = FrmLaunchLeft.BtnLaunch.TranslatePoint(New Point(0, 0), FrmMain.PanForm)
  662. If Relative.X < -ButtonWidth * 2 Then
  663. FrmLaunchLeft.AprilPosTrans.X += FrmMain.PanForm.ActualWidth + ButtonWidth * 2 '离开左边界
  664. AprilSpeed.X -= 80
  665. If Relative.Y < 0 Then
  666. FrmLaunchLeft.AprilPosTrans.Y += ButtonHeight * 2.5
  667. ElseIf Relative.Y > FrmMain.PanForm.ActualHeight - ButtonHeight * 2 Then
  668. FrmLaunchLeft.AprilPosTrans.Y -= ButtonHeight * 2.5
  669. End If
  670. ElseIf Relative.X > FrmMain.PanForm.ActualWidth Then
  671. FrmLaunchLeft.AprilPosTrans.X -= FrmMain.PanForm.ActualWidth + ButtonWidth * 2 '离开右边界
  672. AprilSpeed.X += 80
  673. If Relative.Y < 0 Then
  674. FrmLaunchLeft.AprilPosTrans.Y += ButtonHeight * 2.5
  675. ElseIf Relative.Y > FrmMain.PanForm.ActualHeight - ButtonHeight * 2 Then
  676. FrmLaunchLeft.AprilPosTrans.Y -= ButtonHeight * 2.5
  677. End If
  678. ElseIf Relative.Y < -ButtonHeight * 2 Then
  679. FrmLaunchLeft.AprilPosTrans.Y += FrmMain.PanForm.ActualHeight + ButtonHeight * 2 '离开上边界
  680. AprilSpeed.Y -= 25
  681. If Relative.X < 0 Then
  682. FrmLaunchLeft.AprilPosTrans.X += ButtonWidth * 2
  683. ElseIf Relative.X > FrmMain.PanForm.ActualWidth - ButtonWidth * 2 Then
  684. FrmLaunchLeft.AprilPosTrans.X -= ButtonWidth * 2
  685. End If
  686. ElseIf Relative.Y > FrmMain.PanForm.ActualHeight Then
  687. FrmLaunchLeft.AprilPosTrans.Y -= FrmMain.PanForm.ActualHeight + ButtonHeight * 2 '离开下边界
  688. AprilSpeed.Y += 25
  689. If Relative.X < 0 Then
  690. FrmLaunchLeft.AprilPosTrans.X += ButtonWidth * 2
  691. ElseIf Relative.X > FrmMain.PanForm.ActualWidth - ButtonWidth * 2 Then
  692. FrmLaunchLeft.AprilPosTrans.X -= ButtonWidth * 2
  693. End If
  694. End If
  695. '移动
  696. AprilSpeed = AprilSpeed * 0.8 + Acc
  697. Dim SpeedValue = Math.Min(60, AprilSpeed.Length)
  698. If SpeedValue < 0.01 Then Return
  699. AprilSpeed.Normalize()
  700. AprilSpeed *= SpeedValue
  701. AprilDistance += SpeedValue
  702. FrmLaunchLeft.AprilPosTrans.X += AprilSpeed.X
  703. FrmLaunchLeft.AprilPosTrans.Y += AprilSpeed.Y
  704. '大小改变
  705. FrmLaunchLeft.AprilScaleTrans.ScaleX = MathClamp(1 - (Math.Abs(Direction.X) - Math.Abs(Direction.Y)) * (SpeedValue / 160), 0.2, 1.8)
  706. FrmLaunchLeft.AprilScaleTrans.ScaleY = MathClamp(1 - (Math.Abs(Direction.Y) - Math.Abs(Direction.X)) * (SpeedValue / 100), 0.2, 1.8)
  707. '放弃提示
  708. If AprilDistance > 4000 Then
  709. AprilDistance = -4000
  710. Select Case RandomInteger(0, 3)
  711. Case 0
  712. Hint("放弃吧!只需要点一下右下角的小白旗……")
  713. Case 1
  714. Hint("看到右下角的那面小白旗了吗?")
  715. Case 2
  716. Hint("这里建议点一下右下角的小白旗投降呢.jpg")
  717. Case 3
  718. Hint("右下角的小白旗永远等着你……")
  719. End Select
  720. End If
  721. Catch ex As Exception
  722. Log(ex, "愚人节移动出错", LogLevel.Feedback)
  723. End Try
  724. End Sub
  725. #End Region
  726. #Region "系统"
  727. ''' <summary>
  728. ''' 把某个 PCL 窗口拖到最前面。
  729. ''' </summary>
  730. Public Sub ShowWindowToTop(Handle As IntPtr)
  731. Try
  732. PostMessage(Handle, 400 * 16 + 2, 0, 0)
  733. SetForegroundWindow(Handle) '不在这里放不行,神秘 WinAPI,建议别动
  734. Catch ex As Exception
  735. Log(ex, "设置窗口置顶失败", LogLevel.Hint)
  736. End Try
  737. End Sub
  738. Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ClassName As String, WindowName As String) As IntPtr
  739. Public Declare Function SetForegroundWindow Lib "user32" (hWnd As IntPtr) As Integer
  740. Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (hWnd As IntPtr, msg As UInteger, wParam As Long, lParam As Long) As Boolean
  741. ''' <summary>
  742. ''' 将特定程序设置为使用高性能显卡启动。
  743. ''' 如果失败,则抛出异常。
  744. ''' </summary>
  745. Public Sub SetGPUPreference(Executeable As String)
  746. Const REG_KEY As String = "Software\Microsoft\DirectX\UserGpuPreferences"
  747. Const REG_VALUE As String = "GpuPreference=2;"
  748. '查看现有设置
  749. Using ReadOnlyKey = My.Computer.Registry.CurrentUser.OpenSubKey(REG_KEY, False)
  750. If ReadOnlyKey IsNot Nothing Then
  751. Dim CurrentValue = ReadOnlyKey.GetValue(Executeable)
  752. If REG_VALUE = CurrentValue?.ToString() Then
  753. Log($"[System] 无需调整显卡设置:{Executeable}")
  754. Return
  755. End If
  756. Else
  757. '创建父级键
  758. Log($"[System] 需要创建显卡设置的父级键")
  759. My.Computer.Registry.CurrentUser.CreateSubKey(REG_KEY)
  760. End If
  761. End Using
  762. '写入新设置
  763. Using WriteKey = My.Computer.Registry.CurrentUser.OpenSubKey(REG_KEY, True)
  764. WriteKey.SetValue(Executeable, REG_VALUE)
  765. Log($"[System] 已调整显卡设置:{Executeable}")
  766. End Using
  767. End Sub
  768. ''' <summary>
  769. ''' 对替换标记进行处理。会对替换内容使用 EscapeHandler 进行转义。
  770. ''' </summary>
  771. Public Function ArgumentReplace(Text As String, Optional EscapeHandler As Func(Of String, String) = Nothing, Optional ReplaceTime As Boolean = True) As String
  772. '预处理
  773. If Text Is Nothing Then Return Nothing
  774. Dim Replacer =
  775. Function(s As String) As String
  776. If s Is Nothing Then Return ""
  777. If EscapeHandler Is Nothing Then Return s
  778. If s.Contains(":\") Then s = ShortenPath(s)
  779. Return EscapeHandler(s)
  780. End Function
  781. '基础
  782. Text = Text.Replace("{pcl_version}", Replacer(VersionBaseName))
  783. Text = Text.Replace("{pcl_version_code}", Replacer(VersionCode))
  784. Text = Text.Replace("{pcl_version_branch}", Replacer(VersionBranchName))
  785. Text = Text.Replace("{pcl_branch}", Replacer(VersionBranchMain))
  786. Text = Text.Replace("{identify}", Replacer(Identify))
  787. Text = Text.Replace("{path}", Replacer(Path))
  788. Text = Text.Replace("{path_with_name}", Replacer(PathWithName))
  789. Text = Text.Replace("{path_temp}", Replacer(PathTemp))
  790. '时间
  791. If ReplaceTime Then '在窗口标题中,时间会被后续动态替换,所以此时不应该替换
  792. Text = Text.Replace("{date}", Replacer(Date.Now.ToString("yyyy/M/d")))
  793. Text = Text.Replace("{time}", Replacer(Date.Now.ToString("HH:mm:ss")))
  794. End If
  795. 'Minecraft
  796. Text = Text.Replace("{java}", Replacer(McLaunchJavaSelected?.PathFolder))
  797. Text = Text.Replace("{minecraft}", Replacer(PathMcFolder))
  798. If McVersionCurrent IsNot Nothing Then
  799. Text = Text.Replace("{version_path}", Replacer(McVersionCurrent.Path)) : Text = Text.Replace("{verpath}", Replacer(McVersionCurrent.Path))
  800. Text = Text.Replace("{version_indie}", Replacer(McVersionCurrent.PathIndie)) : Text = Text.Replace("{verindie}", Replacer(McVersionCurrent.PathIndie))
  801. Text = Text.Replace("{name}", Replacer(McVersionCurrent.Name))
  802. If {"unknown", "old", "pending"}.Contains(McVersionCurrent.Version.McName.ToLower) Then
  803. Text = Text.Replace("{version}", Replacer(McVersionCurrent.Name))
  804. Else
  805. Text = Text.Replace("{version}", Replacer(McVersionCurrent.Version.McName))
  806. End If
  807. Else
  808. Text = Text.Replace("{version_path}", Replacer(Nothing)) : Text = Text.Replace("{verpath}", Replacer(Nothing))
  809. Text = Text.Replace("{version_indie}", Replacer(Nothing)) : Text = Text.Replace("{verindie}", Replacer(Nothing))
  810. Text = Text.Replace("{name}", Replacer(Nothing))
  811. Text = Text.Replace("{version}", Replacer(Nothing))
  812. End If
  813. '登录信息
  814. If McLoginLoader.State = LoadState.Finished Then
  815. Text = Text.Replace("{user}", Replacer(McLoginLoader.Output.Name))
  816. Text = Text.Replace("{uuid}", Replacer(McLoginLoader.Output.Uuid.ToLower))
  817. Select Case McLoginLoader.Input.Type
  818. Case McLoginType.Legacy
  819. Text = Text.Replace("{login}", Replacer("离线"))
  820. Case McLoginType.Ms
  821. Text = Text.Replace("{login}", Replacer("正版"))
  822. Case McLoginType.Nide
  823. Text = Text.Replace("{login}", Replacer("统一通行证"))
  824. Case McLoginType.Auth
  825. Text = Text.Replace("{login}", Replacer("Authlib-Injector"))
  826. End Select
  827. Else
  828. Text = Text.Replace("{user}", Replacer(Nothing))
  829. Text = Text.Replace("{uuid}", Replacer(Nothing))
  830. Text = Text.Replace("{login}", Replacer(Nothing))
  831. End If
  832. '高级
  833. Text = Text.RegexReplaceEach("\{hint\}", Function() Replacer(PageOtherTest.GetRandomHint()))
  834. Text = Text.RegexReplaceEach("\{cave\}", Function() Replacer(PageOtherTest.GetRandomCave()))
  835. Text = Text.RegexReplaceEach("\{setup:([a-zA-Z0-9]+)\}", Function(m) Replacer(Setup.GetSafe(m.Groups(1).Value, McVersionCurrent)))
  836. Text = Text.RegexReplaceEach("\{varible:([^:\}]+)(?::([^\}]+))?\}", Function(m) Replacer(ReadReg("CustomEvent" & m.Groups(1).Value, m.Groups(2).Value)))
  837. Return Text
  838. End Function
  839. #End Region
  840. #Region "任务缓存"
  841. Private IsTaskTempCleared As Boolean = False
  842. Private IsTaskTempClearing As Boolean = False
  843. ''' <summary>
  844. ''' 尝试清理任务缓存文件夹。
  845. ''' 在整次运行中只会实际清理一次。
  846. ''' </summary>
  847. Public Sub TryClearTaskTemp()
  848. If Not IsTaskTempCleared Then
  849. IsTaskTempCleared = True
  850. IsTaskTempClearing = True
  851. Try
  852. Log("[System] 开始清理任务缓存文件夹")
  853. DeleteDirectory($"{OsDrive}ProgramData\PCL\TaskTemp\")
  854. DeleteDirectory($"{PathTemp}TaskTemp\")
  855. Log("[System] 已清理任务缓存文件夹")
  856. Catch ex As Exception
  857. Log(ex, "清理任务缓存文件夹失败")
  858. Finally
  859. IsTaskTempClearing = False
  860. End Try
  861. ElseIf IsTaskTempClearing Then
  862. '等待另一个清理步骤完成
  863. Do While IsTaskTempClearing
  864. Thread.Sleep(1)
  865. Loop
  866. End If
  867. End Sub
  868. ''' <summary>
  869. ''' 申请一个可用于任务缓存的临时文件夹,以 \ 结尾。这些文件夹无需进行后续清理。
  870. ''' 若所有缓存位置均没有权限,会抛出异常。
  871. ''' </summary>
  872. ''' <param name="RequireNonSpace">是否要求路径不包含空格。</param>
  873. Public Function RequestTaskTempFolder(Optional RequireNonSpace As Boolean = False) As String
  874. TryClearTaskTemp()
  875. Dim ResultFolder As String
  876. Try
  877. ResultFolder = $"{PathTemp}TaskTemp\{GetUuid()}-{RandomInteger(0, 1000000)}\"
  878. If RequireNonSpace AndAlso ResultFolder.Contains(" ") Then Exit Try '带空格
  879. Directory.CreateDirectory(ResultFolder)
  880. CheckPermissionWithException(ResultFolder)
  881. Return ResultFolder
  882. Catch
  883. End Try
  884. '使用备用路径
  885. ResultFolder = $"{OsDrive}ProgramData\PCL\TaskTemp\{GetUuid()}-{RandomInteger(0, 1000000)}\"
  886. Directory.CreateDirectory(ResultFolder)
  887. CheckPermission(ResultFolder)
  888. Return ResultFolder
  889. End Function
  890. #End Region
  891. Public DragControl = Nothing
  892. Private Timer4Count As Integer = 0
  893. Private Timer150Count As Integer = 0
  894. Private Sub TimerMain()
  895. Try
  896. #Region "每 50ms 执行一次的代码"
  897. HintTick()
  898. MyMsgBoxTick()
  899. FrmMain.DragTick()
  900. LoaderTaskbarProgressRefresh()
  901. If ThemeDontClick = 2 Then ThemeRefresh()
  902. #End Region
  903. Catch ex As Exception
  904. Log(ex, "短程主时钟执行异常", LogLevel.Critical)
  905. End Try
  906. Timer4Count += 1
  907. If Timer4Count = 4 Then
  908. Timer4Count = 0
  909. Try
  910. #Region "每 250ms 执行一次的代码"
  911. If ThemeNow = 12 Then ThemeRefresh()
  912. #End Region
  913. Catch ex As Exception
  914. Log(ex, "中程主时钟执行异常", LogLevel.Debug)
  915. End Try
  916. End If
  917. Timer150Count += 1
  918. If Timer150Count = 150 Then
  919. Timer150Count = 0
  920. Try
  921. #Region "每 7.5s 执行一次的代码"
  922. If FrmMain.BtnExtraApril_ShowCheck AndAlso AprilDistance <> 0 Then FrmMain.BtnExtraApril.Ribble()
  923. '以未知原因窗口被丢到一边去的修复(Top、Left = -25600),还有 #745
  924. RunInUi(
  925. Sub()
  926. If Not FrmMain.Hidden Then
  927. If FrmMain.Top < -9000 Then FrmMain.Top = 100
  928. If FrmMain.Left < -9000 Then FrmMain.Left = 100 '窗口拉至最大时 Left = -18.8
  929. End If
  930. End Sub)
  931. #End Region
  932. Catch ex As Exception
  933. Log(ex, "长程主时钟执行异常", LogLevel.Critical)
  934. End Try
  935. End If
  936. End Sub
  937. Public Sub TimerMainStart()
  938. RunInNewThread(
  939. Sub()
  940. Try
  941. Do While True
  942. RunInUiWait(AddressOf TimerMain)
  943. Thread.Sleep(50 * 0.98)
  944. Loop
  945. Catch ex As Exception
  946. Log(ex, "程序主时钟出错", LogLevel.Feedback)
  947. End Try
  948. End Sub, "Timer Main")
  949. If Not IsAprilEnabled Then Return
  950. RunInNewThread(
  951. Sub()
  952. Try
  953. Dim LastTime = My.Computer.Clock.TickCount
  954. Do While True
  955. If LastTime <> My.Computer.Clock.TickCount Then
  956. LastTime = My.Computer.Clock.TickCount
  957. RunInUiWait(AddressOf TimerFool)
  958. End If
  959. Thread.Sleep(1)
  960. Loop
  961. Catch ex As Exception
  962. Log(ex, "愚人节主时钟出错", LogLevel.Feedback)
  963. End Try
  964. End Sub, "Timer Main Fool")
  965. End Sub
  966. End Module