From 1000ee3b052ad0a0299c59c4cc6c8b241951967f Mon Sep 17 00:00:00 2001 From: r_dh Date: Wed, 22 Jul 2020 11:59:44 +0200 Subject: [PATCH] fix: Removed plugin related scripts and services --- Maria.Editor/editorservice.cs | 72 --------- Maria.Editor/editorstartup.cs | 34 ----- Maria.Editor/pluginassociations.cs | 20 --- Maria.Editor/pluginhandler.cs | 188 ----------------------- Maria.Editor/pluginloader.cs | 238 ----------------------------- Maria.Editor/pluginvalidator.cs | 112 -------------- 6 files changed, 664 deletions(-) delete mode 100644 Maria.Editor/editorservice.cs delete mode 100644 Maria.Editor/editorstartup.cs delete mode 100644 Maria.Editor/pluginassociations.cs delete mode 100644 Maria.Editor/pluginhandler.cs delete mode 100644 Maria.Editor/pluginloader.cs delete mode 100644 Maria.Editor/pluginvalidator.cs diff --git a/Maria.Editor/editorservice.cs b/Maria.Editor/editorservice.cs deleted file mode 100644 index af416d4..0000000 --- a/Maria.Editor/editorservice.cs +++ /dev/null @@ -1,72 +0,0 @@ -using Maria.Threading; -using System; -using System.Collections.Generic; -using System.IO; -using System.Threading; -using UnityEditor; -using UnityEngine; - -namespace Maria.Editor -{ - internal class EditorService - { - //-------------------------------------------------------------------------------------- - // Constants - private static readonly string MARIA_INSTALL_LOCATION = "C:\\DAE\\bin\\" + Application.unityVersion + "\\"; - - //-------------------------------------------------------------------------------------- - // Properties - public bool IsRunning - { - get; - private set; - } - - private readonly PluginHandler plugin_handler; - - //-------------------------------------------------------------------------------------- - public EditorService() - { - IsRunning = false; - - plugin_handler = new PluginHandler(); - } - - //-------------------------------------------------------------------------------------- - public void run() - { - // - // Subscribe to update and quit event - // - EditorApplication.update += update; - EditorApplication.quitting += stop; - - // - // Flag that we are running the application - // - IsRunning = plugin_handler.initialize(MARIA_INSTALL_LOCATION); - } - - //-------------------------------------------------------------------------------------- - private void update() - { - if (!IsRunning) - return; - - plugin_handler.update(Time.deltaTime); - } - //-------------------------------------------------------------------------------------- - private void stop() - { - if (!IsRunning) - return; - - plugin_handler.stop(); - - EditorApplication.quitting -= stop; - EditorApplication.update -= update; - - IsRunning = false; - } - } -} diff --git a/Maria.Editor/editorstartup.cs b/Maria.Editor/editorstartup.cs deleted file mode 100644 index 13a31c5..0000000 --- a/Maria.Editor/editorstartup.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.IO; - -using UnityEditor; -using UnityEngine; - -namespace Maria.Editor -{ - [InitializeOnLoad] - public class EditorStartup - { - //--------------------------------------------------------------------------------------- - // Fields - private static EditorService service; - - //--------------------------------------------------------------------------------------- - static EditorStartup() - { - initialize(); - - UnityEngine.Debug.Log("Engine up and running!"); - } - - //--------------------------------------------------------------------------------------- - private static void initialize() - { - if (service == null) - { - service = new EditorService(); - service.run(); - } - } - } -} diff --git a/Maria.Editor/pluginassociations.cs b/Maria.Editor/pluginassociations.cs deleted file mode 100644 index e81c970..0000000 --- a/Maria.Editor/pluginassociations.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Collections.Generic; -using Maria.IO; - -namespace Maria.Editor -{ - public class PluginAssociations - { - //-------------------------------------------------------------------------------------- - // Properties - public Dictionary> Extensions { get; } = new Dictionary>() - { - { PluginType.DEBUG, new List() { FileExtension.DLL, FileExtension.PDB, FileExtension.META} }, - { PluginType.RELEASE, new List() { FileExtension.DLL, FileExtension.META } } - }; - - //-------------------------------------------------------------------------------------- - public PluginAssociations() - { } - } -} diff --git a/Maria.Editor/pluginhandler.cs b/Maria.Editor/pluginhandler.cs deleted file mode 100644 index b6444dd..0000000 --- a/Maria.Editor/pluginhandler.cs +++ /dev/null @@ -1,188 +0,0 @@ -using System; -using System.IO; -using UnityEditor; -using UnityEngine; - -namespace Maria.Editor -{ - public class PluginHandler - { - //-------------------------------------------------------------------------------------- - // Constants - public static readonly string UNITY_PLUGIN_LOCATION = Application.dataPath + "\\Plugins\\"; - public static readonly string MARIA_PLUGIN_LOCATION = "maria\\"; - - private static readonly float PLUGIN_FLUSH_INTERVAL = 4.0f; - private static readonly float PLUGIN_VALIDATE_INTERVAL = 3600.0f; - - //-------------------------------------------------------------------------------------- - // Fields - private bool refresh_assets; - - private Guid loader_refresh_timer_id; - private Guid validator_timer_id; - - private TimerManager timer_manager; - - private PluginLoader plugin_loader; - private PluginValidator plugin_validator; - - private string install_location; - - //-------------------------------------------------------------------------------------- - public PluginHandler() - { - refresh_assets = false; - } - - //-------------------------------------------------------------------------------------- - public bool initialize(string installLocation) - { - if(!Directory.Exists(UNITY_PLUGIN_LOCATION + MARIA_PLUGIN_LOCATION)) - { - Debug.LogWarning("Please move \"Maria\" plugins inside a \"Maria\" subdirectory folder. eg: \"Assets/Plugins/maria/maria_core.dll\""); - return false; - } - - install_location = installLocation; - -#if DEBUG - PluginType plugin_type = PluginType.DEBUG; -#else - PluginType plugin_type = PluginType.RELEASE; -#endif - - if (!Directory.Exists(install_location)) - { - UnityEngine.Debug.LogWarning("Install location not found: " + install_location); - UnityEngine.Debug.Log("Installing loaded plugins ..."); - - Directory.CreateDirectory(install_location); - - foreach (string file_path in Directory.GetFiles(UNITY_PLUGIN_LOCATION + MARIA_PLUGIN_LOCATION)) - { - if (plugin_type == PluginType.DEBUG) - { - if (!IO.Helpers.isDebugFile(file_path)) - continue; - } - - Debug.Log("SOURCE: " + file_path); - Debug.Log("DEST: " + Path.Combine(installLocation, System.IO.Path.GetFileName(file_path))); - - File.Copy(file_path, Path.Combine(installLocation, System.IO.Path.GetFileName(file_path))); - } - - UnityEngine.Debug.Log("Installation finished!"); - foreach (string file_path in Directory.GetFiles(installLocation)) - { - if (plugin_type == PluginType.DEBUG) - { - if (!IO.Helpers.isDebugFile(file_path)) - continue; - - UnityEngine.Debug.Log("Installed file: " + file_path); - } - } - } - - plugin_validator = new PluginValidator(UNITY_PLUGIN_LOCATION + MARIA_PLUGIN_LOCATION, plugin_type); - plugin_loader = new PluginLoader(install_location, UNITY_PLUGIN_LOCATION + MARIA_PLUGIN_LOCATION, plugin_type); - plugin_loader.onFinishedLoading += onPluginsLoaded; - plugin_loader.onFileDeleted += onPluginRemoved; - - timer_manager = new TimerManager(); - - loader_refresh_timer_id = timer_manager.createTimer(createPluginLoaderTimerInfo()); - validator_timer_id = timer_manager.createTimer(createPluginValidatorTimerInfo()); - - return true; -} - - //-------------------------------------------------------------------------------------- - public void update(float dTime) - { - timer_manager.update(dTime); - - if (refresh_assets) - { - plugin_validator.validate(); - - AssetDatabase.Refresh(); - - refresh_assets = false; - } - } - - //-------------------------------------------------------------------------------------- - public void stop() - { - plugin_loader.onFinishedLoading -= onPluginsLoaded; - plugin_loader.onFileDeleted -= onPluginRemoved; - - refresh_assets = false; - - timer_manager.stopTimer(loader_refresh_timer_id); - timer_manager.stopTimer(validator_timer_id); - } - - //-------------------------------------------------------------------------------------- - private void flushPluginLoader(Guid timerId) - { - if (!plugin_loader.IsDirty || timerId != loader_refresh_timer_id) - return; - - plugin_loader.flush(); - - UnityEngine.Debug.Log("Flushing plugins ..."); - } - //-------------------------------------------------------------------------------------- - private void validatePluginValidator(Guid timerId) - { - if (timerId != validator_timer_id) - return; - - plugin_validator.validate(); - - UnityEngine.Debug.Log("Validating plugins ..."); - } - - //-------------------------------------------------------------------------------------- - private void onPluginsLoaded() - { - refresh_assets = true; - - UnityEngine.Debug.Log("Plugins Loaded!"); - } - //-------------------------------------------------------------------------------------- - private void onPluginRemoved() - { - refresh_assets = true; - - UnityEngine.Debug.Log("Plugin Removed!"); - } - - //-------------------------------------------------------------------------------------- - private TimerCreationInfo createPluginLoaderTimerInfo() - { - TimerCreationInfo info = new TimerCreationInfo(); - info.finished_delegate += flushPluginLoader; - info.finish_behaviour = TimerFinishedBehaviour.RESET_START_ON_FINSHED; - info.start_on_creation = true; - info.start_time = PLUGIN_FLUSH_INTERVAL; - - return info; - } - //-------------------------------------------------------------------------------------- - private TimerCreationInfo createPluginValidatorTimerInfo() - { - TimerCreationInfo info = new TimerCreationInfo(); - info.finished_delegate += validatePluginValidator; - info.finish_behaviour = TimerFinishedBehaviour.RESET_START_ON_FINSHED; - info.start_on_creation = true; - info.start_time = PLUGIN_VALIDATE_INTERVAL; - - return info; - } - } -} diff --git a/Maria.Editor/pluginloader.cs b/Maria.Editor/pluginloader.cs deleted file mode 100644 index dbe5c7e..0000000 --- a/Maria.Editor/pluginloader.cs +++ /dev/null @@ -1,238 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Threading; -using Maria.Threading; -using Maria.Diagnostics; -using UnityEngine; - -namespace Maria.Editor -{ - public enum PluginType - { - DEBUG, - RELEASE - } - - public class PluginLoader - { - //-------------------------------------------------------------------------------------- - // Delegates - public delegate void PluginLoaderEventHandler(); - - public PluginLoaderEventHandler onFinishedLoading; - - public PluginLoaderEventHandler onFileChanged; - public PluginLoaderEventHandler onFileCreated; - public PluginLoaderEventHandler onFileRenamed; - public PluginLoaderEventHandler onFileDeleted; - - //-------------------------------------------------------------------------------------- - // Properties - public bool IsDirty - { - get { return copy_data.Count > 0; } - } - - //-------------------------------------------------------------------------------------- - // Fields - private readonly string source_directory; - private readonly string destination_directory; - private readonly PluginType plugin_type; - private readonly IO.FileSystemWatcher file_system_watcher; - private readonly List copy_data; - private CopyTask copy_task; - private readonly PluginAssociations plugin_associations; - - //-------------------------------------------------------------------------------------- - public PluginLoader(string source, string dest, PluginType type) - { - source_directory = source; - destination_directory = dest; - plugin_type = type; - copy_data = new List(); - plugin_associations = new PluginAssociations(); - - try - { - file_system_watcher = new IO.FileSystemWatcher(createLogger()); - file_system_watcher.subscribe(source_directory, IO.FileSystemWatcher.DEFAULT_CREATION_INFO); - file_system_watcher.onFileChanged += fileChanged; - file_system_watcher.onFileCreated += fileCreated; - file_system_watcher.onFileRenamed += fileRenamed; - file_system_watcher.onFileDeleted += fileDeleted; - - foreach(string file_path in Directory.GetFiles(source)) - { - if (plugin_type == PluginType.DEBUG) - { - if (!IO.Helpers.isDebugFile(file_path)) - continue; - } - - scheduleCopy(file_path, Path.GetFileName(file_path)); - } - } - catch(Exception e) - { - UnityEngine.Debug.Log(e.Message); - } - } - - //-------------------------------------------------------------------------------------- - public void flush() - { - copy_task = new CopyTask(copy_data.ToArray(), createLogger()); - - copy_task.onStarted += onStartedCopy; - copy_task.onFinished += onFinishedCopy; - - Thread thread = new Thread(new ThreadStart(copy_task.execute)); - thread.Start(); - } - - //------------------------------------------------------------------------------------- - private void fileChanged(FileSystemWatcher source, FileSystemEventArgs args) - { - // - // schedule a new task to copy. - // - if (scheduleCopy(args.FullPath, args.Name)) - { - if (onFileChanged != null) - onFileChanged(); - } - else - { - UnityEngine.Debug.Log("Failed to schedule plugin copy task when file was CHANGED."); - } - } - //------------------------------------------------------------------------------------- - private void fileCreated(FileSystemWatcher source, FileSystemEventArgs args) - { - // - // schedule a new task to copy. - // - if (scheduleCopy(args.FullPath, args.Name)) - { - if (onFileCreated != null) - onFileCreated(); - } - else - { - UnityEngine.Debug.Log("Failed to schedule plugin copy task when file was CREATED."); - } - } - //------------------------------------------------------------------------------------- - private void fileRenamed(FileSystemWatcher source, RenamedEventArgs args) - { - // - // Delete the old file before creating a new one. - // - if(File.Exists(destination_directory + Path.GetFileName(args.OldFullPath))) - { - File.Delete(destination_directory + Path.GetFileName(args.OldFullPath)); - } - - // - // schedule a new task to copy. - // - if (scheduleCopy(args.FullPath, args.Name)) - { - if (onFileRenamed != null) - onFileRenamed(); - } - else - { - UnityEngine.Debug.Log("Failed to schedule plugin copy task when file was RENAMED."); - } - } - //------------------------------------------------------------------------------------- - private void fileDeleted(FileSystemWatcher source, FileSystemEventArgs args) - { - // - // Delete the old file. - // - if (File.Exists(destination_directory + Path.GetFileName(args.FullPath))) - { - File.Delete(destination_directory + Path.GetFileName(args.FullPath)); - } - - if (onFileDeleted != null) - onFileDeleted(); - - UnityEngine.Debug.Log("File Deleted"); - } - - //-------------------------------------------------------------------------------------- - private bool scheduleCopy(string fullPath, string name) - { - // - // We only want to work with supported files. - // - IO.FileExtension file_extionsion = plugin_associations.Extensions[plugin_type].Find(ex => fullPath.Contains(IO.FileExtensions.toString(ex))); - if (file_extionsion == IO.FileExtension.NONE) - return false; - - // - // If we specified to copy debug library files - // We should check if they have the required postfix. - // - if (plugin_type == PluginType.DEBUG) - { - if (!IO.Helpers.isDebugFile(name)) - return false; - } - - return prepareCopy(source_directory + Path.GetFileName(fullPath), destination_directory + Path.GetFileName(fullPath), true); - } - //-------------------------------------------------------------------------------------- - private bool prepareCopy(string from, string to, bool overwrite) - { - if (File.Exists(from)) - { - CopyData data = new CopyData - { - from = from, - to = to, - overwrite = overwrite - }; - - copy_data.Add(data); - - return true; - } - - return false; - } - - //-------------------------------------------------------------------------------------- - private void onStartedCopy(Task task) - { - // Nothing to implement - } - //-------------------------------------------------------------------------------------- - private void onFinishedCopy(Task task) - { - if (onFinishedLoading != null) - onFinishedLoading(); - - // Clear copy members - copy_task = null; - copy_data.Clear(); - } - - //-------------------------------------------------------------------------------------- - private Maria.Diagnostics.Logger createLogger() - { - Maria.Diagnostics.LoggerCreationInfo logger_creation_info = new Maria.Diagnostics.LoggerCreationInfo - { - log_function = UnityEngine.Debug.Log, - warn_function = UnityEngine.Debug.LogWarning, - error_function = UnityEngine.Debug.LogError - }; - - return new Maria.Diagnostics.Logger(logger_creation_info); - } - } -} diff --git a/Maria.Editor/pluginvalidator.cs b/Maria.Editor/pluginvalidator.cs deleted file mode 100644 index 18e54cc..0000000 --- a/Maria.Editor/pluginvalidator.cs +++ /dev/null @@ -1,112 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using Maria.IO; -using UnityEngine; - -namespace Maria.Editor -{ - public class PluginValidator - { - //-------------------------------------------------------------------------------------- - // Fields - private readonly PluginType plugin_type; - private readonly string source_directory; - private readonly PluginAssociations plugin_associations; - - //-------------------------------------------------------------------------------------- - public PluginValidator(string source, PluginType type) - { - UnityEngine.Debug.Assert(Directory.Exists(source), "Path does not represent a directory"); - - source_directory = source; - plugin_type = type; - plugin_associations = new PluginAssociations(); - } - - //-------------------------------------------------------------------------------------- - public void validate() - { - // - // Cache plugin configuration FileExtensions - // - List FileExtensions = plugin_associations.Extensions[plugin_type]; - - // - // We should only print this information in DEBUG mode. - // - if (plugin_type == PluginType.DEBUG) - { - List string_list = new List(); - foreach (FileExtension FileExtension in FileExtensions) - string_list.Add(FileExtension.ToString()); - - UnityEngine.Debug.Log(string.Format("Allowed FileExtensions: {0}", string.Join(", ", string_list.ToArray()))); - } - - // - // Calculate what files should be removed from the plugin folder - // - List to_remove = new List(); - foreach (string file_path in Directory.GetFiles(source_directory)) - { - string full_file_path = source_directory + Path.GetFileName(file_path); - - // - // Unsupported file format, should be removed. - // - FileExtension file_extionsion = FileExtensions.Find(ex => full_file_path.Contains(IO.FileExtensions.toString(ex))); - if (file_extionsion == FileExtension.NONE) - { - to_remove.Add(full_file_path); - continue; - } - - // - // Calculate removal of debugging or release DLL's depending on the setup PluginType. - // - switch (plugin_type) - { - case PluginType.DEBUG: full_file_path = removeReleasePlugin(full_file_path); break; - case PluginType.RELEASE: full_file_path = removeDebugPlugin(full_file_path); break; - } - - if (full_file_path != string.Empty) - to_remove.Add(full_file_path); - } - - // - // Remove files from source directory. - // - if (to_remove.Count == 0) - return; - - foreach (string file_path in to_remove) - { - File.Delete(file_path); - } - } - - //-------------------------------------------------------------------------------------- - private string removeReleasePlugin(string fullFilePath) - { - // - // We are a DLL and do not have the debugging postfix. - // File should be removed. - // - return fullFilePath.Contains(FileExtensions.toString(FileExtension.DLL)) && !IO.Helpers.isDebugFile(fullFilePath) - ? fullFilePath - : string.Empty; - } - //-------------------------------------------------------------------------------------- - private string removeDebugPlugin(string fullFilePath) - { - // - // We are a DLL and have the debugging postfix. - // File should be removed. - // - return fullFilePath.Contains(FileExtensions.toString(FileExtension.DLL)) && IO.Helpers.isDebugFile(fullFilePath) - ? fullFilePath - : string.Empty; - } - } -}