forked from Reloaded-Project/Reloaded-II
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCreateModViewModel.cs
More file actions
56 lines (48 loc) · 1.88 KB
/
Copy pathCreateModViewModel.cs
File metadata and controls
56 lines (48 loc) · 1.88 KB
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
namespace Reloaded.Mod.Launcher.Lib.Models.ViewModel.Dialog;
/// <summary>
/// ViewModel used for creating an individual modification using an individual mod id.
/// </summary>
public class CreateModViewModel : ObservableObject
{
/// <summary>
/// Current ID of the mod.
/// </summary>
public string ModId { get; set; } = "";
private readonly ModConfigService _modConfigService;
/// <inheritdoc />
public CreateModViewModel(ModConfigService modConfigService)
{
_modConfigService = modConfigService;
}
/// <summary>
/// Creates the mod.
/// </summary>
/// <param name="showNonUniqueWindow">Shows a message to tell the user the mod isn't unique.</param>
public async Task<PathTuple<ModConfig>?> CreateMod(Action showNonUniqueWindow)
{
if (!IsUnique(showNonUniqueWindow))
return null;
var config = new ModConfig()
{
ModId = ModId,
ReleaseMetadataFileName = $"{ModId}.ReleaseMetadata.json"
};
config.IgnoreRegexes.Add($"{Regex.Escape($@"{config.ModId}.nuspec")}");
config.IncludeRegexes.Add(Regex.Escape(ModConfig.ConfigFileName));
var modDirectory = Path.Combine(IoC.Get<LoaderConfig>().GetModConfigDirectory(), IOEx.ForceValidFilePath(ModId));
var filePath = Path.Combine(modDirectory, ModConfig.ConfigFileName);
await IConfig<ModConfig>.ToPathAsync(config, filePath);
return new PathTuple<ModConfig>(filePath, config);
}
/// <summary>
/// Returns true if the mod id is unique, else false.
/// </summary>
/// <param name="showNonUniqueWindow">Shows a message to tell the user the mod isn't unique.</param>
private bool IsUnique(Action showNonUniqueWindow)
{
if (!_modConfigService.ItemsById.ContainsKey(ModId))
return true;
showNonUniqueWindow();
return false;
}
}