Exemple #1
0
        public override async Task <bool> PrepareForRun(SessionTemplateGeneratorParameters parameters)
        {
            if (parameters is null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            parameters.Validate();

            if (!parameters.Unattended)
            {
                var window = new UpdatePlatformsWindow(new[] { PlatformType.Windows })
                {
                    ForcePlatformRegenerationVisible = false
                };

                await window.ShowModal();

                if (window.Result == DialogResult.Cancel)
                {
                    return(false);
                }

                parameters.SetTag(PlatformsKey, new List <SelectedSolutionPlatform>(window.SelectedPlatforms));
            }

            return(true);
        }
        public override async Task <bool> PrepareForRun(PackageTemplateGeneratorParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            parameters.Validate();

            var package           = parameters.Package;
            var gameSettingsAsset = package.GetGameSettingsAsset();

            if (gameSettingsAsset == null)
            {
                parameters.Logger.Error($"Could not find game settings asset at location [{GameSettingsAsset.GameSettingsLocation}]");
                return(false);
            }

            // If there are no executable/shared projects in this package, we can't work on it
            var existingPlatformTypesWithExe = new HashSet <PlatformType>(AssetRegistry.SupportedPlatforms.Where(x => File.Exists(ProjectTemplateGeneratorHelper.GeneratePlatformProjectLocation(parameters.Name, parameters.Package, x))).Select(x => x.Type));

            if (!(package.Container is SolutionProject project) || project.Platform != PlatformType.Shared)
            {
                parameters.Logger.Error("The selected package does not contain a shared profile");
                return(false);
            }

            var defaultNamespace = GetDefaultNamespace(parameters);

            if (parameters.Unattended)
            {
                if (!parameters.HasTag(PlatformsKey))
                {
                    throw new InvalidOperationException("The platforms must be set with SetPlatforms before calling PrepareForRun if DontAskForPlatforms is true.");
                }
                parameters.SetTag(ForcePlatformRegenerationKey, true);
            }
            else
            {
                var window = new UpdatePlatformsWindow(existingPlatformTypesWithExe)
                {
                    ForcePlatformRegenerationVisible = parameters.TryGetTag(ForcePlatformRegenerationKey)
                };

                await window.ShowModal();

                if (window.Result == DialogResult.Cancel)
                {
                    return(false);
                }

                parameters.SetTag(PlatformsKey, new List <SelectedSolutionPlatform>(window.SelectedPlatforms));
                parameters.SetTag(ForcePlatformRegenerationKey, window.ForcePlatformRegeneration);
            }
            parameters.SetTag(OrientationKey, (DisplayOrientation)gameSettingsAsset.GetOrCreate <RenderingSettings>().DisplayOrientation);
            parameters.Namespace = defaultNamespace;

            return(true);
        }