Skip to content

Commit

Permalink
fix: handle non-existing settings folder
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jun 16, 2023
1 parent 2b67137 commit e379de0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions MidiShapeShifter/MidiShapeShifter/Mss/MssConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public static class MssConstants
{
public const string APP_NAME = "MIDI Shape Shifter";
public const string APP_FOLDER_NAME = "MidiShapeShifter";
}
}
16 changes: 11 additions & 5 deletions MidiShapeShifter/MidiShapeShifter/Mss/MssFileSystemLocations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@ public static string SettingsFolder
get
{
RegistryKey mssLocalMachineRegKey = CreateMssCurrentUserRegKey();
var settingsFolder = mssLocalMachineRegKey.GetValue("SettingsFolder");
var settingsFolderObject = mssLocalMachineRegKey.GetValue("SettingsFolder");

// if doesn't exist, create it
if (settingsFolder == null)
string settingsFolder = "";
if (settingsFolderObject == null)
{
mssLocalMachineRegKey.SetValue("SettingsFolder", MssConstants.DEFAULT_SETTINGS_FOLDER);
settingsFolder = mssLocalMachineRegKey.GetValue("SettingsFolder");
// set it to the current user's Documents/MidiShapeShifter folder
string current_user_documents_folder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
Debug.Assert(current_user_documents_folder != "");
string default_settings_folder = current_user_documents_folder + @"\" + MssConstants.APP_FOLDER_NAME + @"\";

mssLocalMachineRegKey.SetValue("SettingsFolder", default_settings_folder);
settingsFolder = default_settings_folder;
}
Debug.Assert(settingsFolder != null);
Debug.Assert(settingsFolder != "");

mssLocalMachineRegKey.Close();

Expand Down

0 comments on commit e379de0

Please sign in to comment.