예제 #1
0
        public void Import(JsonGestureIntentStore from, bool replace = false)
        {
            if (from == null)
            {
                return;
            }

            if (replace)
            {
                GlobalApp.GestureIntents.Clear();
                GlobalApp.IsGesturingEnabled = from.GlobalApp.IsGesturingEnabled;
                ExeAppsRegistry.Clear();
            }

            GlobalApp.ImportGestures(from.GlobalApp);

            foreach (var kv in from.ExeAppsRegistry)
            {
                ExeApp appInSelf;
                //如果应用程序已经在列表中,则合并手势
                if (TryGetExeApp(kv.Key, out appInSelf))
                {
                    appInSelf.ImportGestures(kv.Value);
                    appInSelf.IsGesturingEnabled = appInSelf.IsGesturingEnabled && kv.Value.IsGesturingEnabled;
                }
                else//否则将app添加到列表中
                {
                    Add(kv.Value);
                }
            }
        }
예제 #2
0
        public JsonGestureIntentStore Clone()
        {
            var ret = new JsonGestureIntentStore();
            ret.GlobalApp = GlobalApp;
            ret.Apps = Apps;
            ret.FileVersion = FileVersion;
            ret.jsonPath = jsonPath;

            return ret;
        }
예제 #3
0
        public JsonGestureIntentStore Clone()
        {
            var ret = new JsonGestureIntentStore();

            ret.GlobalApp       = GlobalApp;
            ret.ExeAppsRegistry = ExeAppsRegistry;
            ret.FileVersion     = FileVersion;
            ret.jsonPath        = jsonPath;

            return(ret);
        }
예제 #4
0
        public JsonGestureIntentStore Clone()
        {
            //fixme: dummy impl
            var ret = new JsonGestureIntentStore();

            ret.GlobalApp         = GlobalApp;
            ret.Apps              = Apps;
            ret.FileVersion       = FileVersion;
            ret.jsonPath          = jsonPath;
            ret.HotCornerCommands = HotCornerCommands;
            return(ret);
        }
예제 #5
0
        public SettingsFormController(IConfig config, GestureParser parser,
            Win32MousePathTracker2 pathTracker, JsonGestureIntentStore intentStore,
            CanvasWindowGestureView gestureView)
        {
            _config = config;
            _parser = parser;
            _pathTracker = pathTracker;
            _intentStore = intentStore;
            _gestureView = gestureView;

            #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));
            
            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));

            HotCornerCommandViewFactory.Register<DoNothingCommand, GeneralNoParameterCommandView>();
            HotCornerCommandViewFactory.Register<HotKeyCommand, HotKeyCommandView>();
            #endregion

            _form = new SettingsForm(this);
        }
예제 #6
0
        public void Import(JsonGestureIntentStore from, bool replace = false)
        {
            if (from == null)
            {
                return;
            }

            if (replace)
            {
                GlobalApp.GestureIntents.Clear();
                GlobalApp.IsGesturingEnabled = from.GlobalApp.IsGesturingEnabled;
                Apps.Clear();
                HotCornerCommands = from.HotCornerCommands;
            }
            else
            {
                for (var i = 0; i < from.HotCornerCommands.Length; i++)
                {
                    if (from.HotCornerCommands[i] != null)
                    {
                        HotCornerCommands[i] = from.HotCornerCommands[i];
                    }
                }
            }

            GlobalApp.ImportGestures(from.GlobalApp);

            foreach (var kv in from.Apps)
            {
                ExeApp appInSelf;
                //如果应用程序已经在列表中,则合并手势
                if (TryGetExeApp(kv.Key.ToLower(), out appInSelf))
                {
                    appInSelf.ImportGestures(kv.Value);
                    appInSelf.IsGesturingEnabled = appInSelf.IsGesturingEnabled && kv.Value.IsGesturingEnabled;
                }
                else//否则将app添加到列表中
                {
                    Add(kv.Value);
                }
            }
        }
예제 #7
0
        public void Import(JsonGestureIntentStore from, bool replace=false)
        {
            if (from == null) return;

            if (replace)
            {
                GlobalApp.GestureIntents.Clear();
                GlobalApp.IsGesturingEnabled = from.GlobalApp.IsGesturingEnabled;
                Apps.Clear();
            }

            GlobalApp.ImportGestures(from.GlobalApp);

            foreach (var kv in from.Apps)
            {
                ExeApp appInSelf;
                //如果应用程序已经在列表中,则合并手势
                if (TryGetExeApp(kv.Key.ToLower(), out appInSelf))
                {
                    appInSelf.ImportGestures(kv.Value);
                    appInSelf.IsGesturingEnabled = appInSelf.IsGesturingEnabled && kv.Value.IsGesturingEnabled;
                }
                else//否则将app添加到列表中
                {
                    Add(kv.Value);
                }
            }
        }
예제 #8
0
        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 configFile = recent + @"\config.plist";

            try
            {
                if (File.Exists(gesturesFileV1))
                {
                    gestures = new JsonGestureIntentStore(gesturesFileV1, "1");
                }else if (File.Exists(gestureFileV2))
                {
                    gestures = new JsonGestureIntentStore(gestureFileV2, "2");
                }

                if (File.Exists(configFile))
                {
                    config = new PlistConfig(configFile);
                }
            }
            catch (Exception e)
            {

                throw new MigrateException(e.Message, e);
            }


            return new ConfigAndGestures(config, gestures);

        }
예제 #9
0
        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
                    {
                        var version = "1";
                        if (fileName.EndsWith(".json"))
                        {
                            version = "1";
                        }
                        else if (fileName.EndsWith(".wg"))
                        {
                            version = "2";
                        }
                        gestures = new JsonGestureIntentStore(file.GetStream(), true, version);
                    }

                }
            }
            catch (Exception e)
            {
                if (e is SystemException) throw;
                throw new MigrateException("文件内容错误");
            }
            

            if(config == null || gestures == null) throw new MigrateException("文件内容错误");

            return new ConfigAndGestures(config, gestures);
            

        }
예제 #10
0
        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);
        }
예제 #11
0
 public JsonGestureIntentStore Clone()
 {
     //fixme: dummy impl
     var ret = new JsonGestureIntentStore();
     ret.GlobalApp = GlobalApp;
     ret.Apps = Apps;
     ret.FileVersion = FileVersion;
     ret.jsonPath = jsonPath;
     ret.HotCornerCommands = HotCornerCommands;
     return ret;
 }
예제 #12
0
        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();
        }
예제 #13
0
        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);
            }
        }
예제 #14
0
 public ConfigAndGestures(PlistConfig config, JsonGestureIntentStore gestures)
 {
     Config = config;
     GestureIntentStore = gestures;
 }