Esempio n. 1
0
        private void previousSessionsTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Node.Parent != null)
            {
                int key = e.Node.Index + (e.Node.Parent.Index << 16);
                displayHistoryResults(savedHistoryResults[key]);
            }
            else if (e.Node.Nodes.Count == 0 && !e.Node.Text.Equals(String.Empty))
            {
                XmlTextReader reader = new XmlTextReader((String)savedHistoryFileNames[e.Node.Index]);
                reader.WhitespaceHandling = WhitespaceHandling.None;
                reader.Read(); reader.Read();
                if (!reader.Name.Equals("session"))
                {
                    return; //invalid file
                }
                reader.Read();
                int index = 0;
                while (reader.Name.Equals("result"))
                {
                    reader.MoveToNextAttribute();
                    String summary = reader.Value;
                    reader.Read();
                    Board            board    = Board.Parse(reader.ReadElementContentAsString());
                    double           time     = reader.ReadElementContentAsDouble();
                    Consts.GameTypes gameType = (Consts.GameTypes)Enum.Parse(typeof(Consts.GameTypes), reader.ReadElementContentAsString());
                    reader.Read();

                    ArrayList simulations = new ArrayList();
                    while (reader.Name.Equals("simulation"))
                    {
                        ArrayList cards           = new ArrayList();
                        ArrayList playerNames     = new ArrayList();
                        ArrayList preflopEquities = new ArrayList();
                        ArrayList flopEquities    = new ArrayList();
                        ArrayList turnEquities    = new ArrayList();
                        ArrayList riverEquities   = new ArrayList();
                        reader.Read();
                        while (reader.Name.Equals("hand"))
                        {
                            reader.MoveToNextAttribute();
                            cards.Add(Cards.Parse(reader.Value));
                            reader.MoveToNextAttribute();
                            playerNames.Add(reader.Value);
                            reader.Read();
                            preflopEquities.Add(reader.ReadElementContentAsDouble());
                            flopEquities.Add(reader.ReadElementContentAsDouble());
                            turnEquities.Add(reader.ReadElementContentAsDouble());
                            riverEquities.Add(reader.ReadElementContentAsDouble());
                            reader.Read();
                        }
                        simulations.Add(new Simulation((Cards[])cards.ToArray(typeof(Cards)), (String[])playerNames.ToArray(typeof(String)),
                                                       (double[])preflopEquities.ToArray(typeof(double)),
                                                       (double[])flopEquities.ToArray(typeof(double)),
                                                       (double[])turnEquities.ToArray(typeof(double)),
                                                       (double[])riverEquities.ToArray(typeof(double))));
                        reader.Read();
                    }
                    reader.Read();
                    String handHistory = reader.ReadElementContentAsString();

                    Results result = new Results(gameType, board, handHistory);
                    foreach (Simulation simulation in simulations)
                    {
                        result.AddSimulation(simulation);
                    }
                    result.Time    = time;
                    result.Summary = summary;

                    int key = index + (e.Node.Index << 16);
                    savedHistoryResults[key] = result;
                    e.Node.Nodes.Add(result.Summary);
                    reader.Read();
                    index++;
                }
                e.Node.Expand();
                reader.Close();
            }
        }
