/// <summary> /// Called when the watcher has registered a filesystem change /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void watcher_Changed(object sender, FileSystemEventArgs e) { var watcher = (FileSystemWatcher)sender; var length = e.FullPath.Length - watcher.Path.Length - Path.GetExtension(e.Name).Length - 1; var sub_path = e.FullPath.Substring(watcher.Path.Length + 1, length); QueuedChange change; if (!changeQueue.TryGetValue(sub_path, out change)) { change = new QueuedChange(); changeQueue[sub_path] = change; } change.timer?.Destroy(); change.timer = null; switch (e.ChangeType) { case WatcherChangeTypes.Changed: if (change.type != WatcherChangeTypes.Created) { change.type = WatcherChangeTypes.Changed; } break; case WatcherChangeTypes.Created: if (change.type == WatcherChangeTypes.Deleted) { change.type = WatcherChangeTypes.Changed; } else { change.type = WatcherChangeTypes.Created; } break; case WatcherChangeTypes.Deleted: if (change.type == WatcherChangeTypes.Created) { changeQueue.Remove(sub_path); return; } change.type = WatcherChangeTypes.Deleted; break; } Interface.Oxide.NextTick(() => { change.timer?.Destroy(); change.timer = timers.Once(.2f, () => { change.timer = null; changeQueue.Remove(sub_path); if (Regex.Match(sub_path, @"Include\\", RegexOptions.IgnoreCase).Success) { if (change.type == WatcherChangeTypes.Created || change.type == WatcherChangeTypes.Changed) { FirePluginSourceChanged(sub_path); } return; } switch (change.type) { case WatcherChangeTypes.Changed: if (watchedPlugins.Contains(sub_path)) { FirePluginSourceChanged(sub_path); } else { FirePluginAdded(sub_path); } break; case WatcherChangeTypes.Created: FirePluginAdded(sub_path); break; case WatcherChangeTypes.Deleted: if (watchedPlugins.Contains(sub_path)) { FirePluginRemoved(sub_path); } break; } }); }); }
/// <summary> /// Called when the watcher has registered a filesystem change /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void watcher_Changed(object sender, FileSystemEventArgs e) { var watcher = (FileSystemWatcher)sender; var length = e.FullPath.Length - watcher.Path.Length - Path.GetExtension(e.Name).Length - 1; var sub_path = e.FullPath.Substring(watcher.Path.Length + 1, length); QueuedChange change; if (!changeQueue.TryGetValue(sub_path, out change)) { change = new QueuedChange(); changeQueue[sub_path] = change; } change.timer?.Destroy(); change.timer = null; switch (e.ChangeType) { case WatcherChangeTypes.Changed: if (change.type != WatcherChangeTypes.Created) change.type = WatcherChangeTypes.Changed; break; case WatcherChangeTypes.Created: if (change.type == WatcherChangeTypes.Deleted) change.type = WatcherChangeTypes.Changed; else change.type = WatcherChangeTypes.Created; break; case WatcherChangeTypes.Deleted: if (change.type == WatcherChangeTypes.Created) { changeQueue.Remove(sub_path); return; } change.type = WatcherChangeTypes.Deleted; break; } Interface.Oxide.NextTick(() => { change.timer?.Destroy(); change.timer = timers.Once(.2f, () => { change.timer = null; changeQueue.Remove(sub_path); if (Regex.Match(sub_path, @"Include\\", RegexOptions.IgnoreCase).Success) { if (change.type == WatcherChangeTypes.Created || change.type == WatcherChangeTypes.Changed) FirePluginSourceChanged(sub_path); return; } switch (change.type) { case WatcherChangeTypes.Changed: if (watchedPlugins.Contains(sub_path)) FirePluginSourceChanged(sub_path); else FirePluginAdded(sub_path); break; case WatcherChangeTypes.Created: FirePluginAdded(sub_path); break; case WatcherChangeTypes.Deleted: if (watchedPlugins.Contains(sub_path)) FirePluginRemoved(sub_path); break; } }); }); }