Ejemplo n.º 1
0
 private void updateLocalStatsData()
 {
     userStatsData = jData.ReadStatsData("data\\stats.json");
     if (userStatsData == null)
     {
         MessageBox.Show("An error occured: Json file (stats) is not working.\nContact support or create issue on github", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Write in the json file specified
 /// </summary>
 /// <param name="j">Json data type</param>
 /// <param name="p">Json file path</param>
 /// <returns>True if the file is successfully created</returns>
 public bool WriteStatsData(StatsData j, string p)
 {
     try
     {
         System.IO.File.WriteAllText(p, JsonConvert.SerializeObject(j, Formatting.None));
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 3
0
        private void ResetStatistics(object sender, EventArgs e)
        {
            DialogResult resultMsgBox = MessageBox.Show("Are you really sure?", "CClick", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (resultMsgBox == DialogResult.Yes)
            {
                StatsData statsReset = new StatsData
                {
                    ClicksAverage           = 0.0,
                    TotalClicks             = 0,
                    TotalMsElapsedOnTest    = 0.0,
                    TotalTests              = 0,
                    ClicksPerSecondsAverage = 0.0,
                    ClicksPerSecondsAllTest = null,
                    BestScores              = null
                };
                jData.WriteStatsData(statsReset, "data\\stats.json");
                updateLocalStatsData();
            }
        }
Ejemplo n.º 4
0
        private TimeSpan EndTest(bool fromStopButton = false)
        {
            #region Changing / removing / creating vars
            watcher.Stop();
            clickableButton.Text = "START";
            isTestRunning        = false;
            timer.Enabled        = false;
            timer.Stop();
            timer.Dispose();
            firstClickValuesCheck     = false;
            maximumProgressBarChecked = false;
            double thisTestCps = Math.Round(ToClickPerSeconds(clickCounter, watcher.ElapsedMilliseconds), 3);
            stopTestButton.Visible = false;
            #endregion

            if (!fromStopButton)
            {
                #region Add this test cps to cpsAllTest (used below to write in the userStatsData)
                List <double> cpsAllTest;
                if (userStatsData.ClicksPerSecondsAllTest != null)
                {
                    cpsAllTest = new List <double>(userStatsData.ClicksPerSecondsAllTest);
                    cpsAllTest.Add(thisTestCps);
                }
                else
                {
                    cpsAllTest = new List <double>(new[] { thisTestCps });
                }
                #endregion

                #region Best score checking
                Dictionary <string, double> bestScores;
                if (userStatsData.BestScores != null)
                {
                    bestScores = userStatsData.BestScores;
                    double currentlyInArray;
                    if (bestScores.ContainsKey(currentTestName) && bestScores.TryGetValue(currentTestName, out currentlyInArray))
                    {
                        if (currentlyInArray < thisTestCps)
                        {
                            bestScores.Remove(currentTestName);
                            bestScores.Add(currentTestName, thisTestCps);
                        }
                    }
                    else
                    {
                        bestScores.Add(currentTestName, thisTestCps);
                    }
                }
                else
                {
                    bestScores = new Dictionary <string, double>
                    {
                        { currentTestName, thisTestCps }
                    };
                }
                #endregion

                #region Write new stats data
                StatsData newStatsData = new StatsData
                {
                    ClicksAverage           = (userStatsData.TotalClicks + clickCounter) / (userStatsData.TotalTests + 1.0), // If 1, that's automatically round the double value
                    TotalClicks             = userStatsData.TotalClicks + clickCounter,
                    TotalMsElapsedOnTest    = userStatsData.TotalMsElapsedOnTest + watcher.ElapsedMilliseconds,
                    TotalTests              = userStatsData.TotalTests + 1,
                    ClicksPerSecondsAverage = ToClickPerSeconds(userStatsData.TotalClicks + clickCounter, (long)userStatsData.TotalMsElapsedOnTest + watcher.ElapsedMilliseconds),
                    ClicksPerSecondsAllTest = cpsAllTest,
                    BestScores              = bestScores
                };

                jData.WriteStatsData(newStatsData, "data\\stats.json");
                updateLocalStatsData();
                #endregion
            }

            #region Enable menus (which were disabled on test start)
            richTextBox1.Enabled        = true;
            typeCheckBox.Enabled        = true;
            typeTextBox.Enabled         = true;
            battleTypeCheckBox.Enabled  = true;
            battleHealthTextBox.Enabled = true;
            battleDamageTextBox.Enabled = true;
            applyConfigButton.Enabled   = true;
            #endregion

            return(watcher.Elapsed);
        }
Ejemplo n.º 5
0
        public CClick()
        {
            InitializeComponent();

            #region Check if CClick is already started
            Process   currentProcess = Process.GetCurrentProcess();
            Process[] procColl       = Process.GetProcessesByName(currentProcess.ProcessName);
            foreach (Process p in procColl)
            {
                if (p.Id != currentProcess.Id)
                {
                    MessageBox.Show("CClick is already opened", "CClick", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    Close();
                }
            }
            #endregion

            #region Version Check
            string latestVersion = new WebClient().DownloadString("https://pastebin.com/raw/vNb10fgb");

            NumberFormatInfo provider = new NumberFormatInfo
            {
                NumberDecimalSeparator = "."
            };

            // Version check
            if (Convert.ToDouble(version, provider) < Convert.ToDouble(latestVersion, provider))
            {
                DialogResult verResult = MessageBox.Show($"A new version is now available :\nYou are using > {version}\nNew > {latestVersion}\nDo you want to install the new version?", "WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);

                if (verResult == DialogResult.Yes)
                {
                    Process.Start(new ProcessStartInfo("cmd", $"/c start https://github.com/Cu-chi/CClick/releases/download/{latestVersion}/CClick-{latestVersion}.zip")
                    {
                        CreateNoWindow = true
                    });
                }
            }
            #endregion

            #region JSON: user settings data (default test, sound effect etc...)
            if (!System.IO.File.Exists("data\\data.json"))
            {
                DialogResult resultMsgBox        = MessageBox.Show("Have you just updated Click?", "CClick", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                string       olderDataCClickPath = "";
                if (resultMsgBox == DialogResult.Yes)
                {
                    FolderBrowserDialog openFolderDialog = new FolderBrowserDialog
                    {
                        Description = "Select your older CClick folder"
                    };

                    if (openFolderDialog.ShowDialog() == DialogResult.OK)
                    {
                        olderDataCClickPath = openFolderDialog.SelectedPath + "\\data";

                        DirectoryInfo dir = new DirectoryInfo(olderDataCClickPath);
                        FileInfo[]    files;
                        try
                        {
                            files = dir.GetFiles();
                        }
                        catch (DirectoryNotFoundException)
                        {
                            MessageBox.Show("Can't find any data folder.", "CClick", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        Directory.CreateDirectory("data");

                        foreach (FileInfo file in files)
                        {
                            if (file.Extension == ".json")
                            {
                                file.CopyTo($"data\\{file.Name}", false);
                            }
                        }
                    }

                    updateLocalData();
                }
                else
                {
                    Data json = new Data
                    {
                        EnableSound              = false,
                        EnableProgressBar        = false,
                        DefaultTest              = -1,
                        CustomConfig             = null,
                        RichTextBoxSaveEnabled   = false,
                        RichTextBoxContent       = {},
                        SaveBestScoreForEachTest = true
                    };

                    Directory.CreateDirectory("data");

                    if (!jData.WriteData(json, "data\\data.json"))
                    {
                        MessageBox.Show("An error occured: Json file can't be created.\nContact support or create issue on github", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                        return;
                    }
                }
            }
            else
            {
                userData = jData.ReadData("data\\data.json");
                if (userData == null)
                {
                    MessageBox.Show("An error occured: Json file is not working.\nContact support or create issue on github", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;
                }

                if (userData.EnableSound)
                {
                    settingsForm.soundEffectCheckBox.CheckState = CheckState.Checked;
                }

                if (userData.DefaultTest != -1)
                {
                    comboBox.SelectedIndex = userData.DefaultTest;
                }

                if (comboBox.SelectedIndex == 5) // If selected test is custom
                {
                    if (userData.CustomConfig != null)
                    {
                        if (userData.CustomConfig[0] == "click")
                        {
                            typeCheckBox.CheckState = CheckState.Unchecked;
                        }
                        else
                        {
                            typeCheckBox.CheckState = CheckState.Checked;
                        }

                        if (userData.CustomConfig[1] == "battle")
                        {
                            battleTypeCheckBox.CheckState = CheckState.Checked;
                        }
                        else
                        {
                            typeCheckBox.CheckState = CheckState.Unchecked;
                        }

                        typeTextBox.Text         = userData.CustomConfig[2];
                        battleHealthTextBox.Text = userData.CustomConfig[3];
                        battleDamageTextBox.Text = userData.CustomConfig[4];
                    }

                    CustomTestDisplay(true); // Display customization panel
                }
            }
            #endregion

            #region JSON: user statistics data
            if (!System.IO.File.Exists("data\\stats.json"))
            {
                StatsData json = new StatsData
                {
                    ClicksAverage           = 0,
                    TotalClicks             = 0,
                    TotalMsElapsedOnTest    = 0,
                    TotalTests              = 0,
                    ClicksPerSecondsAverage = 0,
                    ClicksPerSecondsAllTest = {},
                    BestScores              = null
                };

                if (!jData.WriteStatsData(json, "data\\stats.json"))
                {
                    MessageBox.Show("An error occured: Json file can't be created.\nContact support or create issue on github", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;
                }
            }
            else
            {
                userStatsData = jData.ReadStatsData("data\\stats.json");
                if (userStatsData == null)
                {
                    MessageBox.Show("An error occured: Json file (stats) is not working.\nContact support or create issue on github", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;
                }
            }
            #endregion
        }