From 8a06024bd2f8d64349689432f6ac308ca36f99f9 Mon Sep 17 00:00:00 2001 From: Alex Sanchez-Stern Date: Mon, 14 Oct 2024 19:29:43 -0700 Subject: [PATCH] Fix some more windows build errors --- src/gui/clipboard.cpp | 4 ++- src/gui/dragdrop/dragdropmanager.cpp | 37 ++++++---------------------- 2 files changed, 10 insertions(+), 31 deletions(-) diff --git a/src/gui/clipboard.cpp b/src/gui/clipboard.cpp index e9a3523..3bc6149 100644 --- a/src/gui/clipboard.cpp +++ b/src/gui/clipboard.cpp @@ -271,7 +271,9 @@ namespace Toolbox { return make_clipboard_error( "Can't set clipboard to mulitple types at once on Windows!"); } - TOOLBOX_ASSERT(formats.size() > 0); + if (formats.size() == 0) { + return make_clipboard_error("The mimedata set on the clipboard has no formats!"); + } auto type = formats[0]; std::optional result = mimedata.get_data(type); diff --git a/src/gui/dragdrop/dragdropmanager.cpp b/src/gui/dragdrop/dragdropmanager.cpp index 049824d..4172be0 100644 --- a/src/gui/dragdrop/dragdropmanager.cpp +++ b/src/gui/dragdrop/dragdropmanager.cpp @@ -15,29 +15,6 @@ #elif defined(TOOLBOX_PLATFORM_LINUX) #endif -static std::vector splitLines(std::string_view s) { - std::vector result; - size_t last_pos = 0; - size_t next_newline_pos = s.find('\n', 0); - while (next_newline_pos != std::string::npos) { - if (s[next_newline_pos - 1] == '\r') { - result.push_back(s.substr(last_pos, next_newline_pos - last_pos - 1)); - } else { - result.push_back(s.substr(last_pos, next_newline_pos - last_pos)); - } - last_pos = next_newline_pos + 1; - next_newline_pos = s.find('\n', last_pos); - } - if (last_pos < s.size()) { - if (s[s.size() - 1] == '\r') { - result.push_back(s.substr(last_pos, s.size() - last_pos - 1)); - } else { - result.push_back(s.substr(last_pos)); - } - } - return result; -} - namespace Toolbox::UI { RefPtr DragDropManager::createDragAction(UUID64 source_uuid, MimeData &&data, bool system_level) { @@ -59,18 +36,18 @@ namespace Toolbox::UI { void DragDropManager::shutdown() { OleUninitialize(); } Result DragDropManager::createSystemDragDropSource(MimeData &&data) { - std::string paths = data.get_urls().value_or(""); + auto maybe_paths = data.get_urls(); + if (!maybe_paths) { + return make_error("DRAG_DROP", "Passed Mimedata did not include urls"); + } + std::vector paths = maybe_paths.value(); std::vector pidls; - std::vector lines = splitLines(paths); size_t next_newline_pos = 0; - for (const std::string_view &line : lines) { - if (line.empty()) { - continue; - } + for (const std::string_view &path : paths) { - std::wstring wpath = std::wstring(line.begin(), line.end()); + std::wstring wpath = std::wstring(path.begin(), path.end()); PIDLIST_ABSOLUTE pidl = ILCreateFromPathW(wpath.c_str()); if (pidl == NULL) {