Skip to content
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

Code Quality: Assigned execution alias and URI for each build #16182

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
54 changes: 50 additions & 4 deletions .github/scripts/Configure-AppxManifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,20 @@ param(
[string]$SecretGitHubOAuthClientId = ""
)

# Load Package.appxmanifest
[xml]$xmlDoc = Get-Content $PackageManifestPath

# Add namespaces
$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")
$nsmgr.AddNamespace("uap", "http://schemas.microsoft.com/appx/manifest/uap/windows10")
$nsmgr.AddNamespace("uap5", "http://schemas.microsoft.com/appx/manifest/uap/windows10/5")
0x5bfa marked this conversation as resolved.
Show resolved Hide resolved
$ap = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Applications/pkg:Application/pkg:Extensions/uap:Extension[@Category='windows.protocol']/uap:Protocol", $nsmgr)
$aea = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Applications/pkg:Application/pkg:Extensions/uap5:Extension[@Category='windows.appExecutionAlias']/uap5:AppExecutionAlias", $nsmgr)
$ea = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Applications/pkg:Application/pkg:Extensions/uap5:Extension[@Category='windows.appExecutionAlias']/uap5:AppExecutionAlias/uap5:ExecutionAlias", $nsmgr)

# Update the publisher
$xmlDoc.Package.Identity.Publisher = $Publisher

if ($Branch -eq "Preview")
Expand All @@ -21,13 +34,25 @@ if ($Branch -eq "Preview")
$xmlDoc.Package.Properties.DisplayName="Files - Preview"
$xmlDoc.Package.Applications.Application.VisualElements.DisplayName="Files - Preview"
$xmlDoc.Package.Applications.Application.VisualElements.DefaultTile.ShortName="Files - Preview"

# Update app protocol and execution alias
$ap.SetAttribute("Name", "files-pre");
$ea.SetAttribute("Alias", "files-pre.exe");

# Save modified Package.appxmanifest
$xmlDoc.Save($PackageManifestPath)

Get-ChildItem $WorkingDir -Include *.csproj, *.appxmanifest, *.wapproj, *.xaml -recurse | ForEach-Object -Process `
{ `
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "Assets\\AppTiles\\Dev", "Assets\AppTiles\Preview" }) | `
Set-Content $_ -NoNewline `
}

Get-ChildItem $WorkingDir -Include *.cs, *.cpp -recurse | ForEach-Object -Process `
{ `
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "files-dev", "files-pre" }) | `
Set-Content $_ -NoNewline `
}
}
elseif ($Branch -eq "Stable")
{
Expand All @@ -36,13 +61,25 @@ elseif ($Branch -eq "Stable")
$xmlDoc.Package.Properties.DisplayName="Files"
$xmlDoc.Package.Applications.Application.VisualElements.DisplayName="Files"
$xmlDoc.Package.Applications.Application.VisualElements.DefaultTile.ShortName="Files"

# Update app protocol and execution alias
$ap.SetAttribute("Name", "files");
$aea.RemoveChild(aea.FirstChild); # Avoid duplication

# Save modified Package.appxmanifest
$xmlDoc.Save($PackageManifestPath)

Get-ChildItem $WorkingDir -Include *.csproj, *.appxmanifest, *.wapproj, *.xaml -recurse | ForEach-Object -Process `
{ `
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "Assets\\AppTiles\\Dev", "Assets\AppTiles\Release" }) | `
Set-Content $_ -NoNewline `
}

Get-ChildItem $WorkingDir -Include *.cs, *.cpp -recurse | ForEach-Object -Process `
{ `
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "files-dev", "files" }) | `
Set-Content $_ -NoNewline `
}
}
elseif ($Branch -eq "Store")
{
Expand All @@ -52,19 +89,28 @@ elseif ($Branch -eq "Store")
$xmlDoc.Package.Applications.Application.VisualElements.DisplayName="Files"
$xmlDoc.Package.Applications.Application.VisualElements.DefaultTile.ShortName="Files"

# Remove an capability that is used for the sideload
$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")
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
# Remove capability that is only used for the sideload package
$pm = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Capabilities/rescap:Capability[@Name='packageManagement']", $nsmgr)
$xmlDoc.Package.Capabilities.RemoveChild($pm)

# Update app protocol and execution alias
$ap.SetAttribute("Name", "files");
$aea.RemoveChild(aea.FirstChild); # Avoid duplication

# Save modified Package.appxmanifest
$xmlDoc.Save($PackageManifestPath)

Get-ChildItem $WorkingDir -Include *.csproj, *.appxmanifest, *.wapproj, *.xaml -recurse | ForEach-Object -Process `
{ `
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "Assets\\AppTiles\\Dev", "Assets\AppTiles\Release" }) | `
Set-Content $_ -NoNewline `
}

