2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-06-06 08:27:43 +00:00

Make unlinker open a gdt file if not raw specified

This commit is contained in:
Jan 2021-03-06 12:09:00 +01:00
parent aa972614e5
commit fc59a09d02
5 changed files with 99 additions and 40 deletions

View File

@ -0,0 +1,6 @@
#include "AssetDumpingContext.h"
AssetDumpingContext::AssetDumpingContext()
: m_zone(nullptr)
{
}

View File

@ -2,6 +2,7 @@
#include <string>
#include "Obj/Gdt/GdtStream.h"
#include "Zone/Zone.h"
class AssetDumpingContext
@ -9,4 +10,7 @@ class AssetDumpingContext
public:
Zone* m_zone;
std::string m_base_path;
std::unique_ptr<GdtOutputStream> m_gdt;
AssetDumpingContext();
};

View File

@ -183,6 +183,22 @@ class Unlinker::Impl
return result;
}
static bool OpenGdtFile(Zone* zone, const fs::path& zoneDefinitionFileFolder, std::ofstream& stream)
{
auto gdtFilePath(zoneDefinitionFileFolder);
gdtFilePath.append(zone->m_name);
gdtFilePath.replace_extension(".gdt");
stream = std::ofstream(gdtFilePath, std::fstream::out | std::fstream::binary);
if (!stream.is_open())
{
printf("Failed to open file for zone definition file of zone \"%s\".\n", zone->m_name.c_str());
return false;
}
return true;
}
/**
* \brief Performs the tasks specified by the command line arguments on the specified zone.
* \param zone The zone to handle.
@ -204,12 +220,31 @@ class Unlinker::Impl
zoneDefinitionFileFolder.append("zone_source");
fs::create_directories(zoneDefinitionFileFolder);
WriteZoneDefinitionFile(zone, zoneDefinitionFileFolder);
if (!WriteZoneDefinitionFile(zone, zoneDefinitionFileFolder))
return false;
std::ofstream gdtStream;
AssetDumpingContext context;
context.m_zone = zone;
context.m_base_path = outputFolderPath;
if(!m_args.m_raw)
{
if (!OpenGdtFile(zone, zoneDefinitionFileFolder, gdtStream))
return false;
auto gdt = std::make_unique<GdtOutputStream>(gdtStream);
gdt->BeginStream();
gdt->WriteVersion(GdtVersion(zone->m_game->GetName(), 1));
context.m_gdt = std::move(gdt);
}
ObjWriting::DumpZone(context);
if(!m_args.m_raw)
{
context.m_gdt->EndStream();
gdtStream.close();
}
}
return true;

View File

@ -7,54 +7,62 @@
#include "ObjLoading.h"
#include "ObjWriting.h"
const CommandLineOption* const OPTION_HELP = CommandLineOption::Builder::Create()
const CommandLineOption* const OPTION_HELP =
CommandLineOption::Builder::Create()
.WithShortName("?")
.WithLongName("help")
.WithDescription("Displays usage information.")
.Build();
const CommandLineOption* const OPTION_VERBOSE = CommandLineOption::Builder::Create()
const CommandLineOption* const OPTION_VERBOSE =
CommandLineOption::Builder::Create()
.WithShortName("v")
.WithLongName("verbose")
.WithDescription("Outputs a lot more and more detailed messages.")
.Build();
const CommandLineOption* const OPTION_MINIMAL_ZONE_FILE = CommandLineOption::Builder::Create()
const CommandLineOption* const OPTION_MINIMAL_ZONE_FILE =
CommandLineOption::Builder::Create()
.WithShortName("min")
.WithLongName("minimal-zone")
.WithDescription(
"Minimizes the size of the zone file output by only including assets that are not a dependency of another asset.")
.WithDescription("Minimizes the size of the zone file output by only including assets that are not a dependency of another asset.")
.Build();
const CommandLineOption* const OPTION_LIST = CommandLineOption::Builder::Create()
const CommandLineOption* const OPTION_LIST =
CommandLineOption::Builder::Create()
.WithShortName("l")
.WithLongName("list")
.WithDescription(
"Lists the contents of a zone instead of writing them to the disk.")
.WithDescription("Lists the contents of a zone instead of writing them to the disk.")
.Build();
const CommandLineOption* const OPTION_OUTPUT_FOLDER = CommandLineOption::Builder::Create()
const CommandLineOption* const OPTION_OUTPUT_FOLDER =
CommandLineOption::Builder::Create()
.WithShortName("o")
.WithLongName("output-folder")
.WithDescription(
"Specifies the output folder containing the contents of the unlinked zones. Defaults to ./%zoneName%")
.WithDescription("Specifies the output folder containing the contents of the unlinked zones. Defaults to ./%zoneName%")
.WithParameter("outputFolderPath")
.Build();
const CommandLineOption* const OPTION_SEARCH_PATH = CommandLineOption::Builder::Create()
const CommandLineOption* const OPTION_SEARCH_PATH =
CommandLineOption::Builder::Create()
.WithLongName("search-path")
.WithDescription(
"Specifies a semi-colon separated list of paths to search for additional game files.")
.WithDescription("Specifies a semi-colon separated list of paths to search for additional game files.")
.WithParameter("searchPathString")
.Build();
const CommandLineOption* const OPTION_IMAGE_FORMAT = CommandLineOption::Builder::Create()
const CommandLineOption* const OPTION_IMAGE_FORMAT =
CommandLineOption::Builder::Create()
.WithLongName("image-format")
.WithDescription(
"Specifies the format of dumped image files. Valid values are: DDS, IWI")
.WithDescription("Specifies the format of dumped image files. Valid values are: DDS, IWI")
.WithParameter("imageFormatValue")
.Build();
const CommandLineOption* const OPTION_RAW =
CommandLineOption::Builder::Create()
.WithLongName("raw")
.WithDescription("Prevents generation of a GDT and dumps assets as raw whenever possible.")
.Build();
const CommandLineOption* const COMMAND_LINE_OPTIONS[]
{
OPTION_HELP,
@ -63,7 +71,8 @@ const CommandLineOption* const COMMAND_LINE_OPTIONS[]
OPTION_LIST,
OPTION_OUTPUT_FOLDER,
OPTION_SEARCH_PATH,
OPTION_IMAGE_FORMAT
OPTION_IMAGE_FORMAT,
OPTION_RAW
};
UnlinkerArgs::UnlinkerArgs()
@ -237,6 +246,9 @@ bool UnlinkerArgs::ParseArgs(const int argc, const char** argv)
}
}
// --raw
m_raw = m_argument_parser.IsOptionSpecified(OPTION_RAW);
return true;
}

View File

@ -39,6 +39,8 @@ public:
std::string m_output_folder;
bool m_minimal_zone_def;
bool m_raw;
bool m_verbose;
UnlinkerArgs();