Skip to content
Permalink
Browse files

[Assets] Fix platform updates

  • Loading branch information
xen2 committed Sep 12, 2018
1 parent b894a17 commit 598f4656f7ca7bf16204b17039f61c95c38db0e8
@@ -152,8 +152,17 @@ protected override bool Generate(SessionTemplateGeneratorParameters parameters)
// Add Effects as an asset folder in order to load xksl
package.Profile.AssetFolders.Add(new AssetFolder("Effects"));

var packageParameters = new PackageTemplateGeneratorParameters
{
Name = package.Meta.Name,
OutputDirectory = package.FullPath.GetFullDirectory(),
Description = parameters.Description,
Package = package,
Logger = parameters.Logger,
};

// Generate executable projects for each platform
ProjectTemplateGeneratorHelper.UpdatePackagePlatforms(parameters, platforms, orientation, package.Id, name, package, false);
ProjectTemplateGeneratorHelper.UpdatePackagePlatforms(packageParameters, platforms, orientation, false);

// Add asset packages
CopyAssetPacks(parameters, package);
@@ -59,13 +59,11 @@ public override async Task<bool> PrepareForRun(PackageTemplateGeneratorParameter
return false;
}

// TODO CSPROJ=XKPKG
// If there are no executable/shared projects in this package, we can't work on it
/*var sharedProfile = package.Profile;
var existingPlatformTypesWithExe = new HashSet<PlatformType>(package.Profiles.Where(profile => profile.Platform != PlatformType.Shared && profile.ProjectReferences.Any(projectRef => projectRef.Type == ProjectType.Executable)).Select(item => item.Platform));
if (sharedProfile == null || existingPlatformTypesWithExe.Count == 0)
var existingPlatformTypesWithExe = new HashSet<PlatformType>(AssetRegistry.SupportedPlatforms.Where(x => File.Exists(ProjectTemplateGeneratorHelper.GeneratePlatformProjectLocation(parameters.Name, parameters.Package, x))).Select(x => x.Type));
if (package.Profile.Platform != PlatformType.Shared)
{
parameters.Logger.Error("The selected package does not contain a shared profile with executable projects");
parameters.Logger.Error("The selected package does not contain a shared profile");
return false;
}

@@ -93,7 +91,7 @@ public override async Task<bool> PrepareForRun(PackageTemplateGeneratorParameter
parameters.SetTag(ForcePlatformRegenerationKey, window.ForcePlatformRegeneration);
}
parameters.SetTag(OrientationKey, (DisplayOrientation)gameSettingsAsset.GetOrCreate<RenderingSettings>().DisplayOrientation);
parameters.Namespace = defaultNamespace;*/
parameters.Namespace = defaultNamespace;

return true;
}
@@ -125,7 +123,7 @@ public sealed override bool Run(PackageTemplateGeneratorParameters parameters)

// Generate missing platforms
bool forceGenerating = parameters.GetTag(ForcePlatformRegenerationKey);
ProjectTemplateGeneratorHelper.UpdatePackagePlatforms(parameters, parameters.GetTag(PlatformsKey), parameters.GetTag(OrientationKey), package.Id, name, package, forceGenerating);
ProjectTemplateGeneratorHelper.UpdatePackagePlatforms(parameters, parameters.GetTag(PlatformsKey), parameters.GetTag(OrientationKey), forceGenerating);

// Save the session after the update
// FIXME: Saving like this is not supported anymore - let's not save for now be we should provide a proper way to save!
@@ -488,11 +488,10 @@ public async Task UpdatePackageTemplate(TemplateDescription template)
// Errors might occur when generating the template. For the moment we consider them non-fatal and allow to open the project anyway.
await TemplateGeneratorHelper.RunTemplateGeneratorSafe(generator, parameters, workProgress);

RefreshPackageReferences();
Session.ProcessAddedPackages(loggerResult, workProgress, true);
Session.ProcessRemovedPackages();

await workProgress.NotifyWorkFinished(false, loggerResult.HasErrors);

Package.IsDirty = true;
}

public async Task AddExistingProject()
@@ -1167,21 +1167,13 @@ private async Task NewPackage()
workProgress.ProgressValue = 0;
workProgress.Maximum = session.Projects.OfType<SolutionProject>().Where(x => !packageMap.ContainsValue(x)).Sum(x => x.Package.Assets.Count);

var newPackages = new List<PackageViewModel>();
// This action is uncancellable - In case of errors, we still try to create view models to match what is currently in the PackageSession, but the template has responsibility to clean itself up in case of failure.
// TODO: check what is created here and try to avoid it
foreach (var package in session.Projects.OfType<SolutionProject>().Where(x => !packageMap.ContainsValue(x)))
{
var viewModel = CreateProjectViewModel(package, true);
viewModel.LoadPackageInformation(loggerResult, workProgress);
newPackages.Add(viewModel);
}
ProcessAddedPackages(loggerResult, workProgress, true);

if (CurrentProject == null)
AutoSelectCurrentProject();

ProcessAddedPackages(newPackages);

await workProgress.NotifyWorkFinished(false, loggerResult.HasErrors);
}

@@ -1231,15 +1223,7 @@ private async Task AddExistingPackage()

using (var transaction = UndoRedoService.CreateTransaction())
{
var newPackages = new List<PackageViewModel>();
foreach (var package in session.Projects.OfType<SolutionProject>().Where(x => !packageMap.ContainsValue(x)))
{
var viewModel = CreateProjectViewModel(package, false);
viewModel.LoadPackageInformation(loggerResult, workProgress);
newPackages.Add(viewModel);
}
ProcessAddedPackages(newPackages);

ProcessAddedPackages(loggerResult, workProgress, false);
UndoRedoService.SetName(transaction, $"Import package '{new UFile(packagePath).GetFileNameWithoutExtension()}'");
}

