mirror of
https://github.com/geode-sdk/geode.git
synced 2024-12-13 17:41:15 -05:00
84 lines
1.6 KiB
C++
84 lines
1.6 KiB
C++
|
#include <Geode/utils/platform.hpp>
|
||
|
#include <Geode/Geode.hpp>
|
||
|
|
||
|
#ifdef GEODE_IS_WINDOWS
|
||
|
|
||
|
USE_GEODE_NAMESPACE();
|
||
|
|
||
|
#include <iostream>
|
||
|
#include <sstream>
|
||
|
#include <Windows.h>
|
||
|
|
||
|
bool utils::clipboard::write(std::string const& data) {
|
||
|
if (!OpenClipboard(nullptr))
|
||
|
return false;
|
||
|
if (!EmptyClipboard()) {
|
||
|
CloseClipboard();
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
HGLOBAL hg = GlobalAlloc(GMEM_MOVEABLE, data.size() + 1);
|
||
|
|
||
|
if (!hg) {
|
||
|
CloseClipboard();
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
auto dest = GlobalLock(hg);
|
||
|
|
||
|
if (!dest) {
|
||
|
CloseClipboard();
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
memcpy(dest, data.c_str(), data.size() + 1);
|
||
|
|
||
|
GlobalUnlock(hg);
|
||
|
|
||
|
SetClipboardData(CF_TEXT, hg);
|
||
|
CloseClipboard();
|
||
|
|
||
|
GlobalFree(hg);
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
std::string utils::clipboard::read() {
|
||
|
if (!OpenClipboard(nullptr))
|
||
|
return "";
|
||
|
|
||
|
HANDLE hData = GetClipboardData(CF_TEXT);
|
||
|
if (hData == nullptr) {
|
||
|
CloseClipboard();
|
||
|
return "";
|
||
|
}
|
||
|
|
||
|
char * pszText = static_cast<char*>(GlobalLock(hData));
|
||
|
if (pszText == nullptr) {
|
||
|
CloseClipboard();
|
||
|
return "";
|
||
|
}
|
||
|
|
||
|
std::string text(pszText);
|
||
|
|
||
|
GlobalUnlock(hData);
|
||
|
CloseClipboard();
|
||
|
|
||
|
return text;
|
||
|
}
|
||
|
|
||
|
ghc::filesystem::path utils::dirs::geodeRoot() {
|
||
|
return ghc::filesystem::path(CCFileUtils::sharedFileUtils()->getWritablePath2().c_str());
|
||
|
}
|
||
|
|
||
|
bool utils::dirs::openFolder(ghc::filesystem::path const& path) {
|
||
|
ShellExecuteA(NULL, "open", path.string().c_str(), NULL, NULL, SW_SHOWDEFAULT);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void geode::utils::web::openLinkInBrowser(std::string const& url) {
|
||
|
ShellExecuteA(0, 0, url.c_str(), 0, 0, SW_SHOW);
|
||
|
}
|
||
|
|
||
|
#endif
|