Esempio n. 1
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;
        }
Esempio n. 2
0
        private static string FormatMessage(RInstallData data)
        {
            Debug.Assert(data.Status != RInstallStatus.OK);

            switch (data.Status)
            {
            case RInstallStatus.UnsupportedVersion:
                return(string.Format(CultureInfo.InvariantCulture, Resources.Error_UnsupportedRVersion,
                                     data.Version.Major, data.Version.Minor, data.Version.Build,
                                     SupportedRVersionList.MinMajorVersion, SupportedRVersionList.MinMinorVersion, "*",
                                     SupportedRVersionList.MaxMajorVersion, SupportedRVersionList.MaxMinorVersion, "*"));

            case RInstallStatus.ExceptionAccessingPath:
                return(string.Format(CultureInfo.InvariantCulture, Resources.Error_ExceptionAccessingPath, data.Path, data.Exception.Message));

            case RInstallStatus.NoRBinaries:
                Debug.Assert(!string.IsNullOrEmpty(data.Path));
                return(string.Format(CultureInfo.InvariantCulture, Resources.Error_CannotFindRBinariesFormat, data.Path));

            case RInstallStatus.PathNotSpecified:
                return(string.Format(CultureInfo.InvariantCulture, Resources.Error_UnableToFindR));
            }

            return(String.Empty);
        }
        private static string FormatMessage(RInstallData data) {
            Debug.Assert(data.Status != RInstallStatus.OK);

            switch (data.Status) {
                case RInstallStatus.UnsupportedVersion:
                    return string.Format(CultureInfo.InvariantCulture, Resources.Error_UnsupportedRVersion, 
                        data.Version.Major, data.Version.Minor, data.Version.Build,
                        SupportedRVersionList.MinMajorVersion, SupportedRVersionList.MinMinorVersion, "*",
                        SupportedRVersionList.MaxMajorVersion, SupportedRVersionList.MaxMinorVersion, "*");

                case RInstallStatus.ExceptionAccessingPath:
                    return string.Format(CultureInfo.InvariantCulture, Resources.Error_ExceptionAccessingPath, data.Path, data.Exception.Message);

                case RInstallStatus.NoRBinaries:
                    Debug.Assert(!string.IsNullOrEmpty(data.Path));
                    return string.Format(CultureInfo.InvariantCulture, Resources.Error_CannotFindRBinariesFormat, data.Path);

                case RInstallStatus.PathNotSpecified:
                    return string.Format(CultureInfo.InvariantCulture, Resources.Error_UnableToFindR);
            }

            return String.Empty;
        }
Esempio n. 4
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);
        }