Skip to content

Commit

Permalink
Update to 1.5, add P5R & PKG building
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrineFox committed Sep 22, 2020
1 parent 919b398 commit fc27bd5
Show file tree
Hide file tree
Showing 20 changed files with 401 additions and 81 deletions.
72 changes: 72 additions & 0 deletions Source/ModCompendium/GameConfigWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,78 @@ public GameConfigWindow(GameConfig config)
{
var ppConfig = (ModCpkGameConfig)config;
}
else if (config is PKGGameConfig)
{
var pkgConfig = (PKGGameConfig)config;

// Add extra row
ConfigPropertyGrid.RowDefinitions.Add(new RowDefinition());

// Cpk root directory path label
{
var pkgPathLabel = new Label()
{
Content = "App PKG Path",
ToolTip = $"Path to the unencrypted {config.Game.ToString()} full game PKG",
HorizontalContentAlignment = HorizontalAlignment.Center,
VerticalContentAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Height = 25,
Width = 120
};

Grid.SetRow(pkgPathLabel, 2);
Grid.SetColumn(pkgPathLabel, 0);
ConfigPropertyGrid.Children.Add(pkgPathLabel);
}

// PKG path text box
TextBox pkgPathTextBox;
{
pkgPathTextBox = new TextBox()
{
VerticalContentAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Height = 20,
TextWrapping = TextWrapping.Wrap,
Width = 291,
};

pkgPathTextBox.SetBinding(TextBox.TextProperty, new Binding(nameof(Persona5RoyalGameConfig.PKGPath)));

Grid.SetRow(pkgPathTextBox, 2);
Grid.SetColumn(pkgPathTextBox, 1);
ConfigPropertyGrid.Children.Add(pkgPathTextBox);
}

// PKG Path text box button
{
var pkgPathTextBoxButton = new Button()
{
Content = "...",
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Center,
Width = 20,
Height = 20
};

pkgPathTextBoxButton.Click += (s, e) =>
{
var file = SelectFile(new CommonFileDialogFilter("PKG file", ".pkg"));
if (file != null)
{
pkgConfig.PKGPath = file;
pkgPathTextBox.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
}
};

Grid.SetRow(pkgPathTextBoxButton, 2);
Grid.SetColumn(pkgPathTextBoxButton, 1);
ConfigPropertyGrid.Children.Add(pkgPathTextBoxButton);
}
}
else
{
var ppConfig = (PersonaPortableGameConfig)config;
Expand Down
41 changes: 12 additions & 29 deletions Source/ModCompendium/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public partial class MainWindow : Window
"Persona 4 Golden",
"Persona 4 Dancing All Night",
"Persona 5",
"Persona 5 Royal",
"Persona 3 Dancing Moon Night",
"Persona 5 Dancing Star Night",
"Persona Q",
Expand All @@ -58,6 +59,8 @@ public partial class MainWindow : Window

public Mod SelectedMod => ( Mod )SelectedModViewModel;

public List<Mod> gEnabledMods;

public MainWindow()
{
InitializeComponent();
Expand Down Expand Up @@ -122,9 +125,9 @@ private void RefreshModDatabase()
private bool UpdateGameConfigEnabledMods()
{
var enabledMods = Mods.Where( x => x.Enabled )
.Select( x => x.Id )
.ToList();

.Select( x => x.Id )
.ToList();
GameConfig.ClearEnabledMods();

if ( enabledMods.Count == 0 )
Expand Down Expand Up @@ -265,21 +268,21 @@ private void BuildButton_Click( object sender, RoutedEventArgs e )

var task = Task.Factory.StartNew( () =>
{
var enabledMods = GameConfig.ModConfigs.Where( x => x.Enabled )
gEnabledMods = GameConfig.ModConfigs.Where( x => x.Enabled )
.OrderBy( x => x.Priority )
.Select( x => x.ModId )
.Select( x => ModDatabase.Get( x ) )
.ToList();

Log.General.Info( "Building mods:" );
foreach ( var enabledMod in enabledMods )
foreach ( var enabledMod in gEnabledMods)
Log.General.Info( $"\t{enabledMod.Title}" );

// Run prebuild scripts
RunModScripts( enabledMods, "prebuild.bat" );
RunModScripts(gEnabledMods, "prebuild.bat" );

var merger = new TopToBottomModMerger();
var merged = merger.Merge( enabledMods );
var merged = merger.Merge(gEnabledMods);

// Todo
var builder = ModBuilderManager.GetCompatibleModBuilders( SelectedGame ).First().Create();
Expand All @@ -297,7 +300,7 @@ private void BuildButton_Click( object sender, RoutedEventArgs e )
try
#endif
{
builder.Build( merged, GameConfig.OutputDirectoryPath );
builder.Build( merged, gEnabledMods, GameConfig.OutputDirectoryPath);
}
#if !DEBUG
catch ( InvalidConfigException exception )
Expand Down Expand Up @@ -343,7 +346,7 @@ private void BuildButton_Click( object sender, RoutedEventArgs e )
if ( t.Result )
{
MessageBox.Show(this, "Done building!", "Done", MessageBoxButton.OK, MessageBoxImage.None);
RunPostBuildScript( "postbuild.bat" );
RunModScripts(gEnabledMods, "postbuild.bat");
}
} );
} );
Expand Down Expand Up @@ -371,26 +374,6 @@ private static void RunModScripts( List<Mod> enabledMods, string scriptFileName
}
}

