Clean up

Brian [2016-08-12 01:57:00]
Clean up
Filename
src/RocketBotGUI/DeviceForm.cs
src/RocketBotGUI/DeviceHelper.cs
src/RocketBotGUI/ItemBox.cs
src/RocketBotGUI/MainForm.cs
src/RocketBotGUI/PokemonObject.cs
src/RocketBotGUI/Settings.cs
diff --git a/src/RocketBotGUI/DeviceForm.cs b/src/RocketBotGUI/DeviceForm.cs
index d69257c..51b8e5c 100644
--- a/src/RocketBotGUI/DeviceForm.cs
+++ b/src/RocketBotGUI/DeviceForm.cs
@@ -7,9 +7,10 @@ namespace PokemonGo.RocketAPI.Window
 {
     public partial class DeviceForm : Form
     {
-        private List<DeviceInfo> _deviceInfos;
         private DeviceHelper _deviceHelper;
-        private bool _doNotPopulate = false;
+        private List<DeviceInfo> _deviceInfos;
+        private bool _doNotPopulate;
+
         public DeviceForm()
         {
             InitializeComponent();
@@ -26,21 +27,21 @@ namespace PokemonGo.RocketAPI.Window
             }
             else
             {
-                this.DeviceIdTb.Text = Settings.Instance.DeviceId;
-                this.AndroidBoardNameTb.Text = Settings.Instance.AndroidBoardName;
-                this.AndroidBootloaderTb.Text = Settings.Instance.AndroidBootloader;
-                this.DeviceBrandTb.Text = Settings.Instance.DeviceBrand;
-                this.DeviceModelTb.Text = Settings.Instance.DeviceModel;
-                this.DeviceModelIdentifierTb.Text = Settings.Instance.DeviceModelIdentifier;
-                this.DeviceModelBootTb.Text = Settings.Instance.DeviceModelBoot;
-                this.HardwareManufacturerTb.Text = Settings.Instance.HardwareManufacturer;
-                this.HardwareModelTb.Text = Settings.Instance.HardwareModel;
-                this.FirmwareBrandTb.Text = Settings.Instance.FirmwareBrand;
-                this.FirmwareTagsTb.Text = Settings.Instance.FirmwareTags;
-                this.FirmwareTypeTb.Text = Settings.Instance.FirmwareType;
-                this.FirmwareFingerprintTb.Text = Settings.Instance.FirmwareFingerprint;
+                DeviceIdTb.Text = Settings.Instance.DeviceId;
+                AndroidBoardNameTb.Text = Settings.Instance.AndroidBoardName;
+                AndroidBootloaderTb.Text = Settings.Instance.AndroidBootloader;
+                DeviceBrandTb.Text = Settings.Instance.DeviceBrand;
+                DeviceModelTb.Text = Settings.Instance.DeviceModel;
+                DeviceModelIdentifierTb.Text = Settings.Instance.DeviceModelIdentifier;
+                DeviceModelBootTb.Text = Settings.Instance.DeviceModelBoot;
+                HardwareManufacturerTb.Text = Settings.Instance.HardwareManufacturer;
+                HardwareModelTb.Text = Settings.Instance.HardwareModel;
+                FirmwareBrandTb.Text = Settings.Instance.FirmwareBrand;
+                FirmwareTagsTb.Text = Settings.Instance.FirmwareTags;
+                FirmwareTypeTb.Text = Settings.Instance.FirmwareType;
+                FirmwareFingerprintTb.Text = Settings.Instance.FirmwareFingerprint;
                 _doNotPopulate = true;
-                this.deviceTypeCb.SelectedIndex = Settings.Instance.DeviceBrand.ToLower() == "apple" ? 0 : 1;
+                deviceTypeCb.SelectedIndex = Settings.Instance.DeviceBrand.ToLower() == "apple" ? 0 : 1;
                 _doNotPopulate = false;
             }
         }
@@ -52,7 +53,7 @@ namespace PokemonGo.RocketAPI.Window

         private void SaveBtn_Click(object sender, EventArgs e)
         {
-            if (this.DeviceIdTb.Text == "8525f6d8251f71b7")
+            if (DeviceIdTb.Text == "8525f6d8251f71b7")
             {
                 PopulateDevice();
             }
@@ -60,7 +61,7 @@ namespace PokemonGo.RocketAPI.Window
             {
                 SaveToSetting();
             }
-            this.Close();
+            Close();
         }

         private void deviceTypeCb_SelectedIndexChanged(object sender, EventArgs e)
@@ -70,7 +71,7 @@ namespace PokemonGo.RocketAPI.Window

         private void RandomIDBtn_Click(object sender, EventArgs e)
         {
-            this.DeviceIdTb.Text = _deviceHelper.RandomString(16, "0123456789abcdef");
+            DeviceIdTb.Text = _deviceHelper.RandomString(16, "0123456789abcdef");
         }

         private void PopulateDevice()
@@ -79,40 +80,44 @@ namespace PokemonGo.RocketAPI.Window
             {
                 return;
             }
-            var candidateDevices = deviceTypeCb.SelectedIndex == 0 ? _deviceInfos.Where(d => d.DeviceBrand.ToLower() == "apple").ToList() : _deviceInfos.Where(d => d.DeviceBrand.ToLower() != "apple").ToList();
-            int selectIndex = _deviceHelper.GetRandomIndex(candidateDevices.Count);
+            var candidateDevices = deviceTypeCb.SelectedIndex == 0
+                ? _deviceInfos.Where(d => d.DeviceBrand.ToLower() == "apple").ToList()
+                : _deviceInfos.Where(d => d.DeviceBrand.ToLower() != "apple").ToList();
+            var selectIndex = _deviceHelper.GetRandomIndex(candidateDevices.Count);

-            this.DeviceIdTb.Text = _deviceInfos[selectIndex].DeviceId == "8525f6d8251f71b7" ? _deviceHelper.RandomString(16, "0123456789abcdef") : _deviceInfos[selectIndex].DeviceId;
-            this.AndroidBoardNameTb.Text = _deviceInfos[selectIndex].AndroidBoardName;
-            this.AndroidBootloaderTb.Text = _deviceInfos[selectIndex].AndroidBootloader;
-            this.DeviceBrandTb.Text = _deviceInfos[selectIndex].DeviceBrand;
-            this.DeviceModelTb.Text = _deviceInfos[selectIndex].DeviceModel;
-            this.DeviceModelIdentifierTb.Text = _deviceInfos[selectIndex].DeviceModelIdentifier;
-            this.DeviceModelBootTb.Text = _deviceInfos[selectIndex].DeviceModelBoot;
-            this.HardwareManufacturerTb.Text = _deviceInfos[selectIndex].HardwareManufacturer;
-            this.HardwareModelTb.Text = _deviceInfos[selectIndex].HardwareModel;
-            this.FirmwareBrandTb.Text = _deviceInfos[selectIndex].FirmwareBrand;
-            this.FirmwareTagsTb.Text = _deviceInfos[selectIndex].FirmwareTags;
-            this.FirmwareTypeTb.Text = _deviceInfos[selectIndex].FirmwareType;
-            this.FirmwareFingerprintTb.Text = _deviceInfos[selectIndex].FirmwareFingerprint;
+            DeviceIdTb.Text = _deviceInfos[selectIndex].DeviceId == "8525f6d8251f71b7"
+                ? _deviceHelper.RandomString(16, "0123456789abcdef")
+                : _deviceInfos[selectIndex].DeviceId;
+            AndroidBoardNameTb.Text = _deviceInfos[selectIndex].AndroidBoardName;
+            AndroidBootloaderTb.Text = _deviceInfos[selectIndex].AndroidBootloader;
+            DeviceBrandTb.Text = _deviceInfos[selectIndex].DeviceBrand;
+            DeviceModelTb.Text = _deviceInfos[selectIndex].DeviceModel;
+            DeviceModelIdentifierTb.Text = _deviceInfos[selectIndex].DeviceModelIdentifier;
+            DeviceModelBootTb.Text = _deviceInfos[selectIndex].DeviceModelBoot;
+            HardwareManufacturerTb.Text = _deviceInfos[selectIndex].HardwareManufacturer;
+            HardwareModelTb.Text = _deviceInfos[selectIndex].HardwareModel;
+            FirmwareBrandTb.Text = _deviceInfos[selectIndex].FirmwareBrand;
+            FirmwareTagsTb.Text = _deviceInfos[selectIndex].FirmwareTags;
+            FirmwareTypeTb.Text = _deviceInfos[selectIndex].FirmwareType;
+            FirmwareFingerprintTb.Text = _deviceInfos[selectIndex].FirmwareFingerprint;
             SaveToSetting();
         }

         private void SaveToSetting()
         {
-            Settings.Instance.DeviceId = this.DeviceIdTb.Text;
-            Settings.Instance.AndroidBoardName = this.AndroidBoardNameTb.Text;
-            Settings.Instance.AndroidBootloader = this.AndroidBootloaderTb.Text;
-            Settings.Instance.DeviceBrand = this.DeviceBrandTb.Text;
-            Settings.Instance.DeviceModel = this.DeviceModelTb.Text;
-            Settings.Instance.DeviceModelIdentifier = this.DeviceModelIdentifierTb.Text;
-            Settings.Instance.DeviceModelBoot = this.DeviceModelBootTb.Text;
-            Settings.Instance.HardwareManufacturer = this.HardwareManufacturerTb.Text;
-            Settings.Instance.HardwareModel = this.HardwareModelTb.Text;
-            Settings.Instance.FirmwareBrand = this.FirmwareBrandTb.Text;
-            Settings.Instance.FirmwareTags = this.FirmwareTypeTb.Text;
-            Settings.Instance.FirmwareType = this.FirmwareFingerprintTb.Text;
+            Settings.Instance.DeviceId = DeviceIdTb.Text;
+            Settings.Instance.AndroidBoardName = AndroidBoardNameTb.Text;
+            Settings.Instance.AndroidBootloader = AndroidBootloaderTb.Text;
+            Settings.Instance.DeviceBrand = DeviceBrandTb.Text;
+            Settings.Instance.DeviceModel = DeviceModelTb.Text;
+            Settings.Instance.DeviceModelIdentifier = DeviceModelIdentifierTb.Text;
+            Settings.Instance.DeviceModelBoot = DeviceModelBootTb.Text;
+            Settings.Instance.HardwareManufacturer = HardwareManufacturerTb.Text;
+            Settings.Instance.HardwareModel = HardwareModelTb.Text;
+            Settings.Instance.FirmwareBrand = FirmwareBrandTb.Text;
+            Settings.Instance.FirmwareTags = FirmwareTypeTb.Text;
+            Settings.Instance.FirmwareType = FirmwareFingerprintTb.Text;
             Settings.Instance.Reload();
         }
     }
