GuiXml::GuiXml() { PRINTF("Loading gui.xml file..."); ResourceFinder rf; rf.findInDataDir("gui.xml"); while (const char* path = rf.next()) { PRINTF("Trying to load GUI definitions from \"%s\"...\n", path); // If the file does not exist, just ignore this location (it was // suggested by the ResourceFinder class). if (!base::file_exists(path)) continue; PRINTF(" - \"%s\" found\n", path); // Try to load the XML file if (!m_doc.LoadFile(path)) throw XmlException(&m_doc); // Done, we load the file successfully. return; } throw base::Exception("gui.xml was not found"); }
GuiXml::GuiXml() { PRINTF("Loading gui.xml file..."); ResourceFinder rf; rf.findInDataDir("gui.xml"); while (const char* path = rf.next()) { PRINTF("Trying to load GUI definitions from \"%s\"...\n", path); // If the file does not exist, just ignore this location (it was // suggested by the ResourceFinder class). if (!base::file_exists(path)) continue; PRINTF(" - \"%s\" found\n", path); // Load the XML file. As we've already checked "path" existence, // in a case of exception we should show the error and stop. m_doc = app::open_xml(path); // Done, we load the file successfully. return; } throw base::Exception("gui.xml was not found"); }
void ConvolutionMatrixStock::reloadStock() { #define READ_TOK() { \ if (!tok_read(f, buf, leavings, sizeof (leavings))) \ break; \ } #define READ_INT(var) { \ READ_TOK(); \ var = strtol(buf, NULL, 10); \ } const char *names[] = { "convmatr.usr", "convmatr.gen", "convmatr.def", NULL }; char *s, buf[256], leavings[4096]; int i, c, x, y, w, h, div, bias; SharedPtr<ConvolutionMatrix> matrix; base::UniquePtr<FILE, int(*)(FILE*)> f; std::string name; cleanStock(); for (i=0; names[i]; i++) { ResourceFinder rf; rf.findInDataDir(names[i]); while (const char* path = rf.next()) { // Open matrices stock file f.reset(fopen(path, "r"), fclose); if (!f) continue; tok_reset_line_num(); strcpy(leavings, ""); // Read the matrix name while (tok_read(f, buf, leavings, sizeof(leavings))) { // Name of the matrix name = buf; // Width and height READ_INT(w); READ_INT(h); if ((w <= 0) || (w > 32) || (h <= 0) || (h > 32)) break; // Create the matrix data matrix.reset(new ConvolutionMatrix(w, h)); matrix->setName(name.c_str()); // Centre READ_INT(x); READ_INT(y); if ((x < 0) || (x >= w) || (y < 0) || (y >= h)) break; matrix->setCenterX(x); matrix->setCenterY(y); // Data READ_TOK(); // Jump the `{' char if (*buf != '{') break; c = 0; div = 0; for (y=0; y<h; ++y) { for (x=0; x<w; ++x) { READ_TOK(); int value = strtod(buf, NULL) * ConvolutionMatrix::Precision; div += value; matrix->value(x, y) = value; } } READ_TOK(); // Jump the `}' char if (*buf != '}') break; if (div > 0) bias = 0; else if (div == 0) { div = ConvolutionMatrix::Precision; bias = 128; } else { div = ABS(div); bias = 255; } // Div READ_TOK(); if (strcmp(buf, "auto") != 0) div = strtod(buf, NULL) * ConvolutionMatrix::Precision; matrix->setDiv(div); // Bias READ_TOK(); if (strcmp(buf, "auto") != 0) bias = strtod(buf, NULL); matrix->setBias(bias); // Target READ_TOK(); Target target = 0; for (s=buf; *s; s++) { switch (*s) { case 'r': target |= TARGET_RED_CHANNEL; break; case 'g': target |= TARGET_GREEN_CHANNEL; break; case 'b': target |= TARGET_BLUE_CHANNEL; break; case 'a': target |= TARGET_ALPHA_CHANNEL; break; } } if ((target & (TARGET_RED_CHANNEL | TARGET_GREEN_CHANNEL | TARGET_BLUE_CHANNEL)) != 0) { target |= TARGET_GRAY_CHANNEL; } matrix->setDefaultTarget(target); // Insert the new matrix in the list m_matrices.push_back(matrix); } } } }