/// <summary> /// Erzeugt Pfad relativ zum Loksim-Verzeichnis /// </summary> /// <param name="relativePath">Pfad relativ zum Loksim-Verzeichnis</param> /// <returns>Erzeugter Pfad</returns> public static L3dFilePath CreateRelativeToL3dDir(string relativePath) { L3dFilePath p = new L3dFilePath(); p.SetPathRelativeToL3dDir(relativePath); return(p); }
public void OpenFile(L3dFilePath p) { if (!L3dFilePath.IsNullOrEmpty(p)) { var w = _openAppWindows.FirstOrDefault(m => m._currentViewModel != null && m._currentViewModel.CurrentFile != null && L3dFilePath.Equals(m._currentViewModel.CurrentFile.OwnPath, p)); if (w != null) { //w.BringIntoView(); if (w.WindowState == System.Windows.WindowState.Minimized) { w.WindowState = System.Windows.WindowState.Normal; } w.Activate(); } else { if (_currentViewModel == null) { Mouse.OverrideCursor = Cursors.Wait; LoksimFile file = LoadFile(p); SetCtrlAndViewModel(file); Mouse.OverrideCursor = null; } else { new MainWindow(p.AbsolutePath).Show(); } } SetRecentFilesMenu(); } }
/// <summary> /// Erzeugt Pfad relativ zu anderer DAtei /// <br>Falls relativer Pfad mit '/' beginnt, wird der Pfad als relativ zum Loksim-Verzeichnis interpretiert</br> /// <br>Falls <paramref name="parentFile"/> null ist, wird Pfad relativ zum Loksim-Verzeichnis erzeugt</br> /// </summary> /// <param name="relativePath">Relativer Pfad</param> /// <param name="parentFile">"Eltern-Datei" (kann null sein)</param> /// <returns>Erzeugter Pfad</returns> public static L3dFilePath CreateRelativeToFile(string relativePath, L3dFilePath parentFile) { L3dFilePath ret = new L3dFilePath(); ret.SetPathRelativeToFile(relativePath, parentFile); return(ret); }
/// <summary> /// Liefert Pfad relativ zu angegebener Datei /// </summary> /// <param name="parentFile">"Eltern-Datei"</param> /// <returns>Relativer Pfad zur Datei; Falls diese Datei nicht im gleichen Verzeichnis wie parentFile liegt, wird Pfad relativ zum Loksim-Verzeichnis geliefert</returns> public string GetPathRelativeToFile(L3dFilePath parentFile) { if (!L3dFilePath.IsNullOrEmpty(parentFile)) { string parentDir = parentFile.Directory; if (AbsolutePath.StartsWith(parentDir, StringComparison.OrdinalIgnoreCase)) { return(AbsolutePath.Substring(parentDir.Length + 1)); } } return(PathRelativeToL3dDir); }
private void CommandSaveAs_Executed(object sender, ExecutedRoutedEventArgs e) { if (_currentViewModel != null) { _currentViewModel.FileSaveAsCmd.Execute(null); if (!L3dFilePath.IsNullOrEmpty(_currentViewModel.CurrentFile.OwnPath)) { Settings.RegistrySettings.Default.AddRecentFile(_currentViewModel.CurrentFile.OwnPath); SetRecentFilesMenu(); this.Title = Loksim3D.WetterEdit.Resources.Strings.AppName + " [" + _currentViewModel.CurrentFile.OwnPath.Filename + "]"; } } }
private void CommandOpen_Executed(object sender, ExecutedRoutedEventArgs e) { string str = DialogHelpers.OpenLoksimFile(string.Empty, FileExtensions.AllLoksimFiles, this, MAIN_DLG_OPEN); if (!string.IsNullOrEmpty(str)) { L3dFilePath p = new L3dFilePath(str); if (!L3dFilePath.IsNullOrEmpty(p)) { OpenFile(p); } } }
private LoksimFile LoadFile(L3dFilePath path) { LoksimFile file = null; try { switch (System.IO.Path.GetExtension(path.AbsolutePath).ToLower()) { case ".l3dwth": { WeatherFile f = new WeatherFile(); f.LoadFromFile(path); file = f; } break; case ".l3dsky": { SkyFile f = new SkyFile(); f.LoadFromFile(path); file = f; } break; case ".l3dfst": { DrivingCabFile f = new DrivingCabFile(); f.LoadFromFile(path); file = f; } break; default: Debug.Assert(false, "Unknown File Type"); break; } this.Title = Loksim3D.WetterEdit.Resources.Strings.AppName + " [" + path.Filename + "]"; Settings.RegistrySettings.Default.AddRecentFile(path); } catch (Exception ex) { Mouse.OverrideCursor = null; MessageBox.Show(String.Format(Loksim3D.WetterEdit.Resources.Strings.ErrorLoadingFile_0_Msg_1_, path.Filename, ex.Message), Loksim3D.WetterEdit.Resources.Strings.AppName, MessageBoxButton.OK, MessageBoxImage.Error); } return(file); }
private void SetPathRelativeToFile(string relativePath, L3dFilePath parentFile) { if (string.IsNullOrEmpty(relativePath)) { _absolutePath = string.Empty; } else if (L3dFilePath.IsNullOrEmpty(parentFile) || relativePath[0] == '\\') { SetPathRelativeToL3dDir(relativePath); } else if (Path.IsPathRooted(relativePath)) { _absolutePath = relativePath; } else { _absolutePath = Path.Combine(Path.GetDirectoryName(parentFile.AbsolutePath), relativePath); } ParentFile = parentFile; }
/// <summary> /// Prüft ob <paramref name="l3dPath"/> null ist oder der enthaltene Pfad string.empty ist /// </summary> /// <param name="l3dPath">Pfad</param> /// <returns>true falls null oder leer</returns> public static bool IsNullOrEmpty(L3dFilePath l3dPath) { return(l3dPath == null || String.IsNullOrEmpty(l3dPath.AbsolutePath)); }
public override bool Equals(object obj) { L3dFilePath o = obj as L3dFilePath; return(o != null && String.Equals(o.AbsolutePath, this.AbsolutePath)); }