Skip to content

Feature: Auto update feature of FilesLauncher #11750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 17, 2023
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
1 change: 1 addition & 0 deletions src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ await Task.WhenAll(
var updateService = Ioc.Default.GetRequiredService<IUpdateService>();
await updateService.CheckForUpdates();
await updateService.DownloadMandatoryUpdates();
await updateService.CheckAndUpdateFilesLauncherAsync();
await updateService.CheckLatestReleaseNotesAsync();

static async Task OptionalTask(Task task, bool condition)
Expand Down
Binary file modified src/Files.App/Assets/FilesOpenDialog/FilesLauncher.exe
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
126534c53b4865d8b71d9378ce8d7071ff6dd71a58a0773345867dcfb80952a7
43 changes: 43 additions & 0 deletions src/Files.App/ServicesImplementation/SideloadUpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,49 @@ public async Task CheckForUpdates()
}
}

public async Task CheckAndUpdateFilesLauncherAsync()
{
var destFolderPath = Path.Combine(UserDataPaths.GetDefault().LocalAppData, "Files");
var destExeFilePath = Path.Combine(destFolderPath, "FilesLauncher.exe");

if (Path.Exists(destExeFilePath))
{
var hashEqual = false;
var srcHashFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/FilesOpenDialog/FilesLauncher.exe.sha256"));
var destHashFilePath = Path.Combine(destFolderPath, "FilesLauncher.exe.sha256");

if (Path.Exists(destHashFilePath))
{
using var srcStream = (await srcHashFile.OpenReadAsync()).AsStream();
using var destStream = File.OpenRead(destHashFilePath);

hashEqual = HashEqual(srcStream, destStream);
}

if (!hashEqual)
{
var srcExeFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/FilesOpenDialog/FilesLauncher.exe"));
var destFolder = await StorageFolder.GetFolderFromPathAsync(destFolderPath);

await srcExeFile.CopyAsync(destFolder, "FilesLauncher.exe", NameCollisionOption.ReplaceExisting);
await srcHashFile.CopyAsync(destFolder, "FilesLauncher.exe.sha256", NameCollisionOption.ReplaceExisting);

App.Logger.Info("FilesLauncher updated.");
}
}

bool HashEqual(Stream a, Stream b)
{
Span<byte> bufferA = stackalloc byte[64];
Span<byte> bufferB = stackalloc byte[64];

a.Read(bufferA);
b.Read(bufferB);

return bufferA.SequenceEqual(bufferB);
}
}

private async Task StartBackgroundDownload()
{
try
Expand Down
44 changes: 44 additions & 0 deletions src/Files.App/ServicesImplementation/UpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Threading;
using System.Threading.Tasks;
using Windows.Services.Store;
using Windows.Storage;
using WinRT.Interop;

namespace Files.App.ServicesImplementation
Expand Down Expand Up @@ -178,6 +179,49 @@ public async Task CheckLatestReleaseNotesAsync(CancellationToken cancellationTok
}
}

public async Task CheckAndUpdateFilesLauncherAsync()
{
var destFolderPath = Path.Combine(UserDataPaths.GetDefault().LocalAppData, "Files");
var destExeFilePath = Path.Combine(destFolderPath, "FilesLauncher.exe");

if (Path.Exists(destExeFilePath))
{
var hashEqual = false;
var srcHashFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/FilesOpenDialog/FilesLauncher.exe.sha256"));
var destHashFilePath = Path.Combine(destFolderPath, "FilesLauncher.exe.sha256");

if (Path.Exists(destHashFilePath))
{
using var srcStream = (await srcHashFile.OpenReadAsync()).AsStream();
using var destStream = File.OpenRead(destHashFilePath);

hashEqual = HashEqual(srcStream, destStream);
}

if (!hashEqual)
{
var srcExeFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/FilesOpenDialog/FilesLauncher.exe"));
var destFolder = await StorageFolder.GetFolderFromPathAsync(destFolderPath);

await srcExeFile.CopyAsync(destFolder, "FilesLauncher.exe", NameCollisionOption.ReplaceExisting);
await srcHashFile.CopyAsync(destFolder, "FilesLauncher.exe.sha256", NameCollisionOption.ReplaceExisting);

App.Logger.Info("FilesLauncher updated.");
}
}

bool HashEqual(Stream a, Stream b)
{
Span<byte> bufferA = stackalloc byte[64];
Span<byte> bufferB = stackalloc byte[64];

a.Read(bufferA);
b.Read(bufferB);

return bufferA.SequenceEqual(bufferB);
}
}

