Skip to content

Commit

Permalink
[-](Parser): Fixed not complete builds crashing the app, doubled the …
Browse files Browse the repository at this point in the history
…delay before clicking save
  • Loading branch information
Yooooomi committed Feb 16, 2020
1 parent a8692f7 commit 56069b9
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 67 deletions.
54 changes: 18 additions & 36 deletions app/AutoRunes/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace AutoRunes
/// </summary>
public partial class MainWindow : Window
{
const String LeagueOfLegendsWindowName = "LeagueClientUx";
const string LeagueOfLegendsWindowName = "LeagueClientUx";
readonly WindowManager windowManager = new WindowManager();
readonly MouseManager mouseManager = new MouseManager();
readonly Parser parser = new Parser();
Expand All @@ -44,9 +44,9 @@ public MainWindow()

InitializeComponent();

/* windowManager.AssignWindow(LeagueOfLegendsWindowName);
windowManager.AssignWindow(LeagueOfLegendsWindowName);
mouseManager.enableMouseClicks();
mouseManager.addListener(onMouseClick);*/
//mouseManager.addListener(onMouseClick);
}

private void onMouseClick(object sender, MouseEventExtArgs e)
Expand All @@ -59,27 +59,16 @@ private void onMouseClick(object sender, MouseEventExtArgs e)

