Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

パッケージの更新 / マイナーな改善 #182

Merged
merged 9 commits into from
Mar 10, 2024
Merged
47 changes: 29 additions & 18 deletions LibX4.Tests/CatFileTests/CatFileTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ namespace LibX4.Tests.CatFileTests;
/// </summary>
public class CatFileTest
{
/// <summary>
/// テストデータの基準フォルダ
/// </summary>
private readonly string _baseDir;

/// <summary>
/// 設定ファイル格納先フォルダ
/// </summary>
private readonly string _configFolderPath;


public CatFileTest()
{
var path = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location) ?? Environment.CurrentDirectory;
Expand All @@ -33,6 +42,8 @@ public CatFileTest()
}

_baseDir = path ?? "";

_configFolderPath = Path.Combine(_baseDir, "Config");
}

private string MakePath(string path)
Expand All @@ -46,7 +57,7 @@ private string MakePath(string path)
[Fact]
public void X4Version()
{
var cat = new CatFile(Path.Combine(_baseDir, "VanillaEnvironment"));
var cat = new CatFile(Path.Combine(_baseDir, "VanillaEnvironment"), _configFolderPath);

Assert.Equal("330", cat.Version);
}
Expand All @@ -60,7 +71,7 @@ public void X4Version()
[Fact]
public async Task OpenVanillaFile1()
{
var cat = new CatFile(Path.Combine(_baseDir, "VanillaEnvironment"));
var cat = new CatFile(Path.Combine(_baseDir, "VanillaEnvironment"), _configFolderPath);

using var ms = await cat.OpenFileAsync("libraries/personal_infomation/personal_infomation.xml");

Expand All @@ -76,7 +87,7 @@ public async Task OpenVanillaFile1()
[Fact]
public async Task OpenVanillaFile2()
{
var cat = new CatFile(Path.Combine(_baseDir, "VanillaEnvironment"));
var cat = new CatFile(Path.Combine(_baseDir, "VanillaEnvironment"), _configFolderPath);

using var ms = await cat.OpenFileAsync("libraries/personal_infomation/personal infomation.xml");

Expand All @@ -92,7 +103,7 @@ public async Task OpenVanillaFile2()
[Fact]
public async Task OpenVanillaFile3()
{
var cat = new CatFile(Path.Combine(_baseDir, "VanillaEnvironment"));
var cat = new CatFile(Path.Combine(_baseDir, "VanillaEnvironment"), _configFolderPath);

using var ms = await cat.OpenFileAsync("libraries/personal infomation/personal_infomation.xml");

Expand All @@ -108,7 +119,7 @@ public async Task OpenVanillaFile3()
[Fact]
public async Task OpenVanillaFile4()
{
var cat = new CatFile(Path.Combine(_baseDir, "VanillaEnvironment"));
var cat = new CatFile(Path.Combine(_baseDir, "VanillaEnvironment"), _configFolderPath);

using var ms = await cat.OpenFileAsync("libraries/personal infomation/personal infomation.xml");

Expand All @@ -126,7 +137,7 @@ public async Task OpenVanillaFile5()
{
var ex = await Assert.ThrowsAsync<FileNotFoundException>(async () =>
{
var cat = new CatFile(Path.Combine(_baseDir, "VanillaEnvironment"));
var cat = new CatFile(Path.Combine(_baseDir, "VanillaEnvironment"), _configFolderPath);

using var ms = await cat.OpenFileAsync("libraries/not_exist.txt");
});
Expand All @@ -141,7 +152,7 @@ public async Task OpenVanillaFile5()
[Fact]
public async Task OpenVanillaFile6()
{
var cat = new CatFile(Path.Combine(_baseDir, "VanillaEnvironment"));
var cat = new CatFile(Path.Combine(_baseDir, "VanillaEnvironment"), _configFolderPath);

using var ms = await cat.TryOpenFileAsync("libraries/not_exist.txt");

Expand All @@ -155,7 +166,7 @@ public async Task OpenVanillaFile6()
[Fact]
public async Task OpenVanillaFile7()
{
var cat = new CatFile(Path.Combine(_baseDir, "VanillaEnvironment"));
var cat = new CatFile(Path.Combine(_baseDir, "VanillaEnvironment"), _configFolderPath);

using var ms = await cat.OpenFileAsync("libraries/personal_infomation.xml");

Expand All @@ -167,14 +178,14 @@ public async Task OpenVanillaFile7()



#region Mod入でバニラ環境のファイルを開く
#region Mod入でバニラ環境のファイルを開く
/// <summary>
/// Mod入の環境でバニラのファイルを開く
/// </summary>
[Fact]
public async Task OpenVanillaFileWithMods1()
{
var cat = new CatFile(Path.Combine(_baseDir, "ModEnvironment"));
var cat = new CatFile(Path.Combine(_baseDir, "ModEnvironment"), _configFolderPath);

using var ms = await cat.OpenFileAsync("libraries/personal_infomation/personal_infomation.xml");

Expand All @@ -190,7 +201,7 @@ public async Task OpenVanillaFileWithMods1()
[Fact]
public async Task OpenVanillaFileWithMods2()
{
var cat = new CatFile(Path.Combine(_baseDir, "ModEnvironment"));
var cat = new CatFile(Path.Combine(_baseDir, "ModEnvironment"), _configFolderPath);

using var ms = await cat.OpenFileAsync("libraries/personal_infomation/personal infomation.xml");

Expand All @@ -206,7 +217,7 @@ public async Task OpenVanillaFileWithMods2()
[Fact]
public async Task OpenVanillaFileWithMods3()
{
var cat = new CatFile(Path.Combine(_baseDir, "ModEnvironment"));
var cat = new CatFile(Path.Combine(_baseDir, "ModEnvironment"), _configFolderPath);

using var ms = await cat.OpenFileAsync("libraries/personal infomation/personal_infomation.xml");

Expand All @@ -222,7 +233,7 @@ public async Task OpenVanillaFileWithMods3()
[Fact]
public async Task OpenVanillaFileWithMods4()
{
var cat = new CatFile(Path.Combine(_baseDir, "ModEnvironment"));
var cat = new CatFile(Path.Combine(_baseDir, "ModEnvironment"), _configFolderPath);

using var ms = await cat.OpenFileAsync("libraries/personal infomation/personal infomation.xml");

Expand All @@ -241,7 +252,7 @@ public async Task OpenVanillaFileWithMods4()
[Fact]
public async Task OpenModFile1()
{
var cat = new CatFile(Path.Combine(_baseDir, "ModEnvironment"));
var cat = new CatFile(Path.Combine(_baseDir, "ModEnvironment"), _configFolderPath);

using var ms = await cat.OpenFileAsync("libraries/foo_mod_personal_infomation/personal_infomation.xml");

Expand All @@ -257,7 +268,7 @@ public async Task OpenModFile1()
[Fact]
public async Task OpenModFile2()
{
var cat = new CatFile(Path.Combine(_baseDir, "PlaneFileModEnvironment"));
var cat = new CatFile(Path.Combine(_baseDir, "PlaneFileModEnvironment"), _configFolderPath);

using var ms = await cat.OpenFileAsync("libraries/foo_mod_personal_infomation/personal_infomation.xml");

Expand All @@ -275,7 +286,7 @@ public async Task OpenModFile2()
[Fact]
public async Task OpenIndexFile1()
{
var cat = new CatFile(Path.Combine(_baseDir, "VanillaIndexXml"));
var cat = new CatFile(Path.Combine(_baseDir, "VanillaIndexXml"), _configFolderPath);

var xml1 = await cat.OpenIndexXmlAsync("index/macros.xml", "foo_macro");

Expand All @@ -293,7 +304,7 @@ public async Task OpenIndexFile2()
{
var ex = await Assert.ThrowsAsync<FileNotFoundException>(async () =>
{
var cat = new CatFile(Path.Combine(_baseDir, "VanillaIndexXml"));
var cat = new CatFile(Path.Combine(_baseDir, "VanillaIndexXml"), _configFolderPath);

var xml1 = await cat.OpenIndexXmlAsync("index/macros.xml", "not_exists_macro");
});
Expand All @@ -306,7 +317,7 @@ public async Task OpenIndexFile2()
[Fact]
public async Task OpenIndexFile3()
{
var cat = new CatFile(Path.Combine(_baseDir, "ModIndexXml"));
var cat = new CatFile(Path.Combine(_baseDir, "ModIndexXml"), _configFolderPath);

var xml1 = await cat.OpenIndexXmlAsync("index/macros.xml", "baz_macro");

Expand Down
10 changes: 5 additions & 5 deletions LibX4.Tests/LibX4.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows7.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0-preview-24080-01" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="coverlet.collector" Version="6.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
3 changes: 3 additions & 0 deletions LibX4.Tests/TestData/CatFileTest/Config/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
</root>
3 changes: 3 additions & 0 deletions LibX4.Tests/TestData/CatFileTest/Config/content.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<content sync="true">
</content>
10 changes: 6 additions & 4 deletions LibX4/FileSystem/CatFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ private static readonly Regex _ParseModRegex
/// コンストラクタ
/// </summary>
/// <param name="gameRoot">X4インストール先ディレクトリパス</param>
/// <param name="configFolderPath">設定フォルダパス</param>
/// <param name="option">cat ファイルの読み込みオプション</param>
/// <exception cref="DependencyResolutionException">Mod の依存関係の解決に失敗した場合</exception>
public CatFile(string gameRoot, CatLoadOption option = CatLoadOption.All)
public CatFile(string gameRoot, string configFolderPath, CatLoadOption option = CatLoadOption.All)
{
// X4のバージョンを取得
{
Expand All @@ -93,7 +94,7 @@ public CatFile(string gameRoot, CatLoadOption option = CatLoadOption.All)
}
}

var modInfo = GetModInfo(gameRoot, option);
var modInfo = GetModInfo(gameRoot, configFolderPath, option);

_loadedMods = new HashSet<string>(modInfo.Select(x => $"extensions/{Path.GetFileName(x.Directory)}".Replace('\\', '/')));

Expand All @@ -112,9 +113,10 @@ public CatFile(string gameRoot, CatLoadOption option = CatLoadOption.All)
/// Mod の情報を <see cref="IReadOnlyList{ModInfo}"/> で返す
/// </summary>
/// <param name="gameRoot">X4 インストール先ディレクトリパス</param>
/// <param name="configFolderPath">設定フォルダパス</param>
/// <param name="option">cat ファイルの読み込みオプション</param>
/// <returns>Mod の情報を表す <see cref="IReadOnlyList{ModInfo}"/></returns>
private static IReadOnlyList<ModInfo> GetModInfo(string gameRoot, CatLoadOption option)
private static IReadOnlyList<ModInfo> GetModInfo(string gameRoot, string configFolderPath, CatLoadOption option)
{
var entensionsPath = Path.Combine(gameRoot, "extensions");

Expand All @@ -125,7 +127,7 @@ private static IReadOnlyList<ModInfo> GetModInfo(string gameRoot, CatLoadOption
}

// ユーザフォルダにある content.xml を開く
_ = XDocumentEx.TryLoad(Path.Combine(X4Path.GetUserDirectory(), "content.xml"), out var userContentXml);
_ = XDocumentEx.TryLoad(Path.Combine(configFolderPath, "content.xml"), out var userContentXml);

var unloadedMods = Directory.GetDirectories(entensionsPath)
.Select(x => new ModInfo(userContentXml, x))
Expand Down
24 changes: 0 additions & 24 deletions LibX4/FileSystem/CatFileLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,28 +241,4 @@ public XrCatalogParseException(string message)
{

}


/// <summary>
/// <see cref="XrCatalogParseException"/> を生成する
/// </summary>
/// <param name="message">エラーメッセージ</param>
/// <param name="inner">原因となる例外</param>
public XrCatalogParseException(string message, Exception inner)
: base(message, inner)
{

}


/// <summary>
/// <see cref="XrCatalogParseException"/> を生成する
/// </summary>
/// <param name="info">シリアライズ情報</param>
/// <param name="context">ストリーミングコンテキスト</param>
protected XrCatalogParseException(SerializationInfo info, StreamingContext context)
: base(info, context)
{

}
}
2 changes: 1 addition & 1 deletion LibX4/LibX4.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
25 changes: 11 additions & 14 deletions LibX4/X4Path.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Microsoft.Win32;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

Expand Down Expand Up @@ -58,37 +60,32 @@ public static string GetX4InstallDirectory()


/// <summary>
/// X4 のユーザフォルダパスを取得する
/// X4 の設定フォルダパスを列挙する
/// </summary>
/// <returns>成功した場合 X4 のユーザフォルダパス文字列。失敗した場合空文字列</returns>
public static string GetUserDirectory()
/// <returns>X4 の設定フォルダパスの列挙</returns>
public static IEnumerable<string> EnumerateConfigFolders()
{
// C:\Users\(UserName)\Documents\Egosoft\X4
var x4Dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Egosoft", "X4");

if (!Directory.Exists(x4Dir))
{
return "";
yield break;
}

// Steam 版のユーザフォルダを検索
// Steam 版の設定フォルダを検索
foreach (var dir in Directory.GetDirectories(x4Dir))
{
// 名前が全て数字で構成されているフォルダの中に config.xml があればそのフォルダをユーザフォルダと見なす
// 名前が全て数字で構成されているフォルダの中に config.xml があればそのフォルダを設定フォルダと見なす
var folderName = Path.GetFileName(dir);
if (folderName.All(char.IsDigit) && File.Exists(Path.Combine(dir, "config.xml")))
{
return dir;
yield return dir;
}
}

// 非 Steam 版のユーザフォルダか判定
// 非 Steam 版の設定フォルダか判定
if (File.Exists(Path.Combine(x4Dir, "config.xml")))
{
return x4Dir;
yield return x4Dir;
}

// 見つからなかった
return "";
}
}
2 changes: 1 addition & 1 deletion X4_ComplexCalculator/Localization/Lang.csv
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ MainWindow_Menu_File_MenuItem_Import_MenuItem_Loadout_Header;Module equipments
MainWindow_Menu_File_MenuItem_Export_Header;Export
MainWindow_Menu_File_MenuItem_Export_MenuItem_StationCalculator_Header;Station Calculator
MainWindow_Menu_File_UpdateDB_Header;Update DB
MainWindow_Menu_File_UpdateDB_DBUpdate_ConfirmationMessage;Do you want to display the DB update screen?
MainWindow_Menu_File_UpdateDB_DBUpdate_RestartRequestMessage;Please restart the application to apply the DB update.
MainWindow_Menu_File_UpdateDB_DBUpdate_FailureMessage;Failed to update the DB, \r\nplease check if the DB file is accessible and try again.

Expand Down Expand Up @@ -407,6 +406,7 @@ DBViewer_Ships_HangerCapacity_Drone;Drone
DataExporter_Title;X4: Foundations data exporter
DataExporter_Input;Input
DataExporter_Input_RootDirectory;X4: Foundations Install directory
DataExporter_Input_ConfigFolder;Config folder path
DataExporter_Output;Output
DataExporter_Output_Language;Language
DataExporter_Export;Export
Expand Down
2 changes: 1 addition & 1 deletion X4_ComplexCalculator/Localization/Lang.ja-JP.csv
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ MainWindow_Menu_File_MenuItem_Import_MenuItem_Loadout_Header;モジュールの
MainWindow_Menu_File_MenuItem_Export_Header;エクスポート
MainWindow_Menu_File_MenuItem_Export_MenuItem_StationCalculator_Header;Station Calculator
MainWindow_Menu_File_UpdateDB_Header;DB更新
MainWindow_Menu_File_UpdateDB_DBUpdate_ConfirmationMessage;DB更新画面を表示しますか?
MainWindow_Menu_File_UpdateDB_DBUpdate_RestartRequestMessage;DBの更新を適用するためには本アプリケーションの再起動を行ってください。
MainWindow_Menu_File_UpdateDB_DBUpdate_FailureMessage;DBの更新に失敗しました。\r\nDBファイルにアクセス可能か確認後、再度実行してください。

Expand Down Expand Up @@ -407,6 +406,7 @@ DBViewer_Ships_HangerCapacity_Drone;ドローン
DataExporter_Title;X4: Foundations データ抽出機
DataExporter_Input;入力
DataExporter_Input_RootDirectory;X4: Foundations インストール先フォルダ
DataExporter_Input_ConfigFolder;設定フォルダパス
DataExporter_Output;出力
DataExporter_Output_Language;言語
DataExporter_Export;抽出
Expand Down
Loading
Loading