-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha.cs
100 lines (92 loc) · 4.12 KB
/
a.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Text.RegularExpressions;
using System.IO;
using System.Net;
namespace url_generator
{
class Program
{
static void Main(string[] args)
{
bool debug = true;
int line_number;
string crash_line, true_url_without_line_number, true_url_with_line_number,lua_path = "";
string base_url = "https://github.com/steam-test1/Payday-2-LuaJit-Source-With-Line-Numbers-Continued/blob/master/";
crash_line = Console.ReadLine();
if (debug) Console.WriteLine("debug:crash_line=" + crash_line);
if (crash_line.Length == 0) return;
//rule out mod path
if (crash_line.Contains("@mods/") || crash_line.Contains("mods/"))
{
Console.WriteLine("no valid url for mods.");
Console.ReadLine();
return;
}
//make the url
if (crash_line.IndexOf("core/") != -1)lua_path = func(crash_line, crash_line.IndexOf("core/"));
else
{
if (crash_line.IndexOf("lib/") != -1) lua_path = func(crash_line, crash_line.IndexOf("lib/"));
else
{
Console.WriteLine("no vaild path at this line!");
Console.ReadLine();
return;
}
}
if (debug) Console.WriteLine("debug:lua_path=" + lua_path);
true_url_without_line_number = String.Concat(base_url, lua_path);
if (debug) Console.WriteLine("debug:true_url_without_line_number=" + true_url_without_line_number);
Console.WriteLine(true_url_without_line_number);
//get the line number
line_number= int.Parse(Regex.Replace(crash_line, @"[^0-9]+", ""));
if(debug) Console.WriteLine("debug:line_number=" + line_number);
//get http info
HttpWebRequest hwrqe = (HttpWebRequest)WebRequest.Create(true_url_without_line_number);
hwrqe.KeepAlive = false;
hwrqe.Timeout = 20000;//ms
hwrqe.Method = "get";
hwrqe.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
HttpWebResponse hwrs = (HttpWebResponse)hwrqe.GetResponse();
if (hwrs.StatusCode != HttpStatusCode.OK)
{
return;
}
if (debug) Console.WriteLine("a");
using (StreamReader sr = new StreamReader(hwrs.GetResponseStream()))
{
while(sr.Peek()>=0)
{
string line = sr.ReadLine();
if (debug) Console.WriteLine(line);
int a = line.IndexOf("--</span> Lines ");
if (a!=-1)
{
if (debug) Console.WriteLine("debug:line=" + line);
string temp = line.Substring(a + 16);
temp = temp.Remove(temp.IndexOf("<"));
int min, max;
if (debug) Console.WriteLine(temp.Substring(0, temp.IndexOf("-") - 1));
min = int.Parse(temp.Substring(0, temp.IndexOf("-")-1));
max = int.Parse(temp.Substring(temp.IndexOf("-")+1));
if (debug) Console.WriteLine("debug:max=" + max+",min="+min);
if (line_number >= min && line_number<= max)
{
temp = line.Remove(line.IndexOf("class"));
true_url_with_line_number = String.Concat(true_url_without_line_number, "#L", Regex.Replace(temp, @"[^0-9]+", ""));
Console.WriteLine(true_url_with_line_number);
}
}
}
}
Console.ReadLine();
}
static string func(string crash_line, int index)
{
string a;
crash_line = crash_line.Substring(index);
a= crash_line.Remove(crash_line.IndexOf(".lua") + 4);
return a;
}
}
}