Ejemplo n.º 1
0
        /// <summary>
        /// Gets the packages installed locally.
        /// </summary>
        /// <returns>An enumeratior of <see cref="Package"/>.</returns>
        public IEnumerable <Package> GetInstalledPackages()
        {
            var packages = new List <Package> {
                defaultPackage
            };

            if (store != null)
            {
                var log = new LoggerResult();

                var metas = store.Manager.LocalRepository.GetPackages();
                foreach (var meta in metas)
                {
                    var path = store.PathResolver.GetPackageDirectory(meta.Id, meta.Version);

                    var package = Package.Load(log, path, GetDefaultPackageLoadParameters());
                    if (package != null && packages.All(packageRegistered => packageRegistered.Meta.Name != defaultPackage.Meta.Name))
                    {
                        package.IsSystem = true;
                        packages.Add(package);
                    }
                }
            }

            return(packages);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PackageStore"/> class.
        /// </summary>
        /// <exception cref="System.InvalidOperationException">Unable to find a valid Xenko installation path</exception>
        private PackageStore(string installationPath = null, string defaultPackageName = "Xenko", string defaultPackageVersion = XenkoVersion.CurrentAsText)
        {
            // TODO: these are currently hardcoded to Xenko
            DefaultPackageName      = defaultPackageName;
            DefaultPackageVersion   = new PackageVersion(defaultPackageVersion);
            defaultPackageDirectory = DirectoryHelper.GetPackageDirectory(defaultPackageName);

            // 1. Try to use the specified installation path
            if (installationPath != null)
            {
                if (!DirectoryHelper.IsInstallationDirectory(installationPath))
                {
                    throw new ArgumentException("Invalid Xenko installation path [{0}]".ToFormat(installationPath), "installationPath");
                }

                globalInstallationPath = installationPath;
            }

            // 2. Try to resolve an installation path from the path of this assembly
            // We need to be able to use the package manager from an official Xenko install as well as from a developer folder
            if (globalInstallationPath == null)
            {
                globalInstallationPath = DirectoryHelper.GetInstallationDirectory(DefaultPackageName);
            }

            // If there is no root, this is an error
            if (globalInstallationPath == null)
            {
                throw new InvalidOperationException("Unable to find a valid Xenko installation or dev path");
            }

            // Preload default package
            var logger             = new LoggerResult();
            var defaultPackageFile = DirectoryHelper.GetPackageFile(defaultPackageDirectory, DefaultPackageName);

            defaultPackage = Package.Load(logger, defaultPackageFile, GetDefaultPackageLoadParameters());
            if (defaultPackage == null)
            {
                throw new InvalidOperationException("Error while loading default package from [{0}]: {1}".ToFormat(defaultPackageFile, logger.ToText()));
            }
            defaultPackage.IsSystem = true;

            // A flag variable just to know if it is a bare bone development directory
            isDev = defaultPackageDirectory != null && DirectoryHelper.IsRootDevDirectory(defaultPackageDirectory);

            // Check if we are in a root directory with store/packages facilities
            if (NugetStore.IsStoreDirectory(globalInstallationPath))
            {
                packagesDirectory = UPath.Combine(globalInstallationPath, (UDirectory)NugetStore.DefaultGamePackagesDirectory);
                store             = new NugetStore(globalInstallationPath);
            }
            else
            {
                // We should exit from here if NuGet is not configured.
                MessageBox.Show($"Unexpected installation. Cannot find a proper NuGet configuration for [{defaultPackageName}] in [{globalInstallationPath}]", "Installation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(1);
            }
        }
Ejemplo n.º 3
0
        public override bool Execute()
        {
            var result  = new LoggerResult();
            var package = Package.Load(result, File.ItemSpec, new PackageLoadParameters()
            {
                AutoCompileProjects     = false,
                LoadAssemblyReferences  = false,
                AutoLoadTemporaryAssets = false,
            });

            foreach (var message in result.Messages)
            {
                if (message.Type >= LogMessageType.Error)
                {
                    Log.LogError(message.ToString());
                }
                else if (message.Type == LogMessageType.Warning)
                {
                    Log.LogWarning(message.ToString());
                }
                else
                {
                    Log.LogMessage(message.ToString());
                }
            }

            // If we have errors loading the package, exit
            if (result.HasErrors)
            {
                return(false);
            }

            // Override version with task SpecialVersion (if specified by user)
            if (!string.IsNullOrEmpty(SpecialVersion))
            {
                package.Meta.Version = new PackageVersion(package.Meta.Version.Version, SpecialVersion);
            }

            Log.LogMessage(MessageImportance.High, "Packaging [{0}] version [{1}]", package.Meta.Name, package.Meta.Version);

            // Build the package
            PackageArchive.Build(package);
            return(true);
        }
Ejemplo n.º 4
0
        private static Package PreLoadPackage(PackageSession session, ILogger log, string filePath, bool isSystemPackage, PackageCollection loadedPackages, PackageLoadParameters loadParameters)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            if (log == null)
            {
                throw new ArgumentNullException("log");
            }
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }
            if (loadedPackages == null)
            {
                throw new ArgumentNullException("loadedPackages");
            }
            if (loadParameters == null)
            {
                throw new ArgumentNullException("loadParameters");
            }

            try
            {
                var packageId = Package.GetPackageIdFromFile(filePath);

                // Check that the package was not already loaded, otherwise return the same instance
                if (session.Packages.ContainsById(packageId))
                {
                    return(session.Packages.Find(packageId));
                }

                // Package is already loaded, use the instance
                if (loadedPackages.ContainsById(packageId))
                {
                    return(loadedPackages.Find(packageId));
                }

                // Load the package without loading assets
                var newLoadParameters = loadParameters.Clone();
                newLoadParameters.AssemblyContainer = session.assemblyContainer;

                // Load the package
                var package = Package.Load(log, filePath, newLoadParameters);
                package.IsSystem = isSystemPackage;

                // Add the package has loaded before loading dependencies
                loadedPackages.Add(package);

                // Load package dependencies
                PreLoadPackageDependencies(session, log, package, loadedPackages, loadParameters);

                // Add the package to the session but don't freeze it yet
                session.Packages.Add(package);

                // Validate assets from package
                package.ValidateAssets(loadParameters.GenerateNewAssetIds);

                // Freeze the package after loading the assets
                session.FreezePackage(package);

                return(package);
            }
            catch (Exception ex)
            {
                log.Error("Error while pre-loading package [{0}]", ex, filePath);
            }

            return(null);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PackageStore"/> class.
        /// </summary>
        /// <exception cref="System.InvalidOperationException">Unable to find a valid Paradox installation path</exception>
        private PackageStore(string installationPath = null, string defaultPackageName = "Paradox", string defaultPackageVersion = ParadoxVersion.CurrentAsText)
        {
            // 1. Try to use the specified installation path
            if (installationPath != null)
            {
                if (!IsRootDirectory(installationPath))
                {
                    throw new ArgumentException("Invalid Paradox installation path [{0}]".ToFormat(installationPath), "installationPath");
                }

                globalInstallationPath = installationPath;
            }

            // TODO: these are currently hardcoded to Paradox
            DefaultPackageName    = defaultPackageName;
            DefaultPackageVersion = new PackageVersion(defaultPackageVersion);

            // 2. Try to resolve an installation path from the path of this assembly
            // We need to be able to use the package manager from an official Paradox install as well as from a developer folder

            // Try to determine the root package manager from the current assembly
            var thisAssemblyLocation = typeof(PackageStore).Assembly.Location;
            var binDirectory         = !string.IsNullOrWhiteSpace(thisAssemblyLocation) ? new FileInfo(thisAssemblyLocation).Directory : null;

            if (binDirectory != null && binDirectory.Parent != null && binDirectory.Parent.Parent != null)
            {
                var defaultPackageDirectoryTemp = binDirectory.Parent.Parent;

                // If we have a root directory, then store it as the default package directory
                if (IsPackageDirectory(defaultPackageDirectoryTemp.FullName, DefaultPackageName))
                {
                    defaultPackageDirectory = defaultPackageDirectoryTemp.FullName;
                }
                else
                {
                    throw new InvalidOperationException("The current assembly [{0}] is not part of the package [{1}]".ToFormat(thisAssemblyLocation, DefaultPackageName));
                }

                if (globalInstallationPath == null)
                {
                    // Check if we have a regular distribution
                    if (defaultPackageDirectoryTemp.Parent != null && IsRootDirectory(defaultPackageDirectoryTemp.Parent.FullName))
                    {
                        globalInstallationPath = defaultPackageDirectoryTemp.Parent.FullName;
                    }
                    else if (IsRootDirectory(defaultPackageDirectory))
                    {
                        // we have a dev distribution
                        globalInstallationPath = defaultPackageDirectory;
                    }
                }
            }

            // 3. Try from the environement variable
            if (globalInstallationPath == null)
            {
                var rootDirectory = Environment.GetEnvironmentVariable(DefaultEnvironmentSdkDir);
                if (!string.IsNullOrWhiteSpace(rootDirectory) && IsRootDirectory(rootDirectory))
                {
                    globalInstallationPath = rootDirectory;
                    if (defaultPackageDirectory == null)
                    {
                        defaultPackageDirectory = globalInstallationPath;
                    }
                }
            }

            // If there is no root, this is an error
            if (globalInstallationPath == null)
            {
                throw new InvalidOperationException("Unable to find a valid Paradox installation or dev path");
            }

            // Preload default package
            var logger             = new LoggerResult();
            var defaultPackageFile = GetPackageFile(defaultPackageDirectory, DefaultPackageName);

            defaultPackage = Package.Load(logger, defaultPackageFile, GetDefaultPackageLoadParameters());
            if (defaultPackage == null)
            {
                throw new InvalidOperationException("Error while loading default package from [{0}]: {1}".ToFormat(defaultPackageFile, logger.ToText()));
            }
            defaultPackage.IsSystem = true;

            // A flag variable just to know if it is a bare bone development directory
            isDev = defaultPackageDirectory != null && IsRootDevDirectory(defaultPackageDirectory);

            // Check if we are in a root directory with store/packages facilities
            if (NugetStore.IsStoreDirectory(globalInstallationPath))
            {
                packagesDirectory = UPath.Combine(globalInstallationPath, (UDirectory)NugetStore.DefaultGamePackagesDirectory);
                store             = new NugetStore(globalInstallationPath);
            }
        }