private void CheckAppStartAsAdmin()
        {
            var wi = WindowsIdentity.GetCurrent();
            var wp = new WindowsPrincipal(wi);

            bool runAsAdmin = wp.IsInRole(WindowsBuiltInRole.Administrator);

            // OH WIR SIND KEIN ADMIN!!!!!
            if (!runAsAdmin)
            {
                ProcessStartInfo info = new ProcessStartInfo(Application.ResourceAssembly.Location);
                info.UseShellExecute = true;
                if (System.Environment.OSVersion.Version.Major >= 6)
                {
                    info.Verb = "runas";
                }

                // Start the new process
                try
                {
                    Process.Start(info);
                }
                catch (Exception)
                {
                    Bindermessage.ShowError("Ups...Ich kann leider ohne Administrative Rechte nicht richtig funktionieren.");
                }

                Application.Current.Shutdown();
            }
        }
        private void StoreKeybinds()
        {
            if (m_Auflistung_Keybinds.Count == 0)
            {
                return;
            }

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

            try
            {
                XmlSerializer seri = new XmlSerializer(typeof(ObservableCollection <M_Binding>));
                using (StreamWriter writ = new StreamWriter(m_Fullpath))
                {
                    seri.Serialize(writ, m_Auflistung_Keybinds);
                }
            }
            catch (Exception ex)
            {
                Bindermessage.ShowError("Fehler beim Speichern der Keybinds!\n\nError:\n" + ex);
            }
        }
        private void Execute_Command_Button_Add_Hotkey(object Parameter)
        {
            if (m_Command == null || m_Hotkey == null)
            {
                return;
            }

            if (m_Hotkey.Trim().Length != 0 && m_Hotkey != "BELEGT" && m_Hotkey != "ERROR" && m_Command.Trim().Length != 0)
            {
                // Baue Hotkey und Hotkey Display Objekt
                M_Binding Disp = new M_Binding();
                Disp.Bezeichnung   = m_Hotkey;
                Disp.KeyValue      = CurrentKeyValue;
                Disp.KeyValueForms = (int)(System.Windows.Forms.Keys)KeyInterop.VirtualKeyFromKey((Key)CurrentKeyValue);
                Disp.ModValue      = CurrentKeyModValue;
                Disp.AutoEnter     = AutoEnter;

                Disp.Auflistung_BindingOptions = new List <M_BindingOption>();

                // Command aufsplitten, wenn Contains ~
                if (m_Command.Contains("~"))
                {
                    if (!AutoEnter)
                    {
                        // Hinweis Anzeigen, wenn Mehrere Commands da sind, aber AutoEnter False ist
                        if (MessageBoxResult.No == Bindermessage.ShowQuestionYesNo("Sie haben den Hotkey mit mehreren Befehlen belegt und die Auto-Enter Funktion deaktiviert!\nBeachten Sie, dass hierdurch nur der letzte Befehl nicht automatisch abgesendet wird!\n\nMöchten Sie den Hotkey trotzdem hinzufügen?"))
                        {
                            return;
                        }
                    }


                    string[] commands = m_Command.Split('~');

                    foreach (string command in commands)
                    {
                        M_BindingOption opt = new M_BindingOption();
                        opt.cmd = command.TrimStart();
                        Disp.Auflistung_BindingOptions.Add(opt);
                    }
                }
                else
                {
                    M_BindingOption opt = new M_BindingOption();
                    opt.cmd = m_Command.TrimStart();
                    Disp.Auflistung_BindingOptions.Add(opt);
                }

                m_Auflistung_Keybinds.Add(Disp);
                OnPropertyChanged("Auflistung_Keybinds");


                // RESET FIELDS
                m_Hotkey  = String.Empty;
                m_Command = String.Empty;

                OnPropertyChanged("Hotkey");
                OnPropertyChanged("Command");
            }
        }
        private void Execute_Command_Button_Edit_Save(object Parameter)
        {
            // Suche das alte Binding in der Liste
            for (int i = 0; i < m_Auflistung_Keybinds.Count; i++)
            {
                if (m_Altes_Binding.Bezeichnung == m_Auflistung_Keybinds[i].Bezeichnung & m_Altes_Binding.KeyValue == m_Auflistung_Keybinds[i].KeyValue && m_Altes_Binding.ModValue == m_Auflistung_Keybinds[i].ModValue && m_Altes_Binding.Auflistung_BindingOptions[0].cmd == m_Auflistung_Keybinds[i].Auflistung_BindingOptions[0].cmd)
                {
                    m_Auflistung_Keybinds[i].AutoEnter     = AutoEnter_Edit;
                    m_Auflistung_Keybinds[i].Bezeichnung   = Hotkey_Edit;
                    m_Auflistung_Keybinds[i].KeyValue      = CurrentKeyValue;
                    m_Auflistung_Keybinds[i].KeyValueForms = (int)(System.Windows.Forms.Keys)KeyInterop.VirtualKeyFromKey((Key)CurrentKeyValue);
                    m_Auflistung_Keybinds[i].ModValue      = CurrentKeyModValue;

                    //Reset Commands
                    m_Auflistung_Keybinds[i].Auflistung_BindingOptions = new List <M_BindingOption>();

                    // Command aufsplitten, wenn Contains ~
                    if (m_Command_Edit.Contains("~"))
                    {
                        if (!AutoEnter_Edit)
                        {
                            // Hinweis Anzeigen, wenn Mehrere Commands da sind, aber AutoEnter False ist
                            if (MessageBoxResult.No == Bindermessage.ShowQuestionYesNo("Sie haben den Hotkey mit mehreren Befehlen belegt und die Auto-Enter Funktion deaktiviert!\nBeachten Sie, dass hierdurch nur der letzte Befehl nicht automatisch abgesendet wird!\n\nMöchten Sie den Hotkey trotzdem hinzufügen?"))
                            {
                                return;
                            }
                        }

                        string[] commands = m_Command_Edit.Split('~');
                        foreach (string command in commands)
                        {
                            M_BindingOption opt = new M_BindingOption();
                            opt.cmd = command.TrimStart();
                            m_Auflistung_Keybinds[i].Auflistung_BindingOptions.Add(opt);
                        }
                    }
                    else
                    {
                        M_BindingOption opt = new M_BindingOption();
                        opt.cmd = m_Command_Edit.TrimStart();
                        m_Auflistung_Keybinds[i].Auflistung_BindingOptions.Add(opt);
                    }
                }
            }

            Hotkey_Edit  = String.Empty;
            Command_Edit = String.Empty;
            isEditMode   = false;

            OnPropertyChanged("Auflistung_Keybinds");

            Auflistung_Keybinds = new ObservableCollection <M_Binding>(m_Auflistung_Keybinds);

            _CONTROLLER.SetzeUC(_CONTROLLER.VCustomKeybinds, _CONTROLLER.VMCustomKeybinds);
        }
        public VM_CustomKeybinds(MainController controller)
        {
            // CONTROLLER zuweisen
            if (controller == null)
            {
                Bindermessage.ShowError("Die Initialisierung ist fehlgeschlagen! Das Programm wird beendet.");
                return;
            }

            _CONTROLLER = controller;

            LoadKeybinds();
        }
