static void tokenize(const UnicodeString & str, rde::vector<UnicodeString> & tokens, const UnicodeString & delimiters = L" ", const bool trimEmpty = false) { intptr_t lastPos = 0; while (true) { intptr_t pos = str.FindFirstOf(delimiters.c_str(), lastPos); if (pos == NPOS) { pos = str.Length(); if (pos != lastPos || !trimEmpty) { tokens.push_back( UnicodeString(str.data() + lastPos, pos - lastPos)); } break; } else { if (pos != lastPos || !trimEmpty) { tokens.push_back( UnicodeString(str.data() + lastPos, pos - lastPos)); } } lastPos = pos + 1; } }
UnicodeString far_get_full_path(const UnicodeString& file_path) { const unsigned c_buf_size = 0x10000; UnicodeString full_path; int size = static_cast<int>(g_fsf.ConvertPath(CPM_FULL, file_path.data(), full_path.buf(c_buf_size), c_buf_size)); if (size > c_buf_size) g_fsf.ConvertPath(CPM_FULL, file_path.data(), full_path.buf(size), size); full_path.set_size(); return full_path; }
UnicodeString reg_read_string(HKEY hkey, const UnicodeString& name, const UnicodeString& def_value) { UnicodeString value = def_value; DWORD type = REG_SZ; DWORD data_size; // get string size LONG res = RegQueryValueExW(hkey, name.data(), NULL, &type, NULL, &data_size); if (res == ERROR_SUCCESS) { UnicodeString data; // get string value res = RegQueryValueExW(hkey, name.data(), NULL, &type, (LPBYTE) data.buf(data_size / sizeof(wchar_t)), &data_size); if (res == ERROR_SUCCESS) { data.set_size(data_size / sizeof(wchar_t) - 1); // throw away terminating NULL value = data; } } return value; }
bool set(const wchar_t* name, const UnicodeString& value) { FarSettingsItem fsi = { sizeof(FarSettingsItem) }; fsi.Root = 0; fsi.Name = name; fsi.Type = FST_STRING; fsi.String = value.data(); return control(SCTL_SET, &fsi) != 0; }
bool ExecuteShell(const UnicodeString & APath, const UnicodeString & Params, HANDLE & Handle) { TShellExecuteInfoW ExecuteInfo; ::ZeroMemory(&ExecuteInfo, sizeof(ExecuteInfo)); ExecuteInfo.cbSize = sizeof(ExecuteInfo); ExecuteInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ExecuteInfo.hwnd = reinterpret_cast<HWND>(::GetModuleHandle(0)); ExecuteInfo.lpFile = const_cast<wchar_t *>(APath.data()); ExecuteInfo.lpParameters = const_cast<wchar_t *>(Params.data()); ExecuteInfo.nShow = SW_SHOW; bool Result = (::ShellExecuteEx(&ExecuteInfo) != 0); if (Result) { Handle = ExecuteInfo.hProcess; } return Result; }
void WINAPI GetPluginInfoW(PluginInfo* info) { info->StructSize = sizeof(PluginInfo); ObjectArray<DeviceInfo> dev_list; try { init_if_needed(); get_device_list(dev_list); } catch (...) { dev_list.clear(); } if (dev_list.size() == 0) { if (g_plugin_options.last_dev_type == dtPDA) disk_menu[0] = far_msg_ptr(MSG_DISK_MENU_PDA); else if (g_plugin_options.last_dev_type == dtSmartPhone) disk_menu[0] = far_msg_ptr(MSG_DISK_MENU_SMARTPHONE); else disk_menu[0] = far_msg_ptr(MSG_DISK_MENU_PDA); } else { if (dev_list[0].platform == L"PocketPC") { disk_menu[0] = far_msg_ptr(MSG_DISK_MENU_PDA); g_plugin_options.last_dev_type = dtPDA; } else if (dev_list[0].platform == L"SmartPhone") { disk_menu[0] = far_msg_ptr(MSG_DISK_MENU_SMARTPHONE); g_plugin_options.last_dev_type = dtSmartPhone; } else { disk_menu[0] = far_msg_ptr(MSG_DISK_MENU_PDA); g_plugin_options.last_dev_type = dtPDA; } save_plugin_options(g_plugin_options); } if (g_plugin_options.add_to_disk_menu) { info->DiskMenu.Strings = disk_menu; info->DiskMenu.Guids = &c_disk_menu_guid; info->DiskMenu.Count = ARRAYSIZE(disk_menu); } if (g_plugin_options.add_to_plugin_menu) { plugin_menu[0] = far_msg_ptr(MSG_PLUGIN_NAME); info->PluginMenu.Strings = plugin_menu; info->PluginMenu.Guids = &c_plugin_menu_guid; info->PluginMenu.Count = ARRAYSIZE(plugin_menu); } config_menu[0] = far_msg_ptr(MSG_PLUGIN_NAME); info->PluginConfig.Strings = config_menu; info->PluginConfig.Guids = &c_config_menu_guid; info->PluginConfig.Count = ARRAYSIZE(config_menu); info->CommandPrefix = g_plugin_format.data(); }
bool ExecuteShellAndWait(HINSTANCE /*Handle*/, const UnicodeString & APath, const UnicodeString & Params, TProcessMessagesEvent ProcessMessages) { TShellExecuteInfoW ExecuteInfo; ::ZeroMemory(&ExecuteInfo, sizeof(ExecuteInfo)); ExecuteInfo.cbSize = sizeof(ExecuteInfo); ExecuteInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ExecuteInfo.hwnd = reinterpret_cast<HWND>(::GetModuleHandle(0)); ExecuteInfo.lpFile = const_cast<wchar_t *>(APath.data()); ExecuteInfo.lpParameters = const_cast<wchar_t *>(Params.data()); ExecuteInfo.nShow = SW_SHOW; bool Result = (::ShellExecuteEx(&ExecuteInfo) != 0); if (Result) { if (ProcessMessages != nullptr) { uint32_t WaitResult; do { WaitResult = ::WaitForSingleObject(ExecuteInfo.hProcess, 200); if (WaitResult == WAIT_FAILED) { throw Exception(LoadStr(DOCUMENT_WAIT_ERROR)); } ProcessMessages(); } while (WaitResult == WAIT_TIMEOUT); } else { ::WaitForSingleObject(ExecuteInfo.hProcess, INFINITE); } } return Result; }
void WINAPI GetOpenPanelInfoW(OpenPanelInfo* info) { PluginInstance* plugin = (PluginInstance*) info->hPanel; info->StructSize = sizeof(OpenPanelInfo); info->Flags = OPIF_ADDDOTS | OPIF_SHORTCUT; info->CurDir = plugin->current_dir.data(); info->Format = g_plugin_format.data(); if (g_plugin_options.last_dev_type == dtPDA) plugin->panel_title = far_msg_ptr(MSG_DISK_MENU_PDA); else if (g_plugin_options.last_dev_type == dtSmartPhone) plugin->panel_title = far_msg_ptr(MSG_DISK_MENU_SMARTPHONE); else plugin->panel_title = far_msg_ptr(MSG_DISK_MENU_PDA); plugin->panel_title.add(L":").add(plugin->current_dir); if (g_plugin_options.show_free_space) plugin->panel_title.add(L":" + format_data_size(plugin->free_space, get_size_suffixes())); info->PanelTitle = plugin->panel_title.data(); info->InfoLines = plugin->sys_info.data(); info->InfoLinesNumber = plugin->sys_info.size(); }
// unicode <-> oem codepage conversions void unicode_to_oem(AnsiString& oem_str, const UnicodeString& u_str) { unsigned size = u_str.size() + 1; int res = WideCharToMultiByte(CP_OEMCP, 0, u_str.data(), size, oem_str.buf(u_str.size()), size, NULL, NULL); if (res == 0) FAIL(SystemError()); oem_str.set_size(res - 1); }
bool ExecuteShell(const UnicodeString & APath, const UnicodeString & Params) { return ((intptr_t)::ShellExecute(nullptr, L"open", const_cast<wchar_t *>(APath.data()), const_cast<wchar_t *>(Params.data()), nullptr, SW_SHOWNORMAL) > 32); }