Ejemplo n.º 1
0
        private static void _LoadProfiles()
        {
            _LoadAvatars();

            var knownFiles = new List <string>();

            if (_Profiles.Count > 0)
            {
                var ids = new int[_Profiles.Keys.Count];
                _Profiles.Keys.CopyTo(ids, 0);
                foreach (int id in ids)
                {
                    if (_Profiles[id].LoadProfile())
                    {
                        knownFiles.Add(Path.GetFileName(_Profiles[id].FilePath));
                    }
                    else
                    {
                        _Profiles.Remove(id);
                    }
                }
            }


            var files = new List <string>();

            foreach (string path in CConfig.ProfileFolders)
            {
                files.AddRange(CHelper.ListFiles(path, "*.xml", true, true));
            }

            foreach (string file in files)
            {
                if (knownFiles.Contains(Path.GetFileName(file)))
                {
                    continue;
                }

                var profile = new CProfile();

                if (profile.LoadProfile(file))
                {
                    profile.ID = _ProfileIDs.Dequeue();
                    _Profiles.Add(profile.ID, profile);
                }
            }
            _ProfilesChanged = true;
        }
Ejemplo n.º 2
0
        private async static void _LoadProfiles()
        {
            _LoadAvatars();

            var knownFiles = new List <string>();

            if (_Profiles.Count > 0)
            {
                var ids = new Guid[_Profiles.Keys.Count];
                _Profiles.Keys.CopyTo(ids, 0);
                foreach (Guid id in ids)
                {
                    if (_Profiles[id].LoadProfile())
                    {
                        knownFiles.Add(Path.GetFileName(_Profiles[id].FilePath));
                    }
                    else
                    {
                        _Profiles.Remove(id);
                    }
                }
            }

            if (CConfig.UseCloudServer)
            {
                string json = JsonConvert.SerializeObject(new { Key = CConfig.CloudServerKey });

                var    content        = new StringContent(json, Encoding.UTF8, "application/json");
                string responseString = "";
                var    response       = await _Client.PostAsync(CConfig.CloudServerURL + "/api/getProfiles", content);

                responseString = await response.Content.ReadAsStringAsync();

                CProfile[] CloudProfiles = JsonConvert.DeserializeObject <CProfile[]>(responseString);
                Console.Write(CloudProfiles);
                foreach (CProfile profile in CloudProfiles)
                {
                    _Profiles.Add(profile.ID, profile);
                }
            }
            else
            {
                var files = new List <string>();

                foreach (string path in CConfig.ProfileFolders)
                {
                    files.AddRange(CHelper.ListFiles(path, "*.xml", true, true));
                }

                foreach (string file in files)
                {
                    if (knownFiles.Contains(Path.GetFileName(file)))
                    {
                        continue;
                    }

                    var profile = new CProfile();

                    if (profile.LoadProfile(file))
                    {
                        _Profiles.Add(profile.ID, profile);
                    }
                }
            }
            _ProfilesChanged = true;
        }