2022-02-06 03:29:03 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
using Microsoft.Win32;
|
|
|
|
|
|
|
|
|
|
namespace ScrapModLoader
|
|
|
|
|
{
|
|
|
|
|
public class ModsLauncher
|
|
|
|
|
{
|
|
|
|
|
public List<ScrapMod> Mods { get; private set; }
|
|
|
|
|
public String ScraplandPath { get; set; }
|
|
|
|
|
public String ScraplandRemasteredPath { get; set; }
|
2022-02-06 12:20:05 +00:00
|
|
|
|
public String SelectedGameVersion { get; set; }
|
2022-02-06 03:29:03 +00:00
|
|
|
|
|
|
|
|
|
public ModsLauncher()
|
|
|
|
|
{
|
|
|
|
|
Mods = new List<ScrapMod>();
|
|
|
|
|
ScraplandPath = Settings.Default.ScraplandPath;
|
|
|
|
|
ScraplandRemasteredPath = Settings.Default.ScraplandRemasteredPath;
|
2022-02-06 12:20:05 +00:00
|
|
|
|
SelectedGameVersion = "0.0";
|
2022-02-06 03:29:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ScanMods()
|
|
|
|
|
{
|
|
|
|
|
Mods.Clear();
|
|
|
|
|
foreach (String? folder in Settings.Default.ModsPathes)
|
|
|
|
|
{
|
|
|
|
|
if (folder != null)
|
|
|
|
|
{
|
|
|
|
|
String[] files = Directory.GetFiles(folder, "*.sm", SearchOption.AllDirectories);
|
|
|
|
|
foreach (String file in files)
|
|
|
|
|
Mods.Add(new ScrapMod(file));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Boolean SearchForScrapland()
|
|
|
|
|
{
|
|
|
|
|
Boolean isFound = false;
|
|
|
|
|
|
|
|
|
|
String[] registryPathes =
|
|
|
|
|
{
|
|
|
|
|
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
|
|
|
|
|
@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
foreach (String registryPath in registryPathes)
|
|
|
|
|
{
|
|
|
|
|
RegistryKey? key = Registry.LocalMachine.OpenSubKey(registryPath);
|
|
|
|
|
if (key == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
foreach (String subkey_name in key.GetSubKeyNames())
|
|
|
|
|
{
|
|
|
|
|
using RegistryKey? subkey = key.OpenSubKey(subkey_name);
|
|
|
|
|
if (subkey == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
String? displayName = subkey.GetValue("DisplayName")?.ToString();
|
|
|
|
|
if (displayName == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (displayName == "Scrapland")
|
|
|
|
|
{
|
|
|
|
|
ScraplandPath = subkey.GetValue("InstallLocation")?.ToString() ?? "";
|
2022-02-06 13:06:49 +00:00
|
|
|
|
Settings.Default.ScraplandPath = ScraplandPath;
|
2022-02-06 03:29:03 +00:00
|
|
|
|
isFound = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (displayName == "Scrapland Remastered")
|
|
|
|
|
{
|
|
|
|
|
ScraplandRemasteredPath = subkey.GetValue("InstallLocation")?.ToString() ?? "";
|
2022-02-06 13:06:49 +00:00
|
|
|
|
Settings.Default.ScraplandRemasteredPath = ScraplandRemasteredPath;
|
2022-02-06 03:29:03 +00:00
|
|
|
|
isFound = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return isFound;
|
|
|
|
|
}
|
2022-02-06 10:59:08 +00:00
|
|
|
|
|
2022-02-06 12:20:05 +00:00
|
|
|
|
public void LoadMods()
|
2022-02-06 10:59:08 +00:00
|
|
|
|
{
|
2022-02-06 12:20:05 +00:00
|
|
|
|
String gamePath = SelectedGameVersion == "1.0" ? ScraplandPath : ScraplandRemasteredPath;
|
|
|
|
|
|
2022-02-06 11:50:32 +00:00
|
|
|
|
foreach (ScrapMod mod in Mods)
|
|
|
|
|
{
|
2022-02-06 12:20:05 +00:00
|
|
|
|
if (mod.RequiredGame != SelectedGameVersion)
|
|
|
|
|
continue;
|
|
|
|
|
|
2022-02-06 11:50:32 +00:00
|
|
|
|
if (mod.Checked)
|
|
|
|
|
{
|
|
|
|
|
if (!mod.IsEnabled(gamePath))
|
|
|
|
|
mod.Enable(gamePath);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (mod.IsEnabled(gamePath))
|
|
|
|
|
mod.Disable(gamePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-06 10:59:08 +00:00
|
|
|
|
}
|
2022-02-06 03:29:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|