Skip to content

Commit

Permalink
Fix issue#24
Browse files Browse the repository at this point in the history
  • Loading branch information
qianlifeng committed Mar 11, 2014
1 parent 8ef6827 commit 9adf764
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 179 deletions.
95 changes: 0 additions & 95 deletions Wox.Infrastructure/UAC.cs

This file was deleted.

1 change: 0 additions & 1 deletion Wox.Infrastructure/Wox.Infrastructure.csproj
Expand Up @@ -53,7 +53,6 @@
<Compile Include="GloablHotkey.cs" />
<Compile Include="HotkeyModel.cs" />
<Compile Include="IniParser.cs" />
<Compile Include="UAC.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UserSettings\PluginHotkey.cs" />
<Compile Include="UserSettings\UserSelectedRecords.cs" />
Expand Down
70 changes: 70 additions & 0 deletions Wox.UAC/FileTypeAssociateInstaller.cs
@@ -0,0 +1,70 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows;
using ICSharpCode.SharpZipLib.Zip;
using Microsoft.Win32;
using Newtonsoft.Json;
using Wox.Plugin;

namespace Wox.UAC
{
public class FileTypeAssociateInstaller
{
[DllImport("shell32.dll")]
private static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2);

/// <summary>
/// associate filetype with specified program
/// </summary>
/// <param name="filePath"></param>
/// <param name="fileType"></param>
/// <param name="iconPath"></param>
/// <param name="overrides"></param>
private static void SaveReg(string filePath, string fileType, string iconPath, bool overrides)
{
RegistryKey classRootKey = Registry.ClassesRoot.OpenSubKey("", true);
RegistryKey woxKey = classRootKey.OpenSubKey(fileType, true);
if (woxKey != null)
{
if (!overrides)
{
return;
}
classRootKey.DeleteSubKeyTree(fileType);
}
classRootKey.CreateSubKey(fileType);
woxKey = classRootKey.OpenSubKey(fileType, true);
woxKey.SetValue("", "wox.wox");
woxKey.SetValue("Content Type", "application/wox");

RegistryKey iconKey = woxKey.CreateSubKey("DefaultIcon");
iconKey.SetValue("", iconPath);

woxKey.CreateSubKey("shell");
RegistryKey shellKey = woxKey.OpenSubKey("shell", true);
shellKey.SetValue("", "Open");
RegistryKey openKey = shellKey.CreateSubKey("open");
openKey.SetValue("", "Open with wox");

openKey = shellKey.OpenSubKey("open", true);
openKey.CreateSubKey("command");
RegistryKey commandKey = openKey.OpenSubKey("command", true);
string pathString = "\"" + filePath + "\" \"installPlugin\" \"%1\"";
commandKey.SetValue("", pathString);

//refresh cache
SHChangeNotify(0x8000000, 0, IntPtr.Zero, IntPtr.Zero);
}

public void RegisterInstaller()
{
string filePath = Directory.GetCurrentDirectory() + "\\Wox.exe";
string iconPath = Directory.GetCurrentDirectory() + "\\app.ico";

SaveReg(filePath, ".wox", iconPath, true);
}

}
}
22 changes: 1 addition & 21 deletions Wox.UAC/MainWindow.xaml.cs
Expand Up @@ -6,7 +6,7 @@ namespace Wox.UAC
{
public partial class MainWindow : Window
{
PluginInstaller installer = new PluginInstaller();
FileTypeAssociateInstaller installer = new FileTypeAssociateInstaller();

public MainWindow()
{
Expand All @@ -16,32 +16,12 @@ public MainWindow()
{
switch (param[1])
{
case "UAC":
Invoke(param[2], param[3], param[4]);
break;

case "AssociatePluginInstaller":
installer.RegisterInstaller();
break;

case "InstallPlugin":
var path = param[2];
installer.Install(path);
break;
}
}
Application.Current.Shutdown(0);
}

private static void Invoke(string namespaceName, string className, string methodName)
{
Type type = Type.GetType(namespaceName + "." + className + "," + namespaceName);
if (type != null)
{
object instance = Activator.CreateInstance(type);
MethodInfo method = type.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);
if (method != null) method.Invoke(instance, null);
}
}
}
}
2 changes: 1 addition & 1 deletion Wox.UAC/Wox.UAC.csproj
Expand Up @@ -82,7 +82,7 @@
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="PluginInstaller.cs" />
<Compile Include="FileTypeAssociateInstaller.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
Expand Down
66 changes: 7 additions & 59 deletions Wox.UAC/PluginInstaller.cs → Wox/Helper/PluginInstaller.cs
@@ -1,72 +1,20 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Linq;
using System.Text;
using System.Windows;
using ICSharpCode.SharpZipLib.Zip;
using Microsoft.Win32;
using Newtonsoft.Json;
using Wox.Plugin;

