From 9ab95a0f0efa2fa1d15da6bd6c2b5e923bb1af42 Mon Sep 17 00:00:00 2001 From: Treeki Date: Wed, 12 Sep 2012 15:44:55 +0200 Subject: console interface --- LayoutStudio.pro | 1 + main.cpp | 117 +++++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 106 insertions(+), 12 deletions(-) mode change 100644 => 100755 LayoutStudio.pro mode change 100644 => 100755 main.cpp diff --git a/LayoutStudio.pro b/LayoutStudio.pro old mode 100644 new mode 100755 index cd34307..2b61e62 --- a/LayoutStudio.pro +++ b/LayoutStudio.pro @@ -2,6 +2,7 @@ # Project created by QtCreator 2010-10-03T04:03:27 # ------------------------------------------------- QT += xml +CONFIG += console TARGET = LayoutStudio TEMPLATE = app SOURCES += main.cpp \ diff --git a/main.cpp b/main.cpp old mode 100644 new mode 100755 index a8ae533..1a46dfe --- a/main.cpp +++ b/main.cpp @@ -31,42 +31,135 @@ #include "lsrlytexporter.h" #include #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)); - LSExportPackage(&eArc, args.at(3)); + 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) { - LYTArchivePackage eArc(dir.filePath(thing)); QString niceName = thing; niceName.replace(".arc", ""); - LSExportPackage(&eArc, outDir.filePath("exp_"+niceName)); + 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)); - QStringList filters("*.arc"); - QStringList things = dir.entryList(filters); + outDir.mkpath("."); + QStringList things = dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot); foreach (const QString &thing, things) { - QString niceName = thing; - niceName.replace(".arc", ""); QDir inDir = dir; - inDir.cd(niceName); - LYTArchivePackage eArc(inDir.filePath(thing)); - LSExportPackage(&eArc, outDir.filePath("exp_"+niceName)); + 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 { - std::printf("LayoutStudio command-line un-exporter"); + 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; -- cgit v1.2.3