Get-ChildItem $WorkingDir -Include *.cs, *.cpp -recurse | ForEach-Object -Process `
{ `
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "files-dev", "files" }) | `
Set-Content $_ -NoNewline `
}
}

Get-ChildItem $WorkingDir -Include *.cs -recurse | ForEach-Object -Process `
Expand Down
9 changes: 9 additions & 0 deletions src/Files.App (Package)/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,20 @@
</uap3:Extension>

<uap:Extension Category="windows.protocol">
<!-- This is for backward compatibility -->
<uap:Protocol ReturnResults="none" Name="files-uwp" />
</uap:Extension>

<uap:Extension Category="windows.protocol">
<!-- This value changes based on the build branch (files, files-pre, files-dev). -->
<uap:Protocol ReturnResults="none" Name="files-dev" />
</uap:Extension>

<uap5:Extension Category="windows.appExecutionAlias">
<uap5:AppExecutionAlias>
<!-- This value changes based on the build branch (files, files-pre, files-dev). -->
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
<uap5:ExecutionAlias Alias="files-dev.exe" />
<!-- This is for backward compatibility -->
<uap5:ExecutionAlias Alias="files.exe" />
</uap5:AppExecutionAlias>
</uap5:Extension>
Expand Down
10 changes: 5 additions & 5 deletions src/Files.App.Launcher/FilesLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
LocalFree(szArglist);

WCHAR szBuf[MAX_PATH];
ExpandEnvironmentStringsW(L"%LOCALAPPDATA%\\Microsoft\\WindowsApps\\files.exe", szBuf, MAX_PATH - 1);
ExpandEnvironmentStringsW(L"%LOCALAPPDATA%\\Microsoft\\WindowsApps\\files-dev.exe", szBuf, MAX_PATH - 1);
std::wcout << szBuf << std::endl;
if (_waccess(szBuf, 0) == -1)
{
Expand Down Expand Up @@ -172,7 +172,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
swprintf(args, _countof(args) - 1, L"\"%s\" -select \"%s\"", szBuf, item.c_str());
}

std::wstring uriWithArgs = L"files-uwp:?cmd=" + str2wstr(wstring_to_utf8_hex(args));
std::wstring uriWithArgs = L"files-dev:?cmd=" + str2wstr(wstring_to_utf8_hex(args));

std::wcout << L"Invoking: " << args << L" = " << uriWithArgs << std::endl;

Expand All @@ -187,7 +187,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
{
std::wcout << L"Protocol error: " << GetLastError() << std::endl;

//ShExecInfo.lpFile = L"files.exe";
//ShExecInfo.lpFile = L"files-dev.exe";
//ShExecInfo.lpParameters = args;
//if (!ShellExecuteEx(&ShExecInfo))
//{
Expand All @@ -202,13 +202,13 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
SHELLEXECUTEINFO ShExecInfo = { 0 };
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOASYNC | SEE_MASK_FLAG_NO_UI;
ShExecInfo.lpFile = L"files-uwp:";
ShExecInfo.lpFile = L"files-dev:";
ShExecInfo.nShow = SW_SHOW;

if (!ShellExecuteEx(&ShExecInfo))
{
std::wcout << L"Protocol error: " << GetLastError() << std::endl;
//ShExecInfo.lpFile = L"files.exe";
//ShExecInfo.lpFile = L"files-dev.exe";
//if (!ShellExecuteEx(&ShExecInfo))
//{
//std::wcout << L"Command line error: " << GetLastError() << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App.OpenDialog/FilesOpenDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ STDAPICALL CFilesOpenDialog::Show(HWND hwndOwner)
PWSTR pszPath = NULL;
WCHAR szBuf[MAX_PATH];
TCHAR args[1024] = { 0 };
ExpandEnvironmentStringsW(L"%LOCALAPPDATA%\\Microsoft\\WindowsApps\\files.exe", szBuf, MAX_PATH - 1);
ExpandEnvironmentStringsW(L"%LOCALAPPDATA%\\Microsoft\\WindowsApps\\files-dev.exe", szBuf, MAX_PATH - 1);

HANDLE closeEvent = CreateEvent(NULL, FALSE, FALSE, TEXT("FILEDIALOG"));

Expand All @@ -177,7 +177,7 @@ STDAPICALL CFilesOpenDialog::Show(HWND hwndOwner)
swprintf(args, _countof(args) - 1, L"\"%s\" -outputpath \"%s\"", szBuf, _outputPath.c_str());
}

std::wstring uriWithArgs = L"files-uwp:?cmd=" + str2wstr(wstring_to_utf8_hex(args));
std::wstring uriWithArgs = L"files-dev:?cmd=" + str2wstr(wstring_to_utf8_hex(args));
ShExecInfo.lpFile = uriWithArgs.c_str();
ShExecInfo.nShow = SW_SHOW;
ShellExecuteEx(&ShExecInfo);
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App.SaveDialog/FilesSaveDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ HRESULT __stdcall CFilesSaveDialog::Show(HWND hwndOwner)
PWSTR pszPath = NULL;
WCHAR szBuf[MAX_PATH];
TCHAR args[1024] = { 0 };
ExpandEnvironmentStringsW(L"%LOCALAPPDATA%\\Microsoft\\WindowsApps\\files.exe", szBuf, MAX_PATH - 1);
ExpandEnvironmentStringsW(L"%LOCALAPPDATA%\\Microsoft\\WindowsApps\\files-dev.exe", szBuf, MAX_PATH - 1);

HANDLE closeEvent = CreateEvent(NULL, FALSE, FALSE, TEXT("FILEDIALOG"));

Expand All @@ -460,7 +460,7 @@ HRESULT __stdcall CFilesSaveDialog::Show(HWND hwndOwner)
swprintf(args, _countof(args) - 1, L"\"%s\" -outputpath \"%s\"", szBuf, _outputPath.c_str());
}

std::wstring uriWithArgs = L"files-uwp:?cmd=" + str2wstr(wstring_to_utf8_hex(args));
std::wstring uriWithArgs = L"files-dev:?cmd=" + str2wstr(wstring_to_utf8_hex(args));
ShExecInfo.lpFile = uriWithArgs.c_str();
ShExecInfo.nShow = SW_SHOW;
ShellExecuteEx(&ShExecInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public virtual async Task ExecuteAsync(object? parameter = null)
foreach (ListedItem listedItem in items)
{
var selectedItemPath = (listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath;
var folderUri = new Uri($"files-uwp:?folder={@selectedItemPath}");
var folderUri = new Uri($"files-dev:?folder={@selectedItemPath}");

await Launcher.LaunchUriAsync(folderUri);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Helpers/Application/AppLifecycleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public static void HandleAppUnhandledException(Exception? ex, bool showToastNoti
// Try to re-launch and start over
MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
{
await Launcher.LaunchUriAsync(new Uri("files-uwp:"));
await Launcher.LaunchUriAsync(new Uri("files-dev:"));
})
.Wait(100);
}
Expand Down
7 changes: 3 additions & 4 deletions src/Files.App/Helpers/Navigation/NavigationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,14 @@ public static Task<bool> OpenPathInNewWindowAsync(string? path)
if (string.IsNullOrWhiteSpace(path))
return Task.FromResult(false);

var folderUri = new Uri($"files-uwp:?folder={Uri.EscapeDataString(path)}");
var folderUri = new Uri($"files-dev:?folder={Uri.EscapeDataString(path)}");

return Launcher.LaunchUriAsync(folderUri).AsTask();
}

public static Task<bool> OpenTabInNewWindowAsync(string tabArgs)
{
var folderUri = new Uri($"files-uwp:?tab={Uri.EscapeDataString(tabArgs)}");
var folderUri = new Uri($"files-dev:?tab={Uri.EscapeDataString(tabArgs)}");
return Launcher.LaunchUriAsync(folderUri).AsTask();
}

Expand All @@ -307,8 +307,7 @@ public static void OpenInSecondaryPane(IShellPage associatedInstance, ListedItem

public static Task LaunchNewWindowAsync()
{
var filesUWPUri = new Uri("files-uwp:?window=");
return Launcher.LaunchUriAsync(filesUWPUri).AsTask();
return Launcher.LaunchUriAsync(new Uri("files-dev:?window=")).AsTask();
}

public static async Task OpenSelectedItemsAsync(IShellPage associatedInstance, bool openViaApplicationPicker = false)
Expand Down
6 changes: 3 additions & 3 deletions src/Files.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public async Task InitializeApplicationAsync(object activatedEventArgs)
{
case ILaunchActivatedEventArgs launchArgs:
if (launchArgs.Arguments is not null &&
(CommandLineParser.SplitArguments(launchArgs.Arguments, true)[0].EndsWith($"files.exe", StringComparison.OrdinalIgnoreCase)
|| CommandLineParser.SplitArguments(launchArgs.Arguments, true)[0].EndsWith($"files", StringComparison.OrdinalIgnoreCase)))
(CommandLineParser.SplitArguments(launchArgs.Arguments, true)[0].EndsWith($"files-dev.exe", StringComparison.OrdinalIgnoreCase)
|| CommandLineParser.SplitArguments(launchArgs.Arguments, true)[0].EndsWith($"files-dev", StringComparison.OrdinalIgnoreCase)))
{
// WINUI3: When launching from commandline the argument is not ICommandLineActivatedEventArgs (#10370)
var ppm = CommandLineParser.ParseUntrustedCommands(launchArgs.Arguments);
Expand Down Expand Up @@ -82,7 +82,7 @@ public async Task InitializeApplicationAsync(object activatedEventArgs)
break;

case IProtocolActivatedEventArgs eventArgs:
if (eventArgs.Uri.AbsoluteUri == "files-uwp:")
if (eventArgs.Uri.AbsoluteUri == "files-dev:")
{
rootFrame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo());

Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ static bool ProcessPathPredicate(Process p)
var cmdLaunchArgs = activatedArgs.Data is ILaunchActivatedEventArgs launchArgs &&
launchArgs.Arguments is not null &&
CommandLineParser.SplitArguments(launchArgs.Arguments, true).FirstOrDefault() is string arg0 &&
(arg0.EndsWith($"files.exe", StringComparison.OrdinalIgnoreCase) ||
arg0.EndsWith($"files", StringComparison.OrdinalIgnoreCase)) ? launchArgs.Arguments : null;
(arg0.EndsWith($"files-dev.exe", StringComparison.OrdinalIgnoreCase) ||
arg0.EndsWith($"files-dev", StringComparison.OrdinalIgnoreCase)) ? launchArgs.Arguments : null;
var cmdProtocolArgs = activatedArgs.Data is IProtocolActivatedEventArgs protocolArgs &&
protocolArgs.Uri.Query.TrimStart('?').Split('=') is string[] parsedArgs &&
parsedArgs.Length == 2 && parsedArgs[0] == "cmd" ? Uri.UnescapeDataString(parsedArgs[1]) : null;
Expand Down
16 changes: 14 additions & 2 deletions src/Files.App/Utils/Taskbar/SystemTrayIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,19 @@ public sealed class SystemTrayIcon : IDisposable

// Fields

private readonly static Guid _trayIconGuid = new("684F2832-AC2B-4630-98C2-73D6AEBD46B7");
private readonly static Guid _trayIconGuid = new(
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
#if DEBUG
"684F2832-AC2B-4630-98C2-73D6AEBD4001"
#elif PREVIEW
"684F2832-AC2B-4630-98C2-73D6AEBD4002"
#elif STABLE
"684F2832-AC2B-4630-98C2-73D6AEBD4003"
#elif STORE
"684F2832-AC2B-4630-98C2-73D6AEBD4004"
#else
"684F2832-AC2B-4630-98C2-73D6AEBD4005"
#endif
);

private readonly SystemTrayIconWindow _IconWindow;

Expand Down Expand Up @@ -264,7 +276,7 @@ private void OnLeftClicked()
{
_lastLaunchDate = DateTime.Now;

_ = Launcher.LaunchUriAsync(new Uri("files-uwp:"));
_ = Launcher.LaunchUriAsync(new Uri("files-dev:"));
}
else
MainWindow.Instance.Activate();
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/ViewModels/Settings/GeneralViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private async void DoRestartAsync()
AppLifecycleHelper.SaveSessionTabs();

// Launches a new instance of Files
await Launcher.LaunchUriAsync(new Uri("files-uwp:"));
await Launcher.LaunchUriAsync(new Uri("files-dev:"));

// Closes the current instance
Process.GetCurrentProcess().Kill();
Expand Down