static Optional<Size> deserialize_size(const utf8_string& str){ wxString wxStr(to_wx(str)); wxArrayString strs = wxSplit(to_wx(str), ',', '\0'); if (strs.GetCount() != 2){ return {}; } long width; if (!strs[0].ToLong(&width)){ return {}; } if (width <= 0){ return {}; } long height; if (!strs[1].ToLong(&height)){ return {}; } if (height <= 0){ return {}; } return {Size(static_cast<coord>(width), static_cast<coord>(height))}; }
wxString Utils::BytesToString(unsigned char *bytes) { char asciihash[33]; int p = 0; for(int i=0; i<16; i++) { ::sprintf(&asciihash[p],"%02x",bytes[i]); p += 2; } asciihash[32] = '\0'; return wxStr(std::string(asciihash)); }
wxString FindJavaPath(const wxString& def) { // Open the JRE registry key. HKEY jreKey; std::string jreKeyName = "SOFTWARE\\JavaSoft\\Java Runtime Environment"; if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, jreKeyName.c_str(), 0, KEY_READ | KEY_WOW64_64KEY, &jreKey) == ERROR_SUCCESS) { // Read the current JRE version from the registry. // This will be used to find the key that contains the JavaHome value. char *value = new char[0]; DWORD valueSz = 0; if (RegQueryValueExA(jreKey, "CurrentVersion", NULL, NULL, (BYTE*)value, &valueSz) == ERROR_MORE_DATA) { value = new char[valueSz]; RegQueryValueExA(jreKey, "CurrentVersion", NULL, NULL, (BYTE*)value, &valueSz); } RegCloseKey(jreKey); // Now open the registry key for the JRE version that we just got. jreKeyName.append("\\").append(value); if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, jreKeyName.c_str(), 0, KEY_READ | KEY_WOW64_64KEY, &jreKey) == ERROR_SUCCESS) { // Read the JavaHome value to find where Java is installed. value = new char[0]; valueSz = 0; if (RegQueryValueExA(jreKey, "JavaHome", NULL, NULL, (BYTE*)value, &valueSz) == ERROR_MORE_DATA) { value = new char[valueSz]; RegQueryValueExA(jreKey, "JavaHome", NULL, NULL, (BYTE*)value, &valueSz); } RegCloseKey(jreKey); wxString javaHome = wxStr(value); javaHome = Path::Combine(Path::Combine(javaHome, "bin"), "java.exe"); return javaHome; } } return def; }