From a530e4fda1f5a52efc0b7d1c2624b5d52e9b4c41 Mon Sep 17 00:00:00 2001 From: Evan Dixon Date: Wed, 7 Dec 2016 11:07:58 -0600 Subject: [PATCH] Added library functions for modpack info --- DS ROM Patcher/Forms/Form2.vb | 12 +++--------- DS ROM Patcher/ModBuilder.vb | 24 +++++++++++++++++++----- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/DS ROM Patcher/Forms/Form2.vb b/DS ROM Patcher/Forms/Form2.vb index 69edb23..e68c5a7 100644 --- a/DS ROM Patcher/Forms/Form2.vb +++ b/DS ROM Patcher/Forms/Form2.vb @@ -41,7 +41,6 @@ Public Class Form2 Dim modTempDirectory = Path.Combine(tempDirectory, "modstemp") Dim unpackTempDirectory = Path.Combine(tempDirectory, "dstemp") Dim modsDirectory = Path.Combine(currentDirectory, "Mods") - Dim modpackInfoFilename As String = Path.Combine(modsDirectory, "Modpack.json") Private Async Sub Form2_Load(sender As Object, e As EventArgs) Handles Me.Load Dim completed As Integer = 0 @@ -60,11 +59,7 @@ Public Class Form2 End If 'Load modpack info - If File.Exists(modpackInfoFilename) Then - Modpack = Json.Deserialize(Of ModpackInfo)(File.ReadAllText(modpackInfoFilename)) - Else - Modpack = New ModpackInfo - End If + Modpack = ModBuilder.GetModpackInfo(currentDirectory) 'Unpack Mods If Directory.Exists(modsDirectory) Then @@ -187,7 +182,7 @@ Public Class Form2 Dim metaEdit As New ModpackMetadataWindow(Modpack) If metaEdit.ShowDialog = DialogResult.OK Then Modpack = metaEdit.ModpackInfo - Json.SerializeToFile(modpackInfoFilename, Modpack, New WindowsIOProvider) + ModBuilder.SaveModpackInfo(currentDirectory, metaEdit.ModpackInfo) End If End Sub @@ -195,8 +190,7 @@ Public Class Form2 Dim s As New SaveFileDialog s.Filter = $"{My.Resources.Language.ModpackZip}|*.zip|{My.Resources.Language.AllFiles}|*.*" If s.ShowDialog = DialogResult.OK Then - Dim b As New ModBuilder - b.ZipModpack(currentDirectory, s.FileName) + ModBuilder.ZipModpack(currentDirectory, s.FileName) End If End Sub #End Region diff --git a/DS ROM Patcher/ModBuilder.vb b/DS ROM Patcher/ModBuilder.vb index aa3de50..261ff01 100644 --- a/DS ROM Patcher/ModBuilder.vb +++ b/DS ROM Patcher/ModBuilder.vb @@ -108,7 +108,7 @@ Public Class ModBuilder Public Property CustomFilePatchers As List(Of FilePatcher) - Public property GameCode As string + Public Property GameCode As String Private ReadOnly Property ModTempDir As String Get @@ -142,7 +142,7 @@ Public Class ModBuilder Dim actions As New ModJson actions.DependenciesBefore = ModDependenciesBefore actions.DependenciesAfter = ModDependenciesAfter - actions.ID = ModID + actions.ID = ModId actions.Name = ModName actions.Version = ModVersion actions.Author = ModAuthor @@ -363,7 +363,7 @@ Public Class ModBuilder ''' ''' Copies the patcher program (aka the code library/program that contains this function) to the given directory. ''' - Public Sub CopyPatcherProgram(modpackDirectory As String) + Public Shared Sub CopyPatcherProgram(modpackDirectory As String) Dim currentAssembly = GetType(ModBuilder).Assembly Dim referenced = WindowsReflectionHelpers.GetAssemblyDependencies(currentAssembly) For Each item In referenced.Concat({currentAssembly.Location}) @@ -371,7 +371,7 @@ Public Class ModBuilder Next End Sub - Public Sub CopyMod(modFilename As String, modpackDirectory As String, Optional overwrite As Boolean = True) + Public Shared Sub CopyMod(modFilename As String, modpackDirectory As String, Optional overwrite As Boolean = True) Dim modsDir = Path.Combine(modpackDirectory, "Mods") If Not Directory.Exists(modsDir) Then Directory.CreateDirectory(modsDir) @@ -380,7 +380,21 @@ Public Class ModBuilder File.Copy(modFilename, Path.Combine(modsDir, Path.GetFileName(modFilename)), overwrite) End Sub - Public Sub ZipModpack(modpackDirectory As String, zipFilename As String) + Public Shared Sub ZipModpack(modpackDirectory As String, zipFilename As String) Zip.Zip(modpackDirectory, zipFilename) End Sub + + Public Shared Function GetModpackInfo(modpackDirectory As String) As ModpackInfo + Dim modpackInfoFilename = Path.Combine(modpackDirectory, "Mods", "Modpack.json") + If File.Exists(modpackInfoFilename) Then + Return SkyEditor.Core.Windows.Utilities.Json.DeserializeFromFile(Of ModpackInfo)(modpackInfoFilename) + Else + Return New ModpackInfo + End If + End Function + + Public Shared Sub SaveModpackInfo(modpackDirectory As String, info As ModpackInfo) + Dim modpackInfoFilename = Path.Combine(modpackDirectory, "Mods", "Modpack.json") + SkyEditor.Core.Windows.Utilities.Json.SerializeToFile(modpackInfoFilename, info) + End Sub End Class