Skip to content
Permalink
Browse files

[Launcher] Stay compatible with Xenko 1.x/2.x

  • Loading branch information
xen2 committed Dec 11, 2018
1 parent c5ed27a commit ec0771e60f4083bd9b4c4791baebfaacac32dd30
@@ -41,11 +41,6 @@ namespace Xenko.Core.Packages
/// </summary>
public class NugetStore : INugetDownloadProgress
{
private const string DefaultTargets = @"Targets\Xenko.Common.targets";
private const string DefaultTargetsOld = @"Targets\SiliconStudio.Common.targets";

public const string DefaultGamePackagesDirectory = "GamePackages";

public const string MainExecutables = @"lib\net472\Xenko.GameStudio.exe,Bin\Windows\Xenko.GameStudio.exe,Bin\Windows-Direct3D11\Xenko.GameStudio.exe";
public const string PrerequisitesInstaller = @"Bin\Prerequisites\install-prerequisites.exe";

@@ -55,14 +50,19 @@ public class NugetStore : INugetDownloadProgress
private readonly ISettings settings, localSettings;
private ProgressReport currentProgressReport;

private readonly string oldRootDirectory;

private static Regex powerShellProgressRegex = new Regex(@".*\[ProgressReport:\s*(\d*)%\].*");

/// <summary>
/// Initialize a new instance of <see cref="NugetStore"/>.
/// </summary>
/// <param name="rootDirectory">The location of the Nuget store.</param>
public NugetStore(string rootDirectory)
/// <param name="oldRootDirectory">The location of the Nuget store.</param>
public NugetStore(string oldRootDirectory)
{
// Used only for versions before 3.0
this.oldRootDirectory = oldRootDirectory;

settings = NuGet.Configuration.Settings.LoadDefaultSettings(null);

// Add dev source
@@ -71,7 +71,7 @@ public NugetStore(string rootDirectory)
InstallPath = SettingsUtility.GetGlobalPackagesFolder(settings);

var pathContext = NuGetPathContext.Create(settings);
InstalledPathResolver = new FallbackPackagePathResolver(pathContext);
InstalledPathResolver = new FallbackPackagePathResolver(pathContext.UserPackageFolder, oldRootDirectory != null ? pathContext.FallbackPackageFolders.Concat(new[] { oldRootDirectory }) : pathContext.FallbackPackageFolders);
var packageSourceProvider = new PackageSourceProvider(settings);

var availableSources = packageSourceProvider.LoadPackageSources().Where(source => source.IsEnabled);
@@ -189,11 +189,19 @@ public IEnumerable<NugetLocalPackage> GetLocalPackages(string packageId)
{
var res = new List<NugetLocalPackage>();

var localResource = new FindLocalPackagesResourceV3(InstallPath);
var packages = localResource.FindPackagesById(packageId, NativeLogger, CancellationToken.None);
foreach (var package in packages)
// We also scan rootDirectory for 1.x/2.x
foreach (var installPath in new[] { InstallPath, oldRootDirectory })
{
res.Add(new NugetLocalPackage(package));
// oldRootDirectory might be null
if (installPath == null)
continue;

var localResource = new FindLocalPackagesResourceV3(installPath);
var packages = localResource.FindPackagesById(packageId, NativeLogger, CancellationToken.None);
foreach (var package in packages)
{
res.Add(new NugetLocalPackage(package));
}
}

return res;
@@ -289,6 +297,12 @@ public async Task<NugetLocalPackage> InstallPackage(string packageId, PackageVer
{
var installPath = SettingsUtility.GetGlobalPackagesFolder(settings);

// Old version expects to be installed in GamePackages
if (packageId == "Xenko" && version < new PackageVersion(3, 0, 0, 0) && oldRootDirectory != null)
{
installPath = oldRootDirectory;
}

var specPath = Path.Combine("TestProject", "project.json");
var spec = new PackageSpec()
{
@@ -340,6 +354,11 @@ public async Task<NugetLocalPackage> InstallPackage(string packageId, PackageVer
}
}
}

if (packageId == "Xenko" && version < new PackageVersion(3, 0, 0, 0))
{
UpdateTargetsHelper();
}
}

// Load the recently installed package
@@ -397,6 +416,11 @@ public async Task UninstallPackage(NugetPackage package, ProgressReport progress
//{
// currentProgressReport = null;
//}

if (package.Id == "Xenko" && package.Version < new PackageVersion(3, 0, 0, 0))
{
UpdateTargetsHelper();
}
}
finally
{
@@ -736,6 +760,29 @@ private static void RunPackageInstall(string packageInstall, string arguments, P
}
}

// Used only for Xenko 1.x and 2.x
private void UpdateTargetsHelper()
{
if (oldRootDirectory == null)
return;

// Get latest package only for each MainPackageIds (up to 2.x)
var xenkoOldPackages = GetLocalPackages("Xenko").Where(package => !((package.Tags != null) && package.Tags.Contains("internal"))).Where(x => x.Version.Version.Major < 3).ToList();

// Generate target file
var targetGenerator = new TargetGenerator(this, xenkoOldPackages, "SiliconStudioPackage");
var targetFileContent = targetGenerator.TransformText();
var targetFile = Path.Combine(oldRootDirectory, @"Targets\SiliconStudio.Common.targets");

var targetFilePath = Path.GetDirectoryName(targetFile);

// Make sure directory exists
if (targetFilePath != null && !Directory.Exists(targetFilePath))
Directory.CreateDirectory(targetFilePath);

File.WriteAllText(targetFile, targetFileContent, Encoding.UTF8);
}

private class PackagePathResolverV3 : PackagePathResolver
{
private VersionFolderPathResolver pathResolver;
@@ -98,7 +98,7 @@ public virtual string TransformText()
// List all the correspondances: Major.minor -> latest installed explicit version

// Get all the related versions of the same package also installed, and order by Major.Minor
var allMajorVersions = store.GetLocalPackages(package.Id).GroupBy(p => p.Version.Version.Major, p => p);
var allMajorVersions = store.GetLocalPackages(package.Id).Where(p => p.Version.Version.Major < 3).GroupBy(p => p.Version.Version.Major, p => p);
foreach (var major in allMajorVersions)
{
var majorVersion = major.Key;
@@ -294,7 +294,7 @@ public virtual string TransformText()
foreach (var package in packages)
{
var packageVar = NugetStore.GetPackageVersionVariable(package.Id, packageVersionPrefix);
foreach (var packageVersion in store.GetLocalPackages(package.Id))
foreach (var packageVersion in store.GetLocalPackages(package.Id).Where(p => p.Version.Version.Major < 3))
{
var packageTarget = String.Format(@"{0}\Targets\{1}.targets", packageVersion.Path, packageVersion.Id);

@@ -18,7 +18,7 @@
<# // List all the correspondances: Major.minor -> latest installed explicit version

// Get all the related versions of the same package also installed, and order by Major.Minor
var allMajorVersions = store.GetLocalPackages(package.Id).GroupBy(p => p.Version.Version.Major, p => p);
var allMajorVersions = store.GetLocalPackages(package.Id).Where(p => p.Version.Version.Major < 3).GroupBy(p => p.Version.Version.Major, p => p);
foreach (var major in allMajorVersions)
{
var majorVersion = major.Key;
@@ -45,7 +45,7 @@
<# foreach (var package in packages)
{
var packageVar = NugetStore.GetPackageVersionVariable(package.Id, packageVersionPrefix);
foreach (var packageVersion in store.GetLocalPackages(package.Id))
foreach (var packageVersion in store.GetLocalPackages(package.Id).Where(p => p.Version.Version.Major < 3))
{
var packageTarget = String.Format(@"{0}\Targets\{1}.targets", packageVersion.Path, packageVersion.Id); #>
<Import Project="<#=packageTarget#>" Condition="Exists('<#=packageTarget#>') And '$(<#=packageVar#>)' == '<#=packageVersion.Version.ToNuGetVersion().ToNormalizedString()#>'" />

0 comments on commit ec0771e

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