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); } }
private string GetNewSaveFolder(string name) { //C:\Users\username\AppData\Roaming\Asteroid Miner\Flying Beans\Session 2013-02-16 15.20.00.000\Save 2013-02-16 15.20.000 string timestamp = DateTime.Now.ToString(TIMESTAMPFORMAT); // Session folder if (this.SessionFolder == null) { string baseFolder = UtilityCore.GetOptionsFolder(); baseFolder = System.IO.Path.Combine(baseFolder, FlyingBeansWindow.OPTIONSFOLDER); if (!Directory.Exists(baseFolder)) { Directory.CreateDirectory(baseFolder); } this.SessionFolder = System.IO.Path.Combine(baseFolder, FlyingBeansWindow.SESSIONFOLDERPREFIX + " " + timestamp); } if (!Directory.Exists(this.SessionFolder)) { Directory.CreateDirectory(this.SessionFolder); } // Save folder //NOTE: This class doesn't store the current save folder, just the parent session string retVal = System.IO.Path.Combine(this.SessionFolder, FlyingBeansWindow.SAVEFOLDERPREFIX + " " + timestamp); if (!string.IsNullOrEmpty(name)) { retVal += " " + FlyingBeanSession.EscapeFilename(name); } Directory.CreateDirectory(retVal); // Exit Function return(retVal); }