Skip to content

Commit

Permalink
[DirectoryManager] Return null properly when file is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
slotthhy committed Jun 27, 2024
1 parent d352ddf commit 13b1b59
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 6 additions & 1 deletion EXDCommon/FileAccess/Directory/DirectoryFileAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public DirectoryFileAccess(PatchDataDirectory directory, string storagePath)

public T? GetFile<T>(string path, string? origPath = null) where T : FileResource
{
var sqpackFile = _directory.SqPackFiles[path];
if (!_directory.SqPackFiles.TryGetValue(path, out var sqpackFile)) return null;
var realPath = Path.Combine(_storagePath, sqpackFile.Hash[..2], sqpackFile.Hash);

if(!File.Exists(realPath))
Expand Down Expand Up @@ -88,4 +88,9 @@ public bool FileExists(string path)

return _indexFiles[category].GetFileOffsetAndDat(path) != (0, 0);
}

public GameVersion GetVersion()
{
return _directory.Version;
}
}
4 changes: 3 additions & 1 deletion EXDCommon/FileAccess/IGameFileAccess.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EXDCommon.Sheets;
using EXDCommon.FileAccess.Directory;
using EXDCommon.Sheets;
using Lumina.Data;

namespace EXDCommon.FileAccess;
Expand All @@ -8,4 +9,5 @@ public interface IGameFileAccess
T? GetFile<T>(string path, string? origPath = null) where T : FileResource;
RawExcelSheet? GetRawExcelSheet(string sheetName, Language sheetLanguage = Language.English);
bool FileExists(string path);
GameVersion GetVersion();
}
14 changes: 12 additions & 2 deletions EXDCommon/FileAccess/Lumina/LuminaFileAccess.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EXDCommon.Sheets;
using EXDCommon.FileAccess.Directory;
using EXDCommon.Sheets;
using Lumina;
using Lumina.Data;
using Lumina.Data.Files.Excel;
Expand All @@ -16,7 +17,7 @@ public LuminaFileAccess(GameData gameData)

public T? GetFile<T>(string path, string? origPath = null) where T : FileResource => _gameData.GetFile<T>(path);
public bool FileExists(string path) => _gameData.FileExists(path);

public RawExcelSheet? GetRawExcelSheet(string sheetName, Language sheetLanguage = Language.English)
{
var path = $"exd/{sheetName}.exh";
Expand All @@ -32,4 +33,13 @@ public LuminaFileAccess(GameData gameData)

return newSheet;
}

public GameVersion GetVersion()
{
var gamePath = _gameData.DataPath.Parent;
var file = gamePath!.FullName + "\\ffxivgame.ver";
var text = File.ReadAllText(file);
var version = GameVersion.Parse(text);
return version;
}
}

0 comments on commit 13b1b59

Please sign in to comment.