Skip to content

Commit b7b7562

Browse files
committed
Build v1.3.0, close #13 and fix metadata parsing
1 parent 668dfd5 commit b7b7562

File tree

12 files changed

+468
-13
lines changed

12 files changed

+468
-13
lines changed

BHOUserScript/BHOUserScript.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@
140140
<DependentUpon>ScriptEditFrm.cs</DependentUpon>
141141
</Compile>
142142
<Compile Include="SettingsFile.cs" />
143+
<Compile Include="UpdateBHOFrm.cs">
144+
<SubType>Form</SubType>
145+
</Compile>
146+
<Compile Include="UpdateBHOFrm.Designer.cs">
147+
<DependentUpon>UpdateBHOFrm.cs</DependentUpon>
148+
</Compile>
149+
<Compile Include="UpdateResponse.cs" />
143150
</ItemGroup>
144151
<ItemGroup>
145152
<None Include="App.config" />
@@ -191,6 +198,9 @@
191198
<EmbeddedResource Include="ScriptEditFrm.resx">
192199
<DependentUpon>ScriptEditFrm.cs</DependentUpon>
193200
</EmbeddedResource>
201+
<EmbeddedResource Include="UpdateBHOFrm.resx">
202+
<DependentUpon>UpdateBHOFrm.cs</DependentUpon>
203+
</EmbeddedResource>
194204
</ItemGroup>
195205
<ItemGroup>
196206
<Content Include="LICENSE">

