summaryrefslogtreecommitdiff
path: root/src/SMAPI.Toolkit
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-12-21 12:25:27 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-12-21 12:25:27 -0500
commit71284e7176c55f66754470b19fd74b5b1fda4964 (patch)
tree848a7ec8c99e0e1f8335fac41f9e417dc1c86e40 /src/SMAPI.Toolkit
parent85b947dced10f5398055af36b5fdb6b8d32a6a6b (diff)
parent872a1d5627f20faece618644db1ae4749e124741 (diff)
downloadSMAPI-71284e7176c55f66754470b19fd74b5b1fda4964.tar.gz
SMAPI-71284e7176c55f66754470b19fd74b5b1fda4964.tar.bz2
SMAPI-71284e7176c55f66754470b19fd74b5b1fda4964.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI.Toolkit')
-rw-r--r--src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs48
-rw-r--r--src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs10
2 files changed, 43 insertions, 15 deletions
diff --git a/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs b/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs
index 825988a5..d4c82180 100644
--- a/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs
+++ b/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs
@@ -15,20 +15,33 @@ namespace StardewModdingAPI.Toolkit.Framework.GameScanning
public class GameScanner
{
/*********
+ ** Fields
+ *********/
+ /// <summary>The current OS.</summary>
+ private readonly Platform Platform;
+
+ /// <summary>The name of the Stardew Valley executable.</summary>
+ private readonly string ExecutableName;
+
+
+ /*********
** Public methods
*********/
+ /// <summary>Construct an instance.</summary>
+ public GameScanner()
+ {
+ this.Platform = EnvironmentUtility.DetectPlatform();
+ this.ExecutableName = EnvironmentUtility.GetExecutableName(this.Platform);
+ }
+
/// <summary>Find all valid Stardew Valley install folders.</summary>
/// <remarks>This checks default game locations, and on Windows checks the Windows registry for GOG/Steam install data. A folder is considered 'valid' if it contains the Stardew Valley executable for the current OS.</remarks>
public IEnumerable<DirectoryInfo> Scan()
{
- // get OS info
- Platform platform = EnvironmentUtility.DetectPlatform();
- string executableFilename = EnvironmentUtility.GetExecutableName(platform);
-
// get install paths
IEnumerable<string> paths = this
- .GetCustomInstallPaths(platform)
- .Concat(this.GetDefaultInstallPaths(platform))
+ .GetCustomInstallPaths()
+ .Concat(this.GetDefaultInstallPaths())
.Select(PathUtilities.NormalizePath)
.Distinct(StringComparer.OrdinalIgnoreCase);
@@ -36,21 +49,27 @@ namespace StardewModdingAPI.Toolkit.Framework.GameScanning
foreach (string path in paths)
{
DirectoryInfo folder = new DirectoryInfo(path);
- if (folder.Exists && folder.EnumerateFiles(executableFilename).Any())
+ if (this.LooksLikeGameFolder(folder))
yield return folder;
}
}
+ /// <summary>Get whether a folder seems to contain the game.</summary>
+ /// <param name="dir">The folder to check.</param>
+ public bool LooksLikeGameFolder(DirectoryInfo dir)
+ {
+ return dir.Exists && dir.EnumerateFiles(this.ExecutableName).Any();
+ }
+
/*********
** Private methods
*********/
/// <summary>The default file paths where Stardew Valley can be installed.</summary>
- /// <param name="platform">The target platform.</param>
- /// <remarks>Derived from the crossplatform mod config: https://github.com/Pathoschild/Stardew.ModBuildConfig. </remarks>
- private IEnumerable<string> GetDefaultInstallPaths(Platform platform)
+ /// <remarks>Derived from the <a href="https://github.com/Pathoschild/Stardew.ModBuildConfig">crossplatform mod config</a>.</remarks>
+ private IEnumerable<string> GetDefaultInstallPaths()
{
- switch (platform)
+ switch (this.Platform)
{
case Platform.Linux:
case Platform.Mac:
@@ -102,16 +121,15 @@ namespace StardewModdingAPI.Toolkit.Framework.GameScanning
break;
default:
- throw new InvalidOperationException($"Unknown platform '{platform}'.");
+ throw new InvalidOperationException($"Unknown platform '{this.Platform}'.");
}
}
/// <summary>Get the custom install path from the <c>stardewvalley.targets</c> file in the home directory, if any.</summary>
- /// <param name="platform">The target platform.</param>
- private IEnumerable<string> GetCustomInstallPaths(Platform platform)
+ private IEnumerable<string> GetCustomInstallPaths()
{
// get home path
- string homePath = Environment.GetEnvironmentVariable(platform == Platform.Windows ? "USERPROFILE" : "HOME");
+ string homePath = Environment.GetEnvironmentVariable(this.Platform == Platform.Windows ? "USERPROFILE" : "HOME");
if (string.IsNullOrWhiteSpace(homePath))
yield break;
diff --git a/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs b/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs
index 6d6b6417..5eacee9e 100644
--- a/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs
+++ b/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs
@@ -112,10 +112,20 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning
if (manifestFile == null)
{
FileInfo[] files = this.RecursivelyGetRelevantFiles(searchFolder).ToArray();
+
+ // empty folder
if (!files.Any())
return new ModFolder(root, searchFolder, ModType.Invalid, null, ModParseError.EmptyFolder, "it's an empty folder.");
+
+ // XNB mod
if (files.All(this.IsPotentialXnbFile))
return new ModFolder(root, searchFolder, ModType.Xnb, null, ModParseError.XnbMod, "it's not a SMAPI mod (see https://smapi.io/xnb for info).");
+
+ // SMAPI installer
+ if (files.Any(p => p.Name == "install on Linux.sh" || p.Name == "install on Mac.command" || p.Name == "install on Windows.bat"))
+ return new ModFolder(root, searchFolder, ModType.Invalid, null, ModParseError.ManifestMissing, "the SMAPI installer isn't a mod (you can delete this folder after running the installer file).");
+
+ // not a mod?
return new ModFolder(root, searchFolder, ModType.Invalid, null, ModParseError.ManifestMissing, "it contains files, but none of them are manifest.json.");
}