FILE *path_fopen(const string& path, const string& mode) { #ifdef _WIN32 wstring path_wc = string_to_wstring(path); wstring mode_wc = string_to_wstring(mode); return _wfopen(path_wc.c_str(), mode_wc.c_str()); #else return fopen(path.c_str(), mode.c_str()); #endif }
bool windows_tray_notification::set_tray_message(const std::string& title, const std::string& message) { // prevents deletion of icon when resetting already existing notification message_reset = (nid->uFlags & NIF_INFO) != 0; nid->uFlags |= NIF_INFO; lstrcpy(nid->szInfoTitle, string_to_wstring(title).data()); lstrcpy(nid->szInfo, string_to_wstring(message).data()); // setting notification return Shell_NotifyIcon(NIM_MODIFY, nid) != FALSE; }
//-------------------------------------------------------------- void ofxFileDialog::setPath(std::string path) { if(!ofDirectory::doesDirectoryExist(path)) { ofLogWarning("ofxFileDialog") << "can't set path, " << path << " doesn't exist"; return; } if(!ofFilePath::isAbsolute(path)) { m_path = string_to_wstring(ofFilePath::getAbsolutePath(path)); } else { m_path = string_to_wstring(path); } refresh(); }
int Database::load() { if (open() != 0) return -1; Json::Reader reader; if (!reader.parse(file_in, root, false)){ ERR("Json reader parse error, maybe empty file\n"); root.clear(); return -1; } try { Json::Value::Members member = root.getMemberNames(); Json::Value::Members::iterator it = member.begin(); for (; it != member.end(); it++){ if (load_obj(string_to_wstring(*it)) == NULL) ERR("Load object error\n"); } } catch (Json::LogicError & e) { cout << e.what() << endl; ERR("Json file data not correct\n"); close_json(); return -1; } return 0; }
static bool create_directories_recursivey(const string& path) { if(path_is_directory(path)) { /* Directory already exists, nothing to do. */ return true; } if(path_exists(path)) { /* File exists and it's not a directory. */ return false; } string parent = path_dirname(path); if(parent.size() > 0 && parent != path) { if(!create_directories_recursivey(parent)) { return false; } } #ifdef _WIN32 wstring path_wc = string_to_wstring(path); return _wmkdir(path_wc.c_str()) == 0; #else return mkdir(path.c_str(), 0777) == 0; #endif }
char* CLS_DlgStreamPusher::GetDeviceName(int _iDeviceType) { char* pDeviceName = NULL; CString cstrDevName = ""; CString cstrOutDevName = ""; if (_iDeviceType == n_Audio){ m_cboDeviceAudio.GetWindowText(cstrDevName); } else if (_iDeviceType == n_Video){ m_cboDeviceVideo.GetWindowText(cstrDevName); } AnsiToUTF8(cstrDevName.GetBuffer(), cstrOutDevName); if (_iDeviceType == n_Audio){ cstrOutDevName = "audio=" + cstrDevName; } else if (_iDeviceType == n_Video){ cstrOutDevName = "video=" + cstrDevName; } wchar_t* wstring = string_to_wstring(cstrOutDevName.GetBuffer()); pDeviceName = dup_wchar_to_utf8(wstring); return pDeviceName; }
//-------------------------------------------------------------- ofxFileDialog::ofxFileDialog() : ofxEditor() { m_currentFile = 0; m_path = string_to_wstring(ofFilePath::getUserHomeDir()); m_mode = SAVEAS; m_active = false; m_saveAsState = FILENAME; refresh(); }
bool PPDownloadRequest::DataNotify( size_t expectedDataSize, const void* data, size_t dataSize ) { bool ret = false; if ( m_instance.m_eventStop.m_hObject != NULL ) { if ( ::WaitForSingleObject( m_instance.m_eventStop.m_hObject, 0 ) == WAIT_OBJECT_0 ) { return ret; // canceled by the user } } switch ( this->m_requestType ) { case ( RequestType::P3DObject ): { if ( m_p3dRequest ) { ret = P3D_instance_feed_url_stream_ptr( m_p3dRequest->_instance, m_p3dRequest->_request._get_url._unique_id, P3D_RC_in_progress, 0, expectedDataSize, data, dataSize ); } } break; case ( RequestType::File ): { if ( m_hFile == INVALID_HANDLE_VALUE ) { wstring filename_w; string_to_wstring(filename_w, m_fileName); m_hFile = ::CreateFileW( filename_w.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); if ( m_hFile == INVALID_HANDLE_VALUE ) { return ret; } } DWORD numberOfBytesWritten = 0; if ( ::WriteFile( m_hFile, data, dataSize, &numberOfBytesWritten, NULL ) == TRUE ) { ret = true; } } break; case ( RequestType::Data ): { if ( m_data ) { std::string bits( static_cast< const char* >( data ), dataSize ); *m_data << bits; ret = true; } } break; } return ret; }
void ofxGLEditor::pasteFromClipBoard() { wstring m_CopyBuffer = string_to_wstring(clipBoard.getTextFromPasteboard()); glEditor[currentEditor]->m_Text.insert(glEditor[currentEditor]->m_Position,m_CopyBuffer); glEditor[currentEditor]->m_Selection=false; glEditor[currentEditor]->m_Position+=m_CopyBuffer.size(); glEditor[currentEditor]->ProcessTabs(); }
void ofxGLEditor::pasteFromLuaScript(string _s) { wstring m_CopyBuffer = string_to_wstring(_s); glEditor[currentEditor]->m_Text.insert(glEditor[currentEditor]->m_Position,m_CopyBuffer); glEditor[currentEditor]->m_Selection=false; glEditor[currentEditor]->m_Position+=m_CopyBuffer.size(); glEditor[currentEditor]->ProcessTabs(); }
/* virtual */ void base::print_on(std::wostream& wos) const { TRACE_NEVER("hugh::support::ostream::printable::base::print_on(std::wostream)"); std::ostringstream ostr; print_on(ostr); wos << string_to_wstring(ostr.str()); }
//-------------------------------------------------------------- void ofxFileDialog::refresh() { ofLogVerbose("ofxFileDialog") << "loading path: " << wstring_to_string(m_path); m_filenames.clear(); m_directories.clear(); ofDirectory dir(wstring_to_string(m_path)); dir.listDir(); vector<ofFile> files = dir.getFiles(); ofLogVerbose("ofxFileDialog") << files.size() << " files: "; // one level up if(m_path != U"/") { m_directories.insert(0); m_filenames.push_back(U".."); } // first dirs for(int i = 0; i < files.size(); ++i) { if(files[i].isDirectory()) { m_directories.insert(m_filenames.size()); m_filenames.push_back(string_to_wstring(files[i].getFileName())); ofLogVerbose("ofxFileDialog") << "\t" << wstring_to_string(m_filenames.back()); // select previous dir if(m_prevBasename != U"" && m_filenames.back() == m_prevBasename) { m_currentFile = m_filenames.size()-1; } } } // then files for(int i = 0; i < files.size(); ++i) { if(!files[i].isDirectory()) { m_filenames.push_back(string_to_wstring(files[i].getFileName())); ofLogVerbose("ofxFileDialog") << "\t" << wstring_to_string(m_filenames.back()); } } m_prevBasename = U""; }
void ofxGLEditor::setup(string fontFile) { string font = fontFile; string path = ofToDataPath(font); for (int i = 1; i < 10; i++) { GLEditor::InitFont(string_to_wstring(path)); GLEditor* editor = new GLEditor(); glEditor.push_back(editor); } reShape(); currentEditor = 1; }
int HttpWGReader::ReadSearchPlayers(LPSTR str, char nick[NICKLENGTH]) { Json::Value root; Json::StyledWriter styledWriter; Json::Reader reader; LPCWSTR lpcwDesignString; std::wstring ws; std::string status; CHAR lpId[10]; // ID игрока _itoa_s(HttpWGReader::GetPlayerID(), lpId, 10, 10); CHAR tmp[124]; // Парсинг строки BOOL parsingSuccessful = reader.parse(str, root); if (parsingSuccessful) { string_to_wstring(styledWriter.write(root), ws); lpcwDesignString = ws.c_str(); OutputDebugString(lpcwDesignString); } else { OutputDebugStringA("Parsing ReadSearchPlayers error!!!"); return -1; } // Проверяем правильное сообщение или считывание status = root.get("status", "error").asString(); if (strcmp(status.c_str(), "ok")) { OutputDebugStringA("\n\nParsing Status ReadPersonalPlayerData error!!!\n\n"); return -1; } const Json::Value data = root["data"]; for (int i = 0; i < data.size(); i++) { if (!strcmp(data[i]["nickname"].asString().c_str(), nick)) return atoi(data[i]["account_id"].asString().c_str()); else return -1; } }
bool path_exists(const string& path) { #ifdef _WIN32 string fixed_path = path_make_compatible(path); wstring path_wc = string_to_wstring(fixed_path); path_stat_t st; if(path_wstat(path_wc, &st) != 0) { return false; } return st.st_mode != 0; #else /* _WIN32 */ struct stat st; if(stat(path.c_str(), &st) != 0) { return 0; } return st.st_mode != 0; #endif /* _WIN32 */ }
LFXE_API void DeviceManager::UpdateDevicesWorker() { bool isUpdating = false; chrono::milliseconds timeTick; while (!this->stopUpdateDevicesWorker) { try { bool flushQueue = false; if (isUpdating && !this->updateDevicesNotifyEvent.IsNotified()) { // Still updating from previous iterations without new updates coming in, sleep for a while to prevent unneeded CPU usage this_thread::sleep_for(chrono::milliseconds(this->updateDevicesInterval)); } else { // Wait for when we get signaled to update or stop this->updateDevicesNotifyEvent.Wait(); // Reset certain variables since we should have a new timeline here flushQueue = this->flushQueue; this->flushQueue = false; isUpdating = false; } // Stop worker if it has been signaled to stop if (this->stopUpdateDevicesWorker) { break; } // Update every device bool done = true; timeTick = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()); for (size_t i = 0; i < this->GetChildrenCount(); ++i) { if (!isUpdating) { // This update is done for the first time, commit queued timeline and optionally flush the queue this->GetChildByIndex(i)->CommitQueuedTimeline(flushQueue); } done &= this->GetChildByIndex(i)->Update(timeTick); } isUpdating = !done; } catch (const exception& ex) { LOG_ERROR(L"Caught exception in DeviceManager thread: " + string_to_wstring(ex.what())); } } }
char* HttpWGReader::GetLocationUrl(LPSTR str) { Json::Value root; Json::StyledWriter styledWriter; Json::Reader reader; LPCWSTR lpcwDesignString; std::wstring ws; std::string status; char* s; int nLength = 0; // Парсинг строки BOOL parsingSuccessful = reader.parse(str, root); if (parsingSuccessful) { string_to_wstring(styledWriter.write(root), ws); lpcwDesignString = ws.c_str(); OutputDebugString(lpcwDesignString); } else { OutputDebugStringA("Parsing ReadSearchPlayers error!!!"); return NULL; } // Проверяем правильное сообщение или считывание status = root.get("status", "error").asString(); if (strcmp(status.c_str(), "ok")) { OutputDebugStringA("\n\nParsing Status GetLocationUrl error!!!\n\n"); return NULL; } nLength = strlen(root["data"]["location"].asString().c_str()) + 10; s = new char[nLength]; strcpy_s(s, nLength, root["data"]["location"].asString().c_str()); return s; }
bool V4fWriter::Open() { if (Opened || CURRENT_POSITION().Value().direction <= 0) return false; try { SECURITY_ATTRIBUTES sa; sa.nLength= sizeof(sa); sa.lpSecurityDescriptor= NULL; time_t now = time(NULL); localtime(&now); char hms[32]=""; char full_path [MAX_PATH] = "", short_path [128] = ""; strftime(hms, 31, "%Hh%Mm%Ss", localtime(&now)); _snprintf(short_path, 127, "%s_%s.v4f", wstring_to_string(cameraName).c_str(), hms); CreateFullPath(full_path, CURRENT_POSITION().Value().direction, CURRENT_POSITION().Value().way, CURRENT_POSITION().Value().start_time, short_path, wstring_to_string(VIDEO_OPTIONS().Value().video_server)); fullPath = string_to_wstring(full_path); dataSet = new V4fDataSet(wstring_to_string(fullPath), short_path, CURRENT_POSITION().Value().direction, CURRENT_POSITION().Value().way, CURRENT_POSITION().Value().start_time); if(dataSet) { dataSet->OpenWriteFile(); dataSet->WriteHeader(); Opened = true; current_start_time = CURRENT_POSITION().Value().start_time; return true; } } catch(std::exception e) { LOG_ERROR(L"ќшибка при открытии файла .v4f"); } return false; }
bool check_folder_exist(const std::string &strPath) { WIN32_FIND_DATA wfd; bool rValue = false; HANDLE hFind = NULL; #ifdef UNICODE wstring w_strPath; if (string_to_wstring(strPath, w_strPath)) { hFind = FindFirstFile(w_strPath.c_str(), &wfd); } #else hFind = FindFirstFile(strPath.c_str(), &wfd); #endif if ((hFind != INVALID_HANDLE_VALUE) && (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { rValue = true; } FindClose(hFind); return rValue; }
//-------------------------------------------------------------- void ofxEditorSyntax::setStringLiteral(const std::string &begin, const std::string &end) { stringLiteralBegin = string_to_wstring(begin); stringLiteralEnd = string_to_wstring(end); }
static int path_stat(const string& path, path_stat_t *st) { wstring path_wc = string_to_wstring(path); return path_wstat(path_wc, st); }
//-------------------------------------------------------------- void ofxEditorSyntax::setSingleLineComment(const std::string &begin) { singleLineComment = string_to_wstring(begin); }
LFXE_API size_t DeviceManager::InitializeDevices() { LOG_DEBUG(L"Initializing devices"); size_t i = 0; auto config = this->GetLightFXExtender()->GetConfigManager()->GetMainConfig(); this->updateDevicesInterval = config->TimelineUpdateInterval; auto lightpack = make_shared<DeviceLightpack>(config->LightpackHost, config->LightpackPort, config->LightpackKey); this->AddChild(L"Lightpack", lightpack); if (lightpack->Initialize()) { ++i; } auto logitech = make_shared<DeviceLogitech>(); logitech->SetRange(config->LogitechColorRangeOutMin, config->LogitechColorRangeOutMax, config->LogitechColorRangeInMin, config->LogitechColorRangeInMax); this->AddChild(L"Logitech", logitech); logitech->SetRestoreLightsOnNullEnabled(config->LogitechRestoreLightsOnNullEnabled); logitech->SetG110WorkaroundEnabled(config->LogitechG110WorkaroundEnabled); if (logitech->Initialize()) { ++i; } auto corsair = make_shared<DeviceCorsair>(); this->AddChild(L"Corsair", corsair); if (corsair->Initialize()) { ++i; } auto razer = make_shared<DeviceRazer>(); razer->SetHardware(config->RazerUseWithKeyboard, config->RazerUseWithMouse, config->RazerUseWithHeadset, config->RazerUseWithMousepad, config->RazerUseWithKeypad); this->AddChild(L"Razer", razer); if (razer->Initialize()) { ++i; } // Load native LightFX devices this->lightFXLibrary = unique_ptr<LightFX2Proxy>(new LightFX2Proxy(config->AlienwareDllName, config->AlienwareBackupDllName)); if (this->lightFXLibrary->Load()) { LOG_DEBUG(L"Alienware LightFX library found"); LFX_RESULT result; result = this->lightFXLibrary->LFX_Initialize(); if (result == LFX_SUCCESS) { unsigned int numDevices = 0; result = this->lightFXLibrary->LFX_GetNumDevices(&numDevices); if (result == LFX_SUCCESS) { LOG_DEBUG(to_wstring(numDevices) + L" LightFX devices found"); for (unsigned int j = 0; j < numDevices; ++j) { auto lightFX = make_shared<DeviceLightFX>(); lightFX->SetDeviceIndex(j); // Get device name first so we can properly add it to the list of devices char* devDesc = new char[LFX_MAX_STRING_SIZE]; unsigned char devType = 0; if (this->lightFXLibrary->LFX_GetDeviceDescription(j, devDesc, LFX_MAX_STRING_SIZE, &devType) == LFX_SUCCESS) { wstring deviceName = string_to_wstring(devDesc); if (deviceName == L"") { deviceName = L"LightFX " + to_wstring(j); } this->AddChild(deviceName, lightFX); if (lightFX->Initialize()) { ++i; } lightFX->SetDeviceName(deviceName); } else { LOG_ERROR(L"Failed to get the device name of LightFX device " + to_wstring(j)); } LFX_SAFE_DELETE_ARRAY(devDesc); } //TODO: Periodically check for changes (e.g. when a device gets connected or disconnected) } else { LOG_ERROR(L"Failed to check the number of LightFX devices: " + this->lightFXLibrary->LfxResultToString(result)); } } else { LOG_ERROR(L"Failed to initialize LightFX: " + this->lightFXLibrary->LfxResultToString(result)); } } else { LOG_DEBUG(L"Alienware LightFX library not found"); } LOG_INFO(L"Successfully initialized " + to_wstring(i) + L" devices"); // Enable devices where needed if (config->AutoDeviceDetection) { for (size_t i = 0; i < this->GetChildrenCount(); ++i) { auto device = this->GetChildByIndex(i); if (device == nullptr) { LOG_WARNING(L"Device " + device->GetDeviceName() + L" is configured in settings, but was not found in the system"); continue; } if (!device->IsInitialized()) { LOG_WARNING(L"Device " + device->GetDeviceName() + L" cannot be enabled, because was not initialized"); continue; } bool auto_result = device->Enable(); LOG_WARNING(L"Device " + device->GetDeviceName() + L" was automatically set to " + (auto_result ? L"ON" : L"OFF")); } } else { for (pair<wstring, bool> device : config->EnabledDevices) { if (device.second) { auto dev = this->GetChild(device.first); if (dev == nullptr) { LOG_WARNING(L"Device " + device.first + L" is configured in settings, but was not found in the system"); continue; } if (!dev->IsInitialized()) { LOG_WARNING(L"Device " + device.first + L" cannot be enabled, because was not initialized"); continue; } dev->Enable(); } } } return i; }
//-------------------------------------------------------------- void ofxEditorSyntax::setPreprocessor(const std::string &begin) { preprocessor = string_to_wstring(begin); }
//-------------------------------------------------------------- void ofxEditorSyntax::setMultiLineComment(const std::string &begin, const std::string &end) { multiLineCommentBegin = string_to_wstring(begin); multiLineCommentEnd = string_to_wstring(end); }
//-------------------------------------------------------------- bool ofxEditorSyntax::loadFile(const std::string& xmlFile) { std::string path = ofToDataPath(xmlFile); ofXml xml; if(!xml.load(path)) { ofLogError("ofxEditorSyntax") << "couldn't load \"" << ofFilePath::getFileName(xmlFile) << "\""; return false; } auto root = xml.getChild("syntax"); if(!root) { ofLogWarning("ofxEditorSyntax") << "root xml tag not \"syntax\", ignoring"; return false; } clear(); for(auto & child : root.getChildren()) { if(child.getName() == "lang") {setLang(child.getValue());} else if(child.getName() == "files") { for(auto & file : child.getChildren()) { if(file.getName() == "ext") {addFileExt(file.getValue());} else { ofLogWarning("ofxEditorSyntax") << "ignoring unknown files xml tag \"" << file.getName() << "\""; } } } else if(child.getName() == "singlecomment") {singleLineComment = string_to_wstring(child.getValue());} else if(child.getName() == "multicomment") { auto begin = child.getChild("begin"); auto end = child.getChild("end"); if(begin) {multiLineCommentBegin = string_to_wstring(begin.getValue());} if(end) {multiLineCommentBegin = string_to_wstring(end.getValue());} } else if(child.getName() == "stringliteral") { auto begin = child.getChild("begin"); auto end = child.getChild("end"); if(begin) {stringLiteralBegin = string_to_wstring(begin.getValue());} if(end) {stringLiteralEnd = string_to_wstring(end.getValue());} } else if(child.getName() == "preprocessor") {preprocessor = string_to_wstring(child.getValue());} else if(child.getName() == "hexliteral") { std::string b = child.getValue(); if(b == "true") {setHexLiteral(true);} else if(b == "false") {setHexLiteral(false);} else { ofLogWarning("ofxEditorSyntax") << "ignoring unknown xml bool string \"" << b << "\""; } } else if(child.getName() == "operator") {operatorChars = string_to_wstring(child.getValue());} else if(child.getName() == "punctuation") {punctuationChars = string_to_wstring(child.getValue());} else if(child.getName() == "words") { for(auto &word : child.getChildren()) { if(word.getName() == "keyword") {setWord(word.getValue(), KEYWORD);} else if(word.getName() == "typename") {setWord(word.getValue(), TYPENAME);} else if(word.getName() == "function") {setWord(word.getValue(), FUNCTION);} else { ofLogWarning("ofxEditorSyntax") << "ignoring unknown words xml tag \"" << word.getName() << "\""; } } } else { ofLogWarning("ofxEditorSyntax") << "ignoring unknown xml tag \"" << child.getName() << "\""; } } return true; }
//-------------------------------------------------------------- void ofxEditorSyntax::setPunctuationChars(const std::string &chars) { setPunctuationChars(string_to_wstring(chars)); }
//-------------------------------------------------------------- void ofxEditorSyntax::setOperatorChars(const std::string &chars) { setOperatorChars(string_to_wstring(chars)); }
//-------------------------------------------------------------- ofxEditorSyntax::WordType ofxEditorSyntax::getWordType(const std::string &word) { getWordType(string_to_wstring(word)); }
//-------------------------------------------------------------- void ofxEditorSyntax::setWord(const std::string &word, WordType type) { setWord(string_to_wstring(word), type); }