This commit is contained in:
Ray 2019-04-20 18:25:14 +01:00
parent 18dc43e491
commit 988857d91c
4 changed files with 260 additions and 221 deletions

View File

@ -1,4 +1,6 @@
using bzit.bomg.Models; using bzit.bomg.Models;
using ICSharpCode.SharpZipLib.Zip;
using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@ -18,9 +20,10 @@ namespace bzit.bomg
} }
protected AppMode appMode = AppMode.Clear; protected AppMode appMode = AppMode.Clear;
protected SessionFileFormat sessionFileFormat = null;
protected string sessionFilename = null; protected string sessionFilename = null;
//protected SessionFileFormat sessionFileFormat = null;
public MainForm() public MainForm()
{ {
InitializeComponent(); InitializeComponent();
@ -41,12 +44,6 @@ namespace bzit.bomg
this.Close(); this.Close();
} }
//this.IconDatabase = new IconDatabase();
// toolbar // toolbar
viewHelpHelpMenuItem.Enabled = File.Exists(Path.ChangeExtension(Application.ExecutablePath, ".chm")); viewHelpHelpMenuItem.Enabled = File.Exists(Path.ChangeExtension(Application.ExecutablePath, ".chm"));
@ -63,8 +60,9 @@ namespace bzit.bomg
// this.Close(); // this.Close();
//} //}
sessionFileFormat = new SessionFileFormat(this); //sessionFileFormat = new SessionFileFormat(this);
this.ApplicationMode = AppMode.Clear; this.ApplicationMode = AppMode.Clear;
sessionFilename = null;
//treeView1.OnNodeCountUpdate = delegate (ulong v) { //treeView1.OnNodeCountUpdate = delegate (ulong v) {
// statusBarPanel2.Text = v.ToString(); // statusBarPanel2.Text = v.ToString();
@ -90,54 +88,53 @@ namespace bzit.bomg
this.Location = Screen.PrimaryScreen.WorkingArea.Location; this.Location = Screen.PrimaryScreen.WorkingArea.Location;
// command line // command line
string[] szr = Environment.GetCommandLineArgs(); //string[] szr = Environment.GetCommandLineArgs();
int i = 0; //int i = 0;
while (true) //while (true)
{ //{
if (i > (szr.Length - 1)) // if (i > (szr.Length - 1))
{ // {
break; // break;
} // }
switch (szr[i].Trim().ToLower()) // switch (szr[i].Trim().ToLower())
{ // {
case "-o": // case "-o":
case "-open": // case "-open":
if ((i + 1) > (szr.Length - 1)) // if ((i + 1) > (szr.Length - 1))
{ // {
break; // break;
} // }
sessionFilename = szr[(i + 1)]; // sessionFilename = szr[(i + 1)];
if (string.IsNullOrEmpty(sessionFilename)) // if (string.IsNullOrEmpty(sessionFilename))
{ // {
sessionFilename = null; // sessionFilename = null;
break; // break;
} // }
if (!File.Exists(sessionFilename)) // if (!File.Exists(sessionFilename))
{ // {
sessionFilename = null; // sessionFilename = null;
break; // break;
} // }
OpenBookmarkFile(sessionFilename); // OpenBookmarkFile(sessionFilename);
i++; // i++;
break; // break;
} // }
i++; // i++;
} //}
} }
protected override void OnFormClosing(FormClosingEventArgs e) protected override void OnFormClosing(FormClosingEventArgs e)
{ {
//this.IconDatabase?.Close();
if (this.ApplicationMode == AppMode.Clear) if (this.ApplicationMode == AppMode.Clear)
{ {
this.ApplicationMode = AppMode.Clear;
Application.Exit(); Application.Exit();
return; return;
} }
@ -149,68 +146,68 @@ namespace bzit.bomg
return; return;
} }
if (this.ApplicationMode == AppMode.Open) //if (this.ApplicationMode == AppMode.Open)
{ //{
if (string.IsNullOrEmpty(sessionFilename)) // if (string.IsNullOrEmpty(sessionFilename))
{ // {
this.ApplicationMode = AppMode.Clear; // this.ApplicationMode = AppMode.Clear;
Application.Exit(); // Application.Exit();
return; // return;
} // }
if (MessageBox.Show("Save changes to open bookmarks.", "Save?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) // if (MessageBox.Show("Save changes to open bookmarks.", "Save?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{ // {
this.ApplicationMode = AppMode.Clear; // this.ApplicationMode = AppMode.Clear;
Application.Exit(); // Application.Exit();
return; // return;
} // }
while (true) // while (true)
{ // {
bool rv = sessionFileFormat.saveToRyz(sessionFilename); // bool rv = sessionFileFormat.saveToRyz(sessionFilename);
if (!rv) // if (!rv)
{ // {
switch (MessageBox.Show("There was a problem saving bookmarks. Retry?", "Retry?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)) // switch (MessageBox.Show("There was a problem saving bookmarks. Retry?", "Retry?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
{ // {
case DialogResult.Yes: // case DialogResult.Yes:
break; // break;
case DialogResult.No: // case DialogResult.No:
this.ApplicationMode = AppMode.Clear; // this.ApplicationMode = AppMode.Clear;
Application.Exit(); // Application.Exit();
break; // break;
case DialogResult.Cancel: // case DialogResult.Cancel:
e.Cancel = true; // e.Cancel = true;
break; // break;
default: break; // default: break;
} // }
} // }
else // else
{ // {
this.ApplicationMode = AppMode.Clear; // this.ApplicationMode = AppMode.Clear;
Application.Exit(); // Application.Exit();
break; // break;
} // }
} // }
} //}
else if (this.ApplicationMode == AppMode.New) //else if (this.ApplicationMode == AppMode.New)
{ //{
if (MessageBox.Show("Save changes to open bookmarks.", "Save?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) // if (MessageBox.Show("Save changes to open bookmarks.", "Save?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ // {
bool rt = SaveBookmarkFile(); // bool rt = SaveBookmarkFile();
if (rt) // if (rt)
{ // {
this.ApplicationMode = AppMode.Clear; // this.ApplicationMode = AppMode.Clear;
Application.Exit(); // Application.Exit();
return; // return;
} // }
} // }
else // else
{ // {
this.ApplicationMode = AppMode.Clear; // this.ApplicationMode = AppMode.Clear;
Application.Exit(); // Application.Exit();
return; // return;
} // }
} //}
} }
//#region public properties //#region public properties
@ -298,53 +295,53 @@ namespace bzit.bomg
*/ */
private void closeMenuItem_Click(object sender, EventArgs e) private void closeMenuItem_Click(object sender, EventArgs e)
{ {
if (ApplicationMode == AppMode.Clear) //if (ApplicationMode == AppMode.Clear)
{ //{
return; // return;
} //}
if (!treeView1.HasChanged) //if (!treeView1.HasChanged)
{ //{
ApplicationMode = AppMode.Clear; // ApplicationMode = AppMode.Clear;
return; // return;
} //}
if (ApplicationMode == AppMode.Open) //if (ApplicationMode == AppMode.Open)
{ //{
if (string.IsNullOrEmpty(sessionFilename)) // if (string.IsNullOrEmpty(sessionFilename))
{ // {
ApplicationMode = AppMode.Clear; // ApplicationMode = AppMode.Clear;
return; // return;
} // }
if (MessageBox.Show("Save changes to open bookmarks.", "Save?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) // if (MessageBox.Show("Save changes to open bookmarks.", "Save?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{ // {
ApplicationMode = AppMode.Clear; // ApplicationMode = AppMode.Clear;
return; // return;
} // }
bool rv = sessionFileFormat.saveToRyz(sessionFilename); // bool rv = sessionFileFormat.saveToRyz(sessionFilename);
if (!rv) // if (!rv)
{ // {
if (MessageBox.Show("There was a problem saving bookmarks. Bookmarks are not saved", "Not Saved", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) return; // if (MessageBox.Show("There was a problem saving bookmarks. Bookmarks are not saved", "Not Saved", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) return;
} // }
ApplicationMode = AppMode.Clear; // ApplicationMode = AppMode.Clear;
} //}
else if (ApplicationMode == AppMode.New) //else if (ApplicationMode == AppMode.New)
{ //{
if (MessageBox.Show("Save changes to open bookmarks.", "Save?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) // if (MessageBox.Show("Save changes to open bookmarks.", "Save?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{ // {
ApplicationMode = AppMode.Clear; // ApplicationMode = AppMode.Clear;
return; // return;
} // }
bool rt = SaveBookmarkFile(); // bool rt = SaveBookmarkFile();
if (rt) // if (rt)
{ // {
ApplicationMode = AppMode.Clear; // ApplicationMode = AppMode.Clear;
} // }
} //}
} }
/** /**
@ -352,16 +349,16 @@ namespace bzit.bomg
*/ */
private void importSnapshotToolStripMenuItem_Click(object sender, EventArgs e) private void importSnapshotToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (string.IsNullOrEmpty(sessionFilename)) //if (string.IsNullOrEmpty(sessionFilename))
{ //{
return; // return;
} //}
bool rv = sessionFileFormat.saveToRyz(sessionFilename); //bool rv = sessionFileFormat.saveToRyz(sessionFilename);
if (rv) //if (rv)
{ //{
treeView1.HasChanged = false; // treeView1.HasChanged = false;
} //}
} }
/** /**
@ -369,11 +366,11 @@ namespace bzit.bomg
*/ */
private void exportSnapshotToolStripMenuItem_Click(object sender, EventArgs e) private void exportSnapshotToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (SaveBookmarkFile()) //if (SaveBookmarkFile())
{ //{
ApplicationMode = AppMode.Open; // ApplicationMode = AppMode.Open;
treeView1.HasChanged = false; // treeView1.HasChanged = false;
} //}
} }
/** /**
@ -485,84 +482,121 @@ namespace bzit.bomg
/** /**
* ? -> Always-On-Top * ? -> Always-On-Top
*/ */
private void alwaysOnTopToolStripMenuItem_Click(object sender, EventArgs e) private void alwaysOnTopToolStripMenuItem_Click(object sender, EventArgs e) => this.TopMost = !this.TopMost;
{
this.TopMost = !this.TopMost;
}
#endregion #endregion
protected void OpenBookmarkFile(string filename) protected void OpenBookmarkFile(string filename)
{ {
treeView1.HasChanged = false; //treeView1.HasChanged = false;
if (RyzStudio.IO.SharpZipLib.IsZipEncrypted(filename)) //if (RyzStudio.IO.SharpZipLib.IsZipEncrypted(filename))
{ //{
PasswordForm oPassword = new PasswordForm(this); // PasswordForm oPassword = new PasswordForm(this);
sessionFileFormat.passkey = oPassword.ShowDialog(); // sessionFileFormat.passkey = oPassword.ShowDialog();
if (sessionFileFormat.passkey.Equals("")) // if (sessionFileFormat.passkey.Equals(""))
{ // {
return; // return;
} // }
} //}
else //else
{ //{
sessionFileFormat.passkey = ""; // sessionFileFormat.passkey = "";
} //}
bool rv = sessionFileFormat.loadFromRyz(filename); //bool rv = sessionFileFormat.loadFromRyz(filename);
if (rv) //if (rv)
{ //{
this.Text = Path.GetFileNameWithoutExtension(filename) + " - " + Properties.Resources.app_name; // this.Text = Path.GetFileNameWithoutExtension(filename) + " - " + Properties.Resources.app_name;
this.ApplicationMode = AppMode.Open; // this.ApplicationMode = AppMode.Open;
treeView1.HasChanged = false; // treeView1.HasChanged = false;
} //}
} }
protected bool SaveBookmarkFile() protected bool SaveBookmarkFile()
{ {
bool rv = false; bool rv = false;
if (saveFileDialog.ShowDialog() == DialogResult.OK) //if (saveFileDialog.ShowDialog() == DialogResult.OK)
{ //{
switch (saveFileDialog.FilterIndex) // switch (saveFileDialog.FilterIndex)
{ // {
case 1: // case 1:
sessionFileFormat.passkey = ""; // sessionFileFormat.passkey = "";
rv = sessionFileFormat.saveToRyz(saveFileDialog.FileName); // rv = sessionFileFormat.saveToRyz(saveFileDialog.FileName);
break; // break;
case 2: // case 2:
PasswordForm oPassword = new PasswordForm(this); // PasswordForm oPassword = new PasswordForm(this);
sessionFileFormat.passkey = oPassword.ShowDialog(); // sessionFileFormat.passkey = oPassword.ShowDialog();
rv = sessionFileFormat.saveToRyz(saveFileDialog.FileName); // rv = sessionFileFormat.saveToRyz(saveFileDialog.FileName);
if (rv) // if (rv)
{ // {
treeView1.HasChanged = false; // treeView1.HasChanged = false;
} // }
break; // break;
default: break; // default: break;
} // }
} //}
if (rv) //if (rv)
{ //{
ApplicationMode = AppMode.Open; // ApplicationMode = AppMode.Open;
sessionFilename = saveFileDialog.FileName; // sessionFilename = saveFileDialog.FileName;
this.Text = Path.GetFileNameWithoutExtension(saveFileDialog.FileName) + " - " + Properties.Resources.app_name; // this.Text = Path.GetFileNameWithoutExtension(saveFileDialog.FileName) + " - " + Properties.Resources.app_name;
} //}
return rv; return rv;
} }
protected void saveBookmarkFile(string filename)
{
List<BookmarkItemViewModel> rs = treeView1.GetBookmarkList();
int size = 2048;
byte[] buffer = new byte[size];
int bufferSize = 0;
ZipOutputStream zipStream = new ZipOutputStream(File.Create(filename));
zipStream.SetLevel(9);
// make readable
MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(rs)));
ms.Position = 0;
// write new document xml
zipStream.PutNextEntry(new ZipEntry("bookmarks.json"));
buffer = new byte[size];
bufferSize = 0;
do
{
bufferSize = ms.Read(buffer, 0, buffer.Length);
zipStream.Write(buffer, 0, bufferSize);
}
while (bufferSize > 0);
ms.Flush();
ms.Close();
ms.Dispose();
ms = null;
zipStream.Finish();
zipStream.Flush();
zipStream.Close();
zipStream.Dispose();
zipStream = null;
}
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
protected void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{ {
if (e.Button != MouseButtons.Right) if (e.Button != MouseButtons.Right)
{ {
@ -585,9 +619,9 @@ namespace bzit.bomg
} }
} }
private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) => openBookmark(e.Node); protected void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) => openBookmark(e.Node);
private void treeView1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) protected void treeView1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{ {
TreeNode tn = treeView1.SelectedNode; TreeNode tn = treeView1.SelectedNode;
if (tn == null) if (tn == null)
@ -775,15 +809,16 @@ namespace bzit.bomg
private void moveUpContextMenu2_Click(object sender, EventArgs e) => treeView1.SNode.MoveUp(); private void moveUpContextMenu2_Click(object sender, EventArgs e) => treeView1.SNode.MoveUp();
private void moveDownContextMenu2_Click(object sender, EventArgs e) => treeView1.SNode.MoveDown(); private void moveDownContextMenu2_Click(object sender, EventArgs e) => treeView1.SNode.MoveDown();
#endregion #endregion
private void toolStripButton1_Click(object sender, EventArgs e) private void toolStripButton1_Click(object sender, EventArgs e)
{ {
List<BookmarkItemViewModel> rs = treeView1.GetBookmarkList(); List<BookmarkItemViewModel> rs = treeView1.GetBookmarkList();
//MessageBox.Show(treeView1.GetNodePath(treeView1.SelectedNode)); string filename = @"N:\test.jsnx";
MessageBox.Show("!");
saveBookmarkFile(filename);
} }
} }
} }

