Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO
- Imports System.Text
- Imports System.Runtime.InteropServices
- Public Class MainWindow
- 'SHARED VARIABLES
- Dim modsfile As String = Application.StartupPath & "/mods.cfg"
- Dim oProcess As New Process()
- 'MAIN WINDOW
- Private Sub MainWindow_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- If My.Settings.firstRun Then
- Dim firstRunDialog As New firstRun
- firstRunDialog.ShowDialog()
- Else
- steamDirBox.Text = My.Settings.steamDir
- serverDirBox.Text = My.Settings.serverDir
- userNameBox.Text = My.Settings.userName
- userPassBox.Text = My.Settings.userPass
- branchCombo.Text = My.Settings.selectedBranch
- If My.Settings.installedBranch = "" Then
- infoBranchBox.Text = "N/A"
- Else
- infoBranchBox.Text = My.Settings.installedBranch
- End If
- If My.Settings.lastUpdated = "00:00:00" Then
- infoUpdatedBox.Text = "N/A"
- Else
- infoUpdatedBox.Text = My.Settings.lastUpdated
- End If
- End If
- UpdateModGrid()
- End Sub
- Private Sub MainWindow_Close(sender As Object, e As EventArgs) Handles MyBase.Closed
- Try
- oProcess.Kill()
- Catch ex As Exception
- End Try
- End Sub
- Private Sub InstallCMDToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles InstallCMDToolStripMenuItem.Click
- Dim installSteam As New installSteamCMD
- installSteam.ShowDialog()
- End Sub
- Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
- Me.Close()
- End Sub
- Private Sub OpenSteamCMDDirToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenSteamCMDDirToolStripMenuItem.Click
- Process.Start(My.Settings.steamDir)
- End Sub
- Private Sub OpenA3DirectoryToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenA3DirectoryToolStripMenuItem.Click
- Process.Start(My.Settings.serverDir)
- End Sub
- Private Sub OpenModsLocationToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenModsLocationToolStripMenuItem.Click
- Try
- Process.Start(My.Settings.steamDir & "\steamapps\workshop\content\107410")
- Catch ex As Exception
- MessageBox.Show("No MODS currently installed in the for the selected steam install.", "Information")
- MsgBox("An exception occurred:" & vbCrLf & ex.Message)
- End Try
- End Sub
- 'MAIN TAB
- Private Sub SteamDirSelect_Click(sender As Object, e As EventArgs) Handles steamDirButton.Click
- ChooseSteamDir()
- End Sub
- Private Sub CancelUpdateButton_Click(sender As Object, e As EventArgs) Handles cancelUpdateButton.Click
- oProcess.Kill()
- steamOutputBox.Text = "Process Cancelled" & Environment.NewLine
- End Sub
- Private Sub ShowUserPassButton_Click(sender As Object, e As EventArgs) Handles showUserPassButton.Click
- If userPassBox.PasswordChar = "*" Then
- userPassBox.PasswordChar = ""
- showUserPassButton.BackgroundImage = My.Resources.Invisible_32px
- Else
- userPassBox.PasswordChar = "*"
- showUserPassButton.BackgroundImage = My.Resources.Visible_32px
- End If
- End Sub
- Private Sub UpdateServer(sender As Object, e As EventArgs) Handles updateServerButton.Click
- Dim branchId As String
- Dim steamCommand As String
- Dim steamCMD As String = steamDirBox.Text + "\steamcmd.exe"
- If branchCombo.SelectedItem = "Stable" Then
- branchId = "233780"
- Else
- branchId = "107410 -beta development"
- End If
- steamCommand = "+login " & userNameBox.Text & " " & userPassBox.Text & " +force_install_dir " & serverDirBox.Text & " +app_update " & branchId & " validate +quit"
- My.Settings.installedBranch = branchCombo.SelectedItem
- infoBranchBox.Text = branchCombo.SelectedItem
- My.Settings.lastUpdated = DateTime.Now
- infoUpdatedBox.Text = My.Settings.lastUpdated.ToString
- RunSteamCommand(steamCMD, steamCommand, "server")
- End Sub
- Private Sub ServerDirButton_Click(sender As Object, e As EventArgs) Handles serverDirButton.Click
- ChooseServerDir()
- End Sub
- Private Sub SteamDirBox_TextChanged(sender As Object, e As EventArgs) Handles steamDirBox.TextChanged
- steamDirBox.BackColor = Color.Empty
- My.Settings.steamDir = steamDirBox.Text
- End Sub
- Private Sub UserNameBox_TextChanged(sender As Object, e As EventArgs) Handles userNameBox.TextChanged
- userNameBox.BackColor = Color.Empty
- My.Settings.userName = userNameBox.Text
- End Sub
- Private Sub UserPassBox_TextChanged(sender As Object, e As EventArgs) Handles userPassBox.TextChanged
- userPassBox.BackColor = Color.Empty
- My.Settings.userPass = userPassBox.Text
- End Sub
- Private Sub BranchCombo_SelectedValueChanged(sender As Object, e As EventArgs) Handles branchCombo.SelectedValueChanged
- My.Settings.selectedBranch = branchCombo.Text
- If My.Settings.selectedBranch = "Development" Then
- MessageBox.Show("WARNING - Due to the A3 Dev branch server using the main game you will also download all Workshop Items for A3 that you are subscribed to on the Steam account you are currently logged into. These mods will be auto detected and added to the mods tab.", "WARNING - Dev Branch")
- End If
- End Sub
- Private Sub ServerDirBox_TextChanged(sender As Object, e As EventArgs) Handles serverDirBox.TextChanged
- serverDirBox.BackColor = Color.Empty
- My.Settings.serverDir = serverDirBox.Text
- End Sub
- Public Sub ChooseSteamDir()
- If steamDirDialog.ShowDialog() = DialogResult.OK Then
- steamDirBox.Text = steamDirDialog.SelectedPath
- End If
- End Sub
- Public Sub ChooseServerDir()
- If serverDirDialog.ShowDialog() = DialogResult.OK Then
- serverDirBox.Text = serverDirDialog.SelectedPath
- End If
- End Sub
- 'MODS TAB
- Private Sub ImportMod_Click(sender As Object, e As EventArgs) Handles modUrlButton.Click
- Dim importDiaglog As New ImportMod
- importDiaglog.ShowDialog()
- End Sub
- Private Sub ModLauncherButton_Click(sender As Object, e As EventArgs) Handles modLauncherButton.Click
- ImportModSetFile()
- End Sub
- Private Sub ModsDataGrid_CellContentClick(sender As System.Object, e As DataGridViewCellEventArgs) Handles modsDataGrid.CellContentClick
- Dim senderGrid = DirectCast(sender, DataGridView)
- 'UPDATE MOD
- If TypeOf senderGrid.Columns(e.ColumnIndex) Is DataGridViewButtonColumn AndAlso e.ColumnIndex = 4 Then
- Dim modID As String = modsDataGrid.Rows(e.RowIndex).Cells(0).Value
- Dim modName As String = modsDataGrid.Rows(e.RowIndex).Cells(1).Value
- UpdateMod(modID, modName)
- End If
- 'VIEW DETAILS
- If TypeOf senderGrid.Columns(e.ColumnIndex) Is DataGridViewButtonColumn AndAlso e.ColumnIndex = 5 Then
- Dim url As String = "http://steamcommunity.com/sharedfiles/filedetails/?id=" & modsDataGrid.Rows(e.RowIndex).Cells(0).Value
- Process.Start(url)
- End If
- 'DELETE BUTTON
- If TypeOf senderGrid.Columns(e.ColumnIndex) Is DataGridViewButtonColumn AndAlso e.ColumnIndex = 6 Then
- Dim modID As Integer = modsDataGrid.Rows(e.RowIndex).Cells(0).Value
- Dim modName As String = modsDataGrid.Rows(e.RowIndex).Cells(1).Value
- DeleteMod(modID, modName)
- End If
- End Sub
- Public Sub ImportModSetFile()
- If importModSet.ShowDialog() = DialogResult.OK Then
- Dim modSetFile As String = importModSet.FileName
- Dim dataReader As New StreamReader(modSetFile, Encoding.Default)
- Dim modLine As String
- Do
- modLine = dataReader.ReadLine
- If modLine Is Nothing Then Exit Do
- Dim values() As String = modLine.Split(Environment.NewLine)
- If modLine.Contains("data-type=""Link"">") Then
- Dim link As String
- link = modLine.Substring(modLine.IndexOf("http://steam"))
- link = StrReverse(link)
- link = link.Substring(link.IndexOf("epyt-atad") + 11)
- link = StrReverse(link)
- ImportMod.ImportModToList(link)
- End If
- Loop
- dataReader.Close()
- End If
- End Sub
- Public Sub UpdateModGrid()
- modsDataGrid.Rows.Clear()
- Try
- If My.Computer.FileSystem.FileExists(modsfile) Then
- Dim dataReader As New StreamReader(modsfile, Encoding.Default)
- Dim modLine As String
- Do
- modLine = dataReader.ReadLine
- If modLine Is Nothing Then Exit Do
- Dim values() As String = modLine.Split(",")
- modsDataGrid.Rows.Add("")
- For ix As Integer = 0 To 2
- modsDataGrid.Rows(modsDataGrid.Rows.Count - 1).Cells(ix).Value = values(ix)
- Next
- Loop
- dataReader.Close()
- End If
- Catch ex As Exception
- MsgBox("An exception occurred:" & vbCrLf & ex.Message)
- End Try
- End Sub
- Public Sub UpdateMod(modID As String, modName As String)
- Dim steamCommand As String
- Dim steamCMD As String = steamDirBox.Text + "\steamcmd.exe"
- Dim modPath As String = My.Settings.steamDir & "\steamapps\workshop\content\107410\" & modID
- steamCommand = "+login " & userNameBox.Text & " " & userPassBox.Text & " +workshop_download_item 107410 " & modID & " validate +quit"
- Try
- 'C:\mklink /D C:\TestFolder C:\Users\Geek\TestFolder
- Dim linkCommand As String
- Dim linkPath As String = My.Settings.serverDir & "\@" & modName
- linkCommand = "/c mklink /D " & linkPath & " " & modPath
- Dim oStartInfo As New ProcessStartInfo("cmd", linkCommand)
- oStartInfo.CreateNoWindow = True
- oStartInfo.WindowStyle = ProcessWindowStyle.Hidden
- oProcess.StartInfo = oStartInfo
- oProcess.Start()
- Catch ex As Exception
- MsgBox("An exception occurred:" & vbCrLf & ex.Message)
- End Try
- RunSteamCommand(steamCMD, steamCommand, "addon")
- End Sub
- Public Sub DeleteMod(modID As String, modName As String)
- Dim modPath As String = My.Settings.steamDir & "\steamapps\workshop\content\107410\" & modID
- Dim workshopFile As String = My.Settings.steamDir & "\steamapps\workshop\appworkshop_107410.acf"
- Dim shortcutPath As String = My.Settings.serverDir & "\@" & modName & ".lnk"
- Dim lines As List(Of String) = System.IO.File.ReadAllLines(modsfile).ToList
- lines.RemoveAt(GetLineNo(modID, modsfile) - 1)
- System.IO.File.WriteAllLines(modsfile, lines)
- Try
- Dim lines2 As List(Of String) = System.IO.File.ReadAllLines(workshopFile).ToList
- Dim startLine As Integer = GetLineNo(modID, workshopFile) - 1
- lines2.RemoveRange(startLine, 6)
- System.IO.File.WriteAllLines(workshopFile, lines2)
- Catch ex As Exception
- MsgBox("An exception occurred:" & vbCrLf & ex.Message)
- End Try
- UpdateModGrid()
- Try
- System.IO.Directory.Delete(modPath, True)
- System.IO.File.Delete(shortcutPath)
- Catch ex As Exception
- MsgBox("An exception occurred:" & vbCrLf & ex.Message)
- End Try
- End Sub
- 'SHARED
- Public Function GetLineNo(target As String, targetFile As String)
- Dim count As Integer
- For Each line As String In System.IO.File.ReadLines(targetFile)
- count = count + 1
- If line.Contains(target) Then Return count
- Next
- Return ""
- End Function
- Public Function ReadyToUpdate() As Boolean
- If steamDirBox.Text = "" Then
- Return False
- ElseIf userNameBox.Text = "" Then
- Return False
- ElseIf userPassBox.Text = "" Then
- Return False
- ElseIf serverDirBox.Text = "" Then
- Return False
- Else
- Return True
- End If
- End Function
- Public Async Sub RunSteamCommand(steamCMD As String, steamCommand As String, type As String)
- If ReadyToUpdate() Then
- steamProgressBar.Value = 0
- cancelUpdateButton.Enabled = True
- categoryTabs.SelectedTab = serverTab
- Dim tasks As New List(Of Task)()
- updateServerButton.Enabled = False
- modsDataGrid.Enabled = False
- If type Is "addon" Then
- steamOutputBox.Text = "Starting SteamCMD to update Addon" & Environment.NewLine
- ElseIf type Is "server" Then
- steamOutputBox.Text = "Starting SteamCMD to update Server" & Environment.NewLine
- Else
- End If
- tasks.Add(Task.Run(
- Sub()
- Dim oStartInfo As New ProcessStartInfo(steamCMD, steamCommand)
- oStartInfo.CreateNoWindow = True
- oStartInfo.WindowStyle = ProcessWindowStyle.Hidden
- oStartInfo.UseShellExecute = False
- oStartInfo.RedirectStandardOutput = True
- oProcess.StartInfo = oStartInfo
- oProcess.Start()
- Dim sOutput As String
- Using oStreamReader As System.IO.StreamReader = oProcess.StandardOutput
- Do Until oProcess.HasExited
- Try
- sOutput = oStreamReader.ReadLine
- If sOutput Like "*Update state*" Then
- Dim counter As Integer = sOutput.IndexOf(":")
- Dim progress As String = sOutput.Substring(counter + 2, 2)
- Dim progressValue As Integer
- If progress.Contains(".") Then
- progressValue = progress.Substring(0, 1)
- Else
- progressValue = progress
- End If
- steamProgressBar.Invoke(
- Sub()
- steamProgressBar.Value = progressValue
- End Sub
- )
- End If
- If sOutput Like "*Success*" Then
- steamProgressBar.Invoke(
- Sub()
- steamProgressBar.Value = 100
- End Sub
- )
- End If
- steamOutputBox.Invoke(
- Sub()
- steamOutputBox.AppendText(sOutput & Environment.NewLine)
- steamOutputBox.SelectionStart = steamOutputBox.Text.Length
- steamOutputBox.ScrollToCaret()
- End Sub
- )
- Catch ex As Exception
- MsgBox("An exception occurred:" & vbCrLf & ex.Message)
- End Try
- Loop
- End Using
- End Sub
- ))
- Await Task.WhenAll(tasks)
- steamOutputBox.Text = steamOutputBox.Text.TrimEnd
- modsDataGrid.Enabled = True
- cancelUpdateButton.Enabled = False
- updateServerButton.Enabled = True
- Else
- MessageBox.Show("Please check all fields are correct:" & Environment.NewLine & Environment.NewLine & " - Steam Dir" & Environment.NewLine & " - User Name & Pass" & Environment.NewLine & " - Server Dir", "Error")
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement