diff --git a/VECTO/GUI/VehicleForm.vb b/VECTO/GUI/VehicleForm.vb index b4c40c509731695b6a9e71913b082dc166587c3b..c9c639088196dbc8452968256118e7928bb90fb1 100644 --- a/VECTO/GUI/VehicleForm.vb +++ b/VECTO/GUI/VehicleForm.vb @@ -500,7 +500,7 @@ Public Class VehicleForm If (vehicle.VehicleType <> VectoSimulationJobType.ConventionalVehicle AndAlso vehicle.VehicleType <> VectoSimulationJobType.EngineOnlySimulation) Then lvREESSPacks.Items.Clear() For Each entry As IElectricStorageEngineeringInputData In vehicle.Components.ElectricStorage.ElectricStorageElements.OrderBy(Function(x) x.StringId) - lvREESSPacks.Items.Add(CreateREESSPackListViewItem(GetRelativePath(entry.REESSPack.DataSource.SourceFile, basePath), entry.Count, entry.StringId)) + lvREESSPacks.Items.Add(CreateREESSPackListViewItem(entry.REESSPack.DataSource.SourceFile, entry.Count, entry.StringId)) Next if (cfg.DeclMode) Then tbInitialSoC.Text = string.Empty diff --git a/VECTO/MainModule.vb b/VECTO/MainModule.vb index d95fd515ff23d7e369782c910e8e5d8739377223..08f7e5345aece10723bb9d8570b0a2f2fd8555c9 100644 --- a/VECTO/MainModule.vb +++ b/VECTO/MainModule.vb @@ -137,15 +137,16 @@ Module MainModule End Function Public Function GetRelativePath(filePath As String, basePath As String) As String - If (String.IsNullOrEmpty(filePath)) then - Return "" - End If - If (string.isnullOrempty(basePath)) Then - Return filePath - End If - If (Path.GetDirectoryName(Path.GetFullPath(filePath)).StartsWith(basePath, StringComparison.OrdinalIgnoreCase)) Then - Return Path.GetFullPath(filePath).Substring(basePath.Length + If(basePath.EndsWith("\"), 0, 1)) - End If - Return filePath + Return JSONFileWriter.GetRelativePath(filePath, basePath) + 'If (String.IsNullOrEmpty(filePath)) then + ' Return "" + 'End If + ' If (string.isnullOrempty(basePath)) Then + ' Return filePath + ' End If + 'If (Path.GetDirectoryName(Path.GetFullPath(filePath)).StartsWith(basePath, StringComparison.OrdinalIgnoreCase)) Then + ' Return Path.GetFullPath(filePath).Substring(basePath.Length + If(basePath.EndsWith("\"), 0, 1)) + 'End If + 'Return filePath End Function End Module diff --git a/VectoCore/VectoCore/OutputData/FileIO/JSONFileWriter.cs b/VectoCore/VectoCore/OutputData/FileIO/JSONFileWriter.cs index d703e57488896f1a34108d6519325096f8929d99..a6ff4d3c0e40f7b3e0a4087841e96111eb4f159c 100644 --- a/VectoCore/VectoCore/OutputData/FileIO/JSONFileWriter.cs +++ b/VectoCore/VectoCore/OutputData/FileIO/JSONFileWriter.cs @@ -13,6 +13,7 @@ using TUGraz.VectoCore; using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Models.Declaration.Auxiliaries; +using TUGraz.VectoCore.Utils; public class JSONFileWriter : IOutputFileWriter { @@ -66,6 +67,15 @@ public class JSONFileWriter : IOutputFileWriter return filePath; } + var filePathNormalized = new Uri(Path.GetFullPath(filePath)); + var basePathNormalized = new Uri(Path.GetFullPath(basePath) + (Path.GetFullPath(basePath).EndsWith(Path.DirectorySeparatorChar.ToString()) ? "" : Path.DirectorySeparatorChar.ToString())); + var commonPrefix = PathHelper.GetLongestCommonPrefix(basePathNormalized.AbsolutePath, filePathNormalized.AbsolutePath); + if (commonPrefix.Length > 3) { + // at least on the same drive... + var relative = basePathNormalized.MakeRelativeUri(filePathNormalized); + return relative.ToString(); + } + if (Path.GetDirectoryName(Path.GetFullPath(filePath)).StartsWith(basePath, StringComparison.OrdinalIgnoreCase)) { return Path.GetFullPath(filePath).Substring(basePath.Length + (basePath.EndsWith(@"\") ? 0 : 1)); } @@ -73,6 +83,7 @@ public class JSONFileWriter : IOutputFileWriter return filePath; } + public void SaveElectricMotor(IElectricMotorEngineeringInputData electricMachine, string filename, bool declMode) { var header = GetHeader(ElectricMotorFormatVersion); diff --git a/VectoCore/VectoCore/Utils/PathHelper.cs b/VectoCore/VectoCore/Utils/PathHelper.cs index 2459f872dbc37fd28167a8fe1f6155bd3756367d..e5b64cc6eff9076d17828db9845afdc28cd205b7 100644 --- a/VectoCore/VectoCore/Utils/PathHelper.cs +++ b/VectoCore/VectoCore/Utils/PathHelper.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using TUGraz.VectoCommon.Utils; namespace TUGraz.VectoCore.Utils { @@ -34,6 +35,20 @@ namespace TUGraz.VectoCore.Utils return Path.Combine(result, pathFileName); } + public static string GetLongestCommonPrefix(params string[] s) + { + if (s.Length == 0) + return ""; + var prefix = s[0]; + for (var i = 1; i < s.Length; i++) + while (s[i].IndexOf(prefix) != 0) { + prefix = prefix.Substring(0, prefix.Length - 1); + if (prefix.IsNullOrEmpty()) + return ""; + } + return prefix; + } + public static string GetAbsolutePath(string relativeTo, string relativePath) { return Path.GetFullPath(Path.Combine(Path.GetDirectoryName(relativeTo), relativePath));