more compilation fixes and add strings.h/.cc for string conversions
This commit is contained in:
@@ -44,6 +44,7 @@ source_set("xp_activate32_sources") {
|
||||
"src/framework.h",
|
||||
"src/globals.h",
|
||||
"src/keygen.h",
|
||||
"src/strings.h",
|
||||
"src/resource.h",
|
||||
"src/utils.h",
|
||||
"src/xp_activate32.h",
|
||||
@@ -51,6 +52,7 @@ source_set("xp_activate32_sources") {
|
||||
|
||||
sources += [
|
||||
"src/keygen.cc",
|
||||
"src/strings.cc",
|
||||
"src/resource.rc",
|
||||
"src/utils.cc",
|
||||
"src/xp_activate32.cc",
|
||||
|
||||
@@ -40,11 +40,9 @@
|
||||
#endif // not __MINGW32__
|
||||
|
||||
#include <windows.h>
|
||||
#include <combaseapi.h>
|
||||
#include <commctrl.h>
|
||||
#include <commdlg.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#include "strings.h"
|
||||
|
||||
std::wstring stringToWstring(const std::string& str) {
|
||||
if (str.empty()) {
|
||||
return std::wstring();
|
||||
}
|
||||
// Windows: convert UTF-8 → UTF-16
|
||||
#ifdef _WIN32
|
||||
// Get length of string
|
||||
int wide_len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0);
|
||||
if (wide_len == 0) {
|
||||
throw std::runtime_error("MultiByteToWideChar failed!");
|
||||
}
|
||||
|
||||
// Convert it!
|
||||
std::wstring result(wide_len, L'\0');
|
||||
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, &result[0], wide_len);
|
||||
|
||||
// Remove the null terminator added by Windows API ugh
|
||||
if (!result.empty() && result.back() == L'\0') {
|
||||
result.pop_back();
|
||||
}
|
||||
// POSIX systems: convert UTF-8 → UTF-32 wchar_t
|
||||
#else
|
||||
// Set locale for multibyte conversion (thread-local)
|
||||
std::mbstate_t state{};
|
||||
const char* src = str.c_str();
|
||||
// find required size
|
||||
size_t len = std::mbsrtowcs(nullptr, &src, 0, &state);
|
||||
if (len == static_cast<size_t>(-1)) {
|
||||
throw std::runtime_error("mbsrtowcs failed");
|
||||
}
|
||||
|
||||
std::wstring result(len, L'\0');
|
||||
state = std::mbstate_t{};
|
||||
src = str.c_str();
|
||||
std::mbsrtowcs(result.data(), &src, len, &state);
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string WstringToString(const std::wstring& wstr) {
|
||||
if (wstr.empty()) {
|
||||
return std::string();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef XP_ACTIVATE32_STRINGS_H_
|
||||
#define XP_ACTIVATE32_STRINGS_H_
|
||||
|
||||
#include "framework.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
std::wstring stringToWstring(const std::string& str);
|
||||
|
||||
std::string WstringToString(const std::wstring& wstr);
|
||||
|
||||
#endif // XP_ACTIVATE32_STRINGS_H_
|
||||
+2
-2
@@ -122,9 +122,9 @@ float getWinNTVersion() {
|
||||
}
|
||||
|
||||
std::wstring GetWinVersion() {
|
||||
std::string ver = GetOSName();
|
||||
std::wstring wver = L"1.0";
|
||||
const std::string ver = GetOSName();
|
||||
WinVer = ver;
|
||||
std::wstring wver = stringToWstring(WinVer);
|
||||
return wver;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include "constants.h"
|
||||
#include "framework.h"
|
||||
#include "strings.h"
|
||||
|
||||
extern wchar_t strings[16][256];
|
||||
|
||||
|
||||
@@ -152,6 +152,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src/keygen.cc" />
|
||||
<ClCompile Include="src/strings.cc" />
|
||||
<ClCompile Include="src/utils.cc" />
|
||||
<ClCompile Include="src/xp_activate32.cc" />
|
||||
</ItemGroup>
|
||||
@@ -160,6 +161,7 @@
|
||||
<ClInclude Include="src/framework.h" />
|
||||
<ClInclude Include="src/globals.h" />
|
||||
<ClInclude Include="src/keygen.h" />
|
||||
<ClInclude Include="src/strings.h" />
|
||||
<ClInclude Include="src/resource.h" />
|
||||
<ClInclude Include="src/xp_activate32.h" />
|
||||
<ClInclude Include="src/utils.h" />
|
||||
|
||||
@@ -26,6 +26,9 @@
|
||||
<ClCompile Include="src/keygen.cc">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src/strings.cc">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src/utils.cc">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@@ -52,6 +55,9 @@
|
||||
<ClInclude Include="src/xp_activate32.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src/strings.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src/utils.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
||||
Reference in New Issue
Block a user