RWELabs / Stardew-Valley-Mod-Manager

[Passion Project] The Stardew Valley Mod Manager is a powerful tool that is designed to be used alongside SMAPI to help you install and manage mods, automatically install modpacks and manage your game saves.
Other
26 stars 1 forks source link

[Issue] Launching SDV Mod Manager before ever running Stardew Valley results in Unhandled Exception #18

Closed RyanWalpole closed 2 years ago

RyanWalpole commented 2 years ago

Describe the Issue Stardew Valley Mod Manager will return an Unhandled Exception after the initial application setup if Stardew Valley has never been run on the system (even if Stardew Valley and SMAPI are installed)

Unhandled exception has occurred in your application. 
If you click Continue, the application will ignore this error and attempt to continue. 
If you click Quit, the application will close immediately.

Could not find a part of the path
'C:\Users\user\AppData\Roaming\StardewValley\Saves'

Steps to Replicate Steps to reproduce the behavior:

  1. Have Stardew Valley and SMAPI installed on your system, but have not ever run Stardew Valley.
  2. Open the Mod Manager (and complete setup for the Mod Manager)
  3. Witness error

Expected behavior For the application to launch without an unhandled exception, for the exception to be handled in code.

Screenshots image

Environment:

Suggested Resolution Handle the exception at Form.Load. Currently the application assumes that the user has run Stardew Valley before and therefore the Game Save Management tab attempts to load all directories in the AppData\StardewValley\Saves\ folder. Simply put a catch statement to catch the Exception and present a MessageBox:

MessageBox.Show(
"We weren't able to find your Game Saves folder. This usually happens if you've never run 
Stardew Valley before. If you're on a new PC, consider checking if your 
Game Save files were successfully moved.",
"Game Save Management | Stardew Valley Modded Framework", 
MessageBoxButtons.OK, MessageBoxIcon.Warning)

//Unsure of actual name of button, but probably should
//disable the button that opens the game save directory since it doesn't exist.
ViewSaveFilesButton.Enabled = False;
RyanWalpole commented 2 years ago

Have uploaded commit, adding a new "Splash" screen that programmatically checks for the folders that are required and creates them if they haven't already been created.

private void CheckDirectory_Tick(object sender, EventArgs e)
        {
            CheckDirectory.Stop();
            Status.Text = "Validating Directories...";

            CreateDirectories();

            LaunchApplication.Start();
        }
private void CreateDirectories()
        {
            //Check for Mods Directory
            string ModsDirectory = Properties.Settings.Default.StardewDir + @"\Mods";
            if (!Directory.Exists(ModsDirectory))
            {
                Directory.CreateDirectory(ModsDirectory);
            }

            //Check for Inactive Mods Directory
            string InactiveModsDirectory = Properties.Settings.Default.StardewDir + @"\inactive-mods";
            if (!Directory.Exists(InactiveModsDirectory))
            {
                Directory.CreateDirectory(InactiveModsDirectory);
            }

            //Check for Presets Directory
            string PresetsDirectory = Properties.Settings.Default.StardewDir + @"\mod-presets";
            if (!Directory.Exists(PresetsDirectory))
            {
                Directory.CreateDirectory(PresetsDirectory);
            }

            //Check for Saves Directory
            string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string sdvsaves = appdata + @"\StardewValley\Saves\";
            if (!Directory.Exists(sdvsaves))
            {
                Directory.CreateDirectory(sdvsaves);
            }

            //Check for Save Backups Directory
            string backupsdir = Properties.Settings.Default.StardewDir + @"\savebackups\";
            if (!Directory.Exists(backupsdir))
            {
                Directory.CreateDirectory(backupsdir);
            }
        }
RyanWalpole commented 2 years ago

Add documentation for issue https://github.com/RyanWalpoleEnterprises/Stardew-Valley-Mod-Manager/issues/18

See here: https://github.com/RyanWalpoleEnterprises/Stardew-Valley-Mod-Manager/wiki/Issues:-Stardew-Valley-Mod-Manager#unhandled-exception-could-not-find-a-part-of-the-path

RyanWalpole commented 2 years ago

Issue has been resolved in release build 220303