Always load default settings when deserializing SettingsRepository.
- VERBESSERT: Bei Updates werden neue eingebaute Stile jetzt immer berücksichtigt.
This commit is contained in:
parent
7eaabb7f13
commit
3fcb6c1af5
@ -72,7 +72,9 @@ namespace zaaReloaded2.Controller
|
||||
stream.Write(bytes, 0, bytes.Length);
|
||||
stream.Position = 0;
|
||||
SoapFormatter serializer = new SoapFormatter();
|
||||
return serializer.Deserialize(stream) as SettingsRepository;
|
||||
SettingsRepository repo = serializer.Deserialize(stream) as SettingsRepository;
|
||||
repo.LoadDefaults();
|
||||
return repo;
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,7 +115,7 @@ namespace zaaReloaded2.Controller
|
||||
public SettingsRepository()
|
||||
{
|
||||
SettingsList = new List<Settings>();
|
||||
CreateDefault();
|
||||
Reset();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -181,23 +183,46 @@ namespace zaaReloaded2.Controller
|
||||
/// Resets the Settings contained in this SettingsRepository
|
||||
/// to the default set of settings.
|
||||
/// </summary>
|
||||
private void CreateDefault()
|
||||
private void Reset()
|
||||
{
|
||||
SettingsList.Clear();
|
||||
LoadDefaults();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads default, built-in settings, replacing existing default
|
||||
/// settings that might have been persisted.
|
||||
/// </summary>
|
||||
private void LoadDefaults()
|
||||
{
|
||||
Assembly myAssembly = this.GetType().Assembly;
|
||||
SoapFormatter deserializer = new SoapFormatter();
|
||||
Stream stream = myAssembly.GetManifestResourceStream("zaaReloaded2.Defaults.ward.zaaReloaded");
|
||||
Settings settings = deserializer.Deserialize(stream) as Settings;
|
||||
settings.Name = Properties.Settings.Default.SettingsNameWard + BUILTIN_LABEL;
|
||||
settings.Uid = Guid.Parse(DEFAULT_SETTINGS_1_UID);
|
||||
SettingsList.Add(settings);
|
||||
ReplaceOrAdd(settings);
|
||||
|
||||
stream = myAssembly.GetManifestResourceStream("zaaReloaded2.Defaults.clinic.zaaReloaded");
|
||||
settings = deserializer.Deserialize(stream) as Settings;
|
||||
settings.Name = Properties.Settings.Default.SettingsNameClinic + BUILTIN_LABEL;
|
||||
settings.Uid = Guid.Parse(DEFAULT_SETTINGS_2_UID);
|
||||
SettingsList.Add(settings);
|
||||
ReplaceOrAdd(settings);
|
||||
}
|
||||
|
||||
private void ReplaceOrAdd(Settings settings)
|
||||
{
|
||||
Settings existing = SettingsList.FirstOrDefault(s => s.Uid == settings.Uid);
|
||||
if (existing == null)
|
||||
{
|
||||
SettingsList.Add(settings);
|
||||
}
|
||||
else
|
||||
{
|
||||
int index = SettingsList.IndexOf(existing);
|
||||
SettingsList.RemoveAt(index);
|
||||
SettingsList.Insert(index, settings);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
Loading…
Reference in New Issue
Block a user