Skip to content

Commit

Permalink
Way to misread the given task, Seong
Browse files Browse the repository at this point in the history
Accepts absolute *and* relative paths, and hope QDir solves the filepath for us in the case of relative.
  • Loading branch information
SeongGino authored Mar 26, 2024
1 parent a49b156 commit 7b06294
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,17 @@ int main(int argc, char *argv[])
}
if(arguments.contains("-p")) {
if(arguments.length() > 1) {
mainApp.customPath = QDir::fromNativeSeparators(arguments[arguments.indexOf("-p")+1]);
// QDir::fromNativeSeparators uses forwardslashes on both OSes, thank Parace
#ifdef Q_OS_WIN
// closest way to check for drive letter, since colons aren't allowed in Windows filenames anyways
if(mainApp.customPath.contains(":/")) {
#else
if(mainApp.customPath.contains('/')) {
#endif // Q_OS_WIN
mainApp.customPathSet = true;
if(!mainApp.customPath.endsWith('/')) {
mainApp.customPath.append('/');
}
qInfo() << "Setting search path to" << mainApp.customPath;
arguments.removeAt(arguments.indexOf("-p")+1);
} else {
qWarning() << "Bad custom path specified (must be an absolute path)! Disregarding.";
}
mainApp.customPath = QDir::fromNativeSeparators(arguments[arguments.indexOf("-p")+1]);
mainApp.customPathSet = true;
if(QDir::isRelativePath(mainApp.customPath)) {
mainApp.customPath.prepend(QDir::currentPath() + '/');
}
if(!mainApp.customPath.endsWith('/')) {
mainApp.customPath.append('/');
}
qInfo() << "Setting search path to" << mainApp.customPath;
arguments.removeAt(arguments.indexOf("-p")+1);
} else {
qWarning() << "Detected custom path flag without any path specified! Disregarding.";
}
Expand Down

0 comments on commit 7b06294

Please sign in to comment.