From 8b4635ee5ff0f8c0f93208ad3cafe384c2ecb142 Mon Sep 17 00:00:00 2001
From: kalilistic <35899782+kalilistic@users.noreply.github.com>
Date: Sat, 10 Apr 2021 16:15:03 -0400
Subject: [PATCH] refactor: new code style in Data
---
Dalamud.sln.DotSettings | 3 +++
Dalamud/Data/DataManager.cs | 37 +++++++++++++++++++++++--------------
2 files changed, 26 insertions(+), 14 deletions(-)
diff --git a/Dalamud.sln.DotSettings b/Dalamud.sln.DotSettings
index 6a9bd9b76..822d0841c 100644
--- a/Dalamud.sln.DotSettings
+++ b/Dalamud.sln.DotSettings
@@ -47,6 +47,9 @@
True
True
True
+ True
True
True
+ True
+ True
True
\ No newline at end of file
diff --git a/Dalamud/Data/DataManager.cs b/Dalamud/Data/DataManager.cs
index c8dced858..a524a9e04 100644
--- a/Dalamud/Data/DataManager.cs
+++ b/Dalamud/Data/DataManager.cs
@@ -5,6 +5,7 @@ using System.Diagnostics;
using System.IO;
using System.Threading;
+using JetBrains.Annotations;
using Lumina;
using Lumina.Data;
using Lumina.Data.Files;
@@ -19,17 +20,12 @@ namespace Dalamud.Data
///
public class DataManager : IDisposable
{
- ///
- /// The current game client language.
- ///
- internal ClientLanguage Language;
-
private const string IconFileFormat = "ui/icon/{0:D3}000/{1}{2:D6}.tex";
///
/// A object which gives access to any excel/game data.
///
- private Lumina.GameData gameData;
+ private GameData gameData;
private Thread luminaResourceThread;
@@ -45,6 +41,11 @@ namespace Dalamud.Data
this.Language = language;
}
+ ///
+ /// Gets the current game client language.
+ ///
+ public ClientLanguage Language { get; private set; }
+
///
/// Gets the OpCodes sent by the server to the client.
///
@@ -53,6 +54,7 @@ namespace Dalamud.Data
///
/// Gets the OpCodes sent by the client to the server.
///
+ [UsedImplicitly]
public ReadOnlyDictionary ClientOpCodes { get; private set; }
///
@@ -104,11 +106,19 @@ namespace Dalamud.Data
ClientLanguage.French => Lumina.Data.Language.French,
_ => throw new ArgumentOutOfRangeException(
nameof(this.Language),
- "Unknown Language: " + this.Language),
+ @"Unknown Language: " + this.Language),
},
};
- this.gameData = new GameData(Path.Combine(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName), "sqpack"), luminaOptions);
+ var processModule = Process.GetCurrentProcess().MainModule;
+ if (processModule != null)
+ {
+ this.gameData =
+ new GameData(
+ Path.Combine(
+ Path.GetDirectoryName(processModule.FileName) !,
+ "sqpack"), luminaOptions);
+ }
Log.Information("Lumina is ready: {0}", this.gameData.DataPath);
@@ -163,7 +173,7 @@ namespace Dalamud.Data
ClientLanguage.English => Lumina.Data.Language.English,
ClientLanguage.German => Lumina.Data.Language.German,
ClientLanguage.French => Lumina.Data.Language.French,
- _ => throw new ArgumentOutOfRangeException(nameof(this.Language), "Unknown Language: " + this.Language)
+ _ => throw new ArgumentOutOfRangeException(nameof(this.Language), @"Unknown Language: " + this.Language)
};
return this.Excel.GetSheet(lang);
}
@@ -186,11 +196,10 @@ namespace Dalamud.Data
/// The of the file.
public T GetFile(string path) where T : FileResource
{
- ParsedFilePath filePath = GameData.ParseFilePath(path);
+ var filePath = GameData.ParseFilePath(path);
if (filePath == null)
- return default(T);
- Repository repository;
- return this.gameData.Repositories.TryGetValue(filePath.Repository, out repository) ? repository.GetFile(filePath.Category, filePath) : default(T);
+ return default;
+ return this.gameData.Repositories.TryGetValue(filePath.Repository, out var repository) ? repository.GetFile(filePath.Category, filePath) : default(T);
}
///
@@ -226,7 +235,7 @@ namespace Dalamud.Data
ClientLanguage.English => "en/",
ClientLanguage.German => "de/",
ClientLanguage.French => "fr/",
- _ => throw new ArgumentOutOfRangeException(nameof(this.Language), "Unknown Language: " + this.Language)
+ _ => throw new ArgumentOutOfRangeException(nameof(this.Language), @"Unknown Language: " + this.Language)
};
return this.GetIcon(type, iconId);