-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinkedinAddon.cs
57 lines (52 loc) · 2.13 KB
/
LinkedinAddon.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using G1ANT.Language;
using G1ANT.Addon.Linkedin.Properties;
using System.IO;
namespace G1ANT.Addon.Linkedin
{
[Addon(Name = "Linkedin", Tooltip = "Automates the LinkedIn site")]
[Copyright(Author = "", Copyright = "", Email = "support@g1ant.com", Website = "www.g1ant.com")]
[License(Type = "LGPL", ResourceName = "License.txt")]
[CommandGroup(Name = "linkedin", Tooltip = "")]
public class LinkedinAddon : Language.Addon
{
public override void LoadDlls()
{
UnpackDrivers();
base.LoadDlls();
}
private void UnpackDrivers()
{
var unpackFolder = AbstractSettingsContainer.Instance.UserDocsAddonFolder.FullName;
var embeddedResourceDictionary = new Dictionary<string, byte[]>()
{
{ "chromedriver.exe", Resources.chromedriver },
{ "geckodriver.exe", Resources.geckodriver },
{ "IEDriverServer.exe", Resources.IEDriverServer },
{ "MicrosoftWebDriver.exe", Resources.MicrosoftWebDriver }
};
foreach (var embededResource in embeddedResourceDictionary.Where(e => !DoesFileExist(unpackFolder, e.Key) || !AreFilesOfTheSameLength(e.Value.Length, unpackFolder, e.Key)))
{
try
{
using (FileStream stream = File.Create(Path.Combine(unpackFolder, embededResource.Key)))
{
stream.Write(embededResource.Value, 0, embededResource.Value.Length);
}
}
catch (Exception ex) { RobotMessageBox.Show(ex.Message); }
}
}
private bool DoesFileExist(string folder, string fileName)
{
return File.Exists(Path.Combine(folder, fileName));
}
private bool AreFilesOfTheSameLength(int length, string folder, string fileName)
{
return length == new FileInfo(Path.Combine(folder, fileName)).Length;
}
}
}