Exemplo n.º 1
0
        //Tries to load existing killer data from a JSON object and creates a new one if one doesn't already exist
        public KillerStats loadKillerStats()
        {
            //check if there is existing data
            if (System.IO.File.Exists(Constants.PathToRoot + "data\\killer.json"))
            {
                try
                {
                    string      jsonInput    = System.IO.File.ReadAllText(Constants.PathToRoot + "data\\killer.json");
                    KillerStats existingData = Newtonsoft.Json.JsonConvert.DeserializeObject <KillerStats>(jsonInput);
                    return(existingData);
                }
                catch
                {
                    MessageBox.Show("Something went wrong loading existing data. Exiting.");
                    System.Environment.Exit(0);
                }
            }

            //else display a message and create new data
            MessageBox.Show("No existing data found.");
            KillerStats newStats = new KillerStats();

            writeKillerDataToJSON(newStats);
            return(newStats);
        }
Exemplo n.º 2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //run the batch script to pull new log files
            KillerStats temp = new KillerStats();

            ExecuteBatFileAndUpdateUI(temp);
        }
Exemplo n.º 3
0
        public void processLogLine(string line, string prevLine, ref KillerStats statsObj)
        {
            Boolean isBPtotal = false;

            if (line.IndexOf("Logging Player Score Event") != -1)
            {
                line = line.Substring(line.IndexOf("Logging Player Score Event") + 1);
                if (line.Contains("DBDPlayerScore_EnterParadise"))
                {
                    statsObj.matchesPlayed++;
                }
                else if (line.Contains("DBDSlasherScore_Destroy"))
                {
                    statsObj.breakActionCount++;
                }
                else if (line.Contains("DBDSlasherScore_SacrificeSuccess"))
                {
                    statsObj.sacrificeCount++;
                }
                else if (line.Contains("DBDSlasherScore_CamperHookedFirstTime"))
                {
                    statsObj.firstHookCount++;
                }
                else if (line.Contains("DBDSlasherScore_Hook"))
                {
                    statsObj.hookCount++;
                }
            }
            else if (line.IndexOf("DBDPlayerScore_AddBloodpoints") != -1 && !line.Equals(prevLine))
            {
                line      = line.Substring(line.IndexOf("DBDPlayerScore_AddBloodpoints") + 1);
                isBPtotal = true;
            }
            else
            {
                return;
            }

            try
            {
                int bpValue = (int)float.Parse(Regex.Match(line, @"[+-]?([0-9]*[.])?[0-9]+").Value);
                if (isBPtotal)
                {
                    statsObj.bloodpointsEarned += bpValue;
                }
            }
            catch
            {
                return;
            }
        }
Exemplo n.º 4
0
 public void writeKillerDataToJSON(KillerStats kStats)
 {
     try
     {
         //write the data to a json object
         string jsonObj = Newtonsoft.Json.JsonConvert.SerializeObject(kStats);
         System.IO.File.WriteAllText(Constants.PathToRoot + "data\\killer.json", jsonObj);
     }
     catch
     {
         MessageBox.Show("Error writing out new data. Exiting.");
         System.Environment.Exit(0);
     }
 }
Exemplo n.º 5
0
        public MainWindow()
        {
            InitializeComponent();

            //handle visibility
            loadingicon.Visibility = Visibility.Hidden;
            scroll.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;

            KillerStats kStats = loadKillerStats();

            dataList.Width = Constants.DataItemWidth;
            initUIElements(kStats.formatData());
            doStartupPrompts();

            //generate a random background
            Random newRand = new Random();

            background.Source = new BitmapImage(new Uri("Resources/backgrounds/banner_" + newRand.Next(9) + ".png", UriKind.Relative));
        }
Exemplo n.º 6
0
        //Takes a KillerStats object and displays the data on the window

        /*
         * public void displayKillerStats(KillerStats killStat)
         * {
         *  dataBox.Text = killStat.formatData();
         *
         * }
         */

        public void updateKillerStatsFromLogfiles(ref KillerStats statsObj)
        {
            //get the filenames for the log files
            string path          = Constants.PathToRoot + "data\\";
            string searchPattern = "*.log";

            string[] MyFiles = System.IO.Directory.GetFiles(path, searchPattern);

            foreach (string file in MyFiles)
            {
                string   prevLine = "";
                string[] lines    = System.IO.File.ReadAllLines(file);
                foreach (string line in lines)
                {
                    if (goodLines.Any(line.Contains))
                    {
                        processLogLine(line, prevLine, ref statsObj);
                    }
                    prevLine = line;
                }
            }
        }
Exemplo n.º 7
0
        public void ExecuteBatFileAndUpdateUI(KillerStats statsObj)
        {
            Process proc = new Process();

            //oof
            proc.StartInfo.FileName              = System.AppDomain.CurrentDomain.BaseDirectory + Constants.PathToRoot + "cpy.bat";
            proc.StartInfo.Arguments             = Constants.PathToRoot + "settings.ini";
            proc.StartInfo.RedirectStandardError = true;
            proc.StartInfo.CreateNoWindow        = true;
            proc.StartInfo.UseShellExecute       = false;
            proc.EnableRaisingEvents             = true;
            loadingicon.Visibility = Visibility.Visible;
            proc.Start();


            //listen for the process to finish running and alert the main thread to update the visibility
            proc.Exited += (sender, e) => { this.Dispatcher.Invoke(() => {
                    loadingicon.Visibility = Visibility.Hidden;
                    updateKillerStatsFromLogfiles(ref statsObj);
                    initUIElements(statsObj.formatData());
                    //write the new stats to file, overwriting whatever was there
                    writeKillerDataToJSON(statsObj);
                }); };
        }