Skip to content
Permalink
Browse files

[Launcher] Allow to select Xenko version

  • Loading branch information
xen2 committed Jun 23, 2019
1 parent b2a4491 commit f4d406cede1875f23886a110d64e14fef21f0566

Some generated files are not rendered by default. Learn more.

@@ -422,4 +422,8 @@
<value>Open '{0}'</value>
<comment>The tooltip for website links.</comment>
</data>
</root>
<data name="InstallVersion" xml:space="preserve">
<value>Install {0}</value>
<comment>{0}: long version name</comment>
</data>
</root>
Git LFS file not shown
@@ -93,7 +93,7 @@ public void Dispose()

public VsixVersionViewModel VsixPackage { get; }

public XenkoVersionViewModel ActiveVersion { get { return activeVersion; } set { SetValue(ref activeVersion, value, () => Dispatcher.InvokeAsync(() => StartStudioCommand.IsEnabled = (value != null))); } }
public XenkoVersionViewModel ActiveVersion { get { return activeVersion; } set { SetValue(ref activeVersion, value); Dispatcher.InvokeAsync(() => StartStudioCommand.IsEnabled = (value != null) && value.CanStart); } }

public ObservableList<RecentProjectViewModel> RecentProjects { get; } = new ObservableList<RecentProjectViewModel>();

@@ -195,7 +195,6 @@ public async Task RetrieveAllXenkoVersions()
await RetrieveLocalXenkoVersions();
await RetrieveServerXenkoVersions();
Dispatcher.Invoke(() => IsSynchronizing = false);

}

public async Task RetrieveLocalXenkoVersions()
@@ -231,7 +230,7 @@ public async Task RetrieveLocalXenkoVersions()
{
version = (XenkoStoreVersionViewModel)xenkoVersions[index];
}
version.UpdateLocalPackage(localPackage);
version.UpdateLocalPackage(localPackage, package);
updatedLocalPackages.Add(version);
}
}
@@ -240,7 +239,7 @@ public async Task RetrieveLocalXenkoVersions()
Dispatcher.Invoke(() =>
{
foreach (var xenkoUninstalledVersion in xenkoVersions.OfType<XenkoStoreVersionViewModel>().Where(x => !updatedLocalPackages.Contains(x)))
xenkoUninstalledVersion.UpdateLocalPackage(null);
xenkoUninstalledVersion.UpdateLocalPackage(null, new NugetLocalPackage[0]);
});

