WIP: load bookmarks
This commit is contained in:
parent
ad9c1242cf
commit
fa8f2c046d
156
LoadBookmarksForm.Designer.cs
generated
Normal file
156
LoadBookmarksForm.Designer.cs
generated
Normal file
@ -0,0 +1,156 @@
|
||||
namespace bzit.bomg
|
||||
{
|
||||
partial class LoadBookmarksForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||
this.label5 = new System.Windows.Forms.Label();
|
||||
this.progressBar1 = new RyzStudio.Windows.ThemedForms.ProgressBar();
|
||||
this.horizontalSeparator1 = new RyzStudio.Windows.Forms.HorizontalSeparator();
|
||||
this.button2 = new RyzStudio.Windows.ThemedForms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(12, 25);
|
||||
this.label1.Margin = new System.Windows.Forms.Padding(3);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(63, 13);
|
||||
this.label1.TabIndex = 0;
|
||||
this.label1.Text = "Bookmarks";
|
||||
//
|
||||
// pictureBox1
|
||||
//
|
||||
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.pictureBox1.BackColor = System.Drawing.Color.Transparent;
|
||||
this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
|
||||
this.pictureBox1.ErrorImage = null;
|
||||
this.pictureBox1.InitialImage = null;
|
||||
this.pictureBox1.Location = new System.Drawing.Point(226, 77);
|
||||
this.pictureBox1.Name = "pictureBox1";
|
||||
this.pictureBox1.Size = new System.Drawing.Size(32, 32);
|
||||
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
|
||||
this.pictureBox1.TabIndex = 60;
|
||||
this.pictureBox1.TabStop = false;
|
||||
//
|
||||
// label5
|
||||
//
|
||||
this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.label5.ForeColor = System.Drawing.Color.OrangeRed;
|
||||
this.label5.Location = new System.Drawing.Point(9, 77);
|
||||
this.label5.Margin = new System.Windows.Forms.Padding(3);
|
||||
this.label5.Name = "label5";
|
||||
this.label5.Size = new System.Drawing.Size(211, 32);
|
||||
this.label5.TabIndex = 64;
|
||||
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||
//
|
||||
// progressBar1
|
||||
//
|
||||
this.progressBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.progressBar1.BackColor = System.Drawing.Color.Transparent;
|
||||
this.progressBar1.BarColour = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(225)))), ((int)(((byte)(249)))));
|
||||
this.progressBar1.BarTextColour = System.Drawing.SystemColors.ControlText;
|
||||
this.progressBar1.Location = new System.Drawing.Point(96, 15);
|
||||
this.progressBar1.Margin = new System.Windows.Forms.Padding(3, 10, 3, 10);
|
||||
this.progressBar1.Maximum = 0;
|
||||
this.progressBar1.Minimum = 0;
|
||||
this.progressBar1.Name = "progressBar1";
|
||||
this.progressBar1.Padding = new System.Windows.Forms.Padding(4, 4, 3, 3);
|
||||
this.progressBar1.Size = new System.Drawing.Size(276, 32);
|
||||
this.progressBar1.TabIndex = 66;
|
||||
this.progressBar1.Value = 0;
|
||||
//
|
||||
// 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 = 65;
|
||||
//
|
||||
// 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 = "&Close";
|
||||
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 = 4;
|
||||
this.button2.Click += new System.EventHandler(this.button2_Click);
|
||||
//
|
||||
// LoadBookmarksForm
|
||||
//
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.BackColor = System.Drawing.Color.White;
|
||||
this.ClientSize = new System.Drawing.Size(384, 121);
|
||||
this.Controls.Add(this.progressBar1);
|
||||
this.Controls.Add(this.horizontalSeparator1);
|
||||
this.Controls.Add(this.label5);
|
||||
this.Controls.Add(this.button2);
|
||||
this.Controls.Add(this.pictureBox1);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "LoadBookmarksForm";
|
||||
this.ShowIcon = false;
|
||||
this.ShowInTaskbar = false;
|
||||
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||
this.Text = "Load Bookmarks";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.PictureBox pictureBox1;
|
||||
private RyzStudio.Windows.ThemedForms.Button button2;
|
||||
private System.Windows.Forms.Label label5;
|
||||
private RyzStudio.Windows.Forms.HorizontalSeparator horizontalSeparator1;
|
||||
private RyzStudio.Windows.ThemedForms.ProgressBar progressBar1;
|
||||
}
|
||||
}
|
413
LoadBookmarksForm.cs
Normal file
413
LoadBookmarksForm.cs
Normal file
@ -0,0 +1,413 @@
|
||||
using bzit.bomg.Models;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using Newtonsoft.Json;
|
||||
using RyzStudio.Windows.Forms;
|
||||
using RyzStudio.Windows.ThemedForms;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using AppMode = bzit.bomg.MainForm.AppMode;
|
||||
using Form = System.Windows.Forms.Form;
|
||||
using Resources = bzit.bomg.Properties.Resources;
|
||||
|
||||
namespace bzit.bomg
|
||||
{
|
||||
public partial class LoadBookmarksForm : Form
|
||||
{
|
||||
protected bool isBusy = false;
|
||||
protected bool requestCancel = false;
|
||||
|
||||
protected MainForm parentForm = null;
|
||||
protected string sessionFilename = null;
|
||||
|
||||
public LoadBookmarksForm(MainForm mainForm, string filename) : base()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
parentForm = mainForm;
|
||||
sessionFilename = filename;
|
||||
|
||||
this.StartPosition = FormStartPosition.WindowsDefaultLocation;
|
||||
}
|
||||
|
||||
protected override void OnClosing(CancelEventArgs e)
|
||||
{
|
||||
base.OnClosing(e);
|
||||
|
||||
if (this.IsBusy)
|
||||
{
|
||||
e.Cancel = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnShown(EventArgs e)
|
||||
{
|
||||
base.OnShown(e);
|
||||
|
||||
loadFile(sessionFilename);
|
||||
}
|
||||
|
||||
protected bool IsBusy
|
||||
{
|
||||
get => isBusy;
|
||||
set
|
||||
{
|
||||
isBusy = value;
|
||||
parentForm.IsBusy = value;
|
||||
|
||||
//ThreadControl.SetImage(pictureBox1, (value) ? Resources.aniZomq2x32 : null);
|
||||
//ThreadControl.SetEnable(button2, !value);
|
||||
}
|
||||
}
|
||||
|
||||
private async void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (this.IsBusy)
|
||||
{
|
||||
//requestCancel = true;
|
||||
//ThreadControl.SetText(button1, "&Cancelling...");
|
||||
return;
|
||||
}
|
||||
|
||||
this.IsBusy = true;
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
//ThreadControl.SetText(button1, "&Updating...");
|
||||
|
||||
//if (requestCancel)
|
||||
//{
|
||||
// this.IsBusy = false;
|
||||
|
||||
// ThreadControl.SetText(button1, "&Update");
|
||||
|
||||
// requestCancel = false;
|
||||
// return;
|
||||
//}
|
||||
|
||||
//List<TreeNode> nodeList = parentForm.treeView1.GetBookmarkNodeList();
|
||||
|
||||
//ThreadControl.SetValue(progressBar1, 0, nodeList.Count);
|
||||
|
||||
//for (int i = 0; i < nodeList.Count; i++)
|
||||
//{
|
||||
// if (requestCancel)
|
||||
// {
|
||||
// this.IsBusy = false;
|
||||
|
||||
// ThreadControl.SetText(button1, "&Update");
|
||||
|
||||
// requestCancel = false;
|
||||
// return;
|
||||
// }
|
||||
|
||||
// ThreadControl.SetValue(progressBar1, (i + 1));
|
||||
|
||||
// BookmarkItemViewModel viewModel = (BookmarkItemViewModel)nodeList[i].Tag;
|
||||
// BookmarkItemModel model = viewModel.ToModel();
|
||||
// bool rv = model.UpdateFavicon();
|
||||
// if (rv)
|
||||
// {
|
||||
// if (parentForm.treeView1.InvokeRequired)
|
||||
// {
|
||||
// parentForm.treeView1.Invoke(new MethodInvoker(() =>
|
||||
// {
|
||||
// parentForm.treeView1.UpdateItem(nodeList[i], model.ToViewModel());
|
||||
// }));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// parentForm.treeView1.UpdateItem(nodeList[i], model.ToViewModel());
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
this.IsBusy = false;
|
||||
|
||||
//ThreadControl.SetText(button1, "&Update");
|
||||
|
||||
//requestCancel = false;
|
||||
});
|
||||
}
|
||||
|
||||
private void button2_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (this.IsBusy)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.Close();
|
||||
}
|
||||
|
||||
|
||||
protected void loadFile(string filename)
|
||||
{
|
||||
parentForm.ClearSession();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(filename))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string password = string.Empty;
|
||||
|
||||
if (RyzStudio.IO.SharpZipLib.IsZipEncrypted(filename))
|
||||
{
|
||||
TextBoxForm passwordForm = new TextBoxForm("Password", "Password", true);
|
||||
|
||||
while (true)
|
||||
{
|
||||
password = passwordForm.ShowDialog();
|
||||
if (string.IsNullOrWhiteSpace(password))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (RyzStudio.IO.SharpZipLib.TestZipEncrypted(filename, password))
|
||||
{
|
||||
parentForm.SetSessionFile(filename, password);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.IsBusy = true;
|
||||
|
||||
string ext = Path.GetExtension(filename).Trim('.').ToLower();
|
||||
if (ext.Equals("jsnx"))
|
||||
{
|
||||
loadJSNXBookmarkFile(filename, password);
|
||||
}
|
||||
else if (ext.Equals("ryz"))
|
||||
{
|
||||
//##loadFileType = LoadFileType.Ryz;
|
||||
}
|
||||
else
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
this.IsBusy = false;
|
||||
parentForm.AllowSave = false;
|
||||
}
|
||||
|
||||
protected void loadJSNXBookmarkFile(string filename, string password)
|
||||
{
|
||||
int size = 2048;
|
||||
byte[] buffer = new byte[size];
|
||||
int bufferSize = 0;
|
||||
|
||||
List<BookmarkItemViewModel> 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<List<BookmarkItemViewModel>>(sr.ReadToEnd());
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
readStream.Flush();
|
||||
readStream.Close();
|
||||
readStream.Dispose();
|
||||
readStream = null;
|
||||
|
||||
parentForm.SetBookmarkItem(rs);
|
||||
parentForm.ApplicationMode = AppMode.Open;
|
||||
|
||||
//// RyzStudio.Windows.Forms.ThreadControl.SetText(this, Path.GetFileNameWithoutExtension(filename) + " - " + Resources.app_name);
|
||||
}
|
||||
|
||||
//protected void loadBookmarkFile_ForRYZ(string filename, string password = "")
|
||||
//{
|
||||
// int size = 2048;
|
||||
// byte[] buffer = new byte[size];
|
||||
// int bufferSize = 0;
|
||||
|
||||
// List<BookmarkItemViewModel> rs = new List<BookmarkItemViewModel>();
|
||||
|
||||
// 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;
|
||||
// }
|
||||
|
||||
// readStream.Flush();
|
||||
// readStream.Close();
|
||||
// readStream.Dispose();
|
||||
// readStream = null;
|
||||
|
||||
// treeView1.AddItem(rs);
|
||||
|
||||
// sessionFilename = sessionPassword = null;
|
||||
// usePassword = !string.IsNullOrWhiteSpace(password);
|
||||
|
||||
// if (this.InvokeRequired)
|
||||
// {
|
||||
// this.Invoke(new MethodInvoker(() =>
|
||||
// {
|
||||
// this.ApplicationMode = AppMode.New;
|
||||
// }));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.ApplicationMode = AppMode.New;
|
||||
// }
|
||||
|
||||
// RyzStudio.Windows.Forms.ThreadControl.SetText(this, Path.GetFileNameWithoutExtension(filename) + " - " + Resources.app_name);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
120
LoadBookmarksForm.resx
Normal file
120
LoadBookmarksForm.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
697
MainForm.cs
697
MainForm.cs
@ -9,8 +9,9 @@ using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml;
|
||||
using static RyzStudio.Windows.Forms.BookmarkTreeView;
|
||||
using TextBoxForm = RyzStudio.Windows.ThemedForms.TextBoxForm;
|
||||
using Resources = bzit.bomg.Properties.Resources;
|
||||
using TextBoxForm = RyzStudio.Windows.ThemedForms.TextBoxForm;
|
||||
using ThreadControl = RyzStudio.Windows.Forms.ThreadControl;
|
||||
|
||||
namespace bzit.bomg
|
||||
{
|
||||
@ -30,7 +31,8 @@ namespace bzit.bomg
|
||||
Ryz
|
||||
}
|
||||
|
||||
protected BackgroundWorker loadFileThread = null;
|
||||
//protected BackgroundWorker loadFileThread = null;
|
||||
protected bool isBusy = false;
|
||||
protected LoadFileType loadFileType = LoadFileType.None;
|
||||
|
||||
protected AppMode appMode = AppMode.Clear;
|
||||
@ -42,14 +44,14 @@ namespace bzit.bomg
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
if (loadFileThread == null)
|
||||
{
|
||||
loadFileThread = new BackgroundWorker();
|
||||
loadFileThread.WorkerReportsProgress = loadFileThread.WorkerSupportsCancellation = true;
|
||||
}
|
||||
//if (loadFileThread == null)
|
||||
//{
|
||||
// loadFileThread = new BackgroundWorker();
|
||||
// loadFileThread.WorkerReportsProgress = loadFileThread.WorkerSupportsCancellation = true;
|
||||
//}
|
||||
|
||||
loadFileThread.DoWork += loadFileThread_DoWork;
|
||||
loadFileThread.RunWorkerCompleted += loadFileThread_RunWorkerCompleted;
|
||||
//loadFileThread.DoWork += loadFileThread_DoWork;
|
||||
//loadFileThread.RunWorkerCompleted += loadFileThread_RunWorkerCompleted;
|
||||
|
||||
treeView1.OnNodeChanged += treeView1_OnNodeChanged;
|
||||
}
|
||||
@ -70,9 +72,7 @@ namespace bzit.bomg
|
||||
}
|
||||
|
||||
this.ApplicationMode = AppMode.Clear;
|
||||
|
||||
sessionFilename = sessionPassword = null;
|
||||
usePassword = false;
|
||||
this.ClearSession();
|
||||
}
|
||||
|
||||
protected override void OnShown(EventArgs e)
|
||||
@ -105,15 +105,8 @@ namespace bzit.bomg
|
||||
if (string.IsNullOrWhiteSpace(openFilename)) break;
|
||||
if (!File.Exists(openFilename)) break;
|
||||
|
||||
string openExtension = Path.GetExtension(openFilename).Trim('.');
|
||||
if (openExtension.Equals("jsnx", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
loadBookmarkFile(openFilename, 1);
|
||||
}
|
||||
else if (openExtension.Equals("ryz", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
loadBookmarkFile(openFilename, 2);
|
||||
}
|
||||
LoadBookmarksForm loadFileForm = new LoadBookmarksForm(this, openFilename);
|
||||
loadFileForm.ShowDialog();
|
||||
|
||||
i++;
|
||||
break;
|
||||
@ -198,13 +191,14 @@ namespace bzit.bomg
|
||||
treeView1.CloseIconDatabase();
|
||||
|
||||
treeView1.Clear();
|
||||
|
||||
this.ApplicationMode = AppMode.Clear;
|
||||
sessionFilename = sessionPassword = null;
|
||||
this.ClearSession();
|
||||
|
||||
Application.Exit();
|
||||
}
|
||||
|
||||
protected AppMode ApplicationMode
|
||||
public AppMode ApplicationMode
|
||||
{
|
||||
get => appMode;
|
||||
set
|
||||
@ -214,46 +208,56 @@ namespace bzit.bomg
|
||||
switch (value)
|
||||
{
|
||||
case AppMode.Clear:
|
||||
this.Text = Properties.Resources.app_name;
|
||||
ThreadControl.SetText(this, Resources.app_name);
|
||||
|
||||
closeFileMenuItem.Enabled = false;
|
||||
saveFileMenuItem.Enabled = saveMenuBarItem.Enabled = false;
|
||||
saveAsFileMenuItem.Enabled = false;
|
||||
findEditMenuItem.Enabled = false;
|
||||
expandAllViewMenuItem.Enabled = collapseAllViewMenuItem.Enabled = false;
|
||||
optionsToolMenuItem.Enabled = false;
|
||||
ThreadControl.SetEnable(toolStrip1, closeFileMenuItem, false);
|
||||
this.AllowSave = false;
|
||||
ThreadControl.SetEnable(toolStrip1, saveAsFileMenuItem, false);
|
||||
ThreadControl.SetEnable(toolStrip1, findEditMenuItem, false);
|
||||
ThreadControl.SetEnable(toolStrip1, expandAllViewMenuItem, false);
|
||||
ThreadControl.SetEnable(toolStrip1, collapseAllViewMenuItem, false);
|
||||
ThreadControl.SetEnable(toolStrip1, optionsToolMenuItem, false);
|
||||
|
||||
break;
|
||||
case AppMode.Open:
|
||||
closeFileMenuItem.Enabled = true;
|
||||
saveFileMenuItem.Enabled = saveMenuBarItem.Enabled = true;
|
||||
saveAsFileMenuItem.Enabled = true;
|
||||
findEditMenuItem.Enabled = true;
|
||||
expandAllViewMenuItem.Enabled = collapseAllViewMenuItem.Enabled = true;
|
||||
optionsToolMenuItem.Enabled = true;
|
||||
ThreadControl.SetEnable(toolStrip1, closeFileMenuItem, true);
|
||||
this.AllowSave = true;
|
||||
ThreadControl.SetEnable(toolStrip1, saveAsFileMenuItem, true);
|
||||
ThreadControl.SetEnable(toolStrip1, findEditMenuItem, true);
|
||||
ThreadControl.SetEnable(toolStrip1, expandAllViewMenuItem, true);
|
||||
ThreadControl.SetEnable(toolStrip1, collapseAllViewMenuItem, true);
|
||||
ThreadControl.SetEnable(toolStrip1, optionsToolMenuItem, true);
|
||||
|
||||
break;
|
||||
case AppMode.New:
|
||||
this.Text = Properties.Resources.app_name;
|
||||
ThreadControl.SetText(this, Resources.app_name);
|
||||
|
||||
closeFileMenuItem.Enabled = true;
|
||||
saveFileMenuItem.Enabled = saveMenuBarItem.Enabled = true;
|
||||
saveAsFileMenuItem.Enabled = true;
|
||||
findEditMenuItem.Enabled = true;
|
||||
expandAllViewMenuItem.Enabled = collapseAllViewMenuItem.Enabled = true;
|
||||
optionsToolMenuItem.Enabled = true;
|
||||
ThreadControl.SetEnable(toolStrip1, closeFileMenuItem, true);
|
||||
this.AllowSave = true;
|
||||
ThreadControl.SetEnable(toolStrip1, saveAsFileMenuItem, true);
|
||||
ThreadControl.SetEnable(toolStrip1, findEditMenuItem, true);
|
||||
ThreadControl.SetEnable(toolStrip1, expandAllViewMenuItem, true);
|
||||
ThreadControl.SetEnable(toolStrip1, collapseAllViewMenuItem, true);
|
||||
ThreadControl.SetEnable(toolStrip1, optionsToolMenuItem, true);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected bool IsBusy
|
||||
public bool AllowSave
|
||||
{
|
||||
get
|
||||
get => (saveMenuBarItem.Enabled || saveFileMenuItem.Enabled);
|
||||
set
|
||||
{
|
||||
return loadFileThread.IsBusy;
|
||||
ThreadControl.SetEnable(toolStrip1, saveMenuBarItem, value);
|
||||
ThreadControl.SetEnable(toolStrip1, saveFileMenuItem, value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsBusy
|
||||
{
|
||||
get => isBusy;
|
||||
set
|
||||
{
|
||||
treeView1.Enabled = !value;
|
||||
@ -339,7 +343,7 @@ namespace bzit.bomg
|
||||
treeView1.Clear(rv);
|
||||
|
||||
this.ApplicationMode = AppMode.New;
|
||||
sessionFilename = sessionPassword = null;
|
||||
this.ClearSession();
|
||||
}
|
||||
|
||||
private void fileOpenMenuItem_Click(object sender, EventArgs e)
|
||||
@ -411,7 +415,8 @@ namespace bzit.bomg
|
||||
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
loadBookmarkFile(openFileDialog.FileName, openFileDialog.FilterIndex);
|
||||
LoadBookmarksForm loadFileForm = new LoadBookmarksForm(this, openFileDialog.FileName);
|
||||
loadFileForm.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
@ -483,8 +488,9 @@ namespace bzit.bomg
|
||||
}
|
||||
|
||||
treeView1.Clear();
|
||||
|
||||
this.ApplicationMode = AppMode.Clear;
|
||||
sessionFilename = sessionPassword = null;
|
||||
this.ClearSession();
|
||||
}
|
||||
|
||||
private void fileSaveMenuItem_Click(object sender, EventArgs e)
|
||||
@ -657,284 +663,284 @@ namespace bzit.bomg
|
||||
|
||||
#endregion
|
||||
|
||||
protected void loadBookmarkFile(string filename, int filterIndex)
|
||||
{
|
||||
sessionFilename = sessionPassword = null;
|
||||
usePassword = false;
|
||||
//protected void loadBookmarkFile(string filename, int filterIndex)
|
||||
//{
|
||||
// sessionFilename = sessionPassword = null;
|
||||
// usePassword = false;
|
||||
|
||||
//sessionFilename = filename;
|
||||
//sessionPassword = null;
|
||||
//usePassword = false;
|
||||
// //sessionFilename = filename;
|
||||
// //sessionPassword = null;
|
||||
// //usePassword = false;
|
||||
|
||||
if (RyzStudio.IO.SharpZipLib.IsZipEncrypted(filename))
|
||||
{
|
||||
TextBoxForm passwordForm = new TextBoxForm("Password", "Password", true);
|
||||
string password = string.Empty;
|
||||
// if (RyzStudio.IO.SharpZipLib.IsZipEncrypted(filename))
|
||||
// {
|
||||
// TextBoxForm passwordForm = new TextBoxForm("Password", "Password", true);
|
||||
// string password = string.Empty;
|
||||
|
||||
while (true)
|
||||
{
|
||||
password = passwordForm.ShowDialog();
|
||||
if (string.IsNullOrWhiteSpace(password))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (RyzStudio.IO.SharpZipLib.TestZipEncrypted(filename, password))
|
||||
{
|
||||
sessionFilename = filename;
|
||||
sessionPassword = password;
|
||||
usePassword = true;
|
||||
|
||||
loadFileType = LoadFileType.Jsnx;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (filterIndex)
|
||||
{
|
||||
case 1:
|
||||
loadFileType = LoadFileType.Jsnx;
|
||||
break;
|
||||
case 2:
|
||||
loadFileType = LoadFileType.Ryz;
|
||||
break;
|
||||
default:
|
||||
loadFileType = LoadFileType.None;
|
||||
break;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(sessionFilename))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.IsBusy = true;
|
||||
|
||||
loadFileThread.RunWorkerAsync();
|
||||
}
|
||||
|
||||
protected void loadBookmarkFile_ForJSNX(string filename, string password = "")
|
||||
{
|
||||
int size = 2048;
|
||||
byte[] buffer = new byte[size];
|
||||
int bufferSize = 0;
|
||||
|
||||
List<BookmarkItemViewModel> 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<List<BookmarkItemViewModel>>(sr.ReadToEnd());
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
readStream.Flush();
|
||||
readStream.Close();
|
||||
readStream.Dispose();
|
||||
readStream = null;
|
||||
|
||||
treeView1.AddItem(rs);
|
||||
|
||||
if (this.InvokeRequired)
|
||||
{
|
||||
this.Invoke(new MethodInvoker(() =>
|
||||
{
|
||||
this.ApplicationMode = AppMode.Open;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ApplicationMode = AppMode.Open;
|
||||
}
|
||||
|
||||
RyzStudio.Windows.Forms.ThreadControl.SetText(this, Path.GetFileNameWithoutExtension(filename) + " - " + Resources.app_name);
|
||||
}
|
||||
|
||||
protected void loadBookmarkFile_ForRYZ(string filename, string password = "")
|
||||
{
|
||||
int size = 2048;
|
||||
byte[] buffer = new byte[size];
|
||||
int bufferSize = 0;
|
||||
|
||||
List<BookmarkItemViewModel> rs = new List<BookmarkItemViewModel>();
|
||||
|
||||
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();
|
||||
// while (true)
|
||||
// {
|
||||
// password = passwordForm.ShowDialog();
|
||||
// if (string.IsNullOrWhiteSpace(password))
|
||||
// {
|
||||
// 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("\\");
|
||||
// if (RyzStudio.IO.SharpZipLib.TestZipEncrypted(filename, password))
|
||||
// {
|
||||
// sessionFilename = filename;
|
||||
// sessionPassword = password;
|
||||
// usePassword = true;
|
||||
|
||||
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("\\");
|
||||
}
|
||||
// loadFileType = LoadFileType.Jsnx;
|
||||
|
||||
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));
|
||||
}
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
rs.Add(viewModel);
|
||||
}
|
||||
// switch (filterIndex)
|
||||
// {
|
||||
// case 1:
|
||||
// loadFileType = LoadFileType.Jsnx;
|
||||
// break;
|
||||
// case 2:
|
||||
// loadFileType = LoadFileType.Ryz;
|
||||
// break;
|
||||
// default:
|
||||
// loadFileType = LoadFileType.None;
|
||||
// break;
|
||||
// }
|
||||
|
||||
break;
|
||||
}
|
||||
// if (string.IsNullOrWhiteSpace(sessionFilename))
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
readStream.Flush();
|
||||
readStream.Close();
|
||||
readStream.Dispose();
|
||||
readStream = null;
|
||||
// this.IsBusy = true;
|
||||
|
||||
treeView1.AddItem(rs);
|
||||
// loadFileThread.RunWorkerAsync();
|
||||
//}
|
||||
|
||||
sessionFilename = sessionPassword = null;
|
||||
usePassword = !string.IsNullOrWhiteSpace(password);
|
||||
//protected void loadBookmarkFile_ForJSNX(string filename, string password = "")
|
||||
//{
|
||||
// int size = 2048;
|
||||
// byte[] buffer = new byte[size];
|
||||
// int bufferSize = 0;
|
||||
|
||||
if (this.InvokeRequired)
|
||||
{
|
||||
this.Invoke(new MethodInvoker(() =>
|
||||
{
|
||||
this.ApplicationMode = AppMode.New;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ApplicationMode = AppMode.New;
|
||||
}
|
||||
// List<BookmarkItemViewModel> rs = null;
|
||||
|
||||
RyzStudio.Windows.Forms.ThreadControl.SetText(this, Path.GetFileNameWithoutExtension(filename) + " - " + Resources.app_name);
|
||||
}
|
||||
// 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<List<BookmarkItemViewModel>>(sr.ReadToEnd());
|
||||
|
||||
// break;
|
||||
// }
|
||||
|
||||
// readStream.Flush();
|
||||
// readStream.Close();
|
||||
// readStream.Dispose();
|
||||
// readStream = null;
|
||||
|
||||
// treeView1.AddItem(rs);
|
||||
|
||||
// if (this.InvokeRequired)
|
||||
// {
|
||||
// this.Invoke(new MethodInvoker(() =>
|
||||
// {
|
||||
// this.ApplicationMode = AppMode.Open;
|
||||
// }));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.ApplicationMode = AppMode.Open;
|
||||
// }
|
||||
|
||||
// RyzStudio.Windows.Forms.ThreadControl.SetText(this, Path.GetFileNameWithoutExtension(filename) + " - " + Resources.app_name);
|
||||
//}
|
||||
|
||||
//protected void loadBookmarkFile_ForRYZ(string filename, string password = "")
|
||||
//{
|
||||
// int size = 2048;
|
||||
// byte[] buffer = new byte[size];
|
||||
// int bufferSize = 0;
|
||||
|
||||
// List<BookmarkItemViewModel> rs = new List<BookmarkItemViewModel>();
|
||||
|
||||
// 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;
|
||||
// }
|
||||
|
||||
// readStream.Flush();
|
||||
// readStream.Close();
|
||||
// readStream.Dispose();
|
||||
// readStream = null;
|
||||
|
||||
// treeView1.AddItem(rs);
|
||||
|
||||
// sessionFilename = sessionPassword = null;
|
||||
// usePassword = !string.IsNullOrWhiteSpace(password);
|
||||
|
||||
// if (this.InvokeRequired)
|
||||
// {
|
||||
// this.Invoke(new MethodInvoker(() =>
|
||||
// {
|
||||
// this.ApplicationMode = AppMode.New;
|
||||
// }));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.ApplicationMode = AppMode.New;
|
||||
// }
|
||||
|
||||
// RyzStudio.Windows.Forms.ThreadControl.SetText(this, Path.GetFileNameWithoutExtension(filename) + " - " + Resources.app_name);
|
||||
//}
|
||||
|
||||
protected void openBookmark(TreeNode node)
|
||||
{
|
||||
@ -1185,34 +1191,69 @@ namespace bzit.bomg
|
||||
if (this.InvokeRequired)
|
||||
{
|
||||
this.Invoke(new MethodInvoker(() => {
|
||||
saveMenuBarItem.Enabled = saveFileMenuItem.Enabled = treeView1.HasChanged;
|
||||
this.AllowSave = treeView1.HasChanged;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
saveMenuBarItem.Enabled = saveFileMenuItem.Enabled = treeView1.HasChanged;
|
||||
this.AllowSave = treeView1.HasChanged;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void loadFileThread_DoWork(object sender, DoWorkEventArgs e)
|
||||
public void ClearSession()
|
||||
{
|
||||
if (loadFileType == LoadFileType.Jsnx)
|
||||
{
|
||||
loadBookmarkFile_ForJSNX(sessionFilename, sessionPassword ?? string.Empty);
|
||||
}
|
||||
else if (loadFileType == LoadFileType.Ryz)
|
||||
{
|
||||
loadBookmarkFile_ForRYZ(sessionFilename, sessionPassword ?? string.Empty);
|
||||
}
|
||||
sessionFilename = sessionPassword = null;
|
||||
usePassword = false;
|
||||
}
|
||||
|
||||
private void loadFileThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
||||
public void SetSessionFile(string filename, string password)
|
||||
{
|
||||
this.IsBusy = false;
|
||||
saveMenuBarItem.Enabled = saveFileMenuItem.Enabled = false;
|
||||
sessionFilename = filename;
|
||||
sessionPassword = password;
|
||||
usePassword = !string.IsNullOrWhiteSpace(password);
|
||||
|
||||
string ext = Path.GetExtension(filename).Trim('.').ToLower();
|
||||
if (ext.Equals("jsnx"))
|
||||
{
|
||||
loadFileType = LoadFileType.Jsnx;
|
||||
}
|
||||
else if (ext.Equals("ryz"))
|
||||
{
|
||||
loadFileType = LoadFileType.Ryz;
|
||||
}
|
||||
else
|
||||
{
|
||||
loadFileType = LoadFileType.None;
|
||||
}
|
||||
|
||||
ThreadControl.SetText(this, Path.GetFileNameWithoutExtension(sessionFilename) + " - " + Resources.app_name);
|
||||
}
|
||||
|
||||
public void SetBookmarkItem(List<BookmarkItemViewModel> itmes)
|
||||
{
|
||||
treeView1.AddItem(itmes);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//private void loadFileThread_DoWork(object sender, DoWorkEventArgs e)
|
||||
//{
|
||||
// if (loadFileType == LoadFileType.Jsnx)
|
||||
// {
|
||||
// loadBookmarkFile_ForJSNX(sessionFilename, sessionPassword ?? string.Empty);
|
||||
// }
|
||||
// else if (loadFileType == LoadFileType.Ryz)
|
||||
// {
|
||||
// loadBookmarkFile_ForRYZ(sessionFilename, sessionPassword ?? string.Empty);
|
||||
// }
|
||||
//}
|
||||
|
||||
//private void loadFileThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
||||
//{
|
||||
// this.IsBusy = false;
|
||||
// saveMenuBarItem.Enabled = saveFileMenuItem.Enabled = false;
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -355,6 +355,36 @@ namespace RyzStudio.Windows.Forms
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetEnable(Control container, ToolStripMenuItem control, bool value)
|
||||
{
|
||||
if (container.InvokeRequired)
|
||||
{
|
||||
container.Invoke(new MethodInvoker(() =>
|
||||
{
|
||||
control.Enabled = value;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Enabled = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetEnable(Control container, ToolStripItem control, bool value)
|
||||
{
|
||||
if (container.InvokeRequired)
|
||||
{
|
||||
container.Invoke(new MethodInvoker(() =>
|
||||
{
|
||||
control.Enabled = value;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Enabled = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static int GetValue(NumericUpDown sender)
|
||||
{
|
||||
int rv = 0;
|
||||
|
10
bomg.csproj
10
bomg.csproj
@ -102,11 +102,11 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="LoadFileForm.cs">
|
||||
<Compile Include="LoadBookmarksForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="LoadFileForm.Designer.cs">
|
||||
<DependentUpon>LoadFileForm.cs</DependentUpon>
|
||||
<Compile Include="LoadBookmarksForm.Designer.cs">
|
||||
<DependentUpon>LoadBookmarksForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="UpdateIconsForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
@ -205,8 +205,8 @@
|
||||
<Compile Include="Windows\Forms\BookmarkTreeView.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<EmbeddedResource Include="LoadFileForm.resx">
|
||||
<DependentUpon>LoadFileForm.cs</DependentUpon>
|
||||
<EmbeddedResource Include="LoadBookmarksForm.resx">
|
||||
<DependentUpon>LoadBookmarksForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="UpdateIconsForm.resx">
|
||||
<DependentUpon>UpdateIconsForm.cs</DependentUpon>
|
||||
|
Reference in New Issue
Block a user