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)
|
||||
{
|
||||
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
|
||||
CGame.Players[j].ProfileID = profile.ID;
|
||||
|
||||
+10
-14
@@ -327,10 +327,10 @@ namespace Vocaluxe.Base
|
||||
{
|
||||
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;
|
||||
|
||||
profile.ID = _ProfileIDs.Dequeue();
|
||||
@@ -393,7 +393,7 @@ namespace Vocaluxe.Base
|
||||
if (!IsProfileIDValid(profileID))
|
||||
return String.Empty;
|
||||
|
||||
return Path.GetFileName(_Profiles[profileID].FileName);
|
||||
return Path.GetFileName(_Profiles[profileID].FilePath);
|
||||
}
|
||||
|
||||
public static string AddGetPlayerName(int profileID, char chr)
|
||||
@@ -534,7 +534,7 @@ namespace Vocaluxe.Base
|
||||
foreach (int id in ids)
|
||||
{
|
||||
if (_Profiles[id].LoadProfile())
|
||||
knownFiles.Add(Path.GetFileName(_Profiles[id].FileName));
|
||||
knownFiles.Add(Path.GetFileName(_Profiles[id].FilePath));
|
||||
else
|
||||
_Profiles.Remove(id);
|
||||
}
|
||||
@@ -550,13 +550,9 @@ namespace Vocaluxe.Base
|
||||
if (knownFiles.Contains(Path.GetFileName(file)))
|
||||
continue;
|
||||
|
||||
var profile = new CProfile
|
||||
{
|
||||
FileName = Path.GetFileName(file),
|
||||
FilePath = Path.GetDirectoryName(file)
|
||||
};
|
||||
var profile = new CProfile();
|
||||
|
||||
if (profile.LoadProfile())
|
||||
if (profile.LoadProfile(file))
|
||||
{
|
||||
profile.ID = _ProfileIDs.Dequeue();
|
||||
_Profiles.Add(profile.ID, profile);
|
||||
@@ -605,7 +601,7 @@ namespace Vocaluxe.Base
|
||||
if (!IsProfileIDValid(profileID))
|
||||
return;
|
||||
|
||||
if (_Profiles[profileID].FileName == "")
|
||||
if (string.IsNullOrEmpty(_Profiles[profileID].FilePath))
|
||||
{
|
||||
_RemoveProfile(profileID);
|
||||
return;
|
||||
@@ -616,13 +612,13 @@ namespace Vocaluxe.Base
|
||||
//Check if profile saved in config
|
||||
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.SaveConfig();
|
||||
}
|
||||
}
|
||||
File.Delete(Path.Combine(_Profiles[profileID].FilePath, _Profiles[profileID].FileName));
|
||||
File.Delete(_Profiles[profileID].FilePath);
|
||||
_RemoveProfile(profileID);
|
||||
|
||||
//Check if profile is selected in game
|
||||
@@ -636,7 +632,7 @@ namespace Vocaluxe.Base
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ namespace Vocaluxe.Base.Server
|
||||
newProfile = new CProfile
|
||||
{
|
||||
ID = existingProfile.ID,
|
||||
FileName = existingProfile.FileName,
|
||||
FilePath = existingProfile.FilePath,
|
||||
Active = existingProfile.Active,
|
||||
Avatar = existingProfile.Avatar,
|
||||
Difficulty = existingProfile.Difficulty,
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using VocaluxeLib.Xml;
|
||||
|
||||
namespace VocaluxeLib.Profile
|
||||
@@ -34,11 +35,10 @@ namespace VocaluxeLib.Profile
|
||||
|
||||
public class CProfile
|
||||
{
|
||||
public int ID;
|
||||
[XmlIgnore] public int ID;
|
||||
|
||||
public string PlayerName;
|
||||
public string FilePath;
|
||||
public string FileName;
|
||||
public byte[] PasswordHash;
|
||||
public byte[] PasswordSalt;
|
||||
|
||||
@@ -55,28 +55,18 @@ namespace VocaluxeLib.Profile
|
||||
Difficulty = EGameDifficulty.TR_CONFIG_EASY;
|
||||
UserRole = EUserRole.TR_USERROLE_NORMAL;
|
||||
Active = EOffOn.TR_CONFIG_ON;
|
||||
|
||||
FileName = String.Empty;
|
||||
}
|
||||
|
||||
public bool LoadProfile(string pathName, string fileName)
|
||||
public bool LoadProfile(string filePath)
|
||||
{
|
||||
FilePath = pathName;
|
||||
FileName = fileName;
|
||||
return LoadProfile();
|
||||
}
|
||||
|
||||
public bool LoadProfile(string file)
|
||||
{
|
||||
FileName = Path.GetFileName(file);
|
||||
FilePath = Path.GetDirectoryName(file);
|
||||
FilePath = filePath;
|
||||
|
||||
return LoadProfile();
|
||||
}
|
||||
|
||||
public bool LoadProfile()
|
||||
{
|
||||
CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(FilePath, FileName));
|
||||
CXMLReader xmlReader = CXMLReader.OpenFile(FilePath);
|
||||
if (xmlReader == null)
|
||||
return false;
|
||||
|
||||
@@ -98,19 +88,17 @@ namespace VocaluxeLib.Profile
|
||||
xmlReader.GetValue("//root/Info/PasswordSalt", out passwordSalt);
|
||||
PasswordSalt = !string.IsNullOrEmpty(passwordSalt) ? Convert.FromBase64String(passwordSalt) : null;
|
||||
if (!ok)
|
||||
CBase.Log.LogError("Error loading profile file: " + FileName);
|
||||
CBase.Log.LogError("Error loading profile file: " + FilePath);
|
||||
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;
|
||||
}
|
||||
|
||||
public void SaveProfile()
|
||||
{
|
||||
if (String.IsNullOrEmpty(FilePath))
|
||||
FilePath = Path.Combine(CBase.Settings.GetDataPath(), CBase.Settings.GetFolderProfiles());
|
||||
if (FileName == String.Empty)
|
||||
{
|
||||
string filename = string.Empty;
|
||||
// ReSharper disable LoopCanBeConvertedToQuery
|
||||
@@ -124,17 +112,17 @@ namespace VocaluxeLib.Profile
|
||||
if (filename == "")
|
||||
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;
|
||||
try
|
||||
{
|
||||
writer = XmlWriter.Create(Path.Combine(FilePath, FileName), CBase.Config.GetXMLSettings());
|
||||
writer = XmlWriter.Create(FilePath, CBase.Config.GetXMLSettings());
|
||||
}
|
||||
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;
|
||||
}
|
||||
try
|
||||
|
||||
@@ -401,9 +401,8 @@ namespace VocaluxeLib.Xml
|
||||
}
|
||||
#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)
|
||||
return (T)result;
|
||||
|
||||
@@ -425,7 +424,7 @@ namespace VocaluxeLib.Xml
|
||||
};
|
||||
try
|
||||
{
|
||||
return _Deserialize<T>(reader);
|
||||
return _Deserialize<T>(reader, new T());
|
||||
}
|
||||
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)
|
||||
{
|
||||
WhitespaceHandling = WhitespaceHandling.Significant,
|
||||
@@ -443,7 +445,7 @@ namespace VocaluxeLib.Xml
|
||||
};
|
||||
try
|
||||
{
|
||||
return _Deserialize<T>(reader);
|
||||
return _Deserialize<T>(reader, o);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user