Generator: default to a schema filename in line to online resource

The schema is in https://core.telegram.org/schema/json so it's more
logical to expect the file to be named `json`, which is what would
happen if you download it with wget, for example.
This commit is contained in:
Andres G. Aragoneses 2020-04-12 17:58:12 +08:00
parent 9a6e391cae
commit bca8bc5631

View file

@ -20,10 +20,21 @@ namespace TeleSharp.Generator
string MethodStyle = File.ReadAllText("Method.tmp"); string MethodStyle = File.ReadAllText("Method.tmp");
//string method = File.ReadAllText("constructor.tt"); //string method = File.ReadAllText("constructor.tt");
string Json = ""; string Json = "";
string url;
if (args.Count() == 0) url = "tl-schema.json"; else url = args[0];
string url;
if (!args.Any())
url = "json";
else
url = args[0];
try
{
Json = File.ReadAllText(url); Json = File.ReadAllText(url);
}
catch (FileNotFoundException ex)
{
throw new Exception ("Couldn't find schema JSON file, did you download it first e.g. with `wget https://core.telegram.org/schema/json`?", ex);
}
FileStream file = File.OpenWrite("Result.cs"); FileStream file = File.OpenWrite("Result.cs");
StreamWriter sw = new StreamWriter(file); StreamWriter sw = new StreamWriter(file);
TlSchema schema = JsonConvert.DeserializeObject<TlSchema>(Json); TlSchema schema = JsonConvert.DeserializeObject<TlSchema>(Json);