Skip to content

Commit

Permalink
Add support for old modpacks
Browse files Browse the repository at this point in the history
Wrote custom function to read json data from .ttmp's
(function in xivModdingFramework was not sufficient in this project, #11)
  • Loading branch information
shinnova committed May 9, 2019
1 parent a24c27d commit c5cd446
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
3 changes: 3 additions & 0 deletions FFXIV_TexTools_CLI/FFXIV_TexTools_CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<Reference Include="xivModdingFramework">
<HintPath>..\references\xivModdingFramework.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.SharpZipLib">
<HintPath>..\packages\SharpZipLib.1.1.0\lib\net45\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
Expand Down
43 changes: 30 additions & 13 deletions FFXIV_TexTools_CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
using xivModdingFramework.Mods.FileTypes;
using xivModdingFramework.SqPack.FileTypes;
using xivModdingFramework.Textures.Enums;
using xivModdingFramework.Helpers;
using xivModdingFramework.Items.Interfaces;
using ICSharpCode.SharpZipLib.Zip;
using Newtonsoft.Json;
using CommandLine;

namespace FFXIV_TexTools_CLI
Expand All @@ -37,8 +37,6 @@ public class importoptions
{
[Option('g', "gamedirectory", Required = true, HelpText = "Full path including \"Final Fantasy XIV - A Realm Reborn\"")]
public string Directory { get; set; }
//[Option('m', "modpackdirectory", Required = true, HelpText = "Path to modpackdirectory")]
//public string ModPackDirectory { get; set; }
[Option('t', "ttmp", Required = true, HelpText = "Path to .ttmp(2) file")]
public string ttmpPath { get; set; }
}
Expand Down Expand Up @@ -129,14 +127,20 @@ void ImportModpackHandler(DirectoryInfo ttmpPath)
{
PrintMessage($"Problem reading index files:\n{ex.Message}", 2);
}
PrintMessage("Checking if modpack is .ttmp or .ttmp2...");
PrintMessage("Starting import...");
try
{
var ttmp = new TTMP(ttmpPath, "TexTools");
var ttmpData = ttmp.GetModPackJsonData(ttmpPath);

try
{
GetModpackData(ttmpPath, ttmpData.ModPackJson);
if (ttmpPath.Extension == ".ttmp2")
{
var ttmpData = ttmp.GetModPackJsonData(ttmpPath);
GetModpackData(ttmpPath, ttmpData.ModPackJson);
}
else
GetModpackData(ttmpPath, null);
}
catch
{
Expand All @@ -148,7 +152,7 @@ void ImportModpackHandler(DirectoryInfo ttmpPath)
{
if (!importError)
{
PrintMessage($"Exception was thrown:\n{ex.Message}\nRetrying...", 3);
PrintMessage($"Exception was thrown:\n{ex.Message}\nRetrying import...", 3);
GetModpackData(ttmpPath, null);
}
else
Expand All @@ -166,9 +170,9 @@ void GetModpackData(DirectoryInfo ttmpPath, ModPackJson ttmpData)
var modding = new Modding(_gameDirectory);
List<SimpleModPackEntries> ttmpDataList = new List<SimpleModPackEntries>();
TTMP _textoolsModpack = new TTMP(ttmpPath, "TexTools");
PrintMessage($"Extracting data from {ttmpPath.Name}...");
if (ttmpData != null)
{
PrintMessage("New modpack detected. Extracting data from the modpack...");
foreach (var modsJson in ttmpData.SimpleModsList)
{
var race = GetRace(modsJson.FullPath);
Expand Down Expand Up @@ -200,8 +204,21 @@ void GetModpackData(DirectoryInfo ttmpPath, ModPackJson ttmpData)
}
else
{
PrintMessage("Old modpack detected. Extracting data from the modpack...");
var originalModPackData = _textoolsModpack.GetOriginalModPackJsonData(ttmpPath);
var originalModPackData = new List<OriginalModPackJson>();
var fs = new FileStream(ttmpPath.FullName, FileMode.Open, FileAccess.Read);
ZipFile archive = new ZipFile(fs);
ZipEntry mplFile = archive.GetEntry("TTMPL.mpl");
{
using (var streamReader = new StreamReader(archive.GetInputStream(mplFile)))
{
string line;
while ((line = streamReader.ReadLine()) != null)
{
if (!line.ToLower().Contains("version"))
originalModPackData.Add(JsonConvert.DeserializeObject<OriginalModPackJson>(line));
}
}
}

foreach (var modsJson in originalModPackData)
{
Expand Down Expand Up @@ -262,7 +279,7 @@ void ImportModpack(List<SimpleModPackEntries> ttmpDataList, TTMP _textoolsModpac
else
{
totalModsImported = ttmpDataList.Count();
PrintMessage($"{totalModsImported} mod(s) successfully imported.", 1);
PrintMessage($"\n{totalModsImported} mod(s) successfully imported.", 1);
}

}
Expand All @@ -275,7 +292,7 @@ void ImportModpack(List<SimpleModPackEntries> ttmpDataList, TTMP _textoolsModpac
void ReportProgress(double value)
{
float progress = (float)value * 100;
Console.Write($"{(int)progress}%... ");
Console.Write($"\r{(int)progress}%... ");
}

XivRace GetRace(string modPath)
Expand Down
1 change: 1 addition & 0 deletions FFXIV_TexTools_CLI/packages.config
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<package id="CommandLineParser" version="2.5.0" targetFramework="net47" />
<package id="Magick.NET-Q8-AnyCPU" version="7.12.0" targetFramework="net47" />
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net47" />
<package id="SharpZipLib" version="1.1.0" targetFramework="net47" />
</packages>

0 comments on commit c5cd446

Please sign in to comment.