Skip to content

Commit

Permalink
Added library functions for modpack info
Browse files Browse the repository at this point in the history
  • Loading branch information
evandixon committed Dec 7, 2016
1 parent 2b5a9d3 commit a530e4f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
12 changes: 3 additions & 9 deletions DS ROM Patcher/Forms/Form2.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -187,16 +182,15 @@ 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

Private Sub ExportToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExportToolStripMenuItem.Click
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
Expand Down
24 changes: 19 additions & 5 deletions DS ROM Patcher/ModBuilder.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -363,15 +363,15 @@ Public Class ModBuilder
''' <summary>
''' Copies the patcher program (aka the code library/program that contains this function) to the given directory.
''' </summary>
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})
File.Copy(item, Path.Combine(modpackDirectory, Path.GetFileName(item)))
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)
Expand All @@ -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

0 comments on commit a530e4f

Please sign in to comment.