You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-22 15:06:45 +00:00
Lot of work in new importer, importing textures now works.
This commit is contained in:
@@ -34,8 +34,10 @@
|
||||
#include "os/file_access.h"
|
||||
#include "editor_node.h"
|
||||
#include "io/resource_saver.h"
|
||||
#include "io/resource_import.h"
|
||||
#include "editor_settings.h"
|
||||
#include "editor_resource_preview.h"
|
||||
#include "variant_parser.h"
|
||||
|
||||
EditorFileSystem *EditorFileSystem::singleton=NULL;
|
||||
|
||||
@@ -115,75 +117,13 @@ String EditorFileSystemDirectory::get_file_path(int p_idx) const {
|
||||
return "res://"+file;
|
||||
}
|
||||
|
||||
bool EditorFileSystemDirectory::get_file_meta(int p_idx) const {
|
||||
|
||||
ERR_FAIL_INDEX_V(p_idx,files.size(),"");
|
||||
return files[p_idx]->meta.enabled;
|
||||
}
|
||||
|
||||
Vector<String> EditorFileSystemDirectory::get_file_deps(int p_idx) const {
|
||||
|
||||
ERR_FAIL_INDEX_V(p_idx,files.size(),Vector<String>());
|
||||
return files[p_idx]->meta.deps;
|
||||
return files[p_idx]->deps;
|
||||
|
||||
}
|
||||
Vector<String> EditorFileSystemDirectory::get_missing_sources(int p_idx) const {
|
||||
|
||||
ERR_FAIL_INDEX_V(p_idx,files.size(),Vector<String>());
|
||||
Vector<String> missing;
|
||||
for(int i=0;i<files[p_idx]->meta.sources.size();i++) {
|
||||
if (files[p_idx]->meta.sources[i].missing)
|
||||
missing.push_back(files[p_idx]->meta.sources[i].path);
|
||||
}
|
||||
|
||||
return missing;
|
||||
|
||||
|
||||
}
|
||||
bool EditorFileSystemDirectory::is_missing_sources(int p_idx) const {
|
||||
|
||||
ERR_FAIL_INDEX_V(p_idx,files.size(),false);
|
||||
for(int i=0;i<files[p_idx]->meta.sources.size();i++) {
|
||||
if (files[p_idx]->meta.sources[i].missing)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool EditorFileSystemDirectory::have_sources_changed(int p_idx) const {
|
||||
|
||||
ERR_FAIL_INDEX_V(p_idx,files.size(),false);
|
||||
return files[p_idx]->meta.sources_changed;
|
||||
|
||||
}
|
||||
|
||||
int EditorFileSystemDirectory::get_source_count(int p_idx) const {
|
||||
|
||||
ERR_FAIL_INDEX_V(p_idx,files.size(),0);
|
||||
if (!files[p_idx]->meta.enabled)
|
||||
return 0;
|
||||
return files[p_idx]->meta.sources.size();
|
||||
}
|
||||
String EditorFileSystemDirectory::get_source_file(int p_idx,int p_source) const {
|
||||
|
||||
ERR_FAIL_INDEX_V(p_idx,files.size(),String());
|
||||
ERR_FAIL_INDEX_V(p_source,files[p_idx]->meta.sources.size(),String());
|
||||
if (!files[p_idx]->meta.enabled)
|
||||
return String();
|
||||
|
||||
return files[p_idx]->meta.sources[p_source].path;
|
||||
|
||||
}
|
||||
bool EditorFileSystemDirectory::is_source_file_missing(int p_idx,int p_source) const {
|
||||
|
||||
ERR_FAIL_INDEX_V(p_idx,files.size(),false);
|
||||
ERR_FAIL_INDEX_V(p_source,files[p_idx]->meta.sources.size(),false);
|
||||
if (!files[p_idx]->meta.enabled)
|
||||
return false;
|
||||
|
||||
return files[p_idx]->meta.sources[p_source].missing;
|
||||
}
|
||||
|
||||
|
||||
StringName EditorFileSystemDirectory::get_file_type(int p_idx) const {
|
||||
@@ -210,7 +150,6 @@ void EditorFileSystemDirectory::_bind_methods() {
|
||||
ClassDB::bind_method(_MD("get_file","idx"),&EditorFileSystemDirectory::get_file);
|
||||
ClassDB::bind_method(_MD("get_file_path","idx"),&EditorFileSystemDirectory::get_file_path);
|
||||
ClassDB::bind_method(_MD("get_file_type","idx"),&EditorFileSystemDirectory::get_file_type);
|
||||
ClassDB::bind_method(_MD("is_missing_sources","idx"),&EditorFileSystemDirectory::is_missing_sources);
|
||||
ClassDB::bind_method(_MD("get_name"),&EditorFileSystemDirectory::get_name);
|
||||
ClassDB::bind_method(_MD("get_path"),&EditorFileSystemDirectory::get_path);
|
||||
ClassDB::bind_method(_MD("get_parent:EditorFileSystemDirectory"),&EditorFileSystemDirectory::get_parent);
|
||||
@@ -244,42 +183,6 @@ EditorFileSystemDirectory::~EditorFileSystemDirectory() {
|
||||
|
||||
|
||||
|
||||
|
||||
EditorFileSystemDirectory::ImportMeta EditorFileSystem::_get_meta(const String& p_path) {
|
||||
|
||||
return EditorFileSystemDirectory::ImportMeta();
|
||||
#if 0
|
||||
Ref<ResourceImportMetadata> imd = ResourceLoader::load_import_metadata(p_path);
|
||||
EditorFileSystemDirectory::ImportMeta m;
|
||||
if (imd.is_null()) {
|
||||
m.enabled=false;
|
||||
m.sources_changed=false;
|
||||
} else {
|
||||
m.enabled=true;
|
||||
m.sources_changed=false;
|
||||
|
||||
for(int i=0;i<imd->get_source_count();i++) {
|
||||
EditorFileSystemDirectory::ImportMeta::Source s;
|
||||
s.path=imd->get_source_path(i);
|
||||
s.md5=imd->get_source_md5(i);
|
||||
s.modified_time=0;
|
||||
s.missing=false;
|
||||
m.sources.push_back(s);
|
||||
}
|
||||
m.import_editor=imd->get_editor();
|
||||
}
|
||||
|
||||
List<String> deps;
|
||||
ResourceLoader::get_dependencies(p_path,&deps);
|
||||
for(List<String>::Element *E=deps.front();E;E=E->next()) {
|
||||
m.deps.push_back(E->get());
|
||||
}
|
||||
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void EditorFileSystem::_scan_filesystem() {
|
||||
|
||||
ERR_FAIL_COND(!scanning || new_filesystem);
|
||||
@@ -292,7 +195,7 @@ void EditorFileSystem::_scan_filesystem() {
|
||||
|
||||
String project=GlobalConfig::get_singleton()->get_resource_path();
|
||||
|
||||
String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_cache");
|
||||
String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_cache2");
|
||||
FileAccess *f =FileAccess::open(fscache,FileAccess::READ);
|
||||
|
||||
if (f) {
|
||||
@@ -322,30 +225,14 @@ void EditorFileSystem::_scan_filesystem() {
|
||||
FileCache fc;
|
||||
fc.type=split[1];
|
||||
fc.modification_time=split[2].to_int64();
|
||||
String meta = split[3].strip_edges();
|
||||
fc.meta.enabled=false;
|
||||
if (meta.find("<>")!=-1){
|
||||
Vector<String> spl = meta.split("<>");
|
||||
int sc = spl.size()-1;
|
||||
if (sc%3==0){
|
||||
fc.meta.enabled=true;
|
||||
fc.meta.import_editor=spl[0];
|
||||
fc.meta.sources.resize(sc/3);
|
||||
for(int i=0;i<fc.meta.sources.size();i++) {
|
||||
fc.meta.sources[i].path=spl[1+i*3+0];
|
||||
fc.meta.sources[i].md5=spl[1+i*3+1];
|
||||
fc.meta.sources[i].modified_time=spl[1+i*3+2].to_int64();
|
||||
}
|
||||
fc.import_modification_time = split[3].to_int64();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
String deps = split[4].strip_edges();
|
||||
if (deps.length()) {
|
||||
Vector<String> dp = deps.split("<>");
|
||||
for(int i=0;i<dp.size();i++) {
|
||||
String path=dp[i];
|
||||
fc.meta.deps.push_back(path);
|
||||
fc.deps.push_back(path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,7 +280,14 @@ void EditorFileSystem::_scan_filesystem() {
|
||||
|
||||
}
|
||||
|
||||
void EditorFileSystem::_save_filesystem_cache() {
|
||||
String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_cache2");
|
||||
|
||||
FileAccess *f=FileAccess::open(fscache,FileAccess::WRITE);
|
||||
_save_filesystem_cache(filesystem,f);
|
||||
f->close();
|
||||
memdelete(f);
|
||||
}
|
||||
|
||||
void EditorFileSystem::_thread_func(void *_userdata) {
|
||||
|
||||
@@ -408,6 +302,8 @@ bool EditorFileSystem::_update_scan_actions() {
|
||||
|
||||
bool fs_changed=false;
|
||||
|
||||
Vector<String> reimports;
|
||||
|
||||
for (List<ItemAction>::Element *E=scan_actions.front();E;E=E->next()) {
|
||||
|
||||
ItemAction&ia = E->get();
|
||||
@@ -472,18 +368,25 @@ bool EditorFileSystem::_update_scan_actions() {
|
||||
//print_line("*ACTION REMOVE FILE: "+ia.file);
|
||||
|
||||
} break;
|
||||
case ItemAction::ACTION_FILE_SOURCES_CHANGED: {
|
||||
case ItemAction::ACTION_FILE_REIMPORT: {
|
||||
|
||||
|
||||
int idx = ia.dir->find_file_index(ia.file);
|
||||
ERR_CONTINUE(idx==-1);
|
||||
String full_path = ia.dir->get_file_path(idx);
|
||||
sources_changed.push_back(full_path);
|
||||
reimports.push_back(full_path);
|
||||
|
||||
fs_changed=true;
|
||||
} break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (reimports.size()) {
|
||||
reimport_files(reimports);
|
||||
|
||||
}
|
||||
scan_actions.clear();
|
||||
|
||||
return fs_changed;
|
||||
@@ -495,9 +398,10 @@ void EditorFileSystem::scan() {
|
||||
if (false /*&& bool(Globals::get_singleton()->get("debug/disable_scan"))*/)
|
||||
return;
|
||||
|
||||
if (scanning || scanning_sources|| thread)
|
||||
if (scanning || scanning_changes|| thread)
|
||||
return;
|
||||
|
||||
_update_extensions();
|
||||
|
||||
abort_scan=false;
|
||||
if (!use_threads) {
|
||||
@@ -532,43 +436,6 @@ void EditorFileSystem::scan() {
|
||||
|
||||
}
|
||||
|
||||
bool EditorFileSystem::_check_meta_sources(EditorFileSystemDirectory::ImportMeta & p_meta) {
|
||||
|
||||
if (p_meta.enabled) {
|
||||
|
||||
for(int j=0;j<p_meta.sources.size();j++) {
|
||||
|
||||
#if 0
|
||||
String src = EditorImportPlugin::expand_source_path(p_meta.sources[j].path);
|
||||
|
||||
if (!FileAccess::exists(src)) {
|
||||
p_meta.sources[j].missing=true;
|
||||
continue;
|
||||
}
|
||||
|
||||
p_meta.sources[j].missing=false;
|
||||
|
||||
uint64_t mt = FileAccess::get_modified_time(src);
|
||||
|
||||
if (mt!=p_meta.sources[j].modified_time) {
|
||||
//scan
|
||||
String md5 = FileAccess::get_md5(src);
|
||||
//print_line("checking: "+src);
|
||||
//print_line("md5: "+md5);
|
||||
//print_line("vs: "+p_meta.sources[j].md5);
|
||||
if (md5!=p_meta.sources[j].md5) {
|
||||
//really changed
|
||||
return true;
|
||||
}
|
||||
p_meta.sources[j].modified_time=mt;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void EditorFileSystem::ScanProgress::update(int p_current,int p_total) const {
|
||||
|
||||
float ratio = low + ((hi-low)/p_total)*p_current;
|
||||
@@ -586,8 +453,6 @@ EditorFileSystem::ScanProgress EditorFileSystem::ScanProgress::get_sub(int p_cur
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir,DirAccess *da,const ScanProgress& p_progress) {
|
||||
|
||||
List<String> dirs;
|
||||
@@ -675,9 +540,11 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir,DirAccess
|
||||
|
||||
for (List<String>::Element*E=files.front();E;E=E->next(),idx++) {
|
||||
|
||||
|
||||
String ext = E->get().get_extension().to_lower();
|
||||
if (!valid_extensions.has(ext))
|
||||
if (!valid_extensions.has(ext)) {
|
||||
continue; //invalid
|
||||
}
|
||||
|
||||
EditorFileSystemDirectory::FileInfo *fi = memnew( EditorFileSystemDirectory::FileInfo );
|
||||
fi->file=E->get();
|
||||
@@ -687,32 +554,45 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir,DirAccess
|
||||
FileCache *fc = file_cache.getptr(path);
|
||||
uint64_t mt = FileAccess::get_modified_time(path);
|
||||
|
||||
if (fc && fc->modification_time == mt) {
|
||||
if (import_extensions.has(ext)) {
|
||||
|
||||
fi->meta=fc->meta;
|
||||
fi->type=fc->type;
|
||||
fi->modified_time=fc->modification_time;
|
||||
} else {
|
||||
fi->meta=_get_meta(path);
|
||||
fi->type=ResourceLoader::get_resource_type(path);
|
||||
fi->modified_time=mt;
|
||||
//is imported
|
||||
uint64_t import_mt=0;
|
||||
if (FileAccess::exists(path+".import")) {
|
||||
import_mt=FileAccess::get_modified_time(path+".import");
|
||||
}
|
||||
|
||||
}
|
||||
if (fc && fc->modification_time==mt && fc->import_modification_time==import_mt) {
|
||||
|
||||
fi->type=fc->type;
|
||||
fi->modified_time=fc->modification_time;
|
||||
fi->import_modified_time=fc->import_modification_time;
|
||||
|
||||
} else {
|
||||
|
||||
print_line("REIMPORT BECAUSE: time changed");
|
||||
fi->type=ResourceFormatImporter::get_singleton()->get_resource_type(path);
|
||||
fi->modified_time=0;
|
||||
fi->import_modified_time=0;
|
||||
|
||||
if (fi->meta.enabled) {
|
||||
if (_check_meta_sources(fi->meta)) {
|
||||
ItemAction ia;
|
||||
ia.action=ItemAction::ACTION_FILE_SOURCES_CHANGED;
|
||||
ia.action=ItemAction::ACTION_FILE_REIMPORT;
|
||||
ia.dir=p_dir;
|
||||
ia.file=E->get();
|
||||
scan_actions.push_back(ia);
|
||||
fi->meta.sources_changed=true;
|
||||
} else {
|
||||
fi->meta.sources_changed=false;
|
||||
}
|
||||
|
||||
} else {
|
||||
fi->meta.sources_changed=true;
|
||||
//not imported, so just update type if changed
|
||||
if (fc && fc->modification_time == mt) {
|
||||
|
||||
fi->type=fc->type;
|
||||
fi->modified_time=fc->modification_time;
|
||||
fi->import_modified_time=0;
|
||||
} else {
|
||||
fi->type=ResourceLoader::get_resource_type(path);
|
||||
fi->modified_time=mt;
|
||||
fi->import_modified_time=0;
|
||||
}
|
||||
}
|
||||
|
||||
p_dir->files.push_back(fi);
|
||||
@@ -722,11 +602,13 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir,DirAccess
|
||||
}
|
||||
|
||||
|
||||
|
||||
void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir,const ScanProgress& p_progress) {
|
||||
|
||||
uint64_t current_mtime = FileAccess::get_modified_time(p_dir->get_path());
|
||||
|
||||
bool updated_dir=false;
|
||||
String cd = p_dir->get_path();
|
||||
|
||||
//print_line("dir: "+p_dir->get_path()+" MODTIME: "+itos(p_dir->modified_time)+" CTIME: "+itos(current_mtime));
|
||||
|
||||
@@ -751,7 +633,7 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir,const S
|
||||
//then scan files and directories and check what's different
|
||||
|
||||
DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
||||
String cd = p_dir->get_path();
|
||||
|
||||
da->change_dir(cd);
|
||||
da->list_dir_begin();
|
||||
while (true) {
|
||||
@@ -807,7 +689,7 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir,const S
|
||||
|
||||
String path = cd.plus_file(fi->file);
|
||||
fi->modified_time=FileAccess::get_modified_time(path);
|
||||
fi->meta=_get_meta(path);
|
||||
fi->import_modified_time=0;
|
||||
fi->type=ResourceLoader::get_resource_type(path);
|
||||
|
||||
{
|
||||
@@ -817,19 +699,18 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir,const S
|
||||
ia.file=f;
|
||||
ia.new_file=fi;
|
||||
scan_actions.push_back(ia);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//take the chance and scan sources
|
||||
if (_check_meta_sources(fi->meta)) {
|
||||
|
||||
if (import_extensions.has(ext)) {
|
||||
//if it can be imported, and it was added, it needs to be reimported
|
||||
print_line("REIMPORT: file was not found before, reimport");
|
||||
ItemAction ia;
|
||||
ia.action=ItemAction::ACTION_FILE_SOURCES_CHANGED;
|
||||
ia.action=ItemAction::ACTION_FILE_REIMPORT;
|
||||
ia.dir=p_dir;
|
||||
ia.file=f;
|
||||
scan_actions.push_back(ia);
|
||||
fi->meta.sources_changed=true;
|
||||
} else {
|
||||
fi->meta.sources_changed=false;
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -859,15 +740,39 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir,const S
|
||||
|
||||
}
|
||||
|
||||
if (_check_meta_sources(p_dir->files[i]->meta)) {
|
||||
ItemAction ia;
|
||||
ia.action=ItemAction::ACTION_FILE_SOURCES_CHANGED;
|
||||
ia.dir=p_dir;
|
||||
ia.file=p_dir->files[i]->file;
|
||||
scan_actions.push_back(ia);
|
||||
p_dir->files[i]->meta.sources_changed=true;
|
||||
} else {
|
||||
p_dir->files[i]->meta.sources_changed=false;
|
||||
if (import_extensions.has(p_dir->files[i]->file.get_extension().to_lower())) {
|
||||
//check here if file must be imported or not
|
||||
|
||||
String path = cd.plus_file(p_dir->files[i]->file);
|
||||
|
||||
uint64_t mt = FileAccess::get_modified_time(path);
|
||||
|
||||
bool reimport=false;
|
||||
|
||||
if (mt!=p_dir->files[i]->modified_time) {
|
||||
print_line("REIMPORT: modified time changed, reimport");
|
||||
reimport=true; //it was modified, must be reimported.
|
||||
} else if (!FileAccess::exists(path+".import")) {
|
||||
print_line("REIMPORT: no .import exists, reimport");
|
||||
reimport=true; //no .import file, obviously reimport
|
||||
} else {
|
||||
|
||||
uint64_t import_mt=FileAccess::get_modified_time(path+".import");
|
||||
if (import_mt!=p_dir->files[i]->import_modified_time) {
|
||||
print_line("REIMPORT: import modified changed, reimport");
|
||||
reimport=true;
|
||||
}
|
||||
}
|
||||
|
||||
if (reimport) {
|
||||
|
||||
ItemAction ia;
|
||||
ia.action=ItemAction::ACTION_FILE_REIMPORT;
|
||||
ia.dir=p_dir;
|
||||
ia.file=p_dir->files[i]->file;
|
||||
scan_actions.push_back(ia);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
EditorResourcePreview::get_singleton()->check_for_invalidation(p_dir->get_file_path(i));
|
||||
@@ -900,7 +805,7 @@ void EditorFileSystem::_thread_func_sources(void *_userdata) {
|
||||
sp.low=0;
|
||||
efs->_scan_fs_changes(efs->filesystem,sp);
|
||||
}
|
||||
efs->scanning_sources_done=true;
|
||||
efs->scanning_changes_done=true;
|
||||
}
|
||||
|
||||
void EditorFileSystem::get_changed_sources(List<String> *r_changed) {
|
||||
@@ -908,14 +813,15 @@ void EditorFileSystem::get_changed_sources(List<String> *r_changed) {
|
||||
*r_changed=sources_changed;
|
||||
}
|
||||
|
||||
void EditorFileSystem::scan_sources() {
|
||||
void EditorFileSystem::scan_changes() {
|
||||
|
||||
if (scanning || scanning_sources|| thread)
|
||||
if (scanning || scanning_changes|| thread)
|
||||
return;
|
||||
|
||||
_update_extensions();
|
||||
sources_changed.clear();
|
||||
scanning_sources=true;
|
||||
scanning_sources_done=false;
|
||||
scanning_changes=true;
|
||||
scanning_changes_done=false;
|
||||
|
||||
abort_scan=false;
|
||||
|
||||
@@ -931,8 +837,8 @@ void EditorFileSystem::scan_sources() {
|
||||
if (_update_scan_actions())
|
||||
emit_signal("filesystem_changed");
|
||||
}
|
||||
scanning_sources=false;
|
||||
scanning_sources_done=true;
|
||||
scanning_changes=false;
|
||||
scanning_changes_done=true;
|
||||
emit_signal("sources_changed",sources_changed.size()>0);
|
||||
} else {
|
||||
|
||||
@@ -987,11 +893,11 @@ void EditorFileSystem::_notification(int p_what) {
|
||||
|
||||
if (use_threads) {
|
||||
|
||||
if (scanning_sources) {
|
||||
if (scanning_changes) {
|
||||
|
||||
if (scanning_sources_done) {
|
||||
if (scanning_changes_done) {
|
||||
|
||||
scanning_sources=false;
|
||||
scanning_changes=false;
|
||||
|
||||
set_process(false);
|
||||
|
||||
@@ -1053,22 +959,13 @@ void EditorFileSystem::_save_filesystem_cache(EditorFileSystemDirectory*p_dir,Fi
|
||||
|
||||
for(int i=0;i<p_dir->files.size();i++) {
|
||||
|
||||
String s=p_dir->files[i]->file+"::"+p_dir->files[i]->type+"::"+String::num(p_dir->files[i]->modified_time)+"::";
|
||||
if (p_dir->files[i]->meta.enabled) {
|
||||
s+=p_dir->files[i]->meta.import_editor;
|
||||
for(int j=0;j<p_dir->files[i]->meta.sources.size();j++){
|
||||
s+="<>"+p_dir->files[i]->meta.sources[j].path;
|
||||
s+="<>"+p_dir->files[i]->meta.sources[j].md5;
|
||||
s+="<>"+String::num(p_dir->files[i]->meta.sources[j].modified_time);
|
||||
|
||||
}
|
||||
}
|
||||
String s=p_dir->files[i]->file+"::"+p_dir->files[i]->type+"::"+itos(p_dir->files[i]->modified_time)+"::"+itos(p_dir->files[i]->import_modified_time);
|
||||
s+="::";
|
||||
for(int j=0;j<p_dir->files[i]->meta.deps.size();j++) {
|
||||
for(int j=0;j<p_dir->files[i]->deps.size();j++) {
|
||||
|
||||
if (j>0)
|
||||
s+="<>";
|
||||
s+=p_dir->files[i]->meta.deps[j];
|
||||
s+=p_dir->files[i]->deps[j];
|
||||
}
|
||||
|
||||
p_file->store_line(s);
|
||||
@@ -1261,34 +1158,8 @@ void EditorFileSystem::_resource_saved(const String& p_path){
|
||||
|
||||
}
|
||||
|
||||
String EditorFileSystem::_find_first_from_source(EditorFileSystemDirectory* p_dir,const String &p_src) const {
|
||||
|
||||
for(int i=0;i<p_dir->files.size();i++) {
|
||||
for(int j=0;j<p_dir->files[i]->meta.sources.size();j++) {
|
||||
|
||||
if (p_dir->files[i]->meta.sources[j].path==p_src)
|
||||
return p_dir->get_file_path(i);
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=0;i<p_dir->subdirs.size();i++) {
|
||||
|
||||
String ret = _find_first_from_source(p_dir->subdirs[i],p_src);
|
||||
if (ret.length()>0)
|
||||
return ret;
|
||||
}
|
||||
|
||||
return String();
|
||||
}
|
||||
|
||||
|
||||
String EditorFileSystem::find_resource_from_source(const String& p_path) const {
|
||||
|
||||
|
||||
if (filesystem)
|
||||
return _find_first_from_source(filesystem,p_path);
|
||||
return String();
|
||||
}
|
||||
|
||||
void EditorFileSystem::update_file(const String& p_file) {
|
||||
|
||||
@@ -1339,7 +1210,7 @@ void EditorFileSystem::update_file(const String& p_file) {
|
||||
//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);
|
||||
fs->files[cpos]->import_modified_time=0;
|
||||
|
||||
EditorResourcePreview::get_singleton()->call_deferred("check_for_invalidation",p_file);
|
||||
call_deferred("emit_signal","filesystem_changed"); //update later
|
||||
@@ -1347,6 +1218,128 @@ void EditorFileSystem::update_file(const String& p_file) {
|
||||
}
|
||||
|
||||
|
||||
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")) {
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
Ref<ResourceImporter> importer;
|
||||
//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());
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
//finally, perform import!!
|
||||
String base_path = ResourceFormatImporter::get_singleton()->get_import_base_path(p_file);
|
||||
|
||||
List<String> import_variants;
|
||||
|
||||
Error err = importer->import(p_file,base_path,params,&import_variants);
|
||||
|
||||
ERR_EXPLAIN("Error importing: "+p_file);
|
||||
ERR_FAIL_COND(err!=OK);
|
||||
|
||||
//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()+"\"");
|
||||
f->store_line("type=\""+importer->get_resource_type()+"\"");
|
||||
|
||||
if (import_variants.size()) {
|
||||
//import with variants
|
||||
for(List<String>::Element *E=import_variants.front();E;E=E->next()) {
|
||||
|
||||
|
||||
f->store_line("path."+E->get()+"=\""+base_path.c_escape()+"."+E->get()+"."+importer->get_save_extension()+"\"");
|
||||
}
|
||||
} else {
|
||||
|
||||
f->store_line("path=\""+base_path+"."+importer->get_save_extension()+"\"");
|
||||
}
|
||||
|
||||
f->store_line("");
|
||||
f->store_line("[params]");
|
||||
f->store_line("");
|
||||
|
||||
//store options in provided order, to avoid file changing
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
void EditorFileSystem::reimport_files(const Vector<String>& p_files) {
|
||||
|
||||
|
||||
EditorProgress pr("reimport",TTR("(Re)Importing Assets"),p_files.size());
|
||||
for(int i=0;i<p_files.size();i++) {
|
||||
pr.step(p_files[i].get_file(),i);
|
||||
|
||||
_reimport_file(p_files[i]);
|
||||
}
|
||||
|
||||
_save_filesystem_cache();
|
||||
}
|
||||
|
||||
void EditorFileSystem::_bind_methods() {
|
||||
|
||||
@@ -1355,7 +1348,7 @@ void EditorFileSystem::_bind_methods() {
|
||||
ClassDB::bind_method(_MD("is_scanning"),&EditorFileSystem::is_scanning);
|
||||
ClassDB::bind_method(_MD("get_scanning_progress"),&EditorFileSystem::get_scanning_progress);
|
||||
ClassDB::bind_method(_MD("scan"),&EditorFileSystem::scan);
|
||||
ClassDB::bind_method(_MD("scan_sources"),&EditorFileSystem::scan_sources);
|
||||
ClassDB::bind_method(_MD("scan_sources"),&EditorFileSystem::scan_changes);
|
||||
ClassDB::bind_method(_MD("update_file","path"),&EditorFileSystem::update_file);
|
||||
ClassDB::bind_method(_MD("get_filesystem_path:EditorFileSystemDirectory","path"),&EditorFileSystem::get_filesystem_path);
|
||||
ClassDB::bind_method(_MD("get_file_type","path"),&EditorFileSystem::get_file_type);
|
||||
@@ -1365,7 +1358,25 @@ void EditorFileSystem::_bind_methods() {
|
||||
|
||||
}
|
||||
|
||||
void EditorFileSystem::_update_extensions() {
|
||||
|
||||
valid_extensions.clear();
|
||||
import_extensions.clear();
|
||||
|
||||
List<String> extensionsl;
|
||||
ResourceLoader::get_recognized_extensions_for_type("",&extensionsl);
|
||||
for(List<String>::Element *E = extensionsl.front();E;E=E->next()) {
|
||||
|
||||
valid_extensions.insert(E->get());
|
||||
}
|
||||
|
||||
extensionsl.clear();
|
||||
ResourceFormatImporter::get_singleton()->get_recognized_extensions(&extensionsl);
|
||||
for(List<String>::Element *E = extensionsl.front();E;E=E->next()) {
|
||||
|
||||
import_extensions.insert(E->get());
|
||||
}
|
||||
}
|
||||
|
||||
EditorFileSystem::EditorFileSystem() {
|
||||
|
||||
@@ -1379,16 +1390,14 @@ EditorFileSystem::EditorFileSystem() {
|
||||
thread_sources=NULL;
|
||||
new_filesystem=NULL;
|
||||
|
||||
scanning_sources=false;
|
||||
scanning_changes=false;
|
||||
ResourceSaver::set_save_callback(_resource_saved);
|
||||
|
||||
List<String> extensionsl;
|
||||
ResourceLoader::get_recognized_extensions_for_type("",&extensionsl);
|
||||
for(List<String>::Element *E = extensionsl.front();E;E=E->next()) {
|
||||
|
||||
valid_extensions.insert(E->get());
|
||||
DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
||||
if (da->change_dir("res://.import")!=OK) {
|
||||
da->make_dir("res://.import");
|
||||
}
|
||||
|
||||
memdelete(da);
|
||||
|
||||
scan_total=0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user