Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions builds/azure-pipelines-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ jobs:
$xmlDoc.Package.Identity.Publisher="CN=53EC4384-7F5B-4CF6-8C23-513FFE9D1AB7"
$xmlDoc.Package.Properties.DisplayName="Files"
$xmlDoc.Package.Applications.Application.VisualElements.DisplayName="Files"

# Removes packageManagement from Store release
$nsmgr = New-Object System.Xml.XmlNamespaceManager($xmlDoc.NameTable)
$nsmgr.AddNamespace("pkg", "http://schemas.microsoft.com/appx/manifest/foundation/windows10")
$nsmgr.AddNamespace("rescap", "http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities")
$pm = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Capabilities/rescap:Capability[@Name='packageManagement']", $nsmgr)
$xmlDoc.Package.Capabilities.RemoveChild($pm)

$xmlDoc.Save('$(Build.SourcesDirectory)\src\Files.Package\Package.appxmanifest')
failOnStderr: true

Expand Down
8 changes: 8 additions & 0 deletions src/Files.Uwp/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ private IServiceProvider ConfigureServices()
.AddSingleton<IImagingService, ImagingService>()
.AddSingleton<IThreadingService, ThreadingService>()
.AddSingleton<ILocalizationService, LocalizationService>()
#if SIDELOAD
.AddSingleton<IUpdateService, SideloadUpdateService>()
#else
.AddSingleton<IUpdateService, UpdateService>()
#endif
.AddSingleton<IDateTimeFormatterFactory, DateTimeFormatterFactory>()
.AddSingleton<IDateTimeFormatter, UserDateTimeFormatter>()

Expand Down Expand Up @@ -209,7 +213,11 @@ await Task.WhenAll(
// Check for required updates
var updateService = Ioc.Default.GetRequiredService<IUpdateService>();
await updateService.CheckForUpdates();
#if SIDELOAD
//await updateService.DownloadUpdates();
#else
await updateService.DownloadMandatoryUpdates();
#endif

static async Task OptionalTask(Task task, bool condition)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Files.Uwp/Files.Uwp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@
<Compile Include="ServicesImplementation\Settings\PaneSettingsService.cs" />
<Compile Include="ServicesImplementation\Settings\UserSettingsService.cs" />
<Compile Include="ServicesImplementation\Settings\WidgetsSettingsService.cs" />
<Compile Include="ServicesImplementation\SideloadUpdateService.cs" />
<Compile Include="ServicesImplementation\ThreadingService.cs" />
<Compile Include="ServicesImplementation\UpdateService.cs" />
<Compile Include="TemplateSelectors\BaseTemplateSelector.cs" />
Expand Down Expand Up @@ -1655,7 +1656,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Sideload|x64'">
<OutputPath>bin\x64\Sideload\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP;DISABLE_XAML_GENERATED_MAIN;CODE_ANALYSIS</DefineConstants>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP;DISABLE_XAML_GENERATED_MAIN;CODE_ANALYSIS;SIDELOAD</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
Expand Down
126 changes: 126 additions & 0 deletions src/Files.Uwp/ServicesImplementation/SideloadUpdateService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using System.Xml.Serialization;
using Windows.ApplicationModel;
using Windows.Management.Deployment;
using CommunityToolkit.Mvvm.ComponentModel;
using Files.Backend.Services;

namespace Files.Uwp.ServicesImplementation
{
public class SideloadUpdateService : ObservableObject, IUpdateService
{
private const string SideloadStable = "https://cdn.files.community/files/stable/Files.Package.appinstaller";
private const string SideloadPreview = "https://cdn.files.community/files/preview/Files.Package.appinstaller";

private readonly Dictionary<string, string> _sideloadVersion = new()
{
{ "Files", SideloadStable },
{ "FilesPreview", SideloadPreview }
};

private Uri DownloadUri { get; set; }

private bool _isUpdateAvailable;
private bool _isUpdating;

public bool IsUpdateAvailable
{
get => _isUpdateAvailable;
private set => SetProperty(ref _isUpdateAvailable, value);
}

public bool IsUpdating
{
get => _isUpdating;
private set => SetProperty(ref _isUpdating, value);
}

public async Task DownloadUpdates()
{
if (!IsUpdateAvailable)
{
return;
}

IsUpdating = true;

PackageManager pm = new PackageManager();

// Use DeploymentOptions.ForceApplicationShutdown to force shutdown.
await pm.UpdatePackageAsync(DownloadUri, null, DeploymentOptions.None);

IsUpdating = false;
IsUpdateAvailable = false;
}

public Task DownloadMandatoryUpdates()
{
throw new NotImplementedException();
}

public async Task CheckForUpdates()
{
await CheckForRemoteUpdate(_sideloadVersion[Package.Current.Id.Name]);
}

private async Task CheckForRemoteUpdate(string uri)
{
using var client = new WebClient();
using var stream = await client.OpenReadTaskAsync(uri);

// Deserialize AppInstaller.
XmlSerializer xml = new XmlSerializer(typeof(AppInstaller));
var appInstaller = (AppInstaller)xml.Deserialize(stream);

// Get version and package details.
var currentPackageVersion = Package.Current.Id.Version;
var currentPackageName = Package.Current.Id.Name;

var currentVersion = new Version(currentPackageVersion.Major, currentPackageVersion.Minor,
currentPackageVersion.Build, currentPackageVersion.Revision);
var remoteVersion = new Version(appInstaller.Version);

// Check details and version number.
if (appInstaller.MainBundle.Name.Equals(currentPackageName) && currentVersion.CompareTo(remoteVersion) > 0)
{
DownloadUri = new Uri(appInstaller.MainBundle.Uri);
IsUpdateAvailable = true;
}
else
{
IsUpdateAvailable = false;
}
}
}

/// <summary>
/// AppInstaller class to hold information about remote updates.
/// </summary>
[XmlRoot(ElementName = "AppInstaller", Namespace = "http://schemas.microsoft.com/appx/appinstaller/2018")]
public class AppInstaller
{
[XmlElement("MainBundle")]
public MainBundle MainBundle { get; set; }

[XmlAttribute("Uri")]
public string Uri { get; set; }

[XmlAttribute("Version")]
public string Version { get; set; }
}

public class MainBundle
{
[XmlAttribute("Name")]
public string Name { get; set; }

[XmlAttribute("Version")]
public string Version { get; set; }

[XmlAttribute("Uri")]
public string Uri { get; set; }
}
}