From fb1e8559b177939464f39d5fc9424078b600b984 Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 22 May 2010 14:15:29 +0200 Subject: [PATCH] Changed: #927 Move OS specific code from client or server to NeL when it's possible --- code/nel/include/nel/misc/system_utils.h | 33 ++ code/nel/src/misc/displayer.cpp | 29 +- code/nel/src/misc/system_utils.cpp | 254 ++++++++++++++ code/ryzom/client/src/connection.cpp | 10 +- code/ryzom/client/src/init.cpp | 15 +- .../client/src/interface_v3/group_editbox.cpp | 317 ++++++++---------- code/ryzom/client/src/login.cpp | 86 +---- code/ryzom/client/src/login.h | 5 - code/ryzom/client/src/misc.cpp | 24 +- code/ryzom/client/src/r2/editor.cpp | 33 +- code/ryzom/client/src/release.cpp | 8 +- 11 files changed, 470 insertions(+), 344 deletions(-) diff --git a/code/nel/include/nel/misc/system_utils.h b/code/nel/include/nel/misc/system_utils.h index b0a0f66bd..c8e5b578f 100644 --- a/code/nel/include/nel/misc/system_utils.h +++ b/code/nel/include/nel/misc/system_utils.h @@ -44,6 +44,39 @@ public: /// Create/update a progress bar with an appearance depending on system. static bool updateProgressBar(uint value, uint total); + + /// Copy a string to system clipboard. + static bool copyTextToClipboard(const ucstring &text); + + /// Paste a string from system clipboard. + static bool pasteTextFromClipboard(ucstring &text); + + /// Check if system supports unicode. + static bool supportUnicode(); + + /// Check if keyboard layout is AZERTY. + static bool isAzertyKeyboard(); + + /// Check if screensaver is enabled. + static bool isScreensaverEnabled(); + + /// Enable or disable screeensaver. + static bool enableScreensaver(bool screensaver); + + /// Get the ROOT registry key used by getRegKey and setRegKey. + static std::string getRootKey(); + + /// Set the ROOT registry key used by getRegKey and setRegKey. + static void setRootKey(const std::string &root); + + /// Read a value from registry. + static std::string getRegKey(const std::string &Entry); + + /// Write a value to registry. + static bool setRegKey(const std::string &ValueName, const std::string &Value); + + /// Get desktop current color depth without using UDriver. + static uint getCurrentColorDepth(); }; } // NLMISC diff --git a/code/nel/src/misc/displayer.cpp b/code/nel/src/misc/displayer.cpp index bc45dc4ae..93cb5be2c 100644 --- a/code/nel/src/misc/displayer.cpp +++ b/code/nel/src/misc/displayer.cpp @@ -38,6 +38,7 @@ #include "nel/misc/path.h" #include "nel/misc/mutex.h" #include "nel/misc/report.h" +#include "nel/misc/system_utils.h" #include "nel/misc/debug.h" @@ -568,19 +569,7 @@ void CMsgBoxDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *m str += message; - if (OpenClipboard (NULL)) - { - HGLOBAL mem = GlobalAlloc (GHND|GMEM_DDESHARE, str.size()+1); - if (mem) - { - char *pmem = (char *)GlobalLock (mem); - strcpy (pmem, str.c_str()); - GlobalUnlock (mem); - EmptyClipboard (); - SetClipboardData (CF_TEXT, mem); - } - CloseClipboard (); - } + CSystemUtils::copyTextToClipboard(str); // create the string on the screen needSpace = false; @@ -758,19 +747,7 @@ void CMsgBoxDisplayer::display (const std::string& str) { #ifdef NL_OS_WINDOWS - if (OpenClipboard (NULL)) - { - HGLOBAL mem = GlobalAlloc (GHND|GMEM_DDESHARE, str.size()+1); - if (mem) - { - char *pmem = (char *)GlobalLock (mem); - strcpy (pmem, str.c_str()); - GlobalUnlock (mem); - EmptyClipboard (); - SetClipboardData (CF_TEXT, mem); - } - CloseClipboard (); - } + CSystemUtils::copyTextToClipboard(str); string strf = str; strf += "\n\n(this message was copied in the clipboard)"; diff --git a/code/nel/src/misc/system_utils.cpp b/code/nel/src/misc/system_utils.cpp index 8a4e5161a..f06f345f8 100644 --- a/code/nel/src/misc/system_utils.cpp +++ b/code/nel/src/misc/system_utils.cpp @@ -30,6 +30,10 @@ using namespace std; +// Key in registry +static string RootKey; +static const uint32 KeyMaxLength = 1024; + namespace NLMISC { void *CSystemUtils::s_window = NULL; @@ -95,4 +99,254 @@ bool CSystemUtils::updateProgressBar(uint value, uint total) return true; } +bool CSystemUtils::copyTextToClipboard(const ucstring &text) +{ + if (!text.size()) return false; + + bool res = false; + +#ifdef NL_OS_WINDOWS + if (OpenClipboard(NULL)) + { + // check if unicode format is supported by clipboard + bool isUnicode = (IsClipboardFormatAvailable(CF_UNICODETEXT) == TRUE); + + // allocates a buffer to copy text in global memory + HGLOBAL mem = GlobalAlloc(GHND|GMEM_DDESHARE, (text.size()+1) * (isUnicode ? 2:1)); + + if (mem) + { + // create a lock on this buffer + void *hLock = GlobalLock(mem); + + // copy text to this buffer + if (isUnicode) + wcscpy((wchar_t*)hLock, (const wchar_t*)text.c_str()); + else + strcpy((char*)hLock, text.toString().c_str()); + + // unlock buffer + GlobalUnlock(mem); + + // empty clipboard + EmptyClipboard(); + + // set new data to clipboard in the right format + SetClipboardData(isUnicode ? CF_UNICODETEXT:CF_TEXT, mem); + + res = true; + } + + CloseClipboard(); + } +#endif + + return res; +} + +bool CSystemUtils::pasteTextFromClipboard(ucstring &text) +{ + bool res = false; + +#ifdef NL_OS_WINDOWS + if (OpenClipboard(NULL)) + { + // check if unicode format is supported by clipboard + bool isUnicode = (IsClipboardFormatAvailable(CF_UNICODETEXT) == TRUE); + + // get data from clipboard (if not of this type, they are converted) + // warning, this code can't be debuggued in VC++ IDE, hObj will be always NULL + HANDLE hObj = GetClipboardData(isUnicode ? CF_UNICODETEXT:CF_TEXT); + + if (hObj) + { + // create a lock on clipboard data + void *hLock = GlobalLock(hObj); + + if (hLock != NULL) + { + // retrieve clipboard data + if (isUnicode) + text = (const ucchar*)hLock; + else + text = (const char*)hLock; + + // unlock data + GlobalUnlock(hObj); + + res = true; + } + } + + CloseClipboard(); + } +#endif + + return res; +} + +bool CSystemUtils::supportUnicode() +{ + static bool init = false; + static bool unicodeSupported = false; + if (!init) + { + init = true; +#ifdef NL_OS_WINDOWS + OSVERSIONINFO osvi; + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + + // get Windows version + if (GetVersionEx(&osvi)) + { + if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) + { + // unicode is supported since Windows NT 4.0 + if (osvi.dwMajorVersion >= 4) + { + unicodeSupported = true; + } + } + } +#else + unicodeSupported = true; +#endif + } + return unicodeSupported; +} + +bool CSystemUtils::isAzertyKeyboard() +{ +#ifdef NL_OS_WINDOWS + uint16 klId = uint16((uint32)GetKeyboardLayout(0) & 0xFFFF); + // 0x040c is French, 0x080c is Belgian + if (klId == 0x040c || klId == 0x080c) + return true; +#endif + return false; +} + +bool CSystemUtils::isScreensaverEnabled() +{ + bool res = false; +#ifdef NL_OS_WINDOWS +// old code, is not working anymore +// BOOL bRetValue; +// SystemParametersInfoA(SPI_GETSCREENSAVEACTIVE, 0, &bRetValue, 0); +// res = (bRetValue == TRUE); + HKEY hKeyScreenSaver = NULL; + LSTATUS lReturn = RegOpenKeyExA(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop"), 0, KEY_QUERY_VALUE, &hKeyScreenSaver); + if (lReturn == ERROR_SUCCESS) + { + DWORD dwType = 0L; + DWORD dwSize = KeyMaxLength; + unsigned char Buffer[KeyMaxLength] = {0}; + + lReturn = RegQueryValueExA(hKeyScreenSaver, TEXT("SCRNSAVE.EXE"), NULL, &dwType, NULL, &dwSize); + // if SCRNSAVE.EXE is present, check also if it's empty + if (lReturn == ERROR_SUCCESS) + res = (Buffer[0] != '\0'); + } + RegCloseKey(hKeyScreenSaver); +#endif + return res; +} + +bool CSystemUtils::enableScreensaver(bool screensaver) +{ + bool res = false; +#ifdef NL_OS_WINDOWS + res = (SystemParametersInfoA(SPI_SETSCREENSAVEACTIVE, screensaver ? TRUE:FALSE, NULL, 0) == TRUE); +#endif + return res; +} + +std::string CSystemUtils::getRootKey() +{ + return RootKey; +} + +void CSystemUtils::setRootKey(const std::string &root) +{ + RootKey = root; +} + +string CSystemUtils::getRegKey(const string &Entry) +{ + string ret; +#ifdef NL_OS_WINDOWS + HKEY hkey; + + if(RegOpenKeyEx(HKEY_CURRENT_USER, RootKey.c_str(), 0, KEY_READ, &hkey) == ERROR_SUCCESS) + { + DWORD dwType = 0L; + DWORD dwSize = KeyMaxLength; + unsigned char Buffer[KeyMaxLength]; + + if(RegQueryValueEx(hkey, Entry.c_str(), NULL, &dwType, Buffer, &dwSize) != ERROR_SUCCESS) + { + nlwarning("Can't get the reg key '%s'", Entry.c_str()); + } + else + { + ret = (char*)Buffer; + } + RegCloseKey(hkey); + } + else + { + nlwarning("Can't get the reg key '%s'", Entry.c_str()); + } +#endif + return ret; +} + +bool CSystemUtils::setRegKey(const string &ValueName, const string &Value) +{ + bool res = false; +#ifdef NL_OS_WINDOWS + HKEY hkey; + DWORD dwDisp; + + if (RegCreateKeyExA(HKEY_CURRENT_USER, RootKey.c_str(), 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwDisp) == ERROR_SUCCESS) + { + if (RegSetValueExA(hkey, ValueName.c_str(), 0L, REG_SZ, (const BYTE *)Value.c_str(), (DWORD)(Value.size())+1) == ERROR_SUCCESS) + res = true; + RegCloseKey(hkey); + } + else + { + nlwarning("Can't set the reg key '%s' '%s'", ValueName.c_str(), Value.c_str()); + } +#endif + + return res; +} + +uint CSystemUtils::getCurrentColorDepth() +{ + uint depth = 0; + +#ifdef NL_OS_WINDOWS + HWND desktopWnd = GetDesktopWindow(); + if (desktopWnd) + { + HDC desktopDC = GetWindowDC(desktopWnd); + if (desktopDC) + { + depth = (uint) GetDeviceCaps(desktopDC, BITSPIXEL); + ReleaseDC(desktopWnd, desktopDC); + } + } +#else + Display *display = XOpenDisplay(NULL); + if (display) + { + depth = (uint) DefaultDepth(display, DefaultScreen(display)); + XCloseDisplay(display); + } +#endif + return depth; +} + } // NLMISC diff --git a/code/ryzom/client/src/connection.cpp b/code/ryzom/client/src/connection.cpp index 30e8842f3..141b2cff2 100644 --- a/code/ryzom/client/src/connection.cpp +++ b/code/ryzom/client/src/connection.cpp @@ -27,6 +27,7 @@ #include "nel/misc/path.h" #include "nel/misc/time_nl.h" #include "nel/misc/algo.h" +#include "nel/misc/system_utils.h" // 3D Interface. #include "nel/3d/u_driver.h" #include "nel/3d/u_text_context.h" @@ -2394,14 +2395,7 @@ public: } // default to 'ZQSD' for French and Belgian keyboard, 'WASD' else - bool wasd = true; -#ifdef NL_OS_WINDOWS - uint16 klId = uint16((uint32)GetKeyboardLayout(0) & 0xFFFF); - if (klId == 0x040c || klId == 0x080c) - { - wasd = false; - } -#endif + bool wasd = !CSystemUtils::isAzertyKeyboard(); /*sint startIndex = wasd ? wasdIndex : zqsdIndex; if (startIndex == -1) startIndex = 0; diff --git a/code/ryzom/client/src/init.cpp b/code/ryzom/client/src/init.cpp index a41dfca1f..800cdf9a1 100644 --- a/code/ryzom/client/src/init.cpp +++ b/code/ryzom/client/src/init.cpp @@ -656,16 +656,11 @@ void prelogInit() set_new_handler(outOfMemory); -#ifdef NL_OS_WINDOWS - { - BOOL bRetValue; - SystemParametersInfo (SPI_GETSCREENSAVEACTIVE, 0, &bRetValue, 0); - LastScreenSaverEnabled = (bRetValue == TRUE); - SystemParametersInfo (SPI_SETSCREENSAVEACTIVE, FALSE, NULL, 0); - } -#else // NL_OS_WINDOWS - // Not tested, not compiled -#endif // NL_OS_WINDOWS + // save screen saver state and disable it + LastScreenSaverEnabled = CSystemUtils::isScreensaverEnabled(); + + if (LastScreenSaverEnabled) + CSystemUtils::enableScreensaver(false); // Random init srand ((uint)CTime::getLocalTime()); diff --git a/code/ryzom/client/src/interface_v3/group_editbox.cpp b/code/ryzom/client/src/interface_v3/group_editbox.cpp index 58be769c9..fce01798f 100644 --- a/code/ryzom/client/src/interface_v3/group_editbox.cpp +++ b/code/ryzom/client/src/interface_v3/group_editbox.cpp @@ -22,6 +22,7 @@ #include "interface_manager.h" #include "input_handler_manager.h" #include "nel/misc/command.h" +#include "nel/misc/system_utils.h" #include "view_text.h" #include "game_share/xml_auto_ptr.h" #include "interface_options.h" @@ -335,30 +336,10 @@ void CGroupEditBox::copy() nlwarning("Selection can only be on focus"); } stopParentBlink(); - // get the selection - ucstring selection= getSelection(); - // copy - #ifdef NL_OS_WINDOWS - if (selection.size() > 0 && OpenClipboard (NULL)) - { - bool isUnicode = IsClipboardFormatAvailable(CF_UNICODETEXT) == TRUE; - HGLOBAL mem = GlobalAlloc (GHND|GMEM_DDESHARE, (selection.size()+1) * (isUnicode ? 2:1)); - if (mem) - { - void *hLock = GlobalLock (mem); - if (isUnicode) - wcscpy ((wchar_t*)hLock, (const wchar_t*)selection.c_str()); - else - strcpy ((char*)hLock, selection.toString().c_str()); - GlobalUnlock (mem); - EmptyClipboard (); - SetClipboardData (isUnicode ? CF_UNICODETEXT:CF_TEXT, mem); - } - CloseClipboard (); - nlinfo ("Chat input was copied in the clipboard"); - } - #endif // NL_OS_WINDOWS + // get the selection and copy it + if (CSystemUtils::copyTextToClipboard(getSelection())) + nlinfo ("Chat input was copied in the clipboard"); } // ---------------------------------------------------------------------------- @@ -374,172 +355,154 @@ void CGroupEditBox::paste() } stopParentBlink(); makeTopWindow(); - #ifdef NL_OS_WINDOWS - if (OpenClipboard (NULL)) + + ucstring sString; + + if (CSystemUtils::pasteTextFromClipboard(sString)) + { + sint length = (sint)sString.length(); + + ucstring toAppend; + // filter character depending on the netry type + switch (_EntryType) { - bool isUnicode = IsClipboardFormatAvailable(CF_UNICODETEXT) == TRUE; - - HANDLE hObj = GetClipboardData(isUnicode ? CF_UNICODETEXT:CF_TEXT); - - if (hObj) + case Text: + case Password: { - void *hLock = GlobalLock(hObj); - - if (hLock != NULL) + if (_NegativeFilter.empty()) { - ucstring sString; - - if (isUnicode) - sString = (const ucchar*)hLock; - else - sString = (const char*)hLock; - - sint length = (sint)sString.length(); - - ucstring toAppend; - // filter character depending on the netry type - switch (_EntryType) + toAppend = sString; + } + else + { + for (sint k = 0; k < length; ++k) { - case Text: - case Password: + if (!isFiltered(sString[k])) { - if (_NegativeFilter.empty()) - { - toAppend = sString; - } - else - { - for (sint k = 0; k < length; ++k) - { - if (!isFiltered(sString[k])) - { - toAppend += sString[k]; - } - } - } - // remove '\r' characters - toAppend.erase(std::remove(toAppend.begin(), toAppend.end(), (ucchar) '\r'), toAppend.end()); - - } - break; - case PositiveInteger: - case PositiveFloat: - { - for (sint k = 0; k < length; ++k) - { - if (isdigit(sString[k]) || sString[k]== ' ' || - (_EntryType==PositiveFloat && sString[k]=='.') ) - { - if (!isFiltered(sString[k])) - { - toAppend += sString[k]; - } - } - } - } - break; - case Integer: - case Float: - { - for (sint k = 0; k < length; ++k) - { - if (isdigit(sString[k]) || sString[k]== ' ' || sString[k]== '-' || - (_EntryType==Float && sString[k]=='.') ) - { - if (!isFiltered(sString[k])) - { - toAppend += sString[k]; - } - } - } - } - break; - case AlphaNumSpace: - { - for (sint k = 0; k < length; ++k) - { - if (isValidAlphaNumSpace(sString[k])) - { - if (!isFiltered(sString[k])) - { - toAppend += sString[k]; - } - } - } - } - break; - case AlphaNum: - { - for (sint k = 0; k < length; ++k) - { - if (isValidAlphaNum(sString[k])) - { - if (!isFiltered(sString[k])) - { - toAppend += sString[k]; - } - } - } - } - break; - case Alpha: - { - for (sint k = 0; k < length; ++k) - { - if (isValidAlpha(sString[k])) - { - if (!isFiltered(sString[k])) - { - toAppend += sString[k]; - } - } - } - } - break; - case Filename: - { - for (sint k = 0; k < length; ++k) - { - if (isValidFilenameChar(sString[k])) - { - if (!isFiltered(sString[k])) - { - toAppend += sString[k]; - } - } - } - } - break; - case PlayerName: - { - for (sint k = 0; k < length; ++k) - { - if (isValidPlayerNameChar(sString[k])) - { - if (!isFiltered(sString[k])) - { - toAppend += sString[k]; - } - } - } + toAppend += sString[k]; } } - length = (sint)toAppend.size(); - if ((uint) (_InputString.length() + length) > _MaxNumChar) + } + // remove '\r' characters + toAppend.erase(std::remove(toAppend.begin(), toAppend.end(), (ucchar) '\r'), toAppend.end()); + + } + break; + case PositiveInteger: + case PositiveFloat: + { + for (sint k = 0; k < length; ++k) + { + if (isdigit(sString[k]) || sString[k]== ' ' || + (_EntryType==PositiveFloat && sString[k]=='.') ) { - length = _MaxNumChar - (sint)_InputString.length(); + if (!isFiltered(sString[k])) + { + toAppend += sString[k]; + } + } + } + } + break; + case Integer: + case Float: + { + for (sint k = 0; k < length; ++k) + { + if (isdigit(sString[k]) || sString[k]== ' ' || sString[k]== '-' || + (_EntryType==Float && sString[k]=='.') ) + { + if (!isFiltered(sString[k])) + { + toAppend += sString[k]; + } + } + } + } + break; + case AlphaNumSpace: + { + for (sint k = 0; k < length; ++k) + { + if (isValidAlphaNumSpace(sString[k])) + { + if (!isFiltered(sString[k])) + { + toAppend += sString[k]; + } + } + } + } + break; + case AlphaNum: + { + for (sint k = 0; k < length; ++k) + { + if (isValidAlphaNum(sString[k])) + { + if (!isFiltered(sString[k])) + { + toAppend += sString[k]; + } + } + } + } + break; + case Alpha: + { + for (sint k = 0; k < length; ++k) + { + if (isValidAlpha(sString[k])) + { + if (!isFiltered(sString[k])) + { + toAppend += sString[k]; + } + } + } + } + break; + case Filename: + { + for (sint k = 0; k < length; ++k) + { + if (isValidFilenameChar(sString[k])) + { + if (!isFiltered(sString[k])) + { + toAppend += sString[k]; + } + } + } + } + break; + case PlayerName: + { + for (sint k = 0; k < length; ++k) + { + if (isValidPlayerNameChar(sString[k])) + { + if (!isFiltered(sString[k])) + { + toAppend += sString[k]; + } } - ucstring toAdd = toAppend.substr(0, length); - _InputString = _InputString.substr(0, _CursorPos) + toAdd + _InputString.substr(_CursorPos); - _CursorPos += (sint32)toAdd.length(); - GlobalUnlock (hObj); - nlinfo ("Chat input was pasted from the clipboard"); } } - CloseClipboard (); - triggerOnChangeAH(); } - #endif // NL_OS_WINDOWS + length = (sint)toAppend.size(); + if ((uint) (_InputString.length() + length) > _MaxNumChar) + { + length = _MaxNumChar - (sint)_InputString.length(); + } + ucstring toAdd = toAppend.substr(0, length); + _InputString = _InputString.substr(0, _CursorPos) + toAdd + _InputString.substr(_CursorPos); + _CursorPos += (sint32)toAdd.length(); + nlinfo ("Chat input was pasted from the clipboard"); + + triggerOnChangeAH(); + } + _CursorAtPreviousLineEnd = false; } diff --git a/code/ryzom/client/src/login.cpp b/code/ryzom/client/src/login.cpp index 0b233bab0..b07fbd061 100644 --- a/code/ryzom/client/src/login.cpp +++ b/code/ryzom/client/src/login.cpp @@ -26,9 +26,11 @@ #include "nel/misc/debug.h" #include "nel/misc/path.h" #include "nel/misc/thread.h" +#include "nel/misc/big_file.h" +#include "nel/misc/system_utils.h" + #include "nel/net/tcp_sock.h" #include "nel/3d/u_driver.h" -#include "nel/misc/big_file.h" #include "interface_v3/interface_manager.h" #include "interface_v3/input_handler_manager.h" @@ -95,10 +97,6 @@ string R2BackupPatchURL; vector R2PatchURLs; -// Key in registry -static const string RootKey = "SOFTWARE\\Nevrax\\Ryzom"; -static const uint32 KeyMaxLength = 1024; - #define CTRL_EDITBOX_LOGIN "ui:login:checkpass:content:eb_login:eb" #define CTRL_EDITBOX_PASSWORD "ui:login:checkpass:content:eb_password:eb" #define GROUP_LIST_SHARD "ui:login:sharddisp:content:shard_list" @@ -736,7 +734,9 @@ void initLoginScreen() ClientApp = ClientCfg.ConfigFile.getVar("Application").asString(0); - string l = getRegKeyValue("Login").c_str(); + CSystemUtils::setRootKey("SOFTWARE\\Nevrax\\Ryzom"); + + string l = CSystemUtils::getRegKey("Login"); if(!l.empty()) { @@ -927,60 +927,6 @@ bool login() // INTERFACE HELPERS // *************************************************************************** -// *************************************************************************** -string getRegKeyValue(const string &Entry) -{ - string ret; -#ifdef NL_OS_WINDOWS - HKEY hkey; - - if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, RootKey.c_str(), 0, KEY_READ, &hkey) == ERROR_SUCCESS) - { - DWORD dwType = 0L; - DWORD dwSize = KeyMaxLength; - unsigned char Buffer[KeyMaxLength]; - - if(RegQueryValueEx(hkey, Entry.c_str(), NULL, &dwType, Buffer, &dwSize) != ERROR_SUCCESS) - { - nlwarning("Can't get the reg key '%s'", Entry.c_str()); - } - else - { - ret = (char*)Buffer; - } - RegCloseKey(hkey); - } - else - { - nlwarning("Can't get the reg key '%s'", Entry.c_str()); - } -#else - // TODO for Linux and Mac OS -#endif - return ret; -} - -// *************************************************************************** -void setRegKey(const string &ValueName, const string &Value) -{ -#ifdef NL_OS_WINDOWS - HKEY hkey; - DWORD dwDisp; - - if(RegCreateKeyEx(HKEY_LOCAL_MACHINE, RootKey.c_str(), 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwDisp) == ERROR_SUCCESS) - { - RegSetValueEx(hkey, ValueName.c_str(), 0L, REG_SZ, (const BYTE *)Value.c_str(), (DWORD)(Value.size())+1); - RegCloseKey(hkey); - } - else - { - nlwarning("Can't set the reg key '%s' '%s'", ValueName.c_str(), Value.c_str()); - } -#else - // TODO for Linux and Mac OS -#endif -} - // *************************************************************************** void removeSpace(string &s) { @@ -1162,7 +1108,7 @@ void onlogin(bool vanishScreen = true) removeSpace(LoginPassword); if(!LoginLogin.empty()) - setRegKey("Login", LoginLogin); + CSystemUtils::setRegKey("Login", LoginLogin); if(vanishScreen) pIM->getDbProp("UI:VARIABLES:SCREEN")->setValue32(-1); @@ -1836,24 +1782,18 @@ class CAHOpenURL : public IActionHandler #ifdef NL_OS_WINDOWS - const LONG BUFFER_LEN = 1024; - LONG bufferLenght = BUFFER_LEN; - char buffer[BUFFER_LEN]; // Check for special install tag - const char *KeyName = "Software\\Nevrax\\Ryzom\\InstallTag"; + const char *KeyName = "InstallTag"; - LONG ret = RegQueryValueA(HKEY_LOCAL_MACHINE, KeyName, buffer, &bufferLenght); - if (ret == ERROR_SUCCESS) + installTag = CSystemUtils::getRegKey(KeyName); + + if (installTag.length() > 1) { - if (bufferLenght > 1) - { - installTag = buffer; - - nldebug("Found install tag '%s'", url.c_str()); - } + nldebug("Found install tag '%s'", url.c_str()); } else { + DWORD ret = 0; LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | diff --git a/code/ryzom/client/src/login.h b/code/ryzom/client/src/login.h index 583e66206..6c5824480 100644 --- a/code/ryzom/client/src/login.h +++ b/code/ryzom/client/src/login.h @@ -61,11 +61,6 @@ std::string getBGDownloaderCommandLine(); bool login(); void loginIntro(); -// helpers -std::string getRegKeyValue(const std::string &Entry); -void setRegKey(const std::string &ValueName, const std::string &Value); - - // force patch for the mainland part void mainLandPatch(); diff --git a/code/ryzom/client/src/misc.cpp b/code/ryzom/client/src/misc.cpp index 02b570dd9..34a1e1205 100644 --- a/code/ryzom/client/src/misc.cpp +++ b/code/ryzom/client/src/misc.cpp @@ -47,6 +47,7 @@ #include "nel/misc/fast_floor.h" #include "nel/misc/noise_value.h" #include "nel/misc/bitmap.h" +#include "nel/misc/system_utils.h" // Game Share #include "game_share/player_visual_properties.h" #include "game_share/seeds.h" @@ -1464,26 +1465,7 @@ uint getCurrentColorDepth() return videoMode.Depth; } } - uint depth = 0; - #ifdef NL_OS_WINDOWS - HWND desktopWnd = GetDesktopWindow(); - if (desktopWnd) - { - HDC desktopDC = GetWindowDC(desktopWnd); - if (desktopDC) - { - depth = (uint) GetDeviceCaps(desktopDC, BITSPIXEL); - ReleaseDC(desktopWnd, desktopDC); - } - } - #else - Display *display = XOpenDisplay(NULL); - if (display) - { - depth = (uint) DefaultDepth(display, DefaultScreen(display)); - XCloseDisplay(display); - } - #endif - return depth; + + return CSystemUtils::getCurrentColorDepth(); } diff --git a/code/ryzom/client/src/r2/editor.cpp b/code/ryzom/client/src/r2/editor.cpp index fd53a078d..db355193c 100644 --- a/code/ryzom/client/src/r2/editor.cpp +++ b/code/ryzom/client/src/r2/editor.cpp @@ -3028,13 +3028,9 @@ void CEditor::updateSelectingDecals() void CEditor::reset() { //H_AUTO(R2_CEditor_reset) - #ifdef NL_OS_WINDOWS - if (ClientCfg.R2EDExtendedDebug) - { - HWND hWnd = (HWND)Driver->getDisplay (); - SetWindowText(hWnd, "Resetting R2ED editor ..."); - } - #endif // NL_OS_WINDOW + if (ClientCfg.R2EDExtendedDebug) + Driver->setWindowTitle(ucstring("Resetting R2ED editor ...")); + CHECK_EDITOR _SerializeUIConfig = false; // prevent reloading of ui for speed _WantedActOnInit.clear(); @@ -3077,18 +3073,17 @@ void CEditor::reset() // try to return to the act with the same title _SerializeUIConfig = true; - #ifdef NL_OS_WINDOWS - if (ClientCfg.R2EDExtendedDebug) - { - HWND hWnd = (HWND)Driver->getDisplay (); - nlassert (hWnd); - SetWindowTextW (hWnd, (WCHAR*)CI18N::get("TheSagaOfRyzom").c_str ()); - // Get the window - // Show the window - ShowWindow (hWnd, SW_SHOW); - SetForegroundWindow(hWnd); - } - #endif + if (ClientCfg.R2EDExtendedDebug) + { + Driver->setWindowTitle(CI18N::get("TheSagaOfRyzom")); + Driver->showWindow(); + // TODO: check + // Get the window + // Show the window +// ShowWindow (hWnd, SW_SHOW); +// SetForegroundWindow(hWnd); + } + getUI().displaySystemInfo(CI18N::get("uiR2EDEditorReseted"), "BC"); } diff --git a/code/ryzom/client/src/release.cpp b/code/ryzom/client/src/release.cpp index 15ff9b856..1f8f84a3f 100644 --- a/code/ryzom/client/src/release.cpp +++ b/code/ryzom/client/src/release.cpp @@ -24,6 +24,7 @@ // Misc. #include "nel/misc/debug.h" #include "nel/misc/async_file_manager.h" +#include "nel/misc/system_utils.h" // 3D Interface. #include "nel/3d/bloom_effect.h" #include "nel/3d/fasthls_modifier.h" @@ -525,11 +526,8 @@ void release() STRING_MANAGER::CStringManagerClient::instance()->flushStringCache(); STRING_MANAGER::CStringManagerClient::release(true); -#ifdef NL_OS_WINDOWS - { - SystemParametersInfo (SPI_SETSCREENSAVEACTIVE, LastScreenSaverEnabled?TRUE:FALSE, NULL, 0); - } -#endif // NL_OS_WINDOWS + // restore screensaver state + CSystemUtils::enableScreensaver(LastScreenSaverEnabled); // release PACS primitives deletePrimitiveBlocks();