Skip to content

Commit

Permalink
UI: resolve .url, .lnk shortcuts during drag-and-drop
Browse files Browse the repository at this point in the history
On applies to Windows.

Suggested here: https://ideas.obsproject.com/posts/1636
  • Loading branch information
Tim Cooper authored and jp9000 committed Mar 8, 2022
1 parent 748cf32 commit bf09a70
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions UI/window-basic-main-dropfiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <QFileInfo>
#include <QMimeData>
#include <QUrlQuery>
#ifdef _WIN32
#include <QSettings>
#endif
#include <string>

#include "window-basic-main.hpp"
Expand Down Expand Up @@ -58,6 +61,15 @@ static string GenerateSourceName(const char *base)
}
}

#ifdef _WIN32
static QString ReadWindowsURLFile(const QString &file)
{
QSettings iniFile(file, QSettings::IniFormat);
QVariant url = iniFile.value("InternetShortcut/URL");
return url.toString();
}
#endif

void OBSBasic::AddDropURL(const char *url, QString &name, obs_data_t *settings,
const obs_video_info &ovi)
{
Expand Down Expand Up @@ -247,6 +259,23 @@ void OBSBasic::dropEvent(QDropEvent *event)
continue;
}

#ifdef _WIN32
if (fileInfo.suffix().compare(
"url", Qt::CaseInsensitive) == 0) {
QString urlTarget = ReadWindowsURLFile(file);
if (!urlTarget.isEmpty()) {
ConfirmDropUrl(urlTarget);
}
continue;
} else if (fileInfo.isShortcut()) {
file = fileInfo.symLinkTarget();
fileInfo = QFileInfo(file);
if (!fileInfo.exists()) {
continue;
}
}
#endif

QString suffixQStr = fileInfo.suffix();
QByteArray suffixArray = suffixQStr.toUtf8();
const char *suffix = suffixArray.constData();
Expand Down

0 comments on commit bf09a70

Please sign in to comment.