1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// NostaleDataFilesManager.cs
//
// Copyright (c) František Boháček. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Diagnostics.CodeAnalysis;
using NosSmooth.Data.Abstractions;
using NosSmooth.Data.Abstractions.Language;
using Remora.Results;
namespace NosSmooth.Data.NOSFiles;
/// <summary>
/// Nostale .NOS files manager.
/// </summary>
public class NostaleDataFilesManager
{
private readonly NostaleDataParser _parser;
private ILanguageService? _languageService;
private IInfoService? _infoService;
/// <summary>
/// Initializes a new instance of the <see cref="NostaleDataFilesManager"/> class.
/// </summary>
/// <param name="parser">The parser.</param>
public NostaleDataFilesManager(NostaleDataParser parser)
{
_parser = parser;
}
/// <summary>
/// Gets the language service.
/// </summary>
public ILanguageService LanguageService
{
get
{
if (_languageService is null)
{
throw new InvalidOperationException
("The language service is null, did you forget to call NostaleDataManager.Initialize?");
}
return _languageService;
}
}
/// <summary>
/// Gets the info service.
/// </summary>
public IInfoService InfoService
{
get
{
if (_infoService is null)
{
throw new InvalidOperationException
("The info service is null, did you forget to call NostaleDataManager.Initialize?");
}
return _infoService;
}
}
/// <summary>
/// Initialize the info and language services.
/// </summary>
/// <returns>A result that may or may not have succeeded.</returns>
public Result Initialize()
{
if (_languageService is null)
{
var languageServiceResult = _parser.CreateLanguageService();
if (!languageServiceResult.IsSuccess)
{
return Result.FromError(languageServiceResult);
}
_languageService = languageServiceResult.Entity;
}
if (_infoService is null)
{
var infoServiceResult = _parser.CreateInfoService();
if (!infoServiceResult.IsSuccess)
{
return Result.FromError(infoServiceResult);
}
_infoService = infoServiceResult.Entity;
}
return Result.FromSuccess();
}
}