/// <summary> /// Import a file as note. /// </summary> /// <param name="sender">Sender object</param> /// <param name="e">Event arguments</param> private void importToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofdlgimportnote = new OpenFileDialog(); StringBuilder sbfilter = new StringBuilder(); sbfilter.Append(Strings.T("Plain text file (*.txt)")).Append("|*.txt|"); sbfilter.Append(Strings.T("RTF file (*.rtf)")).Append("|*.rtf|"); sbfilter.Append(Strings.T("KeyNote NF note (*.knt)")).Append("|*.knt|"); sbfilter.Append(Strings.T("TomBoy note (*.note)")).Append("|*.note|"); sbfilter.Append(Strings.T("MicroSE note (*.not)")).Append("|*.not|"); sbfilter.Append(Strings.T("QuickPad note (*.qpn)")).Append("|*.qpn"); ofdlgimportnote.Filter = sbfilter.ToString(); ofdlgimportnote.Title = Strings.T("import single (note)file"); DialogResult dlgresopennote = ofdlgimportnote.ShowDialog(); if (dlgresopennote == DialogResult.OK) { StreamReader reader = null; try { if (File.Exists(ofdlgimportnote.FileName)) { reader = new StreamReader(ofdlgimportnote.FileName, true); // detect encoding ImportNotes importnote = new ImportNotes(this.notes); switch (ofdlgimportnote.FilterIndex) { case 1: importnote.ReadTextfile(reader, this.rtbNewNote); break; case 2: importnote.ReadRTFfile(reader, this.rtbNewNote); break; case 3: importnote.ReadKeyNotefile(reader, this.rtbNewNote); break; case 4: importnote.ReadTomboyfile(reader, ofdlgimportnote.FileName, this.tbTitle, this.rtbNewNote); break; case 5: importnote.ReadMicroSENotefile(reader, this.tbTitle, this.rtbNewNote); break; case 6: importnote.ReadQuickpadFile(reader, this.tbTitle, this.rtbNewNote); break; } } } finally { reader.Close(); } } }
/// <summary> /// Ask and import notes from NoteFly 1.0.x if application data folder of NoteFly 1.0.x exist. /// </summary> /// <returns>True if imported done, false if importing notefly 1.0.x notes not nessesary.</returns> private bool ImportingNotesNoteFly1() { bool imported = false; string nf1appdata = string.Empty; if (Program.CurrentOS == Program.OS.WINDOWS) { nf1appdata = Path.Combine(System.Environment.GetEnvironmentVariable("APPDATA"), ".NoteFly"); } else if (Program.CurrentOS == Program.OS.LINUX) { nf1appdata = Path.Combine(System.Environment.GetEnvironmentVariable("HOME"), ".NoteFly"); } if (Directory.Exists(nf1appdata) && (!File.Exists(Path.Combine(nf1appdata, IMPORTEDFLAGFILE)))) { DialogResult resdoimport = MessageBox.Show(Strings.T( "Do you want to import the notes from NoteFly 1.0.x?\nPress cancel to ask this again next time."), Strings.T("Import from NoteFly 1.0.x"), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (resdoimport == DialogResult.Yes) { string nf1settingsfile = Path.Combine(nf1appdata, "settings.xml"); string nf1notesavepath = xmlUtil.GetContentString(nf1settingsfile, "notesavepath"); int noteid = 1; ImportNotes importnotes = new ImportNotes(this); string nf1notefile = Path.Combine(nf1notesavepath, noteid + ".xml"); while (File.Exists(nf1notefile)) { nf1notefile = Path.Combine(nf1notesavepath, noteid + ".xml"); importnotes.ReadNoteFly1Note(nf1notefile); noteid++; } this.CreateNotesImportedFlagfile(nf1appdata); imported = true; Log.Write(LogType.info, "Notes from NoteFly 1.0.x imported."); } else if (resdoimport == DialogResult.No) { this.CreateNotesImportedFlagfile(nf1appdata); Log.Write(LogType.info, "Notes from NoteFly 1.0.x will not be imported."); } } return(imported); }