mirror of
https://github.com/YACReader/yacreader
synced 2025-05-25 18:00:46 -04:00
Use QProcess as intented by parsing the input command arguments
This commit is contained in:
parent
a5ff7c8ccf
commit
1cd8635808
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user