Skip to content

Commit

Permalink
Add export-texts and import-texts commands. Rename import/export to p…
Browse files Browse the repository at this point in the history
…ack/unpack
  • Loading branch information
myst6re committed Oct 29, 2024
1 parent 252f673 commit 82a2432
Show file tree
Hide file tree
Showing 38 changed files with 446 additions and 133 deletions.
16 changes: 11 additions & 5 deletions src/Arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,12 @@ Arguments::Arguments() :
QCoreApplication::translate(
"Arguments",
"\nList of available commands:\n"
" export Export files from FS archive\n"
" import Import files to FS archive\n"
" unpack Unpack files from FS archive\n"
" pack Pack files from directory to FS archive\n"
" export-texts Export texts to CSV from FIELD FS archive\n"
" import-texts Import texts from a CSV file to existing FIELD FS archive\n"
"\n"
"\"%1 export --help\" to see help of the specific subcommand"
"\"%1 unpack --help\" to see help of the specific subcommand"
).arg(QFileInfo(qApp->arguments().first()).fileName())
);

Expand All @@ -182,10 +184,14 @@ void Arguments::parse()

const QString &command = args.first();

if (command == "export") {
if (command == "export-texts") {
_command = Export;
} else if (command == "import") {
} else if (command == "import-texts") {
_command = Import;
} else if (command == "unpack") {
_command = Unpack;
} else if (command == "pack") {
_command = Pack;
} else {
qWarning() << qPrintable(QCoreApplication::translate("Arguments", "Unknown command type:")) << qPrintable(command);
return;
Expand Down
4 changes: 3 additions & 1 deletion src/Arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ class Arguments : public HelpArguments
enum Command {
None,
Export,
Import
Import,
Unpack,
Pack
};
Arguments();
inline Command command() const {
Expand Down
25 changes: 12 additions & 13 deletions src/ArgumentsExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@

ArgumentsExport::ArgumentsExport() : CommonArguments()
{
_ADD_FLAG(_OPTION_NAMES("r", "recursive"),
"Extract FS archives recursively.");
_ADD_FLAG(_OPTION_NAMES("f", "force"),
"Overwrite destination file if exists.");

_parser.addPositionalArgument("file", QCoreApplication::translate("ArgumentsExport", "Input file or directory."));
_parser.addPositionalArgument("directory", QCoreApplication::translate("ArgumentsExport", "Output directory."));
_parser.addPositionalArgument("archive", QCoreApplication::translate("ArgumentsExport", "Input Field FS archive."));
_parser.addPositionalArgument("output", QCoreApplication::translate("ArgumentsExport", "Output CSV file path."));

parse();
}

bool ArgumentsExport::recursive() const
bool ArgumentsExport::force() const
{
return _parser.isSet("recursive");
return _parser.isSet("force");
}

void ArgumentsExport::parse()
Expand All @@ -44,16 +44,15 @@ void ArgumentsExport::parse()

QStringList paths = wilcardParse();
if (paths.size() == 2) {
// Output directory
if (QDir(paths.last()).exists()) {
_directory = paths.takeLast();
} else {
// Output file
_destination = paths.takeLast();

if (!_parser.isSet("force") && QFile::exists(_destination)) {
qWarning() << qPrintable(
QCoreApplication::translate("Arguments", "Error: target directory does not exist:"))
<< qPrintable(paths.last());
QCoreApplication::translate("Arguments", "Error: target file already exist, use --force to override the file"));
exit(1);
}

if (!paths.isEmpty()) {
_path = paths.first();
}
Expand Down
6 changes: 3 additions & 3 deletions src/ArgumentsExport.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class ArgumentsExport : public CommonArguments
{
public:
ArgumentsExport();
bool recursive() const;
bool force() const;
inline QString destination() const {
return _directory;
return _destination;
}
private:
void parse();
QString _directory;
QString _destination;
};
50 changes: 16 additions & 34 deletions src/ArgumentsImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,31 @@

ArgumentsImport::ArgumentsImport() : CommonArguments()
{
_ADD_FLAG(_OPTION_NAMES("f", "force"),
"Overwrite destination file if exists.");
_ADD_ARGUMENT(_OPTION_NAMES("c", "compression"), "Compression format ([lzs], lz4, none).", "compression-format", "lzs");
_ADD_ARGUMENT("prefix", "Custom directory prefix inside the target archive (default \"c:\\ff8\\data\\\")", "prefix", "c:\\ff8\\data\\");
_ADD_FLAG(_OPTION_NAMES("c", "column"),
"Column (starting at 1) to use as text (default=2).");

_parser.addPositionalArgument("directory", QCoreApplication::translate("ArgumentsImport", "Input directory."));
_parser.addPositionalArgument("file", QCoreApplication::translate("ArgumentsImport", "Input file or directory."));
_parser.addPositionalArgument("archive", QCoreApplication::translate("ArgumentsImport", "Input Field FS archive."));
_parser.addPositionalArgument("file", QCoreApplication::translate("ArgumentsImport", "Input CSV file path."));

parse();
}

bool ArgumentsImport::force() const
int ArgumentsImport::column() const
{
return _parser.isSet("force");
}

QString ArgumentsImport::prefix() const
{
QString pre = _parser.value("prefix");

if (pre.isEmpty()) {
return "c:\\ff8\\data\\";
if (!_parser.isSet("column")) {
return 2;
}

return pre;
}

FiCompression ArgumentsImport::compressionFormat() const
{
QString compression = _parser.value("compression");
if (compression.isEmpty() || compression.toLower() == "lzs") {
return FiCompression::CompressionLzs;
}
if (compression.toLower() == "lz4") {
return FiCompression::CompressionLz4;
}
if (compression.toLower() == "none") {
return FiCompression::CompressionNone;
bool ok = false;
int ret = _parser.value("column").toInt(&ok);

if (!ok || ret <= 0) {
qWarning() << qPrintable(
QCoreApplication::translate("Arguments", "Error: column should be an integer value >= 1"));
exit(1);
}

qWarning() << qPrintable(
QCoreApplication::translate("Arguments", "Error: unknown compression, available values: lzs, lz4, none"));
exit(1);
return ret;
}

void ArgumentsImport::parse()
Expand All @@ -77,7 +59,7 @@ void ArgumentsImport::parse()
if (paths.size() == 2) {
// Source directory
if (QDir(paths.first()).exists()) {
_directory = paths.takeFirst();
_destination = paths.takeFirst();
} else {
qWarning() << qPrintable(
QCoreApplication::translate("Arguments", "Error: source directory does not exist:"))
Expand Down
8 changes: 3 additions & 5 deletions src/ArgumentsImport.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ class ArgumentsImport : public CommonArguments
{
public:
ArgumentsImport();
bool force() const;
FiCompression compressionFormat() const;
QString prefix() const;
int column() const;
inline QString source() const {
return _directory;
return _destination;
}
private:
void parse();
QString _directory;
QString _destination;
};
93 changes: 93 additions & 0 deletions src/ArgumentsPack.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/****************************************************************************
** Copyright (C) 2009-2021 Arzel Jérôme <myst6re@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, either version 3 of the License, or
** (at your option) any later version.
**
** 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 for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "ArgumentsPack.h"

ArgumentsPack::ArgumentsPack() : CommonArguments()
{
_ADD_FLAG(_OPTION_NAMES("f", "force"),
"Overwrite destination file if exists.");
_ADD_ARGUMENT(_OPTION_NAMES("c", "compression"), "Compression format ([lzs], lz4, none).", "compression-format", "lzs");
_ADD_ARGUMENT("prefix", "Custom directory prefix inside the target archive (default \"c:\\ff8\\data\\\")", "prefix", "c:\\ff8\\data\\");

_parser.addPositionalArgument("directory", QCoreApplication::translate("ArgumentsPack", "Input directory."));
_parser.addPositionalArgument("file", QCoreApplication::translate("ArgumentsPack", "Input file or directory."));

parse();
}

bool ArgumentsPack::force() const
{
return _parser.isSet("force");
}

QString ArgumentsPack::prefix() const
{
QString pre = _parser.value("prefix");

if (pre.isEmpty()) {
return "c:\\ff8\\data\\";
}

return pre;
}

FiCompression ArgumentsPack::compressionFormat() const
{
QString compression = _parser.value("compression");
if (compression.isEmpty() || compression.toLower() == "lzs") {
return FiCompression::CompressionLzs;
}
if (compression.toLower() == "lz4") {
return FiCompression::CompressionLz4;
}
if (compression.toLower() == "none") {
return FiCompression::CompressionNone;
}

qWarning() << qPrintable(
QCoreApplication::translate("Arguments", "Error: unknown compression, available values: lzs, lz4, none"));
exit(1);
}

void ArgumentsPack::parse()
{
_parser.process(*qApp);

if (_parser.positionalArguments().size() > 3) {
qWarning() << qPrintable(
QCoreApplication::translate("Arguments", "Error: too much parameters"));
exit(1);
}

QStringList paths = wilcardParse();
if (paths.size() == 2) {
// Source directory
if (QDir(paths.first()).exists()) {
_directory = paths.takeFirst();
} else {
qWarning() << qPrintable(
QCoreApplication::translate("Arguments", "Error: source directory does not exist:"))
<< qPrintable(paths.first());
exit(1);
}

if (!paths.isEmpty()) {
_path = paths.first();
}
}
mapNamesFromFiles();
}
36 changes: 36 additions & 0 deletions src/ArgumentsPack.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/****************************************************************************
** Copyright (C) 2009-2021 Arzel Jérôme <myst6re@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, either version 3 of the License, or
** (at your option) any later version.
**
** 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 for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#pragma once

#include <QtCore>
#include "Arguments.h"
#include "FsArchive.h"

class ArgumentsPack : public CommonArguments
{
public:
ArgumentsPack();
bool force() const;
FiCompression compressionFormat() const;
QString prefix() const;
inline QString source() const {
return _directory;
}
private:
void parse();
QString _directory;
};
62 changes: 62 additions & 0 deletions src/ArgumentsUnpack.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/****************************************************************************
** Copyright (C) 2009-2021 Arzel Jérôme <myst6re@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, either version 3 of the License, or
** (at your option) any later version.
**
** 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 for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "ArgumentsUnpack.h"

ArgumentsUnpack::ArgumentsUnpack() : CommonArguments()
{
_ADD_FLAG(_OPTION_NAMES("r", "recursive"),
"Extract FS archives recursively.");

_parser.addPositionalArgument("file", QCoreApplication::translate("ArgumentsUnpack", "Input file or directory."));
_parser.addPositionalArgument("directory", QCoreApplication::translate("ArgumentsUnpack", "Output directory."));

parse();
}

bool ArgumentsUnpack::recursive() const
{
return _parser.isSet("recursive");
}

void ArgumentsUnpack::parse()
{
_parser.process(*qApp);

if (_parser.positionalArguments().size() > 3) {
qWarning() << qPrintable(
QCoreApplication::translate("Arguments", "Error: too much parameters"));
exit(1);
}

QStringList paths = wilcardParse();
if (paths.size() == 2) {
// Output directory
if (QDir(paths.last()).exists()) {
_directory = paths.takeLast();
} else {
qWarning() << qPrintable(
QCoreApplication::translate("Arguments", "Error: target directory does not exist:"))
<< qPrintable(paths.last());
exit(1);
}

if (!paths.isEmpty()) {
_path = paths.first();
}
}
mapNamesFromFiles();
}
Loading

0 comments on commit 82a2432

Please sign in to comment.