BHOUserScript/ParseScriptMetadata.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ namespace BHOUserScript
99
/// </summary>
1010
static class ParseScriptMetadata
1111
{
12-
static readonly string Name = @"// +@name( |\t)+([a-zA-Z\d :.,/\*_\+\?!-]+)";
13-
static readonly string Description = @"// +@description( |\t)+([a-zA-Z\d :.,/\*_\+\?!-]+)";
14-
static readonly string Author = @"// +@author( |\t)+([a-zA-Z\d :.,/\*_\+\?!-]+)";
15-
static readonly string Version = @"// +@version( |\t)+([a-zA-Z\d :.,/\*_\+\?!-]+)";
16-
static readonly string Match = @"// +@match( |\t)+([a-zA-Z\d :.,/\*_\+\?!-]+)";
17-
static readonly string Include = @"// +@include( |\t)+([a-zA-Z\d :.,/\*_\+\?!-]+)";
18-
static readonly string UpdateUrl = @"// +@updateURL( |\t)+([a-zA-Z\d :.,/\*_\+\?!-]+)";
12+
static readonly string Name = @"// +@name( |\t)+([a-zA-Z\d :.,/\*_\+\?!\-\(\)]+)";
13+
static readonly string Description = @"// +@description( |\t)+([a-zA-Z\d :.,/\*_\+\?!\-\(\)]+)";
14+
static readonly string Author = @"// +@author( |\t)+([a-zA-Z\d :.,/\*_\+\?!\-\(\)]+)";
15+
static readonly string Version = @"// +@version( |\t)+([a-zA-Z\d :.,/\*_\+\?!\-\(\)]+)";
16+
static readonly string Match = @"// +@match( |\t)+([a-zA-Z\d :.,/\*_\+\?!\-\(\)]+)";
17+
static readonly string Include = @"// +@include( |\t)+([a-zA-Z\d :.,/\*_\+\?!\-\(\)]+)";
18+
static readonly string UpdateUrl = @"// +@updateURL( |\t)+([a-zA-Z\d :.,/\*_\+\?!\-\(\)]+)";
1919

2020
public static Script Parse(string path)
2121
{

BHOUserScript/Program.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
using Microsoft.Win32;
1010
using Newtonsoft.Json;
1111
using SHDocVw;
12+
using System.Text;
13+
using System.Diagnostics;
1214

1315
/**
1416
* ____ _ __ __
@@ -69,6 +71,7 @@ public void CheckInstall()
6971
StreamWriter jsonDb = new StreamWriter(SettingsFile);
7072
SettingsFile s = new SettingsFile();
7173
s.BhoCreatedVersion = CurrentVersion();
74+
s.LastUpdateCheckDate = DateTime.Now;
7275

7376
jsonDb.Write(JsonConvert.SerializeObject(s)); // Write blank json settings file
7477
jsonDb.Close();
@@ -224,6 +227,71 @@ public static string WildcardToRegex(string[] pattern)
224227
}
225228
return _out;
226229
}
230+
231+
private void CheckUpdate()
232+
{
233+
if (_prefs.Settings.LastUpdateCheckDate < DateTime.Now - TimeSpan.FromDays(3))
234+
{
235+
try
236+
{
237+
HttpWebRequest wc = (HttpWebRequest)WebRequest.Create(new Uri("https://servc.eu/p/scriptmonkey/version.php"));
238+
StringBuilder sb = new StringBuilder();
239+
byte[] buf = new byte[8192];
240+
Stream resStream = wc.GetResponse().GetResponseStream();
241+
242+
string tempString = null;
243+
int count = 0;
244+
do
245+
{
246+
count = resStream.Read(buf, 0, buf.Length);
247+
if (count != 0)
248+
{
249+
tempString = Encoding.ASCII.GetString(buf, 0, count);
250+
sb.Append(tempString);
251+
}
252+
}
253+
while (count > 0);
254+
255+
UpdateResponse response = JsonConvert.DeserializeObject<UpdateResponse>(sb.ToString());
256+
257+
if (response.Success && response.LatestVersion > CurrentVersion())
258+
{
259+
UpdateBHOFrm form = new UpdateBHOFrm();
260+
form.currentVersionTxt.Text = CurrentVersion().ToString();
261+
form.newVersionTxt.Text = response.LatestVersion.ToString();
262+
form.textBox1.Text = response.Changes;
263+
form.ShowDialog();
264+
265+
if (form.Response != UpdateBHOFrm.UpdateBHOFrmResponse.NextTime)
266+
{
267+
_prefs.Settings.LastUpdateCheckDate = DateTime.Now;
268+
_prefs.Save();
269+
_prefs.ReloadData();
270+
}
271+
if (form.Response == UpdateBHOFrm.UpdateBHOFrmResponse.Now)
272+
{
273+
new Process
274+
{
275+
StartInfo =
276+
{
277+
FileName = "iexplore.exe",
278+
Arguments = "https://servc.eu/p/scriptmonkey/update.html"
279+
}
280+
}.Start();
281+
282+
}
283+
}
284+
else
285+
{
286+
_prefs.Settings.LastUpdateCheckDate = DateTime.Now;
287+
_prefs.Save();
288+
_prefs.ReloadData();
289+
}
290+
}
291+
catch (Exception ex) { }
292+
}
293+
294+
}
227295
#endregion
228296

229297
[Guid("6D5140C1-7436-11CE-8034-00AA006009FA")]
@@ -241,7 +309,11 @@ int IObjectWithSite.SetSite(object site)
241309

242310
// Only need to check for install once per run.
243311
if (!_installChecked)
312+
{
244313
CheckInstall();
314+
CheckUpdate();
315+
}
316+
245317

246318
this._site = site;
247319

BHOUserScript/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.2.0.0")]
35-
[assembly: AssemblyFileVersion("1.2.0.0")]
34+
[assembly: AssemblyVersion("1.3.0.0")]
35+
[assembly: AssemblyFileVersion("1.3.0.0")]

BHOUserScript/SettingsFile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@ public class SettingsFile
1515
public List<Script> Scripts = new List<Script>();
1616

1717
public Version BhoCreatedVersion;
18+
19+
public DateTime LastUpdateCheckDate;
1820
}
1921
}

BHOUserScript/UpdateBHOFrm.Designer.cs

Lines changed: 177 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BHOUserScript/UpdateBHOFrm.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows.Forms;
10+
11+
namespace BHOUserScript
12+
{
13+
public partial class UpdateBHOFrm : Form
14+
{
15+
public enum UpdateBHOFrmResponse
16+
{
17+
Now,
18+
NextTime,
19+
In3Days
20+
}
21+
22+
public UpdateBHOFrmResponse Response = UpdateBHOFrmResponse.NextTime;
23+
24+
25+
public UpdateBHOFrm()
26+
{
27+
InitializeComponent();
28+
}
29+
30+
private void button1_Click(object sender, EventArgs e)
31+
{
32+
Response = UpdateBHOFrmResponse.Now;
33+
Close();
34+
}
35+
36+
private void button3_Click(object sender, EventArgs e)
37+
{
38+
Close();
39+
}
40+
41+
private void button2_Click(object sender, EventArgs e)
42+
{
43+
Response = UpdateBHOFrmResponse.In3Days;
44+
Close();
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)