mirror of
https://github.com/overte-org/overte.git
synced 2025-04-26 05:36:40 +02:00
- change log location lo application data folder - reveal file in Finder (Explorer) implementation
56 lines
1.3 KiB
C++
56 lines
1.3 KiB
C++
//
|
|
// FileUtils.cpp
|
|
// hifi
|
|
//
|
|
// Created by Stojce Slavkovski on 12/23/13.
|
|
//
|
|
//
|
|
|
|
#include "FileUtils.h"
|
|
#include <QtCore>
|
|
#include <QDesktopServices>
|
|
|
|
void FileUtils::LocateFile(QString filePath) {
|
|
|
|
// adopted from
|
|
// http://stackoverflow.com/questions/3490336/how-to-reveal-in-finder-or-show-in-explorer-with-qt
|
|
// and
|
|
// http://lynxline.com/show-in-finder-show-in-explorer/
|
|
|
|
QFileInfo fileInfo(filePath);
|
|
if (!fileInfo.exists()) {
|
|
return;
|
|
}
|
|
|
|
bool success = false;
|
|
#ifdef Q_OS_MAC
|
|
QStringList args;
|
|
args << "-e";
|
|
args << "tell application \"Finder\"";
|
|
args << "-e";
|
|
args << "activate";
|
|
args << "-e";
|
|
args << "select POSIX file \"" + fileInfo.absoluteFilePath().toUtf8() + "\"";
|
|
args << "-e";
|
|
args << "end tell";
|
|
success = QProcess::startDetached("osascript", args);
|
|
#endif
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
QStringList args;
|
|
// don't send `select` command switch if `filePath` is folder
|
|
if (!fileInfo.isDir()) {
|
|
args << "/select,";
|
|
}
|
|
args += QDir::toNativeSeparators(fileInfo.absoluteFilePath().toUtf8());
|
|
success = QProcess::startDetached("explorer", args);
|
|
|
|
#endif
|
|
|
|
// fallback, open enclosing folder
|
|
if (!success) {
|
|
const QString folder = fileInfo.path();
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(folder));
|
|
}
|
|
}
|