Compare commits

...

3 Commits

Author SHA1 Message Date
qhy040404
676fe87f04 Update Snap.Hutao.csproj 2024-04-21 23:49:53 +08:00
qhy040404
2056fa8f4d extract launcher 2024-04-20 15:28:07 +08:00
qhy040404
47debe42ec allow to open elevated app from taskbar 2024-04-20 15:16:22 +08:00
3 changed files with 20 additions and 15 deletions

View File

@@ -20,23 +20,23 @@ internal sealed partial class ShellLinkInterop : IShellLinkInterop
public async ValueTask<bool> TryCreateDesktopShoutcutForElevatedLaunchAsync()
{
string targetLogoPath = Path.Combine(runtimeOptions.DataFolder, "ShellLinkLogo.ico");
string elevatedLauncherPath = Path.Combine(runtimeOptions.DataFolder, "Snap.Hutao.Elevated.Launcher.exe");
try
{
Uri sourceLogoUri = "ms-appx:///Assets/Logo.ico".ToUri();
StorageFile iconFile = await StorageFile.GetFileFromApplicationUriAsync(sourceLogoUri);
await iconFile.OverwriteCopyAsync(targetLogoPath).ConfigureAwait(false);
Uri elevatedLauncherUri = "ms-appx:///Snap.Hutao.Elevated.Launcher.exe".ToUri();
StorageFile launcherFile = await StorageFile.GetFileFromApplicationUriAsync(elevatedLauncherUri);
await launcherFile.OverwriteCopyAsync(elevatedLauncherPath).ConfigureAwait(false);
}
catch
{
return false;
}
return UnsafeTryCreateDesktopShoutcutForElevatedLaunch(targetLogoPath);
return UnsafeTryCreateDesktopShoutcutForElevatedLaunch(elevatedLauncherPath);
}
private unsafe bool UnsafeTryCreateDesktopShoutcutForElevatedLaunch(string targetLogoPath)
private unsafe bool UnsafeTryCreateDesktopShoutcutForElevatedLaunch(string elevatedLauncherPath)
{
bool result = false;
@@ -44,16 +44,9 @@ internal sealed partial class ShellLinkInterop : IShellLinkInterop
HRESULT hr = CoCreateInstance(in ShellLink.CLSID, default, CLSCTX.CLSCTX_INPROC_SERVER, in IShellLinkW.IID, out IShellLinkW* pShellLink);
if (SUCCEEDED(hr))
{
pShellLink->SetPath($"shell:AppsFolder\\{runtimeOptions.FamilyName}!App");
pShellLink->SetPath(elevatedLauncherPath);
pShellLink->SetArguments(runtimeOptions.FamilyName);
pShellLink->SetShowCmd(SHOW_WINDOW_CMD.SW_NORMAL);
pShellLink->SetIconLocation(targetLogoPath, 0);
if (SUCCEEDED(pShellLink->QueryInterface(in IShellLinkDataList.IID, out IShellLinkDataList* pShellLinkDataList)))
{
pShellLinkDataList->GetFlags(out uint flags);
pShellLinkDataList->SetFlags(flags | (uint)SHELL_LINK_DATA_FLAGS.SLDF_RUNAS_USER);
pShellLinkDataList->Release();
}
if (SUCCEEDED(pShellLink->QueryInterface(in IPersistFile.IID, out IPersistFile* pPersistFile)))
{

View File

@@ -327,6 +327,10 @@
<PackageReference Include="Snap.Hutao.Deployment.Runtime" Version="1.16.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Snap.Hutao.Elevated.Launcher.Runtime" Version="1.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Snap.Hutao.SourceGeneration" Version="1.0.7">
<PrivateAssets>all</PrivateAssets>

View File

@@ -70,6 +70,14 @@ internal unsafe struct IShellLinkW
}
}
public HRESULT SetArguments(string szArgs)
{
fixed (char* pszArgs = szArgs)
{
return ThisPtr->SetArguments((IShellLinkW*)Unsafe.AsPointer(ref this), pszArgs);
}
}
internal unsafe readonly struct Vftbl
{
internal readonly IUnknown.Vftbl IUnknownVftbl;