summaryrefslogtreecommitdiff
path: root/src/SMAPI/Constants.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Constants.cs')
-rw-r--r--src/SMAPI/Constants.cs31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs
index 05800970..c3105202 100644
--- a/src/SMAPI/Constants.cs
+++ b/src/SMAPI/Constants.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Reflection;
using StardewModdingAPI.Enums;
using StardewModdingAPI.Framework;
@@ -164,9 +165,6 @@ namespace StardewModdingAPI
/// <summary>The language code for non-translated mod assets.</summary>
internal static LocalizedContentManager.LanguageCode DefaultLanguage { get; } = LocalizedContentManager.LanguageCode.en;
- /// <summary>The name of the last save file loaded by the game.</summary>
- internal static string LastRawSaveFileName { get; set; }
-
/*********
** Internal methods
@@ -343,9 +341,30 @@ namespace StardewModdingAPI
if (Context.LoadStage == LoadStage.None)
return null;
- // get save
- string rawSaveName = Constants.LastRawSaveFileName;
- return new DirectoryInfo(Path.Combine(Constants.SavesPath, rawSaveName));
+ // get basic info
+ string rawSaveName = Game1.GetSaveGameName(set_value: false);
+ ulong saveID = Context.LoadStage == LoadStage.SaveParsed
+ ? SaveGame.loaded.uniqueIDForThisGame
+ : Game1.uniqueIDForThisGame;
+
+ // get best match (accounting for rare case where folder name isn't sanitized)
+ DirectoryInfo folder = null;
+ foreach (string saveName in new[] { rawSaveName, new string(rawSaveName.Where(char.IsLetterOrDigit).ToArray()) })
+ {
+ try
+ {
+ folder = new DirectoryInfo(Path.Combine(Constants.SavesPath, $"{saveName}_{saveID}"));
+ if (folder.Exists)
+ return folder;
+ }
+ catch (ArgumentException)
+ {
+ // ignore invalid path
+ }
+ }
+
+ // if save doesn't exist yet, return the default one we expect to be created
+ return folder;
}
}
}