mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -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)
|
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
|
## 9.15.0
|
||||||
|
|
||||||
### YACReader
|
### YACReader
|
||||||
|
@ -47,15 +47,45 @@ bool YACReader::openComic(const ComicDB &comic,
|
|||||||
return yacreaderFound;
|
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)
|
bool YACReader::openComicInThirdPartyApp(const QString &command, const QString &path)
|
||||||
{
|
{
|
||||||
QString mutableCommand = command;
|
QStringList parsed = parseCommand(command);
|
||||||
QString fullCommand;
|
if (parsed.isEmpty()) {
|
||||||
if (mutableCommand.contains("{comic_file_path}")) {
|
qDebug() << "Empty command";
|
||||||
fullCommand = mutableCommand.replace("{comic_file_path}", "\"" + path + "\"");
|
return false;
|
||||||
} else {
|
|
||||||
fullCommand = mutableCommand + " \"" + path + "\"";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
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.
|
// 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.
|
// This value is only incremented when the database structure changes.
|
||||||
|
Loading…
Reference in New Issue
Block a user