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.Write(bytes, 0, bytes.Length);
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
SoapFormatter serializer = new SoapFormatter();
|
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()
|
public SettingsRepository()
|
||||||
{
|
{
|
||||||
SettingsList = new List<Settings>();
|
SettingsList = new List<Settings>();
|
||||||
CreateDefault();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -181,24 +183,47 @@ namespace zaaReloaded2.Controller
|
|||||||
/// Resets the Settings contained in this SettingsRepository
|
/// Resets the Settings contained in this SettingsRepository
|
||||||
/// to the default set of settings.
|
/// to the default set of settings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void CreateDefault()
|
private void Reset()
|
||||||
{
|
{
|
||||||
SettingsList.Clear();
|
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;
|
Assembly myAssembly = this.GetType().Assembly;
|
||||||
SoapFormatter deserializer = new SoapFormatter();
|
SoapFormatter deserializer = new SoapFormatter();
|
||||||
Stream stream = myAssembly.GetManifestResourceStream("zaaReloaded2.Defaults.ward.zaaReloaded");
|
Stream stream = myAssembly.GetManifestResourceStream("zaaReloaded2.Defaults.ward.zaaReloaded");
|
||||||
Settings settings = deserializer.Deserialize(stream) as Settings;
|
Settings settings = deserializer.Deserialize(stream) as Settings;
|
||||||
settings.Name = Properties.Settings.Default.SettingsNameWard + BUILTIN_LABEL;
|
settings.Name = Properties.Settings.Default.SettingsNameWard + BUILTIN_LABEL;
|
||||||
settings.Uid = Guid.Parse(DEFAULT_SETTINGS_1_UID);
|
settings.Uid = Guid.Parse(DEFAULT_SETTINGS_1_UID);
|
||||||
SettingsList.Add(settings);
|
ReplaceOrAdd(settings);
|
||||||
|
|
||||||
stream = myAssembly.GetManifestResourceStream("zaaReloaded2.Defaults.clinic.zaaReloaded");
|
stream = myAssembly.GetManifestResourceStream("zaaReloaded2.Defaults.clinic.zaaReloaded");
|
||||||
settings = deserializer.Deserialize(stream) as Settings;
|
settings = deserializer.Deserialize(stream) as Settings;
|
||||||
settings.Name = Properties.Settings.Default.SettingsNameClinic + BUILTIN_LABEL;
|
settings.Name = Properties.Settings.Default.SettingsNameClinic + BUILTIN_LABEL;
|
||||||
settings.Uid = Guid.Parse(DEFAULT_SETTINGS_2_UID);
|
settings.Uid = Guid.Parse(DEFAULT_SETTINGS_2_UID);
|
||||||
|
ReplaceOrAdd(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReplaceOrAdd(Settings settings)
|
||||||
|
{
|
||||||
|
Settings existing = SettingsList.FirstOrDefault(s => s.Uid == settings.Uid);
|
||||||
|
if (existing == null)
|
||||||
|
{
|
||||||
SettingsList.Add(settings);
|
SettingsList.Add(settings);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int index = SettingsList.IndexOf(existing);
|
||||||
|
SettingsList.RemoveAt(index);
|
||||||
|
SettingsList.Insert(index, settings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user