// Run button, read the cardfile & write it out as XML private void b_go_Click(object sender, EventArgs e) { string stsMsg = "File " + filename + " had a problem"; // status message rtb_Msg.Text = "Export pressed"; try { FileInfo f = new FileInfo(filename); // card file file to read string outPath = Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar; // path of file to be read string outFileName = Path.GetFileNameWithoutExtension(filename); const string xmlext = ".xml"; string xmlFilePath = outPath + outFileName + xmlext; Writer wrtr = new XmlWriter(xmlFilePath); // Destination of Xml produced bool doTrace = cbDoLogging.Checked; // Logging? const string logext = ".log"; string logFilePath = outPath + outFileName + logext;; CardFile cf = new CardFile(doTrace, logFilePath, wrtr); using (Stream inStrm = f.OpenRead()) { cf.process(inStrm); } rtb_Msg.Text = "File " + xmlFilePath + " produced"; } catch (ExnCardFileRdr ex) { ReportError(ex.Message, "Warning", stsMsg); } catch (Exception ex) when(ex is FileNotFoundException || ex is DirectoryNotFoundException) { ReportError(ex.Message, "Warning", stsMsg); } catch (Exception ex) { ReportError(ex.ToString(), "Error", stsMsg); } //try } //b_go
public override void Import(KeePassLib.PwDatabase pwStorage, System.IO.Stream sInput, IStatusLogger slLogger) { if (pwStorage == null) { throw new ArgumentNullException("CardFileFormatProvider.Import(): null PwDatabase argument received"); } if (!pwStorage.IsOpen) { MessageBox.Show("You first need to open a database!", "CardFileFormatProvider"); return; } if (sInput == null) { throw new ArgumentNullException("CardFileFormatProvider.Import(): null Stream argument received"); } if (slLogger == null) { throw new ArgumentNullException("CardFileFormatProvider.Import(): null IStatusLogger argument received"); } if (!(sInput.CanRead)) { throw new ArgumentException("Input stream not readable"); } try { KPWriter kpWriter = new KPWriter(pwStorage); // The plugin's Keepass Writer CardFile crdfile = new CardFile(false, String.Empty, kpWriter); // The plugin's Importer, false = no logging slLogger.SetText("Importing Cardfile ...", LogStatusType.Info); crdfile.process(sInput); // read the cardfile & write to keepass m_Host.MainWindow.UpdateUI(false, null, true, m_Host.Database.RootGroup, true, null, true); slLogger.SetText("Importing Cardfile completed", LogStatusType.Info); } catch (ExnCardFileRdr ex) { reportError(ex.Message, "Warning", slLogger, LogStatusType.Warning); } catch (FileNotFoundException ex) { reportError(ex.Message, "Warning", slLogger, LogStatusType.Warning); } catch (DirectoryNotFoundException ex) { reportError(ex.Message, "Warning", slLogger, LogStatusType.Warning); } catch (Exception ex) { reportError(ex.ToString(), "Error", slLogger, LogStatusType.Error); } //try }