2015-06-30 06:46:19 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2016-03-04 23:04:30 +00:00
|
|
|
#include "logvisor/logvisor.hpp"
|
|
|
|
#include "nod/nod.hpp"
|
2015-06-30 06:46:19 +00:00
|
|
|
|
2015-06-30 19:38:51 +00:00
|
|
|
static void printHelp()
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage:\n"
|
2016-01-21 06:30:37 +00:00
|
|
|
" nodtool extract [-f] <image-in> [<dir-out>]\n"
|
|
|
|
" nodtool makegcn <gameid> <game-title> <fsroot-in> <dol-in> <apploader-in> [<image-out>]\n"
|
2017-02-05 06:19:34 +00:00
|
|
|
" nodtool makewii <gameid> <game-title> <fsroot-in> <dol-in> <apploader-in> <parthead-in> [<image-out>]\n"
|
|
|
|
" nodtool mergegcn <fsroot-in> <image-in> [<image-out>]\n"
|
|
|
|
" nodtool mergewii <fsroot-in> <image-in> [<image-out>]\n");
|
2015-06-30 19:38:51 +00:00
|
|
|
}
|
|
|
|
|
2015-07-02 20:37:07 +00:00
|
|
|
#if NOD_UCS2
|
|
|
|
#ifdef strcasecmp
|
|
|
|
#undef strcasecmp
|
|
|
|
#endif
|
|
|
|
#define strcasecmp _wcsicmp
|
2016-01-21 06:30:37 +00:00
|
|
|
#define PRISize "Iu"
|
2015-07-02 20:37:07 +00:00
|
|
|
int wmain(int argc, wchar_t* argv[])
|
|
|
|
#else
|
2016-01-21 06:30:37 +00:00
|
|
|
#define PRISize "zu"
|
2015-06-30 06:46:19 +00:00
|
|
|
int main(int argc, char* argv[])
|
2015-07-02 20:37:07 +00:00
|
|
|
#endif
|
2015-06-30 06:46:19 +00:00
|
|
|
{
|
2016-01-21 06:30:37 +00:00
|
|
|
if (argc < 3 ||
|
|
|
|
(!strcasecmp(argv[1], _S("makegcn")) && argc < 7) ||
|
2017-02-05 06:19:34 +00:00
|
|
|
(!strcasecmp(argv[1], _S("makewii")) && argc < 8) ||
|
|
|
|
(!strcasecmp(argv[1], _S("mergegcn")) && argc < 4) ||
|
|
|
|
(!strcasecmp(argv[1], _S("mergewii")) && argc < 4))
|
2015-06-30 06:46:19 +00:00
|
|
|
{
|
2015-06-30 19:38:51 +00:00
|
|
|
printHelp();
|
2016-01-25 20:21:10 +00:00
|
|
|
return 1;
|
2015-06-30 06:46:19 +00:00
|
|
|
}
|
|
|
|
|
2015-07-04 06:02:12 +00:00
|
|
|
/* Enable logging to console */
|
2016-09-08 06:16:22 +00:00
|
|
|
logvisor::RegisterStandardExceptions();
|
2016-03-04 23:04:30 +00:00
|
|
|
logvisor::RegisterConsoleLogger();
|
2015-07-04 06:02:12 +00:00
|
|
|
|
2017-05-21 10:26:22 +00:00
|
|
|
nod::ExtractionContext ctx = { true, true, [&](const std::string& str, float c){
|
2017-05-22 03:12:48 +00:00
|
|
|
fprintf(stderr, "Current node: %s, Extraction %g%% Complete\n", str.c_str(), c * 100.f);
|
2015-09-28 01:55:59 +00:00
|
|
|
}};
|
2016-03-04 23:04:30 +00:00
|
|
|
const nod::SystemChar* inDir = nullptr;
|
|
|
|
const nod::SystemChar* outDir = _S(".");
|
2015-09-28 01:55:59 +00:00
|
|
|
|
2015-06-30 19:38:51 +00:00
|
|
|
for (int a=2 ; a<argc ; ++a)
|
|
|
|
{
|
|
|
|
if (argv[a][0] == '-' && argv[a][1] == 'f')
|
2015-09-28 01:55:59 +00:00
|
|
|
ctx.force = true;
|
|
|
|
else if (argv[a][0] == '-' && argv[a][1] == 'v')
|
|
|
|
ctx.verbose = true;
|
|
|
|
|
2015-06-30 19:38:51 +00:00
|
|
|
else if (!inDir)
|
|
|
|
inDir = argv[a];
|
|
|
|
else
|
|
|
|
outDir = argv[a];
|
|
|
|
}
|
2015-06-30 06:46:19 +00:00
|
|
|
|
2017-05-22 03:12:48 +00:00
|
|
|
auto progFunc = [&](float prog, const nod::SystemString& name, size_t bytes)
|
2017-02-05 06:19:34 +00:00
|
|
|
{
|
2017-05-22 03:18:52 +00:00
|
|
|
nod::Printf(_S("\r "));
|
2017-02-05 06:19:34 +00:00
|
|
|
if (bytes != -1)
|
2017-05-22 03:12:48 +00:00
|
|
|
nod::Printf(_S("\r%g%% %s %" PRISize " B"), prog * 100.f, name.c_str(), bytes);
|
2017-02-05 06:19:34 +00:00
|
|
|
else
|
2017-05-22 03:12:48 +00:00
|
|
|
nod::Printf(_S("\r%g%% %s"), prog * 100.f, name.c_str());
|
2017-02-05 06:19:34 +00:00
|
|
|
fflush(stdout);
|
|
|
|
};
|
|
|
|
|
2015-07-02 20:37:07 +00:00
|
|
|
if (!strcasecmp(argv[1], _S("extract")))
|
2015-06-30 19:38:51 +00:00
|
|
|
{
|
2016-01-22 23:45:58 +00:00
|
|
|
bool isWii;
|
2016-03-04 23:04:30 +00:00
|
|
|
std::unique_ptr<nod::DiscBase> disc = nod::OpenDiscFromImage(inDir, isWii);
|
2015-06-30 19:38:51 +00:00
|
|
|
if (!disc)
|
2016-01-25 20:21:10 +00:00
|
|
|
return 1;
|
2015-06-30 19:38:51 +00:00
|
|
|
|
2016-03-04 23:04:30 +00:00
|
|
|
nod::Mkdir(outDir, 0755);
|
2016-01-22 23:45:58 +00:00
|
|
|
|
|
|
|
if (isWii)
|
2016-03-04 23:04:30 +00:00
|
|
|
static_cast<nod::DiscWii&>(*disc).writeOutDataPartitionHeader(
|
|
|
|
(nod::SystemString(outDir) + _S("/partition_head.bin")).c_str());
|
2016-01-22 23:45:58 +00:00
|
|
|
|
2016-03-04 23:04:30 +00:00
|
|
|
nod::Partition* dataPart = disc->getDataPartition();
|
2015-06-30 19:38:51 +00:00
|
|
|
if (!dataPart)
|
2016-01-25 20:21:10 +00:00
|
|
|
return 1;
|
2015-06-30 06:46:19 +00:00
|
|
|
|
2015-09-28 01:55:59 +00:00
|
|
|
if (!dataPart->extractToDirectory(outDir, ctx))
|
2016-01-25 20:21:10 +00:00
|
|
|
return 1;
|
2015-06-30 19:38:51 +00:00
|
|
|
}
|
2016-01-21 06:30:37 +00:00
|
|
|
else if (!strcasecmp(argv[1], _S("makegcn")))
|
2015-06-30 06:46:19 +00:00
|
|
|
{
|
2016-01-21 06:30:37 +00:00
|
|
|
#if NOD_UCS2
|
2016-01-24 05:06:54 +00:00
|
|
|
if (wcslen(argv[2]) < 6)
|
2017-02-05 06:19:34 +00:00
|
|
|
{
|
|
|
|
nod::LogModule.report(logvisor::Error, _S("game-id is not at least 6 characters"));
|
|
|
|
return 1;
|
|
|
|
}
|
2016-01-21 06:30:37 +00:00
|
|
|
#else
|
|
|
|
if (strlen(argv[2]) < 6)
|
2017-02-05 06:19:34 +00:00
|
|
|
{
|
|
|
|
nod::LogModule.report(logvisor::Error, _S("game-id is not at least 6 characters"));
|
|
|
|
return 1;
|
|
|
|
}
|
2016-01-21 06:30:37 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Pre-validate paths */
|
2016-03-04 23:04:30 +00:00
|
|
|
nod::Sstat theStat;
|
|
|
|
if (nod::Stat(argv[4], &theStat) || !S_ISDIR(theStat.st_mode))
|
2017-02-05 06:19:34 +00:00
|
|
|
{
|
|
|
|
nod::LogModule.report(logvisor::Error, _S("unable to stat %s as directory"), argv[4]);
|
|
|
|
return 1;
|
|
|
|
}
|
2016-03-04 23:04:30 +00:00
|
|
|
if (nod::Stat(argv[5], &theStat) || !S_ISREG(theStat.st_mode))
|
2017-02-05 06:19:34 +00:00
|
|
|
{
|
|
|
|
nod::LogModule.report(logvisor::Error, _S("unable to stat %s as file"), argv[5]);
|
|
|
|
return 1;
|
|
|
|
}
|
2016-03-04 23:04:30 +00:00
|
|
|
if (nod::Stat(argv[6], &theStat) || !S_ISREG(theStat.st_mode))
|
2017-02-05 06:19:34 +00:00
|
|
|
{
|
|
|
|
nod::LogModule.report(logvisor::Error, "unable to stat %s as file", argv[6]);
|
|
|
|
return 1;
|
|
|
|
}
|
2016-03-04 23:04:30 +00:00
|
|
|
|
|
|
|
nod::SystemString gameIdSys(argv[2]);
|
|
|
|
nod::SystemUTF8View gameId(gameIdSys);
|
|
|
|
nod::SystemString gameTitleSys(argv[3]);
|
|
|
|
nod::SystemUTF8View gameTitle(gameTitleSys);
|
2017-02-05 06:19:34 +00:00
|
|
|
|
|
|
|
if (nod::DiscBuilderGCN::CalculateTotalSizeRequired(argv[4], argv[5]) == -1)
|
|
|
|
return 1;
|
2016-01-21 06:30:37 +00:00
|
|
|
|
2017-05-22 03:12:48 +00:00
|
|
|
nod::EBuildResult ret;
|
2016-01-25 20:21:10 +00:00
|
|
|
|
2016-01-21 06:30:37 +00:00
|
|
|
if (argc < 8)
|
|
|
|
{
|
2016-03-04 23:04:30 +00:00
|
|
|
nod::SystemString outPath(argv[4]);
|
2016-01-21 06:30:37 +00:00
|
|
|
outPath.append(_S(".iso"));
|
2016-03-04 23:04:30 +00:00
|
|
|
nod::DiscBuilderGCN b(outPath.c_str(), gameId.utf8_str().c_str(), gameTitle.utf8_str().c_str(), 0x0003EB60, progFunc);
|
2016-01-25 20:21:10 +00:00
|
|
|
ret = b.buildFromDirectory(argv[4], argv[5], argv[6]);
|
2016-01-21 06:30:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-04 23:04:30 +00:00
|
|
|
nod::DiscBuilderGCN b(argv[7], gameId.utf8_str().c_str(), gameTitle.utf8_str().c_str(), 0x0003EB60, progFunc);
|
2016-01-25 20:21:10 +00:00
|
|
|
ret = b.buildFromDirectory(argv[4], argv[5], argv[6]);
|
2016-01-21 06:30:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
2017-05-22 03:12:48 +00:00
|
|
|
if (ret != nod::EBuildResult::Success)
|
2016-01-25 20:21:10 +00:00
|
|
|
return 1;
|
2015-06-30 19:38:51 +00:00
|
|
|
}
|
2017-02-05 06:19:34 +00:00
|
|
|
else if (!strcasecmp(argv[1], _S("makewii")))
|
2016-01-22 02:30:17 +00:00
|
|
|
{
|
|
|
|
#if NOD_UCS2
|
2016-01-24 05:06:54 +00:00
|
|
|
if (wcslen(argv[2]) < 6)
|
2017-02-05 06:19:34 +00:00
|
|
|
{
|
|
|
|
nod::LogModule.report(logvisor::Error, _S("game-id is not at least 6 characters"));
|
|
|
|
return 1;
|
|
|
|
}
|
2016-01-22 02:30:17 +00:00
|
|
|
#else
|
|
|
|
if (strlen(argv[2]) < 6)
|
2017-02-05 06:19:34 +00:00
|
|
|
{
|
|
|
|
nod::LogModule.report(logvisor::Error, _S("game-id is not at least 6 characters"));
|
|
|
|
return 1;
|
|
|
|
}
|
2016-01-22 02:30:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Pre-validate paths */
|
2016-03-04 23:04:30 +00:00
|
|
|
nod::Sstat theStat;
|
|
|
|
if (nod::Stat(argv[4], &theStat) || !S_ISDIR(theStat.st_mode))
|
2017-02-05 06:19:34 +00:00
|
|
|
{
|
|
|
|
nod::LogModule.report(logvisor::Error, _S("unable to stat %s as directory"), argv[4]);
|
|
|
|
return 1;
|
|
|
|
}
|
2016-03-04 23:04:30 +00:00
|
|
|
if (nod::Stat(argv[5], &theStat) || !S_ISREG(theStat.st_mode))
|
2017-02-05 06:19:34 +00:00
|
|
|
{
|
|
|
|
nod::LogModule.report(logvisor::Error, _S("unable to stat %s as file"), argv[5]);
|
|
|
|
return 1;
|
|
|
|
}
|
2016-03-04 23:04:30 +00:00
|
|
|
if (nod::Stat(argv[6], &theStat) || !S_ISREG(theStat.st_mode))
|
2017-02-05 06:19:34 +00:00
|
|
|
{
|
|
|
|
nod::LogModule.report(logvisor::Error, _S("unable to stat %s as file"), argv[6]);
|
|
|
|
return 1;
|
|
|
|
}
|
2016-03-04 23:04:30 +00:00
|
|
|
if (nod::Stat(argv[7], &theStat) || !S_ISREG(theStat.st_mode))
|
2017-02-05 06:19:34 +00:00
|
|
|
{
|
|
|
|
nod::LogModule.report(logvisor::Error, _S("unable to stat %s as file"), argv[7]);
|
|
|
|
return 1;
|
|
|
|
}
|
2016-03-04 23:04:30 +00:00
|
|
|
|
|
|
|
nod::SystemString gameIdSys(argv[2]);
|
|
|
|
nod::SystemUTF8View gameId(gameIdSys);
|
|
|
|
nod::SystemString gameTitleSys(argv[3]);
|
|
|
|
nod::SystemUTF8View gameTitle(gameTitleSys);
|
2017-02-05 06:19:34 +00:00
|
|
|
|
|
|
|
bool dual = false;
|
|
|
|
if (nod::DiscBuilderWii::CalculateTotalSizeRequired(argv[4], argv[5], dual) == -1)
|
|
|
|
return 1;
|
|
|
|
|
2017-05-22 03:12:48 +00:00
|
|
|
nod::EBuildResult ret;
|
2016-01-22 23:45:58 +00:00
|
|
|
|
2016-01-22 02:30:17 +00:00
|
|
|
if (argc < 9)
|
|
|
|
{
|
2016-03-04 23:04:30 +00:00
|
|
|
nod::SystemString outPath(argv[4]);
|
2016-01-22 02:30:17 +00:00
|
|
|
outPath.append(_S(".iso"));
|
2016-03-04 23:04:30 +00:00
|
|
|
nod::DiscBuilderWii b(outPath.c_str(), gameId.utf8_str().c_str(), gameTitle.utf8_str().c_str(), dual, progFunc);
|
2016-01-25 20:21:10 +00:00
|
|
|
ret = b.buildFromDirectory(argv[4], argv[5], argv[6], argv[7]);
|
2016-01-22 02:30:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-04 23:04:30 +00:00
|
|
|
nod::DiscBuilderWii b(argv[8], gameId.utf8_str().c_str(), gameTitle.utf8_str().c_str(), dual, progFunc);
|
2016-01-25 20:21:10 +00:00
|
|
|
ret = b.buildFromDirectory(argv[4], argv[5], argv[6], argv[7]);
|
2016-01-22 02:30:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
2017-05-22 03:12:48 +00:00
|
|
|
if (ret != nod::EBuildResult::Success)
|
2016-01-25 20:21:10 +00:00
|
|
|
return 1;
|
2016-01-22 02:30:17 +00:00
|
|
|
}
|
2017-02-05 06:19:34 +00:00
|
|
|
else if (!strcasecmp(argv[1], _S("mergegcn")))
|
|
|
|
{
|
|
|
|
/* Pre-validate paths */
|
|
|
|
nod::Sstat theStat;
|
|
|
|
if (nod::Stat(argv[2], &theStat) || !S_ISDIR(theStat.st_mode))
|
|
|
|
{
|
|
|
|
nod::LogModule.report(logvisor::Error, _S("unable to stat %s as directory"), argv[2]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (nod::Stat(argv[3], &theStat) || !S_ISREG(theStat.st_mode))
|
|
|
|
{
|
|
|
|
nod::LogModule.report(logvisor::Error, _S("unable to stat %s as file"), argv[3]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isWii;
|
|
|
|
std::unique_ptr<nod::DiscBase> disc = nod::OpenDiscFromImage(argv[3], isWii);
|
|
|
|
if (!disc)
|
|
|
|
{
|
|
|
|
nod::LogModule.report(logvisor::Error, _S("unable to open image %s"), argv[3]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (isWii)
|
|
|
|
{
|
|
|
|
nod::LogModule.report(logvisor::Error, _S("Wii images should be merged with 'mergewii'"));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nod::DiscMergerGCN::CalculateTotalSizeRequired(static_cast<nod::DiscGCN&>(*disc), argv[2]) == -1)
|
|
|
|
return 1;
|
|
|
|
|
2017-05-22 03:12:48 +00:00
|
|
|
nod::EBuildResult ret;
|
2017-02-05 06:19:34 +00:00
|
|
|
|
|
|
|
if (argc < 5)
|
|
|
|
{
|
|
|
|
nod::SystemString outPath(argv[2]);
|
|
|
|
outPath.append(_S(".iso"));
|
|
|
|
nod::DiscMergerGCN b(outPath.c_str(), static_cast<nod::DiscGCN&>(*disc), progFunc);
|
|
|
|
ret = b.mergeFromDirectory(argv[2]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nod::DiscMergerGCN b(argv[4], static_cast<nod::DiscGCN&>(*disc), progFunc);
|
|
|
|
ret = b.mergeFromDirectory(argv[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
2017-05-22 03:12:48 +00:00
|
|
|
if (ret != nod::EBuildResult::Success)
|
2017-02-05 06:19:34 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (!strcasecmp(argv[1], _S("mergewii")))
|
|
|
|
{
|
|
|
|
/* Pre-validate paths */
|
|
|
|
nod::Sstat theStat;
|
|
|
|
if (nod::Stat(argv[2], &theStat) || !S_ISDIR(theStat.st_mode))
|
|
|
|
{
|
|
|
|
nod::LogModule.report(logvisor::Error, _S("unable to stat %s as directory"), argv[2]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (nod::Stat(argv[3], &theStat) || !S_ISREG(theStat.st_mode))
|
|
|
|
{
|
|
|
|
nod::LogModule.report(logvisor::Error, _S("unable to stat %s as file"), argv[3]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isWii;
|
|
|
|
std::unique_ptr<nod::DiscBase> disc = nod::OpenDiscFromImage(argv[3], isWii);
|
|
|
|
if (!disc)
|
|
|
|
{
|
|
|
|
nod::LogModule.report(logvisor::Error, _S("unable to open image %s"), argv[3]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (!isWii)
|
|
|
|
{
|
|
|
|
nod::LogModule.report(logvisor::Error, _S("GameCube images should be merged with 'mergegcn'"));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool dual = false;
|
|
|
|
if (nod::DiscMergerWii::CalculateTotalSizeRequired(static_cast<nod::DiscWii&>(*disc), argv[2], dual) == -1)
|
|
|
|
return 1;
|
|
|
|
|
2017-05-22 03:12:48 +00:00
|
|
|
nod::EBuildResult ret;
|
2017-02-05 06:19:34 +00:00
|
|
|
|
|
|
|
if (argc < 5)
|
|
|
|
{
|
|
|
|
nod::SystemString outPath(argv[2]);
|
|
|
|
outPath.append(_S(".iso"));
|
|
|
|
nod::DiscMergerWii b(outPath.c_str(), static_cast<nod::DiscWii&>(*disc), dual, progFunc);
|
|
|
|
ret = b.mergeFromDirectory(argv[2]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nod::DiscMergerWii b(argv[4], static_cast<nod::DiscWii&>(*disc), dual, progFunc);
|
|
|
|
ret = b.mergeFromDirectory(argv[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
2017-05-22 03:12:48 +00:00
|
|
|
if (ret != nod::EBuildResult::Success)
|
2017-02-05 06:19:34 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2015-06-30 19:38:51 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
printHelp();
|
2016-01-25 20:21:10 +00:00
|
|
|
return 1;
|
2015-06-30 06:46:19 +00:00
|
|
|
}
|
|
|
|
|
2017-02-05 06:19:34 +00:00
|
|
|
nod::LogModule.report(logvisor::Info, _S("Success!"));
|
2015-06-30 06:46:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|