Skip to content
Open
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
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
56 changes: 25 additions & 31 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,45 @@ 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))
// Check if the launcher file is associated with the current branch of the app.
if (File.Exists(branchFilePath))
{
await using var srcStream = (await srcHashFile.OpenReadAsync().AsTask().ConfigureAwait(false)).AsStream();
await using var destStream = File.OpenRead(destHashFilePath);
hashEqual = HashEqual(srcStream, destStream);
try
{
var branch = await File.ReadAllTextAsync(branchFilePath, Encoding.UTF8);
if (!string.Equals(branch.Trim(), "files-dev", StringComparison.OrdinalIgnoreCase))
return;
}
catch { }
}

if (!hashEqual)
else
{
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);
try
{
// Create branch file for users updating from versions earlier than v4.0.20.
await File.WriteAllTextAsync(branchFilePath, "files-dev", Encoding.UTF8);
}
catch { }
}

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);
var srcExeFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/FilesOpenDialog/Files.App.Launcher.exe"));
var destFolder = await StorageFolder.GetFolderFromPathAsync(destFolderPath);

Logger?.LogInformation("Files.App.Launcher updated.");
}
await srcExeFile.CopyAsync(destFolder, "Files.App.Launcher.exe", NameCollisionOption.ReplaceExisting);

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
51 changes: 24 additions & 27 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,39 @@ 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 Files.App.Launcher.exe doesn't exist, no need to update it.
if (!File.Exists(destExeFilePath))
return;

if (Path.Exists(destHashFilePath))
// Check if the launcher file is associated with the current branch of the app.
if (File.Exists(branchFilePath))
{
try
{
await using var srcStream = (await srcHashFile.OpenReadAsync()).AsStream();
await using var destStream = File.OpenRead(destHashFilePath);

hashEqual = HashEqual(srcStream, destStream);
var branch = await File.ReadAllTextAsync(branchFilePath, Encoding.UTF8);
if (!string.Equals(branch.Trim(), "files-dev", StringComparison.OrdinalIgnoreCase))
return;
}

if (!hashEqual)
catch { }
}
else
{
try
{
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);

App.Logger.LogInformation("Files.App.Launcher updated.");
// Create branch file for users updating from versions earlier than v4.0.20.
await File.WriteAllTextAsync(branchFilePath, "files-dev", Encoding.UTF8);
}
catch { }
}

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