diff --git a/Doc/app.psd b/Doc/app.psd new file mode 100644 index 000000000..2ce1b96aa Binary files /dev/null and b/Doc/app.psd differ diff --git a/Plugins/WinAlfred.Plugin.DouBan/.idea/.name b/Plugins/WinAlfred.Plugin.DouBan/.idea/.name new file mode 100644 index 000000000..5d573fded --- /dev/null +++ b/Plugins/WinAlfred.Plugin.DouBan/.idea/.name @@ -0,0 +1 @@ +WinAlfred.Plugin.DouBan \ No newline at end of file diff --git a/Plugins/WinAlfred.Plugin.DouBan/.idea/WinAlfred.Plugin.DouBan.iml b/Plugins/WinAlfred.Plugin.DouBan/.idea/WinAlfred.Plugin.DouBan.iml new file mode 100644 index 000000000..cb7a8494b --- /dev/null +++ b/Plugins/WinAlfred.Plugin.DouBan/.idea/WinAlfred.Plugin.DouBan.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + diff --git a/Plugins/WinAlfred.Plugin.DouBan/.idea/dictionaries/Scott.xml b/Plugins/WinAlfred.Plugin.DouBan/.idea/dictionaries/Scott.xml new file mode 100644 index 000000000..72c46d1bc --- /dev/null +++ b/Plugins/WinAlfred.Plugin.DouBan/.idea/dictionaries/Scott.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/Plugins/WinAlfred.Plugin.DouBan/.idea/encodings.xml b/Plugins/WinAlfred.Plugin.DouBan/.idea/encodings.xml new file mode 100644 index 000000000..e206d70d8 --- /dev/null +++ b/Plugins/WinAlfred.Plugin.DouBan/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/Plugins/WinAlfred.Plugin.DouBan/.idea/misc.xml b/Plugins/WinAlfred.Plugin.DouBan/.idea/misc.xml new file mode 100644 index 000000000..89928bcf5 --- /dev/null +++ b/Plugins/WinAlfred.Plugin.DouBan/.idea/misc.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + diff --git a/Plugins/WinAlfred.Plugin.DouBan/.idea/modules.xml b/Plugins/WinAlfred.Plugin.DouBan/.idea/modules.xml new file mode 100644 index 000000000..b22aac435 --- /dev/null +++ b/Plugins/WinAlfred.Plugin.DouBan/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/Plugins/WinAlfred.Plugin.DouBan/.idea/scopes/scope_settings.xml b/Plugins/WinAlfred.Plugin.DouBan/.idea/scopes/scope_settings.xml new file mode 100644 index 000000000..922003b84 --- /dev/null +++ b/Plugins/WinAlfred.Plugin.DouBan/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/Plugins/WinAlfred.Plugin.DouBan/.idea/vcs.xml b/Plugins/WinAlfred.Plugin.DouBan/.idea/vcs.xml new file mode 100644 index 000000000..def6a6a18 --- /dev/null +++ b/Plugins/WinAlfred.Plugin.DouBan/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Plugins/WinAlfred.Plugin.DouBan/.idea/workspace.xml b/Plugins/WinAlfred.Plugin.DouBan/.idea/workspace.xml new file mode 100644 index 000000000..63658b8a1 --- /dev/null +++ b/Plugins/WinAlfred.Plugin.DouBan/.idea/workspace.xml @@ -0,0 +1,345 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1389365252031 + 1389365252031 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WinAlfred.WorkflowInstaller/App.xaml b/WinAlfred.WorkflowInstaller/App.xaml new file mode 100644 index 000000000..69bfff8c4 --- /dev/null +++ b/WinAlfred.WorkflowInstaller/App.xaml @@ -0,0 +1,8 @@ + + + + + diff --git a/WinAlfred.WorkflowInstaller/App.xaml.cs b/WinAlfred.WorkflowInstaller/App.xaml.cs new file mode 100644 index 000000000..4fe191df0 --- /dev/null +++ b/WinAlfred.WorkflowInstaller/App.xaml.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Windows; + +namespace WinAlfred.WorkflowInstaller +{ + /// + /// App.xaml 的交互逻辑 + /// + public partial class App : Application + { + } +} diff --git a/WinAlfred.WorkflowInstaller/IniParser.cs b/WinAlfred.WorkflowInstaller/IniParser.cs new file mode 100644 index 000000000..d72a38e19 --- /dev/null +++ b/WinAlfred.WorkflowInstaller/IniParser.cs @@ -0,0 +1,217 @@ +using System; +using System.Collections; +using System.IO; + +namespace WinAlfred.Helper +{ + public class IniParser + { + private Hashtable keyPairs = new Hashtable(); + private String iniFilePath; + + private struct SectionPair + { + public String Section; + public String Key; + } + + /// + /// Opens the INI file at the given path and enumerates the values in the IniParser. + /// + /// Full path to INI file. + public IniParser(String iniPath) + { + TextReader iniFile = null; + String strLine = null; + String currentRoot = null; + String[] keyPair = null; + + iniFilePath = iniPath; + + if (File.Exists(iniPath)) + { + try + { + iniFile = new StreamReader(iniPath); + + strLine = iniFile.ReadLine(); + + while (strLine != null) + { + strLine = strLine.Trim(); + + if (strLine != "") + { + if (strLine.StartsWith("[") && strLine.EndsWith("]")) + { + currentRoot = strLine.Substring(1, strLine.Length - 2).ToUpper(); + } + else + { + keyPair = strLine.Split(new char[] { '=' }, 2); + + SectionPair sectionPair; + String value = null; + + if (currentRoot == null) + currentRoot = "ROOT"; + + sectionPair.Section = currentRoot; + sectionPair.Key = keyPair[0].ToUpper().Trim(); + + if (keyPair.Length > 1) + value = keyPair[1]; + + keyPairs.Add(sectionPair, value.Trim()); + } + } + + strLine = iniFile.ReadLine(); + } + + } + catch (Exception ex) + { + throw ex; + } + finally + { + if (iniFile != null) + iniFile.Close(); + } + } + else + throw new FileNotFoundException("Unable to locate " + iniPath); + } + + /// + /// Returns the value for the given section, key pair. + /// + /// Section name. + /// Key name. + public String GetSetting(String sectionName, String settingName) + { + SectionPair sectionPair; + sectionPair.Section = sectionName.ToUpper().Trim(); + sectionPair.Key = settingName.ToUpper().Trim(); + + return (String)keyPairs[sectionPair]; + } + + /// + /// Enumerates all lines for given section. + /// + /// Section to enum. + public String[] EnumSection(String sectionName) + { + ArrayList tmpArray = new ArrayList(); + + foreach (SectionPair pair in keyPairs.Keys) + { + if (pair.Section == sectionName.ToUpper()) + tmpArray.Add(pair.Key); + } + + return (String[])tmpArray.ToArray(typeof(String)); + } + + /// + /// Adds or replaces a setting to the table to be saved. + /// + /// Section to add under. + /// Key name to add. + /// Value of key. + public void AddSetting(String sectionName, String settingName, String settingValue) + { + SectionPair sectionPair; + sectionPair.Section = sectionName.ToUpper(); + sectionPair.Key = settingName.ToUpper(); + + if (keyPairs.ContainsKey(sectionPair)) + keyPairs.Remove(sectionPair); + + keyPairs.Add(sectionPair, settingValue); + } + + /// + /// Adds or replaces a setting to the table to be saved with a null value. + /// + /// Section to add under. + /// Key name to add. + public void AddSetting(String sectionName, String settingName) + { + AddSetting(sectionName, settingName, null); + } + + /// + /// Remove a setting. + /// + /// Section to add under. + /// Key name to add. + public void DeleteSetting(String sectionName, String settingName) + { + SectionPair sectionPair; + sectionPair.Section = sectionName.ToUpper(); + sectionPair.Key = settingName.ToUpper(); + + if (keyPairs.ContainsKey(sectionPair)) + keyPairs.Remove(sectionPair); + } + + /// + /// Save settings to new file. + /// + /// New file path. + public void SaveSettings(String newFilePath) + { + ArrayList sections = new ArrayList(); + String tmpValue = ""; + String strToSave = ""; + + foreach (SectionPair sectionPair in keyPairs.Keys) + { + if (!sections.Contains(sectionPair.Section)) + sections.Add(sectionPair.Section); + } + + foreach (String section in sections) + { + strToSave += ("[" + section + "]\r\n"); + + foreach (SectionPair sectionPair in keyPairs.Keys) + { + if (sectionPair.Section == section) + { + tmpValue = (String)keyPairs[sectionPair]; + + if (tmpValue != null) + tmpValue = "=" + tmpValue; + + strToSave += (sectionPair.Key + tmpValue + "\r\n"); + } + } + + strToSave += "\r\n"; + } + + try + { + TextWriter tw = new StreamWriter(newFilePath); + tw.Write(strToSave); + tw.Close(); + } + catch (Exception ex) + { + throw ex; + } + } + + /// + /// Save settings back to ini file. + /// + public void SaveSettings() + { + SaveSettings(iniFilePath); + } + } +} \ No newline at end of file diff --git a/WinAlfred.WorkflowInstaller/MainWindow.xaml b/WinAlfred.WorkflowInstaller/MainWindow.xaml new file mode 100644 index 000000000..7e8a79355 --- /dev/null +++ b/WinAlfred.WorkflowInstaller/MainWindow.xaml @@ -0,0 +1,8 @@ + + + + + diff --git a/WinAlfred.WorkflowInstaller/MainWindow.xaml.cs b/WinAlfred.WorkflowInstaller/MainWindow.xaml.cs new file mode 100644 index 000000000..1fae4018e --- /dev/null +++ b/WinAlfred.WorkflowInstaller/MainWindow.xaml.cs @@ -0,0 +1,278 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using ICSharpCode.SharpZipLib.Zip; +using Microsoft.Win32; +using WinAlfred.Helper; +using WinAlfred.Plugin; +using Path = System.IO.Path; + +namespace WinAlfred.WorkflowInstaller +{ + + public partial class MainWindow + { + public MainWindow() + { + InitializeComponent(); + Loaded += MainWindow_Loaded; + string[] param = Environment.GetCommandLineArgs(); + if (param.Length == 2) + { + string workflowPath = param[1]; + //string workflowPath = @"c:\Users\Scott\Desktop\Desktop.winalfred"; + if (workflowPath.EndsWith(".winalfred")) + { + InstallWorkflow(workflowPath); + } + } + } + + private void InstallWorkflow(string path) + { + if (File.Exists(path)) + { + string tempFoler = System.IO.Path.GetTempPath() + "\\winalfred\\workflows"; + if (Directory.Exists(tempFoler)) + { + Directory.Delete(tempFoler, true); + } + UnZip(path, tempFoler, true); + + string iniPath = tempFoler + "\\plugin.ini"; + if (!File.Exists(iniPath)) + { + MessageBox.Show("Install failed: config is missing"); + Close(); + return; + } + + PluginMetadata plugin = GetMetadataFromIni(tempFoler); + if (plugin == null || plugin.Name == null) + { + MessageBox.Show("Install failed: config of this workflow is invalid"); + Close(); + return; + } + + string pluginFolerPath = AppDomain.CurrentDomain.BaseDirectory + "Plugins"; + if (!Directory.Exists(pluginFolerPath)) + { + MessageBox.Show("Install failed: cound't find workflow directory"); + Close(); + return; + } + + string newPluginPath = pluginFolerPath + "\\" + plugin.Name; + string content = string.Format( + "Do you want to install following workflow?\r\nName: {0}\r\nVersion: {1}\r\nAuthor: {2}", + plugin.Name, plugin.Version, plugin.Author); + if (Directory.Exists(newPluginPath)) + { + PluginMetadata existingPlugin = GetMetadataFromIni(newPluginPath); + if (existingPlugin == null || existingPlugin.Name == null) + { + //maybe broken plugin, just delete it + Directory.Delete(newPluginPath, true); + } + else + { + content = string.Format( + "Do you want to update following workflow?\r\nName: {0}\r\nOld Version: {1}\r\nNew Version: {2}\r\nAuthor: {3}", + plugin.Name, existingPlugin.Version, plugin.Version, plugin.Author); + } + } + + MessageBoxResult result = MessageBox.Show(content, "Install workflow", + MessageBoxButton.YesNo, MessageBoxImage.Question); + if (result == MessageBoxResult.Yes) + { + if (Directory.Exists(newPluginPath)) + { + Directory.Delete(newPluginPath, true); + } + UnZip(path, newPluginPath, true); + Directory.Delete(tempFoler, true); + + + string winalfred = AppDomain.CurrentDomain.BaseDirectory + "WinAlfred.exe"; + if (File.Exists(winalfred)) + { + Process.Start(winalfred, "refreshWorkflows"); + MessageBox.Show("You have installed workflow " + plugin.Name + " successfully."); + } + else + { + MessageBox.Show("You have installed workflow " + plugin.Name + " successfully. Please restart your winalfred to use new workflow."); + } + Close(); + } + else + { + Close(); + } + } + } + + private static PluginMetadata GetMetadataFromIni(string directory) + { + string iniPath = directory + "\\plugin.ini"; + + if (!File.Exists(iniPath)) + { + return null; + } + + try + { + PluginMetadata metadata = new PluginMetadata(); + IniParser ini = new IniParser(iniPath); + metadata.Name = ini.GetSetting("plugin", "Name"); + metadata.Author = ini.GetSetting("plugin", "Author"); + metadata.Description = ini.GetSetting("plugin", "Description"); + metadata.Language = ini.GetSetting("plugin", "Language"); + metadata.Version = ini.GetSetting("plugin", "Version"); + metadata.PluginType = PluginType.ThirdParty; + metadata.ActionKeyword = ini.GetSetting("plugin", "ActionKeyword"); + metadata.ExecuteFilePath = directory + "\\" + ini.GetSetting("plugin", "ExecuteFile"); + metadata.PluginDirecotry = directory + "\\"; + metadata.ExecuteFileName = ini.GetSetting("plugin", "ExecuteFile"); + + if (!AllowedLanguage.IsAllowed(metadata.Language)) + { + string error = string.Format("Parse ini {0} failed: invalid language {1}", iniPath, + metadata.Language); + return null; + } + if (!File.Exists(metadata.ExecuteFilePath)) + { + string error = string.Format("Parse ini {0} failed: ExecuteFilePath didn't exist {1}", iniPath, + metadata.ExecuteFilePath); + return null; + } + + return metadata; + } + catch (Exception e) + { + return null; + } + } + + /// + /// unzip + /// + /// The ziped file. + /// The STR directory. + /// overwirte + public void UnZip(string zipedFile, string strDirectory, bool overWrite) + { + if (strDirectory == "") + strDirectory = Directory.GetCurrentDirectory(); + if (!strDirectory.EndsWith("\\")) + strDirectory = strDirectory + "\\"; + + using (ZipInputStream s = new ZipInputStream(File.OpenRead(zipedFile))) + { + ZipEntry theEntry; + + while ((theEntry = s.GetNextEntry()) != null) + { + string directoryName = ""; + string pathToZip = ""; + pathToZip = theEntry.Name; + + if (pathToZip != "") + directoryName = Path.GetDirectoryName(pathToZip) + "\\"; + + string fileName = Path.GetFileName(pathToZip); + + Directory.CreateDirectory(strDirectory + directoryName); + + if (fileName != "") + { + if ((File.Exists(strDirectory + directoryName + fileName) && overWrite) || (!File.Exists(strDirectory + directoryName + fileName))) + { + using (FileStream streamWriter = File.Create(strDirectory + directoryName + fileName)) + { + byte[] data = new byte[2048]; + while (true) + { + int size = s.Read(data, 0, data.Length); + + if (size > 0) + streamWriter.Write(data, 0, size); + else + break; + } + streamWriter.Close(); + } + } + } + } + + s.Close(); + } + } + + void MainWindow_Loaded(object sender, RoutedEventArgs e) + { + string filePath = Directory.GetCurrentDirectory() + "\\WinAlfred.WorkflowInstaller.exe"; + string iconPath = Directory.GetCurrentDirectory() + "\\app.ico"; + + SaveReg(filePath, ".winalfred", iconPath, false); + } + + [DllImport("shell32.dll")] + private static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2); + + private static void SaveReg(string filePath, string fileType, string iconPath, bool overrides) + { + RegistryKey classRootKey = Registry.ClassesRoot.OpenSubKey("", true); + RegistryKey winAlfredKey = classRootKey.OpenSubKey(fileType, true); + if (winAlfredKey != null) + { + if (!overrides) + { + return; + } + classRootKey.DeleteSubKeyTree(fileType); + } + classRootKey.CreateSubKey(fileType); + winAlfredKey = classRootKey.OpenSubKey(fileType, true); + winAlfredKey.SetValue("", "winalfred.winalfred"); + winAlfredKey.SetValue("Content Type", "application/winalfred"); + + RegistryKey iconKey = winAlfredKey.CreateSubKey("DefaultIcon"); + iconKey.SetValue("", iconPath); + + winAlfredKey.CreateSubKey("shell"); + RegistryKey shellKey = winAlfredKey.OpenSubKey("shell", true); + shellKey.SetValue("", "Open"); + RegistryKey openKey = shellKey.CreateSubKey("open"); + openKey.SetValue("", "Open with winalfred"); + + openKey = shellKey.OpenSubKey("open", true); + openKey.CreateSubKey("command"); + RegistryKey commandKey = openKey.OpenSubKey("command", true); + string pathString = "\"" + filePath + "\" \"%1\""; + commandKey.SetValue("", pathString); + + //refresh cache + SHChangeNotify(0x8000000, 0, IntPtr.Zero, IntPtr.Zero); + } + } +} diff --git a/WinAlfred.WorkflowInstaller/Properties/AssemblyInfo.cs b/WinAlfred.WorkflowInstaller/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..a43935313 --- /dev/null +++ b/WinAlfred.WorkflowInstaller/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("WinAlfred.WorkflowInstaller")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("qianlifeng")] +[assembly: AssemblyProduct("WinAlfred.WorkflowInstaller")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +//若要开始生成可本地化的应用程序,请在 +// 中的 .csproj 文件中 +//设置 CultureYouAreCodingWith。例如,如果您在源文件中 +//使用的是美国英语,请将 设置为 en-US。然后取消 +//对以下 NeutralResourceLanguage 特性的注释。更新 +//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。 + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //主题特定资源词典所处位置 + //(在页面或应用程序资源词典中 + // 未找到某个资源的情况下使用) + ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置 + //(在页面、应用程序或任何主题特定资源词典中 + // 未找到某个资源的情况下使用) +)] + + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/WinAlfred.WorkflowInstaller/Properties/Resources.Designer.cs b/WinAlfred.WorkflowInstaller/Properties/Resources.Designer.cs new file mode 100644 index 000000000..ba78eff8c --- /dev/null +++ b/WinAlfred.WorkflowInstaller/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.18052 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace WinAlfred.WorkflowInstaller.Properties +{ + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// 返回此类使用的、缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WinAlfred.WorkflowInstaller.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 为所有资源查找重写当前线程的 CurrentUICulture 属性, + /// 方法是使用此强类型资源类。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/WinAlfred.WorkflowInstaller/Properties/Resources.resx b/WinAlfred.WorkflowInstaller/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/WinAlfred.WorkflowInstaller/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WinAlfred.WorkflowInstaller/Properties/Settings.Designer.cs b/WinAlfred.WorkflowInstaller/Properties/Settings.Designer.cs new file mode 100644 index 000000000..e462a1d2a --- /dev/null +++ b/WinAlfred.WorkflowInstaller/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.18052 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace WinAlfred.WorkflowInstaller.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/WinAlfred.WorkflowInstaller/Properties/Settings.settings b/WinAlfred.WorkflowInstaller/Properties/Settings.settings new file mode 100644 index 000000000..033d7a5e9 --- /dev/null +++ b/WinAlfred.WorkflowInstaller/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/WinAlfred.WorkflowInstaller/WinAlfred.WorkflowInstaller.csproj b/WinAlfred.WorkflowInstaller/WinAlfred.WorkflowInstaller.csproj new file mode 100644 index 000000000..ba739c626 --- /dev/null +++ b/WinAlfred.WorkflowInstaller/WinAlfred.WorkflowInstaller.csproj @@ -0,0 +1,129 @@ + + + + + Debug + AnyCPU + {FAFCAD04-C37E-477B-88C9-0C945E4FB928} + WinExe + Properties + WinAlfred.WorkflowInstaller + WinAlfred.WorkflowInstaller + v3.5 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + ..\ + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + app.manifest + + + app.ico + + + + ..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll + + + + + + + + + + + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + + MainWindow.xaml + Code + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + Designer + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + Always + + + + + {8451ECDD-2EA4-4966-BB0A-7BBC40138E80} + WinAlfred.Plugin + + + + + xcopy /Y $(TargetPath) $(SolutionDir)WinAlfred\bin\Debug\ +xcopy /Y $(TargetDir)ICSharpCode.SharpZipLib.dll $(SolutionDir)WinAlfred\bin\Debug\ + + + + \ No newline at end of file diff --git a/WinAlfred.WorkflowInstaller/app.ico b/WinAlfred.WorkflowInstaller/app.ico new file mode 100644 index 000000000..c5f72ba8b Binary files /dev/null and b/WinAlfred.WorkflowInstaller/app.ico differ diff --git a/WinAlfred.WorkflowInstaller/app.manifest b/WinAlfred.WorkflowInstaller/app.manifest new file mode 100644 index 000000000..234bf987f --- /dev/null +++ b/WinAlfred.WorkflowInstaller/app.manifest @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WinAlfred.WorkflowInstaller/packages.config b/WinAlfred.WorkflowInstaller/packages.config new file mode 100644 index 000000000..e2a24c16d --- /dev/null +++ b/WinAlfred.WorkflowInstaller/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/WinAlfred.sln b/WinAlfred.sln index eca79e1fa..30ec5343e 100644 --- a/WinAlfred.sln +++ b/WinAlfred.sln @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinAlfred.Plugin.System", " EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinAlfred.Plugin.Fanyi", "Plugins\WinAlfred.Plugin.Fanyi\WinAlfred.Plugin.Fanyi.csproj", "{353769D3-D11C-4D86-BD06-AC8C1D68642B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinAlfred.WorkflowInstaller", "WinAlfred.WorkflowInstaller\WinAlfred.WorkflowInstaller.csproj", "{FAFCAD04-C37E-477B-88C9-0C945E4FB928}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -100,6 +102,20 @@ Global {353769D3-D11C-4D86-BD06-AC8C1D68642B}.Release|Win32.ActiveCfg = Release|Any CPU {353769D3-D11C-4D86-BD06-AC8C1D68642B}.Release|x64.ActiveCfg = Release|Any CPU {353769D3-D11C-4D86-BD06-AC8C1D68642B}.Release|x86.ActiveCfg = Release|Any CPU + {FAFCAD04-C37E-477B-88C9-0C945E4FB928}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FAFCAD04-C37E-477B-88C9-0C945E4FB928}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FAFCAD04-C37E-477B-88C9-0C945E4FB928}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {FAFCAD04-C37E-477B-88C9-0C945E4FB928}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {FAFCAD04-C37E-477B-88C9-0C945E4FB928}.Debug|Win32.ActiveCfg = Debug|Any CPU + {FAFCAD04-C37E-477B-88C9-0C945E4FB928}.Debug|x64.ActiveCfg = Debug|Any CPU + {FAFCAD04-C37E-477B-88C9-0C945E4FB928}.Debug|x86.ActiveCfg = Debug|Any CPU + {FAFCAD04-C37E-477B-88C9-0C945E4FB928}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FAFCAD04-C37E-477B-88C9-0C945E4FB928}.Release|Any CPU.Build.0 = Release|Any CPU + {FAFCAD04-C37E-477B-88C9-0C945E4FB928}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {FAFCAD04-C37E-477B-88C9-0C945E4FB928}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {FAFCAD04-C37E-477B-88C9-0C945E4FB928}.Release|Win32.ActiveCfg = Release|Any CPU + {FAFCAD04-C37E-477B-88C9-0C945E4FB928}.Release|x64.ActiveCfg = Release|Any CPU + {FAFCAD04-C37E-477B-88C9-0C945E4FB928}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WinAlfred/Helper/DwmDropShadow.cs b/WinAlfred/Helper/DwmDropShadow.cs new file mode 100644 index 000000000..030accebd --- /dev/null +++ b/WinAlfred/Helper/DwmDropShadow.cs @@ -0,0 +1,73 @@ +using System; +using System.Drawing.Printing; +using System.Runtime.InteropServices; +using System.Windows; +using System.Windows.Interop; + +namespace WinAlfred.Helper +{ + public static class DwmDropShadow + { + + [DllImport("dwmapi.dll", PreserveSig = true)] + private static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize); + + [DllImport("dwmapi.dll")] + private static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins pMarInset); + + /// + /// Drops a standard shadow to a WPF Window, even if the window isborderless. Only works with DWM (Vista and Seven). + /// This method is much more efficient than setting AllowsTransparency to true and using the DropShadow effect, + /// as AllowsTransparency involves a huge permormance issue (hardware acceleration is turned off for all the window). + /// + /// Window to which the shadow will be applied + public static void DropShadowToWindow(Window window) + { + if (!DropShadow(window)) + { + window.SourceInitialized += new EventHandler(window_SourceInitialized); + } + } + + private static void window_SourceInitialized(object sender, EventArgs e) //fixed typo + { + Window window = (Window)sender; + + DropShadow(window); + + window.SourceInitialized -= new EventHandler(window_SourceInitialized); + } + + /// + /// The actual method that makes API calls to drop the shadow to the window + /// + /// Window to which the shadow will be applied + /// True if the method succeeded, false if not + private static bool DropShadow(Window window) + { + try + { + WindowInteropHelper helper = new WindowInteropHelper(window); + int val = 2; + int ret1 = DwmSetWindowAttribute(helper.Handle, 2, ref val, 2); + + if (ret1 == 0) + { + Margins m = new Margins { Bottom = 0, Left = 0, Right = 0, Top = 0 }; + int ret2 = DwmExtendFrameIntoClientArea(helper.Handle, ref m); + return ret2 == 0; + } + else + { + return false; + } + } + catch (Exception ex) + { + // Probably dwmapi.dll not found (incompatible OS) + return false; + } + } + + } +} \ No newline at end of file diff --git a/WinAlfred/MainWindow.xaml b/WinAlfred/MainWindow.xaml index 02da826d8..bb69c1e6b 100644 --- a/WinAlfred/MainWindow.xaml +++ b/WinAlfred/MainWindow.xaml @@ -18,7 +18,7 @@ - + diff --git a/WinAlfred/MainWindow.xaml.cs b/WinAlfred/MainWindow.xaml.cs index b612f9365..27602d97d 100644 --- a/WinAlfred/MainWindow.xaml.cs +++ b/WinAlfred/MainWindow.xaml.cs @@ -9,12 +9,14 @@ using System.Windows.Input; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.Windows.Threading; -using IWshRuntimeLibrary; using Microsoft.Win32; using WinAlfred.Commands; using WinAlfred.Helper; using WinAlfred.Plugin; using WinAlfred.PluginLoader; +using DataFormats = System.Windows.DataFormats; +using DragDropEffects = System.Windows.DragDropEffects; +using DragEventArgs = System.Windows.DragEventArgs; using KeyEventArgs = System.Windows.Input.KeyEventArgs; using MessageBox = System.Windows.MessageBox; using Timer = System.Threading.Timer; @@ -84,14 +86,6 @@ namespace WinAlfred } } - protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) - { - base.OnMouseLeftButtonDown(e); - - // Begin dragging the window - this.DragMove(); - } - private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e) { resultCtrl.Dirty = true; @@ -148,21 +142,21 @@ namespace WinAlfred private void SetAutoStart(bool IsAtuoRun) { - string LnkPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "//WinAlfred.lnk"; - if (IsAtuoRun) - { - WshShell shell = new WshShell(); - IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(LnkPath); - shortcut.TargetPath = System.Reflection.Assembly.GetExecutingAssembly().Location; - shortcut.WorkingDirectory = Environment.CurrentDirectory; - shortcut.WindowStyle = 1; //normal window - shortcut.Description = "WinAlfred"; - shortcut.Save(); - } - else - { - System.IO.File.Delete(LnkPath); - } + //string LnkPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "//WinAlfred.lnk"; + //if (IsAtuoRun) + //{ + // WshShell shell = new WshShell(); + // IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(LnkPath); + // shortcut.TargetPath = System.Reflection.Assembly.GetExecutingAssembly().Location; + // shortcut.WorkingDirectory = Environment.CurrentDirectory; + // shortcut.WindowStyle = 1; //normal window + // shortcut.Description = "WinAlfred"; + // shortcut.Save(); + //} + //else + //{ + // System.IO.File.Delete(LnkPath); + //} } private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) @@ -262,5 +256,6 @@ namespace WinAlfred } #endregion + } } \ No newline at end of file diff --git a/WinAlfred/Properties/Resources.resx b/WinAlfred/Properties/Resources.resx index 3ae43d89b..5dcdc10fd 100644 --- a/WinAlfred/Properties/Resources.resx +++ b/WinAlfred/Properties/Resources.resx @@ -119,6 +119,6 @@ - ..\Resources\app.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\app.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a \ No newline at end of file diff --git a/WinAlfred/WinAlfred.csproj b/WinAlfred/WinAlfred.csproj index 66418b728..72c2e6ebc 100644 --- a/WinAlfred/WinAlfred.csproj +++ b/WinAlfred/WinAlfred.csproj @@ -94,6 +94,7 @@ + @@ -189,23 +190,15 @@ - - - - - {F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} - 1 - 0 - 0 - tlbimp - False - True - + + Always + - xcopy /Y $(ProjectDir)Images\*.* $(SolutionDir)WinAlfred\bin\Debug\Images\ + xcopy /Y $(ProjectDir)Images\*.* $(SolutionDir)WinAlfred\bin\Debug\Images\ +xcopy /Y $(ProjectDir)app.ico $(SolutionDir)WinAlfred\bin\Debug\