public void LoadFromFile(FileInfo OpenFile) { try { if (!Directory.Exists(OpenFile.Directory.FullName)) { throw new FileNotFoundException(); //Wenn Ordner nicht vorhanden ist. } //Temp Verzeichnis erstellen string tempPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\tempLoad"; if (Directory.Exists(tempPath)) { Directory.Delete(tempPath, true); //Sichergehen, dass das Verzeichnis nicht exisitiert. } Directory.CreateDirectory(tempPath); ZipFile.ExtractToDirectory(OpenFile.FullName, tempPath); Languages = Serializer.LoadXML <List <Language> >(tempPath + "\\languages.slf"); Snippets = Serializer.LoadXML <List <Snippet> >(tempPath + "\\snippets.slf"); } catch (Exception ex) { win_errorDialog errorDialog = new win_errorDialog("Fehler beim Öffnen der Datei. Bitte überprüfen sie, ob die Datei beschädigt ist.", ex); errorDialog.ShowDialog(); } }
// Properties speichern public void SaveToFile(FileInfo SaveFile) { try { if (!Directory.Exists(SaveFile.Directory.FullName)) { throw new FileNotFoundException(); //Wenn Ordner nicht vorhanden ist. } //Temp Verzeichnis erstellen string tempPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\tempSave"; if (Directory.Exists(tempPath)) { Directory.Delete(tempPath, true); //Sichergehen, dass das Verzeichnis nicht exisitiert. } Directory.CreateDirectory(tempPath); //Daten speichern Serializer.SaveXML(tempPath + "\\languages.slf", Languages); Serializer.SaveXML(tempPath + "\\snippets.slf", Snippets); //Daten zu einer Datei packen und in das Verzeichnís kopieren ZipFile.CreateFromDirectory(tempPath, SaveFile.FullName); } catch (Exception ex) { win_errorDialog errorDialog = new win_errorDialog("Fehler beim speichern der Datei. Nehmen sie Kontakt mit dem Entwickler auf.", ex); errorDialog.ShowDialog(); } }