Пример #6
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();
        }
        private void LoadUserSettings()
        {
            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);
            string m_FullFolderPath = Path.Combine(m_appdatapath, m_foldername);

            //Check File exists
            System.IO.Directory.CreateDirectory(m_FullFolderPath);
            if (!File.Exists(m_Fullpath))
            {
                // Wenn Datei nicht existiert Standardwerte setzen
                Aktuelle_Einstellungen                  = new M_Settings();
                Aktuelle_Einstellungen.Delay            = 60;
                Aktuelle_Einstellungen.MultiCommanDelay = 1000;
                Aktuelle_Einstellungen.Name             = "Spieler_Name";
                // Speichern
                try
                {
                    XmlSerializer seril = new XmlSerializer(typeof(M_Settings));
                    using (StreamWriter writ = new StreamWriter(m_Fullpath))
                    {
                        seril.Serialize(writ, Aktuelle_Einstellungen);
                    }
                }
                catch (Exception ex)
                {
                    Bindermessage.ShowError("Fehler beim Anlegen der Default Einstellungen!\n\nError:\n" + ex);
                }

                return;
            }

            Aktuelle_Einstellungen = new M_Settings();

            try
            {
                XmlSerializer seri = new XmlSerializer(typeof(M_Settings));
                using (StreamReader read = new StreamReader(m_Fullpath))
                {
                    Aktuelle_Einstellungen = seri.Deserialize(read) as M_Settings;
                }
            }
            catch (Exception ex)
            {
                Bindermessage.ShowError("Fehler beim Laden der Einstellungen!\n\nError:\n" + ex);
            }
        }
