/// ------------------------------------------------------------------------------------
        private static string LocateInProgramFilesFolder(string exeName, SearchOption srcOption,
                                                         params string[] subFoldersToSearch)
        {
            if (subFoldersToSearch.Length == 0)
            {
                subFoldersToSearch = new[] { string.Empty }
            }
            ;

            foreach (var progFolder in GetPossibleProgramFilesFolders().Where(Directory.Exists))
            {
                // calling Directory.GetFiles("C:\Program Files", exeName, SearchOption.AllDirectories) will fail
                // if even one of the children of the Program Files doesn't allow you to search it.
                // So instead we first gather up all the children directories, and then search those.
                // Some will give us access denied, and that's fine, we skip them.
                // But we don't want to look in child directories on Linux because GetPossibleProgramFilesFolders()
                // gives us the individual elements of the PATH environment variable, and these specify exactly
                // those directories that should be searched for program files.
                foreach (var path in subFoldersToSearch.Select(sf => Path.Combine(progFolder, sf)).Where(Directory.Exists))
                {
                    if (Platform.IsWindows)
                    {
                        foreach (var subDir in DirectoryUtilities.GetSafeDirectories(path))
                        {
                            var tgtPath = GetFiles(exeName, srcOption, subDir);
                            if (!string.IsNullOrEmpty(tgtPath))
                            {
                                return(tgtPath);
                            }
                        }
                    }
                    else
                    {
                        var tgtPath = GetFiles(exeName, srcOption, path);
                        if (!string.IsNullOrEmpty(tgtPath))
                        {
                            return(tgtPath);
                        }
                    }
                }
            }

            return(null);
        }
Beispiel #2
0
 // See comment on class above regarding Dispose
 public void Dispose()
 {
     if (_detached)
     {
         return;
     }
     try
     {
         File.Delete(Path);
     }
     catch (IOException e)
     {
         // We tried, but we don't want to crash just because virus scanner or similar won't release the file.
         Logger.WriteMinorEvent("Could not delete temp file during Dispose(): " + e.Message);
         Debug.Fail("Could not delete temp file during Dispose(): " + e.Message, e.ToString());
     }
     if (_folderToDelete != null)
     {
         DirectoryUtilities.DeleteDirectoryRobust(_folderToDelete);
     }
 }