private static void RunPostBuildScript(string scriptFileName)
{
var scriptFilePath = Path.Combine(Directory.GetCurrentDirectory(), scriptFileName);
if (File.Exists(scriptFilePath))
{
try
{
var info = new ProcessStartInfo(Path.GetFullPath(scriptFilePath));
info.WorkingDirectory = Path.GetFullPath(Directory.GetCurrentDirectory());

var process = Process.Start(info);
process?.WaitForExit();
}
catch (Exception)
{
}
}
}


private void ModGrid_KeyDown( object sender, KeyEventArgs e )
{
if ( e.Key == Key.Down )
Expand Down
4 changes: 2 additions & 2 deletions Source/ModCompendium/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion( "1.4.0.0" )]
[assembly: AssemblyFileVersion( "1.4.0.0" )]
[assembly: AssemblyVersion( "1.5.0.0" )]
[assembly: AssemblyFileVersion( "1.5.0.0" )]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Xml.Linq;

namespace ModCompendiumLibrary.Configuration
{
public abstract class PKGGameConfig : GameConfig
{
protected PKGGameConfig()
{
PKGPath = string.Empty;
Compression = "True";
}

public string PKGPath { get; set; }
public string Compression { get; set; }

protected override void DeserializeCore(XElement element)
{
PKGPath = element.GetElementValueOrEmpty(nameof(PKGPath));
Compression = element.GetElementValueOrEmpty(nameof(Compression));
}

protected override void SerializeCore(XElement element)
{
element.AddNameValuePair(nameof(PKGPath), PKGPath);
element.AddNameValuePair(nameof(Compression), Compression);
}

public class Persona5RoyalGameConfig : PKGGameConfig
{
public override Game Game => Game.Persona5Royal;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Xml.Linq;

namespace ModCompendiumLibrary.Configuration
{
public class Persona5RoyalGameConfig : PKGGameConfig
{
public override Game Game => Game.Persona5Royal;

}
}
1 change: 1 addition & 0 deletions Source/ModCompendiumLibrary/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public enum Game
Persona4Golden,
Persona4Dancing,
Persona5,
Persona5Royal,
Persona3Dancing,
Persona5Dancing,
PersonaQ,
Expand Down
3 changes: 3 additions & 0 deletions Source/ModCompendiumLibrary/ModCompendiumLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
<Compile Include="Configuration\ConfigStore.cs" />
<Compile Include="Configuration\GameConfigs\CatherineFullBodyGameConfig.cs" />
<Compile Include="Configuration\GameConfigs\ModCpkGameConfig.cs" />
<Compile Include="Configuration\GameConfigs\PKGGameConfig.cs" />
<Compile Include="Configuration\GameConfigs\Persona5RoyalGameConfig.cs" />
<Compile Include="Configuration\GameConfigs\Persona4GoldenGameConfig.cs" />
<Compile Include="Configuration\GameConfigs\PersonaQ2GameConfig.cs" />
<Compile Include="Configuration\GameConfigs\PersonaQGameConfig.cs" />
Expand Down Expand Up @@ -78,6 +80,7 @@
<Compile Include="ModSystem\Builders\Exceptions\InvalidConfigException.cs" />
<Compile Include="ModSystem\Builders\ModBuilderStackExecutor.cs" />
<Compile Include="ModSystem\Builders\Common\CDReaderExtensions.cs" />
<Compile Include="ModSystem\Builders\PS4PKGModBuilder.cs" />
<Compile Include="ModSystem\Builders\ModCpkModBuilder.cs" />
<Compile Include="ModSystem\Builders\Persona34IsoModBuilder.cs" />
<Compile Include="ModSystem\Builders\Persona34\Persona34Common.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using CriPakTools;
using ModCompendiumLibrary.Configuration;
using System.Diagnostics;
using System.Collections.Generic;

namespace ModCompendiumLibrary.ModSystem.Builders
{
Expand All @@ -15,7 +16,7 @@ public abstract class CatherineFullBodyModBuilder : IModBuilder

public bool OutputUnmodifiedFiles { get; } = true;
/// <inheritdoc />
public VirtualFileSystemEntry Build(VirtualDirectory root, string hostOutputPath = null, string gameName = null, bool useCompression = false, bool useExtracted = false)
public VirtualFileSystemEntry Build(VirtualDirectory root, List<Mod> enabledMods, string hostOutputPath = null, string gameName = null, bool useCompression = false, bool useExtracted = false)
{
gameName = Game.ToString();

Expand Down Expand Up @@ -129,7 +130,7 @@ public VirtualFileSystemEntry Build(VirtualDirectory root, string hostOutputPath
// Build mod cpk
var cpkModCompiler = new CpkModBuilder();
var cpkFilePath = hostOutputPath != null ? Path.Combine(hostOutputPath, $"{cpkRootDirectory.Name}.cpk") : null;
var cpkFile = cpkModCompiler.Build(cpkRootDirectory, cpkFilePath, gameName, useCompression);
var cpkFile = cpkModCompiler.Build(cpkRootDirectory, enabledMods, cpkFilePath, gameName, useCompression);
Log.Builder.Info("Done!");
return cpkFile;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using ModCompendiumLibrary.Logging;
Expand All @@ -21,7 +22,7 @@ public class CpkModBuilder : IModBuilder
public bool DeleteCsv { get; } = true;

/// <inheritdoc />
public VirtualFileSystemEntry Build(VirtualDirectory root, string hostOutputPath = null, string gameName = null, bool useCompression = false, bool useExtracted = false)
public VirtualFileSystemEntry Build(VirtualDirectory root, List<Mod> enabledMods, string hostOutputPath = null, string gameName = null, bool useCompression = false, bool useExtracted = false)
{
if (root == null)
{
Expand Down Expand Up @@ -60,14 +61,14 @@ public VirtualFileSystemEntry Build(VirtualDirectory root, string hostOutputPath
}

// Build cpk
string arguments;
string arguments = "";
if (csvPath == string.Empty)
{
arguments = $"\"{Path.GetFullPath(modDirectoryPath)}\" \"{Path.GetFullPath(cpkPath)}\" -align={Alignment} -code={CodePage} -mode={Mode}";
}
else
{
arguments = $"\"{Path.GetFullPath(csvPath)}\" \"{Path.GetFullPath(cpkPath)}\" -dir=\"{modDirectoryPath}\" -align={Alignment} -mode={Mode}";
arguments += $"\"{Path.GetFullPath(csvPath)}\" \"{Path.GetFullPath(cpkPath)}\" -dir=\"{modDirectoryPath}\" -align={Alignment} -mode={Mode}";
Log.Builder.Info($"Compressing CPK (this can take a long time, please wait...)");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ModCompendiumLibrary.VirtualFileSystem;
using DiscUtils.Iso9660;
using ModCompendiumLibrary.Logging;
using System.Collections.Generic;

namespace ModCompendiumLibrary.ModSystem.Builders
{
Expand All @@ -12,7 +13,7 @@ public class CvmModBuilder : IModBuilder
private static readonly byte[] sDummyCvmHeader = GenerateDummyCvmHeader();

/// <inheritdoc />
public VirtualFileSystemEntry Build(VirtualDirectory root, string hostOutputPath = null, string gameName = null, bool useCompression = false, bool useExtracted = false)
public VirtualFileSystemEntry Build(VirtualDirectory root, List<Mod> enabledMods, string hostOutputPath = null, string gameName = null, bool useCompression = false, bool useExtracted = false)
{
if ( root == null )
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ModCompendiumLibrary.VirtualFileSystem;
using System.Collections.Generic;

namespace ModCompendiumLibrary.ModSystem.Builders
{
Expand All @@ -8,11 +9,12 @@ public interface IModBuilder
/// Build a mod file given a virtual directory containing data, and maybe an output path where the mod file should be output to.
/// </summary>
/// <param name="root">Virtual directory containing mod file data.</param>
/// <param name="enabledMods">Tthe list of enabled mods to be used for packaging description.</param>
/// <param name="hostOutputPath">Optional. If specified, the mod builder can be expected to output the built mod file to the location specified.</param>
/// <param name="gameName">Optional. If compression == true, the mod builder will use the CSV of the game name specified for compression.</param>
/// <param name="useCompression">Optional. If compression == true, the mod builder will compress the resulting cpk.</param>
/// <param name="useExtracted">Optional. If extract == true, the mod builder will extract the cpk at the specified cpk path and include its files in the mod.</param>
/// <returns></returns>
VirtualFileSystemEntry Build( VirtualDirectory root, string hostOutputPath = null, string gameName = null, bool useCompression = false, bool useExtracted = false);
VirtualFileSystemEntry Build( VirtualDirectory root, List<Mod> enabledMods, string hostOutputPath = null, string gameName = null, bool useCompression = false, bool useExtracted = false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public VirtualFileSystemEntry Execute(VirtualDirectory root, string hostOutputPa
{
var builderInfo = Stack.Pop();
var builder = builderInfo.Create();
output = builder.Build( input, hostOutputPath );
output = builder.Build(input, new List<Mod>(), hostOutputPath);
if ( output.EntryType == VirtualFileSystemEntryType.File && Stack.Count != 0 )
{
var temp = new VirtualDirectory();
Expand Down
Loading

0 comments on commit fc27bd5

Please sign in to comment.