Beispiel #1
0
        /// <summary>
        /// Gets the xenko SDK dir.
        /// </summary>
        /// <returns></returns>
        internal static async Task <PackageInfo> FindXenkoSdkDir(string solution, string packageName = "Xenko.VisualStudio.Commands")
        {
            // Resolve the sdk version to load from the solution's package
            var packageInfo = new PackageInfo {
                ExpectedVersion = await PackageSessionHelper.GetPackageVersion(solution), SdkPaths = new List <string>()
            };

            // Check if we are in a root directory with store/packages facilities
            var store = new NugetStore(null);
            NugetLocalPackage xenkoPackage = null;

            // Try to find the package with the expected version
            if (packageInfo.ExpectedVersion != null && packageInfo.ExpectedVersion >= MinimumVersion)
            {
                // Xenko up to 3.0
                if (packageInfo.ExpectedVersion < new PackageVersion(3, 1, 0, 0))
                {
                    xenkoPackage = store.GetPackagesInstalled(new[] { "Xenko" }).FirstOrDefault(package => package.Version == packageInfo.ExpectedVersion);
                    if (xenkoPackage != null)
                    {
                        var xenkoSdkDir = store.GetRealPath(xenkoPackage);

                        packageInfo.LoadedVersion = xenkoPackage.Version;

                        foreach (var path in new[]
                        {
                            // Xenko 2.x and 3.0
                            @"Bin\Windows\Direct3D11",
                            @"Bin\Windows",
                            // Xenko 1.x
                            @"Bin\Windows-Direct3D11"
                        })
                        {
                            var fullPath = Path.Combine(xenkoSdkDir, path);
                            if (Directory.Exists(fullPath))
                            {
                                packageInfo.SdkPaths.AddRange(Directory.EnumerateFiles(fullPath, "*.dll", SearchOption.TopDirectoryOnly));
                                packageInfo.SdkPaths.AddRange(Directory.EnumerateFiles(fullPath, "*.exe", SearchOption.TopDirectoryOnly));
                            }
                        }
                    }
                }
                // Xenko 3.1+
                else
                {
                    var logger = new Logger();
                    var(request, result) = await RestoreHelper.Restore(logger, packageName, new VersionRange(packageInfo.ExpectedVersion.ToNuGetVersion()));

                    if (result.Success)
                    {
                        packageInfo.SdkPaths.AddRange(RestoreHelper.ListAssemblies(request, result));
                        packageInfo.LoadedVersion = packageInfo.ExpectedVersion;
                    }
                }
            }

            return(packageInfo);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the xenko SDK dir.
        /// </summary>
        /// <returns></returns>
        private static PackageInfo FindXenkoSdkDir()
        {
            // Resolve the sdk version to load from the solution's package
            var packageInfo = new PackageInfo {
                ExpectedVersion = PackageSessionHelper.GetPackageVersion(solution)
            };

            // TODO: Maybe move it in some common class somewhere? (in this case it would be included with "Add as link" in VSPackage)
            var xenkoSdkDir = Environment.GetEnvironmentVariable("SiliconStudioXenkoDir");

            // Failed to locate xenko
            if (xenkoSdkDir == null)
            {
                return(packageInfo);
            }

            // If we are in a dev directory, assume we have the right version
            if (File.Exists(Path.Combine(xenkoSdkDir, "build\\Xenko.sln")))
            {
                packageInfo.SdkPath       = xenkoSdkDir;
                packageInfo.LoadedVersion = packageInfo.ExpectedVersion;
                return(packageInfo);
            }

            // Check if we are in a root directory with store/packages facilities
            if (NugetStore.IsStoreDirectory(xenkoSdkDir))
            {
                var      store        = new NugetStore(xenkoSdkDir);
                IPackage xenkoPackage = null;

                // Try to find the package with the expected version
                if (packageInfo.ExpectedVersion != null && packageInfo.ExpectedVersion >= MinimumVersion)
                {
                    xenkoPackage = store.GetPackagesInstalled(store.MainPackageIds).FirstOrDefault(package => GetVersion(package) == packageInfo.ExpectedVersion);
                }

                // If the expected version is not found, get the latest package
                if (xenkoPackage == null)
                {
                    xenkoPackage = store.GetLatestPackageInstalled(store.MainPackageIds);
                }

                // If no package was found, return no sdk path
                if (xenkoPackage == null)
                {
                    return(packageInfo);
                }

                // Return the loaded version and the sdk path
                var packageDirectory = store.PathResolver.GetPackageDirectory(xenkoPackage);
                packageInfo.LoadedVersion = GetVersion(xenkoPackage);
                packageInfo.SdkPath       = Path.Combine(xenkoSdkDir, store.RepositoryPath, packageDirectory);
            }

            return(packageInfo);
        }
Beispiel #3
0
        /// <summary>
        /// Gets the xenko SDK dir.
        /// </summary>
        /// <param name="xenkoVersion">The xenko version. If null, it will get latest version.</param>
        /// <returns></returns>
        public static string FindXenkoSdkDir(string xenkoVersion = null)
        {
            // TODO: Almost duplicate of XenkoCommandsProxy.FindXenkoSdkDir!!
            // TODO: Maybe move it in some common class somewhere? (in this case it would be included with "Add as link" in VSPackage)
            var xenkoSdkDir = DirectoryHelper.GetInstallationDirectory("Xenko");

            if (xenkoSdkDir == null)
            {
                xenkoSdkDir = Environment.GetEnvironmentVariable("SiliconStudioXenkoDir");
            }

            if (xenkoSdkDir == null)
            {
                return(null);
            }

            // Check if it is a dev directory
            if (File.Exists(Path.Combine(xenkoSdkDir, "build\\Xenko.sln")))
            {
                return(xenkoSdkDir);
            }

            // Check if we are in a root directory with store/packages facilities
            if (NugetStore.IsStoreDirectory(xenkoSdkDir))
            {
                var store = new NugetStore(xenkoSdkDir);

                var xenkoPackages = store.GetPackagesInstalled(store.MainPackageIds);
                // Convert the provided xenko version into a valid package version
                PackageVersion packageVersion;
                PackageVersion.TryParse(xenkoVersion, out packageVersion);
                // Retrieve the corresponding package, if it exists
                var xenkoPackage = packageVersion != null
                    ? (xenkoPackages.FirstOrDefault(p => p.Version == packageVersion)
                       ?? xenkoPackages.FirstOrDefault(p => p.Version.Version == packageVersion.Version)) // If no exact match, try a second time without the special version tag (beta, alpha, etc...)
                    : xenkoPackages.FirstOrDefault();
                if (xenkoPackage == null)
                {
                    return(null);
                }

                var packageDirectory = store.GetPackageDirectory(xenkoPackage);
                return(Path.Combine(xenkoSdkDir, store.RepositoryPath, packageDirectory));
            }

            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// Gets the paradox SDK dir.
        /// </summary>
        /// <param name="paradoxVersion">The paradox version. If null, it will get latest version.</param>
        /// <returns></returns>
        public static string FindParadoxSdkDir(string paradoxVersion = null)
        {
            // TODO: Almost duplicate of ParadoxCommandsProxy.FindParadoxSdkDir!!
            // TODO: Maybe move it in some common class somewhere? (in this case it would be included with "Add as link" in VSPackage)
            var paradoxSdkDir = DirectoryHelper.GetInstallationDirectory("Paradox");

            if (paradoxSdkDir == null)
            {
                paradoxSdkDir = Environment.GetEnvironmentVariable("SiliconStudioParadoxDir");
            }

            if (paradoxSdkDir == null)
            {
                return(null);
            }

            // Check if it is a dev directory
            if (File.Exists(Path.Combine(paradoxSdkDir, "build\\Paradox.sln")))
            {
                return(paradoxSdkDir);
            }

            // Check if we are in a root directory with store/packages facilities
            if (NugetStore.IsStoreDirectory(paradoxSdkDir))
            {
                var store = new NugetStore(paradoxSdkDir);

                var paradoxPackages = store.GetPackagesInstalled(store.MainPackageId);
                var paradoxPackage  = paradoxVersion != null
                    ? (paradoxPackages.FirstOrDefault(p => p.Version.ToString() == paradoxVersion)
                       ?? paradoxPackages.FirstOrDefault(p => VersionWithoutSpecialPart(p.Version.ToString()) == VersionWithoutSpecialPart(paradoxVersion)))  // If no exact match, try a second time without the special version tag (beta, alpha, etc...)
                    : paradoxPackages.FirstOrDefault();
                if (paradoxPackage == null)
                {
                    return(null);
                }

                var packageDirectory = store.PathResolver.GetPackageDirectory(paradoxPackage);
                return(Path.Combine(paradoxSdkDir, store.RepositoryPath, packageDirectory));
            }

            return(null);
        }
Beispiel #5
0
        public async Task RetrieveLocalXenkoVersions()
        {
            List <RecentProjectViewModel> currentRecentProjects;

            lock (RecentProjects)
            {
                currentRecentProjects = new List <RecentProjectViewModel>(RecentProjects);
            }
            try
            {
                var localPackages = await RunLockTask(() => store.GetPackagesInstalled(store.MainPackageIds).OrderByDescending(p => p.Version).ToList());

                lock (objectLock)
                {
                    // Retrieve all local packages
                    var packages             = localPackages.Where(p => !store.IsDevRedirectPackage(p)).GroupBy(p => $"{p.Version.Version.Major}.{p.Version.Version.Minor}", p => p);
                    var updatedLocalPackages = new HashSet <XenkoStoreVersionViewModel>();
                    foreach (var package in packages)
                    {
                        var localPackage = package.FirstOrDefault();
                        if (localPackage != null)
                        {
                            // Find if we already have this package in our list
                            int index = xenkoVersions.BinarySearch(Tuple.Create(localPackage.Version.Version.Major, localPackage.Version.Version.Minor));
                            XenkoStoreVersionViewModel version;
                            if (index < 0)
                            {
                                // If not, add it
                                version = new XenkoStoreVersionViewModel(this, store, localPackage, localPackage.Version.Version.Major, localPackage.Version.Version.Minor);
                                Dispatcher.Invoke(() => xenkoVersions.Add(version));
                            }
                            else
                            {
                                version = (XenkoStoreVersionViewModel)xenkoVersions[index];
                            }
                            version.UpdateLocalPackage(localPackage);
                            updatedLocalPackages.Add(version);
                        }
                    }

                    // Update versions that are not installed locally anymore
                    Dispatcher.Invoke(() =>
                    {
                        foreach (var xenkoUninstalledVersion in xenkoVersions.OfType <XenkoStoreVersionViewModel>().Where(x => !updatedLocalPackages.Contains(x)))
                        {
                            xenkoUninstalledVersion.UpdateLocalPackage(null);
                        }
                    });

                    // Update the active version if it is now invalid.
                    if (ActiveVersion == null || !xenkoVersions.Contains(ActiveVersion) || !ActiveVersion.CanDelete)
                    {
                        ActiveVersion = XenkoVersions.FirstOrDefault(x => x.CanDelete);
                    }

                    if (!lastActiveVersionRestored)
                    {
                        var restoredVersion = XenkoVersions.FirstOrDefault(x => x.CanDelete && x.Name == LauncherSettings.ActiveVersion);
                        if (restoredVersion != null)
                        {
                            ActiveVersion             = restoredVersion;
                            lastActiveVersionRestored = true;
                        }
                    }
                }

                var devPackages = localPackages.Where(store.IsDevRedirectPackage);
                Dispatcher.Invoke(() => xenkoVersions.RemoveWhere(x => x is XenkoDevVersionViewModel));
                foreach (var package in devPackages)
                {
                    try
                    {
                        var realPath = File.ReadAllText(store.GetRedirectFile(package));
                        if (!Directory.Exists(realPath))
                        {
                            throw new DirectoryNotFoundException();
                        }
                        var version = new XenkoDevVersionViewModel(this, store, package, realPath, true);
                        Dispatcher.Invoke(() => xenkoVersions.Add(version));
                    }
                    catch (Exception e)
                    {
                        await ServiceProvider.Get <IDialogService>().MessageBox(string.Format(Strings.ErrorDevRedirect, e), MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
            }
            catch (Exception e)
            {
                // TODO: error
                e.Ignore();
            }
            finally
            {
                Dispatcher.Invoke(() =>
                {
                    foreach (var project in currentRecentProjects)
                    {
                        // Manually discarding the possibility to upgrade from 1.0
                        if (project.XenkoVersionName == "1.0")
                        {
                            continue;
                        }

                        project.CompatibleVersions.Clear();
                        foreach (var version in XenkoVersions)
                        {
                            // We suppose all dev versions are compatible with any project.
                            if (version is XenkoDevVersionViewModel)
                            {
                                project.CompatibleVersions.Add(version);
                            }

                            var storeVersion = version as XenkoStoreVersionViewModel;
                            if (storeVersion != null && storeVersion.CanDelete)
                            {
                                // Discard the version that matches the recent project version
                                if (project.XenkoVersion == new Version(storeVersion.Version.Version.Major, storeVersion.Version.Version.Minor))
                                {
                                    continue;
                                }

                                // Discard the versions that are anterior to the recent project version
                                if (project.XenkoVersion > storeVersion.Version.Version)
                                {
                                    continue;
                                }

                                project.CompatibleVersions.Add(version);
                            }
                        }
                    }
                });
            }
        }
Beispiel #6
0
        /// <summary>
        /// Gets the stride SDK dir.
        /// </summary>
        /// <returns></returns>
        internal static async Task <PackageInfo> FindStrideSdkDir(string solution, string packageName = "Stride.VisualStudio.Commands")
        {
            // Resolve the sdk version to load from the solution's package
            var packageInfo = new PackageInfo {
                ExpectedVersion = await PackageSessionHelper.GetPackageVersion(solution), SdkPaths = new List <string>()
            };

            // Check if we are in a root directory with store/packages facilities
            var store = new NugetStore(null);
            NugetLocalPackage stridePackage = null;

            // Try to find the package with the expected version
            if (packageInfo.ExpectedVersion != null && packageInfo.ExpectedVersion >= MinimumVersion)
            {
                // Stride up to 3.0
                if (packageInfo.ExpectedVersion < new PackageVersion(3, 1, 0, 0))
                {
                    stridePackage = store.GetPackagesInstalled(new[] { "Stride" }).FirstOrDefault(package => package.Version == packageInfo.ExpectedVersion);
                    if (stridePackage != null)
                    {
                        var strideSdkDir = store.GetRealPath(stridePackage);

                        packageInfo.LoadedVersion = stridePackage.Version;

                        foreach (var path in new[]
                        {
                            // Stride 2.x and 3.0
                            @"Bin\Windows\Direct3D11",
                            @"Bin\Windows",
                            // Stride 1.x
                            @"Bin\Windows-Direct3D11"
                        })
                        {
                            var fullPath = Path.Combine(strideSdkDir, path);
                            if (Directory.Exists(fullPath))
                            {
                                packageInfo.SdkPaths.AddRange(Directory.EnumerateFiles(fullPath, "*.dll", SearchOption.TopDirectoryOnly));
                                packageInfo.SdkPaths.AddRange(Directory.EnumerateFiles(fullPath, "*.exe", SearchOption.TopDirectoryOnly));
                            }
                        }
                    }
                }
                // Stride 3.1+
                else
                {
                    var logger = new Logger();
                    var(request, result) = await RestoreHelper.Restore(logger, NuGetFramework.ParseFrameworkName(".NETFramework,Version=v4.7.2", DefaultFrameworkNameProvider.Instance), "win", packageName, new VersionRange(packageInfo.ExpectedVersion.ToNuGetVersion()));

                    if (result.Success)
                    {
                        packageInfo.SdkPaths.AddRange(RestoreHelper.ListAssemblies(request, result));
                        packageInfo.LoadedVersion = packageInfo.ExpectedVersion;
                    }
                    else
                    {
                        MessageBox.Show($"Could not restore {packageName} {packageInfo.ExpectedVersion}, this visual studio extension may fail to work properly without it."
                                        + $"To fix this you can either build {packageName} or pull the right version from nugget manually");
                        throw new InvalidOperationException($"Could not restore {packageName} {packageInfo.ExpectedVersion}.");
                    }
                }
            }

            return(packageInfo);
        }