private void clickRune(Runes rune, bool isInChampSelect, int sleepTime, bool indentLeft = false)
{
Runes realRune;

if (rune.type != Runes.RuneType.Button)
{
realRune = Runes.GetRune(rune.type, rune.names[0]);
}
else
{
realRune = Runes.GetRune(rune.type, rune.names[0]);
}

WindowManager.Rect rect = windowManager.GetWindowPos();

if (indentLeft)
{
realRune.position.x -= 50;
rune.position.x -= 50;
}

Position convertedPos = Runes.TransferPositionResolution(realRune.position, 1600, 900, rect.Right - rect.Left, rect.Bottom - rect.Top);
Position convertedPos = Runes.TransferPositionResolution(rune.position, 1600, 900, rect.Right - rect.Left, rect.Bottom - rect.Top);

if (isInChampSelect == true && !realRune.position.alreadyTranslated)
if (isInChampSelect == true && !rune.position.alreadyTranslated)
{
convertedPos.x += (int) (0.085 * (rect.Right - rect.Left));
}
Expand All @@ -96,14 +85,7 @@ private void autorunes(string url, bool inChampSelect, bool clickEditRune, bool

ProfileRunes runes;

try
{
runes = parser.Parse(url);
}
catch
{
return;
}

if (clickEditRune)
{
Expand All @@ -112,12 +94,10 @@ private void autorunes(string url, bool inChampSelect, bool clickEditRune, bool

clickRune(Runes.GetRune(Runes.RuneType.Button, "square"), inChampSelect, sleepTime);

runes.primary.type = Runes.RuneType.PrimarySection;
clickRune(runes.primary, inChampSelect, sleepTime);
for (int i = 0; i < 4; i++)
foreach (Runes i in runes.primaryRunes)
{
runes.runes[i].type = Runes.RuneType.Primary;
clickRune(runes.runes[i], inChampSelect, sleepTime);
clickRune(i, inChampSelect, sleepTime);
}

bool indentLeft = false;
Expand All @@ -130,21 +110,23 @@ private void autorunes(string url, bool inChampSelect, bool clickEditRune, bool
indentLeft = true;
}

runes.secondary.type = Runes.RuneType.SecondarySection;
clickRune(runes.secondary, inChampSelect, sleepTime, indentLeft);
for (int i = 4; i < 4 + 2; i++)
foreach (Runes i in runes.secondaryRunes)
{
runes.runes[i].type = Runes.RuneType.Secondary;
clickRune(runes.runes[i], inChampSelect, sleepTime);
clickRune(i, inChampSelect, sleepTime);
}
for (int i = 6; i < 6 + 3; i++)
foreach (Runes i in runes.shards)
{
runes.runes[i].type = Runes.RuneType.Shard;
clickRune(runes.runes[i], inChampSelect, sleepTime);
clickRune(i, inChampSelect, sleepTime);
}

if (clickSave == true)
{
clickRune(Runes.GetRune(Runes.RuneType.Button, "save"), inChampSelect, sleepTime);
clickRune(Runes.GetRune(Runes.RuneType.Button, "save"), inChampSelect, sleepTime * 2);
if (inChampSelect)
{
clickRune(Runes.GetRune(Runes.RuneType.Button, "close"), inChampSelect, sleepTime);
}
}
}

Expand Down
63 changes: 43 additions & 20 deletions app/AutoRunes/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,72 @@ public ProfileRunes Parse(string url)
{
WebClient client = new WebClient();

String html = client.DownloadString(url);
string html = client.DownloadString(url);

HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);

HtmlNodeCollection primariesNode = doc.DocumentNode.SelectNodes("//div[@class='" + "new-runes__title" + "']");
String primaryTier = primariesNode[0].Attributes["path"].Value;
String secondaryTier = primariesNode[1].Attributes["path"].Value;
HtmlNodeCollection primariesNode = doc.DocumentNode.SelectNodes("//div[@class='new-runes__title']");
string primaryTier = primariesNode[0].Attributes["path"].Value;
string secondaryTier = primariesNode[1].Attributes["path"].Value;

Debug.WriteLine(primaryTier);
Debug.WriteLine(secondaryTier);
HtmlNodeCollection primaryRunes = doc.DocumentNode.SelectNodes("(//div[@class='new-runes__primary']//div[@class='new-runes__item']/span[string-length(text()) > 0])[position() < 5]");
HtmlNodeCollection secondaryRunes = doc.DocumentNode.SelectNodes("(//div[@class='new-runes__secondary']//div[@class='new-runes__item']/span[string-length(text()) > 0])[position() < 3]");
HtmlNodeCollection shards = doc.DocumentNode.SelectNodes("(//div[@class='new-runes__shards']//span[@shard-type])[position() < 4]");

HtmlNodeCollection runes = doc.DocumentNode.SelectNodes("(//div[@class='new-runes__item']//span[string-length(text()) > 0])[position() < 7]");
List<String> runeNames = new List<String>();
List<string> primaryRuneNames = new List<string>();
List<string> secondaryRuneNames = new List<string>();
List<string> shardNames = new List<string>();

foreach (var rune in runes)
if (primaryRunes != null)
{
runeNames.Add(rune.InnerText);
foreach (var rune in primaryRunes)
{
primaryRuneNames.Add(rune.InnerText);
}
}

List<String> shardNames = new List<String>();
if (secondaryRunes != null)
{
foreach (var rune in secondaryRunes)
{
secondaryRuneNames.Add(rune.InnerText);
}
}

HtmlNodeCollection shards = doc.DocumentNode.SelectNodes("(//div[@class='new-runes__shards']//span[@shard-type])[position() < 4]");
foreach (var shard in shards)
if (shards != null)
{
shardNames.Add(shard.Attributes["shard-type"].Value);
foreach (var shard in shards)
{
shardNames.Add(shard.Attributes["shard-type"].Value);
}
}

List<Runes> finalRunes = new List<Runes>();

foreach (var i in runeNames)
foreach (var i in primaryRuneNames)
{
finalRunes.Add(Runes.runes.Find(e => e.names.Contains(i.ToLower())).copy());
Runes rune = Runes.GetRune(Runes.RuneType.Primary, i).copy();
finalRunes.Add(rune);
}
foreach (var i in secondaryRuneNames)
{
Runes rune = Runes.GetRune(Runes.RuneType.Secondary, i).copy();
finalRunes.Add(rune);
}
for (int i = 0; i < shardNames.Count; i++)
{
Debug.WriteLine(shardNames[i].ToLower() + (i + 1).ToString());
finalRunes.Add(Runes.runes.Find(e => e.names.Contains(shardNames[i].ToLower() + (i + 1).ToString())).copy());
string shardName = shardNames[i].ToLower() + (i + 1);
Runes shard = Runes.GetRune(Runes.RuneType.Shard, shardName).copy();
finalRunes.Add(shard);
}

Runes primarySection = Runes.GetRune(Runes.RuneType.PrimarySection, primaryTier).copy();
Runes secondarySection = Runes.GetRune(Runes.RuneType.SecondarySection, secondaryTier).copy();

return new ProfileRunes(
Runes.runes.Find(e => e.type == Runes.RuneType.PrimarySection && e.names.Contains(primaryTier.ToLower())).copy(),
Runes.runes.Find(e => e.type == Runes.RuneType.SecondarySection && e.names.Contains(secondaryTier.ToLower())).copy(),
primarySection,
secondarySection,
finalRunes
);
}
Expand Down
35 changes: 30 additions & 5 deletions app/AutoRunes/Runes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ public static Position TransferPositionResolution(Position oldPos, double oldWid
static public List<Runes> buttons = new List<Runes>
{
new Runes(RuneType.Button, new List<String>() { "save" }, new Position(500, 161)),
new Runes(RuneType.Button, new List<String>() { "edit_rune" }, new Position(496, 864, true)),
new Runes(RuneType.Button, new List<String>() { "edit_rune" }, new Position(530, 852, true)),
new Runes(RuneType.Button, new List<String>() { "square" }, new Position(93, 844)),
new Runes(RuneType.Button, new List<String>() { "close" }, new Position(1454, 93, true)),
};

static public List<Runes> runes = new List<Runes>
Expand Down Expand Up @@ -120,11 +121,11 @@ static public Runes GetRune(RuneType type, String name)
{
if (type == RuneType.Button)
{
return Runes.buttons.Find(e => e.type == type && e.names.Contains(name));
return Runes.buttons.Find(e => e.type == type && e.names.Contains(name.ToLower()));
}
else
{
return Runes.runes.Find(e => e.type == type && e.names.Contains(name));
return Runes.runes.Find(e => e.type == type && e.names.Contains(name.ToLower()));
}
}

Expand Down Expand Up @@ -170,13 +171,37 @@ class ProfileRunes
{
public Runes primary;
public Runes secondary;
public List<Runes> runes;
public List<Runes> primaryRunes;
public List<Runes> secondaryRunes;
public List<Runes> shards;

public ProfileRunes(Runes p, Runes s, List<Runes> runes)
{
p.type = Runes.RuneType.PrimarySection;
s.type = Runes.RuneType.SecondarySection;

this.primary = p;
this.secondary = s;
this.runes = runes;

primaryRunes = new List<Runes>();
secondaryRunes = new List<Runes>();
shards = new List<Runes>();

foreach (var i in runes)
{
if (i.type == Runes.RuneType.Primary)
{
primaryRunes.Add(i);
}
else if (i.type == Runes.RuneType.Secondary)
{
secondaryRunes.Add(i);
}
else if (i.type == Runes.RuneType.Shard)
{
shards.Add(i);
}
}
}
}
}
6 changes: 3 additions & 3 deletions app/Installer/Installer.vdproj
Original file line number Diff line number Diff line change
Expand Up @@ -461,15 +461,15 @@
{
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:Autorunes"
"ProductCode" = "8:{E0AC7D90-6068-460D-81CB-8FE3FC593707}"
"PackageCode" = "8:{0C3949B7-B171-4D38-B926-96CDEE7C8098}"
"ProductCode" = "8:{A500DEB2-D136-41E0-9577-FDAA4ABEC8E2}"
"PackageCode" = "8:{A2C65B3A-4423-44EE-BC70-86CE79DD0021}"
"UpgradeCode" = "8:{C334B272-D5F5-4AF4-8031-F8E0A440FDFB}"
"AspNetVersion" = "8:2.0.50727.0"
"RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:2.0.3"
"ProductVersion" = "8:2.1.3"
"Manufacturer" = "8:Yooooomi"
"ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:"
Expand Down
6 changes: 4 additions & 2 deletions extension/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ chrome.tabs.onActivated.addListener((infos) => {
chrome.tabs.get(infos.tabId, (tab) => checkIcon(tab.url));
});

chrome.webNavigation.onCompleted.addListener((infos) => {
checkIcon(infos.url);
chrome.tabs.onUpdated.addListener((tabId, details, tab) => {
if (!tab.active) return;
if (!details.url) return;
checkIcon(details.url);
});

chrome.runtime.onInstalled.addListener(function() {
Expand Down
2 changes: 1 addition & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Autorunes",
"author": "Yooooomi",
"version": "1.0",
"version": "1.0.2",
"description": "Extension to interact directly with native Autorunes APP",
"manifest_version": 2,
"icons": {
Expand Down

0 comments on commit 56069b9

Please sign in to comment.