summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-05-25 03:10:37 -0400
committerisanae <14251494+isanae@users.noreply.github.com>2019-05-25 03:10:37 -0400
commitebb855dc1421e89813a1f4a74a4963d76aba9747 (patch)
tree83fddf2d4d62ac8d35930a7c04dcf4e02c194079 /src
parent9a014db4b3a64dc93450dff8afe980db3694c595 (diff)
ExploreFile() will select the file in explorer when the path is a file
replaced more ShellExecute() calls with ExploreFile()
Diffstat (limited to 'src')
-rw-r--r--src/downloadmanager.cpp25
-rw-r--r--src/modinfodialog.cpp2
-rw-r--r--src/organizercore.cpp44
-rw-r--r--src/organizercore.h2
-rw-r--r--src/overwriteinfodialog.cpp3
5 files changed, 55 insertions, 21 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index 78162f11..686092b5 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -1037,7 +1037,7 @@ void DownloadManager::openFile(int index)
return;
}
- ::ShellExecuteW(nullptr, L"explore", ToWString(QDir::toNativeSeparators(m_OutputDirectory)).c_str(), nullptr, nullptr, SW_SHOWNORMAL);
+ ExploreFile(m_OutputDirectory);
return;
}
@@ -1047,23 +1047,22 @@ void DownloadManager::openInDownloadsFolder(int index)
reportError(tr("OpenFileInDownloadsFolder: invalid download index %1").arg(index));
return;
}
- QString params = "/select,\"";
- QDir path = QDir(m_OutputDirectory);
- if (path.exists(getFileName(index))) {
- params = params + QDir::toNativeSeparators(getFilePath(index)) + "\"";
- ::ShellExecuteW(nullptr, nullptr, L"explorer", ToWString(params).c_str(), nullptr, SW_SHOWNORMAL);
- return;
- }
- else if (path.exists(getFileName(index) + ".unfinished")) {
- params = params + QDir::toNativeSeparators(getFilePath(index)+".unfinished") + "\"";
+ const auto path = getFilePath(index);
- ::ShellExecuteW(nullptr, nullptr, L"explorer", ToWString(params).c_str(), nullptr, SW_SHOWNORMAL);
+ if (QFile::exists(path)) {
+ ExploreFile(path);
return;
}
+ else {
+ const auto unfinished = path + ".unfinished";
+ if (QFile::exists(unfinished)) {
+ ExploreFile(unfinished);
+ return;
+ }
+ }
- ::ShellExecuteW(nullptr, L"explore", ToWString(QDir::toNativeSeparators(m_OutputDirectory)).c_str(), nullptr, nullptr, SW_SHOWNORMAL);
- return;
+ ExploreFile(m_OutputDirectory);
}
diff --git a/src/modinfodialog.cpp b/src/modinfodialog.cpp
index 83c0169a..5fb3e9cf 100644
--- a/src/modinfodialog.cpp
+++ b/src/modinfodialog.cpp
@@ -1242,7 +1242,7 @@ bool ModInfoDialog::recursiveDelete(const QModelIndex &index)
void ModInfoDialog::on_openInExplorerButton_clicked()
{
- ::ShellExecuteW(nullptr, L"explore", ToWString(m_ModInfo->absolutePath()).c_str(), nullptr, nullptr, SW_SHOWNORMAL);
+ ExploreFile(m_ModInfo->absolutePath());
}
void ModInfoDialog::deleteFile(const QModelIndex &index)
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index 2542545f..d228dfe1 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -330,25 +330,59 @@ bool GetFileExecutionContext(
}
}
-bool ExploreFile(const QString& path)
+
+bool ExploreDirectory(const QFileInfo& info)
{
- const auto ws = path.toStdWString();
+ const auto path = QDir::toNativeSeparators(info.absoluteFilePath());
+ const auto ws_path = path.toStdWString();
const auto h = ::ShellExecuteW(
- nullptr, L"explore", ws.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
+ nullptr, L"explore", ws_path.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
// anything <= 32 is not an actual HINSTANCE and signals failure
return (h > reinterpret_cast<HINSTANCE>(32));
}
+bool ExploreFileInDirectory(const QFileInfo& info)
+{
+ const auto path = QDir::toNativeSeparators(info.absoluteFilePath());
+ const auto params = "/select,\"" + path + "\"";
+ const auto ws_params = params.toStdWString();
+
+ const auto h = ::ShellExecuteW(
+ nullptr, nullptr, L"explorer", ws_params.c_str(), nullptr, SW_SHOWNORMAL);
+
+ // anything <= 32 is not an actual HINSTANCE and signals failure
+ return (h > reinterpret_cast<HINSTANCE>(32));
+}
+
+
bool ExploreFile(const QFileInfo& info)
{
- return ExploreFile(info.absolutePath());
+ if (info.isFile()) {
+ return ExploreFileInDirectory(info);
+ } else if (info.isDir()) {
+ return ExploreDirectory(info);
+ } else {
+ // try the parent directory
+ const auto parent = info.dir();
+
+ if (parent.exists()) {
+ return ExploreDirectory(parent.absolutePath());
+ }
+ }
+
+ return false;
+}
+
+bool ExploreFile(const QString& path)
+{
+ return ExploreFile(QFileInfo(path));
}
bool ExploreFile(const QDir& dir)
{
- return ExploreFile(dir.absolutePath());
+ return ExploreFile(QFileInfo(dir.absolutePath()));
}
diff --git a/src/organizercore.h b/src/organizercore.h
index 103443eb..3f773277 100644
--- a/src/organizercore.h
+++ b/src/organizercore.h
@@ -67,8 +67,8 @@ bool GetFileExecutionContext(
QWidget* parent, const QFileInfo &targetInfo,
QFileInfo &binaryInfo, QString &arguments, FileExecutionTypes& type);
-bool ExploreFile(const QString& path);
bool ExploreFile(const QFileInfo& info);
+bool ExploreFile(const QString& path);
bool ExploreFile(const QDir& dir);
diff --git a/src/overwriteinfodialog.cpp b/src/overwriteinfodialog.cpp
index 3d82cf17..e9d7ce06 100644
--- a/src/overwriteinfodialog.cpp
+++ b/src/overwriteinfodialog.cpp
@@ -21,6 +21,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "ui_overwriteinfodialog.h"
#include "report.h"
#include "utility.h"
+#include "organizercore.h"
#include <QMessageBox>
#include <QMenu>
#include <QShortcut>
@@ -263,7 +264,7 @@ void OverwriteInfoDialog::createDirectoryTriggered()
void OverwriteInfoDialog::on_explorerButton_clicked()
{
- ::ShellExecuteW(nullptr, L"explore", ToWString(m_ModInfo->absolutePath()).c_str(), nullptr, nullptr, SW_SHOWNORMAL);
+ ExploreFile(m_ModInfo->absolutePath());
}
void OverwriteInfoDialog::on_filesView_customContextMenuRequested(const QPoint &pos)