Skip to content

Commit cf4e82a

Browse files
authored
Merge pull request #7 from zhangjk95/master
Fix online game data parsing
2 parents 41a3a6a + badf1df commit cf4e82a

File tree

7 files changed

+44
-35
lines changed

7 files changed

+44
-35
lines changed

.vs/Etupirka/v14/.suo

-112 KB
Binary file not shown.

Etupirka.sln

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25420.1
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28307.852
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Etupirka", "Etupirka\Etupirka.csproj", "{2DE8A7AD-A633-4CE4-AB24-9590A7BB0202}"
77
EndProject
@@ -19,4 +19,7 @@ Global
1919
GlobalSection(SolutionProperties) = preSolution
2020
HideSolutionNode = FALSE
2121
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {033E3683-970D-4A61-A634-11B68D67B0E0}
24+
EndGlobalSection
2225
EndGlobal

Etupirka/Dialog/GamePropertyDialog.xaml.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using MahApps.Metro.Controls;
1414
using System.ComponentModel;
1515
using Microsoft.Win32;
16+
using MahApps.Metro.Controls.Dialogs;
1617

1718
namespace Etupirka.Dialog
1819
{
@@ -36,15 +37,25 @@ public GamePropertyDialog(GameExecutionInfo _game)
3637
}
3738

3839
private bool updating;
39-
private void SyncESID_Click(object sender, RoutedEventArgs e)
40+
private async void SyncESID_Click(object sender, RoutedEventArgs e)
4041
{
4142
if (updating)
4243
{
4344
return;
4445
}
4546
updating = true;
46-
bgame.updateInfoFromES();
47-
updating = false;
47+
try
48+
{
49+
await bgame.updateInfoFromES();
50+
}
51+
catch
52+
{
53+
await this.ShowMessageAsync("Error", "Failed to sync game data");
54+
}
55+
finally
56+
{
57+
updating = false;
58+
}
4859
}
4960

5061
private void btnDialogOk_Click(object sender, RoutedEventArgs e)

Etupirka/Etupirka.csproj.user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
<VerifyUploadedFiles>false</VerifyUploadedFiles>
1212
</PropertyGroup>
1313
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
14-
<StartAction>Program</StartAction>
14+
<StartAction>Project</StartAction>
1515
</PropertyGroup>
1616
</Project>

Etupirka/GameData/GameInfo.cs

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ public string SaleDayString
9393
else return "";
9494
}
9595
}
96-
public void updateInfoFromES()
96+
public async Task updateInfoFromES()
9797
{
9898
if (Properties.Settings.Default.useOfflineESDatabase)
9999
{
100100
updateInfoFromESOffline();
101101
}
102102
else
103103
{
104-
updateInfoFromESOnline();
104+
await updateInfoFromESOnline();
105105
}
106106

107107
}
@@ -121,36 +121,16 @@ public void updateInfoFromESOffline()
121121
}
122122
}
123123

124-
public async void updateInfoFromESOnline()
124+
public async Task updateInfoFromESOnline()
125125
{
126126
if (erogameScapeID > 0)
127127
{
128-
string result = await TaskEx.Run(() => { return NetworkUtility.GetString("http://erogamescape.dyndns.org/~ap2/ero/toukei_kaiseki/game.php?game=" + erogameScapeID); });
129-
130-
//Console.Write(result);
131-
string matchTitle = "<div id=\"soft-title\"><span class=\"bold\">(?<title>.*?)</span>";
132-
string matchBrand = "<td><a href=\"brand.php\\?brand=(?<brandid>.*?)\">(?<brand>.*?)</a></td>";
133-
string matchSaleDay = "<td><a href=\"toukei_hatubaibi_month.php\\?.*\">(?<saleday>.*?)</a></td>";
128+
var document = await NetworkUtility.GetHtmlDocument("http://erogamescape.dyndns.org/~ap2/ero/toukei_kaiseki/game.php?game=" + erogameScapeID);
134129

135-
Regex re = new Regex(matchTitle, RegexOptions.IgnoreCase);
136-
for (Match m = re.Match(result); m.Success; m = m.NextMatch())
137-
{
138-
Title = System.Net.WebUtility.HtmlDecode(m.Groups["title"].Value);
139-
// Console.Write(title);
140-
}
141-
re = new Regex(matchBrand, RegexOptions.IgnoreCase);
142-
for (Match m = re.Match(result); m.Success; m = m.NextMatch())
143-
{
144-
Brand = System.Net.WebUtility.HtmlDecode(m.Groups["brand"].Value);
145-
// Console.Write(brand);
146-
}
147-
re = new Regex(matchSaleDay, RegexOptions.IgnoreCase);
148-
for (Match m = re.Match(result); m.Success; m = m.NextMatch())
149-
{
150-
string saleday = m.Groups["saleday"].Value;
151-
SaleDay = DateTime.ParseExact(saleday, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
152-
// Console.Write(saleday);
153-
}
130+
Title = document.GetElementById("soft-title").GetElementsByTagName("span")[0].InnerText;
131+
Brand = document.GetElementById("brand").GetElementsByTagName("td")[0].InnerText;
132+
string saleday = document.GetElementById("sellday").GetElementsByTagName("td")[0].InnerText;
133+
SaleDay = DateTime.ParseExact(saleday, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
154134
}
155135
}
156136

Etupirka/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ private void UpdateStatus(int time=0)
309309
}
310310
catch (Exception e)
311311
{
312-
Console.WriteLine(e);
312+
// Console.WriteLine(e);
313313
}
314314
}
315315

Etupirka/NetworkUtility.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
using System.Text;
66
using System.Collections;
77
using Etupirka.Views;
8+
using System.Windows.Forms;
9+
using System.Threading.Tasks;
10+
using System.Threading;
11+
using Timer = System.Threading.Timer;
812

913
namespace Etupirka
1014
{
@@ -68,5 +72,16 @@ public static byte[] GetData(string uri)
6872
return null;
6973
}
7074
}
75+
76+
public static Task<HtmlDocument> GetHtmlDocument(string uri, int timeoutMs = 10000)
77+
{
78+
var browser = new WebBrowser();
79+
var taskCompletionSource = new TaskCompletionSource<HtmlDocument>();
80+
Timer timer = new Timer((state) => taskCompletionSource.TrySetException(new TimeoutException()), null, timeoutMs, Timeout.Infinite);
81+
browser.DocumentCompleted += (sender, e) => taskCompletionSource.TrySetResult(browser.Document);
82+
browser.ScriptErrorsSuppressed = true;
83+
browser.Navigate(uri);
84+
return taskCompletionSource.Task;
85+
}
7186
}
7287
}

0 commit comments

Comments
 (0)