mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-06-16 16:33:55 +02:00
Canonicalize paths during drag-and-drop
Otherwise we will get a path from somewhere in `$WINEPREFIX/dosdevices`.
This commit is contained in:
@@ -24,6 +24,8 @@
|
|||||||
|
|
||||||
using namespace std::literals::chrono_literals;
|
using namespace std::literals::chrono_literals;
|
||||||
|
|
||||||
|
namespace fs = boost::filesystem;
|
||||||
|
|
||||||
// As defined in `editor.cpp`
|
// As defined in `editor.cpp`
|
||||||
#define THROW_X11_ERROR(error) \
|
#define THROW_X11_ERROR(error) \
|
||||||
do { \
|
do { \
|
||||||
@@ -192,9 +194,9 @@ WineXdndProxy::Handle WineXdndProxy::get_handle() {
|
|||||||
return Handle(instance);
|
return Handle(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WineXdndProxy::begin_xdnd(
|
void WineXdndProxy::begin_xdnd(const boost::container::small_vector_base<
|
||||||
const boost::container::small_vector_base<std::string>& file_paths,
|
boost::filesystem::path>& file_paths,
|
||||||
HWND tracker_window) {
|
HWND tracker_window) {
|
||||||
if (file_paths.empty()) {
|
if (file_paths.empty()) {
|
||||||
throw std::runtime_error("Cannot drag-and-drop without any files");
|
throw std::runtime_error("Cannot drag-and-drop without any files");
|
||||||
}
|
}
|
||||||
@@ -223,7 +225,7 @@ void WineXdndProxy::begin_xdnd(
|
|||||||
((strlen(file_protocol) - 1 + sizeof('\n')) * file_paths.size()));
|
((strlen(file_protocol) - 1 + sizeof('\n')) * file_paths.size()));
|
||||||
for (const auto& path : file_paths) {
|
for (const auto& path : file_paths) {
|
||||||
dragged_files_uri_list.append(file_protocol);
|
dragged_files_uri_list.append(file_protocol);
|
||||||
dragged_files_uri_list.append(path);
|
dragged_files_uri_list.append(path.string());
|
||||||
dragged_files_uri_list.push_back('\n');
|
dragged_files_uri_list.push_back('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -708,7 +710,7 @@ void CALLBACK dnd_winevent_callback(HWINEVENTHOOK /*hWinEventHook*/,
|
|||||||
enumerator->Release();
|
enumerator->Release();
|
||||||
|
|
||||||
// This will contain the normal, Unix-style paths to the files
|
// This will contain the normal, Unix-style paths to the files
|
||||||
boost::container::small_vector<std::string, 4> dragged_files;
|
boost::container::small_vector<fs::path, 4> dragged_files;
|
||||||
for (unsigned int format_idx = 0; format_idx < num_formats; format_idx++) {
|
for (unsigned int format_idx = 0; format_idx < num_formats; format_idx++) {
|
||||||
STGMEDIUM storage{};
|
STGMEDIUM storage{};
|
||||||
if (HRESULT result = tracker_info->dataObject->GetData(
|
if (HRESULT result = tracker_info->dataObject->GetData(
|
||||||
@@ -733,15 +735,36 @@ void CALLBACK dnd_winevent_callback(HWINEVENTHOOK /*hWinEventHook*/,
|
|||||||
DragQueryFileW(drop, file_idx, file_name.data(),
|
DragQueryFileW(drop, file_idx, file_name.data(),
|
||||||
file_name.size());
|
file_name.size());
|
||||||
|
|
||||||
dragged_files.emplace_back(
|
// Normalize the paths to something a bit more friendly
|
||||||
wine_get_unix_file_name(file_name.data()));
|
const char* unix_path =
|
||||||
|
wine_get_unix_file_name(file_name.data());
|
||||||
|
if (unix_path) {
|
||||||
|
boost::system::error_code err;
|
||||||
|
const fs::path cannonical_path =
|
||||||
|
boost::filesystem::canonical(unix_path, err);
|
||||||
|
if (err) {
|
||||||
|
dragged_files.emplace_back(unix_path);
|
||||||
|
} else {
|
||||||
|
dragged_files.emplace_back(cannonical_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalUnlock(storage.hGlobal);
|
GlobalUnlock(storage.hGlobal);
|
||||||
} break;
|
} break;
|
||||||
case TYMED_FILE: {
|
case TYMED_FILE: {
|
||||||
dragged_files.emplace_back(
|
const char* unix_path =
|
||||||
wine_get_unix_file_name(storage.lpszFileName));
|
wine_get_unix_file_name(storage.lpszFileName);
|
||||||
|
if (unix_path) {
|
||||||
|
boost::system::error_code err;
|
||||||
|
const fs::path cannonical_path =
|
||||||
|
boost::filesystem::canonical(unix_path, err);
|
||||||
|
if (err) {
|
||||||
|
dragged_files.emplace_back(unix_path);
|
||||||
|
} else {
|
||||||
|
dragged_files.emplace_back(cannonical_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
default: {
|
default: {
|
||||||
std::cerr << "Unknown drag-and-drop format "
|
std::cerr << "Unknown drag-and-drop format "
|
||||||
|
|||||||
@@ -136,9 +136,9 @@ class WineXdndProxy {
|
|||||||
* Initiate the XDDN protocol by taking ownership of the `XdndSelection`
|
* Initiate the XDDN protocol by taking ownership of the `XdndSelection`
|
||||||
* selection and setting up the event listeners.
|
* selection and setting up the event listeners.
|
||||||
*/
|
*/
|
||||||
void begin_xdnd(
|
void begin_xdnd(const boost::container::small_vector_base<
|
||||||
const boost::container::small_vector_base<std::string>& file_paths,
|
boost::filesystem::path>& file_paths,
|
||||||
HWND tracker_window);
|
HWND tracker_window);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Release ownership of the selection stop listening for X11 events.
|
* Release ownership of the selection stop listening for X11 events.
|
||||||
@@ -236,7 +236,7 @@ class WineXdndProxy {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The files that are currently being dragged, stored as in `text/uri-list`
|
* The files that are currently being dragged, stored as in `text/uri-list`
|
||||||
* format (i.e. a list of URIs, separated by line feeds)
|
* format (i.e. a list of URIs, each ending with a line feed)
|
||||||
*/
|
*/
|
||||||
std::string dragged_files_uri_list;
|
std::string dragged_files_uri_list;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user