Ejemplo n.º 1
0
        public static int NewProfile(string FileName)
        {
            SProfile profile = new SProfile();

            profile.PlayerName   = String.Empty;
            profile.Difficulty   = EGameDifficulty.TR_CONFIG_EASY;
            profile.Avatar       = new SAvatar(-1);
            profile.GuestProfile = EOffOn.TR_CONFIG_OFF;
            profile.Active       = EOffOn.TR_CONFIG_ON;

            if (FileName != String.Empty)
            {
                profile.ProfileFile = Path.Combine(CSettings.sFolderProfiles, FileName);
            }
            else
            {
                profile.ProfileFile = String.Empty;
            }

            if (File.Exists(profile.ProfileFile))
            {
                return(-1);
            }

            _Profiles.Add(profile);
            return(_Profiles.Count - 1);
        }
Ejemplo n.º 2
0
        public static void SetActive(int ProfileNr, EOffOn Option)
        {
            if (ProfileNr < 0 || ProfileNr >= _Profiles.Count)
            {
                return;
            }
            SProfile profile = _Profiles[ProfileNr];

            profile.Active       = Option;
            _Profiles[ProfileNr] = profile;
        }
Ejemplo n.º 3
0
        public static void SetAvatar(int ProfileNr, int AvatarNr)
        {
            if (ProfileNr < 0 || ProfileNr >= _Profiles.Count || AvatarNr < 0 || AvatarNr >= _Avatars.Count)
            {
                return;
            }

            SProfile profile = _Profiles[ProfileNr];

            profile.Avatar       = _Avatars[AvatarNr];
            _Profiles[ProfileNr] = profile;
        }
Ejemplo n.º 4
0
        public static void SetDifficulty(int ProfileNr, EGameDifficulty Difficulty)
        {
            if (ProfileNr < 0 || ProfileNr >= _Profiles.Count)
            {
                return;
            }

            SProfile profile = _Profiles[ProfileNr];

            profile.Difficulty   = Difficulty;
            _Profiles[ProfileNr] = profile;
        }
Ejemplo n.º 5
0
        public static string AddGetPlayerName(int ProfileNr, char Chr)
        {
            if (ProfileNr < 0 || ProfileNr >= _Profiles.Count)
            {
                return(String.Empty);
            }

            SProfile profile = _Profiles[ProfileNr];

            profile.PlayerName  += Chr;
            _Profiles[ProfileNr] = profile;

            return(profile.PlayerName);
        }
Ejemplo n.º 6
0
        public static string GetDeleteCharInPlayerName(int ProfileNr)
        {
            if (ProfileNr < 0 || ProfileNr >= _Profiles.Count)
            {
                return(String.Empty);
            }

            SProfile profile = _Profiles[ProfileNr];

            if (profile.PlayerName.Length > 0)
            {
                profile.PlayerName = profile.PlayerName.Remove(profile.PlayerName.Length - 1);
            }
            _Profiles[ProfileNr] = profile;

            return(profile.PlayerName);
        }
Ejemplo n.º 7
0
        public static int NewProfile(string FileName)
        {
            SProfile profile = new SProfile();

            profile.PlayerName = String.Empty;
            profile.Difficulty = EGameDifficulty.TR_CONFIG_EASY;
            profile.Avatar = new SAvatar(-1);
            profile.GuestProfile = EOffOn.TR_CONFIG_OFF;
            profile.Active = EOffOn.TR_CONFIG_ON;
            
            if (FileName != String.Empty)
                profile.ProfileFile = Path.Combine(CSettings.sFolderProfiles, FileName);
            else
                profile.ProfileFile = String.Empty;

            if (File.Exists(profile.ProfileFile))
                return -1;
            
            _Profiles.Add(profile);
            return _Profiles.Count - 1;
        }
Ejemplo n.º 8
0
        private static void LoadProfile(string FileName)
        {
            bool loaded = false;
            XPathDocument xPathDoc = null;
            XPathNavigator navigator = null;

            SProfile profile = new SProfile();
            profile.ProfileFile = Path.Combine(CSettings.sFolderProfiles, FileName);

            try
            {
                xPathDoc = new XPathDocument(profile.ProfileFile);
                navigator = xPathDoc.CreateNavigator();
                loaded = true;
            }
            catch (Exception e)
            {
                loaded = false;
                if (navigator != null)
                    navigator = null;

                if (xPathDoc != null)
                    xPathDoc = null;

                CLog.LogError("Error opening Profile File " + FileName + ": " + e.Message);
            }

            if (loaded)
            {
                string value = String.Empty;
                if (CHelper.GetValueFromXML("//root/Info/PlayerName", navigator, ref value, value))
                {
                    profile.PlayerName = value;

                    profile.Difficulty = EGameDifficulty.TR_CONFIG_EASY;
                    CHelper.TryGetEnumValueFromXML<EGameDifficulty>("//root/Info/Difficulty", navigator, ref profile.Difficulty);

                    profile.Avatar = new SAvatar(-1);
                    if (CHelper.GetValueFromXML("//root/Info/Avatar", navigator, ref value, value))
                    {
                        profile.Avatar = GetAvatar(value);
                    }

                    profile.GuestProfile = EOffOn.TR_CONFIG_OFF;
                    CHelper.TryGetEnumValueFromXML<EOffOn>("//root/Info/GuestProfile", navigator, ref profile.GuestProfile);

                    profile.Active = EOffOn.TR_CONFIG_ON;
                    CHelper.TryGetEnumValueFromXML<EOffOn>("//root/Info/Active", navigator, ref profile.Active);

                    _Profiles.Add(profile);
                }
                else
                {
                    CLog.LogError("Can't find PlayerName in Profile File: " + FileName);
                }
            }
        }
