-
Notifications
You must be signed in to change notification settings - Fork 9
/
Launcher.cs
59 lines (50 loc) · 1.84 KB
/
Launcher.cs
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
using BTD6_Mod_Manager.Lib;
using BTD6_Mod_Manager.Lib.Game;
using BTD6_Mod_Manager.Lib.MelonMods;
using BTD6_Mod_Manager.Lib.Natives;
using Ionic.Zip;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using static BTD6_Mod_Manager.Lib.MelonMods.MelonMod_Handler;
namespace BTD6_Mod_Manager
{
class Launcher
{
public static void Launch()
{
if (!AreModsValid())
return;
var gameInfo = GameInfo.GetGame(SessionData.currentGame);
if (!Utility.IsProgramRunning(gameInfo.ProcName, out var btd6Proc))
Process.Start("steam://rungameid/" + gameInfo.SteamID);
else
Logger.Log("Please close BTD6 to continue...", OutputType.Both);
}
private static bool AreModsValid()
{
foreach (var mod in SessionData.loadedMods)
{
string filePath = mod;
if (IsFileZip(filePath))
continue;
var melonInfo = MelonMod_Handler.GetModInfo(filePath);
string melonModName = melonInfo.Name;
var similarMods = SessionData.loadedMods.Count(dupMod => GetModInfo(dupMod)?.Name == melonModName);
bool isDuplicate = (similarMods > 1);
if (!isDuplicate)
continue;
Logger.Log($"Error! You are trying to load {melonModName} twice. You need to disable one to continue.", OutputType.Both);
return false;
}
return true;
}
private static bool IsFileZip(string filePath)
{
FileInfo fileInfo = new FileInfo(filePath);
bool isZip = (fileInfo.Extension == ".zip" || fileInfo.Extension == ".rar" || fileInfo.Extension == ".7z");
return isZip;
}
}
}