Commit 400a0dbd authored by shubham's avatar shubham

Done with Chrome module!

parent 9ea05768
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;
using Personal_Insight.Models;
using Personal_Insight.Models.JSON_Models.BrowserHistory;
using Personal_Insight.Models.JSON_Models.ChromeAutofill;
using Personal_Insight.Models.JSON_Models.Extensions;
using Personal_Insight.Models.JSON_Models.SearchEngines;
using Personal_Insight.Pages;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Personal_Insight.ComputeProduct
{
class Chrome
{
private GoogleProductModel googleProduct;
private IntroPage_5 page;
public GoogleProductModel GoogleProduct { get => googleProduct; set => googleProduct = value; }
public List<BookMark> bookMarks;
public List<DictionaryWord> dictionaryWords;
public ChromeAutofillModel autofillContent;
public BrowserHistoryModel browserHistoryModel;
public ExtensionsModel extensionsModel;
public SearchEnginesModel searchEnginesModel;
public Chrome()
{
}
public void startWork(IntroPage_5 page)
{
this.page = page;
page.enterLog("Starting work on Chrome");
string[] files = Directory.GetFiles(googleProduct.ProductFolderPath);
foreach (String file in files)
{
if (file.Contains("Autofill.json"))
{
gather_AutoFills(File.ReadAllText(file));
if (autofillContent.Autofill.Count >= 1)
{
page.enterLog("Logged autofill content!");
}
}
else if (file.Contains("Bookmarks.html"))
{
gather_Bookmarks(file);
page.enterLog("Logged " + bookMarks.Count + " Chrome bookmarks!");
}
else if (file.Contains("BrowserHistory.json"))
{
gather_BrowserEvents(File.ReadAllText(file));
page.enterLog("Logged " + browserHistoryModel.BrowserHistory.Count + " items of browser history!");
}
else if (file.Contains("Dictionary.csv"))
{
gather_DictionaryWords(file);
page.enterLog("Logged " + dictionaryWords.Count + " dictionary words!");
}
else if (file.Contains("Extensions.json"))
{
gather_Extensions(File.ReadAllText(file));
page.enterLog("Logged " + extensionsModel.Extensions.Count + " Chrome Extensions!");
}
else if (file.Contains("SearchEngines.json"))
{
gather_SearchEngines(File.ReadAllText(file));
page.enterLog("Logged " + searchEnginesModel.SearchEngines.Count + " Search Engines!");
}
}
Console.WriteLine("sTOP HERE");
}
private void gather_AutoFills(String jsonText)
{
autofillContent = ChromeAutofillModel.FromJson(jsonText);
}
private void gather_SearchEngines(string jsonText)
{
//jsonText = jsonText.Replace(@"\", @"\\");
searchEnginesModel = SearchEnginesModel.FromJson(jsonText);
}
private void gather_Extensions(string jsonText)
{
//jsonText = jsonText.Replace(@"\", @"\\");
extensionsModel = ExtensionsModel.FromJson(jsonText);
}
private void gather_DictionaryWords(string filePath)
{
dictionaryWords = new List<DictionaryWord>();
String[] lines = File.ReadAllLines(filePath);
foreach(String line in lines)
{
dictionaryWords.Add(new DictionaryWord(line));
}
}
private void gather_BrowserEvents(String jsonText)
{
browserHistoryModel = BrowserHistoryModel.FromJson(jsonText);
}
private void gather_Bookmarks(String filePath)
{
bookMarks = new List<BookMark>();
String[] lines = File.ReadAllLines(filePath);
foreach (String line in lines)
{
if (line.Contains("<DT><A HREF=\""))
{
String link = line.Substring(line.IndexOf("\"")+1);
link = link.Substring(0, link.IndexOf("\""));
String name = line.Remove(0, line.IndexOf(">") + 1);
name = name.Remove(0, name.IndexOf(">") + 1);
name = name.Substring(0, name.IndexOf("<"));
bookMarks.Add(new BookMark(name, link));
//page.enterLog("Name: "+ name + ", Link: " + link);
}
}
}
public class BookMark
{
public String name { get; set; }
public String link { get; set; }
public BookMark(string name, string link)
{
this.name = name;
this.link = link;
}
}
public class DictionaryWord
{
public String word { get; set; }
public DictionaryWord(string word)
{
this.word = word;
}
}
}
}
......@@ -279,7 +279,9 @@ namespace Personal_Insight.Models
break;
case Chrome:
productObject = new Android_Device_Configuration_Service();
productObject = new Chrome();
((Chrome)productObject).GoogleProduct = googleProductModel;
((Chrome)productObject).startWork(page);
break;
case GPC:
......
// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
// using Personal_Insight.Models.JSON_Models.BrowserHistory;
//
// var browserHistoryModel = BrowserHistoryModel.FromJson(jsonString);
namespace Personal_Insight.Models.JSON_Models.BrowserHistory
{
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public partial class BrowserHistoryModel
{
[JsonProperty("Browser History")]
public List<BrowserHistory> BrowserHistory { get; set; }
}
public partial class BrowserHistory
{
[JsonProperty("favicon_url")]
public Uri FaviconUrl { get; set; }
[JsonProperty("page_transition")]
public string PageTransition { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("url")]
public Uri Url { get; set; }
[JsonProperty("time_usec")]
public long TimeUsec { get; set; }
}
public partial class BrowserHistoryModel
{
public static BrowserHistoryModel FromJson(string json) => JsonConvert.DeserializeObject<BrowserHistoryModel>(json, Personal_Insight.Models.JSON_Models.BrowserHistory.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this BrowserHistoryModel self) => JsonConvert.SerializeObject(self, Personal_Insight.Models.JSON_Models.BrowserHistory.Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters =
{
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
}
// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
// using Personal_Insight.Models;
//
// var chromeAutofillModel = ChromeAutofillModel.FromJson(jsonString);
namespace Personal_Insight.Models.JSON_Models.ChromeAutofill
{
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public partial class ChromeAutofillModel
{
[JsonProperty("Autofill")]
public List<Autofill> Autofill { get; set; }
}
public partial class Autofill
{
[JsonProperty("name_first")]
public List<string> NameFirst { get; set; }
[JsonProperty("address_home_country")]
public string AddressHomeCountry { get; set; }
[JsonProperty("address_home_sorting_code")]
public string AddressHomeSortingCode { get; set; }
[JsonProperty("address_home_state")]
public string AddressHomeState { get; set; }
[JsonProperty("address_home_dependent_locality")]
public string AddressHomeDependentLocality { get; set; }
[JsonProperty("address_home_city")]
public string AddressHomeCity { get; set; }
[JsonProperty("address_home_language_code")]
public string AddressHomeLanguageCode { get; set; }
[JsonProperty("name_full")]
public List<string> NameFull { get; set; }
[JsonProperty("origin")]
public string Origin { get; set; }
[JsonProperty("name_last")]
public List<string> NameLast { get; set; }
[JsonProperty("name_middle")]
public List<string> NameMiddle { get; set; }
[JsonProperty("use_count")]
public long UseCount { get; set; }
[JsonProperty("email_address")]
public List<string> EmailAddress { get; set; }
[JsonProperty("company_name")]
public string CompanyName { get; set; }
[JsonProperty("address_home_line1")]
public string AddressHomeLine1 { get; set; }
[JsonProperty("address_home_line2")]
[JsonConverter(typeof(ParseStringConverter))]
public long AddressHomeLine2 { get; set; }
[JsonProperty("guid")]
public Guid Guid { get; set; }
[JsonProperty("address_home_zip")]
[JsonConverter(typeof(ParseStringConverter))]
public long AddressHomeZip { get; set; }
[JsonProperty("address_home_street_address")]
public string AddressHomeStreetAddress { get; set; }
[JsonProperty("phone_home_whole_number")]
public List<string> PhoneHomeWholeNumber { get; set; }
[JsonProperty("use_date")]
public long UseDate { get; set; }
}
public partial class ChromeAutofillModel
{
public static ChromeAutofillModel FromJson(string json) => JsonConvert.DeserializeObject<ChromeAutofillModel>(json, Personal_Insight.Models.JSON_Models.ChromeAutofill.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this ChromeAutofillModel self) => JsonConvert.SerializeObject(self, Personal_Insight.Models.JSON_Models.ChromeAutofill.Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters =
{
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
internal class ParseStringConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(long) || t == typeof(long?);
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) return null;
var value = serializer.Deserialize<string>(reader);
long l;
if (Int64.TryParse(value, out l))
{
return l;
}
throw new Exception("Cannot unmarshal type long");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (long)untypedValue;
serializer.Serialize(writer, value.ToString());
return;
}
public static readonly ParseStringConverter Singleton = new ParseStringConverter();
}
}
// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
// using Personal_Insight.Models.JSON_Models.Extensions;
//
// var extensionsModel = ExtensionsModel.FromJson(jsonString);
namespace Personal_Insight.Models.JSON_Models.Extensions
{
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public partial class ExtensionsModel
{
[JsonProperty("Extensions")]
public List<Extension> Extensions { get; set; }
[JsonProperty("Extension Settings")]
public List<ExtensionSetting> ExtensionSettings { get; set; }
}
public partial class ExtensionSetting
{
[JsonProperty("extension_id")]
public string ExtensionId { get; set; }
[JsonProperty("value")]
public string Value { get; set; }
[JsonProperty("key")]
public string Key { get; set; }
}
public partial class Extension
{
[JsonProperty("incognito_enabled")]
public bool IncognitoEnabled { get; set; }
[JsonProperty("remote_install")]
public bool RemoteInstall { get; set; }
[JsonProperty("disable_reasons")]
public long DisableReasons { get; set; }
[JsonProperty("installed_by_custodian")]
public bool InstalledByCustodian { get; set; }
[JsonProperty("update_url")]
public Uri UpdateUrl { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("version")]
public string Version { get; set; }
[JsonProperty("enabled")]
public bool Enabled { get; set; }
}
public partial class ExtensionsModel
{
public static ExtensionsModel FromJson(string json) => JsonConvert.DeserializeObject<ExtensionsModel>(json, Personal_Insight.Models.JSON_Models.Extensions.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this ExtensionsModel self) => JsonConvert.SerializeObject(self, Personal_Insight.Models.JSON_Models.Extensions.Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters =
{
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
}
// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
// using Personal_Insight.Models.JSON_Models.SearchEngines;
//
// var searchEnginesModel = SearchEnginesModel.FromJson(jsonString);
namespace Personal_Insight.Models.JSON_Models.SearchEngines
{
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public partial class SearchEnginesModel
{
[JsonProperty("Search Engines")]
public List<SearchEngine> SearchEngines { get; set; }
}
public partial class SearchEngine
{
[JsonProperty("suggestions_url")]
public string SuggestionsUrl { get; set; }
[JsonProperty("favicon_url")]
public Uri FaviconUrl { get; set; }
[JsonProperty("safe_for_autoreplace")]
public bool SafeForAutoreplace { get; set; }
[JsonProperty("date_created")]
public double DateCreated { get; set; }
[JsonProperty("url")]
public string Url { get; set; }
[JsonProperty("new_tab_url")]
public string NewTabUrl { get; set; }
[JsonProperty("originating_url")]
public Uri OriginatingUrl { get; set; }
[JsonProperty("sync_guid")]
public Guid SyncGuid { get; set; }
[JsonProperty("short_name")]
public string ShortName { get; set; }
[JsonProperty("keyword")]
public string Keyword { get; set; }
[JsonProperty("input_encodings")]
public string InputEncodings { get; set; }
[JsonProperty("prepopulate_id")]
public long PrepopulateId { get; set; }
[JsonProperty("last_modified")]
public double LastModified { get; set; }
}
public partial class SearchEnginesModel
{
public static SearchEnginesModel FromJson(string json) => JsonConvert.DeserializeObject<SearchEnginesModel>(json, Personal_Insight.Models.JSON_Models.SearchEngines.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this SearchEnginesModel self) => JsonConvert.SerializeObject(self, Personal_Insight.Models.JSON_Models.SearchEngines.Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters =
{
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
}
......@@ -61,12 +61,17 @@ namespace Personal_Insight.Pages
private void worker_DoWork(object sender, DoWorkEventArgs e)
{
var watch = System.Diagnostics.Stopwatch.StartNew();
for (int i = 0; i < googleProductList.Count; i++)
{
product_worker(googleProductList.ElementAt(i));
decimal send = ( ((i + 1) / (decimal)googleProductList.Count) * 100);
(sender as BackgroundWorker).ReportProgress((int)send); // TODO Add a check if count==0
}
watch.Stop();
enterLog("Elapsed Time: " + watch.ElapsedMilliseconds + "ms");
}
......
......@@ -80,6 +80,9 @@
<Reference Include="Microsoft.WindowsAPICodePack.ShellExtensions, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.WindowsAPICodePack-Shell.1.1.0.0\lib\Microsoft.WindowsAPICodePack.ShellExtensions.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NodaTime, Version=2.0.2.0, Culture=neutral, PublicKeyToken=4226afe0d9b296d1, processorArchitecture=MSIL">
<HintPath>packages\NodaTime.2.0.2\lib\net45\NodaTime.dll</HintPath>
</Reference>
......@@ -158,10 +161,15 @@
<Compile Include="ComputeProduct\Blogger.cs" />
<Compile Include="ComputeProduct\Bookmarks.cs" />
<Compile Include="ComputeProduct\Calendar.cs" />
<Compile Include="ComputeProduct\Chrome.cs" />
<Compile Include="ComputeProduct\YouTube.cs" />
<Compile Include="Models\JSON_Models\BrowserHistory\BrowserHistoryModel.cs" />
<Compile Include="Models\JSON_Models\ChromeAutofill\ChromeAutofillModel.cs" />
<Compile Include="Models\GoogleProductModel.cs" />
<Compile Include="Models\GoogleProductsList.cs" />
<Compile Include="Models\HelpfulMethods.cs" />
<Compile Include="Models\JSON_Models\Extensions\ExtensionsModel.cs" />
<Compile Include="Models\JSON_Models\SearchEngines\SearchEnginesModel.cs" />
<Compile Include="Pages\IntroPage_1.xaml.cs">
<DependentUpon>IntroPage_1.xaml</DependentUpon>
</Compile>
......@@ -277,5 +285,6 @@
<ItemGroup>
<Resource Include="assets\icons\icons8-close-window-filled-48.png" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
......@@ -14,6 +14,7 @@
<package id="MaterialDesignThemes" version="2.5.1" targetFramework="net472" />
<package id="Microsoft.WindowsAPICodePack-Core" version="1.1.0.0" targetFramework="net472" />
<package id="Microsoft.WindowsAPICodePack-Shell" version="1.1.0.0" targetFramework="net472" />
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net472" />
<package id="NodaTime" version="2.0.2" targetFramework="net472" />
<package id="System.Reflection" version="4.1.0" targetFramework="net472" />
<package id="System.Reflection.TypeExtensions" version="4.1.0" targetFramework="net472" />
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment