'WSZSTools - GUI, GUI to handle Wiimms SZS Tools 'Copyright (C) 2011 VulcSoft 'This program is free software: you can redistribute it and/or modify 'it under the terms of the GNU General Public License as published by 'the Free Software Foundation, either version 3 of the License, or '(at your option) any later version. 'This program is distributed in the hope that it will be useful, 'but WITHOUT ANY WARRANTY; without even the implied warranty of 'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 'GNU General Public License for more details. 'You should have received a copy of the GNU General Public License 'along with this program. If not, see . Public Class frmMain ' ---- Public Variables ---- ' Configuration Public Shared Configured As Boolean = False Public Shared WSZSTPath As String Public Shared ConfigLines() As String ' General Open Template, public variables Public Shared OpenFileName As String Public Shared OpenExtension As String Public Shared OpenTemp As String Public Shared OpenTempUnix As String ' General Save Template, public variables Public Shared SaveExtension As String Public Shared CombiExt As String Public Shared SaveRUnix As String ' ---- End Public Variables ---- Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load WSZSTPath = My.Settings.WSZSTPath Configured = My.Settings.Configured If Configured = True Then lblConfiguredtest2.Text = "Yes" lblConfiguredtest2.Visible = True Else lblConfiguredtest2.Text = "No" lblConfiguredtest2.Visible = True End If End Sub Private Sub Reset(Optional ByVal Saveonly As Boolean = False) If Saveonly = False Then OpenFileName = "" OpenExtension = "" OpenTemp = "" OpenTempUnix = "" lblLoadFileR.Text = "None" lblInfo.Text = "" End If SaveExtension = "" CombiExt = "" SaveRUnix = "" End Sub Public Sub Shell2(ByVal FileName As String, ByVal Arguments As String) Dim ProcessInfo As New ProcessStartInfo With ProcessInfo .FileName = FileName .Arguments = Arguments End With Process.Start(ProcessInfo) End Sub Public Function CheckFolderEmpty(ByVal InputPath As String) If My.Computer.FileSystem.GetFiles(InputPath, FileIO.SearchOption.SearchAllSubDirectories, "*.*").Count = 0 Then Return True Else Return False End If End Function Private Sub OpenCopy(ByVal Variable As String) OpenTemp = "C:\temp\SZSToolsGUI\" & OpenFileName My.Computer.FileSystem.CopyFile( _ Variable, _ OpenTemp, _ Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs, _ Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing) lblLoadFileR.Text = OpenFileName End Sub Public Function Unixpathmkr(ByVal Inputvar As String) Dim UnixPathmkr1 As String Dim UnixPathmkr2 As String = "" Dim UnixPathmkr3 As String = "" Dim Outputvar As String = "" UnixPathmkr1 = Inputvar If InStr(1, UnixPathmkr1, "\") > 0 Then UnixPathmkr2 = Replace(UnixPathmkr1, "\", "/") End If If InStr(1, UnixPathmkr2, "C:/") > 0 Then Outputvar = Replace(UnixPathmkr2, "C:/", "/cygdrive/c/") End If Return Outputvar End Function ' ----- ' Open/Save code Private Sub OpenFile() Dim OpenFile As New OpenFileDialog ' Filter Settings* Dim FilterOptions1 As String Dim FilterOptions2 As String Dim FilterOptions3 As String FilterOptions1 = "Nintendo SZS Archives (*.szs)|*.szs|Nintendo KMP Files (*.kmp)|*.kmp|" FilterOptions2 = "Nintendo Text Files (*.bmg)|*.bmg|WSZST Text Files (*.txt)|*.txt" FilterOptions3 = "All Supported Formats|*.szs;*.kmp;*.bmg;*.txt|" OpenFile.Filter = FilterOptions3 & FilterOptions1 & FilterOptions2 ' End Filter settings ' Other settings* OpenFile.CheckFileExists = True ' End other settings ' Show Dialog and No cancel check Dim NoCancelCheck As Integer = OpenFile.ShowDialog() If NoCancelCheck = DialogResult.Cancel Then ' Do nothing if canceled Else Dim OpenFileResult As String = OpenFile.FileName ' *Dim OpenFileName As Public String* OpenFileName = IO.Path.GetFileName(OpenFileResult) ' Extension check* If OpenFileResult.EndsWith(".szs") Then OpenExtension = "SZS" End If If OpenFileResult.EndsWith(".kmp") Then OpenExtension = "KMP" End If If OpenFileResult.EndsWith(".bmg") Then OpenExtension = "BMG" End If If OpenFileResult.EndsWith(".txt") Then OpenExtension = "TXT" End If ' If Extension = TXT, ask what type* If OpenExtension = "TXT" Then Dim frmTXTtypeDialog As New TXTtypeDialog Dim TXTtypeD_Result As Integer = frmTXTtypeDialog.ShowDialog() If TXTtypeD_Result = 1 Then ' Canceled, reset all Reset() ElseIf TXTtypeD_Result = 2 Then ' KMP is clicked OpenExtension = "TXT/KMP" OpenCopy(OpenFileResult) lblInfo.Text = "You have opened a KMP-TXT file," & Chr(10) & "you can save it as KMP and KMP-TXT" ElseIf TXTtypeD_Result = 3 Then ' BMG is clicked OpenExtension = "TXT/BMG" OpenCopy(OpenFileResult) lblInfo.Text = "You have opened a BMG-TXT file," & Chr(10) & "you can save it as BMG and BMG-TXT" End If Else OpenCopy(OpenFileResult) If OpenExtension = "SZS" Then lblInfo.Text = "You have opened a SZS file," & Chr(10) & "you can save it as SZS file and directory" End If If OpenExtension = "KMP" Then lblInfo.Text = "You have opened a KMP file," & Chr(10) & "you can save it as KMP and KMP-TXT" End If If OpenExtension = "BMG" Then lblInfo.Text = "You have opened a BMG file," & Chr(10) & "you can save it as BMG and BMG-TXT" End If End If End If End Sub Private Sub OpenDir() Dim OpenDir As New FolderBrowserDialog ' settings* OpenDir.ShowNewFolderButton() = False ' End settings ' Show Dialog and No cancel check Dim NoCancelCheck As Integer = OpenDir.ShowDialog() If NoCancelCheck = DialogResult.Cancel Then ' Do nothing if canceled Else Reset() Dim OpenDirResult As String = OpenDir.SelectedPath ' *Dim OpenFileName As Public String* Dim OpenDirResultPD As String = My.Computer.FileSystem.GetParentPath(OpenDirResult) Dim OpenDirName As String = "" If InStr(OpenDirResult, OpenDirResultPD) Then OpenDirName = Replace(OpenDirResult, OpenDirResultPD & "\", "") End If OpenFileName = OpenDirName ' Extension check* If OpenDirResult.EndsWith(".d") Then OpenExtension = "DIR" End If ' Check if extension = DIR If OpenExtension = "DIR" Then OpenTemp = "C:\temp\SZSToolsGUI\" & OpenFileName My.Computer.FileSystem.CopyDirectory( _ OpenDirResult, _ OpenTemp, _ Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs, _ Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing) lblLoadFileR.Text = OpenFileName lblInfo.Text = "You have opened a SZS directory," & Chr(10) & "you can save it as SZS file and directory" Else MsgBox("You haven't selected a SZS Directory.") Reset() End If ' End Extension check End If End Sub Private Sub SaveFile() Dim SaveFile As New SaveFileDialog ' Filter Settings* Dim FilterOptions1 As String Dim FilterOptions2 As String Dim FilterOptions3 As String FilterOptions1 = "Nintendo SZS Archives (*.szs)|*.szs|Nintendo KMP Files (*.kmp)|*.kmp|" FilterOptions2 = "Nintendo Text Files (*.bmg)|*.bmg|WSZST Text Files (*.txt)|*.txt" FilterOptions3 = "All Supported Formats|*.szs;*.kmp;*.bmg;*.txt|" SaveFile.Filter = FilterOptions3 & FilterOptions1 & FilterOptions2 ' End Filter settings ' Other Settings* SaveFile.OverwritePrompt = True ' End other settings ' Show Dialog and No cancel check Dim NoCancelCheck As Integer = SaveFile.ShowDialog() If NoCancelCheck = DialogResult.Cancel Then ' Do nothing if canceled Else Dim SaveFileResult As String = SaveFile.FileName ' Extension set If SaveFileResult.EndsWith(".szs") Then SaveExtension = "-SZS" End If If SaveFileResult.EndsWith(".kmp") Then SaveExtension = "-KMP" End If If SaveFileResult.EndsWith(".bmg") Then SaveExtension = "-BMG" End If If SaveFileResult.EndsWith(".txt") Then SaveExtension = "-TXT" End If ' Combination set CombiExt = OpenExtension & SaveExtension ' Check which combi: Dim Checked As Boolean ' ----- CombiExt Check ----- ' ' --- SZS to SZS --- If CombiExt = "SZS-SZS" Then OpenTempUnix = Unixpathmkr(OpenTemp) Shell2(WSZSTPath & "\wszst.exe", "NORM " & Chr(34) & OpenTempUnix & Chr(34)) My.Computer.FileSystem.CopyFile( _ OpenTemp, _ SaveFileResult, _ FileIO.UIOption.OnlyErrorDialogs, _ FileIO.UICancelOption.DoNothing) Checked = True End If ' ------------------ ' ' --- KMP to TXT --- If CombiExt = "KMP-TXT" Then SaveRUnix = Unixpathmkr(SaveFileResult) OpenTempUnix = Unixpathmkr(OpenTemp) Shell2(WSZSTPath & "\wkmpt.exe", "DEC " & Chr(34) & OpenTempUnix & Chr(34) & " -o -d " & Chr(34) & SaveRUnix & Chr(34)) Checked = True End If ' ------------------ ' ' --- BMG to TXT --- If CombiExt = "BMG-TXT" Then SaveRUnix = Unixpathmkr(SaveFileResult) OpenTempUnix = Unixpathmkr(OpenTemp) Shell2(WSZSTPath & "\wbmgt.exe", "DEC " & Chr(34) & OpenTempUnix & Chr(34) & " -o -d " & Chr(34) & SaveRUnix & Chr(34)) Checked = True End If ' ------------------ ' ' --- DIR to SZS --- If CombiExt = "DIR-SZS" Then SaveRUnix = Unixpathmkr(SaveFileResult) OpenTempUnix = Unixpathmkr(OpenTemp) Shell2(WSZSTPath & "\wszst.exe", "CREATE " & Chr(34) _ & OpenTempUnix & Chr(34) & " -o -d " & Chr(34) & SaveRUnix & Chr(34)) Checked = True End If ' ------------------ ' ' --- TXT/KMP to KMP --- If CombiExt = "TXT/KMP-KMP" Then SaveRUnix = Unixpathmkr(SaveFileResult) OpenTempUnix = Unixpathmkr(OpenTemp) Shell2(WSZSTPath & "\wkmpt.exe", "ENC " & Chr(34) & OpenTempUnix & Chr(34) & " -o -d " & Chr(34) & SaveRUnix & Chr(34)) Checked = True End If ' ---------------------- ' ' --- TXT/BMG to BMG --- If CombiExt = "TXT/BMG-BMG" Then SaveRUnix = Unixpathmkr(SaveFileResult) OpenTempUnix = Unixpathmkr(OpenTemp) Shell2(WSZSTPath & "\wbmgt.exe", "ENC " & Chr(34) & OpenTempUnix & Chr(34) & " -o -d " & Chr(34) & SaveRUnix & Chr(34)) Checked = True End If ' ---------------------- ' ' --- KMP to KMP --- If CombiExt = "KMP-KMP" Then My.Computer.FileSystem.CopyFile( _ OpenTemp, _ SaveFileResult, _ FileIO.UIOption.OnlyErrorDialogs, _ FileIO.UICancelOption.DoNothing) Checked = True End If ' ------------------ ' ' --- BMG to BMG --- If CombiExt = "BMG-BMG" Then My.Computer.FileSystem.CopyFile( _ OpenTemp, _ SaveFileResult, _ FileIO.UIOption.OnlyErrorDialogs, _ FileIO.UICancelOption.DoNothing) Checked = True End If ' --- All Checked --- ' If isn't checked, give error If Checked = False Then MsgBox("This file cant be saved as " & SaveExtension & ".") End If ' ----- End CombiExt Check ----- Reset(True) End If End Sub Private Sub SaveDir() Dim SaveDir As New FolderBrowserDialog 'Settings SaveDir.ShowNewFolderButton = True 'End Settings 'Show dialog and No cancel check Dim NoCancelCheck As Integer = SaveDir.ShowDialog() If NoCancelCheck = DialogResult.Cancel Then 'Do nothing Else Dim SaveDirResult As String = SaveDir.SelectedPath() If SaveDirResult.EndsWith(".d") = True And CheckFolderEmpty(SaveDirResult) = True Then SaveExtension = "-DIR" CombiExt = OpenExtension & SaveExtension ' Check which combi: Dim Checked As Boolean ' ----- CombiExt Check ----- ' ' --- SZS to Directory --- If CombiExt = "SZS-DIR" Then SaveRUnix = Unixpathmkr(SaveDirResult) OpenTempUnix = Unixpathmkr(OpenTemp) Shell2(WSZSTPath & "\wszst.exe", "X " & Chr(34) & OpenTempUnix & Chr(34) & " -o -a -d " & Chr(34) & SaveRUnix & Chr(34)) Checked = True End If ' ------------------------- ' ' --- Directory to Directory --- If CombiExt = "DIR-DIR" Then My.Computer.FileSystem.CopyDirectory( _ OpenTemp, _ SaveDirResult, _ FileIO.UIOption.OnlyErrorDialogs, FileIO.UICancelOption.DoNothing) Checked = True End If ' ------------------------------ ' ' --- All Checked --- ' If isn't checked give error If Checked = False Then MsgBox("This file cant be saved as a Directory.") End If ' ----- End CombiExt Check ----- Reset(True) Else MsgBox("The name of a SZS Directory should end with [.d], and the folder should be empty") Reset(True) End If End If End Sub ' ----- ' Buttons with code Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click Dim R_exit As MsgBoxResult R_exit = MsgBox("Are you sure you want to Exit SZS Tools?", _ MsgBoxStyle.Question + MsgBoxStyle.YesNo, _ "SZS Editor") If R_exit = MsgBoxResult.Yes Then End End If End Sub Private Sub btnClearTEMP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearTEMP.Click Dim R_clear As MsgBoxResult R_clear = MsgBox("Are you sure to clear the temporary directory." & _ (Chr(13)) & "All opened files will be closed", _ MsgBoxStyle.Question + MsgBoxStyle.YesNo, _ "SZS Editor") ' If you click yes, than clear temporary directory , "close all files" and reset their variables If R_clear = MsgBoxResult.Yes Then Reset() If Dir("C:\TEMP\SZSToolsGUI") <> "" Then My.Computer.FileSystem.DeleteDirectory( _ "C:\TEMP\SZSToolsGUI", _ FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently) End If End If End Sub Private Sub btnCommandConsole_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCommandConsole.Click frmCommandConsole.Show() End Sub Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click AboutBox1.Show() End Sub ' ----- ' Everything about Configuration Private Sub btnConfigure_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConfigure.Click Dim wszstConfig As New OpenFileDialog wszstConfig.Filter = "Executable Files (*.exe)|*.exe" wszstConfig.CheckFileExists = True MsgBox("Specify the location of wszst.exe") Dim NoCancelCheck As Integer = wszstConfig.ShowDialog() If NoCancelCheck = DialogResult.Cancel Then ' Do nothing Else Dim Result As String = wszstConfig.FileName If Result.EndsWith("wszst.exe") Then Dim PathResult As String = My.Computer.FileSystem.GetParentPath(Result) WSZSTPath = PathResult Configured = True lblConfiguredtest2.Visible = True lblConfiguredtest2.Text = "Yes" My.Settings.WSZSTPath = WSZSTPath My.Settings.Configured = Configured My.Settings.Save() End If End If End Sub Private Sub lblConfiguredtest_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblConfiguredtest.MouseHover lblConfiguredtest2.Visible = True If Configured = True Then lblConfiguredtest2.Text = "Yes" Else lblConfiguredtest2.Text = "No" End If End Sub ' ----- ' Open and Save buttons Private Sub File_Open_File_tsmnItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles File_Open_File_tsmnItem.Click OpenFile() End Sub Private Sub File_Open_Dir_tsmnItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles File_Open_Dir_tsmnItem.Click OpenDir() End Sub Private Sub File_Save_File_tsmnItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles File_Save_File_tsmnItem.Click SaveFile() End Sub Private Sub File_Save_Dir_tsmnItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles File_Save_Dir_tsmnItem.Click SaveDir() End Sub ' ----- End Class