Skip to content

Commit 6dbe887

Browse files
authored
Code Quality: Assigned execution alias and URI for each build (#16182)
1 parent 27c937a commit 6dbe887

File tree

12 files changed

+98
-27
lines changed

12 files changed

+98
-27
lines changed

.github/scripts/Configure-AppxManifest.ps1

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,20 @@ param(
1111
[string]$SecretGitHubOAuthClientId = ""
1212
)
1313

14+
# Load Package.appxmanifest
1415
[xml]$xmlDoc = Get-Content $PackageManifestPath
16+
17+
# Add namespaces
18+
$nsmgr = New-Object System.Xml.XmlNamespaceManager($xmlDoc.NameTable)
19+
$nsmgr.AddNamespace("pkg", "http://schemas.microsoft.com/appx/manifest/foundation/windows10")
20+
$nsmgr.AddNamespace("rescap", "http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities")
21+
$nsmgr.AddNamespace("uap", "http://schemas.microsoft.com/appx/manifest/uap/windows10")
22+
$nsmgr.AddNamespace("uap5", "http://schemas.microsoft.com/appx/manifest/uap/windows10/5")
23+
$ap = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Applications/pkg:Application/pkg:Extensions/uap:Extension[@Category='windows.protocol']/uap:Protocol", $nsmgr)
24+
$aea = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Applications/pkg:Application/pkg:Extensions/uap5:Extension[@Category='windows.appExecutionAlias']/uap5:AppExecutionAlias", $nsmgr)
25+
$ea = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Applications/pkg:Application/pkg:Extensions/uap5:Extension[@Category='windows.appExecutionAlias']/uap5:AppExecutionAlias/uap5:ExecutionAlias", $nsmgr)
26+
27+
# Update the publisher
1528
$xmlDoc.Package.Identity.Publisher = $Publisher
1629

1730
if ($Branch -eq "Preview")
@@ -21,13 +34,25 @@ if ($Branch -eq "Preview")
2134
$xmlDoc.Package.Properties.DisplayName="Files - Preview"
2235
$xmlDoc.Package.Applications.Application.VisualElements.DisplayName="Files - Preview"
2336
$xmlDoc.Package.Applications.Application.VisualElements.DefaultTile.ShortName="Files - Preview"
37+
38+
# Update app protocol and execution alias
39+
$ap.SetAttribute("Name", "files-preview");
40+
$ea.SetAttribute("Alias", "files-preview.exe");
41+
42+
# Save modified Package.appxmanifest
2443
$xmlDoc.Save($PackageManifestPath)
2544

2645
Get-ChildItem $WorkingDir -Include *.csproj, *.appxmanifest, *.wapproj, *.xaml -recurse | ForEach-Object -Process `
2746
{ `
2847
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "Assets\\AppTiles\\Dev", "Assets\AppTiles\Preview" }) | `
2948
Set-Content $_ -NoNewline `
3049
}
50+
51+
Get-ChildItem $WorkingDir -Include *.cs, *.cpp -recurse | ForEach-Object -Process `
52+
{ `
53+
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "files-dev", "files-preview" }) | `
54+
Set-Content $_ -NoNewline `
55+
}
3156
}
3257
elseif ($Branch -eq "Stable")
3358
{
@@ -36,13 +61,25 @@ elseif ($Branch -eq "Stable")
3661
$xmlDoc.Package.Properties.DisplayName="Files"
3762
$xmlDoc.Package.Applications.Application.VisualElements.DisplayName="Files"
3863
$xmlDoc.Package.Applications.Application.VisualElements.DefaultTile.ShortName="Files"
64+
65+
# Update app protocol and execution alias
66+
$ap.SetAttribute("Name", "files-stable");
67+
$ea.SetAttribute("Alias", "files-stable.exe");
68+
69+
# Save modified Package.appxmanifest
3970
$xmlDoc.Save($PackageManifestPath)
4071

4172
Get-ChildItem $WorkingDir -Include *.csproj, *.appxmanifest, *.wapproj, *.xaml -recurse | ForEach-Object -Process `
4273
{ `
4374
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "Assets\\AppTiles\\Dev", "Assets\AppTiles\Release" }) | `
4475
Set-Content $_ -NoNewline `
4576
}
77+
78+
Get-ChildItem $WorkingDir -Include *.cs, *.cpp -recurse | ForEach-Object -Process `
79+
{ `
80+
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "files-dev", "files-stable" }) | `
81+
Set-Content $_ -NoNewline `
82+
}
4683
}
4784
elseif ($Branch -eq "Store")
4885
{
@@ -52,19 +89,28 @@ elseif ($Branch -eq "Store")
5289
$xmlDoc.Package.Applications.Application.VisualElements.DisplayName="Files"
5390
$xmlDoc.Package.Applications.Application.VisualElements.DefaultTile.ShortName="Files"
5491

55-
# Remove an capability that is used for the sideload
56-
$nsmgr = New-Object System.Xml.XmlNamespaceManager($xmlDoc.NameTable)
57-
$nsmgr.AddNamespace("pkg", "http://schemas.microsoft.com/appx/manifest/foundation/windows10")
58-
$nsmgr.AddNamespace("rescap", "http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities")
92+
# Remove capability that is only used for the sideload package
5993
$pm = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Capabilities/rescap:Capability[@Name='packageManagement']", $nsmgr)
6094
$xmlDoc.Package.Capabilities.RemoveChild($pm)
95+
96+
# Update app protocol and execution alias
97+
$ap.SetAttribute("Name", "files");
98+
$aea.RemoveChild(aea.FirstChild); # Avoid duplication
99+
100+
# Save modified Package.appxmanifest
61101
$xmlDoc.Save($PackageManifestPath)
62102

63103
Get-ChildItem $WorkingDir -Include *.csproj, *.appxmanifest, *.wapproj, *.xaml -recurse | ForEach-Object -Process `
64104
{ `
65105
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "Assets\\AppTiles\\Dev", "Assets\AppTiles\Release" }) | `
66106
Set-Content $_ -NoNewline `
67107
}
108+
109+
Get-ChildItem $WorkingDir -Include *.cs, *.cpp -recurse | ForEach-Object -Process `
110+
{ `
111+
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "files-dev", "files" }) | `
112+
Set-Content $_ -NoNewline `
113+
}
68114
}
69115

