-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
230 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
using System.Xml.Linq; | ||
|
||
namespace BlocklyAts { | ||
public class UpgradeInfo { | ||
|
||
public string Project; | ||
public Version LatestVersion; | ||
public string Changelog; | ||
public string WebUrl; | ||
|
||
public static async Task<UpgradeInfo> FetchOnline(string url, string name) { | ||
try { | ||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); | ||
request.AutomaticDecompression = DecompressionMethods.GZip; | ||
|
||
using (HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync()) | ||
using (Stream stream = response.GetResponseStream()) | ||
using (StreamReader reader = new StreamReader(stream)) { | ||
var xdoc = XDocument.Parse(reader.ReadToEnd()); | ||
foreach (var project in xdoc.Root.Elements("Project")) { | ||
if (project.Attribute("Name").Value == name) { | ||
return new UpgradeInfo() { | ||
Project = name, | ||
LatestVersion = new Version(project.Element("LatestVersion").Value), | ||
Changelog = project.Element("Changelog").Value.Replace("\\n", Environment.NewLine), | ||
WebUrl = project.Element("WebUrl").Value | ||
}; | ||
} | ||
} | ||
} | ||
|
||
return null; | ||
} catch { | ||
// Failing to get upgrade info is nothing serious. | ||
return null; | ||
} | ||
} | ||
|
||
public void ShowPromptAsRequired() { | ||
if (LatestVersion > Assembly.GetExecutingAssembly().GetName().Version) { | ||
if (MessageBox.Show( | ||
string.Format(I18n.Translate("Msg.UpgradeAvailable"), LatestVersion.ToString(), WebUrl, Changelog), | ||
"Upgrade Available", MessageBoxButtons.OKCancel, MessageBoxIcon.Information | ||
) == DialogResult.OK) { | ||
PlatformFunction.CallBrowser(WebUrl); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Windows.Forms; | ||
using OpenBveApi.Runtime; | ||
|
||
public class LU : List<U> { | ||
public override string ToString() { | ||
return "{" + string.Join(",", this.Select(t => t.ToString())) + "}"; | ||
} | ||
} | ||
|
||
public class U { | ||
private object e; | ||
public U(object d) { e = d; } | ||
|
||
public dynamic Cast(Type type) { | ||
if (e.GetType() == type) return e; | ||
if (type == typeof(bool)) { | ||
if (e is string) { | ||
return (e as string).ToLowerInvariant() == "true" || (e as string) == "1"; | ||
} else if (e is int || e is double) { | ||
return (int)e != 0; | ||
} else { | ||
throw new InvalidCastException(); | ||
} | ||
} else if (type == typeof(int)) { | ||
if (e is string) { | ||
int result; | ||
if (!int.TryParse(e as string, out result)) throw new InvalidCastException(); | ||
return result; | ||
} else if (e is int || e is double) { | ||
return (int)e; | ||
} else { | ||
throw new InvalidCastException(); | ||
} | ||
} else if (type == typeof(double)) { | ||
if (e is string) { | ||
double result; | ||
if (!double.TryParse(e as string, out result)) throw new InvalidCastException(); | ||
return result; | ||
} else if (e is int || e is double) { | ||
return (double)e; | ||
} else { | ||
throw new InvalidCastException(); | ||
} | ||
} else if (type == typeof(string)) { | ||
return e.ToString(); | ||
} else if (type == typeof(LU)) { | ||
throw new InvalidCastException(); | ||
} else { | ||
throw new InvalidCastException(); | ||
} | ||
} | ||
|
||
public static implicit operator U(bool d) => new U(d); | ||
public static implicit operator U(int d) => new U(d); | ||
public static implicit operator U(double d) => new U(d); | ||
public static implicit operator U(string d) => new U(d); | ||
public static implicit operator U(LU d) => new U(d); | ||
|
||
public static implicit operator bool(U d) => d.Cast(typeof(bool)); | ||
public static implicit operator int(U d) => d.Cast(typeof(int)); | ||
public static implicit operator double(U d) => d.Cast(typeof(double)); | ||
public static implicit operator string(U d) => d.Cast(typeof(string)); | ||
public static implicit operator LU(U d) => d.Cast(typeof(LU)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
local LIP={}function LIP.load(b)assert(type(b)=='string','Parameter \"fileName\" must be a string.')local c=assert(io.open(b,'r'),'Error loading file : '..b)local d={}local e;for f in c:lines()do local g=f:match('^%[([^%[%]]+)%]$')if g then e=tonumber(g)and tonumber(g)or g;d[e]=d[e]or{}end;local h,i=f:match('^([%w|_]+)%s-=%s-(.+)$')if h and i~=nil then if tonumber(i)then i=tonumber(i)elseif i=='true'then i=true elseif i=='false'then i=false end;if tonumber(h)then h=tonumber(h)end;d[e][h]=i end end;c:close()return d end;function LIP.save(b,d)assert(type(b)=='string','Parameter \"fileName\" must be a string.')assert(type(d)=='table','Parameter \"data\" must be a table.')local c=assert(io.open(b,'w+b'),'Error loading file :'..b)local j=''for e,h in pairs(d)do j=j..('[%s]\\n'):format(e)for k,i in pairs(h)do j=j..('%s=%s\\n'):format(k,tostring(i))end;j=j..'\\n'end;c:write(j)c:close()end | ||
|
||
__bve_keystate = {false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false} | ||
__bve_doorstate = false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.