Esempio n. 2
0
        public MainForm()
        {
            InitializeComponent();


            handTextBoxes = new TextBox[9] {
                handTextBox1, handTextBox2, handTextBox3, handTextBox4, handTextBox5,
                handTextBox6, handTextBox7, handTextBox8, handTextBox9
            };

            loadedHistoryResult   = null;
            historyResults        = new ArrayList();
            savedHistoryFileNames = new ArrayList();
            savedHistoryResults   = new Dictionary <int, Results>();

            daysRemaining = 0;

            analyzeFromHHButton.Text = "Analyze" + Environment.NewLine + "(Shift+Enter)";

            //Validate Software Registration
            bool isRegistered = false;

            identificationCode = String.Empty;
            registrationKey    = String.Empty;

            String identifier = "QOCalc";

            ManagementClass mc = new System.Management.ManagementClass("Win32_Processor");

            System.Management.ManagementObjectCollection moc = mc.GetInstances();
            foreach (System.Management.ManagementObject mo in moc)
            {
                identifier += mo["ProcessorID"].ToString();
            }

            ManagementObject disk =
                new ManagementObject("win32_logicaldisk.deviceid=\"C:\"");

            disk.Get();
            identifier += disk["VolumeSerialNumber"].ToString();

            mc  = new ManagementClass("Win32_NetworkAdapterConfiguration");
            moc = mc.GetInstances();
            foreach (ManagementObject mo in moc)
            {
                if ((bool)mo["IPEnabled"] == true)
                {
                    identifier += mo["MacAddress"].ToString().Replace(":", "");
                    mo.Dispose();
                    break;
                }
                mo.Dispose();
            }

            int identifierHash = identifier.GetHashCode();

            byte[] hashBytes = BitConverter.GetBytes(identifierHash);
            foreach (byte b in hashBytes)
            {
                identificationCode += String.Format("{0,2:X2}", b);
            }

            DESCryptoServiceProvider key = new DESCryptoServiceProvider();

            key.Key = ASCIIEncoding.ASCII.GetBytes("12664961");
            key.IV  = ASCIIEncoding.ASCII.GetBytes("QODDCALC");

            MemoryStream ms        = new MemoryStream();
            CryptoStream encStream = new CryptoStream(ms, key.CreateEncryptor(), CryptoStreamMode.Write);

            encStream.Write(hashBytes, 0, hashBytes.Length);
            encStream.FlushFinalBlock();

            byte[] encryptedBytes = ms.ToArray();

            encStream.Close();
            ms.Close();

            foreach (byte b in encryptedBytes)
            {
                registrationKey += String.Format("{0,2:X2}", b);
            }

            try
            {
                reg = Registry.CurrentUser.OpenSubKey("SOFTWARE\\QuickOdds", true);
                String registrationKeyInRegistry = reg.GetValue("RegistrationKey").ToString();

                if (registrationKeyInRegistry.Equals(registrationKey))
                {
                    isRegistered = true;
                }
            }
            catch (Exception)
            {
                //key does not exist, therefore create registry data
                reg = Registry.CurrentUser.OpenSubKey("SOFTWARE\\", true);
                reg = reg.CreateSubKey("QuickOdds\\");
                reg.SetValue("RegistrationKey", "", RegistryValueKind.String);
                reg.SetValue("FirstRunDate", BitConverter.GetBytes((DateTime.Now.Ticks)));
            }
            if (!isRegistered)
            {
                DateTime firstRunDate;
                try
                {
                    firstRunDate = new DateTime(BitConverter.ToInt64((byte[])reg.GetValue("FirstRunDate"), 0));
                }
                catch (Exception)
                {
                    firstRunDate = DateTime.MinValue;
                }
                if (firstRunDate < DateTime.Now.AddDays(-14) || firstRunDate > DateTime.Now)
                {
                    //disable
                    DisableButtons();
                    resultsRichTextBox.Text += "TRIAL EXPIRED. Please register to continue using QuickOdds Calculator.";
                }
                else
                {
                    TimeSpan timeRemaining = firstRunDate - DateTime.Now;
                    daysRemaining            = timeRemaining.Days + 14;
                    resultsRichTextBox.Text += "TRIAL VERSION. You have " + daysRemaining + " days remaining.";
                }
            }

            SetRegistrationValues(isRegistered);

            try
            {
                Consts.BuildDictionaries();
            }
            catch
            {
                DisableButtons();
                resultsRichTextBox.Text = "Data files are corrupted, please reinstall QuickOdds.\n";
            }

            String[] historyFilenames = Directory.GetFiles("History\\");
            Array.Sort(historyFilenames);
            Array.Reverse(historyFilenames);
            foreach (String filename in historyFilenames)
            {
                FileInfo fileInfo = new FileInfo(filename);
                if (fileInfo.Length < 2048) //if filesize is too small to be valid
                {
                    File.Delete(filename);
                }

                else
                {
                    DateTime filenameDate;
                    String   dateString = filename.Substring(8, 10);

                    if (DateTime.TryParse(dateString, out filenameDate))
                    {
                        if (filenameDate < DateTime.Today.AddDays(Properties.Settings.Default.SaveDays * -1.0))
                        {
                            File.Delete(filename);
                        }
                        else
                        {
                            savedHistoryFileNames.Add(filename);
                            previousSessionsTreeView.Nodes.Add(filenameDate.ToString("d"));
                        }
                    }
                    else
                    {
                        File.Delete(filename);
                    }
                }
            }

            showPlayerNamesCheckBox.Checked        = Properties.Settings.Default.ShowPlayerNames;
            saveSimulationsCheckBox.Checked        = Properties.Settings.Default.SaveSimulations;
            saveDaysTextBox.Text                   = Properties.Settings.Default.SaveDays.ToString();
            showTimeCheckBox.Checked               = Properties.Settings.Default.ShowTime;
            gameComboBox.SelectedIndex             = Properties.Settings.Default.GameType;
            historyShowPlayerNamesCheckBox.Checked = Properties.Settings.Default.HistoryShowPlayerNames;
        }
Esempio n. 3
0
 private void addHistoryResults(Results results)
 {
     historyResults.Insert(0, results);
     historyListBox.Items.Insert(0, results.ToString());
 }
Esempio n. 4
0
 private void clearButton_Click(object sender, EventArgs e)
 {
     resultsRichTextBox.ResetText();
     hhRichTextBox.ResetText();
     results = null;
 }