-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathGameModel.cs
More file actions
62 lines (52 loc) · 2.1 KB
/
GameModel.cs
File metadata and controls
62 lines (52 loc) · 2.1 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
57
58
59
60
61
62
using Avalonia.Media.Imaging;
using MelonLoader.Installer.GameLaunchers;
using Semver;
namespace MelonLoader.Installer.ViewModels;
public class GameModel(string path, string name, Architecture architecture, GameLauncher? launcher, Bitmap? icon, SemVersion? mlVersion, bool isProtected) : ViewModelBase
{
public string Path => path;
public string Name => name;
public Architecture Arch => architecture;
public bool IsLinux => architecture == Architecture.LinuxX64;
public GameLauncher? Launcher => launcher;
public Bitmap? Icon => icon;
public string? MLVersionText => mlVersion != null ? 'v' + mlVersion.ToString() : null;
public string MLStatusText => mlVersion == null ? "Not Installed" : "Installed " + MLVersionText;
public bool MLInstalled => mlVersion != null;
public bool IsProtected => isProtected;
public string Dir { get; } = System.IO.Path.GetDirectoryName(path)!;
public SemVersion? MLVersion
{
get => mlVersion;
set
{
mlVersion = value;
OnPropertyChanged();
OnPropertyChanged(nameof(MLVersionText));
OnPropertyChanged(nameof(MLStatusText));
OnPropertyChanged(nameof(MLInstalled));
}
}
/// <summary>
/// Checks if the game is still valid. Otherwise, automatically removes it from the Games list.
/// </summary>
/// <returns>True if the game still exists, otherwise false.</returns>
public bool ValidateGame()
{
var exeExtIdx = path.LastIndexOf('.');
var pathNoExt = exeExtIdx != -1 ? path[..exeExtIdx] : path;
if (!File.Exists(path) || !Directory.Exists(pathNoExt + "_Data"))
{
GameManager.RemoveGame(this);
return false;
}
var newMlVersion = Installer.MLVersion.GetMelonLoaderVersion(Dir, out var arch);
if (newMlVersion != null && arch != Arch)
newMlVersion = null;
if (newMlVersion == MLVersion)
return true;
MLVersion = newMlVersion;
GameManager.ResortGame(this);
return true;
}
}