From ad535144bd615622bdff6872833d4cce4c368802 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 21 Apr 2019 18:53:56 +0100 Subject: [PATCH] WIP --- BookmarkEditForm.Designer.cs | 4 + MainForm.Designer.cs | 26 +- MainForm.cs | 309 ++++++++++++++++-- MainForm.resx | 4 +- NewSessionForm.cs | 51 --- PasswordForm.Designer.cs | 91 +++--- PasswordForm.cs | 8 - PasswordForm.resx | 25 -- RyzStudio/IO/SharpZipLib.cs | 116 +++++-- RyzStudio/Windows/ThemedForms/Button.cs | 2 + RyzStudio/Windows/ThemedForms/TextBox.cs | 27 ++ .../ThemedForms/TextBoxForm.Designer.cs | 85 ++--- RyzStudio/Windows/ThemedForms/TextBoxForm.cs | 67 ++++ .../Windows/ThemedForms/TextBoxForm.resx | 0 Windows/Forms/BookmarkTreeView.cs | 135 +++----- bomg.csproj | 11 +- 16 files changed, 622 insertions(+), 339 deletions(-) delete mode 100644 NewSessionForm.cs rename NewSessionForm.Designer.cs => RyzStudio/Windows/ThemedForms/TextBoxForm.Designer.cs (76%) create mode 100644 RyzStudio/Windows/ThemedForms/TextBoxForm.cs rename NewSessionForm.resx => RyzStudio/Windows/ThemedForms/TextBoxForm.resx (100%) diff --git a/BookmarkEditForm.Designer.cs b/BookmarkEditForm.Designer.cs index c1bd6f0..049eff0 100644 --- a/BookmarkEditForm.Designer.cs +++ b/BookmarkEditForm.Designer.cs @@ -137,7 +137,9 @@ namespace bzit.bomg this.textBox2.Name = "textBox2"; this.textBox2.Padding = new System.Windows.Forms.Padding(10, 10, 9, 9); this.textBox2.Size = new System.Drawing.Size(259, 32); + this.textBox2.SubmitButton = this.button1; this.textBox2.TabIndex = 0; + this.textBox2.UseSystemPasswordChar = false; // // textBox1 // @@ -149,7 +151,9 @@ namespace bzit.bomg this.textBox1.Name = "textBox1"; this.textBox1.Padding = new System.Windows.Forms.Padding(10, 10, 9, 9); this.textBox1.Size = new System.Drawing.Size(259, 32); + this.textBox1.SubmitButton = this.button2; this.textBox1.TabIndex = 2; + this.textBox1.UseSystemPasswordChar = false; // // horizontalSeparator1 // diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index 59d99c7..a94f3fb 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -91,6 +91,7 @@ namespace bzit.bomg this.openMenuBarItem = new System.Windows.Forms.ToolStripButton(); this.saveMenuBarItem = new System.Windows.Forms.ToolStripButton(); this.toolStripSeparator9 = new System.Windows.Forms.ToolStripSeparator(); + this.toolStripButton1 = new System.Windows.Forms.ToolStripButton(); this.rootTreeNodeMenu = new System.Windows.Forms.ContextMenuStrip(this.components); this.toolStripMenuItem17 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem18 = new System.Windows.Forms.ToolStripMenuItem(); @@ -98,7 +99,6 @@ namespace bzit.bomg this.toolStripMenuItem20 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator13 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripMenuItem22 = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripButton1 = new System.Windows.Forms.ToolStripButton(); this.treeView1 = new RyzStudio.Windows.Forms.BookmarkTreeView(); this.pageTreeNodeMenu.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit(); @@ -451,8 +451,8 @@ namespace bzit.bomg // // openFileDialog // - this.openFileDialog.DefaultExt = "ryz"; - this.openFileDialog.Filter = "Bookmarks files|*.ryz"; + this.openFileDialog.DefaultExt = "jsnx"; + this.openFileDialog.Filter = "Bookmarks files (*.jsnx)|*.jsnx|Bookmarks files (*.ryz)|*.ryz"; this.openFileDialog.Title = "Open bookmarks file"; // // folderTreeNodeMenu @@ -604,6 +604,16 @@ namespace bzit.bomg this.toolStripSeparator9.Name = "toolStripSeparator9"; this.toolStripSeparator9.Size = new System.Drawing.Size(6, 25); // + // toolStripButton1 + // + this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.toolStripButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton1.Image"))); + this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta; + this.toolStripButton1.Name = "toolStripButton1"; + this.toolStripButton1.Size = new System.Drawing.Size(23, 22); + this.toolStripButton1.Text = "toolStripButton1"; + this.toolStripButton1.Click += new System.EventHandler(this.toolStripButton1_Click); + // // rootTreeNodeMenu // this.rootTreeNodeMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -654,16 +664,6 @@ namespace bzit.bomg this.toolStripMenuItem22.Text = "&Sort"; this.toolStripMenuItem22.Click += new System.EventHandler(this.sortContextMenu_Click); // - // toolStripButton1 - // - this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; - this.toolStripButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton1.Image"))); - this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta; - this.toolStripButton1.Name = "toolStripButton1"; - this.toolStripButton1.Size = new System.Drawing.Size(23, 22); - this.toolStripButton1.Text = "toolStripButton1"; - this.toolStripButton1.Click += new System.EventHandler(this.toolStripButton1_Click); - // // treeView1 // this.treeView1.AllowDrop = true; diff --git a/MainForm.cs b/MainForm.cs index f4c2433..05ab05d 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -5,8 +5,12 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; +using System.Text; using System.Windows.Forms; +using System.Xml; using static RyzStudio.Windows.Forms.BookmarkTreeView; +using TextBoxForm = RyzStudio.Windows.ThemedForms.TextBoxForm; + namespace bzit.bomg { @@ -22,8 +26,6 @@ namespace bzit.bomg protected AppMode appMode = AppMode.Clear; protected string sessionFilename = null; - //protected SessionFileFormat sessionFileFormat = null; - public MainForm() { InitializeComponent(); @@ -218,6 +220,7 @@ namespace bzit.bomg set { appMode = value; + switch (value) { case AppMode.Clear: @@ -271,8 +274,24 @@ namespace bzit.bomg /// private void newMenuItem_Click(object sender, EventArgs e) { - NewSessionForm newSessionForm = new NewSessionForm(this); - newSessionForm.ShowDialog(); + TextBoxForm newSessionForm = new TextBoxForm("New Session", "Name"); + string rv = newSessionForm.ShowDialog(); + if (string.IsNullOrWhiteSpace(rv)) + { + return; + } + + if (this.ApplicationMode == AppMode.Clear) + { + + } + else + { + + } + + //treeView1.HasChanged.ToString() + } /// @@ -284,9 +303,9 @@ namespace bzit.bomg { if (openFileDialog.ShowDialog() == DialogResult.OK) { - sessionFilename = openFileDialog.FileName; + //##sessionFilename = openFileDialog.FileName; - OpenBookmarkFile(sessionFilename); + loadBookmarkFile(openFileDialog.FileName, openFileDialog.FilterIndex); } } @@ -486,33 +505,9 @@ namespace bzit.bomg #endregion - protected void OpenBookmarkFile(string filename) - { - //treeView1.HasChanged = false; - //if (RyzStudio.IO.SharpZipLib.IsZipEncrypted(filename)) - //{ - // PasswordForm oPassword = new PasswordForm(this); - // sessionFileFormat.passkey = oPassword.ShowDialog(); - // if (sessionFileFormat.passkey.Equals("")) - // { - // return; - // } - //} - //else - //{ - // sessionFileFormat.passkey = ""; - //} - //bool rv = sessionFileFormat.loadFromRyz(filename); - //if (rv) - //{ - // this.Text = Path.GetFileNameWithoutExtension(filename) + " - " + Properties.Resources.app_name; - // this.ApplicationMode = AppMode.Open; - // treeView1.HasChanged = false; - //} - } protected bool SaveBookmarkFile() { @@ -553,8 +548,250 @@ namespace bzit.bomg return rv; } + protected void loadBookmarkFile(string filename, int filterIndex) + { + switch (filterIndex) + { + case 1: + if (RyzStudio.IO.SharpZipLib.IsZipEncrypted(filename)) + { + PasswordForm passwordForm = new PasswordForm(this); + string password = string.Empty; - protected void saveBookmarkFile(string filename) + while (true) + { + password = passwordForm.ShowDialog(); + if (string.IsNullOrWhiteSpace(password)) + { + break; + } + + if (RyzStudio.IO.SharpZipLib.TestZipEncrypted(filename, password)) + { + loadBookmarkFile_ForJSNX(filename, password); + break; + } + } + } + else + { + loadBookmarkFile_ForJSNX(filename); + } + + break; + case 2: + if (RyzStudio.IO.SharpZipLib.IsZipEncrypted(filename)) + { + PasswordForm passwordForm = new PasswordForm(this); + string password = string.Empty; + + while (true) + { + password = passwordForm.ShowDialog(); + if (string.IsNullOrWhiteSpace(password)) + { + break; + } + + if (RyzStudio.IO.SharpZipLib.TestZipEncrypted(filename, password)) + { + loadBookmarkFile_ForRYZ(filename, password); + break; + } + } + } + else + { + loadBookmarkFile_ForRYZ(filename); + } + + break; + default: + break; + } + } + + protected void loadBookmarkFile_ForJSNX(string filename, string password = "") + { + int size = 2048; + byte[] buffer = new byte[size]; + int bufferSize = 0; + + List rs = null; + + ZipEntry readEntry = null; + ZipInputStream readStream = new ZipInputStream(File.OpenRead(filename)); + readStream.Password = password; + + while (true) + { + readEntry = readStream.GetNextEntry(); + if (readEntry == null) + { + break; + } + + if (string.IsNullOrWhiteSpace(readEntry.Name)) + { + continue; + } + + if (!readEntry.IsFile) + { + continue; + } + + if (!readEntry.Name.Equals("bookmarks.json")) + { + continue; + } + + MemoryStream ms = new MemoryStream(); + buffer = new byte[size]; + bufferSize = 0; + + do + { + bufferSize = readStream.Read(buffer, 0, buffer.Length); + ms.Write(buffer, 0, bufferSize); + } + while (bufferSize > 0); + + ms.Position = 0; + + StreamReader sr = new StreamReader(ms); + rs = JsonConvert.DeserializeObject>(sr.ReadToEnd()); + + break; + } + + treeView1.AddItem(rs); + } + + protected void loadBookmarkFile_ForRYZ(string filename, string password = "") + { + int size = 2048; + byte[] buffer = new byte[size]; + int bufferSize = 0; + + List rs = new List(); + + ZipEntry readEntry = null; + ZipInputStream readStream = new ZipInputStream(File.OpenRead(filename)); + readStream.Password = password; + + while (true) + { + readEntry = readStream.GetNextEntry(); + if (readEntry == null) + { + break; + } + + if (string.IsNullOrWhiteSpace(readEntry.Name)) + { + continue; + } + + if (!readEntry.IsFile) + { + continue; + } + + if (!readEntry.Name.Equals("bookmarks.xml")) + { + continue; + } + + MemoryStream ms = new MemoryStream(); + buffer = new byte[size]; + bufferSize = 0; + + do + { + bufferSize = readStream.Read(buffer, 0, buffer.Length); + ms.Write(buffer, 0, bufferSize); + } + while (bufferSize > 0); + + ms.Position = 0; + + // read stream + StreamReader sr = new StreamReader(ms); + + // load xml + XmlDocument xmlDocument = new XmlDocument(); + xmlDocument.LoadXml(sr.ReadToEnd()); + + // parse + XmlNode xnl = xmlDocument.SelectSingleNode("bomg/b/g"); + if (xnl == null) + { + break; + } + + string rootName = (xnl.Attributes["name"] == null) ? "Bookmarks" : (string.IsNullOrWhiteSpace(xnl.Attributes["name"].InnerText) ? "Bookmarks" : xnl.Attributes["name"].InnerText.Trim()); + + foreach (XmlNode xn in xnl.ChildNodes) + { + BookmarkItemViewModel viewModel = new BookmarkItemViewModel(); + + foreach (XmlNode xn2 in xn.ChildNodes) + { + switch (xn2.LocalName) + { + case "name": + viewModel.SiteName = xn2.InnerText?.Trim(); + break; + case "address": + viewModel.SiteAddress = xn2.InnerText?.Trim(); + break; + case "description": + viewModel.SiteDescription = xn2.InnerText?.Trim(); + break; + //case "created": + // bi.Created = xn2.InnerText?.Trim(); + // break; + default: + break; + } + } + + // fix fullpath and name + if (viewModel.SiteName.Contains("|")) + { + StringBuilder sb = new StringBuilder(); + sb.Append("\\"); + sb.Append(System.Web.HttpUtility.UrlEncode(rootName)); + sb.Append("\\"); + + string[] pathParts = viewModel.SiteName.Split('|'); + for (int i = 0; i < (pathParts.Length - 1); i++) + { + sb.Append(pathParts[i]); + //sb.Append(System.Web.HttpUtility.UrlDecode(pathParts[i])); + sb.Append("\\"); + } + + viewModel.SiteName = System.Web.HttpUtility.UrlDecode(pathParts[(pathParts.Length - 1)] ?? string.Empty); + viewModel.TreeviewPath = sb.ToString(); + } + else + { + viewModel.SiteName = System.Web.HttpUtility.UrlDecode(viewModel.SiteName); + viewModel.TreeviewPath = string.Format("\\{0}\\", System.Web.HttpUtility.UrlEncode(rootName)); + } + + rs.Add(viewModel); + } + + break; + } + + treeView1.AddItem(rs); + } + + protected void saveBookmarkFile(string filename, string password = "") { List rs = treeView1.GetBookmarkList(); @@ -564,12 +801,13 @@ namespace bzit.bomg ZipOutputStream zipStream = new ZipOutputStream(File.Create(filename)); zipStream.SetLevel(9); + zipStream.Password = password; - // make readable + // stream MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(rs))); ms.Position = 0; - // write new document xml + // write file entry zipStream.PutNextEntry(new ZipEntry("bookmarks.json")); buffer = new byte[size]; @@ -815,9 +1053,10 @@ namespace bzit.bomg { List rs = treeView1.GetBookmarkList(); - string filename = @"N:\test.jsnx"; + //string filename = @"N:\test.jsnx"; - saveBookmarkFile(filename); + //saveBookmarkFile(filename, string.Empty); + //loadBookmarkFile(filename, string.Empty); } } diff --git a/MainForm.resx b/MainForm.resx index df4dc2d..7a6034f 100644 --- a/MainForm.resx +++ b/MainForm.resx @@ -157,14 +157,14 @@ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAHZSURBVDhPjZM7SxxRGIY1qfwPClaCICFkZUsRxELQQkmK - EAjEQsHOCxYpFSttZFmWNJJOsAik2yKwBAkJiu6i4g0iYrGbvbmzO5dzzszE1+87OOOOay4fPEyx5332 + EAjEQsHOCxYpFSttZFmWNJJOsAik2C6wBAkJiu6i4g0iYrGbvbmzO5dzzszE1+87OOOOay4fPEyx5332 PWfmtDVNJxEj4v+gm3hCtEzMcRwjk8n89n0fjyGlRCKRWKe1j0riHLYsC7Zth9TrddRqNRSLRS0pFApI JpMtknYizguEEFBK6SdjmiYMw0CpVNICagn+k1QqFUj0aIFXz0Fe72pBIOFAo9FAuVyObIfhjE7TaIE4 m4M4ng4XeJ6n9x1spVKp6Cb5fP5ecHM122Eevhnc/zS0IU+mIA9eQ16swq1+g+9aEQk34fOoVqv3Ank6 +UGdzkCez8O9XIX6uQSxPw5r+wXE4WKkCW+Hz4RFoQB49dQ5mPgszxdIsEaCZTi5l3Cy7+B7Si9kXNfV 58ISJhTwXO+NPRO5UaiLZaiz97C+9sE1jsIwwy2Cw+U2EYG1MzwismOwvz+Hud1L9WNQv77oUAA3YDjc Kvgx8Da72fPRlxV4hDhZgbzaagk3ExHQhB/SQ5pbNMO/cUanabQgnU7fPBT8Cf7sOaPTd9NPr8f+22UK - uLszJmX49obTRfQTbP0fKNzWdQu5+pvuDaXQ3AAAAABJRU5ErkJggg== + uLszJmX49obTRfQTbP0fKNzWdQuznZvllfjFsQAAAABJRU5ErkJggg== diff --git a/NewSessionForm.cs b/NewSessionForm.cs deleted file mode 100644 index 74ebd4f..0000000 --- a/NewSessionForm.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Windows.Forms; - -namespace bzit.bomg -{ - public partial class NewSessionForm : Form - { - private MainForm parentForm = null; - - public NewSessionForm(MainForm form) - { - InitializeComponent(); - - parentForm = form; - } - - private void button2_Click(object sender, EventArgs e) - { - if (parentForm == null) - { - return; - } - - if (string.IsNullOrEmpty(textBox2.Text)) - { - return; - } - - parentForm.treeView1.Clear(); - parentForm.treeView1.Nodes.Add("", textBox2.Text.Trim(), 0, 0); - parentForm.ApplicationMode = MainForm.AppMode.New; - - this.Close(); - } - - private void textBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) - { - switch (e.KeyCode) - { - case Keys.Enter: - button2_Click(sender, null); - break; - case Keys.Escape: - this.Close(); - break; - default: break; - } - } - - } -} \ No newline at end of file diff --git a/PasswordForm.Designer.cs b/PasswordForm.Designer.cs index deaee9c..21a52fa 100644 --- a/PasswordForm.Designer.cs +++ b/PasswordForm.Designer.cs @@ -28,62 +28,77 @@ namespace bzit.bomg /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PasswordForm)); - this.label1 = new System.Windows.Forms.Label(); - this.textBox1 = new System.Windows.Forms.TextBox(); - this.btnSave = new RyzStudio.Windows.Forms.BigButton(); + this.button2 = new RyzStudio.Windows.ThemedForms.Button(); + this.horizontalSeparator1 = new RyzStudio.Windows.Forms.HorizontalSeparator(); + this.textBox1 = new RyzStudio.Windows.ThemedForms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); this.SuspendLayout(); // - // label1 + // button2 // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(12, 12); - this.label1.Margin = new System.Windows.Forms.Padding(3); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(91, 13); - this.label1.TabIndex = 0; - this.label1.Text = "Enter a password"; + this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.button2.BackColor = System.Drawing.Color.Transparent; + this.button2.DefaultImage = null; + this.button2.DownImage = null; + this.button2.LabelText = "&OK"; + this.button2.Location = new System.Drawing.Point(264, 77); + this.button2.Name = "button2"; + this.button2.OverImage = null; + this.button2.Padding = new System.Windows.Forms.Padding(4, 4, 3, 3); + this.button2.Size = new System.Drawing.Size(108, 32); + this.button2.TabIndex = 1; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // horizontalSeparator1 + // + this.horizontalSeparator1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.horizontalSeparator1.Location = new System.Drawing.Point(12, 62); + this.horizontalSeparator1.Margin = new System.Windows.Forms.Padding(3, 10, 3, 10); + this.horizontalSeparator1.MaximumSize = new System.Drawing.Size(4920, 2); + this.horizontalSeparator1.Name = "horizontalSeparator1"; + this.horizontalSeparator1.Size = new System.Drawing.Size(360, 2); + this.horizontalSeparator1.TabIndex = 73; // // textBox1 // this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.textBox1.Location = new System.Drawing.Point(12, 31); + this.textBox1.BackColor = System.Drawing.Color.Transparent; + this.textBox1.Location = new System.Drawing.Point(96, 15); + this.textBox1.Margin = new System.Windows.Forms.Padding(10, 6, 10, 6); this.textBox1.Name = "textBox1"; - this.textBox1.PasswordChar = '*'; - this.textBox1.Size = new System.Drawing.Size(280, 21); + this.textBox1.Padding = new System.Windows.Forms.Padding(10, 10, 9, 9); + this.textBox1.Size = new System.Drawing.Size(276, 32); + this.textBox1.SubmitButton = this.button2; this.textBox1.TabIndex = 0; - this.textBox1.UseSystemPasswordChar = true; - this.textBox1.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.textBox1_PreviewKeyDown); + this.textBox1.UseSystemPasswordChar = false; // - // btnSave + // label2 // - this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.btnSave.BackColor = System.Drawing.Color.WhiteSmoke; - this.btnSave.Location = new System.Drawing.Point(196, 67); - this.btnSave.MaximumSize = new System.Drawing.Size(120, 32); - this.btnSave.MinimumSize = new System.Drawing.Size(32, 32); - this.btnSave.Name = "btnSave"; - this.btnSave.Padding = new System.Windows.Forms.Padding(4); - this.btnSave.Size = new System.Drawing.Size(96, 32); - this.btnSave.TabIndex = 23; - this.btnSave.Value = "&OK"; - this.btnSave.Click += new System.EventHandler(this.button2_Click); + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 25); + this.label2.Margin = new System.Windows.Forms.Padding(3); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(53, 13); + this.label2.TabIndex = 71; + this.label2.Text = "Password"; // // PasswordForm // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.BackColor = System.Drawing.Color.White; - this.ClientSize = new System.Drawing.Size(304, 111); - this.Controls.Add(this.btnSave); + this.ClientSize = new System.Drawing.Size(384, 121); + this.Controls.Add(this.button2); + this.Controls.Add(this.horizontalSeparator1); this.Controls.Add(this.textBox1); - this.Controls.Add(this.label1); + this.Controls.Add(this.label2); this.Font = new System.Drawing.Font("Tahoma", 8.25F); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; - this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.MinimizeBox = false; + this.MinimumSize = new System.Drawing.Size(400, 160); this.Name = "PasswordForm"; + this.ShowIcon = false; this.ShowInTaskbar = false; this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; @@ -94,9 +109,9 @@ namespace bzit.bomg } #endregion - - private System.Windows.Forms.Label label1; - private System.Windows.Forms.TextBox textBox1; - private RyzStudio.Windows.Forms.BigButton btnSave; + private RyzStudio.Windows.ThemedForms.Button button2; + private RyzStudio.Windows.Forms.HorizontalSeparator horizontalSeparator1; + private RyzStudio.Windows.ThemedForms.TextBox textBox1; + private System.Windows.Forms.Label label2; } } \ No newline at end of file diff --git a/PasswordForm.cs b/PasswordForm.cs index 5336a59..724808d 100644 --- a/PasswordForm.cs +++ b/PasswordForm.cs @@ -21,11 +21,6 @@ namespace bzit.bomg return; } - if (string.IsNullOrEmpty(textBox1.Text)) - { - return; - } - this.Close(); } @@ -33,9 +28,6 @@ namespace bzit.bomg { switch (e.KeyCode) { - case Keys.Enter: - button2_Click(sender, null); - break; case Keys.Escape: this.Close(); break; diff --git a/PasswordForm.resx b/PasswordForm.resx index de6f015..d58980a 100644 --- a/PasswordForm.resx +++ b/PasswordForm.resx @@ -117,29 +117,4 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - - AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAzjMmFRJ7V6TmMy+AkZqRWAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAR63jyYXp+f9M2fX/OZHM8yNgnF0AAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEeq4c+g5vj/N9Ly/0bW9v86k831IlqYYhlS - tw0cXb8NAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAvl9pcOZ3dzpji9v9S3PX/Rdn2/zaP - zPQ0gs/oNYPS6B9dplMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACyU2TRFqeHKT7fl3l3Z - 8v9N2/b/Wt33/1TY9f8tf833H1ehWQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADOY - 2oaI3fT/aeD2/3Li9/9e3/b/VNr2/zd+zfMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAA6oN2vqO75/33m+P+Z6Pj/fdHw/3/i9v8+l9nwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAALZXZZlzA6v2i8Pv/f9Tw/33H7P9Pot31IG21WQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAokNhwbsns/8nz+/9WueftJITNSAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAALJXaAjCY2olFquHLKpXaYwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAA//+sQf//rEH//6xB4f+sQeD/rEHgH6xB4A+sQfAHrEH8B6xB/AesQfwHrEH+D6xB/h+sQf// - rEH//6xB//+sQQ== - - \ No newline at end of file diff --git a/RyzStudio/IO/SharpZipLib.cs b/RyzStudio/IO/SharpZipLib.cs index b162124..d1f7c77 100644 --- a/RyzStudio/IO/SharpZipLib.cs +++ b/RyzStudio/IO/SharpZipLib.cs @@ -1,75 +1,123 @@ -using System; -using System.IO; -using ICSharpCode.SharpZipLib.Zip; - -namespace RyzStudio.IO +namespace RyzStudio.IO { + using System; + using System.IO; + using ICSharpCode.SharpZipLib.Zip; + public class SharpZipLib { - /// - /// Is zip file encrypted - /// - /// Filename - /// Is encrypted - public static bool IsZipEncrypted(string fn) + public static bool IsZipEncrypted(string filename) { - bool ret_val = false; + bool rv = false; + try { - ZipInputStream zipIn = new ZipInputStream(System.IO.File.OpenRead(fn)); - ZipEntry theEntry = null; - while ((theEntry = zipIn.GetNextEntry()) != null) + ZipInputStream zipStream = new ZipInputStream(File.OpenRead(filename)); + + ZipEntry zipEntry = null; + while ((zipEntry = zipStream.GetNextEntry()) != null) { - if (theEntry.IsCrypted) + if (zipEntry.IsCrypted) { - ret_val = true; + rv = true; } break; } - zipIn.Close(); + zipStream.Close(); } catch - { + { // do nothing } - return ret_val; + return rv; } - public static void AddFile(ZipOutputStream zipstream, string filename, string prefixpath = null) + public static bool TestZipEncrypted(string filename, string password) + { + bool rv = false; + + int size = 2; + byte[] buffer = new byte[size]; + int bufferSize = 0; + + ZipEntry readEntry = null; + ZipInputStream readStream = new ZipInputStream(File.OpenRead(filename)); + readStream.Password = password; + + while (true) + { + readEntry = readStream.GetNextEntry(); + if (readEntry == null) + { + break; + } + + if (string.IsNullOrWhiteSpace(readEntry.Name)) + { + continue; + } + + if (!readEntry.IsFile) + { + continue; + } + + if (readEntry.Size <= 0) + { + continue; + } + + try + { + bufferSize = readStream.Read(buffer, 0, buffer.Length); + rv = true; + } + catch + { + break; + } + + break; + } + + return rv; + } + + public static void AddFile(ZipOutputStream zipStream, string filename, string prefixPath = null) { byte[] buffer = new byte[4096]; - + string f1 = ""; - if (prefixpath != null) + if (prefixPath != null) { f1 = Path.GetDirectoryName(filename).TrimEnd('\\') + "\\"; - f1 = f1.Replace(prefixpath, "").TrimEnd('\\') + "\\"; + f1 = f1.Replace(prefixPath, "").TrimEnd('\\') + "\\"; f1 = f1 + Path.GetFileName(filename); f1 = f1.TrimStart('\\'); } - - ZipEntry entry = new ZipEntry(f1); - entry.DateTime = DateTime.Now; - zipstream.PutNextEntry(entry); - FileStream fs = File.OpenRead(filename); + ZipEntry zipEntry = new ZipEntry(f1); + zipEntry.DateTime = DateTime.Now; + zipStream.PutNextEntry(zipEntry); + + FileStream fileStream = File.OpenRead(filename); int sourceBytes; do { - sourceBytes = fs.Read(buffer, 0, buffer.Length); - zipstream.Write(buffer, 0, sourceBytes); + sourceBytes = fileStream.Read(buffer, 0, buffer.Length); + zipStream.Write(buffer, 0, sourceBytes); } while (sourceBytes > 0); } - public static void AddFolder(ZipOutputStream zipstream, string folderpath, string prefixpath = null) + public static void AddFolder(ZipOutputStream zipStream, string folderPath, string prefixPath = null) { - foreach (string fn in Directory.GetFiles(folderpath, "*.*", System.IO.SearchOption.AllDirectories)) + foreach (string fn in Directory.GetFiles(folderPath, "*.*", System.IO.SearchOption.AllDirectories)) { - AddFile(zipstream, fn, prefixpath); + AddFile(zipStream, fn, prefixPath); } } } diff --git a/RyzStudio/Windows/ThemedForms/Button.cs b/RyzStudio/Windows/ThemedForms/Button.cs index 06cefb6..9e3cf0a 100644 --- a/RyzStudio/Windows/ThemedForms/Button.cs +++ b/RyzStudio/Windows/ThemedForms/Button.cs @@ -100,5 +100,7 @@ [Browsable(false)] public ButtonStyle StyleDefault { get; set; } = new ButtonStyle(Color.White, Color.Black); + + public void PerformClick() => this.OnClick(null); } } \ No newline at end of file diff --git a/RyzStudio/Windows/ThemedForms/TextBox.cs b/RyzStudio/Windows/ThemedForms/TextBox.cs index ec54dc7..676b6d5 100644 --- a/RyzStudio/Windows/ThemedForms/TextBox.cs +++ b/RyzStudio/Windows/ThemedForms/TextBox.cs @@ -15,6 +15,7 @@ InitializeComponent(); this.Margin = new Padding(10, 6, 10, 6); + textBox1.PreviewKeyDown += textBox_PreviewKeyDown; } protected override void OnResize(EventArgs e) @@ -33,6 +34,24 @@ textBox1.Focus(); } + protected void textBox_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) + { + switch (e.KeyCode) + { + case Keys.Enter: + if (this.SubmitButton != null) + { + this.SubmitButton.PerformClick(); + } + + break; + //case Keys.Escape: + // this.Close(); + // break; + default: break; + } + } + [Browsable(true), EditorBrowsable(EditorBrowsableState.Advanced)] [Category("Appearance")] public System.Windows.Forms.TextBox InnerTextBox { get => textBox1; set => textBox1 = value; } @@ -41,6 +60,14 @@ [Category("Appearance")] public new string Text { get => textBox1.Text; set => textBox1.Text = value; } + [Browsable(true), EditorBrowsable(EditorBrowsableState.Advanced)] + [Category("Appearance")] + public bool UseSystemPasswordChar { get => textBox1.UseSystemPasswordChar; set => textBox1.UseSystemPasswordChar = value; } + + [Browsable(true), EditorBrowsable(EditorBrowsableState.Advanced)] + [Category("Appearance")] + public Button SubmitButton { get; set; } = null; + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new Padding Margin { get { return base.Margin; } set { base.Margin = value; } } diff --git a/NewSessionForm.Designer.cs b/RyzStudio/Windows/ThemedForms/TextBoxForm.Designer.cs similarity index 76% rename from NewSessionForm.Designer.cs rename to RyzStudio/Windows/ThemedForms/TextBoxForm.Designer.cs index 031ac36..9e5fa61 100644 --- a/NewSessionForm.Designer.cs +++ b/RyzStudio/Windows/ThemedForms/TextBoxForm.Designer.cs @@ -1,6 +1,6 @@ -namespace bzit.bomg +namespace RyzStudio.Windows.ThemedForms { - partial class NewSessionForm + partial class TextBoxForm { /// /// Required designer variable. @@ -28,26 +28,43 @@ namespace bzit.bomg /// private void InitializeComponent() { - this.textBox2 = new RyzStudio.Windows.ThemedForms.TextBox(); + this.textBox1 = new RyzStudio.Windows.ThemedForms.TextBox(); + this.button2 = new RyzStudio.Windows.ThemedForms.Button(); this.label2 = new System.Windows.Forms.Label(); this.horizontalSeparator1 = new RyzStudio.Windows.Forms.HorizontalSeparator(); - this.button2 = new RyzStudio.Windows.ThemedForms.Button(); this.SuspendLayout(); - // - // textBox2 - // - this.textBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + // + // textBox1 + // + this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.textBox2.BackColor = System.Drawing.Color.Transparent; - this.textBox2.Location = new System.Drawing.Point(96, 15); - this.textBox2.Margin = new System.Windows.Forms.Padding(10, 6, 10, 6); - this.textBox2.Name = "textBox2"; - this.textBox2.Padding = new System.Windows.Forms.Padding(10, 10, 9, 9); - this.textBox2.Size = new System.Drawing.Size(276, 32); - this.textBox2.TabIndex = 68; - // + this.textBox1.BackColor = System.Drawing.Color.Transparent; + this.textBox1.Location = new System.Drawing.Point(96, 15); + this.textBox1.Margin = new System.Windows.Forms.Padding(10, 6, 10, 6); + this.textBox1.Name = "textBox1"; + this.textBox1.Padding = new System.Windows.Forms.Padding(10, 10, 9, 9); + this.textBox1.Size = new System.Drawing.Size(276, 32); + this.textBox1.SubmitButton = this.button2; + this.textBox1.TabIndex = 0; + this.textBox1.UseSystemPasswordChar = false; + // + // button2 + // + this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.button2.BackColor = System.Drawing.Color.Transparent; + this.button2.DefaultImage = null; + this.button2.DownImage = null; + this.button2.LabelText = "&OK"; + this.button2.Location = new System.Drawing.Point(264, 77); + this.button2.Name = "button2"; + this.button2.OverImage = null; + this.button2.Padding = new System.Windows.Forms.Padding(4, 4, 3, 3); + this.button2.Size = new System.Drawing.Size(108, 32); + this.button2.TabIndex = 1; + this.button2.Click += new System.EventHandler(this.button2_Click); + // // label2 - // + // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(12, 25); this.label2.Margin = new System.Windows.Forms.Padding(3); @@ -55,45 +72,31 @@ namespace bzit.bomg this.label2.Size = new System.Drawing.Size(34, 13); this.label2.TabIndex = 67; this.label2.Text = "Name"; - // + // // horizontalSeparator1 - // - this.horizontalSeparator1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + // + this.horizontalSeparator1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.horizontalSeparator1.Location = new System.Drawing.Point(12, 63); + this.horizontalSeparator1.Location = new System.Drawing.Point(12, 62); this.horizontalSeparator1.Margin = new System.Windows.Forms.Padding(3, 10, 3, 10); this.horizontalSeparator1.MaximumSize = new System.Drawing.Size(4920, 2); this.horizontalSeparator1.Name = "horizontalSeparator1"; this.horizontalSeparator1.Size = new System.Drawing.Size(360, 2); this.horizontalSeparator1.TabIndex = 69; - // - // button2 - // - this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.button2.BackColor = System.Drawing.Color.Transparent; - this.button2.DefaultImage = null; - this.button2.DownImage = null; - this.button2.LabelText = "&OK"; - this.button2.Location = new System.Drawing.Point(264, 78); - this.button2.Name = "button2"; - this.button2.OverImage = null; - this.button2.Padding = new System.Windows.Forms.Padding(4, 4, 3, 3); - this.button2.Size = new System.Drawing.Size(108, 32); - this.button2.TabIndex = 70; - this.button2.Click += new System.EventHandler(this.button2_Click); - // + // // NewSessionForm - // + // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.BackColor = System.Drawing.Color.White; - this.ClientSize = new System.Drawing.Size(384, 122); + this.ClientSize = new System.Drawing.Size(384, 121); this.Controls.Add(this.button2); this.Controls.Add(this.horizontalSeparator1); - this.Controls.Add(this.textBox2); + this.Controls.Add(this.textBox1); this.Controls.Add(this.label2); this.Font = new System.Drawing.Font("Tahoma", 8.25F); this.MaximizeBox = false; this.MinimizeBox = false; + this.MinimumSize = new System.Drawing.Size(400, 160); this.Name = "NewSessionForm"; this.ShowIcon = false; this.ShowInTaskbar = false; @@ -105,7 +108,7 @@ namespace bzit.bomg } #endregion - private RyzStudio.Windows.ThemedForms.TextBox textBox2; + private RyzStudio.Windows.ThemedForms.TextBox textBox1; private System.Windows.Forms.Label label2; private RyzStudio.Windows.Forms.HorizontalSeparator horizontalSeparator1; private RyzStudio.Windows.ThemedForms.Button button2; diff --git a/RyzStudio/Windows/ThemedForms/TextBoxForm.cs b/RyzStudio/Windows/ThemedForms/TextBoxForm.cs new file mode 100644 index 0000000..92c94c3 --- /dev/null +++ b/RyzStudio/Windows/ThemedForms/TextBoxForm.cs @@ -0,0 +1,67 @@ +using System; +using System.Windows.Forms; + +namespace RyzStudio.Windows.ThemedForms +{ + public partial class TextBoxForm : Form + { + public TextBoxForm(string title, string labelText, string defaultValue) + { + InitializeComponent(); + + this.Text = title; + label2.Text = labelText; + textBox1.Text = defaultValue; + } + + public TextBoxForm(string title, string labelText, string defaultValue, bool password) + { + InitializeComponent(); + + this.Text = title; + label2.Text = labelText; + textBox1.Text = defaultValue; + textBox1.UseSystemPasswordChar = password; + } + + public TextBoxForm(string title, string labelText) + { + InitializeComponent(); + + this.Text = title; + label2.Text = labelText; + } + + public TextBoxForm(string title, string labelText, bool password) + { + InitializeComponent(); + + this.Text = title; + label2.Text = labelText; + textBox1.UseSystemPasswordChar = password; + } + + private void button2_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void textBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) + { + switch (e.KeyCode) + { + case Keys.Escape: + this.Close(); + break; + default: break; + } + } + + public new string ShowDialog() + { + base.ShowDialog(); + + return textBox1.Text; + } + } +} \ No newline at end of file diff --git a/NewSessionForm.resx b/RyzStudio/Windows/ThemedForms/TextBoxForm.resx similarity index 100% rename from NewSessionForm.resx rename to RyzStudio/Windows/ThemedForms/TextBoxForm.resx diff --git a/Windows/Forms/BookmarkTreeView.cs b/Windows/Forms/BookmarkTreeView.cs index 062d2b0..7c5c0d8 100644 --- a/Windows/Forms/BookmarkTreeView.cs +++ b/Windows/Forms/BookmarkTreeView.cs @@ -198,6 +198,21 @@ namespace RyzStudio.Windows.Forms return node.Nodes.Add(encodePath(name), name, (int)IconSet.Folder1, (int)IconSet.Folder2); } + public void AddItem(List viewModelList) + { + this.Clear(); + + if (viewModelList == null) + { + return; + } + + foreach (BookmarkItemViewModel item in viewModelList) + { + AddItem(item); + } + } + public void AddItem(BookmarkItemViewModel viewModel) { int iconIndex = addIcon(viewModel); @@ -296,7 +311,10 @@ namespace RyzStudio.Windows.Forms return rs; } - traverseBookmarkList(rs, this.Nodes[0]); + foreach (TreeNode item in this.Nodes) + { + traverseBookmarkList(rs, item); + } return rs; } @@ -403,13 +421,19 @@ namespace RyzStudio.Windows.Forms public void Clear() { - //nodeCount = 0; - //NodeCountUpdate(nodeCount); this.Nodes.Clear(); this.HasChanged = true; } + public void Clear(string name) + { + this.Nodes.Clear(); + this.Nodes.Add("", name?.Trim(), (int)IconSet.Root, (int)IconSet.Root); + + this.HasChanged = true; + } + #endregion #region integrated behaviour @@ -491,22 +515,6 @@ namespace RyzStudio.Windows.Forms this.HasChanged = true; base.OnBeforeLabelEdit(e); - - //if (e.Node == null) - //{ - // e.CancelEdit = true; - //} - //else - //{ - // if (e.Node.Tag == null) - // { - // // do it - // } - // else - // { - // e.CancelEdit = true; - // } - //} } protected override void OnAfterLabelEdit(NodeLabelEditEventArgs e) @@ -627,14 +635,8 @@ namespace RyzStudio.Windows.Forms base.OnPreviewKeyDown(e); } - //protected virtual void NodeCountUpdate(ulong v) - //{ - // this.OnNodeCountUpdate?.Invoke(v); - //} - #endregion - protected int addIcon(BookmarkItemViewModel viewModel) => addIcon(viewModel.ToModel()); protected int addIcon(BookmarkItemModel model) @@ -672,11 +674,12 @@ namespace RyzStudio.Windows.Forms protected TreeNode addFolderPath(string path) { - TreeNode tn = this.Nodes[0]; - if (tn == null) - { - return tn; - } + TreeNode tn = null; + //TreeNode tn = this.Nodes[0]; + //if (tn == null) + //{ + // return tn; + //} if (string.IsNullOrWhiteSpace(path)) { @@ -694,18 +697,28 @@ namespace RyzStudio.Windows.Forms return tn; } - foreach (string item in folderList) + for (int i=0; i UpdateIconForm.cs - Form @@ -175,11 +174,11 @@ FindForm.cs - + Form - - NewSessionForm.cs + + TextBoxForm.cs Form @@ -242,8 +241,8 @@ FindForm.cs - - NewSessionForm.cs + + TextBoxForm.cs PasswordForm.cs