mirror of
https://github.com/sochix/TLSharp.git
synced 2026-04-05 14:37:04 +00:00
Redesign Everything
This commit is contained in:
parent
b5472c6cd7
commit
6af7c66a81
710 changed files with 32932 additions and 302 deletions
6
TeleSharp.Generator/App.config
Normal file
6
TeleSharp.Generator/App.config
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
</startup>
|
||||
</configuration>
|
||||
39
TeleSharp.Generator/Constructor.tmp
Normal file
39
TeleSharp.Generator/Constructor.tmp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TeleSharp.TL;
|
||||
namespace /* NAMESPACE */
|
||||
{
|
||||
[TLObject(/*Constructor*/)]
|
||||
public class /* NAME */ : /* PARENT */
|
||||
{
|
||||
public override int Constructor
|
||||
{
|
||||
get
|
||||
{
|
||||
return /*Constructor*/;
|
||||
}
|
||||
}
|
||||
|
||||
/* PARAMS */
|
||||
|
||||
public void ComputeFlags()
|
||||
{
|
||||
/* COMPUTE */
|
||||
}
|
||||
|
||||
public override void DeserializeBody(BinaryReader br)
|
||||
{
|
||||
/* DESERIALIZE */
|
||||
}
|
||||
|
||||
public override void SerializeBody(BinaryWriter bw)
|
||||
{
|
||||
bw.Write(Constructor);
|
||||
/* SERIALIZE */
|
||||
}
|
||||
}
|
||||
}
|
||||
13
TeleSharp.Generator/ConstructorAbs.tmp
Normal file
13
TeleSharp.Generator/ConstructorAbs.tmp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TeleSharp.TL;
|
||||
namespace /* NAMESPACE */
|
||||
{
|
||||
public abstract class /* NAME */ : TLObject
|
||||
{
|
||||
}
|
||||
}
|
||||
43
TeleSharp.Generator/Method.tmp
Normal file
43
TeleSharp.Generator/Method.tmp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TeleSharp.TL;
|
||||
namespace /* NAMESPACE */
|
||||
{
|
||||
[TLObject(/*Constructor*/)]
|
||||
public class /* NAME */ : /* PARENT */
|
||||
{
|
||||
public override int Constructor
|
||||
{
|
||||
get
|
||||
{
|
||||
return /*Constructor*/;
|
||||
}
|
||||
}
|
||||
|
||||
/* PARAMS */
|
||||
|
||||
public void ComputeFlags()
|
||||
{
|
||||
/* COMPUTE */
|
||||
}
|
||||
|
||||
public override void DeserializeBody(BinaryReader br)
|
||||
{
|
||||
/* DESERIALIZE */
|
||||
}
|
||||
|
||||
public override void SerializeBody(BinaryWriter bw)
|
||||
{
|
||||
bw.Write(Constructor);
|
||||
/* SERIALIZE */
|
||||
}
|
||||
public override void deserializeResponse(BinaryReader br)
|
||||
{
|
||||
/* DESERIALIZEResp */
|
||||
}
|
||||
}
|
||||
}
|
||||
36
TeleSharp.Generator/Models.cs
Normal file
36
TeleSharp.Generator/Models.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Schema;
|
||||
namespace TeleSharp.Generator
|
||||
{
|
||||
class Method
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string method { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("params")]
|
||||
public List<Param> Params { get; set; }
|
||||
public string type { get; set; }
|
||||
|
||||
}
|
||||
class Param
|
||||
{
|
||||
public string name { get; set; }
|
||||
public string type { get; set; }
|
||||
}
|
||||
class Constructor
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string predicate { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("params")]
|
||||
public List<Param> Params { get; set; }
|
||||
public string type { get; set; }
|
||||
}
|
||||
class Schema
|
||||
{
|
||||
public List<Constructor> constructors { get; set; }
|
||||
public List<Method> methods { get; set; }
|
||||
}
|
||||
}
|
||||
433
TeleSharp.Generator/Program.cs
Normal file
433
TeleSharp.Generator/Program.cs
Normal file
|
|
@ -0,0 +1,433 @@
|
|||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.CodeDom;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace TeleSharp.Generator
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static List<String> keywords = new List<string>(new string[] { "abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class", "const", "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event", "explicit", "extern", "false", "finally", "fixed", "float", "for", "foreach", "goto", "if", "implicit", "in", "in", "int", "interface", "internal", "is", "lock", "long", "namespace", "new", "null", "object", "operator", "out", "out", "override", "params", "private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed", "short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "virtual", "void", "volatile", "while", "add", "alias", "ascending", "async", "await", "descending", "dynamic", "from", "get", "global", "group", "into", "join", "let", "orderby", "partial", "partial", "remove", "select", "set", "value", "var", "where", "where", "yield" });
|
||||
static List<String> interfacesList = new List<string>();
|
||||
static List<String> classesList = new List<string>();
|
||||
static void Main(string[] args)
|
||||
{
|
||||
|
||||
string AbsStyle = File.ReadAllText("ConstructorAbs.tmp");
|
||||
string NormalStyle = File.ReadAllText("Constructor.tmp");
|
||||
string MethodStyle = File.ReadAllText("Method.tmp");
|
||||
//string method = File.ReadAllText("constructor.tt");
|
||||
string Json = "";
|
||||
string url;
|
||||
if (args.Count() == 0) url = "tl-schema.json"; else url = args[0];
|
||||
|
||||
Json = File.ReadAllText(url);
|
||||
FileStream file = File.OpenWrite("Result.cs");
|
||||
StreamWriter sw = new StreamWriter(file);
|
||||
Schema schema = JsonConvert.DeserializeObject<Schema>(Json);
|
||||
foreach (var c in schema.constructors)
|
||||
{
|
||||
interfacesList.Add(c.type);
|
||||
classesList.Add(c.predicate);
|
||||
}
|
||||
foreach (var c in schema.constructors)
|
||||
{
|
||||
var list = schema.constructors.Where(x => x.type == c.type);
|
||||
if (list.Count() > 1)
|
||||
{
|
||||
string path = (GetNameSpace(c.type).Replace("TeleSharp.TL", "TL\\").Replace(".", "") + "\\" + GetNameofClass(c.type, true) + ".cs").Replace("\\\\", "\\");
|
||||
FileStream classFile = MakeFile(path);
|
||||
using (StreamWriter writer = new StreamWriter(classFile))
|
||||
{
|
||||
string nspace = (GetNameSpace(c.type).Replace("TeleSharp.TL", "TL\\").Replace(".", "")).Replace("\\\\", "\\").Replace("\\", ".");
|
||||
if (nspace.EndsWith("."))
|
||||
nspace = nspace.Remove(nspace.Length - 1, 1);
|
||||
string temp = AbsStyle.Replace("/* NAMESPACE */", "TeleSharp." + nspace);
|
||||
temp = temp.Replace("/* NAME */", GetNameofClass(c.type, true));
|
||||
writer.Write(temp);
|
||||
writer.Close();
|
||||
classFile.Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
interfacesList.Remove(list.First().type);
|
||||
list.First().type = "himself";
|
||||
}
|
||||
}
|
||||
foreach (var c in schema.constructors)
|
||||
{
|
||||
string path = (GetNameSpace(c.predicate).Replace("TeleSharp.TL", "TL\\").Replace(".", "") + "\\" + GetNameofClass(c.predicate, false) + ".cs").Replace("\\\\", "\\");
|
||||
FileStream classFile = MakeFile(path);
|
||||
using (StreamWriter writer = new StreamWriter(classFile))
|
||||
{
|
||||
#region About Class
|
||||
string nspace = (GetNameSpace(c.predicate).Replace("TeleSharp.TL", "TL\\").Replace(".", "")).Replace("\\\\", "\\").Replace("\\", ".");
|
||||
if (nspace.EndsWith("."))
|
||||
nspace = nspace.Remove(nspace.Length - 1, 1);
|
||||
string temp = NormalStyle.Replace("/* NAMESPACE */", "TeleSharp." + nspace);
|
||||
temp = (c.type == "himself") ? temp.Replace("/* PARENT */", "TLObject") : temp.Replace("/* PARENT */", GetNameofClass(c.type, true));
|
||||
temp = temp.Replace("/*Constructor*/", c.id.ToString());
|
||||
temp = temp.Replace("/* NAME */", GetNameofClass(c.predicate, false));
|
||||
#endregion
|
||||
#region Fields
|
||||
string fields = "";
|
||||
foreach (var tmp in c.Params)
|
||||
{
|
||||
fields += $" public {CheckForFlagBase(tmp.type, GetTypeName(tmp.type))} {CheckForKeyword(tmp.name)} " + "{get;set;}" + Environment.NewLine;
|
||||
}
|
||||
temp = temp.Replace("/* PARAMS */", fields);
|
||||
#endregion
|
||||
#region ComputeFlagFunc
|
||||
if (!c.Params.Any(x => x.name == "flags")) temp = temp.Replace("/* COMPUTE */", "");
|
||||
else
|
||||
{
|
||||
var compute = "flags = 0;" + Environment.NewLine;
|
||||
foreach (var param in c.Params.Where(x => IsFlagBase(x.type)))
|
||||
{
|
||||
if (IsTrueFlag(param.type))
|
||||
{
|
||||
compute += $"flags = {CheckForKeyword(param.name)} ? (flags | {GetBitMask(param.type)}) : (flags & ~{GetBitMask(param.type)});" + Environment.NewLine;
|
||||
}
|
||||
else
|
||||
{
|
||||
compute += $"flags = {CheckForKeyword(param.name)} != null ? (flags | {GetBitMask(param.type)}) : (flags & ~{GetBitMask(param.type)});" + Environment.NewLine;
|
||||
}
|
||||
}
|
||||
temp = temp.Replace("/* COMPUTE */", compute);
|
||||
}
|
||||
#endregion
|
||||
#region SerializeFunc
|
||||
var serialize = "";
|
||||
|
||||
if (c.Params.Any(x => x.name == "flags")) serialize += "ComputeFlags();" + Environment.NewLine + "bw.Write(flags);" + Environment.NewLine;
|
||||
foreach (var p in c.Params.Where(x => x.name != "flags"))
|
||||
{
|
||||
serialize += WriteWriteCode(p) + Environment.NewLine;
|
||||
}
|
||||
temp = temp.Replace("/* SERIALIZE */", serialize);
|
||||
#endregion
|
||||
#region DeSerializeFunc
|
||||
var deserialize = "";
|
||||
|
||||
foreach (var p in c.Params)
|
||||
{
|
||||
deserialize += WriteReadCode(p) + Environment.NewLine;
|
||||
}
|
||||
temp = temp.Replace("/* DESERIALIZE */", deserialize);
|
||||
#endregion
|
||||
writer.Write(temp);
|
||||
writer.Close();
|
||||
classFile.Close();
|
||||
}
|
||||
}
|
||||
foreach (var c in schema.methods)
|
||||
{
|
||||
if (c.method.Contains("updateUsername"))
|
||||
{
|
||||
|
||||
}
|
||||
string path = (GetNameSpace(c.method).Replace("TeleSharp.TL", "TL\\").Replace(".", "") + "\\" + GetNameofClass(c.method, false,true) + ".cs").Replace("\\\\", "\\");
|
||||
FileStream classFile = MakeFile(path);
|
||||
using (StreamWriter writer = new StreamWriter(classFile))
|
||||
{
|
||||
#region About Class
|
||||
string nspace = (GetNameSpace(c.method).Replace("TeleSharp.TL", "TL\\").Replace(".", "")).Replace("\\\\", "\\").Replace("\\", ".");
|
||||
if (nspace.EndsWith("."))
|
||||
nspace = nspace.Remove(nspace.Length - 1, 1);
|
||||
string temp = MethodStyle.Replace("/* NAMESPACE */", "TeleSharp." + nspace);
|
||||
temp = temp.Replace("/* PARENT */", "TLMethod");
|
||||
temp = temp.Replace("/*Constructor*/", c.id.ToString());
|
||||
temp = temp.Replace("/* NAME */", GetNameofClass(c.method, false,true));
|
||||
#endregion
|
||||
#region Fields
|
||||
string fields = "";
|
||||
foreach (var tmp in c.Params)
|
||||
{
|
||||
fields += $" public {CheckForFlagBase(tmp.type, GetTypeName(tmp.type))} {CheckForKeyword(tmp.name)} " + "{get;set;}" + Environment.NewLine;
|
||||
}
|
||||
fields += $" public {CheckForFlagBase(c.type, GetTypeName(c.type))} Response" + "{ get; set;}" + Environment.NewLine;
|
||||
temp = temp.Replace("/* PARAMS */", fields);
|
||||
#endregion
|
||||
#region ComputeFlagFunc
|
||||
if (!c.Params.Any(x => x.name == "flags")) temp = temp.Replace("/* COMPUTE */", "");
|
||||
else
|
||||
{
|
||||
var compute = "flags = 0;" + Environment.NewLine;
|
||||
foreach (var param in c.Params.Where(x => IsFlagBase(x.type)))
|
||||
{
|
||||
if (IsTrueFlag(param.type))
|
||||
{
|
||||
compute += $"flags = {CheckForKeyword(param.name)} ? (flags | {GetBitMask(param.type)}) : (flags & ~{GetBitMask(param.type)});" + Environment.NewLine;
|
||||
}
|
||||
else
|
||||
{
|
||||
compute += $"flags = {CheckForKeyword(param.name)} != null ? (flags | {GetBitMask(param.type)}) : (flags & ~{GetBitMask(param.type)});" + Environment.NewLine;
|
||||
}
|
||||
}
|
||||
temp = temp.Replace("/* COMPUTE */", compute);
|
||||
}
|
||||
#endregion
|
||||
#region SerializeFunc
|
||||
var serialize = "";
|
||||
|
||||
if (c.Params.Any(x => x.name == "flags")) serialize += "ComputeFlags();" + Environment.NewLine + "bw.Write(flags);" + Environment.NewLine;
|
||||
foreach (var p in c.Params.Where(x => x.name != "flags"))
|
||||
{
|
||||
serialize += WriteWriteCode(p) + Environment.NewLine;
|
||||
}
|
||||
temp = temp.Replace("/* SERIALIZE */", serialize);
|
||||
#endregion
|
||||
#region DeSerializeFunc
|
||||
var deserialize = "";
|
||||
|
||||
foreach (var p in c.Params)
|
||||
{
|
||||
deserialize += WriteReadCode(p) + Environment.NewLine;
|
||||
}
|
||||
temp = temp.Replace("/* DESERIALIZE */", deserialize);
|
||||
#endregion
|
||||
#region DeSerializeRespFunc
|
||||
var deserializeResp = "";
|
||||
Param p2 = new Param() { name = "Response", type = c.type };
|
||||
deserializeResp += WriteReadCode(p2) + Environment.NewLine;
|
||||
temp = temp.Replace("/* DESERIALIZEResp */", deserializeResp);
|
||||
#endregion
|
||||
writer.Write(temp);
|
||||
writer.Close();
|
||||
classFile.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static string FormatName(string input)
|
||||
{
|
||||
if (String.IsNullOrEmpty(input))
|
||||
throw new ArgumentException("ARGH!");
|
||||
if (input.IndexOf('.') != -1)
|
||||
{
|
||||
input = input.Replace(".", " ");
|
||||
var temp = "";
|
||||
foreach (var s in input.Split(' '))
|
||||
{
|
||||
temp += FormatName(s) + " ";
|
||||
}
|
||||
input = temp.Trim();
|
||||
}
|
||||
return input.First().ToString().ToUpper() + input.Substring(1);
|
||||
}
|
||||
public static string CheckForKeyword(string name)
|
||||
{
|
||||
if (keywords.Contains(name)) return "@" + name;
|
||||
return name;
|
||||
}
|
||||
public static string GetNameofClass(string type, bool isinterface = false, bool ismethod = false)
|
||||
{
|
||||
if (!ismethod)
|
||||
{
|
||||
if (type.IndexOf('.') != -1 && type.IndexOf('?') == -1)
|
||||
return isinterface ? "TLAbs" + FormatName(type.Split('.')[1]) : "TL" + FormatName(type.Split('.')[1]);
|
||||
else if (type.IndexOf('.') != -1 && type.IndexOf('?') != -1)
|
||||
return isinterface ? "TLAbs" + FormatName(type.Split('?')[1]) : "TL" + FormatName(type.Split('?')[1]);
|
||||
else
|
||||
return isinterface ? "TLAbs" + FormatName(type) : "TL" + FormatName(type);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (type.IndexOf('.') != -1 && type.IndexOf('?') == -1)
|
||||
return "TLRequest" + FormatName(type.Split('.')[1]);
|
||||
else if (type.IndexOf('.') != -1 && type.IndexOf('?') != -1)
|
||||
return "TLRequest" + FormatName(type.Split('?')[1]);
|
||||
else
|
||||
return "TLRequest" + FormatName(type) ;
|
||||
}
|
||||
}
|
||||
private static bool IsFlagBase(string type)
|
||||
{
|
||||
return type.IndexOf("?") != -1;
|
||||
}
|
||||
private static int GetBitMask(string type)
|
||||
{
|
||||
return (int)Math.Pow((double)2, (double)int.Parse(type.Split('?')[0].Split('.')[1]));
|
||||
}
|
||||
private static bool IsTrueFlag(string type)
|
||||
{
|
||||
return type.Split('?')[1] == "true";
|
||||
}
|
||||
public static string GetNameSpace(string type)
|
||||
{
|
||||
if (type.IndexOf('.') != -1)
|
||||
return "TeleSharp.TL" + FormatName(type.Split('.')[0]);
|
||||
else
|
||||
return "TeleSharp.TL";
|
||||
}
|
||||
public static string CheckForFlagBase(string type, string result)
|
||||
{
|
||||
if (type.IndexOf('?') == -1)
|
||||
return result;
|
||||
else
|
||||
{
|
||||
string innerType = type.Split('?')[1];
|
||||
if (innerType == "true") return result;
|
||||
else if ((new string[] {"bool","int", "uint", "long", "double" }).Contains(result)) return result + "?";
|
||||
else return result;
|
||||
}
|
||||
}
|
||||
public static string GetTypeName(string type)
|
||||
{
|
||||
if (type.ToLower().Contains("inputcontact")) return "TLInputPhoneContact";
|
||||
switch (type.ToLower())
|
||||
{
|
||||
case "#":
|
||||
case "int":
|
||||
return "int";
|
||||
case "uint":
|
||||
return "uint";
|
||||
case "long":
|
||||
return "long";
|
||||
case "double":
|
||||
return "double";
|
||||
case "string":
|
||||
return "string";
|
||||
case "bytes":
|
||||
return "byte[]";
|
||||
case "true":
|
||||
case "bool":
|
||||
return "bool";
|
||||
case "!x":
|
||||
return "TLObject";
|
||||
case "x":
|
||||
return "TLObject";
|
||||
}
|
||||
if (type.StartsWith("Vector"))
|
||||
return "TLVector<" + GetTypeName(type.Replace("Vector<", "").Replace(">", "")) + ">";
|
||||
else
|
||||
{
|
||||
if (type.IndexOf('.') != -1 && type.IndexOf('?') == -1)
|
||||
{
|
||||
|
||||
if (interfacesList.Any(x => x.ToLower() == (type).ToLower()))
|
||||
return FormatName(type.Split('.')[0]) + "." + "TLAbs" + type.Split('.')[1];
|
||||
else if (classesList.Any(x => x.ToLower() == (type).ToLower()))
|
||||
return FormatName(type.Split('.')[0]) + "." + "TL" + type.Split('.')[1];
|
||||
else
|
||||
return FormatName(type.Split('.')[1]);
|
||||
}
|
||||
else if (type.IndexOf('?') == -1)
|
||||
{
|
||||
if (interfacesList.Any(x => x.ToLower() == type.ToLower()))
|
||||
return "TLAbs" + type;
|
||||
else if (classesList.Any(x => x.ToLower() == type.ToLower()))
|
||||
return "TL" + type;
|
||||
else
|
||||
return type;
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetTypeName(type.Split('?')[1]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public static string LookTypeInLists(string src)
|
||||
{
|
||||
if (interfacesList.Any(x => x.ToLower() == src.ToLower()))
|
||||
return "TLAbs" + FormatName(src);
|
||||
else if (classesList.Any(x => x.ToLower() == src.ToLower()))
|
||||
return "TL" + FormatName(src);
|
||||
else
|
||||
return src;
|
||||
}
|
||||
public static string WriteWriteCode(Param p, bool flag = false)
|
||||
{
|
||||
switch (p.type.ToLower())
|
||||
{
|
||||
case "#":
|
||||
case "int":
|
||||
return flag ? $"bw.Write({CheckForKeyword(p.name)}.Value);" : $"bw.Write({CheckForKeyword(p.name)});";
|
||||
case "long":
|
||||
return flag ? $"bw.Write({CheckForKeyword(p.name)}.Value);" : $"bw.Write({CheckForKeyword(p.name)});";
|
||||
case "string":
|
||||
return $"StringUtil.Serialize({CheckForKeyword(p.name)},bw);";
|
||||
case "bool":
|
||||
return flag ? $"BoolUtil.Serialize({CheckForKeyword(p.name)}.Value,bw);" : $"BoolUtil.Serialize({CheckForKeyword(p.name)},bw);";
|
||||
case "true":
|
||||
return $"BoolUtil.Serialize({CheckForKeyword(p.name)},bw);";
|
||||
case "bytes":
|
||||
return $"BytesUtil.Serialize({CheckForKeyword(p.name)},bw);";
|
||||
case "double":
|
||||
return flag ? $"bw.Write({CheckForKeyword(p.name)}.Value);" : $"bw.Write({CheckForKeyword(p.name)});";
|
||||
default:
|
||||
if (!IsFlagBase(p.type))
|
||||
return $"ObjectUtils.SerializeObject({CheckForKeyword(p.name)},bw);";
|
||||
else
|
||||
{
|
||||
if (IsTrueFlag(p.type))
|
||||
return $"";
|
||||
else
|
||||
{
|
||||
Param p2 = new Param() { name = p.name, type = p.type.Split('?')[1] };
|
||||
return $"if ((flags & {GetBitMask(p.type).ToString()}) != 0)" + Environment.NewLine +
|
||||
WriteWriteCode(p2, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static string WriteReadCode(Param p)
|
||||
{
|
||||
switch (p.type.ToLower())
|
||||
{
|
||||
case "#":
|
||||
case "int":
|
||||
return $"{CheckForKeyword(p.name)} = br.ReadInt32();";
|
||||
case "long":
|
||||
return $"{CheckForKeyword(p.name)} = br.ReadInt64();";
|
||||
case "string":
|
||||
return $"{CheckForKeyword(p.name)} = StringUtil.Deserialize(br);";
|
||||
case "bool":
|
||||
case "true":
|
||||
return $"{CheckForKeyword(p.name)} = BoolUtil.Deserialize(br);";
|
||||
case "bytes":
|
||||
return $"{CheckForKeyword(p.name)} = BytesUtil.Deserialize(br);";
|
||||
case "double":
|
||||
return $"{CheckForKeyword(p.name)} = br.ReadDouble();";
|
||||
default:
|
||||
if (!IsFlagBase(p.type))
|
||||
{
|
||||
if (p.type.ToLower().Contains("vector"))
|
||||
{
|
||||
return $"{CheckForKeyword(p.name)} = ({GetTypeName(p.type)})ObjectUtils.DeserializeVector<{GetTypeName(p.type).Replace("TLVector<","").Replace(">","")}>(br);";
|
||||
}
|
||||
else return $"{CheckForKeyword(p.name)} = ({GetTypeName(p.type)})ObjectUtils.DeserializeObject(br);";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsTrueFlag(p.type))
|
||||
return $"{CheckForKeyword(p.name)} = (flags & {GetBitMask(p.type).ToString()}) != 0;";
|
||||
else
|
||||
{
|
||||
Param p2 = new Param() { name = p.name, type = p.type.Split('?')[1] };
|
||||
return $"if ((flags & {GetBitMask(p.type).ToString()}) != 0)" + Environment.NewLine +
|
||||
WriteReadCode(p2) + Environment.NewLine +
|
||||
"else" + Environment.NewLine +
|
||||
$"{CheckForKeyword(p.name)} = null;" + Environment.NewLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static FileStream MakeFile(string path)
|
||||
{
|
||||
if (!Directory.Exists(Path.GetDirectoryName(path)))
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
if (File.Exists(path))
|
||||
File.Delete(path);
|
||||
return File.OpenWrite(path);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
36
TeleSharp.Generator/Properties/AssemblyInfo.cs
Normal file
36
TeleSharp.Generator/Properties/AssemblyInfo.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("TeleSharp.Generator")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("TeleSharp.Generator")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("9be3b9d4-9ff6-4dc8-b9cc-eb2e3f390129")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
80
TeleSharp.Generator/TeleSharp.Generator.csproj
Normal file
80
TeleSharp.Generator/TeleSharp.Generator.csproj
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{9BE3B9D4-9FF6-4DC8-B9CC-EB2E3F390129}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>TeleSharp.Generator</RootNamespace>
|
||||
<AssemblyName>TeleSharp.Generator</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Models.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<Content Include="Method.tmp">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Constructor.tmp">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="ConstructorAbs.tmp">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
4
TeleSharp.Generator/packages.config
Normal file
4
TeleSharp.Generator/packages.config
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
|
||||
</packages>
|
||||
Loading…
Add table
Add a link
Reference in a new issue