Ejemplo n.º 1
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);
        }