private void bwFetcher_DoWork(object sender, DoWorkEventArgs e) { ProgressReport pr = new ProgressReport(); pr.type = "taskstart"; pr.status = "Connecting to Steam API..."; bwFetcher.ReportProgress(0, pr); List<SteamFriend> friends = new List<SteamFriend>(); List<SteamUserTile> controls = new List<SteamUserTile>(); using (dynamic steamUser = WebAPI.GetInterface("ISteamUser", "D0EEFB98C8993BA3AC91A55879D28D91")) { steamUser.Timeout = (int)TimeSpan.FromSeconds(20).TotalMilliseconds; KeyValue results = steamUser.GetFriendList(steamid: _steamid, method: WebRequestMethods.Http.Get, secure: true); pr.status = "Fetching friends..."; bwFetcher.ReportProgress(0, pr); foreach (var f in results.Children[0].Children) { SteamFriend friend = new SteamFriend(); friend.steamid = f.Children[0].Value; friend.relationship = f.Children[1].Value; friend.friend_since = f.Children[2].Value; friends.Add(friend); } pr.type = "friendscount"; pr.value = friends.Count; bwFetcher.ReportProgress(0, pr); string ssteamids = ""; int count = 0; int handled = 0; int batchdone = 0; do { ssteamids += friends[count].steamid; count++; handled++; if (handled == 100 || count == friends.Count) { //Get user info steamUser.Timeout = (int)TimeSpan.FromSeconds(20).TotalMilliseconds; KeyValue result = steamUser.GetPlayerSummaries(steamids: ssteamids, MethodAccessException: WebRequestMethods.Http.Get, secure: true); for (int k = 0; k < handled; k++) { int index = (100 * batchdone) + k; friends[index].name = FetchKeyValue(result.Children[0].Children[0].Children[k], "personaname"); friends[index].profileurl = FetchKeyValue(result.Children[0].Children[0].Children[k], "profileurl"); friends[index].avatar = FetchKeyValue(result.Children[0].Children[0].Children[k], "avatarmedium"); } handled = 0; ssteamids = ""; batchdone++; } else { ssteamids += ","; } bwFetcher.ReportProgress(count, pr); } while (count < friends.Count); //Creating user tiles int num = 0; pr.type = "taskstart"; pr.status = "Creating tiles...."; bwFetcher.ReportProgress(0, pr); pr.type = "friendscount"; pr.value = friends.Count; bwFetcher.ReportProgress(0, pr); foreach (var friend in friends) { SteamUserTile tile = new SteamUserTile(); tile.SteamName = friend.name; tile.SteamProfile = friend.profileurl; tile.Avatar = friend.avatar; tile.Top = 5 + (85 * num); controls.Add(tile); num++; bwFetcher.ReportProgress(num, pr); } this.Friends = friends; this.Tiles = controls; } }
private void btnOk_Click(object sender, EventArgs e) { panelFriends.Controls.Clear(); panelNewFriends.Controls.Clear(); string mode = "new"; Configuration oldconfig = new Configuration(); if (File.Exists(txtSteamID.Text + ".json")) { FileStream fs = new FileStream(txtSteamID.Text + ".json", FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs); string json = sr.ReadToEnd(); sr.Close(); fs.Close(); oldconfig = JsonConvert.DeserializeObject<Configuration>(json); if (MetroMessageBox.Show(this, "Your friend list has been found. Would you like to use it and see who deleted you? (Date : " + oldconfig.datetime.Date + " )", "A friend list has been found", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { mode = "compare"; lblFriendsList1.Text = "Saved Friend List"; lblFriendsList2.Text = "Current friend list"; } else { if(MetroMessageBox.Show(this, "Would you like to load this friend list and replace the old one?", "Replace",MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes) { mode = "new"; lblFriendsList1.Text = "Current friend list"; } else { mode = "cancel"; } } } if(mode == "new" || mode == "compare") { frmFetch frm = new frmFetch(txtSteamID.Text); frm.ShowDialog(); friends = frm.Friends; if(mode == "new") { foreach (var c in frm.Tiles) { panelFriends.Controls.Add((SteamUserTile)c); } //Saving the friends list if (MetroMessageBox.Show(this, "Would you like to save your current friend list?", "Save", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Configuration config = new Configuration(); config.datetime = DateTime.Now; config.friends = friends; string json = JsonConvert.SerializeObject(config); FileStream fs = new FileStream(txtSteamID.Text + ".json", FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.Write(json); sw.Close(); fs.Close(); MetroMessageBox.Show(this, "Your friend list has been saved. Launch this program again to see who deleted you!", "Saved", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); } } else if(mode == "compare") { //Loading old friends if(oldconfig.friends != null) { int num = 0; foreach (var f in oldconfig.friends) { SteamUserTile tile = new SteamUserTile(); tile.SteamName = f.name; tile.SteamProfile = f.profileurl; tile.Avatar = f.avatar; tile.Top = 5 + (85 * num); panelFriends.Controls.Add(tile); num++; } } //Loading new friends foreach (var c in frm.Tiles) { panelNewFriends.Controls.Add((SteamUserTile)c); } // Start compare } } else if (mode == "cancel") { } }