2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* editor_file_system.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:45:00 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "editor_file_system.h"
|
2017-03-18 23:36:26 +00:00
|
|
|
#include "editor_node.h"
|
|
|
|
#include "editor_resource_preview.h"
|
|
|
|
#include "editor_settings.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "globals.h"
|
|
|
|
#include "io/resource_loader.h"
|
|
|
|
#include "io/resource_saver.h"
|
2017-03-18 23:36:26 +00:00
|
|
|
#include "os/file_access.h"
|
|
|
|
#include "os/os.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorFileSystem *EditorFileSystem::singleton = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
void EditorFileSystemDirectory::sort_files() {
|
|
|
|
|
|
|
|
files.sort_custom<FileInfoSort>();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int EditorFileSystemDirectory::find_file_index(const String &p_file) const {
|
2016-01-05 13:36:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < files.size(); i++) {
|
|
|
|
if (files[i]->file == p_file)
|
2016-01-05 13:36:24 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
int EditorFileSystemDirectory::find_dir_index(const String &p_dir) const {
|
2016-01-05 13:36:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < subdirs.size(); i++) {
|
|
|
|
if (subdirs[i]->name == p_dir)
|
2016-01-05 13:36:24 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
int EditorFileSystemDirectory::get_subdir_count() const {
|
|
|
|
|
|
|
|
return subdirs.size();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorFileSystemDirectory *EditorFileSystemDirectory::get_subdir(int p_idx) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, subdirs.size(), NULL);
|
2014-02-10 01:10:30 +00:00
|
|
|
return subdirs[p_idx];
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int EditorFileSystemDirectory::get_file_count() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return files.size();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String EditorFileSystemDirectory::get_file(int p_idx) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, files.size(), "");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
return files[p_idx]->file;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String EditorFileSystemDirectory::get_path() const {
|
|
|
|
|
|
|
|
String p;
|
2017-03-18 23:36:26 +00:00
|
|
|
const EditorFileSystemDirectory *d = this;
|
|
|
|
while (d->parent) {
|
|
|
|
p = d->name + "/" + p;
|
|
|
|
d = d->parent;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return "res://" + p;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String EditorFileSystemDirectory::get_file_path(int p_idx) const {
|
|
|
|
|
|
|
|
String file = get_file(p_idx);
|
2017-03-18 23:36:26 +00:00
|
|
|
const EditorFileSystemDirectory *d = this;
|
|
|
|
while (d->parent) {
|
|
|
|
file = d->name + "/" + file;
|
|
|
|
d = d->parent;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return "res://" + file;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorFileSystemDirectory::get_file_meta(int p_idx) const {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, files.size(), "");
|
2016-01-05 13:36:24 +00:00
|
|
|
return files[p_idx]->meta.enabled;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2015-08-23 23:15:56 +00:00
|
|
|
Vector<String> EditorFileSystemDirectory::get_file_deps(int p_idx) const {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, files.size(), Vector<String>());
|
2016-01-05 13:36:24 +00:00
|
|
|
return files[p_idx]->meta.deps;
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector<String> EditorFileSystemDirectory::get_missing_sources(int p_idx) const {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, files.size(), Vector<String>());
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector<String> missing;
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < files[p_idx]->meta.sources.size(); i++) {
|
2016-01-05 13:36:24 +00:00
|
|
|
if (files[p_idx]->meta.sources[i].missing)
|
|
|
|
missing.push_back(files[p_idx]->meta.sources[i].path);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return missing;
|
|
|
|
}
|
|
|
|
bool EditorFileSystemDirectory::is_missing_sources(int p_idx) const {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, files.size(), false);
|
|
|
|
for (int i = 0; i < files[p_idx]->meta.sources.size(); i++) {
|
2016-01-05 13:36:24 +00:00
|
|
|
if (files[p_idx]->meta.sources[i].missing)
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-27 17:18:40 +00:00
|
|
|
bool EditorFileSystemDirectory::have_sources_changed(int p_idx) const {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, files.size(), false);
|
2016-05-27 17:18:40 +00:00
|
|
|
return files[p_idx]->meta.sources_changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
int EditorFileSystemDirectory::get_source_count(int p_idx) const {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, files.size(), 0);
|
2016-05-27 17:18:40 +00:00
|
|
|
if (!files[p_idx]->meta.enabled)
|
|
|
|
return 0;
|
2016-05-31 05:21:13 +00:00
|
|
|
return files[p_idx]->meta.sources.size();
|
2016-05-27 17:18:40 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
String EditorFileSystemDirectory::get_source_file(int p_idx, int p_source) const {
|
2016-05-27 17:18:40 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, files.size(), String());
|
|
|
|
ERR_FAIL_INDEX_V(p_source, files[p_idx]->meta.sources.size(), String());
|
2016-05-27 17:18:40 +00:00
|
|
|
if (!files[p_idx]->meta.enabled)
|
|
|
|
return String();
|
|
|
|
|
|
|
|
return files[p_idx]->meta.sources[p_source].path;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
bool EditorFileSystemDirectory::is_source_file_missing(int p_idx, int p_source) const {
|
2016-05-27 17:18:40 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, files.size(), false);
|
|
|
|
ERR_FAIL_INDEX_V(p_source, files[p_idx]->meta.sources.size(), false);
|
2016-05-27 17:18:40 +00:00
|
|
|
if (!files[p_idx]->meta.enabled)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return files[p_idx]->meta.sources[p_source].missing;
|
|
|
|
}
|
|
|
|
|
2015-08-23 23:15:56 +00:00
|
|
|
StringName EditorFileSystemDirectory::get_file_type(int p_idx) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, files.size(), "");
|
2016-01-05 13:36:24 +00:00
|
|
|
return files[p_idx]->type;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String EditorFileSystemDirectory::get_name() {
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorFileSystemDirectory *EditorFileSystemDirectory::get_parent() {
|
|
|
|
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileSystemDirectory::_bind_methods() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ObjectTypeDB::bind_method(_MD("get_subdir_count"), &EditorFileSystemDirectory::get_subdir_count);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_subdir", "idx"), &EditorFileSystemDirectory::get_subdir);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_file_count"), &EditorFileSystemDirectory::get_file_count);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_file", "idx"), &EditorFileSystemDirectory::get_file);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_file_path", "idx"), &EditorFileSystemDirectory::get_file_path);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_file_types", "idx"), &EditorFileSystemDirectory::get_file_type);
|
|
|
|
ObjectTypeDB::bind_method(_MD("is_missing_sources", "idx"), &EditorFileSystemDirectory::is_missing_sources);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_name"), &EditorFileSystemDirectory::get_name);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_parent"), &EditorFileSystemDirectory::get_parent);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EditorFileSystemDirectory::EditorFileSystemDirectory() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
modified_time = 0;
|
|
|
|
parent = NULL;
|
2017-06-16 20:32:46 +00:00
|
|
|
verified = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EditorFileSystemDirectory::~EditorFileSystemDirectory() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < files.size(); i++) {
|
2016-01-05 13:36:24 +00:00
|
|
|
|
|
|
|
memdelete(files[i]);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < subdirs.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
memdelete(subdirs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorFileSystemDirectory::ImportMeta EditorFileSystem::_get_meta(const String &p_path) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Ref<ResourceImportMetadata> imd = ResourceLoader::load_import_metadata(p_path);
|
|
|
|
EditorFileSystemDirectory::ImportMeta m;
|
|
|
|
if (imd.is_null()) {
|
2017-03-18 23:36:26 +00:00
|
|
|
m.enabled = false;
|
|
|
|
m.sources_changed = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
m.enabled = true;
|
|
|
|
m.sources_changed = false;
|
2016-05-27 17:18:40 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < imd->get_source_count(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
EditorFileSystemDirectory::ImportMeta::Source s;
|
2017-03-18 23:36:26 +00:00
|
|
|
s.path = imd->get_source_path(i);
|
|
|
|
s.md5 = imd->get_source_md5(i);
|
|
|
|
s.modified_time = 0;
|
|
|
|
s.missing = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
m.sources.push_back(s);
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
m.import_editor = imd->get_editor();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2015-08-23 23:15:56 +00:00
|
|
|
|
|
|
|
List<String> deps;
|
2017-03-18 23:36:26 +00:00
|
|
|
ResourceLoader::get_dependencies(p_path, &deps);
|
|
|
|
for (List<String>::Element *E = deps.front(); E; E = E->next()) {
|
2015-08-23 23:15:56 +00:00
|
|
|
m.deps.push_back(E->get());
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
void EditorFileSystem::_scan_filesystem() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
ERR_FAIL_COND(!scanning || new_filesystem);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//read .fscache
|
|
|
|
String cpath;
|
|
|
|
|
|
|
|
sources_changed.clear();
|
2016-01-05 13:36:24 +00:00
|
|
|
file_cache.clear();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String project = Globals::get_singleton()->get_resource_path();
|
2015-06-06 12:44:38 +00:00
|
|
|
|
2015-08-23 23:15:56 +00:00
|
|
|
String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_cache");
|
2017-03-18 23:36:26 +00:00
|
|
|
FileAccess *f = FileAccess::open(fscache, FileAccess::READ);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (f) {
|
|
|
|
//read the disk cache
|
2017-03-18 23:36:26 +00:00
|
|
|
while (!f->eof_reached()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String l = f->get_line().strip_edges();
|
2017-03-18 23:36:26 +00:00
|
|
|
if (l == String())
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (l.begins_with("::")) {
|
|
|
|
Vector<String> split = l.split("::");
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_CONTINUE(split.size() != 3);
|
2014-02-10 01:10:30 +00:00
|
|
|
String name = split[1];
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
cpath = name;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
Vector<String> split = l.split("::");
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_CONTINUE(split.size() != 5);
|
2014-02-10 01:10:30 +00:00
|
|
|
String name = split[0];
|
|
|
|
String file;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
file = name;
|
|
|
|
name = cpath.plus_file(name);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
FileCache fc;
|
2017-03-18 23:36:26 +00:00
|
|
|
fc.type = split[1];
|
|
|
|
fc.modification_time = split[2].to_int64();
|
2014-02-10 01:10:30 +00:00
|
|
|
String meta = split[3].strip_edges();
|
2017-03-18 23:36:26 +00:00
|
|
|
fc.meta.enabled = false;
|
|
|
|
if (meta.find("<>") != -1) {
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector<String> spl = meta.split("<>");
|
2017-03-18 23:36:26 +00:00
|
|
|
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();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-23 23:15:56 +00:00
|
|
|
String deps = split[4].strip_edges();
|
|
|
|
if (deps.length()) {
|
|
|
|
Vector<String> dp = deps.split("<>");
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < dp.size(); i++) {
|
|
|
|
String path = dp[i];
|
2015-08-23 23:15:56 +00:00
|
|
|
fc.meta.deps.push_back(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
file_cache[name] = fc;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
f->close();
|
|
|
|
memdelete(f);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorProgressBG scan_progress("efs", "ScanFS", 1000);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
ScanProgress sp;
|
2017-03-18 23:36:26 +00:00
|
|
|
sp.low = 0;
|
|
|
|
sp.hi = 1;
|
|
|
|
sp.progress = &scan_progress;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
new_filesystem = memnew(EditorFileSystemDirectory);
|
|
|
|
new_filesystem->parent = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
|
|
|
d->change_dir("res://");
|
2017-03-18 23:36:26 +00:00
|
|
|
_scan_new_dir(new_filesystem, d, sp);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
file_cache.clear(); //clear caches, no longer needed
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
memdelete(d);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//save back the findings
|
2017-03-18 23:36:26 +00:00
|
|
|
// String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("file_cache");
|
2015-06-06 12:44:38 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
f = FileAccess::open(fscache, FileAccess::WRITE);
|
|
|
|
_save_filesystem_cache(new_filesystem, f);
|
2014-02-10 01:10:30 +00:00
|
|
|
f->close();
|
|
|
|
memdelete(f);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
scanning = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileSystem::_thread_func(void *_userdata) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorFileSystem *sd = (EditorFileSystem *)_userdata;
|
2016-01-05 13:36:24 +00:00
|
|
|
sd->_scan_filesystem();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorFileSystem::_update_scan_actions() {
|
|
|
|
|
|
|
|
sources_changed.clear();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool fs_changed = false;
|
2016-01-05 13:36:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<ItemAction>::Element *E = scan_actions.front(); E; E = E->next()) {
|
2016-01-05 13:36:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ItemAction &ia = E->get();
|
2016-01-05 13:36:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (ia.action) {
|
2016-01-05 13:36:24 +00:00
|
|
|
case ItemAction::ACTION_NONE: {
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case ItemAction::ACTION_DIR_ADD: {
|
|
|
|
|
|
|
|
//print_line("*ACTION ADD DIR: "+ia.new_dir->get_name());
|
2017-03-18 23:36:26 +00:00
|
|
|
int idx = 0;
|
|
|
|
for (int i = 0; i < ia.dir->subdirs.size(); i++) {
|
2016-01-05 13:36:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ia.new_dir->name < ia.dir->subdirs[i]->name)
|
2016-01-05 13:36:24 +00:00
|
|
|
break;
|
|
|
|
idx++;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx == ia.dir->subdirs.size()) {
|
2016-01-05 13:36:24 +00:00
|
|
|
ia.dir->subdirs.push_back(ia.new_dir);
|
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
ia.dir->subdirs.insert(idx, ia.new_dir);
|
2016-01-05 13:36:24 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
fs_changed = true;
|
2016-01-05 13:36:24 +00:00
|
|
|
} break;
|
|
|
|
case ItemAction::ACTION_DIR_REMOVE: {
|
|
|
|
|
|
|
|
ERR_CONTINUE(!ia.dir->parent);
|
|
|
|
//print_line("*ACTION REMOVE DIR: "+ia.dir->get_name());
|
|
|
|
ia.dir->parent->subdirs.erase(ia.dir);
|
2017-03-18 23:36:26 +00:00
|
|
|
memdelete(ia.dir);
|
|
|
|
fs_changed = true;
|
2016-01-05 13:36:24 +00:00
|
|
|
} break;
|
|
|
|
case ItemAction::ACTION_FILE_ADD: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int idx = 0;
|
|
|
|
for (int i = 0; i < ia.dir->files.size(); i++) {
|
2016-01-05 13:36:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ia.new_file->file < ia.dir->files[i]->file)
|
2016-01-05 13:36:24 +00:00
|
|
|
break;
|
|
|
|
idx++;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx == ia.dir->files.size()) {
|
2016-01-05 13:36:24 +00:00
|
|
|
ia.dir->files.push_back(ia.new_file);
|
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
ia.dir->files.insert(idx, ia.new_file);
|
2016-01-05 13:36:24 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
fs_changed = true;
|
2016-01-05 13:36:24 +00:00
|
|
|
//print_line("*ACTION ADD FILE: "+ia.new_file->file);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case ItemAction::ACTION_FILE_REMOVE: {
|
|
|
|
|
|
|
|
int idx = ia.dir->find_file_index(ia.file);
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_CONTINUE(idx == -1);
|
|
|
|
memdelete(ia.dir->files[idx]);
|
2016-01-05 13:36:24 +00:00
|
|
|
ia.dir->files.remove(idx);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
fs_changed = true;
|
2016-01-05 13:36:24 +00:00
|
|
|
//print_line("*ACTION REMOVE FILE: "+ia.file);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case ItemAction::ACTION_FILE_SOURCES_CHANGED: {
|
|
|
|
|
|
|
|
int idx = ia.dir->find_file_index(ia.file);
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_CONTINUE(idx == -1);
|
2016-01-05 13:36:24 +00:00
|
|
|
String full_path = ia.dir->get_file_path(idx);
|
|
|
|
sources_changed.push_back(full_path);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
scan_actions.clear();
|
|
|
|
|
|
|
|
return fs_changed;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileSystem::scan() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (bool(Globals::get_singleton()->get("debug/disable_scan")))
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (scanning || scanning_sources || thread)
|
|
|
|
return;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
abort_scan = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!use_threads) {
|
2017-03-18 23:36:26 +00:00
|
|
|
scanning = true;
|
|
|
|
scan_total = 0;
|
2016-01-05 13:36:24 +00:00
|
|
|
_scan_filesystem();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (filesystem)
|
|
|
|
memdelete(filesystem);
|
2017-03-18 23:36:26 +00:00
|
|
|
// file_type_cache.clear();
|
|
|
|
filesystem = new_filesystem;
|
|
|
|
new_filesystem = NULL;
|
2016-01-05 13:36:24 +00:00
|
|
|
_update_scan_actions();
|
2017-03-18 23:36:26 +00:00
|
|
|
scanning = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
emit_signal("filesystem_changed");
|
2017-03-18 23:36:26 +00:00
|
|
|
emit_signal("sources_changed", sources_changed.size() > 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ERR_FAIL_COND(thread);
|
|
|
|
set_process(true);
|
|
|
|
Thread::Settings s;
|
2017-03-18 23:36:26 +00:00
|
|
|
scanning = true;
|
|
|
|
scan_total = 0;
|
|
|
|
s.priority = Thread::PRIORITY_LOW;
|
|
|
|
thread = Thread::create(_thread_func, this, s);
|
2014-02-10 01:10:30 +00:00
|
|
|
//tree->hide();
|
|
|
|
//progress->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool EditorFileSystem::_check_meta_sources(EditorFileSystemDirectory::ImportMeta &p_meta) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (p_meta.enabled) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int j = 0; j < p_meta.sources.size(); j++) {
|
2014-03-14 01:57:24 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String src = EditorImportPlugin::expand_source_path(p_meta.sources[j].path);
|
|
|
|
|
|
|
|
if (!FileAccess::exists(src)) {
|
2017-03-18 23:36:26 +00:00
|
|
|
p_meta.sources[j].missing = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_meta.sources[j].missing = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
uint64_t mt = FileAccess::get_modified_time(src);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (mt != p_meta.sources[j].modified_time) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scan
|
|
|
|
String md5 = FileAccess::get_md5(src);
|
2016-01-05 13:36:24 +00:00
|
|
|
//print_line("checking: "+src);
|
|
|
|
//print_line("md5: "+md5);
|
|
|
|
//print_line("vs: "+p_meta.sources[j].md5);
|
2017-03-18 23:36:26 +00:00
|
|
|
if (md5 != p_meta.sources[j].md5) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//really changed
|
|
|
|
return true;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
p_meta.sources[j].modified_time = mt;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void EditorFileSystem::ScanProgress::update(int p_current, int p_total) const {
|
2016-01-05 13:36:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
float ratio = low + ((hi - low) / p_total) * p_current;
|
|
|
|
progress->step(ratio * 1000);
|
|
|
|
EditorFileSystem::singleton->scan_total = ratio;
|
2016-01-05 13:36:24 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorFileSystem::ScanProgress EditorFileSystem::ScanProgress::get_sub(int p_current, int p_total) const {
|
2016-01-05 13:36:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ScanProgress sp = *this;
|
|
|
|
float slice = (sp.hi - sp.low) / p_total;
|
|
|
|
sp.low += slice * p_current;
|
|
|
|
sp.hi = slice;
|
2016-01-05 13:36:24 +00:00
|
|
|
return sp;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess *da, const ScanProgress &p_progress) {
|
2016-01-05 13:36:24 +00:00
|
|
|
|
|
|
|
List<String> dirs;
|
|
|
|
List<String> files;
|
|
|
|
|
|
|
|
String cd = da->get_current_dir();
|
|
|
|
|
|
|
|
p_dir->modified_time = FileAccess::get_modified_time(cd);
|
|
|
|
|
|
|
|
da->list_dir_begin();
|
|
|
|
while (true) {
|
|
|
|
|
|
|
|
bool isdir;
|
|
|
|
String f = da->get_next(&isdir);
|
2017-03-18 23:36:26 +00:00
|
|
|
if (f == "")
|
2016-01-05 13:36:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (isdir) {
|
|
|
|
|
|
|
|
if (f.begins_with(".")) //ignore hidden and . / ..
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (FileAccess::exists(cd.plus_file(f).plus_file("engine.cfg"))) // skip if another project inside this
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dirs.push_back(f);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
files.push_back(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
da->list_dir_end();
|
|
|
|
|
|
|
|
dirs.sort();
|
|
|
|
files.sort();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int total = dirs.size() + files.size();
|
|
|
|
int idx = 0;
|
2016-06-28 11:26:07 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<String>::Element *E = dirs.front(); E; E = E->next(), idx++) {
|
2016-01-05 13:36:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (da->change_dir(E->get()) == OK) {
|
2016-01-05 13:36:24 +00:00
|
|
|
|
2016-06-28 11:26:07 +00:00
|
|
|
String d = da->get_current_dir();
|
2016-01-05 13:36:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (d == cd || !d.begins_with(cd)) {
|
2016-06-28 11:26:07 +00:00
|
|
|
da->change_dir(cd); //avoid recursion
|
|
|
|
} else {
|
2016-01-05 13:36:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorFileSystemDirectory *efd = memnew(EditorFileSystemDirectory);
|
2016-01-05 13:36:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
efd->parent = p_dir;
|
|
|
|
efd->name = E->get();
|
2016-01-05 13:36:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_scan_new_dir(efd, da, p_progress.get_sub(idx, total));
|
2016-06-28 11:26:07 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int idx = 0;
|
|
|
|
for (int i = 0; i < p_dir->subdirs.size(); i++) {
|
2016-06-28 11:26:07 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (efd->name < p_dir->subdirs[i]->name)
|
2016-06-28 11:26:07 +00:00
|
|
|
break;
|
|
|
|
idx++;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx == p_dir->subdirs.size()) {
|
2016-06-28 11:26:07 +00:00
|
|
|
p_dir->subdirs.push_back(efd);
|
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
p_dir->subdirs.insert(idx, efd);
|
2016-06-28 11:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
da->change_dir("..");
|
|
|
|
}
|
2016-01-05 13:36:24 +00:00
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_PRINTS("Cannot go into subdir: " + E->get());
|
2016-01-05 13:36:24 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_progress.update(idx, total);
|
2016-01-05 13:36:24 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<String>::Element *E = files.front(); E; E = E->next(), idx++) {
|
2016-01-05 13:36:24 +00:00
|
|
|
|
|
|
|
String ext = E->get().extension().to_lower();
|
|
|
|
if (!valid_extensions.has(ext))
|
|
|
|
continue; //invalid
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorFileSystemDirectory::FileInfo *fi = memnew(EditorFileSystemDirectory::FileInfo);
|
|
|
|
fi->file = E->get();
|
2016-01-05 13:36:24 +00:00
|
|
|
|
|
|
|
String path = cd.plus_file(fi->file);
|
|
|
|
|
|
|
|
FileCache *fc = file_cache.getptr(path);
|
|
|
|
uint64_t mt = FileAccess::get_modified_time(path);
|
|
|
|
|
|
|
|
if (fc && fc->modification_time == mt) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
fi->meta = fc->meta;
|
|
|
|
fi->type = fc->type;
|
|
|
|
fi->modified_time = fc->modification_time;
|
2016-01-05 13:36:24 +00:00
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
fi->meta = _get_meta(path);
|
|
|
|
fi->type = ResourceLoader::get_resource_type(path);
|
|
|
|
fi->modified_time = mt;
|
2016-01-05 13:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fi->meta.enabled) {
|
|
|
|
if (_check_meta_sources(fi->meta)) {
|
|
|
|
ItemAction ia;
|
2017-03-18 23:36:26 +00:00
|
|
|
ia.action = ItemAction::ACTION_FILE_SOURCES_CHANGED;
|
|
|
|
ia.dir = p_dir;
|
|
|
|
ia.file = E->get();
|
2016-01-05 13:36:24 +00:00
|
|
|
scan_actions.push_back(ia);
|
2017-03-18 23:36:26 +00:00
|
|
|
fi->meta.sources_changed = true;
|
2016-05-27 17:18:40 +00:00
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
fi->meta.sources_changed = false;
|
2016-01-05 13:36:24 +00:00
|
|
|
}
|
2016-05-27 17:18:40 +00:00
|
|
|
|
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
fi->meta.sources_changed = true;
|
2016-01-05 13:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p_dir->files.push_back(fi);
|
2017-03-18 23:36:26 +00:00
|
|
|
p_progress.update(idx, total);
|
2016-01-05 13:36:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const ScanProgress &p_progress) {
|
2016-01-05 13:36:24 +00:00
|
|
|
|
|
|
|
uint64_t current_mtime = FileAccess::get_modified_time(p_dir->get_path());
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool updated_dir = false;
|
2016-01-05 13:36:24 +00:00
|
|
|
|
|
|
|
//print_line("dir: "+p_dir->get_path()+" MODTIME: "+itos(p_dir->modified_time)+" CTIME: "+itos(current_mtime));
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (current_mtime != p_dir->modified_time) {
|
2016-01-05 13:36:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
updated_dir = true;
|
|
|
|
p_dir->modified_time = current_mtime;
|
2016-01-05 13:36:24 +00:00
|
|
|
//ooooops, dir changed, see what's going on
|
|
|
|
|
|
|
|
//first mark everything as veryfied
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < p_dir->files.size(); i++) {
|
2016-01-05 13:36:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_dir->files[i]->verified = false;
|
2016-01-05 13:36:24 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < p_dir->subdirs.size(); i++) {
|
2016-01-05 13:36:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_dir->get_subdir(i)->verified = false;
|
2016-01-05 13:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//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) {
|
|
|
|
|
|
|
|
bool isdir;
|
|
|
|
String f = da->get_next(&isdir);
|
2017-03-18 23:36:26 +00:00
|
|
|
if (f == "")
|
2016-01-05 13:36:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (isdir) {
|
|
|
|
|
|
|
|
if (f.begins_with(".")) //ignore hidden and . / ..
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int idx = p_dir->find_dir_index(f);
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx == -1) {
|
2016-01-05 13:36:24 +00:00
|
|
|
|
|
|
|
if (FileAccess::exists(cd.plus_file(f).plus_file("engine.cfg"))) // skip if another project inside this
|
|
|
|
continue;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorFileSystemDirectory *efd = memnew(EditorFileSystemDirectory);
|
2016-01-05 13:36:24 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
efd->parent = p_dir;
|
|
|
|
efd->name = f;
|
2016-01-05 13:36:24 +00:00
|
|
|
DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
|
|
|
d->change_dir(cd.plus_file(f));
|
2017-03-18 23:36:26 +00:00
|
|
|
_scan_new_dir(efd, d, p_progress.get_sub(1, 1));
|
2016-01-05 13:36:24 +00:00
|
|
|
memdelete(d);
|
|
|
|
|
|
|
|
ItemAction ia;
|
2017-03-18 23:36:26 +00:00
|
|
|
ia.action = ItemAction::ACTION_DIR_ADD;
|
|
|
|
ia.dir = p_dir;
|
|
|
|
ia.file = f;
|
|
|
|
ia.new_dir = efd;
|
2016-01-05 13:36:24 +00:00
|
|
|
scan_actions.push_back(ia);
|
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
p_dir->subdirs[idx]->verified = true;
|
2016-01-05 13:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
String ext = f.extension().to_lower();
|
|
|
|
if (!valid_extensions.has(ext))
|
|
|
|
continue; //invalid
|
|
|
|
|
|
|
|
int idx = p_dir->find_file_index(f);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx == -1) {
|
2016-01-05 13:36:24 +00:00
|
|
|
//never seen this file, add actition to add it
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorFileSystemDirectory::FileInfo *fi = memnew(EditorFileSystemDirectory::FileInfo);
|
|
|
|
fi->file = f;
|
2016-01-05 13:36:24 +00:00
|
|
|
|
|
|
|
String path = cd.plus_file(fi->file);
|
2017-03-18 23:36:26 +00:00
|
|
|
fi->modified_time = FileAccess::get_modified_time(path);
|
|
|
|
fi->meta = _get_meta(path);
|
|
|
|
fi->type = ResourceLoader::get_resource_type(path);
|
2016-01-05 13:36:24 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
ItemAction ia;
|
2017-03-18 23:36:26 +00:00
|
|
|
ia.action = ItemAction::ACTION_FILE_ADD;
|
|
|
|
ia.dir = p_dir;
|
|
|
|
ia.file = f;
|
|
|
|
ia.new_file = fi;
|
2016-01-05 13:36:24 +00:00
|
|
|
scan_actions.push_back(ia);
|
|
|
|
}
|
|
|
|
|
|
|
|
//take the chance and scan sources
|
|
|
|
if (_check_meta_sources(fi->meta)) {
|
|
|
|
|
|
|
|
ItemAction ia;
|
2017-03-18 23:36:26 +00:00
|
|
|
ia.action = ItemAction::ACTION_FILE_SOURCES_CHANGED;
|
|
|
|
ia.dir = p_dir;
|
|
|
|
ia.file = f;
|
2016-01-05 13:36:24 +00:00
|
|
|
scan_actions.push_back(ia);
|
2017-03-18 23:36:26 +00:00
|
|
|
fi->meta.sources_changed = true;
|
2016-05-27 17:18:40 +00:00
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
fi->meta.sources_changed = false;
|
2016-01-05 13:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
p_dir->files[idx]->verified = true;
|
2016-01-05 13:36:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-28 12:47:03 +00:00
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
da->list_dir_end();
|
|
|
|
memdelete(da);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < p_dir->files.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
if (updated_dir && !p_dir->files[i]->verified) {
|
|
|
|
//this file was removed, add action to remove it
|
|
|
|
ItemAction ia;
|
2017-03-18 23:36:26 +00:00
|
|
|
ia.action = ItemAction::ACTION_FILE_REMOVE;
|
|
|
|
ia.dir = p_dir;
|
|
|
|
ia.file = p_dir->files[i]->file;
|
2016-01-05 13:36:24 +00:00
|
|
|
scan_actions.push_back(ia);
|
|
|
|
continue;
|
|
|
|
}
|
2016-07-03 16:15:15 +00:00
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
if (_check_meta_sources(p_dir->files[i]->meta)) {
|
|
|
|
ItemAction ia;
|
2017-03-18 23:36:26 +00:00
|
|
|
ia.action = ItemAction::ACTION_FILE_SOURCES_CHANGED;
|
|
|
|
ia.dir = p_dir;
|
|
|
|
ia.file = p_dir->files[i]->file;
|
2016-01-05 13:36:24 +00:00
|
|
|
scan_actions.push_back(ia);
|
2017-03-18 23:36:26 +00:00
|
|
|
p_dir->files[i]->meta.sources_changed = true;
|
2016-05-27 17:18:40 +00:00
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
p_dir->files[i]->meta.sources_changed = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2016-07-03 16:15:15 +00:00
|
|
|
|
|
|
|
EditorResourcePreview::get_singleton()->check_for_invalidation(p_dir->get_file_path(i));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < p_dir->subdirs.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
if (updated_dir && !p_dir->subdirs[i]->verified) {
|
|
|
|
//this directory was removed, add action to remove it
|
|
|
|
ItemAction ia;
|
2017-03-18 23:36:26 +00:00
|
|
|
ia.action = ItemAction::ACTION_DIR_REMOVE;
|
|
|
|
ia.dir = p_dir->subdirs[i];
|
2016-01-05 13:36:24 +00:00
|
|
|
scan_actions.push_back(ia);
|
|
|
|
continue;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
_scan_fs_changes(p_dir->get_subdir(i), p_progress);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileSystem::_thread_func_sources(void *_userdata) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorFileSystem *efs = (EditorFileSystem *)_userdata;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (efs->filesystem) {
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorProgressBG pr("sources", TTR("ScanSources"), 1000);
|
2016-01-05 13:36:24 +00:00
|
|
|
ScanProgress sp;
|
2017-03-18 23:36:26 +00:00
|
|
|
sp.progress = ≺
|
|
|
|
sp.hi = 1;
|
|
|
|
sp.low = 0;
|
|
|
|
efs->_scan_fs_changes(efs->filesystem, sp);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
efs->scanning_sources_done = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileSystem::get_changed_sources(List<String> *r_changed) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_changed = sources_changed;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileSystem::scan_sources() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (scanning || scanning_sources || thread)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
sources_changed.clear();
|
2017-03-18 23:36:26 +00:00
|
|
|
scanning_sources = true;
|
|
|
|
scanning_sources_done = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
abort_scan = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!use_threads) {
|
2016-01-05 13:36:24 +00:00
|
|
|
if (filesystem) {
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorProgressBG pr("sources", TTR("ScanSources"), 1000);
|
2016-01-05 13:36:24 +00:00
|
|
|
ScanProgress sp;
|
2017-03-18 23:36:26 +00:00
|
|
|
sp.progress = ≺
|
|
|
|
sp.hi = 1;
|
|
|
|
sp.low = 0;
|
|
|
|
scan_total = 0;
|
|
|
|
_scan_fs_changes(filesystem, sp);
|
2016-01-05 13:36:24 +00:00
|
|
|
if (_update_scan_actions())
|
|
|
|
emit_signal("filesystem_changed");
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
scanning_sources = false;
|
|
|
|
scanning_sources_done = true;
|
|
|
|
emit_signal("sources_changed", sources_changed.size() > 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
ERR_FAIL_COND(thread_sources);
|
|
|
|
set_process(true);
|
2017-03-18 23:36:26 +00:00
|
|
|
scan_total = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
Thread::Settings s;
|
2017-03-18 23:36:26 +00:00
|
|
|
s.priority = Thread::PRIORITY_LOW;
|
|
|
|
thread_sources = Thread::create(_thread_func_sources, this, s);
|
2014-02-10 01:10:30 +00:00
|
|
|
//tree->hide();
|
2016-05-04 13:28:37 +00:00
|
|
|
//print_line("SCAN BEGIN!");
|
2014-02-10 01:10:30 +00:00
|
|
|
//progress->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileSystem::_notification(int p_what) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (p_what) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-11-06 00:20:42 +00:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
scan();
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2014-11-06 00:20:42 +00:00
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
2014-02-10 01:10:30 +00:00
|
|
|
if (use_threads && thread) {
|
|
|
|
//abort thread if in progress
|
2017-03-18 23:36:26 +00:00
|
|
|
abort_scan = true;
|
|
|
|
while (scanning) {
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->delay_usec(1000);
|
|
|
|
}
|
|
|
|
Thread::wait_to_finish(thread);
|
|
|
|
memdelete(thread);
|
2017-03-18 23:36:26 +00:00
|
|
|
thread = NULL;
|
2016-05-04 13:28:37 +00:00
|
|
|
WARN_PRINTS("Scan thread aborted...");
|
2014-02-10 01:10:30 +00:00
|
|
|
set_process(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filesystem)
|
|
|
|
memdelete(filesystem);
|
2016-01-05 13:36:24 +00:00
|
|
|
if (new_filesystem)
|
|
|
|
memdelete(new_filesystem);
|
2017-03-18 23:36:26 +00:00
|
|
|
filesystem = NULL;
|
|
|
|
new_filesystem = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case NOTIFICATION_PROCESS: {
|
|
|
|
|
|
|
|
if (use_threads) {
|
|
|
|
|
|
|
|
if (scanning_sources) {
|
|
|
|
|
|
|
|
if (scanning_sources_done) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
scanning_sources = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
set_process(false);
|
|
|
|
|
|
|
|
Thread::wait_to_finish(thread_sources);
|
|
|
|
memdelete(thread_sources);
|
2017-03-18 23:36:26 +00:00
|
|
|
thread_sources = NULL;
|
2016-01-05 13:36:24 +00:00
|
|
|
if (_update_scan_actions())
|
|
|
|
emit_signal("filesystem_changed");
|
2014-04-10 03:18:27 +00:00
|
|
|
//print_line("sources changed: "+itos(sources_changed.size()));
|
2017-03-18 23:36:26 +00:00
|
|
|
emit_signal("sources_changed", sources_changed.size() > 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
} else if (!scanning) {
|
|
|
|
|
|
|
|
set_process(false);
|
|
|
|
|
|
|
|
if (filesystem)
|
|
|
|
memdelete(filesystem);
|
2017-03-18 23:36:26 +00:00
|
|
|
filesystem = new_filesystem;
|
|
|
|
new_filesystem = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
Thread::wait_to_finish(thread);
|
|
|
|
memdelete(thread);
|
2017-03-18 23:36:26 +00:00
|
|
|
thread = NULL;
|
2016-01-05 13:36:24 +00:00
|
|
|
_update_scan_actions();
|
2014-02-10 01:10:30 +00:00
|
|
|
emit_signal("filesystem_changed");
|
2017-03-18 23:36:26 +00:00
|
|
|
emit_signal("sources_changed", sources_changed.size() > 0);
|
2014-04-10 03:18:27 +00:00
|
|
|
//print_line("initial sources changed: "+itos(sources_changed.size()));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
//progress->set_text("Scanning...\n"+itos(total*100)+"%");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorFileSystem::is_scanning() const {
|
|
|
|
|
|
|
|
return scanning;
|
|
|
|
}
|
|
|
|
float EditorFileSystem::get_scanning_progress() const {
|
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
return scan_total;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EditorFileSystemDirectory *EditorFileSystem::get_filesystem() {
|
|
|
|
|
|
|
|
return filesystem;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void EditorFileSystem::_save_filesystem_cache(EditorFileSystemDirectory *p_dir, FileAccess *p_file) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!p_dir)
|
|
|
|
return; //none
|
2017-03-18 23:36:26 +00:00
|
|
|
p_file->store_line("::" + p_dir->get_path() + "::" + String::num(p_dir->modified_time));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < p_dir->files.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String s = p_dir->files[i]->file + "::" + p_dir->files[i]->type + "::" + String::num(p_dir->files[i]->modified_time) + "::";
|
2014-02-10 01:10:30 +00:00
|
|
|
if (p_dir->files[i]->meta.enabled) {
|
2017-03-18 23:36:26 +00:00
|
|
|
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);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
s += "::";
|
|
|
|
for (int j = 0; j < p_dir->files[i]->meta.deps.size(); j++) {
|
2015-08-23 23:15:56 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (j > 0)
|
|
|
|
s += "<>";
|
|
|
|
s += p_dir->files[i]->meta.deps[j];
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
p_file->store_line(s);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < p_dir->subdirs.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_save_filesystem_cache(p_dir->subdirs[i], p_file);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool EditorFileSystem::_find_file(const String &p_file, EditorFileSystemDirectory **r_d, int &r_file_pos) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
//todo make faster
|
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
if (!filesystem || scanning)
|
|
|
|
return false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
String f = Globals::get_singleton()->localize_path(p_file);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
if (!f.begins_with("res://"))
|
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
f = f.substr(6, f.length());
|
|
|
|
f = f.replace("\\", "/");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
Vector<String> path = f.split("/");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (path.size() == 0)
|
2016-01-05 13:36:24 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
String file = path[path.size() - 1];
|
|
|
|
path.resize(path.size() - 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorFileSystemDirectory *fs = filesystem;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < path.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int idx = -1;
|
|
|
|
for (int j = 0; j < fs->get_subdir_count(); j++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (fs->get_subdir(j)->get_name() == path[i]) {
|
|
|
|
idx = j;
|
2016-01-05 13:36:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx == -1) {
|
2016-01-05 13:36:24 +00:00
|
|
|
//does not exist, create i guess?
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorFileSystemDirectory *efsd = memnew(EditorFileSystemDirectory);
|
2017-06-16 20:32:46 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
efsd->name = path[i];
|
2017-06-16 20:32:46 +00:00
|
|
|
efsd->parent = fs;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int idx2 = 0;
|
|
|
|
for (int j = 0; j < fs->get_subdir_count(); j++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (efsd->name < fs->get_subdir(j)->get_name())
|
2016-01-05 13:36:24 +00:00
|
|
|
break;
|
|
|
|
idx2++;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx2 == fs->get_subdir_count())
|
2016-01-05 13:36:24 +00:00
|
|
|
fs->subdirs.push_back(efsd);
|
|
|
|
else
|
2017-03-18 23:36:26 +00:00
|
|
|
fs->subdirs.insert(idx2, efsd);
|
|
|
|
fs = efsd;
|
2016-01-05 13:36:24 +00:00
|
|
|
} else {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
fs = fs->get_subdir(idx);
|
2016-01-05 13:36:24 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int cpos = -1;
|
|
|
|
for (int i = 0; i < fs->files.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (fs->files[i]->file == file) {
|
|
|
|
cpos = i;
|
2016-01-05 13:36:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_file_pos = cpos;
|
|
|
|
*r_d = fs;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (cpos != -1) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
return true;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String EditorFileSystem::get_file_type(const String &p_file) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorFileSystemDirectory *fs = NULL;
|
|
|
|
int cpos = -1;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (!_find_file(p_file, &fs, cpos)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return "";
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return fs->files[cpos]->type;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorFileSystemDirectory *EditorFileSystem::find_file(const String &p_file, int *r_index) const {
|
2016-05-27 17:18:40 +00:00
|
|
|
|
|
|
|
if (!filesystem || scanning)
|
2017-03-18 23:36:26 +00:00
|
|
|
return NULL;
|
2016-05-27 17:18:40 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorFileSystemDirectory *fs = NULL;
|
|
|
|
int cpos = -1;
|
|
|
|
if (!_find_file(p_file, &fs, cpos)) {
|
2016-05-27 17:18:40 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return NULL;
|
2016-05-27 17:18:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (r_index)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_index = cpos;
|
2016-05-27 17:18:40 +00:00
|
|
|
|
|
|
|
return fs;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorFileSystemDirectory *EditorFileSystem::get_path(const String &p_path) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (!filesystem || scanning)
|
|
|
|
return NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String f = Globals::get_singleton()->localize_path(p_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (!f.begins_with("res://"))
|
|
|
|
return NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
f = f.substr(6, f.length());
|
|
|
|
f = f.replace("\\", "/");
|
|
|
|
if (f == String())
|
|
|
|
return filesystem;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (f.ends_with("/"))
|
|
|
|
f = f.substr(0, f.length() - 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Vector<String> path = f.split("/");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (path.size() == 0)
|
|
|
|
return NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorFileSystemDirectory *fs = filesystem;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < path.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int idx = -1;
|
|
|
|
for (int j = 0; j < fs->get_subdir_count(); j++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (fs->get_subdir(j)->get_name() == path[i]) {
|
|
|
|
idx = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx == -1) {
|
|
|
|
return NULL;
|
|
|
|
} else {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
fs = fs->get_subdir(idx);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return fs;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void EditorFileSystem::_resource_saved(const String &p_path) {
|
2016-01-29 11:41:22 +00:00
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
//print_line("resource saved: "+p_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
EditorFileSystem::get_singleton()->update_file(p_path);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String EditorFileSystem::_find_first_from_source(EditorFileSystemDirectory *p_dir, const String &p_src) const {
|
2014-11-12 14:23:23 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < p_dir->files.size(); i++) {
|
|
|
|
for (int j = 0; j < p_dir->files[i]->meta.sources.size(); j++) {
|
2014-11-12 14:23:23 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_dir->files[i]->meta.sources[j].path == p_src)
|
2014-11-12 14:23:23 +00:00
|
|
|
return p_dir->get_file_path(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < p_dir->subdirs.size(); i++) {
|
2014-11-12 14:23:23 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String ret = _find_first_from_source(p_dir->subdirs[i], p_src);
|
|
|
|
if (ret.length() > 0)
|
2014-11-12 14:23:23 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String EditorFileSystem::find_resource_from_source(const String &p_path) const {
|
2014-11-12 14:23:23 +00:00
|
|
|
|
|
|
|
if (filesystem)
|
2017-03-18 23:36:26 +00:00
|
|
|
return _find_first_from_source(filesystem, p_path);
|
2014-11-12 14:23:23 +00:00
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void EditorFileSystem::update_file(const String &p_file) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorFileSystemDirectory *fs = NULL;
|
|
|
|
int cpos = -1;
|
2015-08-23 23:15:56 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (!_find_file(p_file, &fs, cpos)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (!fs)
|
|
|
|
return;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (!FileAccess::exists(p_file)) {
|
|
|
|
//was removed
|
|
|
|
memdelete(fs->files[cpos]);
|
|
|
|
fs->files.remove(cpos);
|
|
|
|
call_deferred("emit_signal", "filesystem_changed"); //update later
|
|
|
|
return;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String type = ResourceLoader::get_resource_type(p_file);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (cpos == -1) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int idx = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < fs->files.size(); i++) {
|
|
|
|
if (p_file < fs->files[i]->file)
|
|
|
|
break;
|
|
|
|
idx++;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorFileSystemDirectory::FileInfo *fi = memnew(EditorFileSystemDirectory::FileInfo);
|
|
|
|
fi->file = p_file.get_file();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx == fs->files.size()) {
|
|
|
|
fs->files.push_back(fi);
|
|
|
|
} else {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
fs->files.insert(idx, fi);
|
|
|
|
}
|
|
|
|
cpos = idx;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-04 13:28:37 +00:00
|
|
|
//print_line("UPDATING: "+p_file);
|
2017-03-18 23:36:26 +00:00
|
|
|
fs->files[cpos]->type = type;
|
|
|
|
fs->files[cpos]->modified_time = FileAccess::get_modified_time(p_file);
|
|
|
|
fs->files[cpos]->meta = _get_meta(p_file);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorResourcePreview::get_singleton()->call_deferred("check_for_invalidation", p_file);
|
|
|
|
call_deferred("emit_signal", "filesystem_changed"); //update later
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileSystem::_bind_methods() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("filesystem_changed"));
|
|
|
|
ADD_SIGNAL(MethodInfo("sources_changed", PropertyInfo(Variant::BOOL, "exist")));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EditorFileSystem::EditorFileSystem() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
singleton = this;
|
|
|
|
filesystem = memnew(EditorFileSystemDirectory); //like, empty
|
2017-06-16 20:32:46 +00:00
|
|
|
filesystem->parent = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
thread = NULL;
|
2017-03-18 23:36:26 +00:00
|
|
|
scanning = false;
|
|
|
|
use_threads = true;
|
|
|
|
thread_sources = NULL;
|
|
|
|
new_filesystem = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-06-16 20:32:46 +00:00
|
|
|
abort_scan = false;
|
2017-03-18 23:36:26 +00:00
|
|
|
scanning_sources = false;
|
2017-06-16 20:32:46 +00:00
|
|
|
scanning_sources_done = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
ResourceSaver::set_save_callback(_resource_saved);
|
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
List<String> extensionsl;
|
2017-03-18 23:36:26 +00:00
|
|
|
ResourceLoader::get_recognized_extensions_for_type("", &extensionsl);
|
|
|
|
for (List<String>::Element *E = extensionsl.front(); E; E = E->next()) {
|
2016-01-05 13:36:24 +00:00
|
|
|
|
|
|
|
valid_extensions.insert(E->get());
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
scan_total = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EditorFileSystem::~EditorFileSystem() {
|
|
|
|
}
|