Пример #8
0
        public VM_Einstellungen(MainController controller)
        {
            // CONTROLLER zuweisen
            if (controller == null)
            {
                Bindermessage.ShowError("Die Initialisierung ist fehlgeschlagen! Das Programm wird beendet.");
                return;
            }

            _CONTROLLER = controller;

            // Delay aus Settings setzen
            Delay            = _CONTROLLER.Aktuelle_Einstellungen.Delay.ToString();
            MultiCommanDelay = _CONTROLLER.Aktuelle_Einstellungen.MultiCommanDelay.ToString();
            Name             = _CONTROLLER.Aktuelle_Einstellungen.Name;
        }
        public VM_MainWindow(MainController Controller)
        {
            // CONTROLLER zuweisen
            if (Controller == null)
            {
                Bindermessage.ShowError("Die Initialisierung ist fehlgeschlagen! Das Programm wird beendet.");
                return;
            }

            _CONTROLLER = Controller;

            // Versionsnummer entnehmen
            //GetCurrentVersion();

            // Add User to Whitelist!
            AddWhitelist();
        }
        private void AddWhitelist(bool WithMessage = false)
        {
            try
            {
                //http://game.gvmp.de/whitelist.php
                var data  = new WebClient().DownloadString("http://server.gvmp.de/gv_whitelist.php?server=1");
                var data2 = new WebClient().DownloadString("http://server.gvmp.de/gv_whitelist.php?server=2");
                var data3 = new WebClient().DownloadString("http://server.gvmp.de/gv_whitelist.php?server=3");

                if (WithMessage)
                {
                    Bindermessage.ShowInfo("Du wurdest der Whitelist hinzugefügt!");
                }
            }
            catch (Exception)
            {
                Bindermessage.ShowError("Die Verbindung zu GVMP ist fehlgeschlagen! \nDu konntest leider nicht automatisch der Whitelist hinzugefügt werden!");
            }
        }
        public void RestartKeybinder()
        {
            Bindermessage.ShowInfo("Der Keybinder wird neu gestartet, um die Änderungen zu übernehmen!");

            ProcessStartInfo info = new ProcessStartInfo(Application.ResourceAssembly.Location);

            info.UseShellExecute = true;
            if (System.Environment.OSVersion.Version.Major >= 6)
            {
                info.Verb = "runas";
            }

            try
            {
                Process.Start(info);
                Application.Current.Shutdown();
            }
            catch (Exception ex)
            {
                Bindermessage.ShowError("Beim Versuch den Keybinder als Administrator zu starten, ist ein Fehler aufgetreten! \n\n" + ex.Message);
            }
        }
        private void LoadKeybinds()
        {
            string m_appdatapath      = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string m_foldername       = "Bonnyfication";
            string m_FileNameExtended = "Keybinds_Store_Extended.xml";
            string m_FullpathExtended = Path.Combine(m_appdatapath, m_foldername, m_FileNameExtended);
            string m_FullFolderPath   = Path.Combine(m_appdatapath, m_foldername);


            // C:\Users\Bonnyfication\AppData\Roaming\Bonnyfication_Keybinds.xml
            //Check Folder exists or Create it
            System.IO.Directory.CreateDirectory(m_FullFolderPath);

            // Auslesen
            Auflistung_Keybinds = new ObservableCollection <M_Binding>();

            if (!File.Exists(m_FullpathExtended))
            {
                return;
            }

            try
            {
                XmlSerializer seri = new XmlSerializer(typeof(ObservableCollection <M_Binding>));
                using (StreamReader read = new StreamReader(m_FullpathExtended))
                {
                    m_Auflistung_Keybinds = seri.Deserialize(read) as ObservableCollection <M_Binding>;
                }
            }
            catch (Exception ex)
            {
                Bindermessage.ShowError("Fehler beim Laden der Keybinds!\n\nError:\n" + ex);
            }

            OnPropertyChanged("Auflistung_Keybinds");
        }
