mirror of
https://github.com/QL-Win/QuickLook.git
synced 2026-05-07 02:00:21 +08:00
Add plugin icon registration and include QLPlugin.ico
This commit is contained in:
@@ -235,6 +235,8 @@ public partial class App : Application
|
||||
MessageBoxPatcher.Initialize();
|
||||
|
||||
CheckUpdate();
|
||||
|
||||
CheckAndRegisterPluginIcon();
|
||||
}
|
||||
|
||||
protected virtual void OnSessionEnding(object sender, SessionEndingEventArgs e)
|
||||
@@ -317,7 +319,7 @@ public partial class App : Application
|
||||
// Invalid path, continue to show duplicate message
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Second instance: duplicate
|
||||
MessageBox.Show(TranslationHelper.Get("APP_SECOND_TEXT"), TranslationHelper.Get("APP_SECOND"),
|
||||
MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
@@ -337,6 +339,11 @@ public partial class App : Application
|
||||
SettingHelper.Set("LastUpdateTicks", DateTime.Now.Ticks);
|
||||
}
|
||||
|
||||
private void CheckAndRegisterPluginIcon()
|
||||
{
|
||||
_ = Task.Delay(3000).ContinueWith(_ => PluginIconRegistrationHelper.CheckAndRegisterPluginIcon());
|
||||
}
|
||||
|
||||
private void RunListener(StartupEventArgs e)
|
||||
{
|
||||
TrayIconManager.GetInstance();
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
// Copyright © 2017-2026 QL-Win Contributors
|
||||
//
|
||||
// This file is part of QuickLook program.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using Microsoft.Win32;
|
||||
using QuickLook.Common.Helpers;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Principal;
|
||||
|
||||
namespace QuickLook.Helpers;
|
||||
|
||||
internal static class PluginIconRegistrationHelper
|
||||
{
|
||||
internal static void CheckAndRegisterPluginIcon()
|
||||
{
|
||||
try
|
||||
{
|
||||
var isElevated = new WindowsPrincipal(WindowsIdentity.GetCurrent())
|
||||
.IsInRole(WindowsBuiltInRole.Administrator);
|
||||
if (!isElevated)
|
||||
return;
|
||||
|
||||
var iconPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "QLPlugin.ico");
|
||||
if (!File.Exists(iconPath))
|
||||
return;
|
||||
|
||||
bool changed = false;
|
||||
|
||||
// Computer\HKEY_CLASSES_ROOT\.qlplugin
|
||||
using (var key = Registry.ClassesRoot.CreateSubKey(".qlplugin", true))
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
if (key.GetValue(string.Empty) as string != "QuickLook.Plugin")
|
||||
{
|
||||
key.SetValue(string.Empty, "QuickLook.Plugin");
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (key.GetValue("PerceivedType") as string != "compressed")
|
||||
{
|
||||
key.SetValue("PerceivedType", "compressed");
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Computer\HKEY_CLASSES_ROOT\QuickLook.Plugin\DefaultIcon
|
||||
using (var key = Registry.ClassesRoot.CreateSubKey(@"QuickLook.Plugin\DefaultIcon", true))
|
||||
{
|
||||
var iconValue = $"{iconPath},0";
|
||||
if (key != null && key.GetValue("") as string != iconValue)
|
||||
{
|
||||
key.SetValue("", iconValue);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Computer\HKEY_CLASSES_ROOT\QuickLook.Plugin
|
||||
using (var key = Registry.ClassesRoot.CreateSubKey("QuickLook.Plugin", true))
|
||||
{
|
||||
const string fileTypeName = "QuickLook Plugin File";
|
||||
if (key != null && key.GetValue(string.Empty) as string != fileTypeName)
|
||||
{
|
||||
key.SetValue(string.Empty, fileTypeName);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Computer\HKEY_CLASSES_ROOT\QuickLook.Plugin\shell\open\command
|
||||
using (var key = Registry.ClassesRoot.CreateSubKey(@"QuickLook.Plugin\shell\open\command", true))
|
||||
{
|
||||
var commandValue = $"\"{App.AppFullPath}\" \"%1\"";
|
||||
if (key != null && key.GetValue(string.Empty) as string != commandValue)
|
||||
{
|
||||
key.SetValue(string.Empty, commandValue);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.qlplugin
|
||||
{
|
||||
// It is left to the user to choose whether to restore the default option in the future
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero); // SHCNE_ASSOCCHANGED
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ProcessHelper.WriteLog(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("shell32.dll", SetLastError = true)]
|
||||
private static extern void SHChangeNotify(int wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2);
|
||||
}
|
||||
@@ -136,6 +136,13 @@
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\QLPlugin.ico">
|
||||
<Link>QLPlugin.ico</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\QuickLook.Common\QuickLook.Common.csproj">
|
||||
<Project>{85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}</Project>
|
||||
|
||||
@@ -790,7 +790,8 @@ Interested in contributing? Check out our development resources:
|
||||
|
||||
[@OiCkilL](https://twitter.com/OiCkilL)
|
||||
[@QubitsDev](https://twitter.com/qubitsdev)
|
||||
[Donno](https://github.com/Donnnno)
|
||||
[@Donno](https://github.com/Donnnno)
|
||||
[@Shomnipotence](https://github.com/Shomnipotence)
|
||||
|
||||
*Fluent UI & Icons*
|
||||
|
||||
|
||||
Reference in New Issue
Block a user