PageLaunchRight.xaml.vb 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. Public Class PageLaunchRight
  2. Private Sub Init() Handles Me.Loaded
  3. PanBack.ScrollToHome()
  4. PanLog.Visibility = If(ModeDebug, Visibility.Visible, Visibility.Collapsed)
  5. '刷新主页
  6. If ShouldRefresh Then
  7. ShouldRefresh = False
  8. RefreshCustom()
  9. End If
  10. '快照版提示
  11. #If BETA Then
  12. PanHint.Visibility = Visibility.Collapsed
  13. #Else
  14. PanHint.Title = "快照版提示"
  15. PanHint.Visibility = If(ThemeCheckGold(), Visibility.Collapsed, Visibility.Visible)
  16. LabHint1.Text = "快照版包含尚未在正式版发布的测试性功能,仅用于赞助者本人尝鲜。所以请不要发给其他人或者用于制作整合包哦!如果发现了 Bug,可以在 更多 → 反馈 中提交!"
  17. LabHint2.Text = "你可以通过赞助¥23.33 档位换取解锁码来隐藏这个提示。"
  18. #End If
  19. End Sub
  20. Private LatestFileContent As String = ""
  21. Private LatestFileLink As String = Nothing
  22. Private IsRefreshing As Boolean = False
  23. Public ShouldRefresh As Boolean = True
  24. ''' <summary>
  25. ''' 刷新自定义的主页。返回是否成功。
  26. ''' </summary>
  27. Private Sub RefreshCustom()
  28. If IsRefreshing Then
  29. ShouldRefresh = True
  30. Exit Sub
  31. End If
  32. Try
  33. IsRefreshing = True
  34. PanCustom.Children.Clear()
  35. RunInNewThread(Sub()
  36. Dim FileContent As String = ""
  37. Select Case Setup.Get("UiCustomType")
  38. Case 0
  39. '啥也不干
  40. Case 1
  41. '加载本地文件
  42. FileContent = ReadFile(Path & "PCL\Custom.xaml") 'ReadFile 会进行存在检测
  43. Log("[System] 尝试从本地文件读取主页自定义数据(" & FileContent.Length & ")")
  44. Case 2
  45. '加载联网文件
  46. Try
  47. Dim Link As String = Setup.Get("UiCustomNet")
  48. If Link = LatestFileLink Then
  49. FileContent = LatestFileContent
  50. Log("[System] 尝试缓存加载主页自定义数据(" & FileContent.Length & ")")
  51. ElseIf Not String.IsNullOrWhiteSpace(Link) Then
  52. Log("[System] 开始从网络读取主页自定义数据(" & Link & ")")
  53. FileContent = NetGetCodeByRequestRetry(Link)
  54. Log("[System] 尝试从网络读取主页自定义数据(" & FileContent.Length & ")")
  55. End If
  56. LatestFileLink = Link
  57. LatestFileContent = FileContent
  58. Catch ex As Exception
  59. Log(ex, "获取 PCL2 主页自定义信息失败", LogLevel.Msgbox)
  60. LatestFileLink = ""
  61. End Try
  62. End Select
  63. If FileContent = "" Then
  64. IsRefreshing = False
  65. Exit Sub
  66. End If
  67. FileContent = "<StackPanel xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:local=""clr-namespace:PCL;assembly=Plain Craft Launcher 2"">" & FileContent & "</StackPanel>"
  68. FileContent = FileContent.Replace("{path}", Path)
  69. RunInUi(Sub()
  70. Try
  71. Log("[System] 加载主页自定义数据")
  72. PanCustom.Children.Add(GetObjectFromXML(FileContent))
  73. IsRefreshing = False
  74. Catch ex As Exception
  75. IsRefreshing = False
  76. Log("[System] 自定义信息内容:" & vbCrLf & FileContent)
  77. If MyMsgBox(ex.Message, "加载自定义主页失败", "重试", "取消") = 1 Then
  78. LatestFileLink = Nothing
  79. LatestFileContent = ""
  80. RefreshCustom()
  81. End If
  82. End Try
  83. End Sub)
  84. End Sub, "主页自定义刷新")
  85. Catch ex As Exception
  86. Log(ex, "加载 PCL2 主页自定义信息失败", LogLevel.Msgbox)
  87. IsRefreshing = False
  88. End Try
  89. End Sub
  90. Public Sub ForceRefresh(Optional ShowHint As Boolean = True)
  91. ShouldRefresh = True
  92. LatestFileContent = ""
  93. LatestFileLink = Nothing
  94. If ShowHint Then Hint("已刷新主页!", HintType.Finish)
  95. FrmMain.PageChange(FormMain.PageType.Launch)
  96. Init()
  97. End Sub
  98. Public Shared Sub StartMigration()
  99. MyMsgBox("在迁移过程中,你可能需要设置你的档案信息,此时请注意让年龄大于 18 岁,否则可能导致无法登录!" & vbCrLf &
  100. "在迁移完成后,请在上方选择 微软 登录方式而非 Mojang。", "迁移提示", "继续", ForceWait:=True)
  101. OpenWebsite("https://www.minecraft.net/zh-hans/account-security")
  102. End Sub
  103. End Class