2021-09-07 16:21:28 +00:00
|
|
|
|
using bzit.bomg.Models;
|
2021-09-07 11:32:24 +00:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using RyzStudio.IO;
|
|
|
|
|
using RyzStudio.Windows.Forms;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace BookmarkManager
|
|
|
|
|
{
|
|
|
|
|
public class JSNXSupportedFile : SupportedFileBase
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public JSNXSupportedFile()
|
|
|
|
|
{
|
|
|
|
|
supportedExtensions = new List<string>() { ".jsnx" };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override bool IsEncryptionSupported { get; set; } = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override bool IsEncrypted(string filename) => SharpZipLib.IsZipEncrypted(filename);
|
|
|
|
|
|
|
|
|
|
public override Result Load(BookmarkTreeView treeview, string filename, string password)
|
|
|
|
|
{
|
|
|
|
|
treeview.Clear();
|
|
|
|
|
|
|
|
|
|
if (!SharpZipLib.TestArchive(filename, password))
|
|
|
|
|
{
|
|
|
|
|
return Result.Create(false, "Could not read file, is password correct?");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string sourceCode = SharpZipLib.ReadSingle(filename, password, "bookmarks.json");
|
|
|
|
|
if (string.IsNullOrWhiteSpace(sourceCode))
|
|
|
|
|
{
|
|
|
|
|
return Result.Create(false, "Could not read file, unexpected format");
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-17 15:37:01 +00:00
|
|
|
|
List<BookmarkItem> rs = JsonConvert.DeserializeObject<List<BookmarkItem>>(sourceCode);
|
2021-09-07 11:32:24 +00:00
|
|
|
|
if (rs == null)
|
|
|
|
|
{
|
|
|
|
|
return Result.Create(false, "Could not read file, incorrect format");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//// load bookmark items
|
|
|
|
|
//ThreadControl.SetValue(progressBar1, 0, rs.Count);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < rs.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
// ThreadControl.SetValue(progressBar1, (i + 1));
|
|
|
|
|
|
|
|
|
|
if (treeview.InvokeRequired)
|
|
|
|
|
{
|
|
|
|
|
treeview.Invoke(new MethodInvoker(() => {
|
|
|
|
|
treeview.AddItem(rs[i]);
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
treeview.AddItem(rs[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-09 21:39:23 +00:00
|
|
|
|
//treeview.SetNoChanges();
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
|
|
|
|
return Result.Create(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Result Save(BookmarkTreeView treeview, string filename, string password)
|
|
|
|
|
{
|
2021-09-17 15:37:01 +00:00
|
|
|
|
List<BookmarkItem> rs = treeview.GetBookmarkList();
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
|
|
|
|
bool rv = SharpZipLib.CreateSingle(filename, password, "bookmarks.json", JsonConvert.SerializeObject(rs));
|
|
|
|
|
|
|
|
|
|
return Result.Create(rv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|