static int process_verify(struct file *file, char *pathname) { struct inode *inode = file->f_dentry->d_inode; struct FILE_SIG *fs ; int rc = 0; char digest[SHA_DIG_MAX]; struct fivm_path search_fp ={ NULL, 0} ; fivm_gettime("Enter process verication"); if (!fivm_initialized || !S_ISREG(inode->i_mode)) return 0; rc = _find_dir(file,pathname,&search_fp); if(rc != 0){ return 0 ; /*Nothing to do, Just go on */ } fivm_gettime("Find directory name "); fs = _find_file(search_fp.path); if(!fs){ derr("Can't find file %s in sha table\n", search_fp.path); goto out ; } if(fs->flag){ dprintk("Had verified\n"); goto out ; } fivm_gettime("Find file name "); memset(digest, 0 ,SHA_DIG_MAX); rc = fivm_calc_hash(file,digest); if(rc){ derr("fivm_calc_hash fail\n"); goto out ; } fivm_gettime("Calc file digest "); if(memcmp( digest, fs->sha, SHA_DIG_MAX)){ derr("Sha compare fail\n"); derr("Local calculate:\n"); print_hex_dump_bytes("", DUMP_PREFIX_NONE, digest, SHA_DIG_MAX) ; derr("Store value:\n"); print_hex_dump_bytes("", DUMP_PREFIX_NONE, fs->sha,SHA_DIG_MAX ) ; rc = -1; goto out ; } fs->flag =1 ; rc = 0; out: rel_fivm_path(&search_fp); return rc; }
void EditorFileSystem::update_file(const String& p_file) { EditorFileSystemDirectory *fs=NULL; int cpos=-1; if (!_find_file(p_file,&fs,cpos)) { if (!fs) return; } if (!FileAccess::exists(p_file)) { //was removed memdelete( fs->files[cpos] ); fs->files.remove(cpos); call_deferred("emit_signal","filesystem_changed"); //update later return; } String type = ResourceLoader::get_resource_type(p_file); if (cpos==-1) { int idx=0; for(int i=0;i<fs->files.size();i++) { if (p_file<fs->files[i]->file) break; idx++; } EditorFileSystemDirectory::FileInfo *fi = memnew( EditorFileSystemDirectory::FileInfo ); fi->file=p_file.get_file(); if (idx==fs->files.size()) { fs->files.push_back(fi); } else { fs->files.insert(idx,fi); } cpos=idx; } //print_line("UPDATING: "+p_file); fs->files[cpos]->type=type; fs->files[cpos]->modified_time=FileAccess::get_modified_time(p_file); fs->files[cpos]->meta=_get_meta(p_file); EditorResourcePreview::get_singleton()->call_deferred("check_for_invalidation",p_file); call_deferred("emit_signal","filesystem_changed"); //update later }
String EditorFileSystem::get_file_type(const String &p_file) const { EditorFileSystemDirectory *fs = NULL; int cpos = -1; if (!_find_file(p_file, &fs, cpos)) { return ""; } return fs->files[cpos]->type; }
EditorFileSystemDirectory *EditorFileSystem::find_file(const String &p_file, int *r_index) const { if (!filesystem || scanning) return NULL; EditorFileSystemDirectory *fs = NULL; int cpos = -1; if (!_find_file(p_file, &fs, cpos)) { return NULL; } if (r_index) *r_index = cpos; return fs; }
void EditorFileSystem::update_file(const String& p_file) { EditorFileSystemDirectory *fs=NULL; int cpos=-1; if (!_find_file(p_file,&fs,cpos)) { if (!fs) return; } String type = ResourceLoader::get_resource_type(p_file); if (cpos==-1) { int idx=0; for(int i=0;i<fs->files.size();i++) { if (p_file<fs->files[i].file) break; idx++; } EditorFileSystemDirectory::FileInfo fi; fi.file=p_file.get_file(); if (idx==fs->files.size()) { fs->files.push_back(fi); } else { fs->files.insert(idx,fi); } cpos=idx; } print_line("UPDATING: "+p_file); fs->files[cpos].type=type; fs->files[cpos].modified_time=FileAccess::get_modified_time(p_file); fs->files[cpos].meta=_get_meta(p_file); call_deferred("emit_signal","filesystem_changed"); //update later }
UDFFILE *udfread_file_open(udfread *udf, const char *path) { const struct udf_file_identifier *fi = NULL; struct file_entry *fe; UDFFILE *result; if (!udf || !udf->input || !path) { return NULL; } if (_find_file(udf, path, NULL, &fi) < 0) { return NULL; } if (fi->characteristic & CHAR_FLAG_DIR) { udf_log("error opening file %s (is directory)\n", path); return NULL; } fe = _read_file_entry(udf, &fi->icb); if (!fe) { udf_error("error reading file entry for %s\n", path); return NULL; } result = (UDFFILE *)calloc(1, sizeof(UDFFILE)); if (!result) { free_file_entry(&fe); return NULL; } result->udf = udf; result->fe = fe; return result; }
UDFDIR *udfread_opendir(udfread *udf, const char *path) { const struct udf_dir *dir = NULL; UDFDIR *result; if (!udf || !udf->input || !path) { return NULL; } if (_find_file(udf, path, &dir, NULL) < 0) { return NULL; } if (!dir) { return NULL; } result = (UDFDIR *)calloc(1, sizeof(UDFDIR)); if (result) { result->dir = dir; } return result; }
void EditorFileSystem::_reimport_file(const String &p_file) { print_line("REIMPORTING: " + p_file); EditorFileSystemDirectory *fs = NULL; int cpos = -1; bool found = _find_file(p_file, &fs, cpos); ERR_FAIL_COND(!found); //try to obtain existing params Map<StringName, Variant> params; String importer_name; if (FileAccess::exists(p_file + ".import")) { //use existing Ref<ConfigFile> cf; cf.instance(); Error err = cf->load(p_file + ".import"); if (err == OK) { List<String> sk; cf->get_section_keys("params", &sk); for (List<String>::Element *E = sk.front(); E; E = E->next()) { params[E->get()] = cf->get_value("params", E->get()); } importer_name = cf->get_value("remap", "importer"); } } else { late_added_files.insert(p_file); //imported files do not call update_file(), but just in case.. } Ref<ResourceImporter> importer; bool load_default = false; //find the importer if (importer_name != "") { importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(importer_name); } if (importer.is_null()) { //not found by name, find by extension importer = ResourceFormatImporter::get_singleton()->get_importer_by_extension(p_file.get_extension()); load_default = true; if (importer.is_null()) { ERR_PRINT("BUG: File queued for import, but can't be imported!"); ERR_FAIL(); } } //mix with default params, in case a parameter is missing List<ResourceImporter::ImportOption> opts; importer->get_import_options(&opts); for (List<ResourceImporter::ImportOption>::Element *E = opts.front(); E; E = E->next()) { if (!params.has(E->get().option.name)) { //this one is not present params[E->get().option.name] = E->get().default_value; } } if (load_default && ProjectSettings::get_singleton()->get("importer_defaults/" + importer->get_importer_name())) { //use defaults if exist Dictionary d = ProjectSettings::get_singleton()->get("importer_defaults/" + importer->get_importer_name()); List<Variant> v; d.get_key_list(&v); for (List<Variant>::Element *E = v.front(); E; E = E->next()) { params[E->get()] = d[E->get()]; } } //finally, perform import!! String base_path = ResourceFormatImporter::get_singleton()->get_import_base_path(p_file); List<String> import_variants; List<String> gen_files; Error err = importer->import(p_file, base_path, params, &import_variants, &gen_files); if (err != OK) { ERR_PRINTS("Error importing: " + p_file); } //as import is complete, save the .import file FileAccess *f = FileAccess::open(p_file + ".import", FileAccess::WRITE); ERR_FAIL_COND(!f); //write manually, as order matters ([remap] has to go first for performance). f->store_line("[remap]"); f->store_line(""); f->store_line("importer=\"" + importer->get_importer_name() + "\""); if (importer->get_resource_type() != "") { f->store_line("type=\"" + importer->get_resource_type() + "\""); } if (importer->get_save_extension() == "") { //no path } else if (import_variants.size()) { //import with variants for (List<String>::Element *E = import_variants.front(); E; E = E->next()) { String path = base_path.c_escape() + "." + E->get() + "." + importer->get_save_extension(); f->store_line("path." + E->get() + "=\"" + path + "\""); } } else { f->store_line("path=\"" + base_path + "." + importer->get_save_extension() + "\""); } f->store_line(""); if (gen_files.size()) { f->store_line("[gen]"); Array genf; for (List<String>::Element *E = gen_files.front(); E; E = E->next()) { genf.push_back(E->get()); } String value; VariantWriter::write_to_string(genf, value); f->store_line("files=" + value); f->store_line(""); } f->store_line("[params]"); f->store_line(""); //store options in provided order, to avoid file changing. Order is also important because first match is accepted first. for (List<ResourceImporter::ImportOption>::Element *E = opts.front(); E; E = E->next()) { String base = E->get().option.name; String value; VariantWriter::write_to_string(params[base], value); f->store_line(base + "=" + value); } f->close(); memdelete(f); //update modified times, to avoid reimport fs->files[cpos]->modified_time = FileAccess::get_modified_time(p_file); fs->files[cpos]->import_modified_time = FileAccess::get_modified_time(p_file + ".import"); fs->files[cpos]->deps = _get_dependencies(p_file); fs->files[cpos]->type = importer->get_resource_type(); //if file is currently up, maybe the source it was loaded from changed, so import math must be updated for it //to reload properly if (ResourceCache::has(p_file)) { Resource *r = ResourceCache::get(p_file); if (r->get_import_path() != String()) { String dst_path = ResourceFormatImporter::get_singleton()->get_internal_resource_path(p_file); r->set_import_path(dst_path); r->set_import_last_modified_time(0); } } }
void EditorFileSystem::update_file(const String &p_file) { EditorFileSystemDirectory *fs = NULL; int cpos = -1; if (!_find_file(p_file, &fs, cpos)) { if (!fs) return; } if (!FileAccess::exists(p_file)) { //was removed _delete_internal_files(p_file); memdelete(fs->files[cpos]); fs->files.remove(cpos); call_deferred("emit_signal", "filesystem_changed"); //update later return; } String type = ResourceLoader::get_resource_type(p_file); if (cpos == -1) { //the file did not exist, it was added late_added_files.insert(p_file); //remember that it was added. This mean it will be scanned and imported on editor restart int idx = 0; for (int i = 0; i < fs->files.size(); i++) { if (p_file < fs->files[i]->file) break; idx++; } EditorFileSystemDirectory::FileInfo *fi = memnew(EditorFileSystemDirectory::FileInfo); fi->file = p_file.get_file(); fi->import_modified_time = 0; if (idx == fs->files.size()) { fs->files.push_back(fi); } else { fs->files.insert(idx, fi); } cpos = idx; } else { //the file exists and it was updated, and was not added in this step. //this means we must force upon next restart to scan it again, to get proper type and dependencies late_update_files.insert(p_file); _save_late_updated_files(); //files need to be updated in the re-scan } //print_line("UPDATING: "+p_file); fs->files[cpos]->type = type; fs->files[cpos]->modified_time = FileAccess::get_modified_time(p_file); fs->files[cpos]->deps = _get_dependencies(p_file); //if (FileAccess::exists(p_file+".import")) { // fs->files[cpos]->import_modified_time=FileAccess::get_modified_time(p_file+".import"); //} EditorResourcePreview::get_singleton()->call_deferred("check_for_invalidation", p_file); call_deferred("emit_signal", "filesystem_changed"); //update later }