private void buttonImport_Click(object sender, EventArgs e) { if (buttonImport.Enabled) { FileExporter io; if (radioIAStash.Checked) { io = new IAFileExporter(_filename); } else if (radioGDStash.Checked) { GDTransferFile settings = cbItemSelection.SelectedItem as GDTransferFile; if (settings == null) { io = new GDFileExporter(_filename, false, string.Empty); } else { io = new GDFileExporter(_filename, settings.IsExpansion1, settings.Mod); } } else { _playerItemDao.Save(_sm.EmptyStash(_filename)); MessageBox.Show("Items imported", "Items imported!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } var items = io.Read(); _playerItemDao.Import(items); MessageBox.Show("Items imported\nIf you already had items, you may have gotten duplicates.", "Items imported!", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public void CanWriteItems() { var items = new List <PlayerItem>(); for (int i = 0; i < 4; i++) { items.Add(new PlayerItem { BaseRecord = "records/br1" }); } using (var file = new TempFile()) { var exporter = new IAFileExporter(file.filename); exporter.Write(items); /* * // Byte wise compare * byte[] written = File.ReadAllBytes(file.filename); * byte[] read = File.ReadAllBytes(file.filename); * written.Length.Should().Be.EqualTo(read.Length); * * for (int i = 0; i < written.Length; i++) { * written[i].Should().Be.EqualTo(read[i]); * }*/ // TOOD: Is this proper? its read related testing.. var verifiy = exporter.Read(); verifiy.Count.Should().Be.EqualTo(items.Count); foreach (var item in verifiy) { item.BaseRecord.Should().StartWith("records/"); } } }
public void WriteItemsForSillyPeople() { Random r = new Random(); var items = new List <PlayerItem>(); for (int i = 0; i < 8; i++) { var item = new PlayerItem() { Count = 1, //PrefixRecord = "records/items/lootaffixes/prefix/b_class021_shaman19_je_c.dbr", BaseRecord = "records/items/gearhead/c034_head.dbr", //SuffixRecord = "records/items/lootaffixes/suffix/a031d_off_dmg%lightning_07_we2h.dbr", Seed = r.Next() }; items.Add(item); } var path = @"f:\temp\export.ias"; var exporter = new IAFileExporter(path); exporter.Write(items); var verifiy = exporter.Read(); verifiy.Count.Should().Be.EqualTo(items.Count); }
private void buttonImport_Click(object sender, EventArgs e) { if (buttonImport.Enabled) { FileExporter io; if (radioIAStash.Checked) { io = new IAFileExporter(_filename); } else if (radioGDStash.Checked) { GDTransferFile settings = cbItemSelection.SelectedItem as GDTransferFile; io = new GDFileExporter(_filename, settings?.Mod ?? string.Empty); } else { _playerItemDao.Save(_sm.EmptyStash(_filename)); MessageBox.Show( RuntimeSettings.Language.GetTag("iatag_ui_importexport_import_success"), RuntimeSettings.Language.GetTag("iatag_ui_importexport_import_success"), MessageBoxButtons.OK, MessageBoxIcon.Information ); return; } var items = io.Read(Read(_filename)); Logger.Debug($"Storing {items.Count} items to db"); progressBar1.Maximum = items.Count; buttonImport.Enabled = false; Thread t = new Thread(() => { ExceptionReporter.EnableLogUnhandledOnThread(); isLocked = true; var batches = BatchUtil.ToBatches <PlayerItem>(items); foreach (var batch in batches) { _playerItemDao.Import(batch); Invoke((MethodInvoker) delegate { progressBar1.Value += batch.Count; }); } isLocked = false; MessageBox.Show( RuntimeSettings.Language.GetTag("iatag_ui_importexport_import_success_body"), RuntimeSettings.Language.GetTag("iatag_ui_importexport_import_success"), MessageBoxButtons.OK, MessageBoxIcon.Information ); }); t.Start(); } }
private void buttonExport_Click(object sender, EventArgs e) { if (buttonExport.Enabled) { if (IsGdstashFormat) { var io = new GDFileExporter(filename, false, string.Empty); // Params are not used for writing GDTransferFile settings = cbItemSelection.SelectedItem as GDTransferFile; if (settings == null) { var items = playerItemDao.ListAll(); io.Write(items); } else { var items = playerItemDao.ListAll() .Where(item => item.IsHardcore == settings.IsHardcore /* && item.IsExpansion1 == settings.IsExpansion1*/); if (string.IsNullOrEmpty(settings.Mod)) { io.Write(items.Where(item => string.IsNullOrEmpty(item.Mod)).ToList()); } else { io.Write(items.Where(item => item.Mod == settings.Mod).ToList()); } } } else { var io = new IAFileExporter(filename); var items = playerItemDao.ListAll(); io.Write(items); } MessageBox.Show("Items Exported!", "Items exported!", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } }
private void buttonImport_Click(object sender, EventArgs e) { if (buttonImport.Enabled) { FileExporter io; if (radioIAStash.Checked) { io = new IAFileExporter(_filename); } else if (radioGDStash.Checked) { GDTransferFile settings = cbItemSelection.SelectedItem as GDTransferFile; io = new GDFileExporter(_filename, settings?.Mod ?? string.Empty); } else { _playerItemDao.Save(_sm.EmptyStash(_filename)); MessageBox.Show( RuntimeSettings.Language.GetTag("iatag_ui_importexport_import_success"), RuntimeSettings.Language.GetTag("iatag_ui_importexport_import_success"), MessageBoxButtons.OK, MessageBoxIcon.Information ); return; } var items = io.Read(Read(_filename)); _playerItemDao.Import(items); MessageBox.Show( RuntimeSettings.Language.GetTag("iatag_ui_importexport_import_success_body"), RuntimeSettings.Language.GetTag("iatag_ui_importexport_import_success"), MessageBoxButtons.OK, MessageBoxIcon.Information ); } }
private void Backup(string destination, bool forced) { if (!Directory.Exists(destination)) { Directory.CreateDirectory(destination); } #if DEBUG var suffix = "_DEBUG"; #else var suffix = string.Empty; #endif string target = Path.Combine(destination, string.Format("{0}{1}.zip", DateTime.Now.DayOfWeek, suffix)); // If the file already exists and is newer than 3 days ('not written today'), just skip it. if (File.Exists(target) && !forced) { DateTime lastModified = File.GetLastWriteTime(target); if ((DateTime.Now - lastModified).TotalDays < 3) { return; } } using (var file = new TempFile()) { using (ZipFile zip = new ZipFile { UseZip64WhenSaving = Zip64Option.AsNecessary }) { Logger.Info("Backing up characters.."); string gameSaves = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "My Games", "Grim Dawn", "Save"); if (Directory.Exists(gameSaves)) { zip.AddDirectory(gameSaves, "Save"); } Logger.Info("Backing up items.."); var exporter = new IAFileExporter(file.filename); exporter.Write(_playerItemDao.ListAll()); zip.AddFile(file.filename).FileName = "export.ias"; /* * try { * // TODO: This is now redundant, but leaving it in here "for safety" until the IAS format has proven itself. * zip.AddDirectory(GlobalPaths.UserdataFolder, "IAGD"); * } * catch (Exception ex) { * Logger.Warn(ex.Message); * Logger.Warn(ex.StackTrace); * ExceptionReporter.ReportException(ex); * }*/ string helpfile = Path.Combine("Resources", "YES THIS FILE IS SUPPOSED TO BE SMALL.txt"); if (File.Exists(helpfile)) { zip.AddFile(helpfile, ""); } zip.Comment = string.Format("This backup was created at {0}.", System.DateTime.Now.ToString("G")); try { zip.Save(target); } catch (UnauthorizedAccessException) { Logger.WarnFormat("Access denied writing backup to \"{0}\"", target); throw; } Logger.Info("Created a new backup of the database"); } // } }
private void Backup(string destination, bool forced) { if (!Directory.Exists(destination)) { Directory.CreateDirectory(destination); } #if DEBUG var suffix = "_DEBUG"; #else var suffix = string.Empty; #endif string target = Path.Combine(destination, $"{DateTime.Now.DayOfWeek}{suffix}.zip"); // If the file already exists and is newer than 3 days ('not written today'), just skip it. if (File.Exists(target) && !forced) { DateTime lastModified = File.GetLastWriteTime(target); if ((DateTime.Now - lastModified).TotalDays < 3) { return; } } var items = _playerItemDao.ListAll(); if (items.Count == 0) { Logger.Warn("No items found, skipping backup to avoid overwriting existing good backups."); return; } using (var file = new TempFile()) { using (ZipFile zip = new ZipFile { UseZip64WhenSaving = Zip64Option.AsNecessary }) { Logger.Info("Backing up characters.."); string[] files = Directory.GetFiles(GlobalPaths.SavePath, "*.*", SearchOption.AllDirectories); foreach (var f in files) { if (!IsAcceptedFileFormat(f)) { Logger.Debug($"Ignoring file {f}, invalid file format."); continue; } // Max 1MB if (new FileInfo(f).Length > 1024 * 1024) { Logger.Debug($"Ignoring file {f}, size exceeds 1MB"); continue; } var relativePath = f.Replace(GlobalPaths.SavePath, "").Replace(Path.GetFileName(f), ""); zip.AddFile(f, relativePath); } Logger.Info("Backing up items.."); var exporter = new IAFileExporter(file.filename); exporter.Write(items); zip.AddFile(file.filename).FileName = "export.ias"; string helpfile = Path.Combine("Resources", "YES THIS FILE IS SUPPOSED TO BE SMALL.txt"); if (File.Exists(helpfile)) { zip.AddFile(helpfile, ""); } zip.Comment = string.Format("This backup was created at {0}.", System.DateTime.Now.ToString("G")); try { zip.Save(target); } catch (UnauthorizedAccessException) { Logger.WarnFormat("Access denied writing backup to \"{0}\"", target); throw; } Logger.Info("Created a new backup of the database"); } // } }
private void Backup(string destination, bool forced) { if (!Directory.Exists(destination)) { Directory.CreateDirectory(destination); } #if DEBUG var suffix = "_DEBUG"; #else var suffix = string.Empty; #endif string target = Path.Combine(destination, $"{DateTime.Now.DayOfWeek}{suffix}.zip"); // If the file already exists and is newer than 3 days ('not written today'), just skip it. if (File.Exists(target) && !forced) { DateTime lastModified = File.GetLastWriteTime(target); if ((DateTime.Now - lastModified).TotalDays < 3) { return; } } using (var file = new TempFile()) { using (ZipFile zip = new ZipFile { UseZip64WhenSaving = Zip64Option.AsNecessary }) { Logger.Info("Backing up characters.."); string gameSaves = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "My Games", "Grim Dawn", "Save"); string[] files = Directory.GetFiles(gameSaves, "*.*", SearchOption.AllDirectories); foreach (var f in files) { if (f.EndsWith(".zip") || f.EndsWith(".ias") || f.EndsWith(".gds") || f.EndsWith(".rar")) { continue; } // Max 10MB if (new FileInfo(f).Length > 1024 * 1024 * 10) { continue; } zip.AddFile(f); } Logger.Info("Backing up items.."); var exporter = new IAFileExporter(file.filename); exporter.Write(_playerItemDao.ListAll()); zip.AddFile(file.filename).FileName = "export.ias"; string helpfile = Path.Combine("Resources", "YES THIS FILE IS SUPPOSED TO BE SMALL.txt"); if (File.Exists(helpfile)) { zip.AddFile(helpfile, ""); } zip.Comment = string.Format("This backup was created at {0}.", System.DateTime.Now.ToString("G")); try { zip.Save(target); } catch (UnauthorizedAccessException) { Logger.WarnFormat("Access denied writing backup to \"{0}\"", target); throw; } Logger.Info("Created a new backup of the database"); } // } }