Target_Reader_Ptr Target_Reader::create_reader(const URI & target_source) { Filepath path = uri_to_filename(target_source); if (path != "") { if (boost::filesystem::is_directory(path)) { Filepath target_filepath = path / TARGET_FILENAME; if (boost::filesystem::is_regular(target_filepath)) { return Target_Reader_Ptr (new Target_File_Reader(target_filepath)); } } else if (boost::filesystem::extension(path) == ".target") { return Target_Reader_Ptr (new Target_File_Reader(path)); } } // No suitable reader found log_message("Target_Reader: No suitable reader for circuit_source: " + target_source, SEVERE_LEVEL); return Target_Reader_Ptr(); }
static void confirm_delete (void) { int playlist = aud_playlist_get_active (); int entry_count = aud_playlist_entry_count (playlist); for (int i = 0; i < entry_count; i ++) { if (! aud_playlist_entry_get_selected (playlist, i)) continue; char * uri = aud_playlist_entry_get_filename (playlist, i); char * filename = uri_to_filename (uri); if (filename) { if (aud_get_bool ("delete_files", "use_trash")) move_to_trash (filename); else really_delete (filename); str_unref (filename); } else { SPRINTF (error, _("Error deleting %s: not a local file."), uri); aud_interface_show_error (error); } str_unref (uri); } aud_playlist_delete_selected (playlist); }
void Mesh_File_Reader::load( Meshes & final_meshes, const Cell_Target & cells, const URI & circuit_source, bool load_vertices, bool load_triangles, bool load_mapping, bool load_triangle_strips) { Meshes meshes; boost::filesystem::path mvd_file = uri_to_filename(circuit_source); if (mvd_file == "" || boost::filesystem::extension(mvd_file) != ".mvd2") { throw_exception(Bad_Data_Source("Loading meshes: circuit_source '" + circuit_source + "' "), FATAL_LEVEL, __FILE__, __LINE__); } MVD_File_Parser mvd_parser(mvd_file); mvd_parser.parse_file(cells); for (Cell_Target::iterator cell_gid = cells.begin(); cell_gid != cells.end(); ++cell_gid) { MVD_Cell_Index index = mvd_parser.cell_index(*cell_gid); if (index == UNDEFINED_MVD_CELL_INDEX) { std::stringstream msg; msg << "Loading meshes: bad cell target, neuron gid " << *cell_gid << " not in mvd file '" << mvd_file << "'"; throw_exception(Bad_Data(msg.str()), FATAL_LEVEL, __FILE__, __LINE__); } const Label & label = mvd_parser.morphology_names()[index]; if (meshes.find(label) == meshes.end()) { insert_new_or_updated(label, final_meshes, meshes, load_vertices, load_triangles, load_triangle_strips, load_mapping); } } // Final insertion from local container to result for (Meshes::iterator i = meshes.begin(); i != meshes.end(); ++i) { // This insertion replaces old existing meshes with its updated // version also final_meshes.insert(i.label(), i.ptr()); } }
gchar * get_associated_image_file (const gchar * filename) { if (strncmp (filename, "file://", 7)) return NULL; gchar * unesc = uri_to_filename (filename); if (! unesc) return NULL; gchar * path = g_path_get_dirname (unesc); gchar * base = g_path_get_basename (unesc); gchar * image_file = fileinfo_recursive_get_image (path, base, 0); g_free (unesc); g_free (path); g_free (base); return image_file; }
static void * local_fopen (const char * uri, const char * mode) { bool_t update; mode_t mode_flag; int handle; update = (strchr (mode, '+') != NULL); switch (mode[0]) { case 'r': mode_flag = update ? O_RDWR : O_RDONLY; break; case 'w': mode_flag = (update ? O_RDWR : O_WRONLY) | O_CREAT | O_TRUNC; break; case 'a': mode_flag = (update ? O_RDWR : O_WRONLY) | O_CREAT | O_APPEND; break; default: return NULL; } #ifdef O_CLOEXEC mode_flag |= O_CLOEXEC; #endif #ifdef _WIN32 mode_flag |= O_BINARY; #endif char * filename = uri_to_filename (uri); if (! filename) return NULL; if (mode_flag & O_CREAT) #ifdef S_IRGRP handle = open (filename, mode_flag, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); #else handle = open (filename, mode_flag, S_IRUSR | S_IWUSR); #endif else
char * get_associated_image_file (const char * filename) { char * image_uri = NULL; char * local = uri_to_filename (filename); char * base = local ? last_path_element (local) : NULL; if (local && base) { char * include = get_str (NULL, "cover_name_include"); char * exclude = get_str (NULL, "cover_name_exclude"); SearchParams params = { .basename = base, .include = str_list_to_index (include, ", "), .exclude = str_list_to_index (exclude, ", ") }; str_unref (include); str_unref (exclude); SNCOPY (path, local, base - 1 - local); char * image_local = fileinfo_recursive_get_image (path, & params, 0); if (image_local) image_uri = filename_to_uri (image_local); str_unref (image_local); index_free_full (params.include, (IndexFreeFunc) str_unref); index_free_full (params.exclude, (IndexFreeFunc) str_unref); } str_unref (local); return image_uri; }
static bool_t playlist_save_pls (const char * filename, VFSFile * file, const char * title, Index * filenames, Index * tuples) { int entries = index_count (filenames); vfs_fprintf (file, "[playlist]\n"); vfs_fprintf (file, "NumberOfEntries=%d\n", entries); for (int count = 0; count < entries; count ++) { const char * filename = index_get (filenames, count); char * fn; if (! strncmp (filename, "file://", 7)) fn = uri_to_filename (filename); else fn = strdup (filename); vfs_fprintf (file, "File%d=%s\n", 1 + count, fn); free (fn); } return TRUE; }
void on_skin_view_drag_data_received(GtkWidget * widget, GdkDragContext * context, gint x, gint y, GtkSelectionData * selection_data, guint info, guint time, gpointer user_data) { const gchar * data = (const gchar *) gtk_selection_data_get_data (selection_data); g_return_if_fail (data); const gchar * end = strchr (data, '\r'); if (! end) end = strchr (data, '\n'); if (! end) end = data + strlen (data); gchar * path = g_strndup (data, end - data); if (strstr (path, "://")) { gchar * path2 = uri_to_filename (path); if (path2) { g_free (path); path = path2; } } if (file_is_archive(path)) { if (! active_skin_load (path)) return; skin_install_skin(path); if (skin_view) skin_view_update ((GtkTreeView *) skin_view); } }
void describe_song (const char * name, const Tuple * tuple, char * * _title, char * * _artist, char * * _album) { /* Common folder names to skip */ static const char * const skip[] = {"music"}; char * title = get_nonblank_field (tuple, FIELD_TITLE); char * artist = get_nonblank_field (tuple, FIELD_ARTIST); char * album = get_nonblank_field (tuple, FIELD_ALBUM); if (title && artist && album) { DONE: * _title = title; * _artist = artist; * _album = album; return; } if (! strncmp (name, "file:///", 8)) { char * filename = uri_to_filename (name); if (! filename) goto DONE; char * base, * first, * second; split_filename (skip_top_folders (filename), & base, & first, & second); if (! title) title = str_get (base); for (int i = 0; i < G_N_ELEMENTS (skip); i ++) { if (first && ! g_ascii_strcasecmp (first, skip[i])) first = NULL; if (second && ! g_ascii_strcasecmp (second, skip[i])) second = NULL; } if (first) { if (second && ! artist && ! album) { artist = str_get (second); album = str_get (first); } else if (! artist) artist = str_get (first); else if (! album) album = str_get (first); } free (filename); } else { char buf[strlen (name) + 1]; memcpy (buf, name, sizeof buf); if (! title) { title = str_get_decoded (stream_name (buf)); if (! title) title = str_get_decoded (buf); } else if (! artist) artist = str_get_decoded (stream_name (buf)); else if (! album) album = str_get_decoded (stream_name (buf)); } goto DONE; }
Compartment_Report_Binary_File_Reader::Compartment_Report_Binary_File_Reader (const Report_Specification & specs) : _sequence_start_frame(0), _frame_counter(0), _frame_skip(1.0f), _current_frame(UNDEFINED_FRAME_NUMBER) { static Report_Specialization_Register< Compartment_Report_Binary_File_Reader, float > register_float_buffer; namespace fs = boost::filesystem; Filepath path = uri_to_filename(specs.data_source()); Filepath filename; enum Binary_Type { Multi_Split, Unknown }; Binary_Type binary_type = Unknown; // Checking which type of file if (fs::is_directory(path)) { if (fs::exists((filename = path / (specs.label() + ".rep")))) { binary_type = Multi_Split; } else if (fs::exists((filename = path / (specs.label() + ".bbp")))) { binary_type = Multi_Split; } } else if (fs::exists(path)) { filename = path; if (fs::extension(path) == ".rep") { binary_type = Multi_Split; } else if (fs::extension(path) == ".bbp") { binary_type = Multi_Split; } } if (binary_type == Multi_Split) { _parser.open(filename.string()); } else { throw_exception(Bad_Data("Compartment_Binary_File_Report_Reader: " "no proper binary file for " + specs.data_source() + " found"), FATAL_LEVEL, __FILE__, __LINE__); } }
Compartment_Report_HDF5_File_Reader::Compartment_Report_HDF5_File_Reader (const Report_Specification & specs) : _path(uri_to_filename(specs.data_source())), _report_name(specs.label()), _sequence_start_frame(0), _frame_counter(0), _frame_skip(1.0), _current_framestamp(UNDEFINED_FRAME_NUMBER) { namespace fs = boost::filesystem; static Report_Specialization_Register< Compartment_Report_HDF5_File_Reader, float > register_float_buffer; // Finding a suitable cell name from which has a h5 inside the search path. bool h5_file_found = false; if (!fs::is_directory(_path)) { throw_exception( IO_Error("Compartment_Report_HDF5_File_Reader: data source " "is not a directory: " + specs.data_source()), FATAL_LEVEL, __FILE__, __LINE__); } fs::directory_iterator entry(_path), end_entry; Cell_GID cell_GID = UNDEFINED_CELL_GID; while (cell_GID == UNDEFINED_CELL_GID && entry != end_entry) { fs::path filename = entry->path(); std::string cell_name = fs::basename(filename); char * endptr; if (fs::is_regular(entry->status()) && fs::extension(filename) == ".h5" && // Checking if name matches a[0-9]+ pattern and storing the GID cell_name.size() > 1 && cell_name[0] == 'a' && (cell_GID = strtol(&cell_name[1], &endptr, 10)) > 0 && *endptr == '\0') h5_file_found = true; ++entry; } if (cell_GID == UNDEFINED_CELL_GID) { throw_exception( Bad_Data("Compartment_Report_HDF5_File_Reader: source path " "doesn't contain any valid .h5 file" + specs.data_source()), FATAL_LEVEL, __FILE__, __LINE__); } // Not catching any exception here H5ID file, dataset; open_data_set(cell_GID, "data", file, dataset); float start_time, end_time, delta_time; if (// Trying to read attributes !read_attribute("tstart", dataset, start_time) || !read_attribute("tstop", dataset, end_time) || !read_attribute("Dt", dataset, delta_time) || // And checking them start_time != specs.start_time() || end_time != specs.end_time() || delta_time != specs.timestep()) { /*! \todo Exception commented because the forward_skip is not taken into account in the HDF5. SL - 24.07.08 throw_exception( Bad_Data("Compartment_Report_HDF5_File_Reader: inconsistent" " report metadata found for '" + specs.label() + "' in path " + specs.data_source()), FATAL_LEVEL, __FILE__, __LINE__); */ } }