AccountInterfacePtr AccountManager::loadAccount_( const WString& _accountID ) { AccountInterfacePtr account = this->newAccount_( _accountID ); if( account == nullptr ) { LOGGER_ERROR(m_serviceProvider)("AccountManager::loadAccount_ invalid create account %ls" , _accountID.c_str() ); return nullptr; } if( m_accountProvider != nullptr ) { m_currentAccount = account; m_accountProvider->onCreateAccount( _accountID ); m_currentAccount = nullptr; } if( account->load() == false ) { LOGGER_ERROR(m_serviceProvider)("AccountManager::loadAccount_ invalid load account %ls" , _accountID.c_str() ); return nullptr; } return account; }
// Functions from x64dbg project: https://github.com/x64dbg/x64dbg //Conversion functions taken from: http://www.nubaria.com/en/blog/?p=289 String Utf16ToUtf8(const WString & wstr) { String convertedString; int requiredSize = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, 0, 0, 0, 0); if(requiredSize > 0) { std::vector<char> buffer(requiredSize); WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, &buffer[0], requiredSize, 0, 0); convertedString.assign(buffer.begin(), buffer.end() - 1); } return convertedString; }
void Load() { String name = mName; if (name.substr(name.length() - 4, 4) != ".dll") name += ".dll"; WString wname = StringToWString(name); m_hInst = (HINSTANCE)LoadLibraryEx(wname.c_str(), 0, LOAD_WITH_ALTERED_SEARCH_PATH ); if (!m_hInst) { LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); fprintf(stderr, "%s\n", (char*)lpMsgBuf); // Free the buffer. LocalFree( lpMsgBuf ); String error = "Load " + name + " failed!"; ENGINE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, error, "DynLib::Load"); } }
//--------------------------------------------------------------------- Ogre::DataStreamPtr UnicodeFileSystemArchive::create(const String& _filename) const { if (isReadOnly()) { GOTHOGRE_EXCEPT(_filename << " - Cannot create a file in" << " read-only archive " << getName() << "."); } WString wfullpath = getFullPath(_filename); // Always open in binary mode // Also, always include reading std::ios::openmode mode = std::ios::out | std::ios::binary; std::fstream* rwStream = OGRE_NEW_T(std::fstream, MEMCATEGORY_GENERAL)(); rwStream->open(wfullpath.c_str(), mode); // Should check ensure open succeeded, in case fail for some reason. if (rwStream->fail()) { OGRE_DELETE_T(rwStream, basic_fstream, MEMCATEGORY_GENERAL); GOTHOGRE_EXCEPT(_filename << " - Cannot create file in" << " archive " << getName() << "."); } GOTHOGRE_INFO(_filename << " - " << "Saving to" << " archive " << getName() << "."); /// Construct return stream, tell it to delete on destroy FileStreamDataStream* stream = OGRE_NEW FileStreamDataStream(_filename, rwStream, 0, true); return DataStreamPtr(stream); }
std::string WideToUTF8(const WString &inWideString) { int len = 0; const wchar_t *chars = inWideString.c_str(); for(int i=0;i<inWideString.length();i++) { int c = chars[i]; if( c <= 0x7F ) len++; else if( c <= 0x7FF ) len+=2; else if( c <= 0xFFFF ) len+=3; else len+= 4; } std::string result; result.resize(len); unsigned char *data = (unsigned char *) &result[0]; for(int i=0;i<inWideString.length();i++) { int c = chars[i]; if( c <= 0x7F ) *data++ = c; else if( c <= 0x7FF ) { *data++ = 0xC0 | (c >> 6); *data++ = 0x80 | (c & 63); } else if( c <= 0xFFFF )
winLog::winLog(bool resetLog, const char* path, const char* name) { setLogPath(path); setLogName(name); // MUST use a wchar_t* logDir to manage correctly international chars. // If using char* logDir and UTF-8, fopen() is not working correctly and // will fail to open the log file. (with UTF-8... why?) // So we use _wfopen() and a wchar_t* logDir. StringBuffer logDir; logDir.sprintf("%s\\%s", logPath.c_str(), logName.c_str()); WCHAR* tmp = toWideChar(logDir.c_str()); wlogDir = tmp; delete [] tmp; // // Test to ensure the log file is writable (only if path is set) // if (path) { logFile = _wfopen(wlogDir.c_str(), TEXT("a+")); if (logFile == NULL) { WCHAR tmp[512]; wsprintf(tmp, TEXT("Unable to write log file: \"%s\".\nPlease check your user's permissions."), wlogDir.c_str()); MessageBox(NULL, tmp, TEXT("Funambol"), MB_SETFOREGROUND | MB_OK); } else { fclose(logFile); if (resetLog) { reset(FUNAMBOL_HEADER); } } } }
AString Converter::Unicode2Utf8(const WString& widestring){ int utf8size = ::WideCharToMultiByte(CP_UTF8, 0, widestring.c_str(), -1, NULL, 0, NULL, NULL); if (utf8size == 0) { throw std::exception("Error in conversion."); } std::vector<char> resultstring(utf8size); int convresult = ::WideCharToMultiByte(CP_UTF8, 0, widestring.c_str(), -1, &resultstring[0], utf8size, NULL, NULL); if (convresult != utf8size) { throw std::exception("La falla!"); } return AString(&resultstring[0]); }