Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions src/Files.App.Launcher/Files.App.Launcher.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@
</Link>
<PostBuildEvent>
<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>
xcopy /s /y "$(ProjectDir)$(OutDir)*.exe" "$(ProjectDir)..\..\src\Files.App\Assets\FilesOpenDialog"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
Expand Down

This file was deleted.

4 changes: 3 additions & 1 deletion src/Files.App/Helpers/Application/AppLifecycleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () =>

await updateService.CheckForUpdatesAsync();
await updateService.DownloadMandatoryUpdatesAsync();
await updateService.CheckAndUpdateFilesLauncherAsync();

if (IsAppUpdated)
await updateService.CheckAndUpdateFilesLauncherAsync();
}

/// <summary>
Expand Down
46 changes: 13 additions & 33 deletions src/Files.App/Services/App/AppUpdateSideloadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.Extensions.Logging;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Xml.Serialization;
using Windows.ApplicationModel;
using Windows.Management.Deployment;
Expand Down Expand Up @@ -125,52 +126,31 @@ public async Task CheckAndUpdateFilesLauncherAsync()
{
var destFolderPath = Path.Combine(UserDataPaths.GetDefault().LocalAppData, "Files");
var destExeFilePath = Path.Combine(destFolderPath, "Files.App.Launcher.exe");
var branchFilePath = Path.Combine(destFolderPath, "Branch.txt");

// If Files.App.Launcher.exe doesn't exist, no need to update it.
if (!File.Exists(destExeFilePath))
return;

var hashEqual = false;
var srcHashFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/FilesOpenDialog/Files.App.Launcher.exe.sha256"))
.AsTask().ConfigureAwait(false);
var destHashFilePath = Path.Combine(destFolderPath, "Files.App.Launcher.exe.sha256");

if (File.Exists(destHashFilePath))
{
await using var srcStream = (await srcHashFile.OpenReadAsync().AsTask().ConfigureAwait(false)).AsStream();
await using var destStream = File.OpenRead(destHashFilePath);
hashEqual = HashEqual(srcStream, destStream);
}
// Check if the launcher file is associated with the current branch of the app. Users updating from versions earlier than
// v4.0.20 will not have the branch file in which case we create it for them.
if (File.Exists(branchFilePath) && await File.ReadAllTextAsync(branchFilePath, Encoding.UTF8) != "files-dev")
return;
else if (!File.Exists(branchFilePath))
await File.WriteAllTextAsync(branchFilePath, "files-dev", Encoding.UTF8);

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

await srcExeFile.CopyAsync(destFolder, "Files.App.Launcher.exe", NameCollisionOption.ReplaceExisting)
.AsTask().ConfigureAwait(false);
await srcHashFile.CopyAsync(destFolder, "Files.App.Launcher.exe.sha256", NameCollisionOption.ReplaceExisting)
.AsTask().ConfigureAwait(false);
await srcExeFile.CopyAsync(destFolder, "Files.App.Launcher.exe", NameCollisionOption.ReplaceExisting);

Logger?.LogInformation("Files.App.Launcher updated.");
}
App.Logger.LogInformation("Files.App.Launcher updated.");
}
catch (Exception ex)
{
Logger?.LogError(ex, ex.Message);
return;
}

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);
}
}

public async Task CheckForReleaseNotesAsync()
Expand Down
47 changes: 15 additions & 32 deletions src/Files.App/Services/App/AppUpdateStoreService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.UI.Xaml.Controls;
using System.IO;
using System.Net.Http;
using System.Text;
using Windows.Foundation.Metadata;
using Windows.Services.Store;
using Windows.Storage;
Expand Down Expand Up @@ -180,43 +181,25 @@ public async Task CheckAndUpdateFilesLauncherAsync()
{
var destFolderPath = Path.Combine(UserDataPaths.GetDefault().LocalAppData, "Files");
var destExeFilePath = Path.Combine(destFolderPath, "Files.App.Launcher.exe");
var branchFilePath = Path.Combine(destFolderPath, "Branch.txt");

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

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

hashEqual = HashEqual(srcStream, destStream);
}

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

await srcExeFile.CopyAsync(destFolder, "Files.App.Launcher.exe", NameCollisionOption.ReplaceExisting);
await srcHashFile.CopyAsync(destFolder, "Files.App.Launcher.exe.sha256", NameCollisionOption.ReplaceExisting);
// If Files.App.Launcher.exe doesn't exist, no need to update it.
if (!File.Exists(destExeFilePath))
return;

App.Logger.LogInformation("Files.App.Launcher updated.");
}
}
// Check if the launcher file is associated with the current branch of the app. Users updating from versions earlier than
// v4.0.20 will not have the branch file in which case we create it for them.
if (File.Exists(branchFilePath) && await File.ReadAllTextAsync(branchFilePath, Encoding.UTF8) != "files-dev")
return;
else if (!File.Exists(branchFilePath))
await File.WriteAllTextAsync(branchFilePath, "files-dev", Encoding.UTF8);

bool HashEqual(Stream a, Stream b)
{
Span<byte> bufferA = stackalloc byte[64];
Span<byte> bufferB = stackalloc byte[64];
var srcExeFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/FilesOpenDialog/Files.App.Launcher.exe"));
var destFolder = await StorageFolder.GetFolderFromPathAsync(destFolderPath);

a.Read(bufferA);
b.Read(bufferB);
await srcExeFile.CopyAsync(destFolder, "Files.App.Launcher.exe", NameCollisionOption.ReplaceExisting);

return bufferA.SequenceEqual(bufferB);
}
App.Logger.LogInformation("Files.App.Launcher updated.");
}

private bool HasUpdates()
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/ViewModels/Settings/AdvancedViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private async Task SetAsDefaultExplorerAsync()
var dataPath = Environment.ExpandEnvironmentVariables("%LocalAppData%\\Files");
if (IsSetAsDefaultFileManager)
{
if (!await Win32Helper.RunPowershellCommandAsync($"-command \"New-Item -Force -Path '{dataPath}' -ItemType Directory; Copy-Item -Filter *.* -Path '{destFolder}\\*' -Recurse -Force -Destination '{dataPath}'\"", PowerShellExecutionOptions.Hidden))
if (!await Win32Helper.RunPowershellCommandAsync($"-command \"New-Item -Force -Path '{dataPath}' -ItemType Directory; Copy-Item -Filter *.* -Path '{destFolder}\\*' -Recurse -Force -Destination '{dataPath}'; 'files-dev' | Out-File -Encoding utf8 -Force -FilePath '{dataPath}\\Branch.txt'\"", PowerShellExecutionOptions.Hidden))
{
// Error copying files
await DetectResult();
Expand Down
Loading