add display name field to ModFolder (#583)

This commit is contained in:
Jesse Plamondon-Willard 2018-08-19 21:22:48 -04:00
parent 307bf6ce55
commit ca8699c68f
3 changed files with 19 additions and 14 deletions

View File

@ -30,13 +30,6 @@ namespace StardewModdingAPI.Framework.ModLoading
// parse internal data record (if any)
ModDataRecordVersionedFields dataRecord = modDatabase.Get(manifest?.UniqueID)?.GetVersionedFields(manifest);
// get display name
string displayName = manifest?.Name;
if (string.IsNullOrWhiteSpace(displayName))
displayName = dataRecord?.DisplayName;
if (string.IsNullOrWhiteSpace(displayName))
displayName = PathUtilities.GetRelativePath(rootPath, folder.Directory.FullName);
// apply defaults
if (manifest != null && dataRecord != null)
{
@ -48,7 +41,7 @@ namespace StardewModdingAPI.Framework.ModLoading
ModMetadataStatus status = folder.ManifestParseError == null
? ModMetadataStatus.Found
: ModMetadataStatus.Failed;
yield return new ModMetadata(displayName, folder.Directory.FullName, manifest, dataRecord).SetStatus(status, folder.ManifestParseError);
yield return new ModMetadata(folder.DisplayName, folder.Directory.FullName, manifest, dataRecord).SetStatus(status, folder.ManifestParseError);
}
}

View File

@ -2,6 +2,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using StardewModdingAPI.Toolkit.Serialisation.Models;
using StardewModdingAPI.Toolkit.Utilities;
namespace StardewModdingAPI.Toolkit.Framework.ModScanning
{
@ -11,6 +12,9 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning
/*********
** Accessors
*********/
/// <summary>A suggested display name for the mod folder.</summary>
public string DisplayName { get; }
/// <summary>The folder containing the mod's manifest.json.</summary>
public DirectoryInfo Directory { get; }
@ -25,14 +29,21 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning
** Public methods
*********/
/// <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="manifest">The mod manifest.</param>
/// <param name="manifestParseError">The error which occurred parsing the manifest, if any.</param>
public ModFolder(DirectoryInfo directory, Manifest manifest, string manifestParseError = null)
public ModFolder(DirectoryInfo root, DirectoryInfo directory, Manifest manifest, string manifestParseError = null)
{
// save info
this.Directory = directory;
this.Manifest = manifest;
this.ManifestParseError = manifestParseError;
// set display name
this.DisplayName = manifest?.Name;
if (string.IsNullOrWhiteSpace(this.DisplayName))
this.DisplayName = PathUtilities.GetRelativePath(root.FullName, directory.FullName);
}
/// <summary>Get the update keys for a mod.</summary>

View File

@ -44,8 +44,9 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning
}
/// <summary>Extract information from a mod folder.</summary>
/// <param name="root">The root folder containing mods.</param>
/// <param name="searchFolder">The folder to search for a mod.</param>
public ModFolder ReadFolder(DirectoryInfo searchFolder)
public ModFolder ReadFolder(DirectoryInfo root, DirectoryInfo searchFolder)
{
// find manifest.json
FileInfo manifestFile = this.FindManifest(searchFolder);
@ -53,8 +54,8 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning
{
bool isEmpty = !searchFolder.GetFileSystemInfos().Where(this.IsRelevant).Any();
if (isEmpty)
return new ModFolder(searchFolder, null, "it's an empty folder.");
return new ModFolder(searchFolder, null, "it contains files, but none of them are manifest.json.");
return new ModFolder(root, searchFolder, null, "it's an empty folder.");
return new ModFolder(root, searchFolder, null, "it contains files, but none of them are manifest.json.");
}
// read mod info
@ -76,7 +77,7 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning
}
}
return new ModFolder(manifestFile.Directory, manifest, manifestError);
return new ModFolder(root, manifestFile.Directory, manifest, manifestError);
}
@ -100,7 +101,7 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning
// treat as mod folder
else
yield return this.ReadFolder(folder);
yield return this.ReadFolder(root, folder);
}
/// <summary>Find the manifest for a mod folder.</summary>