70116
Get-ChildItem $WorkingDir -Include *.cs -recurse | ForEach-Object -Process `

src/Files.App (Package)/Package.appxmanifest

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,26 @@
119119
</uap3:Extension>
120120

121121
<uap:Extension Category="windows.protocol">
122+
<!-- This is kept for backward compatibility. -->
122123
<uap:Protocol ReturnResults="none" Name="files-uwp" />
123124
</uap:Extension>
124125

126+
<uap:Extension Category="windows.protocol">
127+
<!-- This is kept for backward compatibility. -->
128+
<uap:Protocol ReturnResults="none" Name="files" />
129+
</uap:Extension>
130+
131+
<uap:Extension Category="windows.protocol">
132+
<!-- This value changes based on the build branch by CI (files-stable, files-preview, files-dev). -->
133+
<uap:Protocol ReturnResults="none" Name="files-dev" />
134+
</uap:Extension>
135+
125136
<uap5:Extension Category="windows.appExecutionAlias">
126137
<uap5:AppExecutionAlias>
138+
<!-- This is kept for backward compatibility. -->
127139
<uap5:ExecutionAlias Alias="files.exe" />
140+
<!-- This value changes based on the build branch by CI (files-stable, files-preview, files-dev). -->
141+
<uap5:ExecutionAlias Alias="files-dev.exe" />
128142
</uap5:AppExecutionAlias>
129143
</uap5:Extension>
130144

src/Files.App.Launcher/FilesLauncher.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
6565
LocalFree(szArglist);
6666

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

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

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

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

190-
//ShExecInfo.lpFile = L"files.exe";
190+
//ShExecInfo.lpFile = L"files-dev.exe";
191191
//ShExecInfo.lpParameters = args;
192192
//if (!ShellExecuteEx(&ShExecInfo))
193193
//{
@@ -202,13 +202,13 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
202202
SHELLEXECUTEINFO ShExecInfo = { 0 };
203203
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
204204
ShExecInfo.fMask = SEE_MASK_NOASYNC | SEE_MASK_FLAG_NO_UI;
205-
ShExecInfo.lpFile = L"files-uwp:";
205+
ShExecInfo.lpFile = L"files-dev:";
206206
ShExecInfo.nShow = SW_SHOW;
207207

208208
if (!ShellExecuteEx(&ShExecInfo))
209209
{
210210
std::wcout << L"Protocol error: " << GetLastError() << std::endl;
211-
//ShExecInfo.lpFile = L"files.exe";
211+
//ShExecInfo.lpFile = L"files-dev.exe";
212212
//if (!ShellExecuteEx(&ShExecInfo))
213213
//{
214214
//std::wcout << L"Command line error: " << GetLastError() << std::endl;

src/Files.App.OpenDialog/FilesOpenDialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ STDAPICALL CFilesOpenDialog::Show(HWND hwndOwner)
162162
PWSTR pszPath = NULL;
163163
WCHAR szBuf[MAX_PATH];
164164
TCHAR args[1024] = { 0 };
165-
ExpandEnvironmentStringsW(L"%LOCALAPPDATA%\\Microsoft\\WindowsApps\\files.exe", szBuf, MAX_PATH - 1);
165+
ExpandEnvironmentStringsW(L"%LOCALAPPDATA%\\Microsoft\\WindowsApps\\files-dev.exe", szBuf, MAX_PATH - 1);
166166

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

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

180-
std::wstring uriWithArgs = L"files-uwp:?cmd=" + str2wstr(wstring_to_utf8_hex(args));
180+
std::wstring uriWithArgs = L"files-dev:?cmd=" + str2wstr(wstring_to_utf8_hex(args));
181181
ShExecInfo.lpFile = uriWithArgs.c_str();
182182
ShExecInfo.nShow = SW_SHOW;
183183
ShellExecuteEx(&ShExecInfo);

src/Files.App.SaveDialog/FilesSaveDialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ HRESULT __stdcall CFilesSaveDialog::Show(HWND hwndOwner)
438438
PWSTR pszPath = NULL;
439439
WCHAR szBuf[MAX_PATH];
440440
TCHAR args[1024] = { 0 };
441-
ExpandEnvironmentStringsW(L"%LOCALAPPDATA%\\Microsoft\\WindowsApps\\files.exe", szBuf, MAX_PATH - 1);
441+
ExpandEnvironmentStringsW(L"%LOCALAPPDATA%\\Microsoft\\WindowsApps\\files-dev.exe", szBuf, MAX_PATH - 1);
442442

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

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

463-
std::wstring uriWithArgs = L"files-uwp:?cmd=" + str2wstr(wstring_to_utf8_hex(args));
463+
std::wstring uriWithArgs = L"files-dev:?cmd=" + str2wstr(wstring_to_utf8_hex(args));
464464
ShExecInfo.lpFile = uriWithArgs.c_str();
465465
ShExecInfo.nShow = SW_SHOW;
466466
ShellExecuteEx(&ShExecInfo);

src/Files.App/Actions/Navigation/OpenInNewWindow/BaseOpenInNewWindowAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public virtual async Task ExecuteAsync(object? parameter = null)
4949
foreach (ListedItem listedItem in items)
5050
{
5151
var selectedItemPath = (listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath;
52-
var folderUri = new Uri($"files-uwp:?folder={@selectedItemPath}");
52+
var folderUri = new Uri($"files-dev:?folder={@selectedItemPath}");
5353

5454
await Launcher.LaunchUriAsync(folderUri);
5555
}

src/Files.App/Helpers/Application/AppLifecycleHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public static void HandleAppUnhandledException(Exception? ex, bool showToastNoti
340340
// Try to re-launch and start over
341341
MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
342342
{
343-
await Launcher.LaunchUriAsync(new Uri("files-uwp:"));
343+
await Launcher.LaunchUriAsync(new Uri("files-dev:"));
344344
})
345345
.Wait(100);
346346
}

src/Files.App/Helpers/Navigation/NavigationHelpers.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,14 @@ public static Task<bool> OpenPathInNewWindowAsync(string? path)
280280
if (string.IsNullOrWhiteSpace(path))
281281
return Task.FromResult(false);
282282

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

285285
return Launcher.LaunchUriAsync(folderUri).AsTask();
286286
}
287287

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

@@ -301,8 +301,7 @@ public static void OpenInSecondaryPane(IShellPage associatedInstance, ListedItem
301301

302302
public static Task LaunchNewWindowAsync()
303303
{
304-
var filesUWPUri = new Uri("files-uwp:?window=");
305-
return Launcher.LaunchUriAsync(filesUWPUri).AsTask();
304+
return Launcher.LaunchUriAsync(new Uri("files-dev:?window=")).AsTask();
306305
}
307306

308307
public static async Task OpenSelectedItemsAsync(IShellPage associatedInstance, bool openViaApplicationPicker = false)

src/Files.App/MainWindow.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public async Task InitializeApplicationAsync(object activatedEventArgs)
6262
{
6363
case ILaunchActivatedEventArgs launchArgs:
6464
if (launchArgs.Arguments is not null &&
65-
(CommandLineParser.SplitArguments(launchArgs.Arguments, true)[0].EndsWith($"files.exe", StringComparison.OrdinalIgnoreCase)
66-
|| CommandLineParser.SplitArguments(launchArgs.Arguments, true)[0].EndsWith($"files", StringComparison.OrdinalIgnoreCase)))
65+
(CommandLineParser.SplitArguments(launchArgs.Arguments, true)[0].EndsWith($"files-dev.exe", StringComparison.OrdinalIgnoreCase)
66+
|| CommandLineParser.SplitArguments(launchArgs.Arguments, true)[0].EndsWith($"files-dev", StringComparison.OrdinalIgnoreCase)))
6767
{
6868
// WINUI3: When launching from commandline the argument is not ICommandLineActivatedEventArgs (#10370)
6969
var ppm = CommandLineParser.ParseUntrustedCommands(launchArgs.Arguments);
@@ -92,7 +92,7 @@ public async Task InitializeApplicationAsync(object activatedEventArgs)
9292
break;
9393

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

src/Files.App/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ static bool ProcessPathPredicate(Process p)
220220
var cmdLaunchArgs = activatedArgs.Data is ILaunchActivatedEventArgs launchArgs &&
221221
launchArgs.Arguments is not null &&
222222
CommandLineParser.SplitArguments(launchArgs.Arguments, true).FirstOrDefault() is string arg0 &&
223-
(arg0.EndsWith($"files.exe", StringComparison.OrdinalIgnoreCase) ||
224-
arg0.EndsWith($"files", StringComparison.OrdinalIgnoreCase)) ? launchArgs.Arguments : null;
223+
(arg0.EndsWith($"files-dev.exe", StringComparison.OrdinalIgnoreCase) ||
224+
arg0.EndsWith($"files-dev", StringComparison.OrdinalIgnoreCase)) ? launchArgs.Arguments : null;
225225
var cmdProtocolArgs = activatedArgs.Data is IProtocolActivatedEventArgs protocolArgs &&
226226
protocolArgs.Uri.Query.TrimStart('?').Split('=') is string[] parsedArgs &&
227227
parsedArgs.Length == 2 && parsedArgs[0] == "cmd" ? Uri.UnescapeDataString(parsedArgs[1]) : null;

0 commit comments

Comments
 (0)