-}
+}
\ No newline at end of file
diff --git a/src/RocketBotGUI/DeviceHelper.cs b/src/RocketBotGUI/DeviceHelper.cs
index b14eaa7..61d6c7d 100644
--- a/src/RocketBotGUI/DeviceHelper.cs
+++ b/src/RocketBotGUI/DeviceHelper.cs
@@ -52,7 +52,7 @@ namespace PokemonGo.RocketAPI.Window

         public string RandomString(int length, string alphabet = "abcdefghijklmnopqrstuvwxyz0123456789")
         {
-            int outOfRange = byte.MaxValue + 1 - (byte.MaxValue + 1) % alphabet.Length;
+            var outOfRange = byte.MaxValue + 1 - (byte.MaxValue + 1)%alphabet.Length;

             return string.Concat(
                 Enumerable
@@ -60,8 +60,8 @@ namespace PokemonGo.RocketAPI.Window
                     .Select(e => RandomByte())
                     .Where(randomByte => randomByte < outOfRange)
                     .Take(length)
-                    .Select(randomByte => alphabet[randomByte % alphabet.Length])
-            );
+                    .Select(randomByte => alphabet[randomByte%alphabet.Length])
+                );
         }

         private static byte RandomByte()
@@ -91,4 +91,4 @@ namespace PokemonGo.RocketAPI.Window
         public string FirmwareType { get; set; }
         public string FirmwareFingerprint { get; set; }
     }
