//------------------------------------------------- #region Worker Method's Region private void Watcher_Worker(Trigger sender, TickHandlerEventArgs <Trigger> handler) { Watcher ??= new FileSystemWatcher(ConfigDir.GetValue(), Config_Filter) { EnableRaisingEvents = true }; Watcher.Changed -= Watcher_Changed; Watcher.Changed += Watcher_Changed; }
static int Main(string[] args) { if (args.Contains("-open")) { Console.WriteLine($"Opening config directory: '{ConfigDir}'"); Process.Start("explorer", $"\"{ConfigDir}\""); } else if (args.ContainsAny("-init")) { var dir = ConfigDir.PathJoin("txt", "01.=== Shell-X for •.txt file ===").EnsureDirectory(); File.WriteAllText(dir.PathJoin("..", "00.separator"), ""); File.WriteAllText(dir.PathJoin("..", "02.separator"), ""); File.WriteAllText(dir.PathJoin("00.Notepad.cmd"), "notepad.exe %*"); File.WriteAllText(dir.PathJoin("01.Notepad++.cmd"), "notepad++.exe %*"); File.WriteAllText(dir.PathJoin("02.separator"), ""); File.WriteAllText(dir.PathJoin("03.Show Info.c.cmd"), $"dir %*{NewLine}pause"); File.WriteAllText(dir.PathJoin("04.separator"), ""); File.WriteAllText(dir.PathJoin("05.Shell-X configure.cmd"), $"explorer \"{ConfigDir}\""); Resources.logo.Save(dir.PathJoin("05.Shell-X configure.ico")); dir = ConfigDir.PathJoin("[any]").EnsureDirectory(); File.WriteAllText(dir.PathJoin("01.Shell-X configure.cmd"), $"explorer \"{ConfigDir}\""); Resources.logo.Save(dir.PathJoin("01.Shell-X configure.ico")); dir = ConfigDir.PathJoin("txt"); Console.WriteLine($"Configured context menu for '*.*' and '*.txt' files: '{ConfigDir}'"); if (!args.ContainsAny("-noui")) { Process.Start("explorer", $"\"{ConfigDir}\""); } } else if (args.ContainsAny("-register", "-r")) { return(Regasm.Register(Assembly.GetExecutingAssembly().Location, Is64BitOperatingSystem) ? 0 : -1); } else if (args.ContainsAny("-unregister", "-u")) { return(Regasm.Unregister(Assembly.GetExecutingAssembly().Location, Is64BitOperatingSystem) ? 0 : -1); } else { var serverType = typeof(DynamicContextMenuExtension); string cpuType = Environment.Is64BitProcess ? "x64" : "x32"; Console.WriteLine($"Dynamic context menu manager. Version {Assembly.GetExecutingAssembly().GetName().Version}"); Console.WriteLine($"Copyright (C) 2019 Oleg Shilo (github.com/oleg-shilo/shell-x)"); Console.WriteLine(); Console.WriteLine("=================================================================="); Console.WriteLine($" Config directory: {ConfigDir}"); Console.WriteLine($" Shell Extension server: {serverType.GUID}"); Console.WriteLine($" Registered ({cpuType}): {serverType.IsRegeiteredComServer()}"); Console.WriteLine("=================================================================="); // Console.WriteLine("-----------------------"); Console.WriteLine(); Console.WriteLine($"{Assembly.GetExecutingAssembly().GetName().Name} [option]"); Console.WriteLine(); Console.WriteLine($"Options:"); Console.WriteLine($" -open Opens configuration folder."); Console.WriteLine($" You can edit the context menus by changing the content of this folder"); Console.WriteLine($" -init Creates the sample configuration (e.g. for *.txt files)."); Console.WriteLine($" -register|-r Registers shell extension server"); Console.WriteLine($" -unregister|-u Unregisters shell extension server"); } return(0); }