diff --git a/Source/IdleMaster/IdleMaster.csproj b/Source/IdleMaster/IdleMaster.csproj index 280db177..e2c9849c 100644 --- a/Source/IdleMaster/IdleMaster.csproj +++ b/Source/IdleMaster/IdleMaster.csproj @@ -75,6 +75,9 @@ True + + ..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll + False ..\packages\Steamworks.NET\Steamworks.NET.dll diff --git a/Source/IdleMaster/frmMain.cs b/Source/IdleMaster/frmMain.cs index a5bd8e00..18ce6911 100644 --- a/Source/IdleMaster/frmMain.cs +++ b/Source/IdleMaster/frmMain.cs @@ -14,6 +14,7 @@ using HtmlAgilityPack; using Steamworks; +using Newtonsoft.Json; namespace IdleMaster { @@ -71,6 +72,7 @@ private void CopyResource(string resourceName, string file) public void SortBadges(String method) { + lblDrops.Text = "Sorting results based on your settings, please wait..."; Dictionary tempBadgesLeft = new Dictionary(); switch (method) { @@ -93,6 +95,44 @@ orderby pair.Value ascending { tempBadgesLeft.Add(pair.Key, pair.Value); } + break; + case "mostvalue": + // Compile the list of appids that need to be idled + string appids = ""; + foreach (KeyValuePair pair in badgesLeft) + { + appids += pair.Key + ","; + } + appids = appids.Remove(appids.Length-1); + + // Query the API to retrieve the average card values of each appid + WebRequest request = WebRequest.Create("http://api.enhancedsteam.com/market_data/average_card_prices/im.php?appids=" + appids); + WebResponse response = request.GetResponse(); + Stream dataStream = response.GetResponseStream(); + StreamReader reader = new StreamReader(dataStream, Encoding.UTF8); + string json = reader.ReadToEnd(); + reader.Close(); + response.Close(); + + // Parse the response and sort it appropriately + DataSet dataSet = JsonConvert.DeserializeObject(json); + DataTable dataTable = dataSet.Tables["avg_values"]; + DataView dataView = dataTable.DefaultView; + dataView.Sort = "avg_price desc"; + DataTable sorted = dataView.ToTable(); + + foreach (DataRow row in sorted.Rows) + { + if (row["avg_price"].ToString() != "") + { + string DropsLeft = ""; + if (badgesLeft.TryGetValue(row["appid"].ToString(), out DropsLeft)) + { + tempBadgesLeft.Add(row["appid"].ToString(), DropsLeft); + } + } + } + break; default: return; diff --git a/Source/IdleMaster/frmSettings.Designer.cs b/Source/IdleMaster/frmSettings.Designer.cs index 3636c1cb..55dbffec 100644 --- a/Source/IdleMaster/frmSettings.Designer.cs +++ b/Source/IdleMaster/frmSettings.Designer.cs @@ -32,6 +32,7 @@ private void InitializeComponent() this.groupBox1 = new System.Windows.Forms.GroupBox(); this.chkMinToTray = new System.Windows.Forms.CheckBox(); this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.radIdleMostValue = new System.Windows.Forms.RadioButton(); this.radIdleLeastDrops = new System.Windows.Forms.RadioButton(); this.radIdleMostDrops = new System.Windows.Forms.RadioButton(); this.radIdleDefault = new System.Windows.Forms.RadioButton(); @@ -63,20 +64,32 @@ private void InitializeComponent() // // groupBox2 // + this.groupBox2.Controls.Add(this.radIdleMostValue); this.groupBox2.Controls.Add(this.radIdleLeastDrops); this.groupBox2.Controls.Add(this.radIdleMostDrops); this.groupBox2.Controls.Add(this.radIdleDefault); this.groupBox2.Location = new System.Drawing.Point(13, 70); this.groupBox2.Name = "groupBox2"; - this.groupBox2.Size = new System.Drawing.Size(322, 84); + this.groupBox2.Size = new System.Drawing.Size(322, 92); this.groupBox2.TabIndex = 1; this.groupBox2.TabStop = false; this.groupBox2.Text = "Idling Order"; // + // radIdleMostValue + // + this.radIdleMostValue.AutoSize = true; + this.radIdleMostValue.Location = new System.Drawing.Point(7, 35); + this.radIdleMostValue.Name = "radIdleMostValue"; + this.radIdleMostValue.Size = new System.Drawing.Size(233, 17); + this.radIdleMostValue.TabIndex = 3; + this.radIdleMostValue.TabStop = true; + this.radIdleMostValue.Text = "Prioritize games with the highest card values"; + this.radIdleMostValue.UseVisualStyleBackColor = true; + // // radIdleLeastDrops // this.radIdleLeastDrops.AutoSize = true; - this.radIdleLeastDrops.Location = new System.Drawing.Point(7, 56); + this.radIdleLeastDrops.Location = new System.Drawing.Point(7, 69); this.radIdleLeastDrops.Name = "radIdleLeastDrops"; this.radIdleLeastDrops.Size = new System.Drawing.Size(295, 17); this.radIdleLeastDrops.TabIndex = 2; @@ -86,7 +99,7 @@ private void InitializeComponent() // radIdleMostDrops // this.radIdleMostDrops.AutoSize = true; - this.radIdleMostDrops.Location = new System.Drawing.Point(7, 38); + this.radIdleMostDrops.Location = new System.Drawing.Point(7, 52); this.radIdleMostDrops.Name = "radIdleMostDrops"; this.radIdleMostDrops.Size = new System.Drawing.Size(299, 17); this.radIdleMostDrops.TabIndex = 1; @@ -97,7 +110,7 @@ private void InitializeComponent() // this.radIdleDefault.AutoSize = true; this.radIdleDefault.Checked = true; - this.radIdleDefault.Location = new System.Drawing.Point(7, 20); + this.radIdleDefault.Location = new System.Drawing.Point(7, 18); this.radIdleDefault.Name = "radIdleDefault"; this.radIdleDefault.Size = new System.Drawing.Size(155, 17); this.radIdleDefault.TabIndex = 0; @@ -109,7 +122,7 @@ private void InitializeComponent() // this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.btnCancel.Location = new System.Drawing.Point(260, 160); + this.btnCancel.Location = new System.Drawing.Point(261, 167); this.btnCancel.Name = "btnCancel"; this.btnCancel.Size = new System.Drawing.Size(75, 23); this.btnCancel.TabIndex = 2; @@ -120,7 +133,7 @@ private void InitializeComponent() // btnOK // this.btnOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.btnOK.Location = new System.Drawing.Point(179, 160); + this.btnOK.Location = new System.Drawing.Point(180, 167); this.btnOK.Name = "btnOK"; this.btnOK.Size = new System.Drawing.Size(75, 23); this.btnOK.TabIndex = 3; @@ -134,7 +147,7 @@ private void InitializeComponent() this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.btnCancel; - this.ClientSize = new System.Drawing.Size(347, 195); + this.ClientSize = new System.Drawing.Size(348, 202); this.Controls.Add(this.btnOK); this.Controls.Add(this.btnCancel); this.Controls.Add(this.groupBox2); @@ -164,5 +177,6 @@ private void InitializeComponent() private System.Windows.Forms.RadioButton radIdleDefault; private System.Windows.Forms.Button btnCancel; private System.Windows.Forms.Button btnOK; + private System.Windows.Forms.RadioButton radIdleMostValue; } } \ No newline at end of file diff --git a/Source/IdleMaster/frmSettings.cs b/Source/IdleMaster/frmSettings.cs index 3cff90f4..668d6dd5 100644 --- a/Source/IdleMaster/frmSettings.cs +++ b/Source/IdleMaster/frmSettings.cs @@ -36,6 +36,10 @@ private void btnOK_Click(object sender, EventArgs e) { Properties.Settings.Default.sort = "mostcards"; } + if (radIdleMostValue.Checked == true) + { + Properties.Settings.Default.sort = "mostvalue"; + } if (chkMinToTray.Checked == true) { @@ -60,6 +64,9 @@ private void frmSettings_Load(object sender, EventArgs e) case "mostcards": radIdleMostDrops.Checked = true; break; + case "mostvalue": + radIdleMostValue.Checked = true; + break; default: break; } diff --git a/Source/IdleMaster/packages.config b/Source/IdleMaster/packages.config index 87c301a6..228ff0d6 100644 --- a/Source/IdleMaster/packages.config +++ b/Source/IdleMaster/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file