Exemple #1
0
        private void Save_Config(int id, Int32 mod = 0, Int32 key = 0, int sms = -1)
        {
            bool _Edited  = false;
            int  _Line_ID = 0;

            string[]      lines;
            List <string> NewFile;

            try
            {
                if (File.Exists("config.cfg"))
                {
                    lines = File.ReadAllLines("config.cfg");
                }
                else
                {
                    lines = Default_Config;
                }

                NewFile = new List <string>(lines);

                /*
                 * if we call this void something is getting written to config we need to figure out what
                 * -1 sms = default = we're not writing to sms (so default to writing mod/key values?)
                 *
                 *
                 *
                 */

                foreach (string line in lines)
                {
                    string[] IVT_Values = { null, null, null };
                    string   IVT;

                    if (string.IsNullOrEmpty(line) || line.Contains("#"))
                    {
                        NewFile[_Line_ID] = line;
                    }
                    else if (line.Contains("SMS"))
                    {
                        if (sms >= 0)
                        {
                            NewFile[_Line_ID] = string.Format("['SMS_0'] = {0:x}", sms);
                            _Edited           = true;
                        }
                        else
                        {
                            NewFile[_Line_ID] = line;
                        }
                    }
                    else if (key != 0 && sms < 0)
                    {
                        IVT = Regex.Replace(line, @"[\['\]\s]", "");
                        IVT = Regex.Replace(IVT, @"[_\=]", "-");

                        IVT_Values = IVT.Split('-');

                        if (IVT_Values[0] == "Modifier" || IVT_Values[0] == "Hotkey")
                        {
                            if (Convert.ToInt32(IVT_Values[1]) == id)
                            {
                                NewFile[_Line_ID] = string.Format("['{0}_{1}'] = 0x{2:x}", IVT_Values[0], IVT_Values[1], IVT_Values[0] == "Modifier" ? mod : key);
                                _Edited           = true;
                            }
                            else
                            {
                                NewFile[_Line_ID] = line;
                            }
                        }
                    }
                    _Line_ID++;
                }

                if (_Edited)
                {
                    File.WriteAllLines("config.cfg", NewFile);
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to save user pref to config file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Console.WriteLine(string.Format("{0}", ex));
            }
        }
Exemple #2
0
        /* PURGEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
         * private void Write_Cache(bool error = false)
         * {
         *  int starttime;
         *  bool comp = false;
         *  foreach (string Title in Caches)
         *  {
         *      comp = false;
         *      starttime = UnixNOW();
         *      //while (true)
         *      //{
         *          //if (UnixNOW() - starttime > 8 || comp)
         *              //break;
         *
         *      using (WebClient wc = new WebClient())
         *      {
         *          wc.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0");
         *          //try
         *          //{
         *          Console.WriteLine("Attempting to grab {0} from https://poe.ninja/api/data/itemoverview?league={1}&type={2} and write to Cache/{3}.cache", Title, comboBox1.Text, Title, Title);
         *          wc.DownloadStringAsync(new Uri(string.Format("https://poe.ninja/api/data/itemoverview?league={0}&type={1}", comboBox1.Text, Title)));
         *          //}
         *          //catch (Exception ex) { throw ex; }
         *
         *          wc.DownloadStringCompleted += (s, e) =>
         *          {
         *              Console.WriteLine("Retrieved :: {0}", e.Result);
         *              try { File.WriteAllText(@"Cache/" + Title + ".cache", e.Result); }
         *              catch (Exception ex) { throw ex; }
         *              comp = true;
         *          };
         *
         *          wc.DownloadProgressChanged += (s, e) =>
         *          {
         *
         *          };
         *      }
         *          Thread.Sleep(500);
         *
         *          while(true)
         *          {
         *              if (UnixNOW() - starttime > 30 || comp)
         *                  break;
         *
         *              Thread.Sleep(500);
         *          }
         *      //}
         *  }
         * }*/

        //TODO :: Write code to save color selection of tooltip.
        private void Load_Config(bool error = false)
        {
            string[] lines;

            if (!error)
            {
                if (!File.Exists("config.cfg"))
                {
                    File.WriteAllLines("config.cfg", Default_Config);
                    lines = Default_Config;
                }
                else
                {
                    lines = File.ReadAllLines("config.cfg");
                }
            }
            else
            {
                lines = Default_Config;
            }


            try
            {
                string[] IVT_Values = { null, null, null };
                string   IVT;
                int      Key;
                int      Key_Value;

                foreach (string line in lines)
                {
                    if (string.IsNullOrEmpty(line) || line.Contains("#"))
                    {
                        continue;
                    }

                    IVT = Regex.Replace(line, @"[\['\]\s]", "");
                    IVT = Regex.Replace(IVT, @"[_\=]", "-");

                    IVT_Values = IVT.Split('-');

                    Key       = Convert.ToInt32(IVT_Values[1]);
                    Key_Value = Convert.ToInt32(IVT_Values[2], 16);

                    if (IVT_Values[0] == "Modifier")
                    {
                        Threads[Key].HK_Modifier = Key_Value;
                    }
                    else if (IVT_Values[0] == "Hotkey")
                    {
                        Threads[Key].Hotkey = Key_Value;
                    }
                    else if (IVT_Values[0] == "SMS")
                    {
                        SMS_ToolTip.Enabled = Convert.ToBoolean(Key_Value);
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
            }
            catch
            {
                MessageBox.Show("Problem while reading config file please delete the config.cfg file if problems persist\r\nloading default config for now.", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Load_Config(true);
            }
        }