Exemplo n.º 1
0
        private static string TryFindRInProgramFiles(string folder, ISupportedRVersionRange supportedVersions)
        {
            string         root        = Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
            string         baseRFolder = Path.Combine(root + @"Program Files\", folder);
            List <Version> versions    = new List <Version>();

            try {
                IEnumerable <IFileSystemInfo> directories = FileSystem.GetDirectoryInfo(baseRFolder)
                                                            .EnumerateFileSystemInfos()
                                                            .Where(x => (x.Attributes & FileAttributes.Directory) != 0);
                foreach (IFileSystemInfo fsi in directories)
                {
                    string  subFolderName = fsi.FullName.Substring(baseRFolder.Length + 1);
                    Version v             = GetRVersionFromFolderName(subFolderName);
                    if (supportedVersions.IsCompatibleVersion(v))
                    {
                        versions.Add(v);
                    }
                }
            } catch (IOException) {
                // Don't do anything if there is no RRO installed
            }

            if (versions.Count > 0)
            {
                versions.Sort();
                Version highest = versions[versions.Count - 1];
                return(Path.Combine(baseRFolder, String.Format(CultureInfo.InvariantCulture, "R-{0}.{1}.{2}", highest.Major, highest.Minor, highest.Build)));
            }

            return(string.Empty);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieves path to the latest (highest version) R installation
        /// from registry. Typically in the form 'Program Files\R\R-3.2.1'
        /// Selects highest from compatible versions, not just the highest.
        /// </summary>
        public static string GetCompatibleEnginePathFromRegistry(ISupportedRVersionRange svl = null)
        {
            svl = svl ?? new SupportedRVersionRange();
            string[] installedEngines   = GetInstalledEngineVersionsFromRegistry();
            string   highestVersionName = String.Empty;
            Version  highest            = null;

            foreach (string name in installedEngines)
            {
                // Protect from random key name format changes
                if (!String.IsNullOrEmpty(name))
                {
                    string  versionString = ExtractVersionString(name);
                    Version v;
                    if (Version.TryParse(versionString, out v) && svl.IsCompatibleVersion(v))
                    {
                        if (highest != null)
                        {
                            if (v > highest)
                            {
                                highest            = v;
                                highestVersionName = name;
                            }
                        }
                        else
                        {
                            highest            = v;
                            highestVersionName = name;
                        }
                    }
                }
            }

            return(GetRVersionInstallPathFromRegistry(highestVersionName));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Retrieves path to the all compatible R installations from registry. 
 /// </summary>
 private IEnumerable<IRInterpreterInfo> GetCompatibleEnginesFromRegistry(ISupportedRVersionRange svr) {
     svr = svr ?? new SupportedRVersionRange();
     var engines = GetInstalledEnginesFromRegistry().Where(e => svr.IsCompatibleVersion(e.Version));
     // Remove duplicates (MRC registers under multiple keys)
     var mrc = engines.FirstOrDefault(e => e.Name.Contains("Microsoft"));
     if(mrc != null) {
         var dupes = engines.Where(e => e.InstallPath.EqualsIgnoreCase(mrc.InstallPath)).Except(new IRInterpreterInfo[] { mrc });
         engines = engines.Except(dupes);
     }
     return engines;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Retrieves path to the all compatible R installations from registry.
        /// </summary>
        private IEnumerable <IRInterpreterInfo> GetCompatibleEnginesFromRegistry(ISupportedRVersionRange svr)
        {
            svr = svr ?? new SupportedRVersionRange();
            var engines = GetInstalledEnginesFromRegistry().Where(e => svr.IsCompatibleVersion(e.Version));

            // Among duplicates by path take the highest version
            return
                (from e in engines
                 group e by e.InstallPath.TrimTrailingSlash()
                 into g
                 select g.OrderByDescending(e => e.Version).First());
        }
Exemplo n.º 5
0
        private IEnumerable <IRInterpreterInfo> GetInstalledCranR(ISupportedRVersionRange svl)
        {
            var rFrameworkPath = Path.Combine("/Library/Frameworks/R.framework/Versions");

            foreach (var path in _fileSystem.GetDirectories(rFrameworkPath))
            {
                var version = VersionFromPath(path, out var versionString);
                if (version != null && svl.IsCompatibleVersion(version))
                {
                    yield return(new RMacInterpreterInfo("R " + versionString, versionString, version, _fileSystem));
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Retrieves path to the all compatible R installations from registry.
        /// </summary>
        private IEnumerable <IRInterpreterInfo> GetCompatibleEnginesFromRegistry(ISupportedRVersionRange svr)
        {
            svr = svr ?? new SupportedRVersionRange();
            var engines = GetInstalledEnginesFromRegistry().Where(e => svr.IsCompatibleVersion(e.Version));
            // Remove duplicates (MRC registers under multiple keys)
            var mrc = engines.FirstOrDefault(e => e.Name.Contains("Microsoft"));

            if (mrc != null)
            {
                var dupes = engines.Where(e => e.InstallPath.EqualsIgnoreCase(mrc.InstallPath)).Except(new IRInterpreterInfo[] { mrc });
                engines = engines.Except(dupes);
            }
            return(engines);
        }
Exemplo n.º 7
0
        public bool VerifyInstallation(ISupportedRVersionRange svr = null, IServiceContainer services = null)
        {
            var ui = services?.GetService <IUIService>();

            if (_isValid.HasValue)
            {
                return(_isValid.Value);
            }

            _isValid = false;

            svr = svr ?? new SupportedRVersionRange();
            string libRPath = Path.Combine(BinPath, "libR.so");

            try {
                if (_fileSystem.DirectoryExists(InstallPath) && _fileSystem.DirectoryExists(BinPath) &&
                    _fileSystem.FileExists(libRPath))
                {
                    if (Version != null)
                    {
                        _isValid = svr.IsCompatibleVersion(Version);
                        if (!_isValid.Value)
                        {
                            ui?.ShowMessage(
                                Resources.Error_UnsupportedRVersion.FormatInvariant(
                                    Version.Major, Version.Minor, Version.Build, svr.MinMajorVersion, svr.MinMinorVersion, "*",
                                    svr.MaxMajorVersion, svr.MaxMinorVersion, "*"), MessageButtons.OK);
                        }
                    }
                    else
                    {
                        // In linux there is no direct way to get version from binary. So assume valid version for a user provided
                        // interpreter path.
                        _isValid = true;
                    }
                }
                else
                {
                    ui?.ShowMessage(Resources.Error_CannotFindRBinariesFormat.FormatInvariant(InstallPath), MessageButtons.OK);
                }
            } catch (Exception ex) when(ex is IOException || ex is ArgumentException || ex is UnauthorizedAccessException)
            {
                ui?.ShowErrorMessage(Resources.Error_ExceptionAccessingPath.FormatInvariant(InstallPath, ex.Message));
            }

            return(_isValid.Value);
        }
Exemplo n.º 8
0
        public bool VerifyInstallation(ISupportedRVersionRange svr = null, IServiceContainer services = null)
        {
            var ui = services?.GetService <IUIService>();

            if (_isValid.HasValue)
            {
                return(_isValid.Value);
            }

            _isValid = false;

            svr = svr ?? new SupportedRVersionRange();

            // Normalize path so it points to R root and not to bin or bin\x64
            string rDllPath      = Path.Combine(BinPath, "R.dll");
            string rGraphAppPath = Path.Combine(BinPath, "Rgraphapp.dll");
            string rTermPath     = Path.Combine(BinPath, "RTerm.exe");
            string rScriptPath   = Path.Combine(BinPath, "RScript.exe");
            string rGuiPath      = Path.Combine(BinPath, "RGui.exe");

            try {
                if (_fileSystem.FileExists(rDllPath) && _fileSystem.FileExists(rTermPath) &&
                    _fileSystem.FileExists(rScriptPath) && _fileSystem.FileExists(rGraphAppPath) &&
                    _fileSystem.FileExists(rGuiPath))
                {
                    var fileVersion = GetRVersionFromBinary(_fileSystem, rDllPath);
                    _isValid = IsSameVersion(fileVersion, Version) && svr.IsCompatibleVersion(Version);
                    if (!_isValid.Value)
                    {
                        ui?.ShowMessage(
                            string.Format(CultureInfo.InvariantCulture, Resources.Error_UnsupportedRVersion,
                                          Version.Major, Version.Minor, Version.Build, svr.MinMajorVersion, svr.MinMinorVersion, "*",
                                          svr.MaxMajorVersion, svr.MaxMinorVersion, "*"), MessageButtons.OK);
                    }
                }
                else
                {
                    ui?.ShowMessage(string.Format(CultureInfo.InvariantCulture, Resources.Error_CannotFindRBinariesFormat, InstallPath), MessageButtons.OK);
                }
            } catch (Exception ex) when(ex is IOException || ex is ArgumentException || ex is UnauthorizedAccessException)
            {
                ui?.ShowErrorMessage(
                    string.Format(CultureInfo.InvariantCulture, Resources.Error_ExceptionAccessingPath, InstallPath, ex.Message));
            }

            return(_isValid.Value);
        }
Exemplo n.º 9
0
        private IRInterpreterInfo TryFindRInProgramFiles(ISupportedRVersionRange supportedVersions)
        {
            // Force 64-bit PF
            var programFiles = Environment.GetEnvironmentVariable("ProgramW6432");
            var baseRFolder  = Path.Combine(programFiles, @"R");
            var versions     = new List <Version>();

            try {
                if (_fileSystem.DirectoryExists(baseRFolder))
                {
                    IEnumerable <IFileSystemInfo> directories = _fileSystem.GetDirectoryInfo(baseRFolder)
                                                                .EnumerateFileSystemInfos()
                                                                .Where(x => (x.Attributes & FileAttributes.Directory) != 0);
                    foreach (IFileSystemInfo fsi in directories)
                    {
                        string  subFolderName = fsi.FullName.Substring(baseRFolder.Length + 1);
                        Version v             = GetRVersionFromFolderName(subFolderName);
                        if (supportedVersions.IsCompatibleVersion(v))
                        {
                            versions.Add(v);
                        }
                    }
                }
            } catch (IOException) {
                // Don't do anything if there is no RRO installed
            }

            if (versions.Count > 0)
            {
                versions.Sort();
                Version highest = versions[versions.Count - 1];
                var     name    = string.Format(CultureInfo.InvariantCulture, "R-{0}.{1}.{2}", highest.Major, highest.Minor, highest.Build);
                var     path    = Path.Combine(baseRFolder, name);
                var     ri      = CreateInfo(name, path);
                if (ri.VerifyInstallation(supportedVersions))
                {
                    return(ri);
                }
            }

            return(null);
        }
Exemplo n.º 10
0
        public bool VerifyInstallation(ISupportedRVersionRange svr = null, IFileSystem fs = null, ICoreShell coreShell = null) {
            if (_isValid.HasValue) {
                return _isValid.Value;
            }

            _isValid = false;

            svr = svr ?? new SupportedRVersionRange();
            fs = fs ?? new FileSystem();

            // Normalize path so it points to R root and not to bin or bin\x64
            string rDllPath = Path.Combine(BinPath, "R.dll");
            string rGraphAppPath = Path.Combine(BinPath, "Rgraphapp.dll");
            string rTermPath = Path.Combine(BinPath, "RTerm.exe");
            string rScriptPath = Path.Combine(BinPath, "RScript.exe");
            string rGuiPath = Path.Combine(BinPath, "RGui.exe");

            try {
                if (fs.FileExists(rDllPath) && fs.FileExists(rTermPath) &&
                    fs.FileExists(rScriptPath) && fs.FileExists(rGraphAppPath) &&
                    fs.FileExists(rGuiPath)) {

                    var fileVersion = GetRVersionFromBinary(fs, rDllPath);
                    _isValid = IsSameVersion(fileVersion, Version) && svr.IsCompatibleVersion(Version);
                    if (!_isValid.Value) {
                        coreShell?.ShowMessage(
                            string.Format(CultureInfo.InvariantCulture, Resources.Error_UnsupportedRVersion,
                            Version.Major, Version.Minor, Version.Build, svr.MinMajorVersion, svr.MinMinorVersion, "*",
                            svr.MaxMajorVersion, svr.MaxMinorVersion, "*"), MessageButtons.OK);
                    }
                } else {
                    coreShell?.ShowMessage(string.Format(CultureInfo.InvariantCulture, Resources.Error_CannotFindRBinariesFormat, InstallPath), MessageButtons.OK);
                }
            } catch (Exception ex) when (ex is IOException || ex is ArgumentException || ex is UnauthorizedAccessException) {
                coreShell?.ShowErrorMessage(
                    string.Format(CultureInfo.InvariantCulture, Resources.Error_ExceptionAccessingPath, InstallPath, ex.Message));
            }

            return _isValid.Value;
        }
Exemplo n.º 11
0
        private IEnumerable <IRInterpreterInfo> GetInstalledCranR(IEnumerable <InstalledPackageInfo> packagesInfo, ISupportedRVersionRange svl)
        {
            var selectedPackages = packagesInfo.Where(p => p.PackageName.EqualsIgnoreCase("r-base-core") && svl.IsCompatibleVersion(p.GetVersion()));

            foreach (var package in selectedPackages)
            {
                yield return(RInterpreterInfo.CreateFromPackage(package, "CRAN R", _fileSystem));
            }
        }
Exemplo n.º 12
0
        private IEnumerable <IRInterpreterInfo> GetInstalledMRO(IEnumerable <InstalledPackageInfo> packagesInfo, ISupportedRVersionRange svl)
        {
            var selectedPackages = packagesInfo.Where(p => p.PackageName.StartsWithIgnoreCase("microsoft-r-open-mro") && svl.IsCompatibleVersion(p.GetVersion()));

            foreach (var package in selectedPackages)
            {
                yield return(RInterpreterInfo.CreateFromPackage(package, "Microsoft R Open", _fileSystem));
            }
        }
Exemplo n.º 13
0
        private IEnumerable <IRInterpreterInfo> GetInstalledCranR(IEnumerable <InstalledPackageInfo> packagesInfo, ISupportedRVersionRange svl)
        {
            var list             = new List <IRInterpreterInfo>();
            var selectedPackages = packagesInfo.Where(p => p.PackageName.EqualsIgnoreCase("r-base-core") && svl.IsCompatibleVersion(p.GetVersion()));

            foreach (var package in selectedPackages)
            {
                var    files        = package.GetPackageFiles(_fileSystem);
                string rInstallPath = GetRInstallPath(files, _fileSystem);
                list.Add(new RInterpreterInfo($"R '{package.Version}'", rInstallPath, package.Version, package.GetVersion(), _fileSystem));
            }

            return(list);
        }
Exemplo n.º 14
0
        private IEnumerable <IRInterpreterInfo> GetInstalledMRO(IEnumerable <InstalledPackageInfo> packagesInfo, ISupportedRVersionRange svl)
        {
            var list             = new List <IRInterpreterInfo>();
            var selectedPackages = packagesInfo.Where(p => p.PackageName.StartsWithIgnoreCase("microsoft-r-open-mro") && svl.IsCompatibleVersion(p.GetVersion()));

            foreach (var package in selectedPackages)
            {
                var    files        = package.GetPackageFiles(_fileSystem);
                string rInstallPath = GetRInstallPath(files, _fileSystem);
                list.Add(new RInterpreterInfo($"Microsoft R Open '{package.Version}'", rInstallPath, package.Version, package.GetVersion(), _fileSystem));
            }

            return(list);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Tries to determine R installation information. If user-specified path
        /// is supplied, it is used. If not, registry is used. If nothing is found
        /// in the registry, makes attempt to find compatible 64-bit installation
        /// of MRO, RRO or R (in this order) in Program Files folder
        /// </summary>
        /// <param name="basePath">Path as specified by the user settings</param>
        /// <returns></returns>
        public static RInstallData GetInstallationData(
            string basePath,
            ISupportedRVersionRange svl,
            ICoreShell coreShell = null)
        {
            string path = GetRInstallPath(basePath, svl, coreShell);

            // If nothing is found, look into the file system
            if (string.IsNullOrEmpty(path))
            {
                foreach (var f in rFolders)
                {
                    path = TryFindRInProgramFiles(f, svl);
                    if (!string.IsNullOrEmpty(path))
                    {
                        break;
                    }
                }
            }

            // Still nothing? Fail, caller will typically display an error message.
            if (string.IsNullOrEmpty(path))
            {
                return(new RInstallData()
                {
                    Status = RInstallStatus.PathNotSpecified
                });
            }

            // Now verify if files do exist and are of the correct version.
            // There may be cases when R was not fully uninstalled or when
            // version claimed in the registry is not what is really in files.
            RInstallData data = new RInstallData()
            {
                Status = RInstallStatus.OK, Path = path
            };

            // Normalize path so it points to R root and not to bin or bin\x64
            path = NormalizeRPath(path);
            try {
                string rDirectory = Path.Combine(path, @"bin\x64");
                data.BinPath = rDirectory;

                string rDllPath      = Path.Combine(rDirectory, "R.dll");
                string rGraphAppPath = Path.Combine(rDirectory, "Rgraphapp.dll");
                string rTermPath     = Path.Combine(rDirectory, "RTerm.exe");
                string rScriptPath   = Path.Combine(rDirectory, "RScript.exe");
                string rGuiPath      = Path.Combine(rDirectory, "RGui.exe");

                if (FileSystem.FileExists(rDllPath) && FileSystem.FileExists(rTermPath) &&
                    FileSystem.FileExists(rScriptPath) && FileSystem.FileExists(rGraphAppPath) &&
                    FileSystem.FileExists(rGuiPath))
                {
                    IFileVersionInfo fvi = FileSystem.GetVersionInfo(rDllPath);
                    int minor, revision;

                    GetRVersionPartsFromFileMinorVersion(fvi.FileMinorPart, out minor, out revision);
                    data.Version = new Version(fvi.FileMajorPart, minor, revision);

                    if (!svl.IsCompatibleVersion(data.Version))
                    {
                        data.Status = RInstallStatus.UnsupportedVersion;
                    }
                }
                else
                {
                    data.Status = RInstallStatus.NoRBinaries;
                }
            } catch (ArgumentException aex) {
                data.Status    = RInstallStatus.ExceptionAccessingPath;
                data.Exception = aex;
            } catch (IOException ioex) {
                data.Status    = RInstallStatus.ExceptionAccessingPath;
                data.Exception = ioex;
            }

            return(data);
        }
Exemplo n.º 16
0
        private IRInterpreterInfo TryFindRInProgramFiles(ISupportedRVersionRange supportedVersions) {
            // Force 64-bit PF
            var programFiles = Environment.GetEnvironmentVariable("ProgramW6432");
            var baseRFolder = Path.Combine(programFiles, @"R");
            var versions = new List<Version>();
            try {
                if (_fileSystem.DirectoryExists(baseRFolder)) {
                    IEnumerable<IFileSystemInfo> directories = _fileSystem.GetDirectoryInfo(baseRFolder)
                                                                    .EnumerateFileSystemInfos()
                                                                    .Where(x => (x.Attributes & FileAttributes.Directory) != 0);
                    foreach (IFileSystemInfo fsi in directories) {
                        string subFolderName = fsi.FullName.Substring(baseRFolder.Length + 1);
                        Version v = GetRVersionFromFolderName(subFolderName);
                        if (supportedVersions.IsCompatibleVersion(v)) {
                            versions.Add(v);
                        }
                    }
                }
            } catch (IOException) {
                // Don't do anything if there is no RRO installed
            }

            if (versions.Count > 0) {
                versions.Sort();
                Version highest = versions[versions.Count - 1];
                var name = string.Format(CultureInfo.InvariantCulture, "R-{0}.{1}.{2}", highest.Major, highest.Minor, highest.Build);
                var path = Path.Combine(baseRFolder, name);
                var ri = new RInterpreterInfo(name, path);
                if (ri.VerifyInstallation(supportedVersions)) {
                    return ri;
                }
            }

            return null;
        }