bool MainWindow::setupWorkDir() { QDir basedir(QDesktopServices::storageLocation(QDesktopServices::DataLocation)); /* The app data directory might not exist, so create it */ if (!basedir.mkpath(basedir.absolutePath())) { return false; } /* Filename generation uses date/time plus a unique number, if necessary */ int i; for (i = 0; i < 16; i++) { QString filename(QDateTime::currentDateTime().toString("yyyyMMdd_hhmm")); if (i > 0) { filename += QString("_%1").arg(i); } filename += ".wahjam"; if (basedir.mkdir(filename)) { client.SetWorkDir(basedir.filePath(filename).toUtf8().data()); return true; } } return false; }
/** * \brief Save an image in the directory, return the short name */ std::string ImageDirectory::save(astro::image::ImagePtr image) { debug(LOG_DEBUG, DEBUG_LOG, 0, "saving an image"); // create a temporary file name in the base directory char buffer[1024]; snprintf(buffer, sizeof(buffer), "%s/XXXXXXXX.fits", basedir().c_str()); int fd = mkstemps(buffer, 5); if (fd < 0) { std::string cause = stringprintf("cannot create a tmp " "image file: %s", strerror(errno)); debug(LOG_ERR, DEBUG_LOG, 0, "%s", cause.c_str()); throw std::runtime_error(cause); } unlink(buffer); close(fd); std::string fullname(buffer); // construct the filename std::string filename = basename(fullname); debug(LOG_DEBUG, DEBUG_LOG, 0, "image full name: %s, filename: %s", fullname.c_str(), filename.c_str()); // write the file ImageDirectory::write(image, filename); // return the filename debug(LOG_DEBUG, DEBUG_LOG, 0, "image short name: %s", filename.c_str()); return filename; }
void project_t::dump() const { fprintf(stderr, "PROJECT {\n"); fprintf(stderr, " NAME=\"%s\"\n", name()); fprintf(stderr, " DESCRIPTION=\"%s\"\n", description()); fprintf(stderr, " DEFAULT=\"%s\"\n", default_target()); fprintf(stderr, " BASEDIR=\"%s\"\n", basedir()); targets_->foreach(dump_one_target, 0); taglists_->foreach(dump_one_taglist, 0); filesets_->foreach(dump_one_fileset, 0); dump_properties(); fprintf(stderr, "}\n"); }
bool RegexSourceSink::StartAcquisition(QString dev) { QRegExp rx("(.+)/(.+)(\\..+)"); //somepath/somename.someextension int pos=0; pos=rx.indexIn(dev); dir=rx.cap(1); basename=rx.cap(2); extension=rx.cap(3); QRegExp rt("(\\d+$)"); // now look for digits in the basename pos=rt.indexIn(basename); basename.truncate(pos); // qDebug()<<dir<<basename<<rt.cap(1)<<extension; QString regexString=basename+"(\\d+)"+extension; // qDebug()<<"Will load files that match"<<regexString; QRegExp movieRegex(regexString); QDir basedir(dir); if (!basedir.exists()) qDebug()<<"Extracted dir does not exist"<<dir; QStringList filt; filt<<"*"+extension; basedir.setNameFilters(filt); QStringList files=basedir.entryList(); QMap<int, QString> map; for (int i=0;i<files.count();i++) { if (movieRegex.indexIn(files.at(i))!=-1) { int newnr=movieRegex.cap(1).toInt(); map.insert(newnr,files.at(i)); } } if (map.count()==0) { qDebug()<<"No matching files found"; return false; } // now sort along captured number goodFiles= new QStringList(map.values()); index=0; nFrames=goodFiles->count(); return true; }
int main(int argc, char *argv[]) { QApplication app(argc, argv); /* Workaround for Qt5 Windows builds that cannot find their default codec. * See http://qt-project.org/forums/viewthread/24896/P15/#121196 */ if (!QTextCodec::codecForLocale()) { QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); } /* These are used by QSettings persistent settings */ QCoreApplication::setOrganizationName(ORGNAME); QCoreApplication::setOrganizationDomain(ORGDOMAIN); QCoreApplication::setApplicationName(APPNAME); /* Instantiate QSettings now that application information has been set */ QSettings appSettings; settings = &appSettings; /* Set up log file */ if (settings->contains("app/logFile")) { logFilePath = settings->value("app/logFile").toString(); } else { QDir basedir(QStandardPaths::writableLocation(QStandardPaths::DataLocation)); /* The app data directory might not exist, so create it */ if (!basedir.mkpath(basedir.absolutePath())) { return false; } logFilePath = basedir.filePath("log.txt"); } logInit(logFilePath); /* Initialize PortAudio once for the whole application */ if (!portAudioInit()) { QMessageBox::critical(NULL, QObject::tr("Unable to initialize PortAudio"), QObject::tr("Audio could not be initialized, " "please report this bug.")); return 1; } portMidiInit(); /* ignore errors since this is not critical */ MainWindow mainWindow; mainWindow.show(); return app.exec(); }
/* * Create a bareos-fd director resource file * that corresponds to our client definition. */ static inline bool configure_create_fd_resource(UAContext *ua, const char *clientname) { POOL_MEM resource(PM_MESSAGE); POOL_MEM filename_tmp(PM_FNAME); POOL_MEM filename(PM_FNAME); POOL_MEM basedir(PM_FNAME); POOL_MEM temp(PM_MESSAGE); const char *dirname = NULL; const bool error_if_exists = false; const bool create_directories = true; const bool overwrite = true; if (!configure_create_fd_resource_string(ua, resource, clientname)) { return false; } /* * Get the path where the resource should get stored. */ basedir.bsprintf("bareos-dir-export/client/%s/bareos-fd.d", clientname); dirname = GetNextRes(R_DIRECTOR, NULL)->name; if (!my_config->get_path_of_new_resource(filename, temp, basedir.c_str(), "director", dirname, error_if_exists, create_directories)) { ua->error_msg("%s", temp.c_str()); return false; } filename_tmp.strcpy(temp); /* * Write resource to file. */ if (!configure_write_resource(filename.c_str(), "filedaemon-export", clientname, resource.c_str(), overwrite)) { ua->error_msg("failed to write filedaemon config resource file\n"); return false; } ua->send->object_start("export"); ua->send->object_key_value("clientname", clientname); ua->send->object_key_value("component", "bareos-fd"); ua->send->object_key_value("resource", "director"); ua->send->object_key_value("name", dirname); ua->send->object_key_value("filename", filename.c_str(), "Exported resource file \"%s\":\n"); ua->send->object_key_value("content", resource.c_str(), "%s"); ua->send->object_end("export"); return true; }
bool RegexSourceSink::StartAcquisition(QString dev) { QRegExp rx("(.+)/(.+)(\\..+)"); int pos=0; pos=rx.indexIn(dev); dir=rx.cap(1); basename=rx.cap(2); extension=rx.cap(3); QRegExp rt("(\\d+$)"); pos=rt.indexIn(basename); basename.truncate(pos); // qDebug()<<dir<<basename<<rt.cap(1)<<extension; QString regexString=basename+"\\d+"+extension; // qDebug()<<"Will load files that match"<<regexString; QRegExp movieRegex(regexString); QDir basedir(dir); if (!basedir.exists()) qDebug()<<"Extracted dir does not exist"<<dir; QStringList filt; filt<<"*"+extension; basedir.setNameFilters(filt); QStringList files=basedir.entryList(); goodFiles=new QStringList; for (int i=0;i<files.count();i++) { if (movieRegex.indexIn(files.at(i))!=-1) { goodFiles->append(files.at(i)); } } if (goodFiles->count()==0) qDebug()<<"No matching files found"; index=0; nFrames=goodFiles->count(); return true; }
bool RegexSourceSink::RecordFrame(ImagePacket &source) { if (source.pixFormat=="BAYERRG8") { cv::Mat dummy(source.image.rows,source.image.cols,CV_8UC3); cv::cvtColor(source.image,dummy,CV_BayerRG2RGB); source.image=dummy; } else if (source.pixFormat=="BAYERGB8") { cv::Mat dummy(source.image.rows,source.image.cols,CV_8UC3); cv::cvtColor(source.image,dummy,CV_BayerGB2RGB); source.image=dummy; } else if (source.pixFormat=="BAYERRG12") { cv::Mat dummy(source.image.rows,source.image.cols,CV_16UC3); cv::cvtColor(source.image,dummy,CV_BayerRG2RGB); source.image=dummy; } else { source.image=source.image.clone(); // needed otherwise recording crashes when fps too high. } QString filenam=QString(dir+"/"+basename+"%1"+extension).arg(index,8,10,QLatin1Char('0')); #ifdef Q_OS_WIN32 if (cv::imwrite(filenam.toStdString().c_str(),source.image)) { #else if (cv::imwrite(filenam.toUtf8().data(),source.image)) { #endif index++; if (startTime==-1) { startTime=source.timeStamp; } timestamps.push_back((source.timeStamp-startTime)); return true; } return false; } bool RegexSourceSink::StartRecording(QString recFold, QString codec, int , int, int) { QDir basedir(recFold); if (basedir.exists()) { dir=recFold; basename="image-"; } else { QRegExp rx("(.+)/(.+)$"); //somepath/somename.someextension int pos=0; pos=rx.indexIn(recFold); if (pos>-1) { dir=rx.cap(1); basename=rx.cap(2); } else { qDebug()<<"Recording Folder does not exist"; dir=recFold; basename="image-"; } // qDebug()<<"recFold"<<dir<<" basename "<<basename; } extension=".png"; if (codec=="BMP") { extension=".bmp"; } else if (codec=="JPG") { extension=".jpg"; } index=0; timestamps.clear(); startTime=-1; return true; }
/** * \brief Build the full name from a */ std::string ImageDirectory::fullname(const std::string& filename) const { return basedir() + "/" + filename; }
/*f * Finds the basename of the given file. Spec1170 conformant. */ char * basename(char *arg) { return(basedir(arg, BASENAME)); }
/*f * Finds the dirname of the given file. Spec1170 conformant. */ char * dirname(char *arg) { return(basedir(arg, DIRNAME)); }
/** check configuration for errors */ static void morechecks(struct config_file* cfg, const char* fname) { warn_hosts("stub-host", cfg->stubs); warn_hosts("forward-host", cfg->forwards); interfacechecks(cfg); aclchecks(cfg); if(cfg->verbosity < 0) fatal_exit("verbosity value < 0"); if(cfg->num_threads <= 0 || cfg->num_threads > 10000) fatal_exit("num_threads value weird"); if(!cfg->do_ip4 && !cfg->do_ip6) fatal_exit("ip4 and ip6 are both disabled, pointless"); if(!cfg->do_udp && !cfg->do_tcp) fatal_exit("udp and tcp are both disabled, pointless"); if(cfg->edns_buffer_size > cfg->msg_buffer_size) fatal_exit("edns-buffer-size larger than msg-buffer-size, " "answers will not fit in processing buffer"); if(cfg->chrootdir && cfg->chrootdir[0] && cfg->chrootdir[strlen(cfg->chrootdir)-1] == '/') fatal_exit("chootdir %s has trailing slash '/' please remove.", cfg->chrootdir); if(cfg->chrootdir && cfg->chrootdir[0] && !is_dir(cfg->chrootdir)) { fatal_exit("bad chroot directory"); } if(cfg->chrootdir && cfg->chrootdir[0]) { char buf[10240]; buf[0] = 0; if(fname[0] != '/') { if(getcwd(buf, sizeof(buf)) == NULL) fatal_exit("getcwd: %s", strerror(errno)); strncat(buf, "/", sizeof(buf)-strlen(buf)-1); } strncat(buf, fname, sizeof(buf)-strlen(buf)-1); if(strncmp(buf, cfg->chrootdir, strlen(cfg->chrootdir)) != 0) fatal_exit("config file %s is not inside chroot %s", buf, cfg->chrootdir); } if(cfg->directory && cfg->directory[0]) { char* ad = fname_after_chroot(cfg->directory, cfg, 0); if(!ad) fatal_exit("out of memory"); if(!is_dir(ad)) fatal_exit("bad chdir directory"); free(ad); } if( (cfg->chrootdir && cfg->chrootdir[0]) || (cfg->directory && cfg->directory[0])) { if(cfg->pidfile && cfg->pidfile[0]) { char* ad = (cfg->pidfile[0]=='/')?strdup(cfg->pidfile): fname_after_chroot(cfg->pidfile, cfg, 1); char* bd = basedir(ad); if(bd && !is_dir(bd)) fatal_exit("pidfile directory does not exist"); free(ad); } if(cfg->logfile && cfg->logfile[0]) { char* ad = fname_after_chroot(cfg->logfile, cfg, 1); char* bd = basedir(ad); if(bd && !is_dir(bd)) fatal_exit("logfile directory does not exist"); free(ad); } } check_chroot_filelist("file with root-hints", cfg->root_hints, cfg->chrootdir, cfg); check_chroot_filelist("trust-anchor-file", cfg->trust_anchor_file_list, cfg->chrootdir, cfg); check_chroot_filelist("auto-trust-anchor-file", cfg->auto_trust_anchor_file_list, cfg->chrootdir, cfg); check_chroot_filelist_wild("trusted-keys-file", cfg->trusted_keys_file_list, cfg->chrootdir, cfg); check_chroot_string("dlv-anchor-file", &cfg->dlv_anchor_file, cfg->chrootdir, cfg); /* remove chroot setting so that modules are not stripping pathnames*/ free(cfg->chrootdir); cfg->chrootdir = NULL; if(strcmp(cfg->module_conf, "iterator") != 0 && strcmp(cfg->module_conf, "validator iterator") != 0 #ifdef WITH_PYTHONMODULE && strcmp(cfg->module_conf, "python iterator") != 0 && strcmp(cfg->module_conf, "python validator iterator") != 0 && strcmp(cfg->module_conf, "validator python iterator") != 0 #endif ) { fatal_exit("module conf '%s' is not known to work", cfg->module_conf); } #ifdef HAVE_GETPWNAM if(cfg->username && cfg->username[0]) { if(getpwnam(cfg->username) == NULL) fatal_exit("user '%s' does not exist.", cfg->username); endpwent(); } #endif if(cfg->remote_control_enable) { check_chroot_string("server-key-file", &cfg->server_key_file, cfg->chrootdir, cfg); check_chroot_string("server-cert-file", &cfg->server_cert_file, cfg->chrootdir, cfg); if(!is_file(cfg->control_key_file)) fatal_exit("control-key-file: \"%s\" does not exist", cfg->control_key_file); if(!is_file(cfg->control_cert_file)) fatal_exit("control-cert-file: \"%s\" does not exist", cfg->control_cert_file); } localzonechecks(cfg); }