public static string CleanHistory(string file)
{
string ret = string.Empty;
string sql = string.Empty;
FileInfo fi = new FileInfo(file);
// open json file
string json = JSON.OpenJSONFiel(Path.Combine(fi.Directory.FullName, "Bookmarks"));
#region // get bookmark urls
List<string> urls = new List<string>();
JObject basenode = JObject.Parse(json);
JToken basetoken = basenode["roots"]["bookmark_bar"]["children"];
Stack<JToken> nodes = new Stack<JToken>();
nodes.Push(basetoken);
while (nodes.Count > 0)
{
JToken node = nodes.Pop();
foreach (JToken t in node.Children())
{
if (t.SelectToken("type") == null) continue;
if (t.SelectToken("type").ToString() == "folder")
{
nodes.Push(t["children"]);
}
else if (t.SelectToken("type").ToString() == "url")
{
//Console.WriteLine(t.SelectToken("id"));
urls.Add(t.SelectToken("url").ToString());
}
}
}
#endregion
#region // get ids from urls table in History database file
List<int> ids = new List<int>();
foreach (string url in urls)
{
int int_result = GetIDsFromURLs(fi.FullName, url);
if (int_result != 0)
{
ids.Add(int_result);
}
}
#endregion
#region // craete query
string where = string.Empty;
string[] cols = new string[] {
"urls", "title"
};
if (ids.Count > 0)
{
where = string.Format("where id not in ({0})", string.Join(",", ids.ToArray()));
}
if (Shred)
{
sql += CreateRandomBlobQuery(cols, "urls", where);
}
sql += string.Format("delete from urls {0};", where);
sql += string.Format("delete from visits;");
cols = new string[] {
"lower_term", "term"
};
if (Shred)
{
sql += CreateRandomBlobQuery(cols, "keyword_search_terms");
}
sql += "delete from keyword_search_terms;";
#endregion
string result = SQLite.ExecuteNonQuery(file, sql);
if (result != string.Empty)
{
ret = "An unkown error occured while executing a query in CommandLogic_Chrome.CleanAutofill";
if (result.Contains("database is locked"))
{
ret = "database is locked";
}
}
return ret;
}