-}
+}
\ No newline at end of file
diff --git a/src/RocketBotGUI/ItemBox.cs b/src/RocketBotGUI/ItemBox.cs
index 65e0f51..bfc46de 100644
--- a/src/RocketBotGUI/ItemBox.cs
+++ b/src/RocketBotGUI/ItemBox.cs
@@ -2,8 +2,6 @@
 using System.Drawing;
 using System.Windows.Forms;
 using POGOProtos.Inventory.Item;
-using System.Collections.Generic;
-using POGOProtos.Inventory;

 namespace PokemonGo.RocketAPI.Window
 {
@@ -28,7 +26,8 @@ namespace PokemonGo.RocketAPI.Window
                 control.MouseClick += childMouseClick;
             }

-            if (item_.ItemId == ItemId.ItemIncubatorBasic || item_.ItemId == ItemId.ItemIncubatorBasicUnlimited || item.Count < 1)
+            if (item_.ItemId == ItemId.ItemIncubatorBasic || item_.ItemId == ItemId.ItemIncubatorBasicUnlimited ||
+                item.Count < 1)
             {
                 Enabled = false;
             }
@@ -80,11 +79,15 @@ namespace PokemonGo.RocketAPI.Window
             }
         }

-        private void tmr_Tick(object sender, EventArgs e) {
-            TimeSpan time = expires - DateTime.UtcNow;
-            if (expires.Ticks == 0 || time.TotalSeconds < 0) {
+        private void tmr_Tick(object sender, EventArgs e)
+        {
+            var time = expires - DateTime.UtcNow;
+            if (expires.Ticks == 0 || time.TotalSeconds < 0)
+            {
                 lblTime.Visible = false;
-            } else {
+            }
+            else
+            {
                 lblTime.Visible = true;
                 lblTime.Text = $"{time.Minutes}m {Math.Abs(time.Seconds)}s";
             }
diff --git a/src/RocketBotGUI/MainForm.cs b/src/RocketBotGUI/MainForm.cs
index c0f70f9..39ff25d 100644
--- a/src/RocketBotGUI/MainForm.cs
+++ b/src/RocketBotGUI/MainForm.cs
@@ -1383,6 +1383,12 @@ namespace PokemonGo.RocketAPI.Window
         {
         }

+        private void deviceToolStripMenuItem_Click(object sender, EventArgs e)
+        {
+            var deviceFrom = new DeviceForm();
+            deviceFrom.ShowDialog();
+        }
+
         #region POKEMON LIST

         private IEnumerable<Candy> families;
@@ -1532,11 +1538,15 @@ namespace PokemonGo.RocketAPI.Window
                 var itemTemplates = await _client2.Download.GetItemTemplates();

                 var appliedItems = new Dictionary<ItemId, DateTime>();
-                var inventoryAppliedItems = inventory.InventoryDelta.InventoryItems.Select(i => i.InventoryItemData?.AppliedItems);
+                var inventoryAppliedItems =
+                    inventory.InventoryDelta.InventoryItems.Select(i => i.InventoryItemData?.AppliedItems);

-                foreach (AppliedItems aItems in inventoryAppliedItems) {
-                    if (aItems != null && aItems.Item != null) {
-                        foreach (AppliedItem item in aItems.Item) {
+                foreach (var aItems in inventoryAppliedItems)
+                {
+                    if (aItems != null && aItems.Item != null)
+                    {
+                        foreach (var item in aItems.Item)
+                        {
                             appliedItems.Add(item.ItemId, Utils.FromUnixTimeUtc(item.ExpireMs));
                         }
                     }
@@ -1603,7 +1613,6 @@ namespace PokemonGo.RocketAPI.Window
                 }

                 lblInventory.Text = itemscount + " / " + profile.PlayerData.MaxItemStorage;
-
             }
             catch (GoogleException ex)
             {
@@ -1665,20 +1674,28 @@ namespace PokemonGo.RocketAPI.Window
                     }
                     else if (item.ItemId == ItemId.ItemIncenseOrdinary)
                     {
-                        if (!_botStarted) {
+                        if (!_botStarted)
+                        {
                             ColoredConsoleWrite(Color.Red, $"Bot must be running first!");
                             SetState(true);
                             return;
                         }
                         var response = await _client.Inventory.UseIncense(ItemId.ItemIncenseOrdinary);
-                        if (response.Result == UseIncenseResponse.Types.Result.Success) {
+                        if (response.Result == UseIncenseResponse.Types.Result.Success)
+                        {
                             ColoredConsoleWrite(Color.Green, $"Using an incense");
                             ColoredConsoleWrite(Color.Yellow, $"Incense valid until: {DateTime.Now.AddMinutes(30)}");
-                        } else if (response.Result == UseIncenseResponse.Types.Result.IncenseAlreadyActive) {
+                        }
+                        else if (response.Result == UseIncenseResponse.Types.Result.IncenseAlreadyActive)
+                        {
                             ColoredConsoleWrite(Color.Orange, $"An incense is already active!");
-                        } else if (response.Result == UseIncenseResponse.Types.Result.LocationUnset) {
+                        }
+                        else if (response.Result == UseIncenseResponse.Types.Result.LocationUnset)
+                        {
                             ColoredConsoleWrite(Color.Red, $"Bot must be running first!");
-                        } else {
+                        }
+                        else
+                        {
                             ColoredConsoleWrite(Color.Red, $"Failed using an incense!");
                         }
                     }
@@ -2012,11 +2029,5 @@ namespace PokemonGo.RocketAPI.Window
         }

         #endregion
-
-        private void deviceToolStripMenuItem_Click(object sender, EventArgs e)
-        {
-            var deviceFrom = new DeviceForm();
-            deviceFrom.ShowDialog();
-        }
     }
 }
\ No newline at end of file
diff --git a/src/RocketBotGUI/PokemonObject.cs b/src/RocketBotGUI/PokemonObject.cs
index b5c95e1..11c9694 100644
--- a/src/RocketBotGUI/PokemonObject.cs
+++ b/src/RocketBotGUI/PokemonObject.cs
@@ -1,9 +1,9 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 using PokemonGo.RocketAPI.Helpers;
 using POGOProtos.Data;
 using POGOProtos.Enums;
 using POGOProtos.Networking.Responses;
-using System;

 namespace PokemonGo.RocketAPI.Window
 {
@@ -51,7 +51,7 @@ namespace PokemonGo.RocketAPI.Window

         public double GetIV
         {
-            get { return Math.Round(PokemonInfo.CalculatePokemonPerfection(PokemonData),2); }
+            get { return Math.Round(PokemonInfo.CalculatePokemonPerfection(PokemonData), 2); }
         }

         public double GetLv
diff --git a/src/RocketBotGUI/Settings.cs b/src/RocketBotGUI/Settings.cs
index 19542bd..b7f1b4c 100644
--- a/src/RocketBotGUI/Settings.cs
+++ b/src/RocketBotGUI/Settings.cs
@@ -92,7 +92,12 @@ namespace PokemonGo.RocketAPI.Window
         public string FirmwareBrandTb => GetSetting() != string.Empty ? GetSetting() : "OnePlus2";
         public string FirmwareTagsTb => GetSetting() != string.Empty ? GetSetting() : "dev-key";
         public string FirmwareTypeTb => GetSetting() != string.Empty ? GetSetting() : "user";
-        public string FirmwareFingerprintTb => GetSetting() != string.Empty ? GetSetting() : "OnePlus/OnePlus2/OnePlus2:6.0.1/MMB29M/1447840820:user/release-keys";
+
+        public string FirmwareFingerprintTb
+            =>
+                GetSetting() != string.Empty
+                    ? GetSetting()
+                    : "OnePlus/OnePlus2/OnePlus2:6.0.1/MMB29M/1447840820:user/release-keys";

         public ICollection<KeyValuePair<ItemId, int>> ItemRecycleFilter => new[]
         {
@@ -271,7 +276,12 @@ namespace PokemonGo.RocketAPI.Window

         public string FirmwareFingerprint
         {
-            get { return GetSetting() != string.Empty ? GetSetting() : "OnePlus/OnePlus2/OnePlus2:6.0.1/MMB29M/1447840820:user/release-keys"; }
+            get
+            {
+                return GetSetting() != string.Empty
+                    ? GetSetting()
+                    : "OnePlus/OnePlus2/OnePlus2:6.0.1/MMB29M/1447840820:user/release-keys";
+            }

             set { SetSetting(value); }
         }
@@ -298,7 +308,7 @@ namespace PokemonGo.RocketAPI.Window

         public void SetSetting(double value, [CallerMemberName] string key = null)
         {
-            var customCulture = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
+            var customCulture = (CultureInfo) Thread.CurrentThread.CurrentCulture.Clone();
             customCulture.NumberFormat.NumberDecimalSeparator = ".";
             Thread.CurrentThread.CurrentCulture = customCulture;
             var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
You may download the files in Public Git.