Пример #13
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);
            }
        }
    }
        private void LoadKeybinds()
        {
            string m_appdatapath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string m_foldername  = "Bonnyfication";

            string m_FileName_Old     = "Keybinds_Store.xml";
            string m_FileNameExtended = "Keybinds_Store_Extended.xml";

            string m_FullpathOld      = Path.Combine(m_appdatapath, m_foldername, m_FileName_Old);
            string m_FullpathExtended = Path.Combine(m_appdatapath, m_foldername, m_FileNameExtended);

            string m_FullFolderPath = Path.Combine(m_appdatapath, m_foldername);


            // C:\Users\Bonnyfication\AppData\Roaming\Bonnyfication_Keybinds.xml
            //Check Folder exists or Create it
            System.IO.Directory.CreateDirectory(m_FullFolderPath);

            // Wenn die alte Keybinder XML besteht auswerten, Convertieren und Löschen
            if (File.Exists(m_FullpathOld))
            {
                //CONVERT AND DELETE
                ObservableCollection <M_Keybind> m_tmp = new ObservableCollection <M_Keybind>();

                try
                {
                    XmlSerializer seri = new XmlSerializer(typeof(ObservableCollection <M_Keybind>));
                    using (StreamReader read = new StreamReader(m_FullpathOld))
                    {
                        m_tmp = seri.Deserialize(read) as ObservableCollection <M_Keybind>;
                    }
                }
                catch (Exception ex)
                {
                    Bindermessage.ShowError("Fehler beim Laden der Keybinds!\n\nError:\n" + ex);
                }


                if (m_tmp.Count > 0)
                {
                    m_Auflistung_Keybinds = new ObservableCollection <M_Binding>();

                    foreach (M_Keybind item in m_tmp)
                    {
                        M_Binding bin = new M_Binding();
                        bin.Bezeichnung   = item.Bezeichnung;
                        bin.KeyValue      = item.KeyValue;
                        bin.KeyValueForms = item.KeyValueForms;
                        bin.ModValue      = item.ModValue;
                        bin.AutoEnter     = true;

                        M_BindingOption opt = new M_BindingOption();
                        opt.cmd = item.cmd;

                        bin.Auflistung_BindingOptions = new List <M_BindingOption>();
                        bin.Auflistung_BindingOptions.Add(opt);
                        m_Auflistung_Keybinds.Add(bin);
                    }

                    // Speichere die Bindings im neuen Format

                    try
                    {
                        XmlSerializer seri = new XmlSerializer(typeof(ObservableCollection <M_Binding>));
                        using (StreamWriter writ = new StreamWriter(m_FullpathExtended))
                        {
                            seri.Serialize(writ, m_Auflistung_Keybinds);
                        }
                    }
                    catch (Exception ex)
                    {
                        Bindermessage.ShowError("Fehler beim Speichern der konvertierten Keybinds!\n\nError:\n" + ex);
                        Application.Current.Shutdown();
                    }

                    OnPropertyChanged("Auflistung_Keybinds");

                    try
                    {
                        File.Delete(m_FullpathOld);
                    }
                    catch (Exception ex)
                    {
                        Bindermessage.ShowError("Die Datei Keybinder_Store.xml konnte nicht gelöscht werden. Dies ist allerdings erforderlich, damit beim start des Keybinders neue Keybinds nicht überschrieben werden.\nSie können die Datei manuell löschen!\n\nPfad:\n" + m_FullpathOld + "\n\nError:" + ex.Message);
                        Application.Current.Shutdown();
                    }
                }
            }
            else // Existiert die Aktuelle Keybinder_Store_Extended.xml ?
            {
                if (!File.Exists(m_FullpathExtended))
                {
                    return;
                }

                // Auslesen
                Auflistung_Keybinds = new ObservableCollection <M_Binding>();

                try
                {
                    XmlSerializer seri = new XmlSerializer(typeof(ObservableCollection <M_Binding>));
                    using (StreamReader read = new StreamReader(m_FullpathExtended))
                    {
                        m_Auflistung_Keybinds = seri.Deserialize(read) as ObservableCollection <M_Binding>;
                    }
                }
                catch (Exception ex)
                {
                    Bindermessage.ShowError("Fehler beim Laden der Keybinds!\n\nError:\n" + ex);
                }

                OnPropertyChanged("Auflistung_Keybinds");
            }
        }