PageSetupSystem.xaml.vb 12 KB

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