Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ef6827
commit 9adf764
Showing
10 changed files
with
98 additions
and
179 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,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); | ||
} | ||
|
||
} | ||
} |
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