Exemplo n.º 1
0
        private void Execute_Command_Button_Save(object Parameter)
        {
            M_Settings set = new M_Settings();

            int i = 1;

            if (Int32.TryParse(Delay, out i))
            {
                set.Delay = Convert.ToInt32(Delay);
            }
            else
            {
                Bindermessage.ShowWarning("Bitte geben Sie das Delay in Millisekunden an!\nEs sind nur positive Ganzzahlen erlaubt.");
                return;
            }

            if (Int32.TryParse(MultiCommanDelay, out i))
            {
                set.MultiCommanDelay = Convert.ToInt32(MultiCommanDelay);
            }
            else
            {
                Bindermessage.ShowWarning("Bitte geben Sie das MultiCommandDelay in Millisekunden an!\nEs sind nur positive Ganzzahlen erlaubt.");
                return;
            }

            set.Name = Name;

            string m_appdatapath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string m_foldername  = "Bonnyfication";
            string m_FileName    = "Keybinds_Settings.xml";
            string m_Fullpath    = Path.Combine(m_appdatapath, m_foldername, m_FileName);

            try
            {
                XmlSerializer seri = new XmlSerializer(typeof(M_Settings));
                using (StreamWriter writ = new StreamWriter(m_Fullpath))
                {
                    seri.Serialize(writ, set);
                }
            }
            catch (Exception ex)
            {
                Bindermessage.ShowError("Fehler beim Speichern der Einstellungen!\n\nError:\n" + ex);
            }


            _CONTROLLER.RestartKeybinder();
        }
Exemplo n.º 2
0
    public void CreateAHKFile(ObservableCollection <M_Binding> ListeKeybinds, M_Settings m_Einstellungen)
    {
        // Directory
        string m_appdatapath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
        string m_foldername  = "Bonnyfication";
        string m_FileName    = "Keybinds_Script.ahk";
        string m_Fullpath    = Path.Combine(m_appdatapath, m_foldername, m_FileName);

        // Lade Default String für die AHK Datei mit Standardfunktionen
        string m_defaultString = GetDefaultSettingsAHK(m_Einstellungen);
        string m_CloseTag      = "return\r\n";

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

        foreach (M_Binding k in ListeKeybinds)
        {
            string m_NewKeybind = String.Empty;
            m_NewKeybind += "\r\n";

            // Hole den Befehl im AHK Format
            if (GetKeyString(k) == String.Empty)
            {
                Bindermessage.ShowWarning("Ein Hotkey konnte nicht konvertiert werden!\n\nFehlerhafter Hotkey:\n" + k.Bezeichnung);
                continue;
            }

            m_NewKeybind += GetKeyString(k);

            // Für jedes Command in der Commands Auflistung

            if (k.Auflistung_BindingOptions.Count > 1) // MEHRERE COMMANDS
            {
                for (int i = 0; i < k.Auflistung_BindingOptions.Count(); i++)
                {
                    if (i + 1 == k.Auflistung_BindingOptions.Count())
                    {
                        if (k.AutoEnter)
                        {
                            m_NewKeybind += "SendMessage(\"" + GetEscapedString(k.Auflistung_BindingOptions[i].cmd) + "\")\r\n";
                        }
                        else
                        {
                            m_NewKeybind += "SendMessageNoEnter(\"" + GetEscapedString(k.Auflistung_BindingOptions[i].cmd) + " \")\r\n";
                        }
                    }
                    else
                    {
                        m_NewKeybind += "SendMessage(\"" + GetEscapedString(k.Auflistung_BindingOptions[i].cmd) + "\")\r\n";
                        m_NewKeybind += "Sleep, " + m_Einstellungen.MultiCommanDelay.ToString() + "\r\n";
                    }
                }
            }
            else // Ein Command
            {
                if (k.AutoEnter)
                {
                    m_NewKeybind += "SendMessage(\"" + GetEscapedString(k.Auflistung_BindingOptions[0].cmd) + "\")\r\n";
                }
                else
                {
                    m_NewKeybind += "SendMessageNoEnter(\"" + GetEscapedString(k.Auflistung_BindingOptions[0].cmd) + " \")\r\n";
                }
            }


            m_NewKeybind += m_CloseTag;
            m_AuflistungHotkeys.Add(m_NewKeybind);
        }

        //Create the AHK File
        using (StreamWriter wr = new StreamWriter(m_Fullpath))
        {
            //Write Defaults
            wr.WriteLine(m_defaultString);

            foreach (string s in m_AuflistungHotkeys)
            {
                wr.WriteLine(s);
            }
        }
    }