Skip to content

Commit

Permalink
Fix import texts
Browse files Browse the repository at this point in the history
  • Loading branch information
myst6re committed Oct 31, 2024
1 parent f550797 commit fc9d6bf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
30 changes: 16 additions & 14 deletions src/ArgumentsImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
ArgumentsImport::ArgumentsImport() : ArgumentsImportExport()
{
_ADD_ARGUMENT(_OPTION_NAMES("c", "column"),
"Column (starting at 1) to use as text.", "COLUMN", "2");
"Column (starting at 1) to use as text.", "COLUMN", "1");

_parser.addPositionalArgument("archive", QCoreApplication::translate("ArgumentsImport", "Input Field FS archive."));
_parser.addPositionalArgument("file", QCoreApplication::translate("ArgumentsImport", "Input CSV file path."));
Expand All @@ -32,19 +32,19 @@ ArgumentsImport::ArgumentsImport() : ArgumentsImportExport()
int ArgumentsImport::column() const
{
if (!_parser.isSet("column")) {
return 2;
return 0;
}

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);
}
return ret;

return ret - 1;
}

void ArgumentsImport::parse()
Expand All @@ -59,18 +59,20 @@ void ArgumentsImport::parse()

QStringList paths = wilcardParse();
if (paths.size() == 2) {
// Source directory
if (QDir(paths.first()).exists()) {
_destination = paths.takeFirst();
} else {
_destination = paths.last();

if (!QFile::exists(_destination)) {
qWarning() << qPrintable(
QCoreApplication::translate("Arguments", "Error: source directory does not exist:"))
<< qPrintable(paths.first());
QCoreApplication::translate("Arguments", "Error: CSV file does not exist"));
exit(1);
}

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

if (!QFile::exists(_path)) {
qWarning() << qPrintable(
QCoreApplication::translate("Arguments", "Error: Field archive does not exist"));
exit(1);
}
}
}
17 changes: 8 additions & 9 deletions src/CLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,24 @@ void CLI::commandImport()
if (args.help() || args.source().isEmpty()) {
args.showHelp();
}
FsArchive *archive = openArchive(args.inputFormat(), args.path());
if (archive == nullptr) {
return;
}


FieldArchivePC fieldArchive;
if (fieldArchive.open(args.path(), &observer) != 0) {
qWarning() << fieldArchive.errorMessage();
qWarning() << "Cannot open field archive" << fieldArchive.errorMessage();
return;
}

TextExporter exporter(&fieldArchive);
if (!exporter.fromCsv(args.source(), args.column(), args.separator(), args.quoteCharacter(), CsvFile::Utf8, &observer) && !observer.observerWasCanceled()) {
qWarning() << "Cannot import CSV file" << exporter.errorString();
return;
}

fieldArchive.save(&observer);
}

if (!fieldArchive.save(&observer)) {
qWarning() << "Cannot save field archive" << fieldArchive.errorMessage();
return;
}
}

void CLI::commandUnpack()
{
Expand Down
2 changes: 1 addition & 1 deletion src/TextExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ bool TextExporter::fromCsv(const QString &fileName, quint8 column, QChar fieldSe
if (column < line.size()) {
texts.append(FF8Text(line.at(column)).toFF8());
} else {
qWarning() << "TextExporter::fromCsv invalid CSV" << line << "at line" << currentLine;
qWarning() << "TextExporter::fromCsv column" << column << " is asked, but line" << currentLine << "has only" << line.size() << "columns";
}
}
}
Expand Down

0 comments on commit fc9d6bf

Please sign in to comment.