Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5bfa committed Sep 24, 2024
1 parent 99b8408 commit fbb78ae
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 28 deletions.
55 changes: 52 additions & 3 deletions .github/scripts/Configure-AppxManifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@ 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")

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

if ($Branch -eq "Preview")
Expand All @@ -21,13 +31,27 @@ 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 = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Applications/pkg:Application/pkg:Extensions/uap:Extension[@Category='windows.protocol']", $nsmgr)
$ap.Attributes["Name"]="files-pre";
$aea = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Applications/pkg:Application/pkg:Extensions/uap:Extension[@Category='windows.appExecutionAlias']/uap5:AppExecutionAlias", $nsmgr)
$aea.Attributes["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 +60,27 @@ 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 = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Applications/pkg:Application/pkg:Extensions/uap:Extension[@Category='windows.protocol']", $nsmgr)
$ap.Attributes["Name"]="files";
$aea = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Applications/pkg:Application/pkg:Extensions/uap:Extension[@Category='windows.appExecutionAlias']/uap5:AppExecutionAlias", $nsmgr)
$aea.Attributes["Alias"]="files.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\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 @@ -53,18 +91,29 @@ elseif ($Branch -eq "Store")
$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")
$pm = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Capabilities/rescap:Capability[@Name='packageManagement']", $nsmgr)
$xmlDoc.Package.Capabilities.RemoveChild($pm)

# Update app protocol and execution alias
$ap = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Applications/pkg:Application/pkg:Extensions/uap:Extension[@Category='windows.protocol']", $nsmgr)
$ap.Attributes["Name"]="files";
$aea = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Applications/pkg:Application/pkg:Extensions/uap:Extension[@Category='windows.appExecutionAlias']/uap5:AppExecutionAlias", $nsmgr)
$aea.Attributes["Alias"]="files.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\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
6 changes: 4 additions & 2 deletions src/Files.App (Package)/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,14 @@
</uap3:Extension>

<uap:Extension Category="windows.protocol">
<uap:Protocol ReturnResults="none" Name="files-uwp" />
<!-- 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>
<uap5:ExecutionAlias Alias="files.exe" />
<!-- This value changes based on the build branch (files, files-pre, files-dev). -->
<uap5:ExecutionAlias Alias="files-dev.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(
#if DEBUG
"e6fc16c1-e6e2-40a2-9c4e-1bf3b54684ad"
#elif PREVIEW
"8bd7e317-ee80-405e-8c90-f4d9866ff9bc"
#elif STABLE
"96b3455b-16bf-454e-ada5-191ba32f2f8e"
#elif STORE
"01966f57-00cf-471f-b2d5-55f227e0dfe6"
#else
"e77abbd8-8721-4d50-a4d2-743d28cdc37b"
#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

0 comments on commit fbb78ae

Please sign in to comment.