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

View File

@ -267,14 +267,14 @@ namespace RyzStudio.Windows.Forms
return null;
}
if (folderList.Length < 2)
{
return "/";
}
//if (folderList.Length < 2)
//{
// return "/";
//}
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(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">
<HintPath>packages\SharpZipLib.1.1.0\lib\net45\ICSharpCode.SharpZipLib.dll</HintPath>
</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.Data" />
<Reference Include="System.Data.Linq" />

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<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="System.Data.SQLite.Core" version="1.0.110.0" targetFramework="net462" />
</packages>