Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions ShinRyuModManager-CE/ModLoadOrder/Dependency/CPKGen/CPK.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text;
using Serilog;

namespace CriPakTools {
public class CPK(Tools tool) {
Expand Down Expand Up @@ -61,7 +62,7 @@ public bool ReadCPK(string sPath) {
}
} catch (Exception ex) {
//MessageBox.Show(ex.ToString());
Console.WriteLine(ex.ToString());
Log.Error(ex, "");
}

TocOffset = (ulong)GetColumnsData2(Utf, 0, "TocOffset", 3);
Expand Down Expand Up @@ -660,8 +661,7 @@ public static object GetColumnData(UTF utf, int row, string name) {
break;
}
} catch (Exception ex) {
//MessageBox.Show(ex.ToString());
Console.WriteLine(ex.ToString());
Log.Error(ex, "");

return null;
}
Expand All @@ -682,8 +682,7 @@ public static long GetColumnPosition(UTF utf, int row, string name) {
break;
}
} catch (Exception ex) {
//MessageBox.Show(ex.ToString());
Console.WriteLine(ex.ToString());
Log.Error(ex, "");

return -1;
}
Expand All @@ -704,8 +703,7 @@ public static Type GetColumnType(UTF utf, int row, string name) {
break;
}
} catch (Exception ex) {
//MessageBox.Show(ex.ToString());
Console.WriteLine(ex.ToString());
Log.Error(ex, "");

return null;
}
Expand Down
33 changes: 17 additions & 16 deletions ShinRyuModManager-CE/ModLoadOrder/Generator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Serilog;
using Serilog.Events;
using ShinRyuModManager.ModLoadOrder.Mods;
using Utils;

Expand Down Expand Up @@ -92,19 +93,19 @@ public static async Task<MLO> GenerateModeLoadOrder(List<string> mods, bool loos
modsObjects[i] = mod;
}

Log.Information("Added {ModCount} mod(s) and {FilesCount} file(s)!\n", mods.Count, files.Count);
Log.Information("Added {ModCount} mod(s) and {FilesCount} file(s)!", mods.Count, files.Count);

// Reverse the list because the last mod in the list should have the highest priority
mods.Reverse();

Console.Write($"Generating {Constants.MLO} file...");
Log.Information($"Generating {Constants.MLO} file...");

// Generate MLO
var mlo = new MLO(modIndices, mods, files, loose.ParlessFolders, cpkDictionary);

mlo.WriteMLO(Path.Combine(GamePath.FullGamePath, Constants.MLO));

Console.WriteLine(" DONE!\n");
Log.Information("Finished generating MLO.");

