private void Form_Shown(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; ListBooks.BeginUpdate(); ListSpecialChars.BeginUpdate(); if (TryOpen(path, out archive) && BackupMeta.TryRead(archive, out meta)) { foreach (var book in meta.Books) { var fullName = BackupMeta.ExpandPath(book.VhfPath); ListBooks.Items.Add(CbAbsolutePath.Checked ? fullName : Path.GetFileNameWithoutExtension(fullName), true); } foreach (var specialChar in meta.SpecialChars) { ListSpecialChars.Items.Add(specialChar, true); } } else { DialogResult = DialogResult.Abort; Close(); } ListBooks.EndUpdate(); ListSpecialChars.EndUpdate(); Cursor.Current = Cursors.Default; }
private void CbAbsolutePath_CheckedChanged(object sender, EventArgs e) { for (var i = 0; i < meta.Books.Count; i++) { var fullName = BackupMeta.ExpandPath(meta.Books[i].VhfPath); ListBooks.Items[i] = CbAbsolutePath.Checked ? fullName : Path.GetFileNameWithoutExtension(fullName); } }
private void BtnRestore_Click(object sender, EventArgs e) { int restored = 0, skipped = 0, failed = 0; void stats(RestoreResult result) { switch (result) { case RestoreResult.Success: restored++; break; case RestoreResult.Skipped: skipped++; break; case RestoreResult.Error: failed++; break; } } for (var i = 0; i < meta.Books.Count; i++) { if (!ListBooks.GetItemChecked(i)) { continue; } var item = meta.Books[i]; var destination = new FileInfo(BackupMeta.ExpandPath(item.VhfPath)); var result = Restore(archive, $"vhf\\{item.FileId}.vhf", destination, GetOverrideMode()); stats(result); if (result == RestoreResult.Success && RbRestoreAssociatedResults.Checked && !string.IsNullOrWhiteSpace(item.VhrCode)) { var resultDestination = new FileInfo(Path.Combine(Settings.Default.VhrPath, item.VhrCode)); stats(Restore(archive, $"vhr\\{item.VhrCode}.vhr", resultDestination, GetOverrideMode())); } } if (RbRestoreAllResults.Checked) { for (var i = 0; i < meta.Results.Count; i++) { var destination = new FileInfo(Path.Combine(Settings.Default.VhrPath, meta.Results[i])); stats(Restore(archive, "vhr\\" + meta.Results[i], destination, GetOverrideMode())); } } for (var i = 0; i < meta.SpecialChars.Count; i++) { if (!ListSpecialChars.GetItemChecked(i)) { continue; } var destination = new FileInfo(Path.Combine(AppInfo.SpecialCharDirectory, meta.SpecialChars[i])); stats(Restore(archive, "chars\\" + meta.SpecialChars[i], destination, GetOverrideMode())); } MessageBox.Show(string.Format(Messages.VdpRestored, restored, skipped, failed), Messages.VdpRestoredT, MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); }