void UmlArtifact::genpro() { UmlPackage * pack = (UmlPackage *) parent()->parent(); Q3CString path; if (! propertyValue("genpro path", path)) { path = pack->cppSrcDir(); if (path.isEmpty()) path = root_dir(); else if (QDir::isRelativePath(path)) { QDir d(root_dir()); d.cd(path); path = d.absPath(); } } if (stereotype() == "executable") { gen_app(path); } else UmlCom::trace(stereotype() + " : not managed"); }
void command_init (Database& db, const std::vector <std::string>& args) { // Verify that root exists. std::string root = db._config->get ("root"); if (root == "") throw std::string ("ERROR: The '--data' option is required."); Directory root_dir (root); if (!root_dir.exists ()) throw std::string ("ERROR: The '--data' path does not exist."); if (!root_dir.is_directory ()) throw std::string ("ERROR: The '--data' path is not a directory."); if (!root_dir.readable ()) throw std::string ("ERROR: The '--data' directory is not readable."); if (!root_dir.writable ()) throw std::string ("ERROR: The '--data' directory is not writable."); if (!root_dir.executable ()) throw std::string ("ERROR: The '--data' directory is not executable."); // Provide some defaults and overrides. db._config->set ("extensions", TASKD_EXTDIR); db._config->setIfBlank ("log", "/tmp/taskd.log"); db._config->setIfBlank ("queue.size", "10"); db._config->setIfBlank ("pid.file", "/tmp/taskd.pid"); db._config->setIfBlank ("ip.log", "on"); db._config->setIfBlank ("request.limit", "1048576"); db._config->setIfBlank ("confirmation", "1"); db._config->setIfBlank ("verbose", "1"); // Suggestions for missing items. if (db._config->get ("server") == "") std::cout << "You must specify the 'server' variable, for example:\n" << " taskd config server localhost:53589\n" << "\n"; // Create the data structure. Directory sub (root_dir); sub.cd (); sub += "orgs"; if (!sub.exists ()) if (!sub.create (0700)) throw std::string ("ERROR: Could not create '") + sub._data + "'."; // Dump the config file? db._config->_original_file = root_dir._data + "/config"; if (! db._config->_original_file.exists ()) db._config->_original_file.create (0600); if (db._config->dirty ()) { db._config->save (); if (db._config->getBoolean ("verbose")) std::cout << "Created " << std::string (db._config->_original_file) << "\n"; } }
void file_system::open_bin_output(FILE *file) { std::string temp_filename = root_dir() + relative_dir(); // file = fopen(temp_filename.std::string::c_str(), "w"); // switch(file not_eq NULL) { case true: stream_ready = true; break; } }
void file_system::open_txt_input(std::fstream &file) { std::string temp_filename = root_dir() + relative_dir(); // file.std::fstream::open(temp_filename.std::string::c_str(), std::fstream::in); // switch(file.std::fstream::is_open() and file.std::fstream::good()) { case true: stream_ready = true; break; } }
void file_system::open_bin_output(std::fstream &file) { std::string temp_filename = root_dir() + relative_dir(); // file.std::fstream::open(temp_filename.std::string::c_str(), std::fstream::out | std::ios::binary | std::ios::app); // switch(file.std::fstream::is_open() and file.std::fstream::good()) { case true: stream_ready = true; break; } }
bool test_create_account_with_account_control() { SETUP_TEST_S3SIMULATOR(); std::auto_ptr<Configuration> config = load_config_file(DEFAULT_BBACKUPD_CONFIG_FILE, BackupDaemonConfigVerify); S3BackupAccountControl control(*config); control.CreateAccount("test", 1000, 2000); FileStream fs("testfiles/store/subdir/" S3_INFO_FILE_NAME); std::auto_ptr<BackupStoreInfo> info = BackupStoreInfo::Load(fs, fs.GetFileName(), true); // ReadOnly TEST_EQUAL(0, info->GetAccountID()); TEST_EQUAL(1, info->GetLastObjectIDUsed()); TEST_EQUAL(1, info->GetBlocksUsed()); TEST_EQUAL(0, info->GetBlocksInCurrentFiles()); TEST_EQUAL(0, info->GetBlocksInOldFiles()); TEST_EQUAL(0, info->GetBlocksInDeletedFiles()); TEST_EQUAL(1, info->GetBlocksInDirectories()); TEST_EQUAL(0, info->GetDeletedDirectories().size()); TEST_EQUAL(1000, info->GetBlocksSoftLimit()); TEST_EQUAL(2000, info->GetBlocksHardLimit()); TEST_EQUAL(0, info->GetNumCurrentFiles()); TEST_EQUAL(0, info->GetNumOldFiles()); TEST_EQUAL(0, info->GetNumDeletedFiles()); TEST_EQUAL(1, info->GetNumDirectories()); TEST_EQUAL(true, info->IsAccountEnabled()); TEST_EQUAL(true, info->IsReadOnly()); TEST_EQUAL(0, info->GetClientStoreMarker()); TEST_EQUAL("test", info->GetAccountName()); FileStream root_stream("testfiles/store/subdir/dirs/0x1.dir"); BackupStoreDirectory root_dir(root_stream); TEST_EQUAL(0, root_dir.GetNumberOfEntries()); TEARDOWN_TEST_S3SIMULATOR(); }
QString UmlArtifact::way(QString pro_dir, bool header) { QString dir; if (stereotype() != "source") { return stereotype() + " not yet managed"; } else if (header) { if (cppHeader().isEmpty()) return 0; dir = ((UmlPackage *) parent()->parent())->cppHDir(); } else { if (cppSource().isEmpty()) return 0; dir = ((UmlPackage *) parent()->parent())->cppSrcDir(); } if (QDir::isRelativePath(dir)) { QDir d(root_dir()); d.cd(dir); dir = d.absPath(); } if (dir.at(dir.length() - 1) != '/') dir += "/"; if (pro_dir.at(pro_dir.length() - 1) != '/') pro_dir += "/"; if (dir == pro_dir) return "./"; // bypass common path header unsigned index = 0; unsigned i; QString s; for (;;) { int i; if ((i = pro_dir.find("/", index) + 1) != 0) { if (pro_dir.left(i) == dir.left(i)) index = i; else if (dir.length() == index) { // pro_dir.left(index) == dir do s += "../"; while ((i = pro_dir.find("/", i) + 1) != 0); return s; } else break; } else // dir.left(index + 1) == pro_dir return dir.mid(index); } if (index == 0) // path fully different return dir; // dir.left(index) == pro_dir.left(index) // dir.mid(index) != pro_dir.mid(index) and they are not empty // dir.at(index - 1) == pro_dir.at(index - 1) == '/' i = index; while ((i = pro_dir.find("/", i) + 1) != 0) s += "../"; return s + dir.mid(index); }
void Application::set_root_dir(const QString & dirname) { QDir root_dir(dirname); //reset internal data model.clear(); clear(); QStringList dirlist = root_dir.entryList(QDir::Dirs|QDir::NoDotAndDotDot, QDir::Name); foreach (const QString & item, dirlist) { QDir dir(root_dir.filePath(item)); QStringList filters; filters << "*.jpg" << "*.bmp" << "*.png"; QStringList filelist = dir.entryList(filters, QDir::Files, QDir::Name); QString path = dir.path(); //setup the model int filecount = filelist.count(); if (filecount<1) { //no images, skip continue; } unsigned row = model.rowCount(); if (!model.insertRow(row)) { std::cout << "Failed model insert " << item.toStdString() << "("<< row << ")" << std::endl; continue; } //add the childrens QModelIndex parent = model.index(row, 0); model.setData(parent, item, Qt::DisplayRole); model.setData(parent, item, Qt::ToolTipRole); model.setData(parent, Qt::Checked, Qt::CheckStateRole); //read projector info int projector_width = 1024, projector_height = 768; //defaults compatible with old software QString projector_filename = dirname + "/" + item + "/projector_info.txt"; FILE * fp = fopen(qPrintable(projector_filename), "r"); if (fp) { //projector info file exists int width, height; if (fscanf(fp, "%u %u", &width, &height)==2 && width>0 && height) { //ok projector_width = width; projector_height = height; std::cerr << "Projector info file loaded: " << projector_filename.toStdString() << std::endl; } else { std::cerr << "Projector info file has invalid values" << std::endl; } fclose(fp); } else { std::cerr << "Projector info file failed to open: " << projector_filename.toStdString() << std::endl; } std::cerr << "Projector info file: using width=" << projector_width << " height=" << projector_height << std::endl; model.setData(parent, projector_width, ProjectorWidthRole); model.setData(parent, projector_height, ProjectorHeightRole); for (int i=0; i<filecount; i++) { const QString & filename = filelist.at(i); if (!model.insertRow(i, parent)) { std::cout << "Failed model insert " << filename.toStdString() << "("<< row << ")" << std::endl; break; } QModelIndex index = model.index(i, 0, parent); QString label = QString("#%1 %2").arg(i, 2, 10, QLatin1Char('0')).arg(filename); model.setData(index, label, Qt::DisplayRole); model.setData(index, label, Qt::ToolTipRole); //additional data model.setData(index, path + "/" + filename, ImageFilenameRole); } }
int main(int argc, char ** argv) { ::diagnostics::Logging_Config::init(); if(argc < 2){ usage(); return 1; } ::std::string root_dir(""); ::std::string _namespace(""); ::std::string include_prefix(""); ::std::string formula = (""); bool include_type = false; ::std::string bool_str("false"); ::std::string pos_nfa("Pos_Nfa"); ::std::string neg_nfa("Neg_Nfa"); ::std::string classname(""); while(argc > 1 && argv[1][0] == '-'){ switch(argv[1][1]){ case 'r': root_dir = argv[2]; --argc; ++argv; break; case 'n': _namespace = argv[2]; --argc; ++argv; break; case 'p': include_prefix = argv[2]; --argc; ++argv; break; case 'i': bool_str = argv[2]; --argc; ++argv; break; case 'c': classname = argv[2]; pos_nfa = ""; neg_nfa = ""; pos_nfa = "Pos_" + classname; neg_nfa = "Neg_" + classname; --argc; ++argv; break; case 'f': formula = argv[2]; --argc; ++argv; break; default: usage(); break; } --argc; ++argv; } if(formula == ""){ ::std::cout << "You must specify a formula! Exiting..." << ::std::endl; return 1; } if(bool_str == "true") include_type = true; typedef ::ltl2fsm::Graphviz_Representation Representation_t; typedef ::ltl2fsm::Ltl_To_Nfa_Pair_Module<Representation_t> Ltl_To_Nfa_Pair_Module_t; typedef ::ltl2fsm::Nfa_To_Cpp_Module<Representation_t> Nfa_To_Cpp_Module_t; Ltl_To_Nfa_Pair_Module_t ltl_to_nfa_pair_module; Ltl_To_Nfa_Pair_Module_t::Nfa_Pair_t nfa_pair; Nfa_To_Cpp_Module_t nfa_to_cpp_module; try{ nfa_pair = ltl_to_nfa_pair_module.execute(formula); } catch( ::ltl2fsm::Invalid_Ltl_Syntax const & ils){ ::std::cout << ils.what() << ::std::endl; return 1; } catch( ::ltl2fsm::Fork_Error const & fe ){ ::std::cout << fe.what() << ::std::endl; return 1; } if(root_dir != ""){ ::std::string root_dir_pos_nfa = root_dir + pos_nfa; ::std::ofstream pos_nfa_cpp((root_dir_pos_nfa + ".cpp").c_str()); ::std::ofstream pos_nfa_hpp((root_dir_pos_nfa + ".hpp").c_str()); nfa_to_cpp_module.execute(*nfa_pair.first, pos_nfa_cpp, pos_nfa_hpp, pos_nfa, _namespace, include_prefix, formula, include_type); ::std::string root_dir_neg_nfa = root_dir + neg_nfa; ::std::ofstream neg_nfa_cpp((root_dir_neg_nfa + ".cpp").c_str()); ::std::ofstream neg_nfa_hpp((root_dir_neg_nfa + ".hpp").c_str()); nfa_to_cpp_module.execute(*nfa_pair.second, neg_nfa_cpp, neg_nfa_hpp, neg_nfa, _namespace, include_prefix, ::std::string("!(" + formula + ")"), include_type); } else{ nfa_to_cpp_module.execute(*nfa_pair.first, ::std::cout, ::std::cout, pos_nfa, _namespace, include_prefix, formula, include_type); nfa_to_cpp_module.execute(*nfa_pair.second, ::std::cout, ::std::cout, neg_nfa, _namespace, include_prefix, ::std::string("!(" + formula + ")"), include_type); } return 0; }
//////////////////////////////////////////////////////////////////////////////// // taskd config --data <root> [<name> [<value>]] void command_config (Database& db, const std::vector <std::string>& args) { bool verbose = db._config->getBoolean ("verbose"); bool confirmation = db._config->getBoolean ("confirmation"); std::string name; std::string value; bool nonNull = false; std::vector <std::string>::const_iterator i; for (i = ++(args.begin ()); i != args.end (); ++i) { if (name == "") name = *i; else if (value == "") { nonNull = true; if (value != "") value += ' '; value += *i; } } std::string root = db._config->get ("root"); Directory root_dir (root); if (!root_dir.exists ()) throw std::string ("ERROR: The '--data' path does not exist."); // Load the config file. Config config; config.load (root_dir._data + "/config"); config.set ("root", root_dir._data); // taskd config <name> <value> // - set <name> to <value> if (name != "" && nonNull) { bool change = false; // Read .taskd/config std::vector <std::string> contents; File::read (config._original_file, contents); bool found = false; std::vector <std::string>::iterator line; for (line = contents.begin (); line != contents.end (); ++line) { // If there is a comment on the line, it must follow the pattern. std::string::size_type comment = line->find ("#"); std::string::size_type pos = line->find (name + "="); if (pos != std::string::npos && (comment == std::string::npos || comment > pos)) { found = true; if (!confirmation || confirm (format ("Are you sure you want to change the value of '{1}' from '{2}' to '{3}'?", name, config.get (name), value))) { if (comment != std::string::npos) *line = name + "=" + value + " " + line->substr (comment); else *line = name + "=" + value; change = true; } } } // Not found, so append instead. if (!found && (!confirmation || confirm (format ("Are you sure you want to add '{1}' with a value of '{2}'?", name, value)))) { contents.push_back (name + "=" + value); change = true; } // Write .taskd (or equivalent) if (change) { File::write (config._original_file, contents); if (verbose) std::cout << format ("Config file {1} modified.", config._original_file._data) << "\n"; } else { if (verbose) std::cout << "No changes made.\n"; } } // taskd config <name> // - remove <name> else if (name != "") { // Read .taskd/config std::vector <std::string> contents; File::read (config._original_file, contents); bool change = false; bool found = false; std::vector <std::string>::iterator line; for (line = contents.begin (); line != contents.end (); ++line) { // If there is a comment on the line, it must follow the pattern. std::string::size_type comment = line->find ("#"); std::string::size_type pos = line->find (name + "="); if (pos != std::string::npos && (comment == std::string::npos || comment > pos)) { found = true; // Remove name if (!confirmation || confirm (format ("Are you sure you want to remove '{1}'?", name))) { *line = ""; change = true; } } } if (!found) throw format ("ERROR: No entry named '{1}' found.", name); // Write .taskd (or equivalent) if (change) { if (! config._original_file.exists ()) config._original_file.create (0600); File::write (config._original_file, contents); if (verbose) std::cout << format ("Config file {1} modified.", config._original_file._data) << "\n"; } else { if (verbose) std::cout << "No changes made.\n"; } } // taskd config // - list all settings. else { if (verbose) std::cout << "\nConfiguration read from " << config._original_file._data << "\n\n"; taskd_renderMap (config, "Variable", "Value"); } }
void command_init (Database& db, const std::vector <std::string>& args) { // Verify that root exists. std::string root = db._config->get ("root"); if (root == "") throw std::string (STRING_INIT_DATA_REQUIRED); Directory root_dir (root); if (!root_dir.exists ()) throw std::string (STRING_INIT_PATH_MISSING); if (!root_dir.is_directory ()) throw std::string (STRING_INIT_PATH_NOT_DIR); if (!root_dir.readable ()) throw std::string (STRING_INIT_PATH_NOT_READ); if (!root_dir.writable ()) throw std::string (STRING_INIT_PATH_NOT_WRITE); if (!root_dir.executable ()) throw std::string (STRING_INIT_PATH_NOT_EXE); // Provide some defaults and overrides. db._config->set ("extensions", TASKD_EXTDIR); db._config->setIfBlank ("log", "/tmp/taskd.log"); db._config->setIfBlank ("queue.size", "10"); db._config->setIfBlank ("pid.file", "/tmp/taskd.pid"); db._config->setIfBlank ("ip.log", "on"); db._config->setIfBlank ("request.limit", "1048576"); db._config->setIfBlank ("confirmation", "1"); db._config->setIfBlank ("verbose", "1"); db._config->setIfBlank ("trust", "strict"); // Suggestions for missing items. if (db._config->get ("server") == "") std::cout << STRING_INIT_SERVER << "\n" << " taskd config server localhost:53589\n" << "\n"; // Create the data structure. Directory sub (root_dir); sub.cd (); sub += "orgs"; if (!sub.exists ()) if (!sub.create (0700)) throw format (STRING_INIT_COULD_NOT_CREATE, sub._data); // Dump the config file? db._config->_original_file = root_dir._data + "/config"; if (! db._config->_original_file.exists ()) db._config->_original_file.create (0600); if (db._config->dirty ()) { db._config->save (); if (db._config->getBoolean ("verbose")) std::cout << format (STRING_INIT_CREATED, db._config->_original_file) << "\n"; } }
int module_helper::_load_current_plugins_cfg(const char* cfg_file) { fsys::path p(cfg_file); pugi::xml_document doc; pugi::xml_parse_result pugi_res = doc.load_file(p.filename().c_str()); if (pugi_res.status == pugi::xml_parse_status::status_ok) { for (auto& x : doc.child("plugin_list")) { string proxy_name = x.attribute("name").as_string(); string dir = x.attribute("dir").as_string(); string prefix = x.attribute("prefix").as_string(); string filename = ""; string workpath = ""; boost_error_code ec; if (proxy_name != "" && prefix != "") { fsys::path p = fsys::current_path() / dir; fsys::directory_iterator search_dir(p, ec); if (!ec) { for (auto f : search_dir) { auto fn = f.path(); if (!fsys::is_directory(fn, ec) && fn.filename().string().find(prefix) != string::npos && fn.extension().string() == ".dll") { filename = fn.string(); workpath = fn.parent_path().string(); break; } } } if (filename == "") { fsys::path win_dir = string(getenv("windir")); fsys::path root_dir(win_dir.root_directory()); fsys::path media_api_dir = (root_dir / "ProgramData" / "Vistek" / "MediaClientPack"); if (fsys::exists(media_api_dir, ec) && fsys::is_directory(media_api_dir, ec)) { fsys::directory_iterator search_dir(p, ec); if (!ec) { for (auto f : search_dir) { auto fn = f.path(); if (!fsys::is_directory(fn, ec) && fn.filename().string().find(prefix) != string::npos && fn.extension().string() == ".dll") { filename = fn.string(); workpath = fn.parent_path().string(); break; } } } } } bool bLoaded = false; if (filename != "") { #ifdef _DEBUG #endif /*TCHAR cur_path[1024] = { 0 }; GetCurrentDirectory(1024, cur_path); fsys::path p(filename); string curr_path = p.parent_path().string(); SetCurrentDirectoryA(curr_path.c_str()); */ try { HMODULE tmp = LoadLibraryA(filename.c_str()); if (!tmp) { cout << GetLastError(); tmp = LoadLibraryExA(filename.c_str(), 0, LOAD_WITH_ALTERED_SEARCH_PATH); } if (tmp) { m_plugins_map.insert(proxy_name, tmp); bLoaded = true; } } catch (exception *exp) { cout << "exception" << exp->what() << endl; } //SetCurrentDirectoryA((char*)cur_path); #ifdef _DEBUG //auto a = GetProcAddress(tmp, "register_device"); #endif } if (bLoaded) { cout << "plugin: " << proxy_name << " load ok; filename: " << filename << endl; } else { cout << "plugin: " << proxy_name << " load fail; filename: " << filename << endl; } } } return v_OK; } return v_ERR_Bad_XML; }