//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// using System; using System.Runtime.CompilerServices; using bs; namespace bs.Editor { /** @addtogroup Utility-Editor * @{ */ /// /// Allows monitoring a file system folder for changes. Depending on the flags set this monitor can notify you when /// file is changed/moved/renamed and similar. /// public class FolderMonitor : ScriptObject { /// /// Triggers when a file in the monitored folder is modified. Provides absolute path to the modified file. /// public Action OnModified; /// /// Triggers when a file/folder is added in the monitored folder. Provides absolute path to the added file/folder. /// public Action OnAdded; /// /// Triggers when a file/folder is removed from the monitored folder. Provides absolute path to the removed /// file/folder. /// public Action OnRemoved; /// /// Triggers when a file/folder is renamed in the monitored folder. Provides absolute path with old and new names. /// public Action OnRenamed; /// /// Constructs a new folder monitor instance that immediately starts monitor the provided folder. /// /// Absolute path to the folder to monitor. public FolderMonitor(string folderToMonitor) { Internal_CreateInstance(this, folderToMonitor); } /// /// Stops monitoring the folder. /// public void Destroy() { Internal_Destroy(mCachedPtr); } /// /// Triggered by the runtime when a file in the monitored folder is modified. /// /// Absolute path to the modified file/folder. private void Internal_DoOnModified(string path) { if (OnModified != null) OnModified(path); } /// /// Triggered by the runtime when a file in the monitored folder is added. /// /// Absolute path to the added file/folder. private void Internal_DoOnAdded(string path) { if (OnAdded != null) OnAdded(path); } /// /// Triggered by the runtime when a file in the monitored folder is removed. /// /// Absolute path to the removed file/folder. private void Internal_DoOnRemoved(string path) { if (OnRemoved != null) OnRemoved(path); } /// /// Triggered by the runtime when a file in the monitored folder is renamed. /// /// Absolute path to the original file/folder location. /// Absolute path to the new file/folder location. private void Internal_DoOnRenamed(string from, string to) { if (OnRenamed != null) OnRenamed(from, to); } [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_CreateInstance(FolderMonitor instance, string folder); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_Destroy(IntPtr thisPtr); } /** @} */ }