View File

@ -267,14 +267,14 @@ namespace RyzStudio.Windows.Forms
return null; return null;
} }
if (folderList.Length < 2) //if (folderList.Length < 2)
{ //{
return "/"; // return "/";
} //}
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i=1; i<(folderList.Length - 1); i++) for (int i=0; i<(folderList.Length - 1); i++)
{ {
sb.Append("\\"); sb.Append("\\");
sb.Append(encodePath(folderList[i] ?? string.Empty)); sb.Append(encodePath(folderList[i] ?? string.Empty));

View File

@ -84,6 +84,9 @@
<Reference Include="ICSharpCode.SharpZipLib, Version=1.1.0.145, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL"> <Reference Include="ICSharpCode.SharpZipLib, Version=1.1.0.145, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
<HintPath>packages\SharpZipLib.1.1.0\lib\net45\ICSharpCode.SharpZipLib.dll</HintPath> <HintPath>packages\SharpZipLib.1.1.0\lib\net45\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference> </Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Data.Linq" /> <Reference Include="System.Data.Linq" />

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="HtmlAgilityPack" version="1.11.2" targetFramework="net462" /> <package id="HtmlAgilityPack" version="1.11.2" targetFramework="net462" />
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net462" />
<package id="SharpZipLib" version="1.1.0" targetFramework="net462" /> <package id="SharpZipLib" version="1.1.0" targetFramework="net462" />
<package id="System.Data.SQLite.Core" version="1.0.110.0" targetFramework="net462" /> <package id="System.Data.SQLite.Core" version="1.0.110.0" targetFramework="net462" />
</packages> </packages>