diff --git a/CHANGELOG.md b/CHANGELOG.md index b695de3c..511fe01c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ Version counting is based on semantic versioning (Major.Feature.Patch) +## WIP (9.15.1) + +### YACReaderLibrary +* Improve flexibility of the open comic in third party app setting so more complex commands can be used. e.g. `open -a "/Applications/My Reader.app" "{comic_file_path}"`. + ## 9.15.0 ### YACReader diff --git a/YACReaderLibrary/library_comic_opener.cpp b/YACReaderLibrary/library_comic_opener.cpp index 595cdbf7..ede63f33 100644 --- a/YACReaderLibrary/library_comic_opener.cpp +++ b/YACReaderLibrary/library_comic_opener.cpp @@ -47,15 +47,45 @@ bool YACReader::openComic(const ComicDB &comic, return yacreaderFound; } +QStringList parseCommand(const QString &input) +{ + QRegularExpression regex(R"((?:\"([^\"]*)\")|(\S+))"); + QStringList result; + auto it = regex.globalMatch(input); + while (it.hasNext()) { + QRegularExpressionMatch match = it.next(); + if (match.hasMatch()) { + result << (match.captured(1).isEmpty() ? match.captured(2) : match.captured(1)); + } + } + return result; +} + bool YACReader::openComicInThirdPartyApp(const QString &command, const QString &path) { - QString mutableCommand = command; - QString fullCommand; - if (mutableCommand.contains("{comic_file_path}")) { - fullCommand = mutableCommand.replace("{comic_file_path}", "\"" + path + "\""); - } else { - fullCommand = mutableCommand + " \"" + path + "\""; + QStringList parsed = parseCommand(command); + if (parsed.isEmpty()) { + qDebug() << "Empty command"; + return false; } - return QProcess::startDetached(fullCommand, {}); + QString program = parsed.takeFirst(); + QStringList rawArguments = parsed; + QStringList arguments; + + auto placeholderFound = false; + for (auto argument : rawArguments) { + if (argument.contains("{comic_file_path}")) { + placeholderFound = true; + arguments << argument.replace("{comic_file_path}", path); + } else { + arguments << argument; + } + } + + if (!placeholderFound) { + arguments << path; + } + + return QProcess::startDetached(program, arguments); } diff --git a/common/yacreader_global.h b/common/yacreader_global.h index b8a13bba..c3b19e95 100644 --- a/common/yacreader_global.h +++ b/common/yacreader_global.h @@ -8,7 +8,7 @@ class QLibrary; -#define VERSION "9.15.0" +#define VERSION "9.15.1" // Used to check if the database needs to be updated, the version is stored in the database. // This value is only incremented when the database structure changes.