SMAPI - Stardew Modding API

SMAPI - Stardew Modding API

971k Downloads

Allow launching multiple SMAPI instances without providing a different log path

tstaples opened this issue ยท 4 comments

commented

Currently if you launch a second SMAPI instance without specifying a different log path (or messing up the command) SMAPI will throw an IO exception:

Unhandled Exception: System.IO.IOException: The process cannot access the file 'C:\Users\Tyler\AppData\Roaming\StardewValley\ErrorLogs\SMAPI-latest.txt' because it is being used by another process.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost)
   at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost)
   at System.IO.StreamWriter..ctor(String path, Boolean append)
   at StardewModdingAPI.Framework.Logging.LogFileManager..ctor(String path) in C:\source\_Stardew\SMAPI\src\SMAPI\Framework\Logging\LogFileManager.cs:line 39
   at StardewModdingAPI.Program..ctor(Boolean writeToConsole, String logPath) in C:\source\_Stardew\SMAPI\src\SMAPI\Program.cs:line 142
   at StardewModdingAPI.Program.Main(String[] args) in C:\source\_Stardew\SMAPI\src\SMAPI\Program.cs:line 131

It would be helpful if the exception was handled and an error message displayed stating the proper syntax for launching another client with the log path specified.

commented

Wait, is it even doable to run multiple SMAPI's on the same system? I would have sworn that XNA sound and its finicky logic will crash the game anyhow....

commented

Yep! There are instructions in the SDV 1.3 migration guide. If you're prone to the SEHException issue, maybe you'd get that more often, but I haven't had any issues doing it.

commented

Instead of showing a better error, how about SMAPI automatically changes the log path itself? Proposed implementation:

  1. On startup, delete all SMAPI-latest*.txt files that aren't locked.
  2. Write to SMAPI-latest.txt if it doesn't exist, else SMAPI-latest.player-X.txt where X is the first number matching a non-existing file.
commented

Done in develop for the upcoming SMAPI 2.6-beta.16.