2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* editor_file_system.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2016-01-01 13:50:53 +00:00
|
|
|
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#ifndef EDITOR_FILE_SYSTEM_H
|
|
|
|
#define EDITOR_FILE_SYSTEM_H
|
|
|
|
|
|
|
|
#include "scene/main/node.h"
|
|
|
|
#include "os/thread.h"
|
|
|
|
#include "os/dir_access.h"
|
|
|
|
#include "set.h"
|
|
|
|
#include "os/thread_safe.h"
|
|
|
|
class FileAccess;
|
|
|
|
|
2016-05-18 06:21:16 +00:00
|
|
|
struct EditorProgressBG;
|
2014-02-10 01:10:30 +00:00
|
|
|
class EditorFileSystemDirectory : public Object {
|
|
|
|
|
|
|
|
OBJ_TYPE( EditorFileSystemDirectory,Object );
|
|
|
|
|
|
|
|
String name;
|
2016-01-05 13:36:24 +00:00
|
|
|
uint64_t modified_time;
|
|
|
|
bool verified; //used for checking changes
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
EditorFileSystemDirectory *parent;
|
|
|
|
Vector<EditorFileSystemDirectory*> subdirs;
|
|
|
|
|
|
|
|
struct ImportMeta {
|
|
|
|
|
|
|
|
struct Source {
|
|
|
|
|
|
|
|
String path;
|
|
|
|
String md5;
|
|
|
|
uint64_t modified_time;
|
|
|
|
bool missing;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Vector<Source> sources;
|
|
|
|
String import_editor;
|
2015-08-23 23:15:56 +00:00
|
|
|
Vector<String> deps;
|
2014-02-10 01:10:30 +00:00
|
|
|
bool enabled;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FileInfo {
|
|
|
|
String file;
|
2015-08-23 23:15:56 +00:00
|
|
|
StringName type;
|
2014-02-10 01:10:30 +00:00
|
|
|
uint64_t modified_time;
|
|
|
|
ImportMeta meta;
|
2016-01-05 13:36:24 +00:00
|
|
|
bool verified; //used for checking changes
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FileInfoSort {
|
|
|
|
bool operator()(const FileInfo *p_a,const FileInfo *p_b) const {
|
|
|
|
return p_a->file<p_b->file;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
void sort_files();
|
|
|
|
|
|
|
|
Vector<FileInfo*> files;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2014-11-12 14:23:23 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
friend class EditorFileSystem;
|
|
|
|
public:
|
|
|
|
|
|
|
|
String get_name();
|
|
|
|
String get_path() const;
|
|
|
|
|
|
|
|
int get_subdir_count() const;
|
|
|
|
EditorFileSystemDirectory *get_subdir(int p_idx);
|
|
|
|
int get_file_count() const;
|
|
|
|
String get_file(int p_idx) const;
|
|
|
|
String get_file_path(int p_idx) const;
|
2015-08-23 23:15:56 +00:00
|
|
|
StringName get_file_type(int p_idx) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
bool get_file_meta(int p_idx) const;
|
|
|
|
bool is_missing_sources(int p_idx) const;
|
|
|
|
Vector<String> get_missing_sources(int p_idx) const;
|
2015-08-23 23:15:56 +00:00
|
|
|
Vector<String> get_file_deps(int p_idx) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
EditorFileSystemDirectory *get_parent();
|
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
int find_file_index(const String& p_file) const;
|
|
|
|
int find_dir_index(const String& p_dir) const;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
EditorFileSystemDirectory();
|
|
|
|
~EditorFileSystemDirectory();
|
|
|
|
};
|
|
|
|
|
|
|
|
class EditorFileSystem : public Node {
|
|
|
|
|
|
|
|
OBJ_TYPE( EditorFileSystem, Node );
|
|
|
|
|
|
|
|
_THREAD_SAFE_CLASS_
|
|
|
|
|
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
|
|
|
|
struct ItemAction {
|
|
|
|
|
|
|
|
enum Action {
|
|
|
|
ACTION_NONE,
|
|
|
|
ACTION_DIR_ADD,
|
|
|
|
ACTION_DIR_REMOVE,
|
|
|
|
ACTION_FILE_ADD,
|
|
|
|
ACTION_FILE_REMOVE,
|
|
|
|
ACTION_FILE_SOURCES_CHANGED
|
|
|
|
};
|
|
|
|
|
|
|
|
Action action;
|
|
|
|
EditorFileSystemDirectory *dir;
|
2014-02-10 01:10:30 +00:00
|
|
|
String file;
|
2016-01-05 13:36:24 +00:00
|
|
|
EditorFileSystemDirectory *new_dir;
|
|
|
|
EditorFileSystemDirectory::FileInfo *new_file;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
ItemAction() { action=ACTION_NONE; dir=NULL; new_dir=NULL; new_file=NULL; }
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
bool use_threads;
|
|
|
|
Thread *thread;
|
|
|
|
static void _thread_func(void *_userdata);
|
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
EditorFileSystemDirectory *new_filesystem;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
bool abort_scan;
|
|
|
|
bool scanning;
|
2016-01-05 13:36:24 +00:00
|
|
|
float scan_total;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
void _scan_filesystem();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
EditorFileSystemDirectory *filesystem;
|
|
|
|
|
|
|
|
static EditorFileSystem *singleton;
|
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
/* Used for reading the filesystem cache file */
|
2014-02-10 01:10:30 +00:00
|
|
|
struct FileCache {
|
|
|
|
|
|
|
|
String type;
|
|
|
|
uint64_t modification_time;
|
|
|
|
EditorFileSystemDirectory::ImportMeta meta;
|
2015-08-23 23:15:56 +00:00
|
|
|
Vector<String> deps;
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
HashMap<String,FileCache> file_cache;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
struct ScanProgress {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
float low;
|
|
|
|
float hi;
|
|
|
|
mutable EditorProgressBG *progress;
|
|
|
|
void update(int p_current,int p_total) const;
|
|
|
|
ScanProgress get_sub(int p_current,int p_total) const;
|
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
static EditorFileSystemDirectory::ImportMeta _get_meta(const String& p_path);
|
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
bool _check_meta_sources(EditorFileSystemDirectory::ImportMeta & p_meta);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
void _save_filesystem_cache(EditorFileSystemDirectory *p_dir,FileAccess *p_file);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
bool _find_file(const String& p_file,EditorFileSystemDirectory ** r_d, int &r_file_pos) const;
|
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
void _scan_fs_changes(EditorFileSystemDirectory *p_dir, const ScanProgress &p_progress);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int md_count;
|
|
|
|
|
2016-01-05 13:36:24 +00:00
|
|
|
Set<String> valid_extensions;
|
|
|
|
|
|
|
|
void _scan_new_dir(EditorFileSystemDirectory *p_dir,DirAccess *da,const ScanProgress& p_progress);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Thread *thread_sources;
|
|
|
|
bool scanning_sources;
|
|
|
|
bool scanning_sources_done;
|
2016-01-05 13:36:24 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
static void _thread_func_sources(void *_userdata);
|
2016-01-05 13:36:24 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
List<String> sources_changed;
|
2016-01-05 13:36:24 +00:00
|
|
|
List<ItemAction> scan_actions;
|
|
|
|
|
|
|
|
bool _update_scan_actions();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
static void _resource_saved(const String& p_path);
|
2014-11-12 14:23:23 +00:00
|
|
|
String _find_first_from_source(EditorFileSystemDirectory* p_dir,const String &p_src) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
static EditorFileSystem* get_singleton() { return singleton; }
|
|
|
|
|
|
|
|
EditorFileSystemDirectory *get_filesystem();
|
|
|
|
bool is_scanning() const;
|
|
|
|
float get_scanning_progress() const;
|
|
|
|
void scan();
|
|
|
|
void scan_sources();
|
|
|
|
void get_changed_sources(List<String> *r_changed);
|
|
|
|
void update_file(const String& p_file);
|
2014-11-12 14:23:23 +00:00
|
|
|
String find_resource_from_source(const String& p_path) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
EditorFileSystemDirectory *get_path(const String& p_path);
|
|
|
|
String get_file_type(const String& p_file) const;
|
|
|
|
EditorFileSystem();
|
|
|
|
~EditorFileSystem();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // EDITOR_FILE_SYSTEM_H
|