Esempio n. 1
0
        public void LoadSettings()
        {
            ResetForms();


            //Wenn File existiert Settings einlesen:
            if (File.Exists(_df.GetFileNamen()))
            {
                //Deserializer erstellen
                var mySerializer = new XmlSerializer(typeof(DefaultSettings));
                //Filestream herstellen
                var myFileStream = new FileStream(_df.GetFileNamen(), FileMode.Open);
                //Objekt erzeugen
                _df = (DefaultSettings)mySerializer.Deserialize(myFileStream);
                //Filestream schliessen
                myFileStream.Close();

                var currentDirectory = _df.GetCurrentDirectory();
                if (string.IsNullOrEmpty(currentDirectory))
                {
                    tab1Labelpfad.Text = @"Einstellungen => Verzeichnis wählen";
                    tab2Labelpfad.Text = @"Verzeichnis wählen";
                    SetToolStatusLabel(@"Verzeichnis wählen!");
                    return;
                }

                //Label setzten
                tab1Labelpfad.Text = currentDirectory;
                tab2Labelpfad.Text = currentDirectory;

                //Setting OpenNotepad anpassen:
                folderBrowserDialog1.SelectedPath = currentDirectory;
                checkBoxOpenNotepad.Checked       = _df.OpenNotepad;
                checkBoxOpenExplorer.Checked      = _df.OpenExplorer;

                //Save Button aktivieren
                buttonSave.Enabled = true;

                SetToolStatusLabel("Einstellung gespeichert!");
            }
            else
            {
                //Config File existiert nicht
                tab1Labelpfad.Text = @"Einstellungen => Verzeichnis wählen";
                tab2Labelpfad.Text = @"Verzeichnis wählen";
                SetToolStatusLabel(@"Verzeichnis wählen!");
            }
        }
Esempio n. 2
0
        public bool GeocacheAusgabe(bool paramOpenNotepad, bool paramOpenExplorer)
        {
            //get current output directory
            var path = _currentSettings.GetCurrentDirectory();

            //if create directory true
            if (_directory)
            {
                //Path ergänzen um Geocachename
                path += "\\" + _fileDirectoryName;

                try
                {
                    // Determine whether the directory exists.
                    if (Directory.Exists(path))
                    {
                        //Stopp directory already exist
                        MessageBox.Show(@"Fehler Verzeichnis existiert bereits!!!", @"Fehler!!", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        return(false);
                    }

                    // Try to create the directory.
                    Directory.CreateDirectory(path);
                }
                catch (Exception e)
                {
                    MessageBox.Show(@"Fehler beim Verzeichnis erstellen!!! " + e, @"Fehler!!", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);

                    return(false);
                }
            }

            //add path with Filename
            path += "\\" + _fileDirectoryName + ".txt";

            //Output
            if (!File.Exists(path))
            {
                // Create a file to write to.
                var text = "Erstellt am " + DateTime.Now.ToString("dd.MM.yyyy") + " - " + DateTime.Now.ToString("HH:mm") +
                           " Uhr" + Environment.NewLine;
                text += _name + " - " + _gcCode + Environment.NewLine;
                text += "_______________________________________________________________" + Environment.NewLine;
                text += "Bemerkung: " + _bemerkung + Environment.NewLine;
                text += "_______________________________________________________________" + Environment.NewLine;
                text += "Dieser Cache wurde am " + _gefunden.ToString("dd.MM.yyyy") + " gefunden" + Environment.NewLine;
                try
                {
                    File.WriteAllText(path, text);
                }
                catch (Exception e)
                {
                    //File writter Fail
                    MessageBox.Show(@"Fehler beim File Schreiben!!! " + e, @"Fehler!!", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);

                    return(false);
                }
            }
            else
            {
                //File already Exist
                MessageBox.Show(@"Fehler File existiert bereits!!! ", @"Fehler!!", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return(false);
            }

            if (paramOpenNotepad)
            {
                //open Notepad++
                var process = new Process
                {
                    StartInfo =
                    {
                        FileName         = "notepad++.exe",
                        WorkingDirectory = @"c:\temp",
                        Arguments        = path
                    }
                };
                process.Start();
            }


            if (paramOpenExplorer)
            {
                //open FileExplorer
                var getDirectory = Path.GetDirectoryName(path);
                if (!string.IsNullOrEmpty(getDirectory))
                {
                    Process.Start(getDirectory);
                }
            }


            //return true wenn erfolgreich gespeichert:
            return(true);
        }