@@ -1248,6 +1232,26 @@ private async Task AddExistingPackage()
}
}

internal void ProcessAddedPackages(LoggerResult loggerResult, WorkProgressViewModel workProgress, bool packageAlreadyInSession)
{
var newPackages = new List<PackageViewModel>();
foreach (var package in session.Projects.OfType<SolutionProject>().Where(x => !packageMap.ContainsValue(x)))
{
var viewModel = CreateProjectViewModel(package, packageAlreadyInSession);
viewModel.LoadPackageInformation(loggerResult, workProgress);
newPackages.Add(viewModel);
}
ProcessAddedPackages(newPackages);
}

internal void ProcessRemovedPackages()
{
foreach (var package in packageMap.Where(x => !session.Projects.Contains(x.Value)))
{
LocalPackages.Remove(package.Key);
}
}

private async void ProcessAddedPackages(IEnumerable<PackageViewModel> packages)
{
var packageList = packages.ToList();
@@ -14,6 +14,7 @@
using Xenko.Graphics;
using Xenko.Shaders.Parser.Mixins;
using Xenko.Core.VisualStudio;
using Xenko.Core.Extensions;

namespace Xenko.Assets.Templates
{
@@ -60,27 +61,49 @@ public static void AddOption(TemplateGeneratorParameters parameters, string opti
return parameters.Tags.TryGetValue(OptionsKey, out options) ? options : new Dictionary<string, object>();
}

public static void UpdatePackagePlatforms(TemplateGeneratorParameters parameters, ICollection<SelectedSolutionPlatform> platforms, DisplayOrientation orientation, Guid sharedProjectGuid, string name, Package package, bool forcePlatformRegeneration)
public static void UpdatePackagePlatforms(PackageTemplateGeneratorParameters packageParameters, ICollection<SelectedSolutionPlatform> platforms, DisplayOrientation orientation, bool forcePlatformRegeneration)
{
if (platforms == null) throw new ArgumentNullException(nameof(platforms));
var logger = parameters.Logger;
var logger = packageParameters.Logger;
var package = packageParameters.Package;
var name = packageParameters.Name;

// Adjust output directory
var parameters = new SessionTemplateGeneratorParameters
{
Logger = logger,
Name = name,
OutputDirectory = package.FullPath.GetFullDirectory().GetParent(),
Session = package.Session,
Description = packageParameters.Description,
};

// Setup the ProjectGameGuid to be accessible from exec (in order to be able to link to the game project.
AddOption(parameters, "ProjectGameGuid", sharedProjectGuid);
AddOption(parameters, "ProjectGameGuid", package.Id);
AddOption(parameters, "ProjectGameRelativePath", (package.Container as SolutionProject)?.FullPath.MakeRelative(parameters.OutputDirectory).ToWindowsPath());
AddOption(parameters, "PackageGameRelativePath", package.FullPath.MakeRelative(parameters.OutputDirectory).ToWindowsPath());

// Add projects
var stepIndex = 0;
var stepCount = platforms.Count + 1;
var projectsToRemove = AssetRegistry.SupportedPlatforms
.Where(platform => !platforms.Select(x => x.Platform).Contains(platform))
.Select(platform =>
{
var projectFullPath = GeneratePlatformProjectLocation(name, package, platform);
return package.Session.Projects.OfType<SolutionProject>().FirstOrDefault(project => project.FullPath == projectFullPath);
})
.NotNull()
.ToList();

foreach (var platform in platforms)
{
stepIndex++;

var projectFullPath = GeneratePlatformProjectLocation(name, package, platform.Platform);
var projectName = projectFullPath.GetFileNameWithoutExtension();

// Don't add a platform that is already in the package
var projectName = Utilities.BuildValidNamespaceName(name) + "." + platform.Platform.Name;
var projectFullPath = UPath.Combine(UPath.Combine(package.RootDirectory.GetParent(), (UDirectory)projectName), (UFile)(projectName + ".csproj"));
var existingProject = package.Session.Projects.OfType<SolutionProject>().FirstOrDefault(x => x.FullPath == projectFullPath);

var projectGuid = Guid.NewGuid();
@@ -119,10 +142,36 @@ public static void UpdatePackagePlatforms(TemplateGeneratorParameters parameters

package.Session.Projects.Add(newExeProject);

package.IsDirty = true;
package.Session.IsDirty = true;
}

foreach (var project in projectsToRemove)
{
var projectFullPath = project.FullPath;
var projectDirectory = Path.GetDirectoryName(projectFullPath.ToWindowsPath());
if (projectDirectory != null && Directory.Exists(projectDirectory))
{
try
{
Directory.Delete(projectDirectory, true);
}
catch (Exception)
{
logger.Warning($"Unable to delete directory [{projectDirectory}]");
}
}

package.Session.Projects.Remove(project);
package.Session.IsDirty = true;
}
}

public static UFile GeneratePlatformProjectLocation(string name, Package package, SolutionPlatform platform)
{
var projectName = Utilities.BuildValidNamespaceName(name) + "." + platform.Name;
return UPath.Combine(UPath.Combine(package.RootDirectory.GetParent(), (UDirectory)projectName), (UFile)(projectName + ".csproj"));
}

public static SolutionProject GenerateTemplate(TemplateGeneratorParameters parameters, ICollection<SelectedSolutionPlatform> platforms, UFile templateRelativePath, string projectName, PlatformType platformType, GraphicsPlatform? graphicsPlatform, ProjectType projectType, DisplayOrientation orientation, Guid? projectGuid = null)
{
AddOption(parameters, "Platforms", platforms.Select(x => x.Platform).ToList());

0 comments on commit 598f465

Please sign in to comment.
You can’t perform that action at this time.