// This updates the date of the most recent save to the text-box value.
 private static void updateRecentSaveDate(BorderlandsDateFormat dateFormat)
 {
     window.MostRecentSaveDate.Text = dateFormat.ToString();
 }
        // This code  happens on every tick of the timer that is determined by the value of the IntegerUpDown
        private static void dispatcherTimer_tick(object sender, EventArgs e)
        {
            try
            {
                Console.WriteLine("Checking for Read-Only!\n\n");

                // Get our currently loaded save using BLIO's GetWillowPlayerController function.
                BLIO.Object WillowPlayerController = getPlayerController();
                string      property = WillowPlayerController.GetProperty("SaveGameName");
                #region Save Gaming
                // The actual save file
                WillowSaveGame saveGame = string.IsNullOrEmpty(property) ? new WillowSaveGame(bl2) : new WillowSaveGame(property, bl2);

                readOnlyCheckbox.IsChecked = saveGame.saveGameInReadOnly;
                // This obtains console output every 10 seconds to notice if the player has ever loaded in.
                if (!saveGame.saveGameInReadOnly)
                {
                    return;
                }

                Console.WriteLine("Read-Only is Enabled!");

                // Code to compare the save file date
                DateTime onDiskSaveFileDate = saveGame.LastWriteTime();

                // This is the general number format of: yyyy / mm / dd / hh / mm / ss
                // This format is the one used in the LastSavedDate property on a PlayerGameSave

                dateFormatter = new BorderlandsDateFormat(
                    onDiskSaveFileDate.Year.ToString(),
                    onDiskSaveFileDate.Month.ToString(),
                    onDiskSaveFileDate.Day.ToString(),
                    onDiskSaveFileDate.Hour.ToString(),
                    onDiskSaveFileDate.Minute.ToString(),
                    onDiskSaveFileDate.Second.ToString(),
                    onDiskSaveFileDate.ToString("tt")
                    );

                updateRecentSaveDate(dateFormatter);

                long onDiskSaveFormat = Convert.ToInt64(dateFormatter.getDateFormat());
                Dictionary <string, string> responseList = GetAll("PlayerSaveGame", "LastSavedDate");

                if (responseList.Count < 0)
                {
                    // If we don't know the date, just return because the math will be incorrect.
                    if (previousMemoryDate == 0)
                    {
                        return;
                    }
                }

                #endregion

                // This handles all of our dates that are / were loaded into the memory at the time.
                #region Memory Date Handling

                long dateDifference = 0;
                #region Current Memory Date
                if (responseList.Count > 0)
                {
                    // This is a list of all of our dates.
                    List <long> memorySaveDateList = new List <long>();

                    foreach (KeyValuePair <string, string> entry in responseList)
                    {
                        try
                        {
                            memorySaveDateList.Add(Convert.ToInt64(entry.Value));
                        }
                        catch (FormatException ex)
                        {
                            continue;
                        }
                    }

                    long highestDate = FindMaxValue(memorySaveDateList, x => x);

                    previousMemoryDate = highestDate;

                    dateDifference = highestDate -
                                     onDiskSaveFormat;
                }
                #endregion

                #region Last known memory date
                else if (responseList.Count == 0)
                {
                    long highest = Math.Max(previousMemoryDate, onDiskSaveFormat);
                    long lowest  = Math.Min(previousMemoryDate, onDiskSaveFormat);
                    if (highest == 0 || lowest == 0)
                    {
                        return;
                    }
                    dateDifference = highest - lowest;
                    Console.WriteLine(highest + " - " + lowest + " = " + dateDifference);
                }
                #endregion



                // This happens when the game is saving AND the on disk date is equal to the date in memory (probably never going to happen but better safe than sorry).
                if (dateDifference <= 0)
                {
                    return;
                }

                if (dateDifference < Properties.Settings.Default.ReadOnlyDifference)
                {
                    return;
                }


                RunCommand("say {0}", Properties.Settings.Default.ReadOnlyText);

                #endregion
            }
            catch (IOException ioexc)
            {
                // Ignore "Pipe Interrupted/Broken" exception
                if (ioexc.HResult.ToString("X") != "80131620")
                {
                    //Debugger.Break();
                }
            }
            catch (Exception ex)
            {
                Debugger.Break();
            }

            #endregion
        }