Ejemplo n.º 1
0
        //TODO: Rework this class to use SessionSaveLoad.cs
        public static void Save(string baseFolder, string saveFolder, FlyingBeanSession session, FlyingBeanOptions options, ItemOptions itemOptions)
        {
            // Session
            //NOTE: This is in the base folder
            UtilityCore.SerializeToFile(Path.Combine(baseFolder, FILENAME_SESSION), session);

            // ItemOptions
            UtilityCore.SerializeToFile(Path.Combine(saveFolder, FILENAME_ITEMOPTIONS), itemOptions);

            // Options
            FlyingBeanOptions optionCloned = UtilityCore.Clone(options);

            optionCloned.DefaultBeanList = null;                // this is programatically generated, no need to save it
            //optionCloned.NewBeanList		//NOTE: These will be serialized with the options file

            SortedList <string, ShipDNA> winningFilenames;
            SortedList <string, double>  maxScores;

            ExtractHistory(out winningFilenames, out maxScores, options.WinnersFinal);          // can't use cloned.winners, that property is skipped when serializing
            optionCloned.WinningScores = maxScores;

            // Main class
            UtilityCore.SerializeToFile(Path.Combine(saveFolder, FILENAME_OPTIONS), optionCloned);

            // Winning beans
            if (winningFilenames != null)
            {
                foreach (string beanFile in winningFilenames.Keys)
                {
                    UtilityCore.SerializeToFile(Path.Combine(saveFolder, beanFile), winningFilenames[beanFile]);
                }
            }
        }
Ejemplo n.º 2
0
        private void btnSaveSession_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                EncogOCR_Session session = new EncogOCR_Session()
                {
                    ImageSize = _pixels,
                    Sketches  = _prevSketches.ToArray(),
                };

                //C:\Users\<username>\AppData\Roaming\Asteroid Miner\EncogOCR\
                string foldername = UtilityCore.GetOptionsFolder();
                foldername = System.IO.Path.Combine(foldername, FOLDER);
                Directory.CreateDirectory(foldername);

                string filename = DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss.fff - ");
                filename += cboSession.Text + ".xml";       //TODO: convert illegal chars
                filename  = System.IO.Path.Combine(foldername, filename);

                UtilityCore.SerializeToFile(filename, session);

                LoadSessionsCombobox();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 3
