std::vector<std::wstring> CAdblockPlusClient::GetExceptionDomains() { Communication::InputBuffer response; if (!CallEngine(Communication::PROC_GET_EXCEPTION_DOMAINS, response)) return std::vector<std::wstring>(); return ReadStrings(response); }
int ShowProgressUI() { if (!sEnableUI) return -1; // Only show the Progress UI if the process is taking a significant amount of // time where a significant amount of time is defined as .5 seconds after // ShowProgressUI is called sProgress is less than 70. usleep(500000); if (sQuit || sProgressVal > 70.0f) return 0; char ini_path[PATH_MAX]; snprintf(ini_path, sizeof(ini_path), "%s.ini", sProgramPath); StringTable strings; if (ReadStrings(ini_path, &strings) != OK) return -1; sWin = gtk_window_new(GTK_WINDOW_TOPLEVEL); if (!sWin) return -1; static GdkPixbuf *pixbuf; char icon_path[PATH_MAX]; snprintf(icon_path, sizeof(icon_path), "%s.png", sProgramPath); g_signal_connect(G_OBJECT(sWin), "delete_event", G_CALLBACK(OnDeleteEvent), NULL); gtk_window_set_title(GTK_WINDOW(sWin), strings.title); gtk_window_set_type_hint(GTK_WINDOW(sWin), GDK_WINDOW_TYPE_HINT_DIALOG); gtk_window_set_position(GTK_WINDOW(sWin), GTK_WIN_POS_CENTER_ALWAYS); gtk_window_set_resizable(GTK_WINDOW(sWin), FALSE); gtk_window_set_decorated(GTK_WINDOW(sWin), TRUE); gtk_window_set_deletable(GTK_WINDOW(sWin),FALSE); pixbuf = gdk_pixbuf_new_from_file (icon_path, NULL); gtk_window_set_icon(GTK_WINDOW(sWin), pixbuf); g_object_unref(pixbuf); GtkWidget *vbox = gtk_vbox_new(TRUE, 6); sLabel = gtk_label_new(strings.info); gtk_misc_set_alignment(GTK_MISC(sLabel), 0.0f, 0.0f); sProgressBar = gtk_progress_bar_new(); gtk_box_pack_start(GTK_BOX(vbox), sLabel, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), sProgressBar, TRUE, TRUE, 0); sTimerID = g_timeout_add(TIMER_INTERVAL, UpdateDialog, NULL); gtk_container_set_border_width(GTK_CONTAINER(sWin), 10); gtk_container_add(GTK_CONTAINER(sWin), vbox); gtk_widget_show_all(sWin); gtk_main(); return 0; }
int ShowProgressUI() { if (!sEnableUI) return -1; // Only show the Progress UI if the process is taking significant time. // Here we measure significant time as taking more than one second. usleep(500000); if (sQuit || sProgressVal > 50.0f) return 0; char path[PATH_MAX]; snprintf(path, sizeof(path), "%s.ini", sProgramPath); StringTable strings; if (ReadStrings(path, &strings) != OK) return -1; sWin = gtk_window_new(GTK_WINDOW_TOPLEVEL); if (!sWin) return -1; // GTK 2.2 seems unable to prevent our dialog from being closed when // the user hits the close button on the dialog. This problem only // occurs when either one of the following methods are called: // gtk_window_set_position // gtk_window_set_type_hint // For this reason, we disable window decorations. g_signal_connect(G_OBJECT(sWin), "delete_event", G_CALLBACK(OnDeleteEvent), NULL); gtk_window_set_title(GTK_WINDOW(sWin), strings.title); gtk_window_set_type_hint(GTK_WINDOW(sWin), GDK_WINDOW_TYPE_HINT_DIALOG); gtk_window_set_position(GTK_WINDOW(sWin), GTK_WIN_POS_CENTER_ALWAYS); gtk_window_set_resizable(GTK_WINDOW(sWin), FALSE); gtk_window_set_decorated(GTK_WINDOW(sWin), FALSE); GtkWidget *vbox = gtk_vbox_new(TRUE, 6); sLabel = gtk_label_new(strings.info); gtk_misc_set_alignment(GTK_MISC(sLabel), 0.0f, 0.0f); sProgressBar = gtk_progress_bar_new(); gtk_box_pack_start(GTK_BOX(vbox), sLabel, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), sProgressBar, TRUE, TRUE, 0); sTimerID = g_timeout_add(TIMER_INTERVAL, UpdateDialog, NULL); gtk_container_set_border_width(GTK_CONTAINER(sWin), 10); gtk_container_add(GTK_CONTAINER(sWin), vbox); gtk_widget_show_all(sWin); gtk_main(); return 0; }
int main(int argc, char const *argv[]) { std::vector<std::string> strings; ReadStrings(&strings); std::sort(strings.begin(), strings.end(), CompareStrings); std::copy(strings.begin(), strings.end(), std::ostream_iterator<std::string>(std::cout, " ")); std::cout << std::endl; return 0; }
std::vector<std::wstring> CAdblockPlusClient::GetElementHidingSelectors(const std::wstring& domain) { Communication::OutputBuffer request; request << Communication::PROC_GET_ELEMHIDE_SELECTORS << ToUtf8String(domain); Communication::InputBuffer response; if (!CallEngine(request, response)) return std::vector<std::wstring>(); return ReadStrings(response); }
bool ReadStringsFromFile(const string& path, StringTable& strings, bool unescape) { ifstream* f = UIOpenRead(path); bool success = false; if (f->is_open()) { success = ReadStrings(*f, strings, unescape); f->close(); } delete f; return success; }
// A wrapper function to read strings for the updater. // Added for compatibility with the original code. int ReadStrings(const NS_tchar *path, StringTable *results) { const unsigned int kNumStrings = 2; const char *kUpdaterKeys = "Title\0Info\0"; char updater_strings[kNumStrings][MAX_TEXT_LEN]; int result = ReadStrings(path, kUpdaterKeys, kNumStrings, updater_strings); strncpy(results->title, updater_strings[0], MAX_TEXT_LEN - 1); results->title[MAX_TEXT_LEN - 1] = '\0'; strncpy(results->info, updater_strings[1], MAX_TEXT_LEN - 1); results->info[MAX_TEXT_LEN - 1] = '\0'; return result; }
/** * A wrapper function to read strings for the maintenance service. * * @param path The path of the ini file to read from * @param results The maintenance service strings that were read * @return OK on success */ static int ReadMaintenanceServiceStrings(LPCWSTR path, MaintenanceServiceStringTable *results) { // Read in the maintenance service description string if specified. const unsigned int kNumStrings = 1; const char *kServiceKeys = "MozillaMaintenanceDescription\0"; char serviceStrings[kNumStrings][MAX_TEXT_LEN]; int result = ReadStrings(path, kServiceKeys, kNumStrings, serviceStrings); if (result != OK) { serviceStrings[0][0] = '\0'; } strncpy(results->serviceDescription, serviceStrings[0], MAX_TEXT_LEN - 1); results->serviceDescription[MAX_TEXT_LEN - 1] = '\0'; return result; }
void TestCustomReadWrite(void) { Strings strings = NewStringsTable(3); String carl = InsertString(strings, "Carl"); String john = InsertString(strings, "John"); String peter = InsertString(strings, "Peter"); const char* c = GetString(strings, carl); const char* j = GetString(strings, john); const char* p = GetString(strings, peter); assert(strcmp(c, "Carl") == 0); assert(strcmp(j, "John") == 0); assert(strcmp(p, "Peter") == 0); // Save data. const char* file = "testfiles/test-strings.bin"; FILE *f = fopen(file, "w"); WriteStrings(strings, f); fclose(f); // Release memory. FreeStringsTable(&strings); f = fopen(file, "r"); strings = ReadStrings(f); fclose(f); assert(strings.table->len == 3); assert(strings.table->cap == 3); assert(strings.table->column_len == 1); c = GetString(strings, carl); j = GetString(strings, john); p = GetString(strings, peter); assert(strcmp(c, "Carl") == 0); assert(strcmp(j, "John") == 0); assert(strcmp(p, "Peter") == 0); FreeStringsTable(&strings); assert(strings.table == NULL); }
int NS_main(int argc, NS_tchar **argv) { printf("Running TestAUSReadStrings tests\n"); int rv = 0; int retval; NS_tchar inifile[MAXPATHLEN]; StringTable testStrings; NS_tchar *slash = NS_tstrrchr(argv[0], PATH_SEPARATOR_CHAR); if (!slash) { fail("%s | unable to find platform specific path separator (check 1)", TEST_NAME); return 20; } *(++slash) = '\0'; // Test success when the ini file exists with both Title and Info in the // Strings section and the values for Title and Info. NS_tsnprintf(inifile, sizeof(inifile), NS_T("%sTestAUSReadStrings1.ini"), argv[0]); retval = ReadStrings(inifile, &testStrings); if (retval == OK) { if (strcmp(testStrings.title, "Title Test - \xD0\x98\xD1\x81\xD0\xBF\xD1\x8B" \ "\xD1\x82\xD0\xB0\xD0\xBD\xD0\xB8\xD0\xB5 " \ "\xCE\x94\xCE\xBF\xCE\xBA\xCE\xB9\xCE\xBC\xCE\xAE " \ "\xE3\x83\x86\xE3\x82\xB9\xE3\x83\x88 " \ "\xE6\xB8\xAC\xE8\xA9\xA6 " \ "\xE6\xB5\x8B\xE8\xAF\x95") != 0) { rv = 21; fail("%s | Title ini value incorrect (check 3)", TEST_NAME); } if (strcmp(testStrings.info, "Info Test - \xD0\x98\xD1\x81\xD0\xBF\xD1\x8B" \ "\xD1\x82\xD0\xB0\xD0\xBD\xD0\xB8\xD0\xB5 " \ "\xCE\x94\xCE\xBF\xCE\xBA\xCE\xB9\xCE\xBC\xCE\xAE " \ "\xE3\x83\x86\xE3\x82\xB9\xE3\x83\x88 " \ "\xE6\xB8\xAC\xE8\xA9\xA6 " \ "\xE6\xB5\x8B\xE8\xAF\x95\xE2\x80\xA6") != 0) { rv = 22; fail("%s | Info ini value incorrect (check 4)", TEST_NAME); } } else { fail("%s | ReadStrings returned %i (check 2)", TEST_NAME, retval); rv = 23; } // Test failure when the ini file exists without Title and with Info in the // Strings section. NS_tsnprintf(inifile, sizeof(inifile), NS_T("%sTestAUSReadStrings2.ini"), argv[0]); retval = ReadStrings(inifile, &testStrings); if (retval != PARSE_ERROR) { rv = 24; fail("%s | ReadStrings returned %i (check 5)", TEST_NAME, retval); } // Test failure when the ini file exists with Title and without Info in the // Strings section. NS_tsnprintf(inifile, sizeof(inifile), NS_T("%sTestAUSReadStrings3.ini"), argv[0]); retval = ReadStrings(inifile, &testStrings); if (retval != PARSE_ERROR) { rv = 25; fail("%s | ReadStrings returned %i (check 6)", TEST_NAME, retval); } // Test failure when the ini file doesn't exist NS_tsnprintf(inifile, sizeof(inifile), NS_T("%sTestAUSReadStringsBogus.ini"), argv[0]); retval = ReadStrings(inifile, &testStrings); if (retval != READ_ERROR) { rv = 26; fail("%s | ini file doesn't exist (check 7)", TEST_NAME); } // Test reading a non-default section name NS_tsnprintf(inifile, sizeof(inifile), NS_T("%sTestAUSReadStrings3.ini"), argv[0]); retval = ReadStrings(inifile, "Title\0", 1, &testStrings.title, "BogusSection2"); if (retval == OK) { if (strcmp(testStrings.title, "Bogus Title") != 0) { rv = 27; fail("%s | Title ini value incorrect (check 9)", TEST_NAME); } } else { fail("%s | ReadStrings returned %i (check 8)", TEST_NAME, retval); rv = 28; } if (rv == 0) { printf("TEST-PASS | %s | all checks passed\n", TEST_NAME); } else { fail("%s | %i out of 9 checks failed", TEST_NAME, gFailCount); } return rv; }
static bool AddSubmittedReport(const string& serverResponse) { StringTable responseItems; istringstream in(serverResponse); ReadStrings(in, responseItems, false); if (responseItems.find("StopSendingReportsFor") != responseItems.end()) { // server wants to tell us to stop sending reports for a certain version string reportPath = gSettingsPath + UI_DIR_SEPARATOR + "EndOfLife" + responseItems["StopSendingReportsFor"]; ofstream* reportFile = UIOpenWrite(reportPath); if (reportFile->is_open()) { // don't really care about the contents *reportFile << 1 << "\n"; reportFile->close(); } delete reportFile; } if (responseItems.find("Discarded") != responseItems.end()) { // server discarded this report... save it so the user can resubmit it // manually return false; } if (responseItems.find("CrashID") == responseItems.end()) return false; string submittedDir = gSettingsPath + UI_DIR_SEPARATOR + "submitted"; if (!UIEnsurePathExists(submittedDir)) { return false; } string path = submittedDir + UI_DIR_SEPARATOR + responseItems["CrashID"] + ".txt"; ofstream* file = UIOpenWrite(path); if (!file->is_open()) { delete file; return false; } char buf[1024]; UI_SNPRINTF(buf, 1024, gStrings["CrashID"].c_str(), responseItems["CrashID"].c_str()); *file << buf << "\n"; if (responseItems.find("ViewURL") != responseItems.end()) { UI_SNPRINTF(buf, 1024, gStrings["CrashDetailsURL"].c_str(), responseItems["ViewURL"].c_str()); *file << buf << "\n"; } file->close(); delete file; WriteSubmissionEvent(Succeeded, responseItems["CrashID"]); return true; }
//-***************************************************************************** void HDF5HierarchyReader::readHierarchy( hid_t iFile ) { std::vector<hobj_ref_t> objectRefs; std::vector<uint32_t> childrenSizes; std::vector<std::string> childrenNames; std::vector<hobj_ref_t> childrenRefs; std::vector<uint32_t> attrSizes; std::vector<std::string> attrNames; std::vector<char> hasMask; std::vector<uint32_t> maskBits; std::vector<char> hasMeta; std::vector<std::string> metaStrs; ReadReferences( iFile, "object_references", objectRefs ); // Children childrenSizes.resize( objectRefs.size() ); H5LTget_attribute_uint( iFile, ".", "children_sizes", &childrenSizes.front() ); ReadReferences( iFile, "children_references", childrenRefs ); childrenNames.resize( childrenRefs.size() ); ReadStrings( iFile, "children_names", childrenNames.size(), &childrenNames.front() ); // Attributes attrSizes.resize( objectRefs.size() ); H5LTget_attribute_uint( iFile, ".", "attr_sizes", &attrSizes.front() ); size_t totalA(0); for( size_t i=0; i < attrSizes.size(); ++i ) totalA += attrSizes[i]; attrNames.resize( totalA ); ReadStrings( iFile, "attr_names", totalA, &attrNames.front() ); // Masks hasMask.resize( totalA ); H5LTget_attribute_char( iFile, ".", "mask_on", &hasMask.front() ); size_t totalMask(0); for( size_t i = 0; i < hasMask.size(); ++i ) totalMask += hasMask[i]; maskBits.resize( totalMask * 6 ); H5LTget_attribute_uint( iFile, ".", "mask_bits", &maskBits.front() ); // MetaData hasMeta.resize( totalA ); H5LTget_attribute_char( iFile, ".", "meta_on", &hasMeta.front() ); size_t totalMeta(0); for( size_t i = 0; i < hasMeta.size(); ++i ) totalMeta += hasMeta[i]; metaStrs.resize( totalMeta ); ReadStrings( iFile, "meta_strs", totalMeta, &metaStrs.front() ); m_H5H.extractFromCompactObjectHierarchy( iFile, objectRefs, childrenSizes, childrenNames, childrenRefs, attrSizes, attrNames, hasMask, maskBits, hasMeta, metaStrs ); }
static void InitDialog(HWND hDlg) { WCHAR filename[MAX_PATH]; if (!GetStringsFile(filename)) return; StringTable uiStrings; if (ReadStrings(filename, &uiStrings) != OK) return; WCHAR szwTitle[MAX_TEXT_LEN]; WCHAR szwInfo[MAX_TEXT_LEN]; MultiByteToWideChar(CP_UTF8, 0, uiStrings.title, strlen(uiStrings.title) + 1, szwTitle, sizeof(szwTitle)/sizeof(szwTitle[0])); MultiByteToWideChar(CP_UTF8, 0, uiStrings.info, strlen(uiStrings.info) + 1, szwInfo, sizeof(szwInfo)/sizeof(szwInfo[0])); SetWindowTextW(hDlg, szwTitle); SetWindowTextW(GetDlgItem(hDlg, IDC_INFO), szwInfo); // Set dialog icon HICON hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_DIALOG)); if (hIcon) SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM) hIcon); HWND hWndPro = GetDlgItem(hDlg, IDC_PROGRESS); SendMessage(hWndPro, PBM_SETRANGE, 0, MAKELPARAM(0, 100)); // Resize the dialog to fit all of the text if necessary. RECT infoSize, textSize; HWND hWndInfo = GetDlgItem(hDlg, IDC_INFO); // Get the control's font for calculating the new size for the control HDC hDCInfo = GetDC(hWndInfo); HFONT hInfoFont, hOldFont; hInfoFont = (HFONT)SendMessage(hWndInfo, WM_GETFONT, 0, 0); if (hInfoFont) hOldFont = (HFONT)SelectObject(hDCInfo, hInfoFont); // There are three scenarios that need to be handled differently // 1. Windows Mobile where dialog should be full screen. // 2. Windows CE where the dialog might wrap. // 3. Windows where the dialog should never wrap. The Windows CE and Windows // scenarios could be combined but then we would have to calculate the // extra border space added by the Aero theme which just adds complexity. #ifdef WINCE #ifdef WINCE_WINDOWS_MOBILE RECT rcDlgInner1, rcDlgInner2, rcInfoOuter1, rcInfoOuter2; // The dialog's client rectangle and the window rectangle for the text before // making the dialog full screen are needed to calculate the change in border // sizes. GetClientRect(hDlg, &rcDlgInner1); GetWindowRect(hWndInfo, &rcInfoOuter1); // Make the dialog fullscreen SHINITDLGINFO shidi; shidi.dwMask = SHIDIM_FLAGS; shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN; shidi.hDlg = hDlg; SHInitDialog(&shidi); if (!SHInitDialog(&shidi)) return; // Hide the OK button SHDoneButton(hDlg, SHDB_HIDE); GetClientRect(hDlg, &rcDlgInner2); GetWindowRect(hWndInfo, &rcInfoOuter2); textSize.left = 0; // Calculate the maximum possible width for the text by adding to the // existing text rectangle's window width the change in the dialog rectangle's // client width and the change in the text rectangle's window left position // after the dialog has been made full screen. textSize.right = (rcInfoOuter2.right - rcInfoOuter2.left) + \ (rcDlgInner2.right - rcDlgInner1.right) + \ (rcInfoOuter1.left - rcInfoOuter2.left); #else RECT rcWorkArea, rcInfoOuter1; GetWindowRect(hWndInfo, &rcInfoOuter1); SystemParametersInfo(SPI_GETWORKAREA, NULL, &rcWorkArea, NULL); textSize.left = 0; // Calculate the maximum possible width for the text by subtracting from the // existing working area's width the text rectangle's margin. textSize.right = (rcWorkArea.right - rcWorkArea.left) - \ (rcInfoOuter1.left + rcInfoOuter1.right); #endif // Measure the space needed for the text allowing multiple lines if necessary. // DT_CALCRECT means nothing is drawn. if (DrawText(hDCInfo, szwInfo, -1, &textSize, DT_CALCRECT | DT_NOCLIP | DT_WORDBREAK)) { GetClientRect(hWndInfo, &infoSize); SIZE extra; // Calculate the additional space needed for the text by subtracting from // the rectangle returned by DrawText the existing client rectangle's width // and height. extra.cx = (textSize.right - textSize.left) - \ (infoSize.right - infoSize.left); extra.cy = (textSize.bottom - textSize.top) - \ (infoSize.bottom - infoSize.top); // XXX rstrong - add 2 pixels to the width to prevent the text from wrapping // due to Windows CE and Windows Mobile adding an extra pixel to the // beginning and the end of the text. Though I have found no good reason for // this it has been consistent with multiple font sizes. extra.cx += 2; RESIZE_WINDOW(hWndInfo, extra.cx, extra.cy); RESIZE_WINDOW(hWndPro, extra.cx, 0); #ifdef WINCE_WINDOWS_MOBILE // Move the controls 1 pixel to the left on Windows Mobile to compensate for // the 2 extra pixels added to the controls above. This isn't needed on // Windows CE for reasons of the unknown variety. MOVE_WINDOW(hWndInfo, -1, 0); MOVE_WINDOW(hWndPro, -1, extra.cy); #else RESIZE_WINDOW(hDlg, extra.cx, extra.cy); MOVE_WINDOW(hWndPro, 0, extra.cy); #endif } #else // Measure the space needed for the text on a single line. DT_CALCRECT means // nothing is drawn. if (DrawText(hDCInfo, szwInfo, -1, &textSize, DT_CALCRECT | DT_NOCLIP | DT_SINGLELINE)) { GetClientRect(hWndInfo, &infoSize); SIZE extra; // Calculate the additional space needed for the text by subtracting from // the rectangle returned by DrawText the existing client rectangle's width // and height. extra.cx = (textSize.right - textSize.left) - \ (infoSize.right - infoSize.left); extra.cy = (textSize.bottom - textSize.top) - \ (infoSize.bottom - infoSize.top); if (extra.cx < 0) extra.cx = 0; if (extra.cy < 0) extra.cy = 0; if ((extra.cx > 0) || (extra.cy > 0)) { RESIZE_WINDOW(hDlg, extra.cx, extra.cy); RESIZE_WINDOW(hWndInfo, extra.cx, extra.cy); RESIZE_WINDOW(hWndPro, extra.cx, 0); MOVE_WINDOW(hWndPro, 0, extra.cy); } } #endif if (hOldFont) SelectObject(hDCInfo, hOldFont); ReleaseDC(hWndInfo, hDCInfo); // On Windows Mobile the dialog is full screen so don't center it. #ifndef WINCE_WINDOWS_MOBILE CenterDialog(hDlg); // make dialog appear in the center of the screen #endif SetTimer(hDlg, TIMER_ID, TIMER_INTERVAL, NULL); }