Beispiel #1
0
        /// <summary>
        /// Receives notification that set download progress changed
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Arguments</param>
        private void OnDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            double bytesIn    = double.Parse(e.BytesReceived.ToString());
            double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
            double percentage = bytesIn / totalBytes * 100;
            string message    = String.Format("Downloading card set {0} ({1}/{2})", MissingSets[CurrentDownloadIndex].Item1, CurrentDownloadIndex + 1, MissingSets.Count);

            MyProgressDisplay.Update(message, percentage);
        }
Beispiel #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        public static void LoadAllGames(IProgressDisplay pdc)
        {
            // Load all known deck names
            DeckNames = new Dictionary <string, string>();
            if (File.Exists(Constants.GetLocalDeckNamesFilePath()))
            {
                try
                {
                    var json = Utilities.ReadLocalFile(Constants.GetLocalDeckNamesFilePath());
                    Dictionary <string, JsonElement> deckNames = JsonSerializer.Deserialize <Dictionary <string, JsonElement> >(json);
                    DeckNames = deckNames["DeckNames"].ToObject <Dictionary <string, string> >();
                }
                catch
                {
                    if (File.Exists(Constants.GetLocalDeckNamesFilePath() + ".backup"))
                    {
                        try
                        {
                            var json = Utilities.ReadLocalFile(Constants.GetLocalDeckNamesFilePath() + ".backup");
                            Dictionary <string, JsonElement> deckNames = JsonSerializer.Deserialize <Dictionary <string, JsonElement> >(json);
                            DeckNames = deckNames["DeckNames"].ToObject <Dictionary <string, string> >();
                        }
                        catch { }
                    }
                }
            }

            // Load all games
            Games = new List <GameRecord>();
            if (Directory.Exists(Constants.GetLocalGamesPath()))
            {
                DirectoryInfo dirInfo      = new DirectoryInfo(Constants.GetLocalGamesPath());
                FileInfo[]    files        = dirInfo.GetFiles("*.txt");
                var           filesInOrder = files.OrderBy(x => x.CreationTime);
                for (int i = 0; i < filesInOrder.Count(); i++)
                {
                    filesInOrder.Count();
                    try
                    {
                        AddGameRecord(GameRecord.LoadFromFile(filesInOrder.ElementAt(i).FullName));
                    }
                    catch
                    {
                        // Skip bad records
                    }
                    pdc.Update("Loading game records...", 100.0 * (i + 1) / filesInOrder.Count());
                    //Thread.Yield();
                }
            }
        }