예제 #1
0
        /// <summary>
        ///     For the given directory this will return possible location.
        ///     It might be that multiple are returned, also normalization is made
        /// </summary>
        /// <param name="directory">A absolute or relative directory</param>
        /// <param name="allowCurrentDirectory">true to allow relative to current working directory</param>
        /// <returns>IEnumerable with possible directories</returns>
        public static IEnumerable <string> DirectoriesFor(string directory, bool allowCurrentDirectory = true)
        {
            var directories = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            // If the path is rooted, it's absolute
            if (Path.IsPathRooted(directory))
            {
                directories.Add(FileTools.NormalizeDirectory(directory));
            }
            else
            {
                // Relative to the assembly location
                directories.Add(DirectoryRelativeToExe(directory));

                // Relative to the current working directory
                if (allowCurrentDirectory)
                {
                    directories.Add(DirectoryRelativeToCurrentWorkingDirectory(directory));
                }
            }
            return(directories.Where(dir => !string.IsNullOrEmpty(dir) && Directory.Exists(dir)).OrderBy(dir => dir));
        }
예제 #2
0
        /// <summary>
        /// Helper method to clean up
        /// </summary>
        private void RemoveCopiedAssemblies()
        {
            if (!CleanupAfterExit || _assembliesToDeleteAtExit.Count == 0)
            {
                return;
            }

            if (Log.IsVerboseEnabled())
            {
                Log.Verbose().WriteLine("Removing cached assembly files: \r\n\t{0}", string.Join("\r\n\t", _assembliesToDeleteAtExit.Select(a => $"\"{FileTools.NormalizeDirectory(a)}\"")));
            }

            var info = new ProcessStartInfo
            {
                Arguments      = "/C choice /C Y /N /D Y /T 3 & Del " + string.Join(" ", _assembliesToDeleteAtExit),
                WindowStyle    = ProcessWindowStyle.Hidden,
                CreateNoWindow = true,
                FileName       = "cmd.exe"
            };

            _assembliesToDeleteAtExit.Clear();
            Process.Start(info);
        }