public static void importCharSave(TH1SaveStructure save) { bool alreadylisted = false; Directory.CreateDirectory("saves"); if (save.lastError == 0) { // Generate list ObservableCollection <CharListImages> list = (ObservableCollection <CharListImages>)MainWindow._CharactersUC.lstCharacters.ItemsSource; CharListImages item = new CharListImages(); TH1Helper ca = new TH1Helper(); // Generate item item.hash = BitConverter.ToString(save.hash).Replace("-", ""); item.name = save.character.name; item.exp = save.character.exp.ToString("N0"); item.level = save.character.level; item.importedon = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); item.bounty = save.character.bounty.ToString("N0"); item.cclass = ca.classNamesArray[save.character.charClass]; item.calign = ca.alignmentNamesArray[save.character.alignment]; item.image = classToImage(save.character.charClass); item.lastplayed = save.character.lastSave.ToString(); // Backup save item.path = @"saves\" + item.hash + ".th1"; save.writeSaveFile(item.path); // Check if already in the list for (int i = 0; i < list.Count; i++) { if (list[i].hash == item.hash) { alreadylisted = true; list[i] = item; } } // Save list if (!alreadylisted) { list.Insert(0, item); } } }
private void btnExport_Click(object sender, RoutedEventArgs e) { if (validateInputs()) { Functions.log("Editor Validated.", Functions.LC_SUCCESS); // saveAll(); // Dead! // Show Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.FileName = "Too Human SaveGame"; // Default file name dlg.DefaultExt = ".txt"; // Default file extension dlg.Filter = "savegame|*.txt"; // Filter files by extension dlg.FileName = "savegame.txt"; // Default Filename // Show save file dialog box Nullable <bool> result = dlg.ShowDialog(); // Process save file dialog box results if (result == true) { // Save document _save.character.lastSave = DateTime.UtcNow; _save.writeSaveFile(dlg.FileName); loadSectorsTab(); if (_save.lastError != 0) { MessageBox.Show("Unable To Save The Current File due To An Error:\r\n------\r\n" + _save.lastErrorMsg, "An Error Has Occured", MessageBoxButton.OK, MessageBoxImage.Error); Functions.log("An Attempt To Save Has Failed. Error #" + _save.lastError, Functions.LC_CRITICAL); _save.clearError(); return; } } } else { Functions.log("Editor Contains Invalid Entries. Saving Cancelled.", Functions.LC_CRITICAL); } }