read item file from ArchiveManager, not using File API ; don't throw exception if item file was not found, but log error

This commit is contained in:
in0finite 2021-01-31 01:34:23 +01:00
parent 20461c854b
commit fdc42b1946
2 changed files with 15 additions and 3 deletions

View file

@ -60,7 +60,7 @@ namespace SanAndreasUnity.Importing.Items
public static void ReadIde(string path)
{
var file = new ItemFile<Definition>(ArchiveManager.GetCaseSensitiveFilePath(Path.GetFileName(path)));
var file = new ItemFile<Definition>(path);
foreach (var obj in file.GetItems<Definition>().OfType<IObjectDefinition>())
{
_definitions.Add(obj.Id, obj);

View file

@ -9,6 +9,7 @@ using System.Linq;
using System.Linq.Expressions;
#endif
using System.Reflection;
using UnityEngine;
namespace SanAndreasUnity.Importing.Items
{
@ -152,11 +153,22 @@ namespace SanAndreasUnity.Importing.Items
public ItemFile(string path)
{
using (var reader = File.OpenText(path))
string fileName = Path.GetFileName(path);
if (!Archive.ArchiveManager.FileExists(fileName))
{
Debug.LogError($"Item file not found: {path}");
return;
}
using (var stream = Archive.ArchiveManager.ReadFile(fileName))
{
using (var reader = new StreamReader(stream))
{
Load(reader);
}
}
}
public ItemFile(StreamReader reader)
{