// WINUI3
private static ContentDialog SetContentDialogRoot(ContentDialog contentDialog)
{
Expand Down
5 changes: 5 additions & 0 deletions src/Files.Backend/Services/IUpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,10 @@ public interface IUpdateService : INotifyPropertyChanged
/// Gets release notes for the latest release
/// </summary>
Task<string?> GetLatestReleaseNotesAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Replace FilesLauncher.exe if it is used and has been updated
/// </summary>
Task CheckAndUpdateFilesLauncherAsync();
}
}
27 changes: 18 additions & 9 deletions src/Files.OpenDialog/FilesLauncher/FilesLauncher.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@
<OutputFile>$(OutDir)FilesLauncher$(TargetExt)</OutputFile>
</Link>
<PostBuildEvent>
<Command>xcopy /s /y "$(ProjectDir)$(OutDir)*.exe" "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog"</Command>
<Command>xcopy /s /y "$(ProjectDir)$(OutDir)*.exe" "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog"
certutil -hashfile "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog\$(TargetFileName)" SHA256|findstr /R /V "^SHA256 ^CertUtil"&gt;"$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog\$(TargetFileName).sha256"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand All @@ -211,7 +212,8 @@
<OutputFile>$(OutDir)FilesLauncher$(TargetExt)</OutputFile>
</Link>
<PostBuildEvent>
<Command>xcopy /s /y "$(ProjectDir)$(OutDir)*.exe" "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog"</Command>
<Command>xcopy /s /y "$(ProjectDir)$(OutDir)*.exe" "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog"
certutil -hashfile "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog\$(TargetFileName)" SHA256|findstr /R /V "^SHA256 ^CertUtil"&gt;"$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog\$(TargetFileName).sha256"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Sideload|Win32'">
Expand All @@ -233,7 +235,8 @@
<OutputFile>$(OutDir)FilesLauncher$(TargetExt)</OutputFile>
</Link>
<PostBuildEvent>
<Command>xcopy /s /y "$(ProjectDir)$(OutDir)*.exe" "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog"</Command>
<Command>xcopy /s /y "$(ProjectDir)$(OutDir)*.exe" "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog"
certutil -hashfile "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog\$(TargetFileName)" SHA256|findstr /R /V "^SHA256 ^CertUtil"&gt;"$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog\$(TargetFileName).sha256"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -251,7 +254,8 @@
<OutputFile>$(OutDir)FilesLauncher$(TargetExt)</OutputFile>
</Link>
<PostBuildEvent>
<Command>xcopy /s /y "$(ProjectDir)$(OutDir)*.exe" "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog"</Command>
<Command>xcopy /s /y "$(ProjectDir)$(OutDir)*.exe" "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog"
certutil -hashfile "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog\$(TargetFileName)" SHA256|findstr /R /V "^SHA256 ^CertUtil"&gt;"$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog\$(TargetFileName).sha256"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|arm64'">
Expand All @@ -269,7 +273,8 @@
<OutputFile>$(OutDir)FilesLauncher$(TargetExt)</OutputFile>
</Link>
<PostBuildEvent>
<Command>xcopy /s /y "$(ProjectDir)$(OutDir)*.exe" "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog"</Command>
<Command>xcopy /s /y "$(ProjectDir)$(OutDir)*.exe" "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog"
certutil -hashfile "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog\$(TargetFileName)" SHA256|findstr /R /V "^SHA256 ^CertUtil"&gt;"$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog\$(TargetFileName).sha256"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -291,7 +296,8 @@
<OutputFile>$(OutDir)FilesLauncher$(TargetExt)</OutputFile>
</Link>
<PostBuildEvent>
<Command>xcopy /s /y "$(ProjectDir)$(OutDir)*.exe" "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog"</Command>
<Command>xcopy /s /y "$(ProjectDir)$(OutDir)*.exe" "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog"
certutil -hashfile "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog\$(TargetFileName)" SHA256|findstr /R /V "^SHA256 ^CertUtil"&gt;"$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog\$(TargetFileName).sha256"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Sideload|x64'">
Expand All @@ -313,7 +319,8 @@
<OutputFile>$(OutDir)FilesLauncher$(TargetExt)</OutputFile>
</Link>
<PostBuildEvent>
<Command>xcopy /s /y "$(ProjectDir)$(OutDir)*.exe" "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog"</Command>
<Command>xcopy /s /y "$(ProjectDir)$(OutDir)*.exe" "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog"
certutil -hashfile "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog\$(TargetFileName)" SHA256|findstr /R /V "^SHA256 ^CertUtil"&gt;"$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog\$(TargetFileName).sha256"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|arm64'">
Expand All @@ -335,7 +342,8 @@
<OutputFile>$(OutDir)FilesLauncher$(TargetExt)</OutputFile>
</Link>
<PostBuildEvent>
<Command>xcopy /s /y "$(ProjectDir)$(OutDir)*.exe" "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog"</Command>
<Command>xcopy /s /y "$(ProjectDir)$(OutDir)*.exe" "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog"
certutil -hashfile "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog\$(TargetFileName)" SHA256|findstr /R /V "^SHA256 ^CertUtil"&gt;"$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog\$(TargetFileName).sha256"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Sideload|arm64'">
Expand All @@ -357,7 +365,8 @@
<OutputFile>$(OutDir)FilesLauncher$(TargetExt)</OutputFile>
</Link>
<PostBuildEvent>
<Command>xcopy /s /y "$(ProjectDir)$(OutDir)*.exe" "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog"</Command>
<Command>xcopy /s /y "$(ProjectDir)$(OutDir)*.exe" "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog"
certutil -hashfile "$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog\$(TargetFileName)" SHA256|findstr /R /V "^SHA256 ^CertUtil"&gt;"$(ProjectDir)..\..\..\src\Files.App\Assets\FilesOpenDialog\$(TargetFileName).sha256"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down