Merge branch 'master' into jgrpp
# Conflicts: # src/console.cpp # src/os/os2/os2.cpp # src/os/unix/font_unix.cpp # src/strgen/strgen.h # src/strgen/strgen_base.cpp # src/table/settings/gui_settings.ini
This commit is contained in:
@@ -189,25 +189,21 @@ const char *GetCurrentLocale(const char *)
|
||||
/**
|
||||
* Return the contents of the clipboard (COCOA).
|
||||
*
|
||||
* @param buffer Clipboard content.
|
||||
* @param last The pointer to the last element of the destination buffer
|
||||
* @return Whether clipboard is empty or not.
|
||||
* @return The (optional) clipboard contents.
|
||||
*/
|
||||
bool GetClipboardContents(char *buffer, const char *last)
|
||||
std::optional<std::string> GetClipboardContents()
|
||||
{
|
||||
NSPasteboard *pb = [ NSPasteboard generalPasteboard ];
|
||||
NSArray *types = [ NSArray arrayWithObject:NSPasteboardTypeString ];
|
||||
NSString *bestType = [ pb availableTypeFromArray:types ];
|
||||
|
||||
/* Clipboard has no text data available. */
|
||||
if (bestType == nil) return false;
|
||||
if (bestType == nil) return std::nullopt;
|
||||
|
||||
NSString *string = [ pb stringForType:NSPasteboardTypeString ];
|
||||
if (string == nil || [ string length ] == 0) return false;
|
||||
if (string == nil || [ string length ] == 0) return std::nullopt;
|
||||
|
||||
strecpy(buffer, [ string UTF8String ], last);
|
||||
|
||||
return true;
|
||||
return [ string UTF8String ];
|
||||
}
|
||||
|
||||
/** Set the application's bundle directory.
|
||||
|
@@ -16,9 +16,12 @@
|
||||
|
||||
#include <mach-o/arch.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <thread>
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
extern std::string SurveyMemoryToText(uint64_t memory);
|
||||
|
||||
void SurveyOS(nlohmann::json &json)
|
||||
{
|
||||
int ver_maj, ver_min, ver_bug;
|
||||
@@ -32,7 +35,8 @@ void SurveyOS(nlohmann::json &json)
|
||||
json["min_ver"] = MAC_OS_X_VERSION_MIN_REQUIRED;
|
||||
json["max_ver"] = MAC_OS_X_VERSION_MAX_ALLOWED;
|
||||
|
||||
json["memory"] = MacOSGetPhysicalMemory();
|
||||
json["memory"] = SurveyMemoryToText(MacOSGetPhysicalMemory());
|
||||
json["hardware_concurrency"] = std::thread::hardware_concurrency();
|
||||
}
|
||||
|
||||
#endif /* WITH_NLOHMANN_JSON */
|
||||
|
@@ -174,27 +174,25 @@ int CDECL main(int argc, char *argv[])
|
||||
return openttd_main(argc, argv);
|
||||
}
|
||||
|
||||
bool GetClipboardContents(char *buffer, const char *last)
|
||||
std::optional<std::string> GetClipboardContents()
|
||||
{
|
||||
/* XXX -- Currently no clipboard support implemented with GCC */
|
||||
#ifndef __INNOTEK_LIBC__
|
||||
HAB hab = 0;
|
||||
|
||||
if (WinOpenClipbrd(hab))
|
||||
{
|
||||
const char *text = (const char*)WinQueryClipbrdData(hab, CF_TEXT);
|
||||
if (WinOpenClipbrd(hab)) {
|
||||
const char *text = (const char *)WinQueryClipbrdData(hab, CF_TEXT);
|
||||
|
||||
if (text != nullptr)
|
||||
{
|
||||
strecpy(buffer, text, last);
|
||||
if (text != nullptr) {
|
||||
std::string result = text;
|
||||
WinCloseClipbrd(hab);
|
||||
return true;
|
||||
return result;
|
||||
}
|
||||
|
||||
WinCloseClipbrd(hab);
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -13,10 +13,13 @@
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <sys/utsname.h>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
extern std::string SurveyMemoryToText(uint64_t memory);
|
||||
|
||||
void SurveyOS(nlohmann::json &json)
|
||||
{
|
||||
struct utsname name;
|
||||
@@ -32,7 +35,8 @@ void SurveyOS(nlohmann::json &json)
|
||||
|
||||
long pages = sysconf(_SC_PHYS_PAGES);
|
||||
long page_size = sysconf(_SC_PAGE_SIZE);
|
||||
json["memory"] = pages * page_size;
|
||||
json["memory"] = SurveyMemoryToText(pages * page_size);
|
||||
json["hardware_concurrency"] = std::thread::hardware_concurrency();
|
||||
}
|
||||
|
||||
#endif /* WITH_NLOHMANN_JSON */
|
||||
|
@@ -270,22 +270,20 @@ int CDECL main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
#ifndef WITH_COCOA
|
||||
bool GetClipboardContents(char *buffer, const char *last)
|
||||
std::optional<std::string> GetClipboardContents()
|
||||
{
|
||||
#ifdef WITH_SDL2
|
||||
if (SDL_HasClipboardText() == SDL_FALSE) {
|
||||
return false;
|
||||
}
|
||||
if (SDL_HasClipboardText() == SDL_FALSE) return std::nullopt;
|
||||
|
||||
char *clip = SDL_GetClipboardText();
|
||||
if (clip != nullptr) {
|
||||
strecpy(buffer, clip, last);
|
||||
std::string result = clip;
|
||||
SDL_free(clip);
|
||||
return true;
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
return false;
|
||||
return std::nullopt;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@@ -14,10 +14,13 @@
|
||||
#include "../../core/format.hpp"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <thread>
|
||||
#include <windows.h>
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
extern std::string SurveyMemoryToText(uint64_t memory);
|
||||
|
||||
void SurveyOS(nlohmann::json &json)
|
||||
{
|
||||
_OSVERSIONINFOA os;
|
||||
@@ -31,7 +34,8 @@ void SurveyOS(nlohmann::json &json)
|
||||
status.dwLength = sizeof(status);
|
||||
GlobalMemoryStatusEx(&status);
|
||||
|
||||
json["memory"] = status.ullTotalPhys;
|
||||
json["memory"] = SurveyMemoryToText(status.ullTotalPhys);
|
||||
json["hardware_concurrency"] = std::thread::hardware_concurrency();
|
||||
}
|
||||
|
||||
#endif /* WITH_NLOHMANN_JSON */
|
||||
|
@@ -549,26 +549,19 @@ void DetermineBasePaths(const char *exe)
|
||||
}
|
||||
|
||||
|
||||
bool GetClipboardContents(char *buffer, const char *last)
|
||||
std::optional<std::string> GetClipboardContents()
|
||||
{
|
||||
HGLOBAL cbuf;
|
||||
const char *ptr;
|
||||
if (!IsClipboardFormatAvailable(CF_UNICODETEXT)) return std::nullopt;
|
||||
|
||||
if (IsClipboardFormatAvailable(CF_UNICODETEXT)) {
|
||||
OpenClipboard(nullptr);
|
||||
cbuf = GetClipboardData(CF_UNICODETEXT);
|
||||
OpenClipboard(nullptr);
|
||||
HGLOBAL cbuf = GetClipboardData(CF_UNICODETEXT);
|
||||
|
||||
ptr = (const char*)GlobalLock(cbuf);
|
||||
int out_len = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)ptr, -1, buffer, (last - buffer) + 1, nullptr, nullptr);
|
||||
GlobalUnlock(cbuf);
|
||||
CloseClipboard();
|
||||
std::string result = FS2OTTD(static_cast<LPCWSTR>(GlobalLock(cbuf)));
|
||||
GlobalUnlock(cbuf);
|
||||
CloseClipboard();
|
||||
|
||||
if (out_len == 0) return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
if (result.empty()) return std::nullopt;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user