0
        private void SaveBell3Map_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Point[] points = GetBellPoints(txtBell3.Text);
                if (points == null)
                {
                    MessageBox.Show("Invalid control points", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                //C:\Users\<username>\AppData\Roaming\Asteroid Miner\NonlinearRandom\
                string foldername = UtilityCore.GetOptionsFolder();
                foldername = System.IO.Path.Combine(foldername, FOLDER);
                Directory.CreateDirectory(foldername);

                string filename = DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss.fff - ");
                filename += BELL3;
                filename  = System.IO.Path.Combine(foldername, filename);

                UtilityCore.SerializeToFile(filename, points);

                RebuildBell3Combo();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 4
0
        public static void SaveShip(ShipDNA ship)
        {
            // Make sure the folder exists
            string foldername = System.IO.Path.Combine(UtilityCore.GetOptionsFolder(), SHIPFOLDER);

            if (!Directory.Exists(foldername))
            {
                Directory.CreateDirectory(foldername);
            }

            int infiniteLoopDetector = 0;

            while (true)
            {
                char[] illegalChars = System.IO.Path.GetInvalidFileNameChars();
                string filename     = new string(ship.ShipName.Select(o => illegalChars.Contains(o) ? '_' : o).ToArray());
                filename = DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss.fff") + " - " + filename + ".xml";
                filename = System.IO.Path.Combine(foldername, filename);

                try
                {
                    UtilityCore.SerializeToFile(filename, ship);
                    break;
                }
                catch (IOException ex)
                {
                    infiniteLoopDetector++;
                    if (infiniteLoopDetector > 100)
                    {
                        throw new ApplicationException("Couldn't create the file\r\n" + filename, ex);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This will save the state of a game/tester
        /// </summary>
        /// <remarks>
        /// Folder Structure:
        ///     baseFolder
        ///         "C:\Users\charlie.rix\AppData\Roaming\Asteroid Miner"
        ///         Only one file per tester here.  Each file is "testername Options.xml"
        ///         Each tester gets one child folder off of base
        ///
        ///     Game Folder
        ///         "C:\Users\charlie.rix\AppData\Roaming\Asteroid Miner\Flying Beans"
        ///         This folder holds custom files for this game.  It will also hold session subfolders (each session would be a different state)
        ///
        ///     Session Folders
        ///         "C:\Users\charlie.rix\AppData\Roaming\Asteroid Miner\Flying Beans\Session 2016-10-09 09.11.35.247"
        ///
        ///     Save Folders
        ///         "C:\Users\charlie.rix\AppData\Roaming\Asteroid Miner\Flying Beans\Session 2016-10-09 09.11.35.247\Save 2016-10-09 09.11.35.247 (auto)"
        ///         This is where all the save folders go.  Each save folder is for the parent session (there are many because backups should occur often)
        ///         When saving, it shouldn't overwrite an existing save, it should create a new save folder, then delete old ones as needed
        ///         If zipped is true, this will be a zip file instead of a folder
        /// </remarks>
        /// <param name="baseFolder">
        /// Use UtilityCore.GetOptionsFolder()
        /// "C:\Users\charlie.rix\AppData\Roaming\Asteroid Miner"
        /// </param>
        /// <param name="name">
        /// This is the name of the tester/game
        /// </param>
        /// <param name="session">
        /// This is the class that goes in the root folder
        /// NOTE: This method will set the LatestSessionFolder property
        /// </param>
        /// <param name="saveFiles">
        /// A set of files to put into the save folder (or zip file)
        /// Item1=Name of file (this method will ensure it ends in .xml)
        /// Item2=Object to serialize
        /// </param>
        /// <param name="zipped">
        /// This only affects the leaf save folder
        /// True: The save folder will be a zip file instead
        /// False: The save folder will be a standard folder containing files
        /// </param>
        public static void Save(string baseFolder, string name, ISessionOptions session, IEnumerable <Tuple <string, object> > saveFiles, bool zipped)
        {
            if (string.IsNullOrEmpty(session.LatestSessionFolder) || !Directory.Exists(session.LatestSessionFolder))
            {
                session.LatestSessionFolder = GetNewSessionFolderName(baseFolder, name);
            }

            #region root session file

            string rootSessionFilename = GetRootOptionsFilename(baseFolder, name);

            UtilityCore.SerializeToFile(rootSessionFilename, session);

            #endregion

            // Session Folder
            //NOTE: This will also create the game folder if it doesn't exist
            Directory.CreateDirectory(session.LatestSessionFolder);

            // Save Folder (or zip file)
            string saveFolder = GetNewSaveFolderName(session.LatestSessionFolder);
            if (zipped)
            {
                // Just tack on a .zip to the save folder name to turn it into a zip filename
                throw new ApplicationException("finish saving to zip file");
            }
            else
            {
                Save_Folder(saveFolder, saveFiles);
            }
        }
Ejemplo n.º 6
0
        private void Export_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //C:\Users\<username>\AppData\Roaming\Asteroid Miner\Miner2D\
                string foldername = UtilityCore.GetOptionsFolder();
                foldername = System.IO.Path.Combine(foldername, FOLDER);
                Directory.CreateDirectory(foldername);

                string filename = DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss.fff - ");

                if (_object_LinearVelocity != null)
                {
                    filename += "LinearVelocity.xml";
                    filename  = System.IO.Path.Combine(foldername, filename);

                    UtilityCore.SerializeToFile(filename, _object_LinearVelocity);
                }
                else if (_object_LinearForce != null)
                {
                    filename += "LinearForce.xml";
                    filename  = System.IO.Path.Combine(foldername, filename);

                    UtilityCore.SerializeToFile(filename, _object_LinearForce);
                }
                else if (_object_OrientationVelocity != null)
                {
                    filename += "OrientationVelocity.xml";
                    filename  = System.IO.Path.Combine(foldername, filename);

                    UtilityCore.SerializeToFile(filename, _object_OrientationVelocity);
                }
                else if (_object_OrientationForce != null)
                {
                    filename += "OrientationForce.xml";
                    filename  = System.IO.Path.Combine(foldername, filename);

                    UtilityCore.SerializeToFile(filename, _object_OrientationForce);
                }
                else
                {
                    MessageBox.Show("There were no settings to export", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 7
0
        private void btnExport_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Get the best of each bean type
                var topBeans = GetTopBeans();
                if (topBeans == null || topBeans.Length == 0)
                {
                    MessageBox.Show("There are no high scoring beans yet", MSGBOXCAPTION, MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                //TODO: May want to ask the user to pick one

                // Make sure the folder exists
                string foldername = PanelBeanTypes.EnsureShipFolderExists(BEANSUBFOLDER);

                string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss.fff");

                // Write a file for each
                foreach (var bean in topBeans)
                {
                    if (bean.Item2 == null)
                    {
                        throw new ApplicationException("ShipDNA should never be null from the finals list");
                    }

                    // Build up filename
                    string filename = timestamp + " - " + bean.Item1 + " - " + Math.Round(bean.Item3, 1).ToString();
                    if (txtExportName.Text != "")
                    {
                        filename += " (" + FlyingBeanSession.EscapeFilename(txtExportName.Text) + ")";
                    }

                    filename += ".xml";

                    filename = System.IO.Path.Combine(foldername, filename);

                    // Write it
                    UtilityCore.SerializeToFile(filename, bean.Item2);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), MSGBOXCAPTION, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 8
0
        private static void Save_Folder(string saveFolder, IEnumerable <Tuple <string, object> > saveFiles)
        {
            Directory.CreateDirectory(saveFolder);

            foreach (var saveFile in saveFiles)
            {
                string filename = saveFile.Item1;
                if (!filename.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
                {
                    filename += ".xml";
                }

                filename = Path.Combine(saveFolder, filename);

                UtilityCore.SerializeToFile(filename, saveFile.Item2);
            }
        }