Esempio n. 1
0
        public void ImportKeyfile(string keyfilePath)
        {
            Keyfile keyfile = null;

            try
            {
                keyfile = this.jsSerializer.Deserialize <Keyfile>(this.DecryptFile(keyfilePath));
            }
            catch (InvalidOperationException e)
            {
                MessageBox.Show(string.Format(Constants.IMPORT_KEYFILE_BAD_FORMAT, e.Message), Constants.IMPORT_KEYFILE_TITLE_ERROR);
                return;
            }

            if (Assembly.GetEntryAssembly().GetName().Version.ToString().CompareTo(keyfile.version) < 0)
            {
                MessageBox.Show(Constants.IMPORT_KEYFILE_NEWER_LAYOUT, Constants.IMPORT_KEYFILE_TITLE_ERROR);
                return;
            }

            if (keyfile.lrVersion != this.lrVersion)
            {
                MessageBox.Show(string.Format(Constants.IMPORT_KEYFILE_WRONG_VERSION, keyfile.lrVersion, this.lrVersion), Constants.IMPORT_KEYFILE_TITLE_ERROR);
                return;
            }

            string filenameVKEYS = keyfile.uuid + Constants.KEYFILE_VKEYS_EXTENSION;
            string toPathVKEYS   = Path.Combine(this.keyfileDirectory, filenameVKEYS);

            if (File.Exists(toPathVKEYS))
            {
                File.Delete(toPathVKEYS);
                return;
            }

            string filenameJSON = keyfile.uuid + Constants.KEYFILE_JSON_EXTENSION;
            string toPathJSON   = Path.Combine(this.keyfileDirectory, filenameJSON);

            if (File.Exists(toPathJSON))
            {
                File.Delete(toPathJSON);
                return;
            }

            File.Move(keyfilePath, toPathJSON);

            this.LoadAllKeyfiles();
            this.LoadDictionaryFromActiveKeysFile();
            this.ResetStatusMenu();

            this.DeletePdfFile(keyfile.uuid);

            MessageBox.Show(string.Format(Constants.IMPORT_KEYFILE_SUCCESS, keyfile.name), Constants.IMPORT_KEYFILE_TITLE_SUCCESS);
        }
Esempio n. 2
0
        private void ResetStatusMenu()
        {
            ContextMenu menu = new ContextMenu();

            /*
             * if (!this.authSuccess)
             * {
             *  this.AddItemToMenu(Constants.STATUSMENUITEM_REGISTER, menu, new System.Windows.RoutedEventHandler(this.BringLicenseWindowToFront));
             * }
             * else
             * {*/
            this.ToggleMenuItem = this.AddItemToMenu(Constants.STATUSMENUITEM_INACTIVE, menu, new System.Windows.RoutedEventHandler(this.MenuToggleKeysActive));
            this.AddItemToMenu(Constants.STATUSMENUITEM_PREFERENCES, menu, new System.Windows.RoutedEventHandler(this.ShowMainWindow));
            menu.Items.Add(new Separator());

            List <string> keys = new List <string>();

            if (this.keyfileList != null)
            {
                keys = this.keyfileList.Keys.ToList();
                keys.Sort((key1, key2) => { return(this.keyfileList[key1].name.CompareTo(this.keyfileList[key2].name)); });
            }

            foreach (string key in keys)
            {
                Keyfile keyfile = this.keyfileList[key];

                if (!keyfile.isActive)
                {
                    continue;
                }

                this.AddItemToMenu(keyfile.name, menu, new System.Windows.RoutedEventHandler(this.KeyfileMenuSelected));
            }

            menu.Items.Add(new Separator());

            this.AddItemToMenu(Constants.STATUSMENUITEM_ABOUT, menu, new System.Windows.RoutedEventHandler(this.ShowAboutWindow));
            //}

            this.AddItemToMenu(Constants.STATUSMENUITEM_QUIT, menu, new System.Windows.RoutedEventHandler(this.QuitApplication));

            if (this.statusBar != null)
            {
                this.statusBar.ContextMenu = menu;
            }

            if (this.authSuccess)
            {
                this.SetMenuForKeyFileActive();
            }
        }
Esempio n. 3
0
        private void LoadAllKeyfiles()
        {
            this.keyfileList = new Dictionary <string, Keyfile>();

            foreach (string filepath in System.IO.Directory.GetFiles(this.keyfileDirectory, "*.*", SearchOption.AllDirectories).Where(s => s.ToLower().EndsWith(Constants.KEYFILE_VKEYS_EXTENSION) || s.ToLower().EndsWith(Constants.KEYFILE_JSON_EXTENSION)))
            {
                string contents = this.DecryptFile(filepath);

                Keyfile keyfile = this.GetLatestVersion(contents);

                if (keyfile == null || keyfile.lrVersion != this.lrVersion)
                {
                    continue;
                }

                keyfile.filename = Path.GetFileName(filepath);

                if (Properties.Settings.Default.KeyfileSettings.ContainsKey(keyfile.uuid))
                {
                    keyfile.isActive = Properties.Settings.Default.KeyfileSettings[keyfile.uuid].isActive;
                }
                else
                {
                    keyfile.isActive = true;
                    Properties.Settings.Default.KeyfileSettings[keyfile.uuid]          = new KeyfileSettings();
                    Properties.Settings.Default.KeyfileSettings[keyfile.uuid].isActive = true;
                }

                if (!this.keyfileList.ContainsKey(keyfile.uuid))
                {
                    this.keyfileList.Add(keyfile.uuid, keyfile);
                }
                else
                {
                    KeyControl.TraceLine(string.Format("Keyfile id {0} already exists. Skipping file load.", keyfile.uuid));
                }
            }

            this.InitActiveKeyfile();
        }
Esempio n. 4
0
        private Keyfile GetLatestVersion(string contents)
        {
            Keyfile keyfile = this.jsSerializer.Deserialize <Keyfile>(contents);

            foreach (var key in keyfile.keys)
            {
                if (key.adj.ContainsKey(Constants.KEYFILE_ADJUSTMENT_REMAP_NODENAME))
                {
                    string    remapKey = key.adj[Constants.KEYFILE_ADJUSTMENT_REMAP_NODENAME] as string;
                    Modifiers remapMod = Modifiers.None;

                    if (remapKey == null)
                    {
                        Dictionary <string, object> remapDict = key.adj[Constants.KEYFILE_ADJUSTMENT_REMAP_NODENAME] as Dictionary <string, object>;

                        if (remapDict != null)
                        {
                            remapKey = (string)remapDict[Constants.KEYFILE_KEY_NODENAME];
                            remapMod = (Modifiers)int.Parse((string)remapDict[Constants.KEYFILE_MODIFIERS_NODENAME]);

                            if ((remapMod & Modifiers.Windows) == Modifiers.Windows)
                            {
                                remapMod |= Modifiers.Control;
                                remapMod ^= Modifiers.Windows;
                            }
                        }
                    }

                    KeyCommand cmd = new KeyCommand();
                    cmd.mod = remapMod;
                    cmd.key = int.Parse(remapKey);
                    cmd.adj = null;
                    key.adj[Constants.KEYFILE_ADJUSTMENT_REMAP_NODENAME] = cmd;
                }
            }

            return(keyfile);
        }