fixed directory issue with preferences.
This commit is contained in:
parent
eeebff355f
commit
831c49b685
@ -1,6 +1,7 @@
|
|||||||
using RhythmBullet.Zer01HD.Utilities.Persistence;
|
using RhythmBullet.Zer01HD.Utilities.Persistence;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -12,12 +13,13 @@ namespace RhythmBullet.Zer01HD.Utilities
|
|||||||
public class PreferencesManager
|
public class PreferencesManager
|
||||||
{
|
{
|
||||||
private readonly Dictionary<Type, Preferences> preferenceList;
|
private readonly Dictionary<Type, Preferences> preferenceList;
|
||||||
public string SavePath;
|
string savePath;
|
||||||
XmlSerializer xmlSerializer;
|
XmlSerializer xmlSerializer;
|
||||||
|
|
||||||
public PreferencesManager(string savePath, params Preferences[] preferences)
|
public PreferencesManager(string savePath, params Preferences[] preferences)
|
||||||
{
|
{
|
||||||
this.SavePath = savePath;
|
this.savePath = savePath;
|
||||||
|
Directory.CreateDirectory(savePath);
|
||||||
preferenceList = new Dictionary<Type, Preferences>();
|
preferenceList = new Dictionary<Type, Preferences>();
|
||||||
|
|
||||||
Type[] preferenceTypes = new Type[preferences.Length];
|
Type[] preferenceTypes = new Type[preferences.Length];
|
||||||
@ -56,10 +58,10 @@ namespace RhythmBullet.Zer01HD.Utilities
|
|||||||
|
|
||||||
private bool LoadSpecific(Type preference)
|
private bool LoadSpecific(Type preference)
|
||||||
{
|
{
|
||||||
string path = SavePath + "/" + preference.Name;
|
string path = savePath + "/" + preference.Name;
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
{
|
{
|
||||||
Stream stream = new FileStream(SavePath + "/" + preference.Name, FileMode.Open);
|
Stream stream = new FileStream(savePath + "/" + preference.Name + ".xml", FileMode.Open);
|
||||||
preferenceList[preference] = (Preferences)xmlSerializer.Deserialize(stream);
|
preferenceList[preference] = (Preferences)xmlSerializer.Deserialize(stream);
|
||||||
stream.Close();
|
stream.Close();
|
||||||
return true;
|
return true;
|
||||||
@ -69,7 +71,7 @@ namespace RhythmBullet.Zer01HD.Utilities
|
|||||||
|
|
||||||
private void SaveSpecific(Type preference)
|
private void SaveSpecific(Type preference)
|
||||||
{
|
{
|
||||||
Stream stream = new FileStream(SavePath + preference.Name, FileMode.Create);
|
Stream stream = new FileStream(savePath + "/" + preference.Name + ".xml", FileMode.Create);
|
||||||
xmlSerializer.Serialize(stream, preferenceList[preference]);
|
xmlSerializer.Serialize(stream, preferenceList[preference]);
|
||||||
stream.Close();
|
stream.Close();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user