// Check if a mod has a par that will override the repacked par, and skip repacking it in that case
foreach (var key in parDictionary.Keys.ToList()) {
Expand Down Expand Up @@ -140,21 +141,21 @@ public static async Task<MLO> GenerateModeLoadOrder(List<string> mods, bool loos
if (cpkRepackingEnabled) {
await CpkPatcher.RepackDictionary(cpkRepackDict);
}
if (ConsoleOutput.ShowWarnings) {
foreach (var key in modsWithFoldersNotFound.Keys.ToList()) {
Console.WriteLine($"Warning: Some folders in the root of \"{key}\" do not exist in the game's data. Check if the mod was extracted correctly.");
if (ConsoleOutput.Verbose) {
foreach (var folder in modsWithFoldersNotFound[key]) {
Console.WriteLine($"Folder not found: {folder}");
}
}
Console.WriteLine();

if (Program.LogLevel > LogEventLevel.Warning)
return mlo;

foreach (var key in modsWithFoldersNotFound.Keys.ToList()) {
Log.Warning("Warning: Some folders in the root of \"{Key}\" do not exist in the game's data. Check if the mod was extracted correctly.", key);

if (Program.LogLevel != LogEventLevel.Verbose)
continue;

foreach (var folder in modsWithFoldersNotFound[key]) {
Log.Warning("Folder not found: {Folder}", folder);
}
}

return mlo;
}
}
32 changes: 13 additions & 19 deletions ShinRyuModManager-CE/ModLoadOrder/Mods/Mod.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text;
using Serilog;
using Utils;

namespace ShinRyuModManager.ModLoadOrder.Mods;
Expand Down Expand Up @@ -26,45 +27,38 @@ public class Mod {
/// </summary>
public List<string> RepackCpKs { get; }

protected readonly ConsoleOutput ConsoleOutput;

public Mod(string name, int indent = 2) {
public Mod(string name) {
Name = name;
Files = [];
ParFolders = [];
CpkFolders = [];
RepackCpKs = [];

ConsoleOutput = new ConsoleOutput(indent);
ConsoleOutput.WriteLine($"Reading directory: {name} ...");
Log.Information("Reading directory: {Name} ...", name);
}

public void PrintInfo() {
ConsoleOutput.WriteLineIfVerbose();

if (Files.Count > 0 || ParFolders.Count > 0) {
if (Files.Count > 0) {
ConsoleOutput.WriteLine($"Added {Files.Count} file(s)");
Log.Information("Added {FilesCount} file(s)", Files.Count);
}

if (ParFolders.Count > 0) {
ConsoleOutput.WriteLine($"Added {ParFolders.Count} folder(s) to be repacked");
Log.Information("Added {ParFoldersCount} folder(s) to be repacked", ParFolders.Count);
}

if (CpkFolders.Count > 0) {
ConsoleOutput.WriteLine($"Added {CpkFolders.Count} CPK folder(s) to be bound");
Log.Information("Added {CpkFoldersCount} CPK folder(s) to be bound", CpkFolders.Count);
}
} else {
ConsoleOutput.WriteLine($"Nothing found for {Name}, skipping");
Log.Information("Nothing found for {Name}, skipping", Name);
}

ConsoleOutput.Flush();
}

public void AddFiles(string path, string check) {
var needsRepack = false;
var basename = GamePath.GetBasename(path);
var parentDir = new DirectoryInfo(path).Parent.Name;
var parentDir = new DirectoryInfo(path).Parent!.Name;

// Check if this path does not need repacking
if (Name != "Parless") {
Expand Down Expand Up @@ -144,7 +138,7 @@ public void AddFiles(string path, string check) {

if (GamePath.CurrentGame == Game.Yakuza5) {
CpkFolders.Add(cpkDataPath + ".cpk");
ConsoleOutput.WriteLineIfVerbose($"Adding CPK folder: {cpkDataPath}");
Log.Verbose("Adding CPK folder: {CpkDataPath}", cpkDataPath);
} else {
if (GamePath.CurrentGame <= Game.YakuzaKiwami) {
RepackCpKs.Add(cpkDataPath + ".cpk");
Expand All @@ -163,15 +157,15 @@ public void AddFiles(string path, string check) {

if (GamePath.CurrentGame is Game.Judgment or Game.LostJudgment) {
CpkFolders.Add(cpkDataPath + ".par");
ConsoleOutput.WriteLineIfVerbose($"Adding CPK folder: {cpkDataPath}");
Log.Verbose("Adding CPK folder: {CpkDataPath}", cpkDataPath);
}

break;
case "gv_files":
cpkDataPath = GamePath.RemoveModPath(path);

CpkFolders.Add($"{cpkDataPath}.cpk");
ConsoleOutput.WriteLineIfVerbose($"Adding CPK folder: {cpkDataPath}");
Log.Verbose("Adding CPK folder: {CpkDataPath}", cpkDataPath);

break;
}
Expand Down Expand Up @@ -241,14 +235,14 @@ public void AddFiles(string path, string check) {

// Add this folder to the list of folders to be repacked and stop recursing
ParFolders.Add(dataPath);
ConsoleOutput.WriteLineIfVerbose($"Adding repackable folder: {dataPath}");
Log.Verbose("Adding repackable folder: {DataPath}", dataPath);
} else {
// Add files in current directory
var files = Directory.GetFiles(path).Where(f => !f.EndsWith(Constants.VORTEX_MANAGED_FILE)).Select(GamePath.GetDataPathFrom);

foreach (var p in files) {
Files.Add(p);
ConsoleOutput.WriteLineIfVerbose($"Adding file: {p}");
Log.Verbose("Adding file: {file}", p);
}

var isParlessMod = GetType() == typeof(ParlessMod);
Expand Down
9 changes: 4 additions & 5 deletions ShinRyuModManager-CE/ModLoadOrder/Mods/ParlessMod.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using Serilog;
using Utils;

namespace ShinRyuModManager.ModLoadOrder.Mods;

public class ParlessMod() : Mod(Constants.PARLESS_NAME, 0) {
public class ParlessMod() : Mod(Constants.PARLESS_NAME) {
public List<ParlessFolder> ParlessFolders { get; } = [];

public new void PrintInfo() {
ConsoleOutput.WriteLineIfVerbose();

if (ParlessFolders.Count > 0) {
ConsoleOutput.WriteLine($"Added {ParlessFolders.Count} .parless path(s)");
Log.Information("Added {ParlessFoldersCount} .parless path(s)", ParlessFolders.Count);
}

base.PrintInfo();
Expand All @@ -35,7 +34,7 @@ public class ParlessMod() : Mod(Constants.PARLESS_NAME, 0) {

ParlessFolders.Add(folder);

ConsoleOutput.WriteLineIfVerbose($"Adding .parless path: {loosePath}");
Log.Verbose("Adding .parless path: {LoosePath}", loosePath);
} else {
// Continue recursing until we find the next ".parless"
foreach (var folder in Directory.GetDirectories(path)) {
Expand Down
47 changes: 16 additions & 31 deletions ShinRyuModManager-CE/ParRepacker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ public static void RemoveOldRepackedPars() {
if (!Directory.Exists(pathToParlessMods))
return;

Console.Write("Removing old pars...");
Log.Information("Removing old pars...");

try {
DeleteDirectory(pathToParlessMods);
} catch {
Console.WriteLine($" FAIL! {pathToParlessMods}\n");
Log.Warning("Failed to remove old pars! {PathToParlessMods}", pathToParlessMods);
}

Console.WriteLine(" DONE!\n");
Log.Information("Removed old pars.");
}

public static async Task RepackDictionary(Dictionary<string, List<string>> parDictionary) {
var parTasks = new List<Task<ConsoleOutput>>();
var parTasks = new List<Task>();

if (parDictionary.Count == 0) {
Log.Information("No pars to repack.");
Expand All @@ -54,31 +54,19 @@ public static async Task RepackDictionary(Dictionary<string, List<string>> parDi
Log.Information("Repacking pars...");

foreach (var parModPair in parDictionary) {
var consoleOutput = new ConsoleOutput(2);

parTasks.Add(Task.Run(() => RepackPar(parModPair.Key, parModPair.Value, consoleOutput)));
parTasks.Add(Task.Run(() => RepackPar(parModPair.Key, parModPair.Value)));
}

while (parTasks.Count > 0) {
var console = await Task.WhenAny(parTasks);

console.Result?.Flush();

parTasks.Remove(console);
}
await Task.WhenAll(parTasks);

/*foreach (var parModPair in parDictionary) {
var consoleOutput = new ConsoleOutput(2);

RepackPar(parModPair.Key, parModPair.Value, consoleOutput);

consoleOutput.Flush();
RepackPar(parModPair.Key, parModPair.Value);
}*/

Log.Information("Repacked {ParDictionaryCount} par(s)!", parDictionary.Count);
}

private static ConsoleOutput RepackPar(string parPath, List<string> mods, ConsoleOutput console) {
private static void RepackPar(string parPath, List<string> mods) {
parPath = parPath.TrimStart(Path.DirectorySeparatorChar);

var parPathReal = GamePath.GetRootParPath(parPath + ".par");
Expand All @@ -104,7 +92,7 @@ private static ConsoleOutput RepackPar(string parPath, List<string> mods, Consol

// Populate fileDict with the files inside each mod
foreach (var mod in mods) {
foreach (var modFile in GetModFiles(parPath, mod, console)) {
foreach (var modFile in GetModFiles(parPath, mod)) {
fileDict.TryAdd(modFile, mod);
}
}
Expand Down Expand Up @@ -195,39 +183,36 @@ private static ConsoleOutput RepackPar(string parPath, List<string> mods, Consol
// Remove the .partemp directory
DeleteDirectory(pathToTempPar);

console.WriteLineIfVerbose();
console.WriteLine($"Repacked {fileDict.Count} file(s) in {parPath + ".par"}!");

return console;
Log.Information("Repacked {FileDictCount} file(s) in {ParPath}!", fileDict.Count, parPath + ".par");
}

private static List<string> GetModFiles(string par, string mod, ConsoleOutput console) {
private static List<string> GetModFiles(string par, string mod) {
List<string> result;

if (mod.StartsWith(Constants.PARLESS_NAME)) {
// Get index of ".parless" in par path
// 15 = ParlessMod.NAME.Length + 1
result = GetModFiles(Path.Combine(GamePath.DataPath, par.Insert(int.Parse(mod[15..]) - 1, ".parless")), console);
result = GetModFiles(Path.Combine(GamePath.DataPath, par.Insert(int.Parse(mod[15..]) - 1, ".parless")));
} else {
result = GetModFiles(GamePath.GetModPathFromDataPath(mod, par), console);
result = GetModFiles(GamePath.GetModPathFromDataPath(mod, par));
}

// Get file path relative to par
return result.Select(f => f.Replace(".parless", "")[(f.Replace(".parless", "").IndexOf(par, StringComparison.Ordinal) + par.Length + 1)..]).ToList();
}

private static List<string> GetModFiles(string path, ConsoleOutput console) {
private static List<string> GetModFiles(string path) {
List<string> files = [];

// Add files in current directory
foreach (var p in Directory.GetFiles(path).Where(f => !f.EndsWith(Constants.VORTEX_MANAGED_FILE)).Select(GamePath.GetDataPathFrom)) {
files.Add(p);
console.WriteLineIfVerbose($"Adding file: {p}");
Log.Verbose("Adding file: {file}", p);
}

// Get files for all subdirectories
foreach (var folder in Directory.GetDirectories(path)) {
files.AddRange(GetModFiles(folder, console));
files.AddRange(GetModFiles(folder));
}

return files;
Expand Down
Loading