Remove Profiles.FileName and use FilePath correctly
This commit is contained in:
1 parent
af88bb2161
commit
93a415205e
5 files changed
+29
-43
No files matched your search
@@ -693,7 +693,7 @@ namespace Vocaluxe.Base
|
|||||||
|
|
||||||
foreach (CProfile profile in profiles)
|
foreach (CProfile profile in profiles)
|
||||||
{
|
{
|
||||||
if (Path.GetFileName(profile.FileName) == Config.Game.Players[j] && profile.Active == EOffOn.TR_CONFIG_ON)
|
if (Path.GetFileName(profile.FilePath) == Config.Game.Players[j] && profile.Active == EOffOn.TR_CONFIG_ON)
|
||||||
{
|
{
|
||||||
//Update Game-infos with player
|
//Update Game-infos with player
|
||||||
CGame.Players[j].ProfileID = profile.ID;
|
CGame.Players[j].ProfileID = profile.ID;
|
||||||
|
|||||||
+10
-14
@@ -327,10 +327,10 @@ namespace Vocaluxe.Base
|
|||||||
{
|
{
|
||||||
var profile = new CProfile
|
var profile = new CProfile
|
||||||
{
|
{
|
||||||
FileName = fileName != "" ? Path.Combine(CConfig.ProfileFolders[0], fileName) : String.Empty
|
FilePath = fileName != "" ? Path.Combine(CConfig.ProfileFolders[0], fileName) : String.Empty
|
||||||
};
|
};
|
||||||
|
|
||||||
if (File.Exists(profile.FileName))
|
if (File.Exists(profile.FilePath))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
profile.ID = _ProfileIDs.Dequeue();
|
profile.ID = _ProfileIDs.Dequeue();
|
||||||
@@ -393,7 +393,7 @@ namespace Vocaluxe.Base
|
|||||||
if (!IsProfileIDValid(profileID))
|
if (!IsProfileIDValid(profileID))
|
||||||
return String.Empty;
|
return String.Empty;
|
||||||
|
|
||||||
return Path.GetFileName(_Profiles[profileID].FileName);
|
return Path.GetFileName(_Profiles[profileID].FilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string AddGetPlayerName(int profileID, char chr)
|
public static string AddGetPlayerName(int profileID, char chr)
|
||||||
@@ -534,7 +534,7 @@ namespace Vocaluxe.Base
|
|||||||
foreach (int id in ids)
|
foreach (int id in ids)
|
||||||
{
|
{
|
||||||
if (_Profiles[id].LoadProfile())
|
if (_Profiles[id].LoadProfile())
|
||||||
knownFiles.Add(Path.GetFileName(_Profiles[id].FileName));
|
knownFiles.Add(Path.GetFileName(_Profiles[id].FilePath));
|
||||||
else
|
else
|
||||||
_Profiles.Remove(id);
|
_Profiles.Remove(id);
|
||||||
}
|
}
|
||||||
@@ -550,13 +550,9 @@ namespace Vocaluxe.Base
|
|||||||
if (knownFiles.Contains(Path.GetFileName(file)))
|
if (knownFiles.Contains(Path.GetFileName(file)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var profile = new CProfile
|
var profile = new CProfile();
|
||||||
{
|
|
||||||
FileName = Path.GetFileName(file),
|
|
||||||
FilePath = Path.GetDirectoryName(file)
|
|
||||||
};
|
|
||||||
|
|
||||||
if (profile.LoadProfile())
|
if (profile.LoadProfile(file))
|
||||||
{
|
{
|
||||||
profile.ID = _ProfileIDs.Dequeue();
|
profile.ID = _ProfileIDs.Dequeue();
|
||||||
_Profiles.Add(profile.ID, profile);
|
_Profiles.Add(profile.ID, profile);
|
||||||
@@ -605,7 +601,7 @@ namespace Vocaluxe.Base
|
|||||||
if (!IsProfileIDValid(profileID))
|
if (!IsProfileIDValid(profileID))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_Profiles[profileID].FileName == "")
|
if (string.IsNullOrEmpty(_Profiles[profileID].FilePath))
|
||||||
{
|
{
|
||||||
_RemoveProfile(profileID);
|
_RemoveProfile(profileID);
|
||||||
return;
|
return;
|
||||||
@@ -616,13 +612,13 @@ namespace Vocaluxe.Base
|
|||||||
//Check if profile saved in config
|
//Check if profile saved in config
|
||||||
for (int i = 0; i < CSettings.MaxNumPlayer; i++)
|
for (int i = 0; i < CSettings.MaxNumPlayer; i++)
|
||||||
{
|
{
|
||||||
if (CConfig.Config.Game.Players[i] == _Profiles[profileID].FileName)
|
if (CConfig.Config.Game.Players[i] == GetProfileFileName(profileID))
|
||||||
{
|
{
|
||||||
CConfig.Config.Game.Players[i] = string.Empty;
|
CConfig.Config.Game.Players[i] = string.Empty;
|
||||||
CConfig.SaveConfig();
|
CConfig.SaveConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File.Delete(Path.Combine(_Profiles[profileID].FilePath, _Profiles[profileID].FileName));
|
File.Delete(_Profiles[profileID].FilePath);
|
||||||
_RemoveProfile(profileID);
|
_RemoveProfile(profileID);
|
||||||
|
|
||||||
//Check if profile is selected in game
|
//Check if profile is selected in game
|
||||||
@@ -636,7 +632,7 @@ namespace Vocaluxe.Base
|
|||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
CLog.LogError("Can't delete Profile File " + _Profiles[profileID].FileName + ".xml");
|
CLog.LogError("Can't delete Profile File " + _Profiles[profileID].FilePath);
|
||||||
}
|
}
|
||||||
_ProfilesChanged = true;
|
_ProfilesChanged = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ namespace Vocaluxe.Base.Server
|
|||||||
newProfile = new CProfile
|
newProfile = new CProfile
|
||||||
{
|
{
|
||||||
ID = existingProfile.ID,
|
ID = existingProfile.ID,
|
||||||
FileName = existingProfile.FileName,
|
FilePath = existingProfile.FilePath,
|
||||||
Active = existingProfile.Active,
|
Active = existingProfile.Active,
|
||||||
Avatar = existingProfile.Avatar,
|
Avatar = existingProfile.Avatar,
|
||||||
Difficulty = existingProfile.Difficulty,
|
Difficulty = existingProfile.Difficulty,
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
using System.Xml.Serialization;
|
||||||
using VocaluxeLib.Xml;
|
using VocaluxeLib.Xml;
|
||||||
|
|
||||||
namespace VocaluxeLib.Profile
|
namespace VocaluxeLib.Profile
|
||||||
@@ -34,11 +35,10 @@ namespace VocaluxeLib.Profile
|
|||||||
|
|
||||||
public class CProfile
|
public class CProfile
|
||||||
{
|
{
|
||||||
public int ID;
|
[XmlIgnore] public int ID;
|
||||||
|
|
||||||
public string PlayerName;
|
public string PlayerName;
|
||||||
public string FilePath;
|
public string FilePath;
|
||||||
public string FileName;
|
|
||||||
public byte[] PasswordHash;
|
public byte[] PasswordHash;
|
||||||
public byte[] PasswordSalt;
|
public byte[] PasswordSalt;
|
||||||
|
|
||||||
@@ -55,28 +55,18 @@ namespace VocaluxeLib.Profile
|
|||||||
Difficulty = EGameDifficulty.TR_CONFIG_EASY;
|
Difficulty = EGameDifficulty.TR_CONFIG_EASY;
|
||||||
UserRole = EUserRole.TR_USERROLE_NORMAL;
|
UserRole = EUserRole.TR_USERROLE_NORMAL;
|
||||||
Active = EOffOn.TR_CONFIG_ON;
|
Active = EOffOn.TR_CONFIG_ON;
|
||||||
|
|
||||||
FileName = String.Empty;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool LoadProfile(string pathName, string fileName)
|
public bool LoadProfile(string filePath)
|
||||||
{
|
{
|
||||||
FilePath = pathName;
|
FilePath = filePath;
|
||||||
FileName = fileName;
|
|
||||||
return LoadProfile();
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool LoadProfile(string file)
|
|
||||||
{
|
|
||||||
FileName = Path.GetFileName(file);
|
|
||||||
FilePath = Path.GetDirectoryName(file);
|
|
||||||
|
|
||||||
return LoadProfile();
|
return LoadProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool LoadProfile()
|
public bool LoadProfile()
|
||||||
{
|
{
|
||||||
CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(FilePath, FileName));
|
CXMLReader xmlReader = CXMLReader.OpenFile(FilePath);
|
||||||
if (xmlReader == null)
|
if (xmlReader == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -98,19 +88,17 @@ namespace VocaluxeLib.Profile
|
|||||||
xmlReader.GetValue("//root/Info/PasswordSalt", out passwordSalt);
|
xmlReader.GetValue("//root/Info/PasswordSalt", out passwordSalt);
|
||||||
PasswordSalt = !string.IsNullOrEmpty(passwordSalt) ? Convert.FromBase64String(passwordSalt) : null;
|
PasswordSalt = !string.IsNullOrEmpty(passwordSalt) ? Convert.FromBase64String(passwordSalt) : null;
|
||||||
if (!ok)
|
if (!ok)
|
||||||
CBase.Log.LogError("Error loading profile file: " + FileName);
|
CBase.Log.LogError("Error loading profile file: " + FilePath);
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
CBase.Log.LogError("Can't find PlayerName in Profile File: " + FileName);
|
CBase.Log.LogError("Can't find PlayerName in Profile File: " + FilePath);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveProfile()
|
public void SaveProfile()
|
||||||
{
|
{
|
||||||
if (String.IsNullOrEmpty(FilePath))
|
if (String.IsNullOrEmpty(FilePath))
|
||||||
FilePath = Path.Combine(CBase.Settings.GetDataPath(), CBase.Settings.GetFolderProfiles());
|
|
||||||
if (FileName == String.Empty)
|
|
||||||
{
|
{
|
||||||
string filename = string.Empty;
|
string filename = string.Empty;
|
||||||
// ReSharper disable LoopCanBeConvertedToQuery
|
// ReSharper disable LoopCanBeConvertedToQuery
|
||||||
@@ -124,17 +112,17 @@ namespace VocaluxeLib.Profile
|
|||||||
if (filename == "")
|
if (filename == "")
|
||||||
filename = "1";
|
filename = "1";
|
||||||
|
|
||||||
FileName = CHelper.GetUniqueFileName(FilePath, filename + ".xml", false);
|
FilePath = Path.Combine(CBase.Settings.GetDataPath(), CBase.Settings.GetFolderProfiles(), CHelper.GetUniqueFileName(FilePath, filename + ".xml", false));
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlWriter writer;
|
XmlWriter writer;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
writer = XmlWriter.Create(Path.Combine(FilePath, FileName), CBase.Config.GetXMLSettings());
|
writer = XmlWriter.Create(FilePath, CBase.Config.GetXMLSettings());
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
CBase.Log.LogError("Error creating/opening Profile File " + FileName + ": " + e.Message);
|
CBase.Log.LogError("Error creating/opening Profile File " + FilePath + ": " + e.Message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -401,9 +401,8 @@ namespace VocaluxeLib.Xml
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private T _Deserialize<T>(XmlReader reader) where T : new()
|
private T _Deserialize<T>(XmlReader reader, object result) where T : new()
|
||||||
{
|
{
|
||||||
object result = new T();
|
|
||||||
if (reader.IsEmptyElement)
|
if (reader.IsEmptyElement)
|
||||||
return (T)result;
|
return (T)result;
|
||||||
|
|
||||||
@@ -425,7 +424,7 @@ namespace VocaluxeLib.Xml
|
|||||||
};
|
};
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return _Deserialize<T>(reader);
|
return _Deserialize<T>(reader, new T());
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -433,8 +432,11 @@ namespace VocaluxeLib.Xml
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Deserialize<T>(string filePath) where T : new()
|
public T Deserialize<T>(string filePath, object o = null) where T : new()
|
||||||
{
|
{
|
||||||
|
Debug.Assert(o == null || o.GetType() is T);
|
||||||
|
if (o == null)
|
||||||
|
o = new T();
|
||||||
var reader = new XmlTextReader(filePath)
|
var reader = new XmlTextReader(filePath)
|
||||||
{
|
{
|
||||||
WhitespaceHandling = WhitespaceHandling.Significant,
|
WhitespaceHandling = WhitespaceHandling.Significant,
|
||||||
@@ -443,7 +445,7 @@ namespace VocaluxeLib.Xml
|
|||||||
};
|
};
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return _Deserialize<T>(reader);
|
return _Deserialize<T>(reader, o);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user