namespace Wox.UAC
namespace Wox.Helper
{
public class PluginInstaller
{
[DllImport("shell32.dll")]
private static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2);

/// <summary>
/// associate filetype with specified program
/// </summary>
/// <param name="filePath"></param>
/// <param name="fileType"></param>
/// <param name="iconPath"></param>
/// <param name="overrides"></param>
private static void SaveReg(string filePath, string fileType, string iconPath, bool overrides)
{
RegistryKey classRootKey = Registry.ClassesRoot.OpenSubKey("", true);
RegistryKey woxKey = classRootKey.OpenSubKey(fileType, true);
if (woxKey != null)
{
if (!overrides)
{
return;
}
classRootKey.DeleteSubKeyTree(fileType);
}
classRootKey.CreateSubKey(fileType);
woxKey = classRootKey.OpenSubKey(fileType, true);
woxKey.SetValue("", "wox.wox");
woxKey.SetValue("Content Type", "application/wox");

RegistryKey iconKey = woxKey.CreateSubKey("DefaultIcon");
iconKey.SetValue("", iconPath);

woxKey.CreateSubKey("shell");
RegistryKey shellKey = woxKey.OpenSubKey("shell", true);
shellKey.SetValue("", "Open");
RegistryKey openKey = shellKey.CreateSubKey("open");
openKey.SetValue("", "Open with wox");

openKey = shellKey.OpenSubKey("open", true);
openKey.CreateSubKey("command");
RegistryKey commandKey = openKey.OpenSubKey("command", true);
string pathString = "\"" + filePath + "\" \"installPlugin\" \"%1\"";
commandKey.SetValue("", pathString);

//refresh cache
SHChangeNotify(0x8000000, 0, IntPtr.Zero, IntPtr.Zero);
}

public void RegisterInstaller()
{
string filePath = Directory.GetCurrentDirectory() + "\\Wox.UAC.exe";
string iconPath = Directory.GetCurrentDirectory() + "\\app.ico";

SaveReg(filePath, ".wox", iconPath, true);
}

public void Install(string path)
public static void Install(string path)
{
if (File.Exists(path))
{
Expand Down Expand Up @@ -149,7 +97,7 @@ public void Install(string path)
}

private static PluginMetadata GetMetadataFromJson(string pluginDirectory)
{
{
string configPath = Path.Combine(pluginDirectory, "plugin.json");
PluginMetadata metadata;

Expand Down Expand Up @@ -208,7 +156,7 @@ private static PluginMetadata GetMetadataFromJson(string pluginDirectory)
/// <param name="zipedFile">The ziped file.</param>
/// <param name="strDirectory">The STR directory.</param>
/// <param name="overWrite">overwirte</param>
private void UnZip(string zipedFile, string strDirectory, bool overWrite)
private static void UnZip(string zipedFile, string strDirectory, bool overWrite)
{
if (strDirectory == "")
strDirectory = Directory.GetCurrentDirectory();
Expand Down
10 changes: 10 additions & 0 deletions Wox/MainWindow.xaml.cs
Expand Up @@ -230,6 +230,16 @@ public void ParseArgs(string[] args)
case "hidestart":
HideApp();
break;

case "installplugin":
var path = args[1];
if (!File.Exists(path))
{
MessageBox.Show("Plugin " + path + " didn't exist");
return;
}
PluginInstaller.Install(path);
break;
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion Wox/SettingWindow.xaml
Expand Up @@ -23,7 +23,9 @@
<TextBlock Text="Theme:" />
<ComboBox x:Name="themeComboBox" SelectionChanged="ThemeComboBox_OnSelectionChanged" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120"/>
</StackPanel>

<StackPanel Orientation="Horizontal" Margin="10">
<Button x:Name="btnEnableInstaller" Click="BtnEnableInstaller_OnClick">enable plugin installer</Button>
</StackPanel>
</StackPanel>
</TabItem>
<TabItem Header="Hotkey">
Expand Down
6 changes: 5 additions & 1 deletion Wox/SettingWindow.xaml.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows;
Expand Down Expand Up @@ -208,6 +209,9 @@ public void ReloadCustomPluginHotkeyView()

#endregion


private void BtnEnableInstaller_OnClick(object sender, RoutedEventArgs e)
{
Process.Start("Wox.UAC.exe", "AssociatePluginInstaller");
}
}
}
1 change: 1 addition & 0 deletions Wox/Wox.csproj
Expand Up @@ -130,6 +130,7 @@
</Compile>
<Compile Include="DispatcherExtensions.cs" />
<Compile Include="Helper\Log.cs" />
<Compile Include="Helper\PluginInstaller.cs" />
<Compile Include="Helper\WoxException.cs" />
<Compile Include="Helper\WoxPythonException.cs" />
<Compile Include="HotkeyControl.xaml.cs">
Expand Down

0 comments on commit 9adf764

Please sign in to comment.