forked from files-community/Files
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Added an out-of-proc WinRT server for long-running backgroun…
…d tasks (files-community#14335)
- Loading branch information
Showing
36 changed files
with
571 additions
and
1,114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Diagnostics; | ||
|
||
namespace Files.App.Server; | ||
|
||
public sealed class AppInstanceMonitor | ||
{ | ||
private static int processCount = 0; | ||
|
||
public static void StartMonitor(int processId) | ||
{ | ||
var process = Process.GetProcessById(processId); | ||
Interlocked.Increment(ref processCount); | ||
process.EnableRaisingEvents = true; | ||
process.Exited += Process_Exited; | ||
} | ||
|
||
private static void Process_Exited(object? sender, EventArgs e) | ||
{ | ||
if (sender is Process process) | ||
{ | ||
process.Dispose(); | ||
|
||
if (Interlocked.Decrement(ref processCount) == 0) | ||
{ | ||
Program.ExitSignalEvent.Set(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<DefaultLanguage>en-US</DefaultLanguage> | ||
<AppxBundleAutoResourcePackageQualifiers>Scale|DXFeatureLevel</AppxBundleAutoResourcePackageQualifiers> | ||
<AppxDefaultResourceQualifiers>Language=en-US;af;ar;bg;ca;cs-CZ;da;da-DK;de-DE;el;en-GB;es-ES;es-419;fa-IR;fi-FI;fil-PH;fr-FR;he-IL;hi-IN;hu-HU;id-ID;it-IT;ja-JP;ka;ko-KR;lt;lv-LV;nb-NO;nl-NL;or-IN;pl-PL;pt-BR;pt-PT;ro-RO;ru-RU;sk-SK;sv-SE;ta;th-TH;tr-TR;uk-UA;vi;zh-Hans;zh-Hant</AppxDefaultResourceQualifiers> | ||
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework> | ||
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<Configurations>Debug;Release;Stable;Preview;Store</Configurations> | ||
<Platforms>x86;x64;arm64</Platforms> | ||
<SelfContained>true</SelfContained> | ||
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers> | ||
<RuntimeIdentifier Condition="'$(Platform)' == 'x86'">win-x86</RuntimeIdentifier> | ||
<RuntimeIdentifier Condition="'$(Platform)' == 'x64'">win-x64</RuntimeIdentifier> | ||
<RuntimeIdentifier Condition="'$(Platform)' == 'arm64'">win-arm64</RuntimeIdentifier> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<CsWinRTComponent>true</CsWinRTComponent> | ||
<CsWinRTWindowsMetadata>10.0.22621.0</CsWinRTWindowsMetadata> | ||
<ApplicationManifest>app.manifest</ApplicationManifest> | ||
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun> | ||
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun> | ||
<PublishReadyToRunComposite Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRunComposite> | ||
<PublishTrimmed Condition="'$(Configuration)' == 'Debug'">False</PublishTrimmed> | ||
<PublishTrimmed Condition="'$(Configuration)' != 'Debug'">True</PublishTrimmed> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)' == 'Debug'"> | ||
<DefineConstants>TRACE;DEBUG;NETFX_CORE</DefineConstants> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)' != 'Debug'"> | ||
<DefineConstants>TRACE;RELEASE;NETFX_CORE</DefineConstants> | ||
<Optimize>true</Optimize> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Manifest Include="app.manifest" /> | ||
<TrimmerRootAssembly Include="Files.App.Server" /> | ||
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.4" /> | ||
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.1.647-beta" PrivateAssets="all" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\Files.App.Server\bin\$(Platform)\$(Configuration)\$(TargetFramework)\win-$(Platform)\Files.App.Server.winmd"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
<Link>Files.App.Server.winmd</Link> | ||
<Visible>false</Visible> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Files.Shared\Files.Shared.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using WinRT; | ||
|
||
namespace Files.App.Server; | ||
|
||
unsafe partial class Helpers | ||
{ | ||
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])] | ||
public static int GetActivationFactory(void* activatableClassId, void** factory) | ||
{ | ||
const int E_INVALIDARG = unchecked((int)0x80070057); | ||
const int CLASS_E_CLASSNOTAVAILABLE = unchecked((int)0x80040111); | ||
const int S_OK = 0; | ||
|
||
if (activatableClassId is null || factory is null) | ||
{ | ||
return E_INVALIDARG; | ||
} | ||
|
||
try | ||
{ | ||
IntPtr obj = Module.GetActivationFactory(MarshalString.FromAbi((IntPtr)activatableClassId)); | ||
|
||
if ((void*)obj is null) | ||
{ | ||
return CLASS_E_CLASSNOTAVAILABLE; | ||
} | ||
|
||
*factory = (void*)obj; | ||
return S_OK; | ||
} | ||
catch (Exception e) | ||
{ | ||
ExceptionHelpers.SetErrorInfo(e); | ||
return ExceptionHelpers.GetHRForException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) 2023 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
{ | ||
"$schema": "https://aka.ms/CsWin32.schema.json", | ||
|
||
// Emit COM interfaces instead of structs, and allow generation of non-blittable structs for the sake of an easier to use API. | ||
"allowMarshaling": true, | ||
|
||
// A value indicating whether to generate APIs judged to be unnecessary or redundant given the target framework. | ||
// This is useful for multi-targeting projects that need a consistent set of APIs across target frameworks | ||
// to avoid too many conditional compilation regions. | ||
"multiTargetingFriendlyAPIs": false, | ||
|
||
// A value indicating whether friendly overloads should use safe handles. | ||
"useSafeHandles": true, | ||
|
||
// Omit ANSI functions and remove `W` suffix from UTF-16 functions. | ||
"wideCharOnly": true, | ||
|
||
// A value indicating whether to emit a single source file as opposed to types spread across many files. | ||
"emitSingleFile": false, | ||
|
||
// The name of a single class under which all p/invoke methods and constants are generated, regardless of imported module. | ||
"className": "PInvoke", | ||
|
||
// A value indicating whether to expose the generated APIs publicly (as opposed to internally). | ||
"public": true | ||
} |
Oops, something went wrong.