Archived
Initial commit
This commit is contained in:
commit
1cdcca7267
143 files changed
+18199
No files matched your search
@@ -0,0 +1,29 @@
|
||||
namespace BookmarkManager
|
||||
{
|
||||
public class Result
|
||||
{
|
||||
public static Result Create() => new Result()
|
||||
{
|
||||
IsSuccess = true,
|
||||
Message = null
|
||||
};
|
||||
|
||||
public static Result Create(bool isSuccess) => new Result()
|
||||
{
|
||||
IsSuccess = isSuccess,
|
||||
Message = null
|
||||
};
|
||||
|
||||
public static Result Create(bool isSuccess, string message) => new Result()
|
||||
{
|
||||
IsSuccess = isSuccess,
|
||||
Message = message
|
||||
};
|
||||
|
||||
|
||||
public bool IsSuccess { get; set; } = false;
|
||||
|
||||
public string Message { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using RyzStudio.Windows.Forms;
|
||||
|
||||
namespace BookmarkManager
|
||||
{
|
||||
public interface ISupportedFile
|
||||
{
|
||||
|
||||
|
||||
bool IsEncryptionSupported { get; set; }
|
||||
|
||||
|
||||
bool IsSupported(string filename);
|
||||
|
||||
bool IsEncrypted(string filename);
|
||||
|
||||
Result Load(BookmarkTreeView treeview, string filename, string password);
|
||||
|
||||
Result Save(BookmarkTreeView treeview, string filename, string password);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
using BookmarkManager.DTO;
|
||||
using bzit.bomg.Models;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using Newtonsoft.Json;
|
||||
using RyzStudio.IO;
|
||||
using RyzStudio.Windows.Forms;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
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");
|
||||
}
|
||||
|
||||
List<BookmarkItemViewModel> rs = JsonConvert.DeserializeObject<List<BookmarkItemViewModel>>(sourceCode);
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
treeview.SetNoChanges();
|
||||
|
||||
return Result.Create(true);
|
||||
}
|
||||
|
||||
public override Result Save(BookmarkTreeView treeview, string filename, string password)
|
||||
{
|
||||
List<BookmarkItemViewModel> rs = treeview.GetBookmarkList();
|
||||
|
||||
bool rv = SharpZipLib.CreateSingle(filename, password, "bookmarks.json", JsonConvert.SerializeObject(rs));
|
||||
|
||||
return Result.Create(rv);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using RyzStudio.IO;
|
||||
using RyzStudio.Windows.Forms;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BookmarkManager
|
||||
{
|
||||
public class RYZSupportedFile : SupportedFileBase
|
||||
{
|
||||
|
||||
|
||||
public RYZSupportedFile()
|
||||
{
|
||||
supportedExtensions = new List<string>() { ".ryz" };
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
return Result.Create(false);
|
||||
}
|
||||
|
||||
public override Result Save(BookmarkTreeView treeview, string filename, string password)
|
||||
{
|
||||
return Result.Create(false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using RyzStudio.Windows.Forms;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace BookmarkManager
|
||||
{
|
||||
public abstract class SupportedFileBase : ISupportedFile
|
||||
{
|
||||
protected List<string> supportedExtensions = new List<string>();
|
||||
|
||||
|
||||
public SupportedFileBase()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public virtual bool IsEncryptionSupported { get; set; } = false;
|
||||
|
||||
|
||||
public virtual bool IsSupported(string filename)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (supportedExtensions == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (supportedExtensions.Count <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return supportedExtensions.Contains(Path.GetExtension(filename)?.Trim()?.ToLower());
|
||||
}
|
||||
|
||||
public virtual bool IsEncrypted(string filename) => false;
|
||||
|
||||
public virtual Result Load(BookmarkTreeView treeview, string filename, string password) => Result.Create(false);
|
||||
|
||||
public virtual Result Save(BookmarkTreeView treeview, string filename, string password) => Result.Create(false);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user