initial commit
This commit is contained in:
173
ModpackUpdater/Form1.vb
Normal file
173
ModpackUpdater/Form1.vb
Normal file
@@ -0,0 +1,173 @@
|
||||
Imports System.IO
|
||||
|
||||
Imports ModpackUpdater.My.Resources
|
||||
|
||||
Imports Telerik.WinControls.UI
|
||||
|
||||
Public Class Form1
|
||||
|
||||
Private updateConfig As New UpdateConfig
|
||||
Private currentUpdating As Boolean = False
|
||||
|
||||
Public Sub New()
|
||||
InitializeComponent()
|
||||
End Sub
|
||||
|
||||
Private Function IsMinecaftProfileLoaded() As Boolean
|
||||
Return Not String.IsNullOrEmpty(GetMinecraftProfilePath)
|
||||
End Function
|
||||
|
||||
Private Function GetMinecraftProfilePath() As string
|
||||
Return RadTextBoxControl_MinecraftProfileFolder.Text.Trim
|
||||
End Function
|
||||
|
||||
Private Function IsUpdateConfigLoaded() As Boolean
|
||||
Return Not String.IsNullOrEmpty(GetUpdateconfigPath)
|
||||
End Function
|
||||
|
||||
Private Function GetUpdateconfigPath() As string
|
||||
Return RadTextBoxControl_ModpackConfig.Text.Trim
|
||||
End Function
|
||||
|
||||
Private Function CheckStatus() As Boolean
|
||||
If Not IsMinecaftProfileLoaded() OrElse Not MinecraftProfileChecker.CheckProfile(GetMinecraftProfilePath) Then
|
||||
SetStatus(LangRes.StatusText_MinecraftProfileWarning, MySymbols.icons8_general_warning_sign_16px)
|
||||
CheckStatus = False
|
||||
ElseIf Not IsUpdateConfigLoaded() Then
|
||||
SetStatus(LangRes.StatusText_MinecraftProfileWarning, MySymbols.icons8_general_warning_sign_16px)
|
||||
CheckStatus = False
|
||||
Else
|
||||
CheckStatus = True
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Sub SetStatus(statusText As string, image As Image)
|
||||
RadLabel_Status.Text = statusText
|
||||
RadLabel_Status.Image = image
|
||||
End Sub
|
||||
|
||||
Private Sub ClearStatus()
|
||||
RadLabel_Status.Text = "-"
|
||||
RadLabel_Status.Image = Nothing
|
||||
End Sub
|
||||
|
||||
Private Sub LoadMinecraftProfile(folderPath As string)
|
||||
RadTextBoxControl_MinecraftProfileFolder.Text = folderPath
|
||||
|
||||
If IsUpdateConfigLoaded() Then
|
||||
RadButton_CheckForUpdates.PerformClick()
|
||||
Else
|
||||
ClearStatus()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub LoadUpdateConfigFile(filePath As string)
|
||||
RadTextBoxControl_ModpackConfig.Text = filePath
|
||||
|
||||
If IsUpdateConfigLoaded() Then
|
||||
updateConfig = UpdateConfig.LoadFromFile(filePath)
|
||||
End If
|
||||
|
||||
If IsMinecaftProfileLoaded() Then
|
||||
RadButton_CheckForUpdates.PerformClick()
|
||||
Else
|
||||
ClearStatus()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Async Function ExecuteUpdate(allowInstall As Boolean) As Task
|
||||
SetStatus(LangRes.StatusText_CheckingForUpdates, MySymbols.icons8_update_16px)
|
||||
|
||||
Dim updater As New UpdateInstaller(updateConfig, GetMinecraftProfilePath)
|
||||
AddHandler updater.InstallProgessUpdated, AddressOf Update_InstallProgessUpdated
|
||||
AddHandler updater.CheckingProgressUpdated, AddressOf Updated_CheckingProgresssUpdated
|
||||
|
||||
Dim result As UpdateCheckResult = Await updater.CheckForUpdates(True)
|
||||
Dim everytingOk As Boolean = False
|
||||
|
||||
If result Is Nothing Then
|
||||
SetStatus(LangRes.StatusText_ErrorWhileUpdateCheckOrUpdate, MySymbols.icons8_delete_16px)
|
||||
ElseIf result.HasUpdates Then
|
||||
SetStatus(LangRes.StatusText_UpdateAvailable, MySymbols.icons8_software_installer_16px)
|
||||
|
||||
If allowInstall Then
|
||||
currentUpdating = True
|
||||
SetStatus(LangRes.StatusText_Installing, MySymbols.icons8_software_installer_16px)
|
||||
|
||||
If Await updater.InstallUpdates(result) Then
|
||||
everytingOk = True
|
||||
End If
|
||||
|
||||
currentUpdating = False
|
||||
End If
|
||||
Else
|
||||
everytingOk = True
|
||||
End If
|
||||
|
||||
If everytingOk Then
|
||||
SetStatus(LangRes.StatusTest_EverythingOk, MySymbols.icons8_checkmark_16px)
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Sub Update_InstallProgessUpdated(result As UpdateCheckResult, processedSyncs As Integer)
|
||||
SetStatus(Math.Round(processedSyncs / result.SyncFiles.Count * 100, 1) & "%", MySymbols.icons8_software_installer_16px)
|
||||
End Sub
|
||||
|
||||
Private Sub Updated_CheckingProgresssUpdated(toCheck As Integer, processed As Integer)
|
||||
SetStatus(Math.Round(processed / toCheck * 100, 1) & "%", MySymbols.icons8_update_16px)
|
||||
End Sub
|
||||
|
||||
Private Sub ButtonX_SearchMinecraftProfile_Click(sender As Object, e As EventArgs) Handles RadButton_SearchMinecraftProfileFolder.Click
|
||||
Dim ofd As New RadOpenFolderDialog
|
||||
|
||||
If ofd.ShowDialog(Me) = DialogResult.OK Then
|
||||
LoadMinecraftProfile(ofd.FileName)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub ButtonX_SearchUpdateConfig_Click(sender As Object, e As EventArgs) Handles RadButton_SearchModpackConfig.Click
|
||||
Dim ofd As New RadOpenFileDialog
|
||||
ofd.Filter = FiledialogFilters.JSON_Display & "|" & FiledialogFilters.JSON_Filter
|
||||
|
||||
If ofd.ShowDialog(Me) = DialogResult.OK Then
|
||||
LoadUpdateConfigFile(ofd.FileName)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub ButtonX_EditUpdateConfig_Click(sender As Object, e As EventArgs) Handles RadButton_EditModpackConfig.Click
|
||||
Dim frm As New FormSettings(updateConfig)
|
||||
frm.ShowDialog(Me)
|
||||
End Sub
|
||||
|
||||
Private Async Sub ButtonX_CheckForUpdates_Click(sender As Object, e As EventArgs) Handles RadButton_CheckForUpdates.Click
|
||||
ClearStatus()
|
||||
If CheckStatus() Then
|
||||
Await ExecuteUpdate(False)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Async Sub ButtonX_StartUpdate_Click(sender As Object, e As EventArgs) Handles RadButton_Install.Click
|
||||
If Not currentUpdating Then
|
||||
ClearStatus()
|
||||
If CheckStatus() Then
|
||||
Await ExecuteUpdate(True)
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
|
||||
AppConfig.Instance.LastMinecraftProfilePath = RadTextBoxControl_MinecraftProfileFolder.Text
|
||||
AppConfig.Instance.LastConfigFilePath = RadTextBoxControl_ModpackConfig.Text
|
||||
AppConfig.Instance.SaveConfig()
|
||||
End Sub
|
||||
|
||||
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
|
||||
If Directory.Exists(AppConfig.Instance.LastMinecraftProfilePath) Then
|
||||
LoadMinecraftProfile(AppConfig.Instance.LastMinecraftProfilePath)
|
||||
End If
|
||||
If File.Exists(AppConfig.Instance.LastConfigFilePath) Then
|
||||
LoadUpdateConfigFile(AppConfig.Instance.LastConfigFilePath)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user