/*******************************************************************************
This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio)
Copyright (c) 2010 Treeki (treeki@gmail.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 2.0.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License 2.0 for more details.
You should have received a copy of the GNU General Public License 2.0
along with this program. If not, see .
*******************************************************************************/
#include
#include "lyt/directorypackage.h"
#include "lyt/archivepackage.h"
#include "lyt/layout.h"
#include
#include "wii/archiveu8.h"
#include
#include "lsrlytexporter.h"
#include
#include
#include
#include
#include "lyt/animation.h"
static QIODevice *debugDevice = 0;
void newMsgHandler(QtMsgType type, const char *msg) {
if (debugDevice && type == QtDebugMsg) {
debugDevice->write(msg);
debugDevice->write("\n", 1);
return;
}
switch (type) {
case QtDebugMsg:
fprintf(stderr, "4:D> %s\n", msg);
break;
case QtWarningMsg:
fprintf(stderr, "3:W> %s\n", msg);
break;
case QtCriticalMsg:
fprintf(stderr, "2:C> %s\n", msg);
break;
case QtFatalMsg:
fprintf(stderr, "1:F> %s\n", msg);
abort();
}
}
int main(int argc, char *argv[]) {
qInstallMsgHandler(newMsgHandler);
QCoreApplication a(argc, argv);
QStringList args = a.arguments();
if (args.count() == 4 && args.at(1) == "export") {
QDir expDir(args.at(3));
expDir.mkpath(".");
QFile debugFile(expDir.filePath("LS_ArchiveReadLog.txt"));
debugFile.open(QFile::WriteOnly | QFile::Text);
debugDevice = &debugFile;
LYTArchivePackage eArc(args.at(2));
debugDevice = 0;
debugFile.close();
QFile debugFile2(expDir.filePath("LS_LayoutReadLog.txt"));
debugFile2.open(QFile::WriteOnly | QFile::Text);
debugDevice = &debugFile2;
LSExportPackage(&eArc, expDir.path());
debugDevice = 0;
debugFile2.close();
} else if (args.count() == 4 && args.at(1) == "export-dir") {
QDir dir(args.at(2));
QDir outDir(args.at(3));
outDir.mkpath(".");
QStringList filters("*.arc");
QStringList things = dir.entryList(filters);
foreach (const QString &thing, things) {
QString niceName = thing;
niceName.replace(".arc", "");
fprintf(stdout, "Exporting %s ...\n", thing.toAscii().constData());
QDir expDir = outDir;
expDir.cd("exp_"+niceName);
expDir.mkpath(".");
QFile debugFile(expDir.filePath("LS_ArchiveReadLog.txt"));
debugFile.open(QFile::WriteOnly | QFile::Text);
debugDevice = &debugFile;
LYTArchivePackage eArc(dir.filePath(thing));
debugDevice = 0;
debugFile.close();
QFile debugFile2(expDir.filePath("LS_LayoutReadLog.txt"));
debugFile2.open(QFile::WriteOnly | QFile::Text);
debugDevice = &debugFile2;
LSExportPackage(&eArc, expDir.path());
debugDevice = 0;
debugFile2.close();
}
} else if (args.count() == 4 && args.at(1) == "export-nsmb") {
QDir dir(args.at(2));
QDir outDir(args.at(3));
outDir.mkpath(".");
QStringList things = dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
foreach (const QString &thing, things) {
QDir inDir = dir;
inDir.cd(thing);
fprintf(stdout, "Checking dir %s ...\n", thing.toAscii().constData());
if (inDir.exists(thing+".arc")) {
fprintf(stdout, "Exporting ...\n");
QDir expDir = outDir;
expDir.cd("exp_"+thing);
expDir.mkpath(".");
QFile debugFile(expDir.filePath("LS_ArchiveReadLog.txt"));
debugFile.open(QFile::WriteOnly | QFile::Text);
debugDevice = &debugFile;
LYTArchivePackage eArc(inDir.filePath(thing+".arc"));
debugDevice = 0;
debugFile.close();
QFile debugFile2(expDir.filePath("LS_LayoutReadLog.txt"));
debugFile2.open(QFile::WriteOnly | QFile::Text);
debugDevice = &debugFile2;
LSExportPackage(&eArc, expDir.path());
debugDevice = 0;
debugFile2.close();
} else {
fprintf(stdout, "No matching arc found\n");
}
}
} else {
fprintf(stdout, "LayoutStudio command-line un-exporter\n");
fprintf(stdout, "(c) Treeki 2010-2012. Please do not distribute.\n");
fprintf(stdout, "\n");
fprintf(stdout, "Accepted commands:\n");
fprintf(stdout, " + ./LS export path/to/layout.arc output/directory\n");
fprintf(stdout, " exports one layout to RLYT, RLAN and TGA\n");
fprintf(stdout, "\n");
fprintf(stdout, " + ./LS export-dir path/to/input/directory output/directory\n");
fprintf(stdout, " exports every arc file in a specific directory\n");
fprintf(stdout, "\n");
fprintf(stdout, " + ./LS export-nsmb path/to/input/directory output/directory\n");
fprintf(stdout, " exports every arc file in named dirs inside a specfic directory\n");
fprintf(stdout, " for example: inDir/layout1/layout1.arc, inDir/layout2/layout2.arc ...\n");
fprintf(stdout, "\n");
}
return 0;
}