/// <summary> /// Speichert die Datei ab /// </summary> /// <param name="saveToFile">Dateipfad</param> public void SaveToFile(L3dFilePath outputPath) { if (OwnPath != outputPath && !L3dFilePath.IsNullOrEmpty(FilePicture)) { try { string newPath = Path.Combine(outputPath.Directory, outputPath.Filename + ".jpg"); File.Copy(FilePicture.AbsolutePath, newPath); FilePicture = new L3dFilePath(newPath); } catch (Exception) { FilePicture = new L3dFilePath(); } } XDocument xDoc = SaveToXmlDocument(GetRootPropsElement(outputPath), outputPath); string output = GetOutputString(xDoc); string tmpFile = TempFileUtility.GetTempFileName("tmp", 0, outputPath.Directory); if (File.Exists(outputPath.AbsolutePath)) { xDoc.Save(tmpFile); File.Replace(tmpFile, outputPath.AbsolutePath, null); } else { File.Delete(tmpFile); xDoc.Save(outputPath.AbsolutePath); } _lastSavedDoc = output; OwnPath = outputPath; }
private bool SaveOrSaveAs(bool saveAs) { L3dFilePath p; if (saveAs || L3dFilePath.IsNullOrEmpty(CurrentFile.OwnPath)) { p = DialogHelpers.SaveLoksimFile(CurrentFile.OwnPath, FileExtensionForSaveAs, SAVEAS_DLG_GUID); } else { p = CurrentFile.OwnPath; } try { if (p != null) { CurrentFile.SaveToFile(p); return(true); } } catch (Exception ex) { MessageBox.Show(String.Format(CultureInfo.CurrentCulture, Resources.Strings.FileSaveError, CurrentFile.OwnPath, ex.Message), Resources.Strings.AppName, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); } return(false); }
private void ValidateCurrentPath() { BindingExpression bindingExpression = BindingOperations.GetBindingExpression(tbPath, AutoCompleteBox.IsEnabledProperty); if (L3dFilePath.IsNullOrEmpty(_curPath)) { //ctrl.TbText = string.Empty; tbPath.Text = string.Empty; Validation.ClearInvalid(bindingExpression); } else { //ctrl.TbText = newPath.PathRelativeToParentFile; tbPath.Text = _curPath.PathRelativeToParentFile; if (_curPath.Exists) { Validation.ClearInvalid(bindingExpression); } else { ValidationError validationError = new ValidationError(new ExceptionValidationRule(), bindingExpression); validationError.ErrorContent = String.Format(Loksim3D.WetterEdit.Resources.Strings.File_0_NotFound, _curPath.PathRelativeToL3dDir); Validation.MarkInvalid(bindingExpression, validationError); } } }
/// <summary> /// Lädt Daten in diese Instanz von der angegebenen Datei /// </summary> /// <param name="path">Dateipfad</param> public void LoadFromFile(L3dFilePath path) { if (!L3dFilePath.IsNullOrEmpty(path)) { XDocument doc = XDocument.Load(path.AbsolutePath); XElement props = doc.Elements().First().Element(FileDescriptions.FILE_GENERAL_EL_PROPS); if (props != null) { FileAuthor = props.Attribute(FileDescriptions.FILE_GENERAL_AT_AUTHOR).Read <string>(); FileInfo = props.Attribute(FileDescriptions.FILE_GENERAL_AT_INFO).Read <string>(); FilePicture = L3dFilePath.CreateRelativeToFile(props.Attribute(FileDescriptions.FILE_GENERAL_AT_PICTURE).Read <string>(), path); FileDoku = L3dFilePath.CreateRelativeToFile(props.Attribute(FileDescriptions.FILE_GENERAL_AT_DOKU).Read <string>(), path); } OwnPath = path; LoadFromDoc(doc); _lastSavedDoc = GetOutputString(SaveToXmlDocument(GetRootPropsElement(OwnPath), OwnPath)); } }
void tbPath_Populating(object sender, PopulatingEventArgs e) { L3dFilePath parentFile = _curPath.ParentFile; string startDir; if (L3dFilePath.IsNullOrEmpty(parentFile) || e.Parameter.StartsWith("\\")) { startDir = L3dFilePath.LoksimDirectory.AbsolutePath; } else { startDir = parentFile.Directory; } startDir = startDir + System.IO.Path.DirectorySeparatorChar + e.Parameter; if (!string.IsNullOrEmpty(startDir)) { string dir = System.IO.Path.GetDirectoryName(startDir); if (Directory.Exists(dir)) { string file = System.IO.Path.GetFileName(startDir); var res = Directory.EnumerateDirectories(dir, file + "*").Select(p => L3dFilePath.CreateRelativeToFile(p, parentFile).PathRelativeToParentFile); if (_possibleExtensions.Count() == 0) { res = res.Union(Directory.EnumerateFiles(dir, file + "*").Select(p => L3dFilePath.CreateRelativeToFile(p, parentFile).PathRelativeToParentFile)); } else { foreach (var ext in _possibleExtensions) { res = res.Union(Directory.EnumerateFiles(dir, file + "*." + ext).Select(p => L3dFilePath.CreateRelativeToFile(p, parentFile).PathRelativeToParentFile)); } } tbPath.ItemsSource = res.Take(15); } else { tbPath.ItemsSource = Enumerable.Empty <string>(); } } }
protected BaseL3dFileViewModel(LoksimFile openFile, Window parentWindow) { CurrentFile = openFile; ParentWindow = parentWindow; _fileSaveCmd = new RelayCommand(obj => { SaveOrSaveAs(false); }, obj => { return(CurrentFile != null && !L3dFilePath.IsNullOrEmpty(CurrentFile.OwnPath)); } ); _fileSaveAsCmd = new RelayCommand(obj => { SaveOrSaveAs(true); }, obj => { return(CurrentFile != null); } ); FilePropertiesCmd = new RelayCommand(obj => { Window dlg = new FilePropertiesWindow(CurrentFile); dlg.Owner = ParentWindow; dlg.ShowDialog(); }, obj => { return(CurrentFile != null); } ); UndoCmd = new RelayCommand(obj => { UndoAwareFile f = CurrentFile as UndoAwareFile; if (f != null) { f.Undo(); } }, obj => { UndoAwareFile f = CurrentFile as UndoAwareFile; return(f != null && f.UndoPossible); } ); RedoCmd = new RelayCommand(obj => { UndoAwareFile f = CurrentFile as UndoAwareFile; if (f != null) { f.Redo(); } }, obj => { UndoAwareFile f = CurrentFile as UndoAwareFile; return(f != null && f.RedoPossible); } ); }
public FilePropertiesViewModel(LoksimFile file, Window parentWindow) { _fileAuthor = file.FileAuthor; _fileInfo = file.FileInfo; _fileDoku = file.FileDoku; _parentWindow = parentWindow; if (!L3dFilePath.IsNullOrEmpty(file.FilePicture)) { SetFilePicSource(file.FilePicture); } OtherPictureCmd = new RelayCommand(obj => { string s = DialogHelpers.OpenLoksimFile(file.FilePicture.AbsolutePath, FileExtensions.ImageFiles, _parentWindow); if (!string.IsNullOrEmpty(s)) { L3dFilePath p = new L3dFilePath(s); RemovePictureCmd.Execute(null); Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { SetFilePicSource(p); }), System.Windows.Threading.DispatcherPriority.Background); } }, obj => { return(!L3dFilePath.IsNullOrEmpty(file.OwnPath)); }); PictureFromClipboardCmd = new RelayCommand(obj => { if (Clipboard.ContainsImage()) { FilePicture = Clipboard.GetImage(); } }, obj => { return(Clipboard.ContainsImage() && !L3dFilePath.IsNullOrEmpty(file.OwnPath)); }); RemovePictureCmd = new RelayCommand(obj => { FilePicture = null; }, obj => { return(FilePicture != null); }); OkCmd = new RelayCommand(obj => { file.FileAuthor = FileAuthor; file.FileInfo = FileInfo; file.FileDoku = FileDoku; try { if (_picChanged) { if (_filePicture != null) { Image bmp = null; JpegBitmapEncoder enc = new JpegBitmapEncoder(); enc.Frames.Add(BitmapFrame.Create(_filePicture)); using (System.IO.MemoryStream memStream = new System.IO.MemoryStream()) { enc.Save(memStream); bmp = new Bitmap(memStream); } using (Image img = ImageHelper.ScaleBitmap(bmp, 512, 512)) { file.FilePicture = new L3dFilePath(file.OwnPath.AbsolutePath + ".jpg"); img.Save(file.FilePicture.AbsolutePath, System.Drawing.Imaging.ImageFormat.Jpeg); } bmp.Dispose(); } else { file.FilePicture = null; } } FilePicture = null; } catch (Exception ex) { Debug.WriteLine(ex); } if (RequestClose != null) { RequestClose(true); } }, obj => { return(true); }); CancelCmd = new RelayCommand(obj => { if (RequestClose != null) { RequestClose(false); } }, obj => { return(true); }); _picChanged = false; }