コード例 #1
0
        private static MessageButtons ShowMessage(ICoreShell coreShell, RInstallData data, ISupportedRVersionRange svl)
        {
            Debug.Assert(data.Status != RInstallStatus.OK);

            switch (data.Status)
            {
            case RInstallStatus.UnsupportedVersion:
                return(coreShell.ShowMessage(
                           string.Format(CultureInfo.InvariantCulture, Resources.Error_UnsupportedRVersion,
                                         data.Version.Major, data.Version.Minor, data.Version.Build,
                                         svl.MinMajorVersion, svl.MinMinorVersion, "*",
                                         svl.MaxMajorVersion, svl.MaxMinorVersion, "*",
                                         Environment.NewLine + Environment.NewLine),
                           MessageButtons.YesNo));

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

            case RInstallStatus.NoRBinaries:
                return(coreShell.ShowMessage(
                           string.Format(CultureInfo.InvariantCulture, Resources.Error_CannotFindRBinariesFormat,
                                         data.Path, Environment.NewLine + Environment.NewLine, Environment.NewLine),
                           MessageButtons.YesNo));

            case RInstallStatus.PathNotSpecified:
                return(coreShell.ShowMessage(string.Format(CultureInfo.InvariantCulture,
                                                           Resources.Error_UnableToFindR, Environment.NewLine + Environment.NewLine), MessageButtons.YesNo));
            }
            return(MessageButtons.OK);
        }
コード例 #2
0
ファイル: RInstallation.cs プロジェクト: CarlosMeloStuff/RTVS
        /// <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)
        {
            string path = GetRInstallPath(basePath, svl);

            // 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);
        }