public void Dispose() { if (IsDisposed) { return; } IsDisposed = true; if (CommandViewFactory != null) { CommandViewFactory.Dispose(); } _config = null; _parser = null; _gestureView = null; _intentStore = null; _pathTracker = null; SupportedCommands.Clear(); SupportedCommands = null; CommandViewFactory = null; _form.Dispose(); _form = null; //GC.Collect(); }
public static ConfigAndGestures ImportWgb(string wgbFilePath) { if (!File.Exists(wgbFilePath)) { throw new MigrateException("文件不存在:" + wgbFilePath); } var config = null as PlistConfig; var gestures = null as JsonGestureIntentStore; var cofnigFileName = Path.GetFileName(AppSettings.ConfigFilePath); var gesturesFileName = Path.GetFileName(AppSettings.GesturesFilePath); var arcFile = new StreamingArchiveFile(wgbFilePath); var files = arcFile.FileIndex.IndexedFileNames.ToArray(); var fileShortNames = (from f in files select Path.GetFileName(f)).ToArray(); if (!fileShortNames.Contains(cofnigFileName) || !fileShortNames.Contains(gesturesFileName)) { throw new MigrateException("文件内容不正确(未找到需要的部分): " + wgbFilePath); } try { // iterate the files in the archive: foreach (var fileName in files) { // write the name of the file Debug.Print("File: " + fileName); // extract the file: var file = arcFile.GetFile(fileName); //file.SaveAs("text.txt"); //config file if (Path.GetFileName(fileName) == cofnigFileName) { config = new PlistConfig(file.GetStream(), closeStream: true); } else if (Path.GetFileName(fileName) == gesturesFileName) { gestures = new JsonGestureIntentStore(file.GetStream(), closeStream: true); } } return(new ConfigAndGestures(config, gestures)); } catch (Exception e) { if (e is SystemException) { throw; } throw new MigrateException("导入错误", e); } }
private static void LoadFailSafeConfigFile() { #if Scafolding config = new PlistConfig(AppSettings.ConfigFilePath) { FileVersion = AppSettings.ConfigFileVersion }; intentStore = new JsonGestureIntentStore(AppSettings.GesturesFilePath, AppSettings.GesturesFileVersion); return; #endif if (!File.Exists(AppSettings.ConfigFilePath)) { File.Copy(string.Format("{0}/defaults/config.plist", Path.GetDirectoryName(Application.ExecutablePath)), AppSettings.ConfigFilePath); } if (!File.Exists(AppSettings.GesturesFilePath)) { File.Copy(string.Format("{0}/defaults/gestures.wg", Path.GetDirectoryName(Application.ExecutablePath)), AppSettings.GesturesFilePath); } //如果文件损坏,则替换。 try { config = new PlistConfig(AppSettings.ConfigFilePath); } catch (Exception) { Debug.WriteLine("Program.Main: config文件损坏!"); File.Delete(AppSettings.ConfigFilePath); File.Copy(string.Format("{0}/defaults/config.plist", Path.GetDirectoryName(Application.ExecutablePath)), AppSettings.ConfigFilePath); config = new PlistConfig(AppSettings.ConfigFilePath); } try { intentStore = new JsonGestureIntentStore(AppSettings.GesturesFilePath, AppSettings.GesturesFileVersion); if (config.FileVersion != AppSettings.ConfigFileVersion || intentStore.FileVersion != AppSettings.GesturesFileVersion) { throw new Exception("配置文件版本不正确"); } } catch (Exception e) { Debug.WriteLine("加载配置文件出错:" + e); File.Delete(AppSettings.GesturesFilePath); File.Copy(string.Format("{0}/defaults/gestures.wg", Path.GetDirectoryName(Application.ExecutablePath)), AppSettings.GesturesFilePath); intentStore = new JsonGestureIntentStore(AppSettings.GesturesFilePath, AppSettings.GesturesFileVersion); } }
public SettingsFormController(IConfig config, GestureParser parser, Win32MousePathTracker2 pathTracker, JsonGestureIntentStore intentStore, CanvasWindowGestureView gestureView, GlobalHotKeyManager hotkeyMgr) { _config = config; _parser = parser; _pathTracker = pathTracker; _intentStore = intentStore; _gestureView = gestureView; _hotkeyMgr = hotkeyMgr; #region 初始化支持的命令和命令视图 //Add Command Types SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(DoNothingCommand)), typeof(DoNothingCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(HotKeyCommand)), typeof(HotKeyCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(WebSearchCommand)), typeof(WebSearchCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(WindowControlCommand)), typeof(WindowControlCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(TaskSwitcherCommand)), typeof(TaskSwitcherCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(OpenFileCommand)), typeof(OpenFileCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(SendTextCommand)), typeof(SendTextCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(GotoUrlCommand)), typeof(GotoUrlCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(CmdCommand)), typeof(CmdCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(ScriptCommand)), typeof(ScriptCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(PauseWGesturesCommand)), typeof(PauseWGesturesCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(ChangeAudioVolumeCommand)), typeof(ChangeAudioVolumeCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(AddToBacklistCommand)), typeof(AddToBacklistCommand)); CommandViewFactory.Register <AddToBacklistCommand, GeneralNoParameterCommandView>(); CommandViewFactory.Register <OpenFileCommand, OpenFileCommandView>(); CommandViewFactory.Register <DoNothingCommand, GeneralNoParameterCommandView>(); CommandViewFactory.Register <HotKeyCommand, HotKeyCommandView>(); CommandViewFactory.Register <GotoUrlCommand, GotoUrlCommandView>(); CommandViewFactory.Register <PauseWGesturesCommand, GeneralNoParameterCommandView>(); CommandViewFactory.Register <WebSearchCommand, WebSearchCommandView>(); CommandViewFactory.Register <WindowControlCommand, WindowControlCommandView>(); CommandViewFactory.Register <CmdCommand, CmdCommandView>(); CommandViewFactory.Register <SendTextCommand, SendTextCommandView>(); CommandViewFactory.Register <TaskSwitcherCommand, TaskSwitcherCommandView>(); CommandViewFactory.Register <ScriptCommand, ScriptCommandView>(); CommandViewFactory.Register <ChangeAudioVolumeCommand, GeneralNoParameterCommandView>(); #endregion #region Hotcorner SupportedHotCornerCommands.Add(NamedAttribute.GetNameOf(typeof(DoNothingCommand)), typeof(DoNothingCommand)); SupportedHotCornerCommands.Add(NamedAttribute.GetNameOf(typeof(HotKeyCommand)), typeof(HotKeyCommand)); SupportedHotCornerCommands.Add(NamedAttribute.GetNameOf(typeof(CmdCommand)), typeof(CmdCommand)); HotCornerCommandViewFactory.Register <DoNothingCommand, GeneralNoParameterCommandView>(); HotCornerCommandViewFactory.Register <HotKeyCommand, HotKeyCommandView>(); HotCornerCommandViewFactory.Register <CmdCommand, CmdCommandView>(); #endregion _form = new SettingsForm(this); }
public static ConfigAndGestures ImportJsonGestures(string jsonPath, string version) { if (!File.Exists(jsonPath)) { throw new MigrateException("文件不存在:" + jsonPath); } var intentStore = new JsonGestureIntentStore(jsonPath, version); return(new ConfigAndGestures(null, intentStore)); }
public SettingsFormController(IConfig config, GestureParser parser, Win32MousePathTracker2 pathTracker, JsonGestureIntentStore intentStore, CanvasWindowGestureView gestureView) { _config = config; _parser = parser; _pathTracker = pathTracker; _intentStore = intentStore; _gestureView = gestureView; #region 初始化支持的命令和命令视图 SupportedCommands = new Dictionary <string, Type>(); CommandViewFactory = new CommandViewFactory <CommandViewUserControl>() { EnableCaching = false }; //Add Command Types SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(DoNothingCommand)), typeof(DoNothingCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(HotKeyCommand)), typeof(HotKeyCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(WebSearchCommand)), typeof(WebSearchCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(WindowControlCommand)), typeof(WindowControlCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(TaskSwitcherCommand)), typeof(TaskSwitcherCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(OpenFileCommand)), typeof(OpenFileCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(SendTextCommand)), typeof(SendTextCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(GotoUrlCommand)), typeof(GotoUrlCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(CmdCommand)), typeof(CmdCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(PauseWGesturesCommand)), typeof(PauseWGesturesCommand)); SupportedCommands.Add(NamedAttribute.GetNameOf(typeof(ChangeAudioVolumeCommand)), typeof(ChangeAudioVolumeCommand)); CommandViewFactory.Register <OpenFileCommand, OpenFileCommandView>(); CommandViewFactory.Register <DoNothingCommand, GeneralNoParameterCommandView>(); CommandViewFactory.Register <HotKeyCommand, HotKeyCommandView>(); CommandViewFactory.Register <GotoUrlCommand, GotoUrlCommandView>(); CommandViewFactory.Register <PauseWGesturesCommand, GeneralNoParameterCommandView>(); CommandViewFactory.Register <WebSearchCommand, WebSearchCommandView>(); CommandViewFactory.Register <WindowControlCommand, WindowControlCommandView>(); CommandViewFactory.Register <CmdCommand, CmdCommandView>(); CommandViewFactory.Register <SendTextCommand, SendTextCommandView>(); CommandViewFactory.Register <TaskSwitcherCommand, TaskSwitcherCommandView>(); CommandViewFactory.Register <ChangeAudioVolumeCommand, GeneralNoParameterCommandView>(); #endregion _form = new SettingsForm(this); }
public static ConfigAndGestures ImportPrevousVersion() { var possibleDirs = Directory.GetDirectories(Directory.GetParent(AppSettings.UserDataDirectory).FullName); possibleDirs = possibleDirs.Where(s => { var dirName = Path.GetFileName(s); int num; return(dirName.Split('.').Length == 4 && int.TryParse(dirName.Replace(".", string.Empty), out num)); }).ToArray(); if (possibleDirs.Length < 2) { return(null); } Func <string, int[]> splitToInts = s => Path.GetFileName(s).Split('.').Select(i => int.Parse(i)).ToArray(); Array.Sort(possibleDirs, (a, b) => { var aNums = splitToInts(a); var bNums = splitToInts(b); var compareResult = 0; for (var i = 0; i < aNums.Length; i++) { if (aNums[i] == bNums[i]) { continue; } compareResult = aNums[i].CompareTo(bNums[i]); break; } return(compareResult); }); //获得最近的那个版本的数据目录 var recent = possibleDirs[possibleDirs.Length - 2]; var gestures = null as JsonGestureIntentStore; var config = null as PlistConfig; var gesturesFileV1 = recent + @"\gestures.json"; var gestureFileV2 = recent + @"\gestures.wg"; var gestureFileV3 = recent + @"\gestures.wg2"; var configFile = recent + @"\config.plist"; try { if (File.Exists(gesturesFileV1)) { gestures = new JsonGestureIntentStore(gesturesFileV1, "1"); } else if (File.Exists(gestureFileV2)) { gestures = new JsonGestureIntentStore(gestureFileV2, "2"); } else if (File.Exists(gestureFileV3)) { gestures = new JsonGestureIntentStore(gestureFileV3, "3"); } if (File.Exists(configFile)) { config = new PlistConfig(configFile); } } catch (Exception e) { throw new MigrateException(e.Message, e); } return(new ConfigAndGestures(config, gestures)); }
public ConfigAndGestures(PlistConfig config, JsonGestureIntentStore gestures) { Config = config; GestureIntentStore = gestures; }