public FrameworkFinder(bool is64Bit)
        {
            string installFolder = GetInstallFolder(is64Bit);
            var    sharedFolder  = Path.Combine(installFolder, "dotnet/shared");

            if (!Directory.Exists(sharedFolder))
            {
                return;
            }

            var frameworkFolders = Directory.GetDirectories(sharedFolder);

            foreach (var folder in frameworkFolders)
            {
                var versions  = Directory.GetDirectories(folder);
                var framework = Path.GetFileName(folder);

                _frameworks[framework] = versions.Select(x =>
                {
                    var version = new NuGetVersion(Path.GetFileName(x));
                    var config  = Actions.TryGetValue(() => RuntimeOptions.FromFile($"{x}//{framework}.runtimeconfig.json"));
                    return(new FrameworkOptionsTuple(new Framework(framework, version.ToString()), config, x));
                }).ToArray();
            }
        }
Esempio n. 2
0
    /// <summary>
    /// Gets all URLs to missing runtime files.
    /// </summary>
    /// <param name="reloadedFolderPath">Folder path for an application, library will check every runtimeconfig.json inside this folder.</param>
    public static async Task <HashSet <UrlCommandlinePair> > GetMissingRuntimeUrls(string reloadedFolderPath)
    {
        var allFiles = Directory.GetFiles(reloadedFolderPath, "*.*", SearchOption.AllDirectories);
        var filesWithRuntimeConfigs = allFiles.Where(x => x.EndsWith(".runtimeconfig.json")).ToArray();

        // Now that we have the runtime config files, get all missing deps from them.
        var urlSet = new HashSet <UrlCommandlinePair>();
        var dotNetCommandLineParams = new string[]
        {
            "/install",
            "/quiet",
            "/norestart"
        };

        foreach (var is64Bit in new[] { true, false })
        {
            var architecture = is64Bit ? Architecture.Amd64 : Architecture.x86;
            var finder       = new FrameworkFinder(is64Bit);
            var resolver     = new DependencyResolver(finder);
            foreach (var runtimeConfig in filesWithRuntimeConfigs)
            {
                var runtimeOptions = RuntimeOptions.FromFile(runtimeConfig);
                var result         = resolver.Resolve(runtimeOptions);;
                foreach (var missingDep in result.MissingDependencies)
                {
                    var frameworkDownloader = new FrameworkDownloader(runtimeOptions.GetAllFrameworks()[0].NuGetVersion, missingDep.FrameworkName);
                    urlSet.Add(new UrlCommandlinePair()
                    {
                        FriendlyName = $".NET Core {runtimeOptions.GetAllFrameworks()[0].Version} {architecture}",
                        Url          = await frameworkDownloader.GetDownloadUrlAsync(architecture),
                        Parameters   = dotNetCommandLineParams
                    });
                }
            }
        }

        // Also check for C++ Runtime.
        if (!RedistributablePackage.IsInstalled(RedistributablePackageVersion.VC2015to2019x64))
        {
            urlSet.Add(new UrlCommandlinePair()
            {
                FriendlyName = "Visual C++ Redist x64",
                Url          = "https://aka.ms/vs/17/release/vc_redist.x64.exe",
                Parameters   = dotNetCommandLineParams
            });
        }

        if (!RedistributablePackage.IsInstalled(RedistributablePackageVersion.VC2015to2019x86))
        {
            urlSet.Add(new UrlCommandlinePair()
            {
                FriendlyName = "Visual C++ Redist x86",
                Url          = "https://aka.ms/vs/17/release/vc_redist.x86.exe",
                Parameters   = dotNetCommandLineParams
            });
        }

        return(urlSet);
    }
    /// <summary>
    /// Attempts to get the runtime options for a DLL or EXE by finding a runtime configuration file.
    /// </summary>
    /// <param name="dllPath">Full path to a given DLL or exe.</param>
    /// <returns>Options if succeeded, else throws.</returns>
    private RuntimeOptions GetRuntimeOptionsForDll(string dllPath)
    {
        if (string.IsNullOrEmpty(dllPath))
        {
            throw new ArgumentException("Given DLL Path is null or empty.");
        }

        if (!File.Exists(dllPath))
        {
            throw new ArgumentException("Given DLL does not exist.");
        }

        var configFilePath = Path.ChangeExtension(dllPath, "runtimeconfig.json");

        if (!File.Exists(configFilePath))
        {
            throw new FileNotFoundException("Configuration file (runtimeconfig.json) not found for given DLL.");
        }

        return(RuntimeOptions.FromFile(configFilePath));
    }
Esempio n. 4
0
        private void LoadRuntimeOptions()
        {
            try
            {
                if (FileManager.FileExists(FileWindow.ApplicationFolderForThisProgram + @"RuntimeOptions.xml"))
                {
                    mRuntimeOptions = RuntimeOptions.FromFile(FileWindow.ApplicationFolderForThisProgram + @"RuntimeOptions.xml");

                    // It's possible the runtime options may have a 0 width or height.  If so, let's fix that here
                    if (mRuntimeOptions.WindowHeight <= 1)
                    {
                        mRuntimeOptions.WindowHeight = 480;
                    }
                    if (mRuntimeOptions.WindowWidth <= 1)
                    {
                        mRuntimeOptions.WindowWidth = 640;
                    }


                    this.Size = new System.Drawing.Size(
                        mRuntimeOptions.WindowWidth,
                        mRuntimeOptions.WindowHeight);

                    if (mRuntimeOptions.FullScreen)
                    {
                        this.WindowState = FormWindowState.Maximized;
                    }



                    OnResize(true);
                }
            }
            catch (Exception e)
            {
                // Who cares, not a big deal, just carry on
            }
        }