Skip to content

Commit 5298cfd

Browse files
committed
Refactor PetroglyphXmlFileParserBase: remove redundant IServiceProvider field, optimize path handling with OS-specific logic.
1 parent 54c833f commit 5298cfd

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/PetroglyphTools/PG.StarWarsGame.Files.XML/Parsers/Base/PetroglyphXmlFileParserBase.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.IO;
33
using System.IO.Abstractions;
4+
using System.Runtime.CompilerServices;
5+
using System.Runtime.InteropServices;
46
using System.Xml;
57
using System.Xml.Linq;
68
using Microsoft.Extensions.DependencyInjection;
@@ -15,9 +17,6 @@ namespace PG.StarWarsGame.Files.XML.Parsers;
1517
public abstract class PetroglyphXmlFileParserBase(IServiceProvider serviceProvider, IXmlParserErrorReporter? errorReporter)
1618
: PetroglyphXmlParserBase(errorReporter)
1719
{
18-
protected readonly IServiceProvider ServiceProvider =
19-
serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
20-
2120
protected readonly IFileSystem FileSystem = serviceProvider.GetRequiredService<IFileSystem>();
2221

2322
protected virtual bool LoadLineInfo => true;
@@ -62,18 +61,24 @@ protected XElement GetRootElement(Stream xmlStream, out string fileName)
6261

6362
return root;
6463
}
65-
64+
6665
private string GetStrippedFileName(string filePath)
6766
{
6867
if (!FileSystem.Path.IsPathFullyQualified(filePath))
6968
return filePath;
70-
71-
var pathPartIndex = filePath.LastIndexOf("DATA\\XML\\", StringComparison.OrdinalIgnoreCase);
69+
70+
var pathPartIndex = filePath.LastIndexOf(GetXmlDataFolder(), StringComparison.OrdinalIgnoreCase);
7271

7372
if (pathPartIndex == -1)
7473
return filePath;
7574

76-
return filePath.Substring(pathPartIndex);
75+
return filePath[pathPartIndex..];
76+
77+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
78+
static string GetXmlDataFolder()
79+
{
80+
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? @"DATA\XML\" : "DATA/XML/";
81+
}
7782
}
7883

7984

0 commit comments

Comments
 (0)