Example #1
0
        /* ----------------------------------------------------------------- */
        ///
        /// Open
        ///
        /// <summary>
        /// Opens the specified source directory with the specified
        /// application.
        /// </summary>
        ///
        /// <param name="src">Path to open.</param>
        /// <param name="method">Method to open.</param>
        /// <param name="app">Path of the application.</param>
        ///
        /* ----------------------------------------------------------------- */
        public static void Open(this Entity src, OpenMethod method, string app)
        {
            if (!method.HasFlag(OpenMethod.Open))
            {
                return;
            }

            var dest = src.IsDirectory ? src.FullName : src.DirectoryName;
            var skip = method.HasFlag(OpenMethod.SkipDesktop) &&
                       dest.FuzzyEquals(Environment.SpecialFolder.Desktop.GetName());

            if (skip)
            {
                return;
            }

            var cvt   = app.HasValue() ? app : "explorer.exe";
            var klass = typeof(EntityExtension);

            klass.LogDebug($"Path:{src.FullName.Quote()}", $"App:{cvt.Quote()}");
            klass.LogWarn(() => new Process
            {
                StartInfo = new()
                {
                    FileName        = cvt,
                    Arguments       = dest.Quote(),
                    CreateNoWindow  = false,
                    UseShellExecute = true,
                    LoadUserProfile = false,
                    WindowStyle     = ProcessWindowStyle.Normal,
                }
            }.Start());