public void LoadNotebook(EncrytedNotebook Notebook) { StripMenu.AddFile((string)Settings.Default["CurrentFile"]); StripMenu.SaveToRegistry(); Content.Controls.Clear(); this.Notebook = new NotebookHandler(); this.Notebook.tabControl.SelectedIndexChanged += TopBarEventHandler.TabControl_SelectedIndexChanged; int i = 0; foreach (EncryptedPage Page in Notebook.EncryptedPages) { this.Notebook.Pages.Add(new TabPage()); this.Notebook.TextBoxes.Add(new RichTextBox()); this.Notebook.Pages[i].Text = Page.Title; this.Notebook.Pages[i].UseVisualStyleBackColor = true; this.Notebook.Pages[i].Controls.Add(this.Notebook.TextBoxes[i]); this.Notebook.TextBoxes[i].Rtf = Page.Contents.Data; this.Notebook.TextBoxes[i].Dock = DockStyle.Fill; this.Notebook.tabControl.Controls.Add(this.Notebook.Pages[i]); i++; } this.Notebook.tabControl.Dock = DockStyle.Fill; Content.Controls.Add(this.Notebook.tabControl); RenameStripMenuItem.Enabled = true; CreateEmptyTab("New Tab"); }
private void OpenToolStripMenuItem_Click(object sender, EventArgs e) { UI.OpenFileFileDialog.ShowDialog(); if (UI.OpenFileFileDialog.FileName == "") { return; } Settings.Default["CurrentFile"] = UI.OpenFileFileDialog.FileName; Settings.Default.Save(); if ((string)Settings.Default["KeyFilePath"] == "" || !File.Exists((string)Settings.Default["KeyFilePath"])) { MessageBox.Show("Please Select or Create a new Key in Settings"); return; } UI.CurrentFile = new FileInfo((string)Settings.Default["CurrentFile"]); switch (UI.CurrentFile.Extension) { case ".jed": UI.IsNotebook = false; EncryptedData Data = new EncryptedData { Data = File.ReadAllText((string)Settings.Default["CurrentFile"]) }; Data.Data = Encryption.Decrypt(Data.Data, JsonConvert.DeserializeObject <KeyFile>(File.ReadAllText((string)Settings.Default["KeyFilePath"])), (int)Settings.Default["Iterations"]); UI.LoadFile(Data); break; case ".jen": UI.IsNotebook = true; EncrytedNotebook Notebook = JsonConvert.DeserializeObject <EncrytedNotebook>(Encryption.Decrypt(File.ReadAllText((string)Settings.Default["CurrentFile"]), JsonConvert.DeserializeObject <KeyFile>(File.ReadAllText((string)Settings.Default["KeyFilePath"])), (int)Settings.Default["Iterations"])); UI.LoadNotebook(Notebook); break; } }
private void MainWindow_Load(object sender, EventArgs e) { StripMenu = TopBarEventHandler.BindEventHandlers(this); if ((string)Settings.Default["KeyFilePath"] == "" || !File.Exists((string)Settings.Default["KeyFilePath"])) { MessageBox.Show("Please Select or Create a new Key in Settings"); return; } if ((string)Settings.Default["CurrentFile"] != "" && (string)Settings.Default["CurrentFile"] != null) { CurrentFile = new FileInfo((string)Settings.Default["CurrentFile"]); if (CurrentFile.Extension == ".jed" || CurrentFile.Extension == ".jen") { switch (CurrentFile.Extension) { case ".jed": IsNotebook = false; Data = new EncryptedData { Data = Encryption.Decrypt(File.ReadAllText((string)Settings.Default["CurrentFile"]), JsonConvert.DeserializeObject <KeyFile>(File.ReadAllText((string)Settings.Default["KeyFilePath"])), (int)Settings.Default["Iterations"]) }; LoadFile(Data); break; case ".jen": IsNotebook = true; EncrytedNotebook Notebook = JsonConvert.DeserializeObject <EncrytedNotebook>(Encryption.Decrypt(File.ReadAllText((string)Settings.Default["CurrentFile"]), JsonConvert.DeserializeObject <KeyFile>(File.ReadAllText((string)Settings.Default["KeyFilePath"])), (int)Settings.Default["Iterations"])); LoadNotebook(Notebook); break; } } } }
private void NewNotebookStripMenuItem3_Click(object sender, EventArgs e) { UI.NewNotebookFileDialog.ShowDialog(); EncrytedNotebook notebook = new EncrytedNotebook(); notebook.EncryptedPages.Add(new EncryptedPage()); notebook.EncryptedPages[0].Title = "Page 1"; notebook.EncryptedPages[0].Contents = new EncryptedData { Data = "", Box = null }; if (UI.NewNotebookFileDialog.FileName == null || UI.NewNotebookFileDialog.FileName == "") { return; } StreamWriter file = File.CreateText(UI.NewNotebookFileDialog.FileName); string jsonString; jsonString = JsonConvert.SerializeObject(notebook); jsonString = Encryption.Encrypt(jsonString, JsonConvert.DeserializeObject <KeyFile>(File.ReadAllText((string)Settings.Default["KeyFilePath"])), (int)Settings.Default["Iterations"]); file.Write(jsonString); file.Close(); Settings.Default["CurrentFile"] = UI.NewNotebookFileDialog.FileName; Settings.Default.Save(); UI.IsNotebook = true; EncrytedNotebook Notebook = JsonConvert.DeserializeObject <EncrytedNotebook>(Encryption.Decrypt(File.ReadAllText((string)Settings.Default["CurrentFile"]), JsonConvert.DeserializeObject <KeyFile>(File.ReadAllText((string)Settings.Default["KeyFilePath"])), (int)Settings.Default["Iterations"])); UI.LoadNotebook(Notebook); }
private void ClickedHandler(int number, string FileName) { if (FileName == "" || !File.Exists(FileName)) { MessageBox.Show("Please Select or Create a new Key in Settings"); return; } Settings.Default["CurrentFile"] = FileName; if ((string)Settings.Default["CurrentFile"] != "" && (string)Settings.Default["CurrentFile"] != null) { FileInfo CurrentFile = new FileInfo(FileName); if (CurrentFile.Extension == ".jed" || CurrentFile.Extension == ".jen") { switch (CurrentFile.Extension) { case ".jed": UI.IsNotebook = false; UI.Data = new EncryptedData { Data = Encryption.Decrypt(File.ReadAllText((string)Settings.Default["CurrentFile"]), JsonConvert.DeserializeObject <KeyFile>(File.ReadAllText((string)Settings.Default["KeyFilePath"])), (int)Settings.Default["Iterations"]) }; UI.LoadFile(UI.Data); break; case ".jen": UI.IsNotebook = true; EncrytedNotebook Notebook = JsonConvert.DeserializeObject <EncrytedNotebook>(Encryption.Decrypt(File.ReadAllText((string)Settings.Default["CurrentFile"]), JsonConvert.DeserializeObject <KeyFile>(File.ReadAllText((string)Settings.Default["KeyFilePath"])), (int)Settings.Default["Iterations"])); UI.LoadNotebook(Notebook); break; } } } }
public static void Save(MainWindow UI) { if ((string)Settings.Default["KeyFilePath"] == "" || !File.Exists((string)Settings.Default["KeyFilePath"])) { MessageBox.Show("Please Select or Create a new Key in Settings"); return; } if ((string)Settings.Default["CurrentFile"] != "") { FileInfo CurrentFile = new FileInfo((string)Settings.Default["CurrentFile"]); if (CurrentFile.Extension == ".jed" || CurrentFile.Extension == ".jen") { switch (CurrentFile.Extension) { case ".jed": StreamWriter file = File.CreateText((string)Settings.Default["CurrentFile"]); string Data = UI.Data.Box.Rtf; Data = Encryption.Encrypt(Data, JsonConvert.DeserializeObject <KeyFile>(File.ReadAllText((string)Settings.Default["KeyFilePath"])), (int)Settings.Default["Iterations"]); file.Write(Data); file.Close(); break; case ".jen": EncrytedNotebook Buffer = new EncrytedNotebook(); int i = 0; foreach (RichTextBox Page in UI.Notebook.TextBoxes) { if (Page.Text != "" || UI.Notebook.Pages[i].Text != "New Tab") { EncryptedPage PageBuffer = new EncryptedPage { Contents = new EncryptedData { Data = Page.Rtf, Box = null }, Title = UI.Notebook.Pages[i].Text }; Buffer.EncryptedPages.Add(PageBuffer); } i++; } using (StreamWriter fileHandler = File.CreateText((string)Settings.Default["CurrentFile"])) { string jsonString; jsonString = JsonConvert.SerializeObject(Buffer); jsonString = Encryption.Encrypt(jsonString, JsonConvert.DeserializeObject <KeyFile>(File.ReadAllText((string)Settings.Default["KeyFilePath"])), (int)Settings.Default["Iterations"]); fileHandler.Write(jsonString); fileHandler.Close(); } break; } } else { MessageBox.Show("The File you have open is not a valid File Type"); return; } } }