Explorar el Código

runtime: notify size and mtime when a file is added

Also save these new informations into the files database.
Daniele Bartolini hace 1 año
padre
commit
030f725919

+ 8 - 4
src/resource/data_compiler.cpp

@@ -84,11 +84,15 @@ CE_STATIC_ASSERT(countof(platform_info) == Platform::COUNT);
 
 
 static volatile bool _quit = false;
 static volatile bool _quit = false;
 
 
-static void notify_add_file(const char *path)
+static void notify_add_file(const char *path, Stat &st)
 {
 {
 	TempAllocator512 ta;
 	TempAllocator512 ta;
 	StringStream ss(ta);
 	StringStream ss(ta);
-	ss << "{\"type\":\"add_file\",\"path\":\"" << path << "\"}";
+	ss << "{\"type\":\"add_file\"";
+	ss << ",\"path\":\"" << path << "\"";
+	ss << ",\"size\":\"" << st.size << "\"";
+	ss << ",\"mtime\":\"" << st.mtime << "\"";
+	ss << "}";
 	console_server()->broadcast(string_stream::c_str(ss));
 	console_server()->broadcast(string_stream::c_str(ss));
 }
 }
 
 
@@ -158,7 +162,7 @@ void SourceIndex::scan_directory(FilesystemDisk &fs, const char *prefix, const c
 			st = fs.stat(file_i.c_str());
 			st = fs.stat(file_i.c_str());
 			hash_map::set(_paths, resource_name, st);
 			hash_map::set(_paths, resource_name, st);
 
 
-			notify_add_file(resource_name.c_str());
+			notify_add_file(resource_name.c_str(), st);
 		}
 		}
 	}
 	}
 }
 }
@@ -612,7 +616,7 @@ void DataCompiler::add_file(const char *path)
 
 
 	// Avoid sending spurious add_file() notifications for already known paths.
 	// Avoid sending spurious add_file() notifications for already known paths.
 	if (prev_st.file_type == Stat::NO_ENTRY)
 	if (prev_st.file_type == Stat::NO_ENTRY)
-		notify_add_file(path);
+		notify_add_file(path, st);
 }
 }
 
 
 void DataCompiler::remove_file(const char *path)
 void DataCompiler::remove_file(const char *path)

+ 3 - 1
tools/level_editor/level_editor.vala

@@ -1075,8 +1075,10 @@ public class LevelEditorApplication : Gtk.Application
 			log(system, (string)msg["severity"], (string)msg["message"]);
 			log(system, (string)msg["severity"], (string)msg["message"]);
 		} else if (msg_type == "add_file") {
 		} else if (msg_type == "add_file") {
 			string path = (string)msg["path"];
 			string path = (string)msg["path"];
+			uint64 size = uint64.parse((string)msg["size"]);
+			uint64 mtime = uint64.parse((string)msg["mtime"]);
 
 
-			_project.add_file(path);
+			_project.add_file(path, size, mtime);
 		} else if (msg_type == "remove_file") {
 		} else if (msg_type == "remove_file") {
 			string path = (string)msg["path"];
 			string path = (string)msg["path"];
 
 

+ 5 - 3
tools/level_editor/project.vala

@@ -47,7 +47,7 @@ public class Project
 	public ImporterData _all_extensions_importer_data;
 	public ImporterData _all_extensions_importer_data;
 	public Gee.ArrayList<ImporterData?> _importers;
 	public Gee.ArrayList<ImporterData?> _importers;
 
 
-	public signal void file_added(string type, string name);
+	public signal void file_added(string type, string name, uint64 size, uint64 mtime);
 	public signal void file_removed(string type, string name);
 	public signal void file_removed(string type, string name);
 	public signal void tree_added(string name);
 	public signal void tree_added(string name);
 	public signal void tree_removed(string name);
 	public signal void tree_removed(string name);
@@ -379,7 +379,7 @@ public class Project
 		return _files;
 		return _files;
 	}
 	}
 
 
-	public void add_file(string path)
+	public void add_file(string path, uint64 size, uint64 mtime)
 	{
 	{
 		string type = path_extension(path);
 		string type = path_extension(path);
 		string name = type == "" ? path : path.substring(0, path.last_index_of("."));
 		string name = type == "" ? path : path.substring(0, path.last_index_of("."));
@@ -389,11 +389,13 @@ public class Project
 		_files.set_property_string(id, "path", path);
 		_files.set_property_string(id, "path", path);
 		_files.set_property_string(id, "type", type);
 		_files.set_property_string(id, "type", type);
 		_files.set_property_string(id, "name", name);
 		_files.set_property_string(id, "name", name);
+		_files.set_property_string(id, "size", size.to_string());
+		_files.set_property_string(id, "mtime", mtime.to_string());
 		_files.add_to_set(GUID_ZERO, "data", id);
 		_files.add_to_set(GUID_ZERO, "data", id);
 
 
 		_map[path] = id;
 		_map[path] = id;
 
 
-		file_added(type, name);
+		file_added(type, name, size, mtime);
 	}
 	}
 
 
 	public void remove_file(string path)
 	public void remove_file(string path)