// Update the active version if it is now invalid.
@@ -368,7 +367,7 @@ private async Task RetrieveServerXenkoVersions()
// If yes, update it and remove it from the list of old version
version = (XenkoStoreVersionViewModel)xenkoVersions[index];
}
version.UpdateServerPackage(serverPackage);
version.UpdateServerPackage(serverPackage, package);
}
}
}
@@ -516,7 +515,7 @@ public async Task StartStudio(string argument)
await Task.Delay(5000);
Dispatcher.Invoke(() =>
{
StartStudioCommand.IsEnabled = ActiveVersion != null;
StartStudioCommand.IsEnabled = ActiveVersion != null && ActiveVersion.CanStart;
//Save settings because launcher maybe have not been closed
LauncherSettings.ActiveVersion = ActiveVersion != null ? ActiveVersion.Name : "";
LauncherSettings.Save();
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xenko.Core;
using Xenko.Core.Annotations;
using Xenko.Core.Packages;
using Xenko.Core.Presentation.Commands;
using Xenko.Core.Presentation.ViewModel;

namespace Xenko.LauncherApp.ViewModels
{
internal sealed class XenkoStoreAlternateVersionViewModel : DispatcherViewModel
{
private XenkoStoreVersionViewModel xenkoVersion;
internal NugetServerPackage ServerPackage;
internal NugetLocalPackage LocalPackage;

public XenkoStoreAlternateVersionViewModel([NotNull] XenkoStoreVersionViewModel xenkoVersion)
: base(xenkoVersion.ServiceProvider)
{
this.xenkoVersion = xenkoVersion;

SetAsActiveCommand = new AnonymousCommand(ServiceProvider, () =>
{
xenkoVersion.UpdateLocalPackage(LocalPackage, null);
if (LocalPackage == null)
{
// If it's a non installed version, offer same version for serverPackage so that it offers to install this specific version
xenkoVersion.UpdateServerPackage(ServerPackage, null);
}
else
{
// Otherwise, offer latest version for update
xenkoVersion.UpdateServerPackage(xenkoVersion.LatestServerPackage, null);
}

xenkoVersion.Launcher.ActiveVersion = xenkoVersion;
});
}

/// <summary>
/// Gets the command that will set the associated version as active.
/// </summary>
public CommandBase SetAsActiveCommand { get; }

public string FullName
{
get
{
if (LocalPackage != null)
return $"{LocalPackage.Id} {LocalPackage.Version} (installed)";
return $"{ServerPackage.Id} {ServerPackage.Version}";
}
}

public PackageVersion Version => LocalPackage?.Version ?? ServerPackage.Version;

internal void UpdateLocalPackage(NugetLocalPackage package)
{
OnPropertyChanging(nameof(FullName), nameof(Version));
LocalPackage = package;
OnPropertyChanged(nameof(FullName), nameof(Version));
}

internal void UpdateServerPackage(NugetServerPackage package)
{
OnPropertyChanging(nameof(FullName), nameof(Version));
ServerPackage = package;
OnPropertyChanged(nameof(FullName), nameof(Version));
}
}
}
@@ -12,6 +12,8 @@
using Xenko.Core.Presentation.Collections;
using Xenko.Core.Presentation.Commands;
using Xenko.Core.Presentation.Services;
using System.Collections.Generic;
using System.Linq;

namespace Xenko.LauncherApp.ViewModels
{
@@ -20,6 +22,7 @@ namespace Xenko.LauncherApp.ViewModels
/// </summary>
internal sealed class XenkoStoreVersionViewModel : XenkoVersionViewModel
{
internal NugetServerPackage LatestServerPackage;
private ReleaseNotesViewModel releaseNotes;

/// <summary>
@@ -57,6 +60,8 @@ public override string FullName
/// </summary>
public string ServerVersionFullName => ServerPackage?.Version?.ToString() ?? "";

public ObservableList<XenkoStoreAlternateVersionViewModel> AlternateVersions { get; } = new ObservableList<XenkoStoreAlternateVersionViewModel>();

/// <summary>
/// Gets the release notes associated to this version.
/// </summary>
@@ -77,22 +82,82 @@ public override string FullName
/// Updates the local package of this version.
/// </summary>
/// <param name="package">The local package corresponding to this version.</param>
internal void UpdateLocalPackage(NugetLocalPackage package)
internal void UpdateLocalPackage(NugetLocalPackage package, IEnumerable<NugetLocalPackage> alternateVersions)
{
OnPropertyChanging(nameof(FullName), nameof(Version));
LocalPackage = package;
OnPropertyChanged(nameof(FullName), nameof(Version));
Dispatcher.Invoke(UpdateStatus);
if (alternateVersions != null)
{
Dispatcher.Invoke(() =>
UpdateAlternateVersions(alternateVersions, (alternateVersionViewModel, alternateVersion) =>
{
if (alternateVersion == null && alternateVersionViewModel.ServerPackage == null)
AlternateVersions.Remove(alternateVersionViewModel);
else
alternateVersionViewModel.UpdateLocalPackage(alternateVersion);
}));
}
}

/// <summary>
/// Updates the server package of this version.
/// </summary>
/// <param name="package">The server package corresponding to this version.</param>
internal void UpdateServerPackage(NugetServerPackage package)
internal void UpdateServerPackage(NugetServerPackage package, IEnumerable<NugetServerPackage> alternateVersions)
{
OnPropertyChanging(nameof(FullName), nameof(Version));
ServerPackage = package;
OnPropertyChanged(nameof(FullName), nameof(Version));

// Always keep track of highest version
if (ServerPackage != null && (LatestServerPackage == null || LatestServerPackage.Version < ServerPackage.Version))
LatestServerPackage = ServerPackage;

Dispatcher.Invoke(UpdateStatus);
if (alternateVersions != null)
{
Dispatcher.Invoke(() =>
UpdateAlternateVersions(alternateVersions, (alternateVersionViewModel, alternateVersion) =>
{
if (alternateVersion == null && alternateVersionViewModel.LocalPackage == null)
AlternateVersions.Remove(alternateVersionViewModel);
else
alternateVersionViewModel.UpdateServerPackage(alternateVersion);
}));
}
}

private void UpdateAlternateVersions<T>(IEnumerable<T> alternateVersions, Action<XenkoStoreAlternateVersionViewModel, T> updateAction) where T : NugetPackage
{
var updatedViewModels = new HashSet<XenkoStoreAlternateVersionViewModel>();
foreach (var alternateVersion in alternateVersions)
{

int index = AlternateVersions.IndexOf(x => x.Version == alternateVersion.Version);
XenkoStoreAlternateVersionViewModel alternateVersionViewModel;
if (index < 0)
{
// If not, add it
alternateVersionViewModel = new XenkoStoreAlternateVersionViewModel(this);
AlternateVersions.Add(alternateVersionViewModel);
}
else
{
// If yes, update it and remove it from the list of old version
alternateVersionViewModel = AlternateVersions[index];
}

updateAction(alternateVersionViewModel, alternateVersion);
updatedViewModels.Add(alternateVersionViewModel);
}

// Update versions that are not installed locally anymore
foreach (var alternateVersionViewModel in AlternateVersions.Where(x => !updatedViewModels.Contains(x)).ToList())
{
updateAction(alternateVersionViewModel, null);
}
}

internal async Task RunPrerequisitesInstaller()
@@ -183,6 +248,8 @@ protected override void AfterDownload()
{
base.AfterDownload();
RunPrerequisitesInstaller().Forget();

Launcher.ActiveVersion = this;
}

/// <summary>
@@ -12,6 +12,7 @@ namespace Xenko.LauncherApp.ViewModels
internal abstract class XenkoVersionViewModel : PackageVersionViewModel, IComparable<XenkoVersionViewModel>, IComparable<Tuple<int, int>>
{
private bool isVisible;
private bool canStart;

internal XenkoVersionViewModel(LauncherViewModel launcher, NugetStore store, NugetLocalPackage localPackage, int major, int minor)
: base(launcher, store, localPackage)
@@ -58,6 +59,11 @@ internal XenkoVersionViewModel(LauncherViewModel launcher, NugetStore store, Nug
/// </summary>
public bool IsVisible { get { return isVisible; } private set { SetValue(ref isVisible, value); } }

/// <summary>
/// Gets whether this version can be started.
/// </summary>
public bool CanStart { get { return canStart; } private set { SetValue(ref canStart, value); } }

/// <summary>
/// Builds a string that represents the given version numbers.
/// </summary>
@@ -92,6 +98,9 @@ protected override void UpdateStatus()
IsVisible = Launcher.ShowBetaVersions || !IsBeta || CanDelete;
SetAsActiveCommand.IsEnabled = CanDelete;
DeleteCommand.IsEnabled = CanDelete;
CanStart = CanDelete;
if (Launcher.ActiveVersion == this)
Launcher.StartStudioCommand.IsEnabled = CanStart;
}

public int CompareTo(XenkoVersionViewModel other)

0 comments on commit f4d406c

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