private void processChild(JToken child, JToken parent, bool recursive)
{
bool root = true;
try
{
child["type"].ToString();
}
catch
{
root = false;
}
if (child["type"].ToString() == "url")
{
bookmarks.Add(new Bookmark(child["url"].ToString(), child["name"].ToString(), "Chrome",
ConvertChromeTime(Int64.Parse(child["date_added"].ToString())),
string.Join("\\", fullPath)));
if (!recursive && child == child.Parent.Last && fullPath.Count != 0)
fullPath.Remove(fullPath.Last());
}
else if (child["type"].ToString() == "folder")
{
Console.WriteLine("FOLDER");
if (!child["name"].Contains("\\"))
fullPath.Add(child["name"].ToString());
else
fullPath.Add(child["name"].ToString().Replace("\\", ""));
foreach (var subChild in child["children"])
{
processChild(subChild, child, true);
if (child == parent.Last && fullPath.Count != 0 && recursive)
fullPath.Remove(fullPath.Last());
}
fullPath.Remove(fullPath.Last());
}
}
public override void GetBookmarks()
{
string json = "";
string path = GetFolder() + "\\Bookmarks";
json = File.ReadAllText(path);
fullPath.Clear();
fullPath.Add("Bookmark Bar");
using (StringReader reader = new StringReader(json))
using (JsonReader jsonReader = new JsonTextReader(reader))
{
JsonSerializer serializer = new JsonSerializer();
var o = (JToken) serializer.Deserialize(jsonReader);
var date_added = o["roots"]["bookmark_bar"]["children"];
Console.WriteLine(o["roots"]["bookmark_bar"]["children"].HasValues);
var ob = JObject.Parse(json);
foreach (var obj in o["roots"]["bookmark_bar"].Children())
{
var property = obj as JProperty;
}
var chil = o["roots"]["bookmark_bar"];
foreach (var child in o["roots"]["bookmark_bar"]["children"])
{
processChild(child, o["roots"]["bookmark_bar"]["children"], false);
}
}
fullPath.Clear();
fullPath.Add("Other Bookmarks");
using (StringReader reader = new StringReader(json))
using (JsonReader jsonReader = new JsonTextReader(reader))
{
JsonSerializer serializer = new JsonSerializer();
var o = (JToken) serializer.Deserialize(jsonReader);
foreach (var child in o["roots"]["other"]["children"])
{
processChild(child, o["roots"]["other"]["children"], false);
}
}
Bookmark.mergeBookmarks(bookmarks);
}