summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-05-01 23:31:42 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-09-14 17:50:39 -0400
commitd74b710833edd19d2df2c0847a033078fa71a06e (patch)
tree01ab382a0e7058854ceab852d5ea6c62ecd1a2e2
parenta450b0ebefbf7eb4ca5fa41947eef36fe18ca19a (diff)
downloadSMAPI-d74b710833edd19d2df2c0847a033078fa71a06e.tar.gz
SMAPI-d74b710833edd19d2df2c0847a033078fa71a06e.tar.bz2
SMAPI-d74b710833edd19d2df2c0847a033078fa71a06e.zip
add mod type to mod scanner result
-rw-r--r--src/SMAPI.Toolkit/Framework/ModScanning/ModFolder.cs7
-rw-r--r--src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs20
-rw-r--r--src/SMAPI.Toolkit/Framework/ModScanning/ModType.cs18
3 files changed, 39 insertions, 6 deletions
diff --git a/src/SMAPI.Toolkit/Framework/ModScanning/ModFolder.cs b/src/SMAPI.Toolkit/Framework/ModScanning/ModFolder.cs
index bb467b36..adfee527 100644
--- a/src/SMAPI.Toolkit/Framework/ModScanning/ModFolder.cs
+++ b/src/SMAPI.Toolkit/Framework/ModScanning/ModFolder.cs
@@ -18,6 +18,9 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning
/// <summary>The folder containing the mod's manifest.json.</summary>
public DirectoryInfo Directory { get; }
+ /// <summary>The mod type.</summary>
+ public ModType Type { get; }
+
/// <summary>The mod manifest.</summary>
public Manifest Manifest { get; }
@@ -34,13 +37,15 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning
/// <summary>Construct an instance.</summary>
/// <param name="root">The root folder containing mods.</param>
/// <param name="directory">The folder containing the mod's manifest.json.</param>
+ /// <param name="type">The mod type.</param>
/// <param name="manifest">The mod manifest.</param>
/// <param name="manifestParseError">The error which occurred parsing the manifest, if any.</param>
/// <param name="shouldBeLoaded">Whether the mod should be loaded by default. This should be <c>false</c> if it was found within a folder whose name starts with a dot.</param>
- public ModFolder(DirectoryInfo root, DirectoryInfo directory, Manifest manifest, string manifestParseError = null, bool shouldBeLoaded = true)
+ public ModFolder(DirectoryInfo root, DirectoryInfo directory, ModType type, Manifest manifest, string manifestParseError = null, bool shouldBeLoaded = true)
{
// save info
this.Directory = directory;
+ this.Type = type;
this.Manifest = manifest;
this.ManifestParseError = manifestParseError;
this.ShouldBeLoaded = shouldBeLoaded;
diff --git a/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs b/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs
index 0ab73d56..507e7be2 100644
--- a/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs
+++ b/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs
@@ -65,10 +65,10 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning
{
FileInfo[] files = searchFolder.GetFiles("*", SearchOption.AllDirectories).Where(this.IsRelevant).ToArray();
if (!files.Any())
- return new ModFolder(root, searchFolder, null, "it's an empty folder.");
+ return new ModFolder(root, searchFolder, ModType.Invalid, null, "it's an empty folder.");
if (files.All(file => this.PotentialXnbModExtensions.Contains(file.Extension)))
- return new ModFolder(root, searchFolder, null, "it's not a SMAPI mod (see https://smapi.io/xnb for info).");
- return new ModFolder(root, searchFolder, null, "it contains files, but none of them are manifest.json.");
+ return new ModFolder(root, searchFolder, ModType.Xnb, null, "it's not a SMAPI mod (see https://smapi.io/xnb for info).");
+ return new ModFolder(root, searchFolder, ModType.Invalid, null, "it contains files, but none of them are manifest.json.");
}
// read mod info
@@ -98,7 +98,17 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning
manifest.Author = this.StripNewlines(manifest.Author);
}
- return new ModFolder(root, manifestFile.Directory, manifest, manifestError);
+ // get mod type
+ ModType type = ModType.Invalid;
+ if (manifest != null)
+ {
+ type = !string.IsNullOrWhiteSpace(manifest.ContentPackFor?.UniqueID)
+ ? ModType.ContentPack
+ : ModType.Smapi;
+ }
+
+ // build result
+ return new ModFolder(root, manifestFile.Directory, type, manifest, manifestError);
}
@@ -112,7 +122,7 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning
{
// skip
if (folder.FullName != root.FullName && folder.Name.StartsWith("."))
- yield return new ModFolder(root, folder, null, "ignored folder because its name starts with a dot.", shouldBeLoaded: false);
+ yield return new ModFolder(root, folder, ModType.Invalid, null, "ignored folder because its name starts with a dot.", shouldBeLoaded: false);
// recurse into subfolders
else if (this.IsModSearchFolder(root, folder))
diff --git a/src/SMAPI.Toolkit/Framework/ModScanning/ModType.cs b/src/SMAPI.Toolkit/Framework/ModScanning/ModType.cs
new file mode 100644
index 00000000..2ceb9e40
--- /dev/null
+++ b/src/SMAPI.Toolkit/Framework/ModScanning/ModType.cs
@@ -0,0 +1,18 @@
+namespace StardewModdingAPI.Toolkit.Framework.ModScanning
+{
+ /// <summary>A general mod type.</summary>
+ public enum ModType
+ {
+ /// <summary>The mod is invalid and its type could not be determined.</summary>
+ Invalid,
+
+ /// <summary>A mod which uses SMAPI directly.</summary>
+ Smapi,
+
+ /// <summary>A mod which contains files loaded by a SMAPI mod.</summary>
+ ContentPack,
+
+ /// <summary>A legacy mod which replaces game files directly.</summary>
+ Xnb
+ }
+}