private void button2_Click(object sender, EventArgs e)
{
textBox2.Text = "";//用于输出日志分析结果
for (int i = 1; i < 7; i++) //开心网小号分为6个小组,开6个外挂同时运行,所以循环6次
{
string[] fileNames = Directory.GetFiles("D://color//VStart50//Tools//Chat//YoYoFarmer//YoyoFarmer" + i.ToString() + "//Log");//获取每个外挂的log文件夹地址
string NewFile = "";
foreach (string file in fileNames)
{
NewFile = file;
}
house(NewFile);
}
}
private void house(string url)//通过传递log文件夹地址逐一分析
{
if (url.Length > 0)
{
StreamReader sr = new StreamReader(url);
string str = sr.ReadToEnd();//.Replace("[","]");
//textBox2.Text = str;
str = str.Replace("操作完毕!", "|");
string[] arr = str.Split('|');
Int32 i1 = arr.Length;
AccessHelper AH = new AccessHelper();//由于我用的是access数据库,所以建了个数据库操作类
string sql = "";
for (Int32 i = 0; i < arr.Length; i++)
{
string a = arr[i];
string a1 = StrCut(a, "正在读取帐号 ", " 的配置信息", 0);
string a2 = StrCut(a, "技能:", "级 /n", 0);
string a3 = StrCut(a, "再务农", "天可升级", 0);
string a4 = StrCut(a, ",魅力 ", ",我的现金余额", 0);
string a5 = StrCut(a, "我的现金余额", "!/r/n", 0);
if (string.IsNullOrEmpty(a2)) a2 = "0";
if (string.IsNullOrEmpty(a3)) a3 = "0";
if (string.IsNullOrEmpty(a4)) a4 = "0";
if (string.IsNullOrEmpty(a5)) a5 = "0";
if (a1.Length > 0)
{
sql = "update G_KaiXin_B set 技能=" + a2 + ",升级=" + a3 + ",魅力=" + a4 + ",现金=" + a5 + " where email='" + a1 + "'";
bool bln = AH.ExeSQL(sql);
textBox2.Text += (i + 1).ToString() + " 邮箱:" + a1 + " 技能:" + a2 + " 升级:" + a3 + "天" + " 魅力:" + a4 + "现金:" + a5 + "/r/n";
}
}
}
}
用到的函数:
/// <summary>
/// 截取字符串特定字符之间的字符串
/// </summary>
/// <param name="str">要截取的字符串 如abcdefg</param>
/// <param name="str1">开始截取的字符串,如b</param>
/// <param name="str2">结束截取的字符串 如f</param>
/// <param name="type">去除类型 0只取中间 1 包含开始的 2 包含结束的 else 包含开始和结束的</param>
/// <returns>得到截取后的字符串,如cde</returns>
static string StrCut(string str, string str1, string str2, int type)
{
string temp = "";
int ad1 = str.IndexOf(str1, 0);
if (ad1 == -1)
{
temp = "";
}
else
{
int ad2 = str.IndexOf(str2, ad1 + str1.Length);
int ad3 = ad2 - ad1;
string t = str.Substring(ad1, ad3);
t = t.Replace(str1, "");
temp = t.ToString();
switch (type)
{
case 0://只取中间的
break;
case 1: //包含开始的
temp = str1 + temp;
break;
case 2://包含结束的
temp = temp + str2;
break;
case 3://包含开始和结束的
temp = str1 + temp + str2;
break;
}
}
return temp;
}