PageSetupSystem.xaml.vb 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. Class PageSetupSystem
  2. #Region "语言"
  3. 'Private Sub PageSetupUI_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
  4. ' AniControlEnabled -= 1
  5. ' '读取设置
  6. ' Select Case Lang
  7. ' Case "zh_CN"
  8. ' ComboLang.SelectedIndex = 0
  9. ' Case "zh_HK"
  10. ' ComboLang.SelectedIndex = 1
  11. ' Case "en_US"
  12. ' ComboLang.SelectedIndex = 2
  13. ' End Select
  14. ' CheckDebug.Checked = ReadReg("SystemDebugMode", "False")
  15. ' AniControlEnabled += 1
  16. 'End Sub
  17. 'Private Sub RefreshLang() Handles ComboLang.SelectionChanged
  18. ' If IsLoaded Then
  19. ' If Not ComboLang.IsLoaded Then Exit Sub
  20. ' Lang = CType(ComboLang.SelectedItem, MyComboBoxItem).Tag
  21. ' Application.Current.Resources.MergedDictionaries(1) = New ResourceDictionary With {.Source = New Url("Languages\" & Lang & ".xaml", UrlKind.Relative)}
  22. ' WriteReg("Lang", Lang)
  23. ' End If
  24. 'End Sub
  25. #End Region
  26. Private Shadows IsLoaded As Boolean = False
  27. Private Sub PageSetupSystem_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
  28. '重复加载部分
  29. PanBack.ScrollToHome()
  30. #If Not BETA Then
  31. ItemSystemUpdateDownload.Content = "在有新版本时自动下载(更新快照版可能需要更新密钥)"
  32. #End If
  33. '非重复加载部分
  34. If IsLoaded Then Exit Sub
  35. IsLoaded = True
  36. AniControlEnabled += 1
  37. Reload()
  38. SliderLoad()
  39. AniControlEnabled -= 1
  40. End Sub
  41. Public Sub Reload()
  42. '下载
  43. SliderDownloadThread.Value = Setup.Get("ToolDownloadThread")
  44. SliderDownloadSpeed.Value = Setup.Get("ToolDownloadSpeed")
  45. ComboDownloadVersion.SelectedIndex = Setup.Get("ToolDownloadVersion")
  46. ComboDownloadTranslate.SelectedIndex = Setup.Get("ToolDownloadTranslate")
  47. CheckDownloadKeepModpack.Checked = Setup.Get("ToolDownloadKeepModpack")
  48. 'Minecraft 更新提示
  49. CheckUpdateRelease.Checked = Setup.Get("ToolUpdateRelease")
  50. CheckUpdateSnapshot.Checked = Setup.Get("ToolUpdateSnapshot")
  51. '辅助设置
  52. CheckHelpChinese.Checked = Setup.Get("ToolHelpChinese")
  53. '系统设置
  54. ComboSystemUpdate.SelectedIndex = Setup.Get("SystemSystemUpdate")
  55. ComboSystemActivity.SelectedIndex = Setup.Get("SystemSystemActivity")
  56. TextSystemCache.Text = Setup.Get("SystemSystemCache")
  57. '调试选项
  58. CheckDebugMode.Checked = Setup.Get("SystemDebugMode")
  59. SliderDebugAnim.Value = Setup.Get("SystemDebugAnim")
  60. CheckDebugDelay.Checked = Setup.Get("SystemDebugDelay")
  61. CheckDebugSkipCopy.Checked = Setup.Get("SystemDebugSkipCopy")
  62. End Sub
  63. '初始化
  64. Public Sub Reset()
  65. Try
  66. Setup.Reset("ToolDownloadThread")
  67. Setup.Reset("ToolDownloadSpeed")
  68. Setup.Reset("ToolDownloadVersion")
  69. Setup.Reset("ToolDownloadTranslate")
  70. Setup.Reset("ToolDownloadKeepModpack")
  71. Setup.Reset("ToolUpdateRelease")
  72. Setup.Reset("ToolUpdateSnapshot")
  73. Setup.Reset("ToolHelpChinese")
  74. Setup.Reset("SystemDebugMode")
  75. Setup.Reset("SystemDebugAnim")
  76. Setup.Reset("SystemDebugDelay")
  77. Setup.Reset("SystemDebugSkipCopy")
  78. Setup.Reset("SystemSystemCache")
  79. Setup.Reset("SystemSystemUpdate")
  80. Setup.Reset("SystemSystemActivity")
  81. Log("[Setup] 已初始化启动器页设置")
  82. Hint("已初始化启动器页设置!", HintType.Finish, False)
  83. Catch ex As Exception
  84. Log(ex, "初始化启动器页设置失败", LogLevel.Msgbox)
  85. End Try
  86. Reload()
  87. End Sub
  88. '将控件改变路由到设置改变
  89. Private Shared Sub CheckBoxChange(sender As MyCheckBox, e As Object) Handles CheckDebugMode.Change, CheckDebugDelay.Change, CheckDebugSkipCopy.Change, CheckUpdateRelease.Change, CheckUpdateSnapshot.Change, CheckHelpChinese.Change, CheckDownloadKeepModpack.Change
  90. If AniControlEnabled = 0 Then Setup.Set(sender.Tag, sender.Checked)
  91. End Sub
  92. Private Shared Sub SliderChange(sender As MySlider, e As Object) Handles SliderDebugAnim.Change, SliderDownloadThread.Change, SliderDownloadSpeed.Change
  93. If AniControlEnabled = 0 Then Setup.Set(sender.Tag, sender.Value)
  94. End Sub
  95. Private Shared Sub ComboChange(sender As MyComboBox, e As Object) Handles ComboDownloadVersion.SelectionChanged, ComboDownloadTranslate.SelectionChanged, ComboSystemUpdate.SelectionChanged, ComboSystemActivity.SelectionChanged
  96. If AniControlEnabled = 0 Then Setup.Set(sender.Tag, sender.SelectedIndex)
  97. End Sub
  98. Private Shared Sub TextBoxChange(sender As MyTextBox, e As Object) Handles TextSystemCache.ValidatedTextChanged
  99. If AniControlEnabled = 0 Then Setup.Set(sender.Tag, sender.Text)
  100. End Sub
  101. '滑动条
  102. Private Sub SliderLoad()
  103. SliderDownloadThread.GetHintText = Function(Value As Integer)
  104. Return Value + 1
  105. End Function
  106. SliderDownloadSpeed.GetHintText = Function(Value As Integer)
  107. If Value <= 14 Then
  108. Return (Value + 1) * 0.1 & " M/s"
  109. ElseIf Value <= 31 Then
  110. Return (Value - 11) * 0.5 & " M/s"
  111. ElseIf Value <= 41 Then
  112. Return (Value - 21) & " M/s"
  113. Else
  114. Return "无限制"
  115. End If
  116. End Function
  117. SliderDebugAnim.GetHintText = Function(Value As Integer)
  118. Return If(Value > 29, "关闭", (Value / 10 + 0.1) & "x")
  119. End Function
  120. End Sub
  121. Private Sub SliderDownloadThread_PreviewChange(sender As Object, e As RouteEventArgs) Handles SliderDownloadThread.PreviewChange
  122. If SliderDownloadThread.Value < 100 Then Exit Sub
  123. If Not Setup.Get("HintDownloadThread") Then
  124. Setup.Set("HintDownloadThread", True)
  125. MyMsgBox("如果设置过多的下载线程,可能会导致下载时出现非常严重的卡顿。" & vbCrLf &
  126. "一般设置 64 线程即可满足大多数下载需求,除非你知道你在干什么,否则不建议设置更多的线程数!", "警告", "我知道了", IsWarn:=True)
  127. End If
  128. End Sub
  129. '调试模式
  130. Private Sub CheckDebugMode_Change() Handles CheckDebugMode.Change
  131. If AniControlEnabled = 0 Then Hint("部分调试信息将在刷新或启动器重启后切换显示!",, False)
  132. End Sub
  133. '清理缓存
  134. Private IsClearingCache As Boolean = False
  135. Private Sub BtnSystemCacheClear_Click(sender As Object, e As EventArgs) Handles BtnSystemCacheClear.Click
  136. If HasDownloadingTask() Then
  137. Hint("请在所有下载任务完成后再清理缓存!", HintType.Critical)
  138. Exit Sub
  139. End If
  140. If MyMsgBox("你确定要清理缓存吗?" & vbCrLf & "在清理缓存后,PCL2 会被强制关闭,以避免缓存缺失带来的异常。", "清理缓存", "确定", "取消") = 2 Then
  141. Exit Sub
  142. End If
  143. If IsClearingCache Then Exit Sub
  144. IsClearingCache = True
  145. Try
  146. Dim TotalSize As ULong = DeleteCacheDirectory(PathTemp)
  147. If TotalSize <= 0 Then
  148. Hint("没有可清理的缓存!")
  149. Else
  150. MyMsgBox("已清理 " & GetString(TotalSize) & " 缓存!" & vbCrLf & "PCL2 即将自动关闭。", "缓存已清理", ForceWait:=True)
  151. FrmMain.EndProgram(False)
  152. End If
  153. Catch ex As Exception
  154. Log(ex, "清理缓存失败", LogLevel.Hint)
  155. Finally
  156. IsClearingCache = False
  157. End Try
  158. End Sub
  159. Private Function DeleteCacheDirectory(Path As String, Optional TotalSize As ULong = 0) As ULong
  160. If Not Directory.Exists(Path) Then Return TotalSize
  161. Dim Temp As String()
  162. Temp = Directory.GetFiles(Path)
  163. For Each str As String In Temp
  164. Try
  165. Dim Info As New FileInfo(str)
  166. Dim FileActualSize = Math.Ceiling(Info.Length / 4096) * 4096
  167. Info.Delete()
  168. TotalSize += FileActualSize
  169. Catch ex As Exception
  170. Log(ex, "删除失败的缓存文件(" & str & ")")
  171. End Try
  172. Next
  173. Temp = Directory.GetDirectories(Path)
  174. For Each str As String In Temp
  175. TotalSize += DeleteCacheDirectory(str)
  176. Next
  177. Return TotalSize
  178. End Function
  179. '自动更新
  180. Private Sub ComboSystemActivity_SizeChanged(sender As Object, e As SelectionChangedEventArgs) Handles ComboSystemActivity.SelectionChanged
  181. If AniControlEnabled <> 0 Then Exit Sub
  182. If ComboSystemActivity.SelectedIndex = 2 Then
  183. If MyMsgBox("若选择此项,即使在将来出现严重问题时,你也无法获取相关通知。" & vbCrLf &
  184. "例如,如果发现某个版本游戏存在严重 Bug,你可能就会因为无法得到通知而导致无法预知的后果。" & vbCrLf & vbCrLf &
  185. "一般选择 仅在有重要通知时显示公告 就可以让你尽量不受打扰了。" & vbCrLf &
  186. "除非你在制作服务器整合包,或时常手动更新启动器,否则极度不推荐选择此项!", "警告", "继续", "取消") = 2 Then
  187. ComboSystemActivity.SelectedItem = e.RemovedItems(0)
  188. End If
  189. End If
  190. End Sub
  191. Private Sub ComboSystemUpdate_SizeChanged(sender As Object, e As SelectionChangedEventArgs) Handles ComboSystemUpdate.SelectionChanged
  192. If AniControlEnabled <> 0 Then Exit Sub
  193. If ComboSystemUpdate.SelectedIndex = 3 Then
  194. If MyMsgBox("若选择此项,即使在启动器将来出现严重问题时,你也无法获取更新并获得修复。" & vbCrLf &
  195. "例如,如果官方修改了登录方式,从而导致现有启动器无法登录,你可能就会因为无法更新而无法开始游戏。" & vbCrLf & vbCrLf &
  196. "一般选择 仅在有重大漏洞更新时显示提示 就可以让你尽量不受打扰了。" & vbCrLf &
  197. "除非你在制作服务器整合包,或时常手动更新启动器,否则极度不推荐选择此项!", "警告", "继续", "取消") = 2 Then
  198. ComboSystemUpdate.SelectedItem = e.RemovedItems(0)
  199. End If
  200. End If
  201. End Sub
  202. Private Sub BtnSystemUpdate_Click(sender As Object, e As EventArgs) Handles BtnSystemUpdate.Click
  203. UpdateCheckByButton()
  204. End Sub
  205. ''' <summary>
  206. ''' 启动器是否已经是最新版?
  207. ''' 若返回 Nothing,则代表无更新缓存文件或出错。
  208. ''' </summary>
  209. Public Shared Function IsLauncherNewest() As Boolean?
  210. Try
  211. '确认服务器公告是否正常
  212. Dim ServerContent As String = ReadFile(PathTemp & "Cache\Notice.cfg")
  213. If ServerContent.Split("|").Count < 3 Then Return Nothing
  214. '确认是否为最新
  215. #If BETA Then
  216. Dim NewVersionCode As Integer = ServerContent.Split("|")(2)
  217. #Else
  218. Dim NewVersionCode As Integer = ServerContent.Split("|")(1)
  219. #End If
  220. Return NewVersionCode <= VersionCode
  221. Catch ex As Exception
  222. Log(ex, "确认启动器更新失败", LogLevel.Feedback)
  223. Return Nothing
  224. End Try
  225. End Function
  226. End Class