Ejemplo n.º 9
0
 private static int CompareByPlayerName(SProfile a, SProfile b)
 {
     return String.Compare(a.PlayerName, b.PlayerName);
 }
Ejemplo n.º 10
0
        private static void LoadProfile(string FileName)
        {
            bool           loaded    = false;
            XPathDocument  xPathDoc  = null;
            XPathNavigator navigator = null;

            SProfile profile = new SProfile();

            profile.ProfileFile = Path.Combine(CSettings.sFolderProfiles, FileName);

            try
            {
                xPathDoc  = new XPathDocument(profile.ProfileFile);
                navigator = xPathDoc.CreateNavigator();
                loaded    = true;
            }
            catch (Exception e)
            {
                loaded = false;
                if (navigator != null)
                {
                    navigator = null;
                }

                if (xPathDoc != null)
                {
                    xPathDoc = null;
                }

                CLog.LogError("Error opening Profile File " + FileName + ": " + e.Message);
            }

            if (loaded)
            {
                string value = String.Empty;
                if (CHelper.GetValueFromXML("//root/Info/PlayerName", navigator, ref value, value))
                {
                    profile.PlayerName = value;

                    profile.Difficulty = EGameDifficulty.TR_CONFIG_EASY;
                    CHelper.TryGetEnumValueFromXML <EGameDifficulty>("//root/Info/Difficulty", navigator, ref profile.Difficulty);

                    profile.Avatar = new SAvatar(-1);
                    if (CHelper.GetValueFromXML("//root/Info/Avatar", navigator, ref value, value))
                    {
                        profile.Avatar = GetAvatar(value);
                    }

                    profile.GuestProfile = EOffOn.TR_CONFIG_OFF;
                    CHelper.TryGetEnumValueFromXML <EOffOn>("//root/Info/GuestProfile", navigator, ref profile.GuestProfile);

                    profile.Active = EOffOn.TR_CONFIG_ON;
                    CHelper.TryGetEnumValueFromXML <EOffOn>("//root/Info/Active", navigator, ref profile.Active);

                    _Profiles.Add(profile);
                }
                else
                {
                    CLog.LogError("Can't find PlayerName in Profile File: " + FileName);
                }
            }
        }
Ejemplo n.º 11
0
        private static void SaveProfile(int ProfileID)
        {
            if (ProfileID < 0 || ProfileID >= _Profiles.Count)
            {
                return;
            }

            if (_Profiles[ProfileID].ProfileFile == String.Empty)
            {
                string filename = string.Empty;
                foreach (char chr in _Profiles[ProfileID].PlayerName)
                {
                    if (char.IsLetter(chr))
                    {
                        filename += chr.ToString();
                    }
                }

                if (filename == String.Empty)
                {
                    filename = "1";
                }

                int i = 0;
                while (File.Exists(Path.Combine(CSettings.sFolderProfiles, filename + ".xml")))
                {
                    i++;
                    if (!File.Exists(Path.Combine(CSettings.sFolderProfiles, filename + i + ".xml")))
                    {
                        filename += i;
                    }
                }

                SProfile profile = _Profiles[ProfileID];
                profile.ProfileFile  = Path.Combine(CSettings.sFolderProfiles, filename + ".xml");
                _Profiles[ProfileID] = profile;
            }

            XmlWriter writer;

            try
            {
                writer = XmlWriter.Create(_Profiles[ProfileID].ProfileFile, _settings);
            }
            catch (Exception e)
            {
                CLog.LogError("Error creating/opening Profile File " + _Profiles[ProfileID].ProfileFile + ": " + e.Message);
                return;
            }

            if (writer == null)
            {
                CLog.LogError("Error creating/opening Profile File " + _Profiles[ProfileID].ProfileFile);
                return;
            }

            writer.WriteStartDocument();
            writer.WriteStartElement("root");

            writer.WriteStartElement("Info");
            writer.WriteElementString("PlayerName", _Profiles[ProfileID].PlayerName);
            writer.WriteElementString("Difficulty", Enum.GetName(typeof(EGameDifficulty), _Profiles[ProfileID].Difficulty));
            writer.WriteElementString("Avatar", _Profiles[ProfileID].Avatar.FileName);
            writer.WriteElementString("GuestProfile", Enum.GetName(typeof(EOffOn), _Profiles[ProfileID].GuestProfile));
            writer.WriteElementString("Active", Enum.GetName(typeof(EOffOn), _Profiles[ProfileID].Active));
            writer.WriteEndElement();

            writer.WriteEndElement(); //end of root
            writer.WriteEndDocument();

            writer.Flush();
            writer.Close();
        }
Ejemplo n.º 12
0
 private static int CompareByPlayerName(SProfile a, SProfile b)
 {
     return(String.Compare(a.PlayerName, b.PlayerName));
 }