示例#1
0
        public static bool VerifyRIsInstalled(ICoreShell coreShell, string path, bool showErrors = true)
        {
            var data = RInstallation.GetInstallationData(path,
                                                         SupportedRVersionList.MinMajorVersion, SupportedRVersionList.MinMinorVersion,
                                                         SupportedRVersionList.MaxMajorVersion, SupportedRVersionList.MaxMinorVersion);

            if (data.Status == RInstallStatus.OK)
            {
                return(true);
            }

            if (showErrors)
            {
                string message = FormatMessage(data);
                coreShell.ShowErrorMessage(message);
                if (data.Status == RInstallStatus.PathNotSpecified || data.Status == RInstallStatus.UnsupportedVersion)
                {
                    RInstallation.GoToRInstallPage();
                }
            }

            return(false);
        }
示例#2
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, int minMajorVersion, int minMinorVersion, int maxMajorVersion, int maxMinorVersion)
        {
            string path = RInstallation.GetRInstallPath(basePath);

            // If nothing is found, look into the file system
            if (String.IsNullOrEmpty(path))
            {
                foreach (var f in rFolders)
                {
                    path = TryFindRInProgramFiles(f, minMajorVersion, minMinorVersion, maxMajorVersion, maxMinorVersion);
                    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 (!SupportedRVersionList.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);
        }