-
-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
190 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Other/ApplySaveFixCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using StardewValley; | ||
|
||
namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Other | ||
{ | ||
/// <summary>A command which runs one of the game's save migrations.</summary> | ||
internal class ApplySaveFixCommand : TrainerCommand | ||
{ | ||
/********* | ||
** Public methods | ||
*********/ | ||
/// <summary>Construct an instance.</summary> | ||
public ApplySaveFixCommand() | ||
: base("apply_save_fix", "Apply one of the game's save migrations to the currently loaded save. WARNING: This may corrupt or make permanent changes to your save. DO NOT USE THIS unless you're absolutely sure.\n\nUsage: apply_save_fix list\nList all valid save IDs.\n\nUsage: apply_save_fix <fix ID>\nApply the named save fix.") { } | ||
|
||
/// <summary>Handle the command.</summary> | ||
/// <param name="monitor">Writes messages to the console and log file.</param> | ||
/// <param name="command">The command name.</param> | ||
/// <param name="args">The command arguments.</param> | ||
public override void Handle(IMonitor monitor, string command, ArgumentParser args) | ||
{ | ||
// get fix ID | ||
if (!args.TryGet(0, "fix_id", out string rawFixId, required: false)) | ||
{ | ||
monitor.Log("Invalid usage. Type 'help apply_save_fix' for details.", LogLevel.Error); | ||
return; | ||
} | ||
rawFixId = rawFixId.Trim(); | ||
|
||
|
||
// list mode | ||
if (rawFixId == "list") | ||
{ | ||
monitor.Log("Valid save fix IDs:\n - " + string.Join("\n - ", this.GetSaveIds()), LogLevel.Info); | ||
return; | ||
} | ||
|
||
// validate fix ID | ||
if (!Enum.TryParse(rawFixId, ignoreCase: true, out SaveGame.SaveFixes fixId)) | ||
{ | ||
monitor.Log($"Invalid save ID '{rawFixId}'. Type 'help apply_save_fix' for details.", LogLevel.Error); | ||
return; | ||
} | ||
|
||
// apply | ||
monitor.Log("THIS MAY CAUSE PERMANENT CHANGES TO YOUR SAVE FILE. If you're not sure, exit your game without saving to avoid issues.", LogLevel.Warn); | ||
monitor.Log($"Trying to apply save fix ID: '{fixId}'.", LogLevel.Warn); | ||
try | ||
{ | ||
Game1.applySaveFix(fixId); | ||
monitor.Log("Save fix applied.", LogLevel.Info); | ||
} | ||
catch (Exception ex) | ||
{ | ||
monitor.Log("Applying save fix failed. The save may be in an invalid state; you should exit your game now without saving to avoid issues.", LogLevel.Error); | ||
monitor.Log($"Technical details: {ex}", LogLevel.Debug); | ||
} | ||
} | ||
|
||
|
||
/********* | ||
** Private methods | ||
*********/ | ||
/// <summary>Get the valid save fix IDs.</summary> | ||
private IEnumerable<string> GetSaveIds() | ||
{ | ||
foreach (SaveGame.SaveFixes id in Enum.GetValues(typeof(SaveGame.SaveFixes))) | ||
{ | ||
if (id == SaveGame.SaveFixes.MAX) | ||
continue; | ||
|
||
yield return id.ToString(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
{ | ||
"Name": "Console Commands", | ||
"Author": "SMAPI", | ||
"Version": "3.8.0", | ||
"Version": "3.8.1", | ||
"Description": "Adds SMAPI console commands that let you manipulate the game.", | ||
"UniqueID": "SMAPI.ConsoleCommands", | ||
"EntryDll": "ConsoleCommands.dll", | ||
"MinimumApiVersion": "3.8.0" | ||
"MinimumApiVersion": "3.8.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
{ | ||
"Name": "Save Backup", | ||
"Author": "SMAPI", | ||
"Version": "3.8.0", | ||
"Version": "3.8.1", | ||
"Description": "Automatically backs up all your saves once per day into its folder.", | ||
"UniqueID": "SMAPI.SaveBackup", | ||
"EntryDll": "SaveBackup.dll", | ||
"MinimumApiVersion": "3.8.0" | ||
"MinimumApiVersion": "3.8.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.