/*Try to cleanup the ouput directory if nothing to a sub-dir*/ void cleanup_output(f_state *s) { char dir_name[MAX_STRING_LENGTH]; DIR *temp; DIR *outputDir; struct dirent *entry; if ((outputDir = opendir(get_output_directory(s))) == NULL) { /*Error?*/ } while ((entry = readdir(outputDir))) { memset(dir_name, 0, MAX_STRING_LENGTH - 1); strcpy(dir_name, get_output_directory(s)); strcat(dir_name, "/"); strcat(dir_name, entry->d_name); temp = opendir(dir_name); if (temp != NULL) { if (is_empty_directory(temp)) { rmdir(dir_name); } } } }
int create_output_directory(f_state *s) { DIR *d; char dir_name[MAX_STRING_LENGTH]; memset(dir_name, 0, MAX_STRING_LENGTH - 1); if (s->time_stamp) { strcpy(dir_name, get_output_directory(s)); strcat(dir_name, "_"); strcat(dir_name, get_start_time(s)); clean_time_string(dir_name); set_output_directory(s, dir_name); } #ifdef DEBUG printf("Checking output directory %s\n", get_output_directory(s)); #endif if ((d = opendir(get_output_directory(s))) != NULL) { /* The directory exists already. It MUST be empty for us to continue */ if (!is_empty_directory(d)) { printf("ERROR: %s is not empty\n \tPlease specify another directory or run with -T.\n", get_output_directory(s)); exit(EXIT_FAILURE); } /* The directory exists and is empty. We're done! */ closedir(d); return FALSE; } /* The error value ENOENT means that either the directory doesn't exist, which is fine, or that the filename is zero-length, which is bad. All other errors are, of course, bad. */ if (errno != ENOENT) { print_error(s, get_output_directory(s), strerror(errno)); return TRUE; } if (strlen(get_output_directory(s)) == 0) { /* Careful! Calling print_error will try to display a filename that is zero characters! In theory this should never happen as our call to realpath should avoid this. But we'll play it safe. */ print_error(s, "(output_directory)", "Output directory name unknown"); return TRUE; } return (make_new_directory(s, get_output_directory(s))); }
detection_thread<T>:: detection_thread(configuration &conf_, mutex *om, const char *name_, const char *arg2_, bool sync, t_chans tc) : thread(om, name_, sync), conf(conf_), arg2(arg2_), frame(120, 160, 1), mutex_in(), mutex_out(), in_updated(false), out_updated(false), bavailable(false), bfed(false), frame_name(""), frame_id(0), outdir(""), total_saved(0), color_space(tc), silent(false), boot(conf), frame_skipped(false), frame_loaded(false), pdetect(NULL) { silent = conf.exists_true("silent"); outdir = get_output_directory(conf); mout << "Saving outputs to " << outdir << std::endl; }
/** * @brief This method creates a directory to store Track files, and reads * in ray tracing data for Tracks and segments from a Track file * if one exists. * @details This method is called by the TrackGenerator::generateTracks() * class method. If a Track file exists for this Geometry, number * of azimuthal angles, and track spacing, then this method will * import the ray tracing Track and segment data to fill the * appropriate data structures. */ void TrackGenerator::initializeTrackFileDirectory() { std::stringstream directory; struct stat buffer; std::stringstream test_filename; /** Create directory to store Track files with pre-generated ray tracing data * if the directory does not yet exist */ directory << get_output_directory() << "/tracks"; struct stat st; if (!stat(directory.str().c_str(), &st) == 0) mkdir(directory.str().c_str(), S_IRWXU); if (_geometry->getCmfd() != NULL){ test_filename << directory.str() << "/" << _num_azim*2.0 << "_angles_" << _spacing << "_cm_spacing_cmfd_" << _geometry->getCmfd()->getNumX() << "x" << _geometry->getCmfd()->getNumY() << ".data"; } else{ test_filename << directory.str() << "/" << _num_azim*2.0 << "_angles_" << _spacing << "_cm_spacing.data"; } _tracks_filename = test_filename.str(); /* Check to see if a Track file exists for this geometry, number of azimuthal * angles, and track spacing, and if so, import the ray tracing data */ if (!stat(_tracks_filename.c_str(), &buffer)) { if (readTracksFromFile()) { _use_input_file = true; _contains_tracks = true; } } }
/*Create file type sub dirs, can get tricky when multiple types use one extraction algorithm (OLE)*/ int create_sub_dirs(f_state *s) { int i = 0; int j = 0; char dir_name[MAX_STRING_LENGTH]; char ole_types[7][4] = { "ppt", "doc", "xls", "sdw", "mbd", "vis", "ole" }; char riff_types[2][4] = { "avi", "wav" }; char zip_types[8][5] = { "sxc", "sxw", "sxi", "sx", "jar","docx","pptx","xlsx" }; for (i = 0; i < s->num_builtin; i++) { memset(dir_name, 0, MAX_STRING_LENGTH - 1); strcpy(dir_name, get_output_directory(s)); strcat(dir_name, "/"); strcat(dir_name, search_spec[i].suffix); make_new_directory(s, dir_name); if (search_spec[i].type == OLE) { for (j = 0; j < 7; j++) { if (strstr(ole_types[j], search_spec[i].suffix)) continue; memset(dir_name, 0, MAX_STRING_LENGTH - 1); strcpy(dir_name, get_output_directory(s)); strcat(dir_name, "/"); strcat(dir_name, ole_types[j]); make_new_directory(s, dir_name); } } else if (get_mode(s, mode_write_all)) { for (j = 0; j < 7; j++) { if (strstr(search_spec[i].suffix, ole_types[j])) { for (j = 0; j < 7; j++) { if (strstr(ole_types[j], search_spec[i].suffix)) continue; memset(dir_name, 0, MAX_STRING_LENGTH - 1); strcpy(dir_name, get_output_directory(s)); strcat(dir_name, "/"); strcat(dir_name, ole_types[j]); make_new_directory(s, dir_name); } break; } } } if (search_spec[i].type == EXE) { memset(dir_name, 0, MAX_STRING_LENGTH - 1); strcpy(dir_name, get_output_directory(s)); strcat(dir_name, "/"); strcat(dir_name, "dll"); make_new_directory(s, dir_name); } if (search_spec[i].type == RIFF) { for (j = 0; j < 2; j++) { if (strstr(ole_types[j], search_spec[i].suffix)) continue; memset(dir_name, 0, MAX_STRING_LENGTH - 1); strcpy(dir_name, get_output_directory(s)); strcat(dir_name, "/"); strcat(dir_name, riff_types[j]); make_new_directory(s, dir_name); } } else if (get_mode(s, mode_write_all)) { for (j = 0; j < 2; j++) { if (strstr(search_spec[i].suffix, riff_types[j])) { for (j = 0; j < 2; j++) { if (strstr(ole_types[j], search_spec[i].suffix)) continue; memset(dir_name, 0, MAX_STRING_LENGTH - 1); strcpy(dir_name, get_output_directory(s)); strcat(dir_name, "/"); strcat(dir_name, riff_types[j]); make_new_directory(s, dir_name); } break; } } } if (search_spec[i].type == ZIP) { for (j = 0; j < 8; j++) { if (strstr(ole_types[j], search_spec[i].suffix)) continue; memset(dir_name, 0, MAX_STRING_LENGTH - 1); strcpy(dir_name, get_output_directory(s)); strcat(dir_name, "/"); strcat(dir_name, zip_types[j]); make_new_directory(s, dir_name); } } else if (get_mode(s, mode_write_all)) { for (j = 0; j < 8; j++) { if (strstr(search_spec[i].suffix, zip_types[j])) { for (j = 0; j < 5; j++) { if (strstr(ole_types[j], search_spec[i].suffix)) continue; memset(dir_name, 0, MAX_STRING_LENGTH - 1); strcpy(dir_name, get_output_directory(s)); strcat(dir_name, "/"); strcat(dir_name, zip_types[j]); make_new_directory(s, dir_name); } break; } } } } return TRUE; }