Skip to content

Commit

Permalink
Fix profile name generation and ini deserialization fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajidur78 committed May 23, 2021
1 parent b2f3ae7 commit 9db33ba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion HedgeModManager/HedgeApp.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ public static void SelectSteamGame(SteamGame steamGame)

ConfigPath = Path.Combine(StartDirectory, "cpkredir.ini");
Config = new CPKREDIRConfig(ConfigPath);
ModsDbPath = Path.Combine(StartDirectory, Path.GetDirectoryName(Config.ModsDbIni));
ModsDbPath = Path.Combine(StartDirectory, Path.GetDirectoryName(Config.ModsDbIni) ?? "Mods");
}

public static void InstallGBHandlers()
Expand Down
15 changes: 13 additions & 2 deletions HedgeModManager/Serialization/IniSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ public static void Deserialize(object obj, IniFile file)
var valueType = property.PropertyType;

if (file.Groups.ContainsKey(group))
property.SetValue(obj, ReadField(group, name, valueType));
{
var value = ReadField(group, name, valueType);
if (value != null)
property.SetValue(obj, value);
}
}

foreach(var field in obj.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance))
Expand All @@ -195,7 +199,11 @@ public static void Deserialize(object obj, IniFile file)
var valueType = field.FieldType;

if (file.Groups.ContainsKey(group))
field.SetValue(obj, ReadField(group, name, valueType));
{
var value = ReadField(group, name, valueType);
if (value != null)
field.SetValue(obj, value);
}
}

object ReadField(string group, string name, Type valueType)
Expand All @@ -221,6 +229,9 @@ object ReadField(string group, string name, Type valueType)
}
else if (valueType == typeof(string))
{
if (!file.Groups.ContainsKey(group) || !file[group].Params.ContainsKey(name))
return null;

return file[group][name];
}
else if (typeof(IEnumerable).IsAssignableFrom(valueType))
Expand Down
4 changes: 4 additions & 0 deletions HedgeModManager/UI/ProfileManagerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ private void UI_Add_Click(object sender, RoutedEventArgs e)
{
// Add Profile
if (DataContext is MainWindowViewModel mainWindow)
{
window.Profile.GeneratePath();
mainWindow.Profiles.Add(window.Profile);
}
}
}

Expand Down Expand Up @@ -107,6 +110,7 @@ private void UI_ProfileRename_Click(object sender, RoutedEventArgs e)
return;
if (!(DataContext is MainWindowViewModel mainWindow))
return;

new ProfileManagerRenameWindow(profile).ShowDialog();
}

Expand Down

0 comments on commit 9db33ba

Please sign in to comment.