mirror of
https://github.com/huiyadanli/RevokeMsgPatcher.git
synced 2025-05-24 06:26:06 +08:00
[+] Google Analytics
This commit is contained in:
parent
b6281f89a9
commit
bb9a82a657
|
@ -22,7 +22,9 @@ namespace RevokeMsgPatcher
|
|||
|
||||
private string thisVersion;
|
||||
private bool needUpdate = false;
|
||||
|
||||
|
||||
private GAHelper ga = new GAHelper(); // Google Analytics 记录
|
||||
|
||||
public void InitModifier()
|
||||
{
|
||||
// 从配置文件中读取配置
|
||||
|
@ -59,6 +61,7 @@ namespace RevokeMsgPatcher
|
|||
InitModifier();
|
||||
InitControls();
|
||||
|
||||
ga.RequestPageView("/main", "进入主界面");
|
||||
}
|
||||
|
||||
private void InitControls()
|
||||
|
@ -81,6 +84,10 @@ namespace RevokeMsgPatcher
|
|||
MessageBox.Show("请选择正确的安装路径!");
|
||||
return;
|
||||
}
|
||||
|
||||
// 记录点了什么应用的防撤回
|
||||
ga.RequestPageView(GetCheckedRadioButtonNameEn() + "/patch", "点击防撤回");
|
||||
|
||||
EnableAllButton(false);
|
||||
// a.重新初始化编辑器
|
||||
modifier.InitEditors(txtPath.Text);
|
||||
|
@ -91,6 +98,7 @@ namespace RevokeMsgPatcher
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ga.RequestPageView(GetCheckedRadioButtonNameEn() + "/patch/sha1/ex", ex.Message);
|
||||
MessageBox.Show(ex.Message);
|
||||
EnableAllButton(true);
|
||||
btnRestore.Enabled = modifier.BackupExists();
|
||||
|
@ -100,6 +108,7 @@ namespace RevokeMsgPatcher
|
|||
try
|
||||
{
|
||||
modifier.Patch();
|
||||
ga.RequestPageView(GetCheckedRadioButtonNameEn() + "/patch/succ", "防撤回成功");
|
||||
MessageBox.Show("补丁安装成功!");
|
||||
EnableAllButton(true);
|
||||
btnRestore.Enabled = modifier.BackupExists();
|
||||
|
@ -107,10 +116,12 @@ namespace RevokeMsgPatcher
|
|||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
ga.RequestPageView(GetCheckedRadioButtonNameEn() + "/patch/ex", ex.Message);
|
||||
MessageBox.Show(ex.Message + " 请以管理员权限启动本程序,并确认微信处于关闭状态。");
|
||||
EnableAllButton(true);
|
||||
btnRestore.Enabled = modifier.BackupExists();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void txtPath_TextChanged(object sender, EventArgs e)
|
||||
|
@ -169,30 +180,7 @@ namespace RevokeMsgPatcher
|
|||
private async void FormMain_Load(object sender, EventArgs e)
|
||||
{
|
||||
// 异步获取最新的补丁信息
|
||||
Task<string> t = new Task<string>(() =>
|
||||
{
|
||||
string downStr = null;
|
||||
WebClient wc = new WebClient();
|
||||
try
|
||||
{
|
||||
downStr = wc.DownloadString("https://huiyadanli.coding.me/i/revokemsg/05.json");
|
||||
}
|
||||
catch (Exception ex1)
|
||||
{
|
||||
Console.WriteLine(ex1.Message);
|
||||
try
|
||||
{
|
||||
downStr = wc.DownloadString("https://www.huiyadan.com/i/revokemsg/05.json");
|
||||
}
|
||||
catch (Exception ex2)
|
||||
{
|
||||
Console.WriteLine(ex2.Message);
|
||||
}
|
||||
}
|
||||
return downStr;
|
||||
});
|
||||
t.Start();
|
||||
string json = await t;
|
||||
string json = await GetPathJsonAsync();
|
||||
if (string.IsNullOrEmpty(json))
|
||||
{
|
||||
lblUpdatePachJson.Text = "[ 获取失败 ]";
|
||||
|
@ -228,14 +216,36 @@ namespace RevokeMsgPatcher
|
|||
}
|
||||
}
|
||||
|
||||
private async Task<string> GetPathJsonAsync()
|
||||
{
|
||||
string downStr = null;
|
||||
try
|
||||
{
|
||||
downStr = await HttpUtil.Client.GetStringAsync("https://huiyadanli.coding.me/i/revokemsg/05.json");
|
||||
}
|
||||
catch (Exception ex1)
|
||||
{
|
||||
Console.WriteLine(ex1.Message);
|
||||
try
|
||||
{
|
||||
downStr = await HttpUtil.Client.GetStringAsync("https://www.huiyadan.com/i/revokemsg/05.json");
|
||||
}
|
||||
catch (Exception ex2)
|
||||
{
|
||||
Console.WriteLine(ex2.Message);
|
||||
}
|
||||
}
|
||||
return downStr;
|
||||
}
|
||||
|
||||
private void lblUpdatePachJson_Click(object sender, EventArgs e)
|
||||
{
|
||||
string tips = "";
|
||||
if(needUpdate)
|
||||
if (needUpdate)
|
||||
{
|
||||
tips += "【当前存在最新版本,点击确定进入软件主页下载最新版本。】" + Environment.NewLine + Environment.NewLine;
|
||||
}
|
||||
tips += "支持以下版本" +Environment.NewLine;
|
||||
tips += "支持以下版本" + Environment.NewLine;
|
||||
tips += " ➯ 微信:" + wechatModifier.Config.GetSupportVersionStr() + Environment.NewLine;
|
||||
tips += " ➯ QQ:" + qqModifier.Config.GetSupportVersionStr() + Environment.NewLine;
|
||||
tips += " ➯ TIM:" + timModifier.Config.GetSupportVersionStr() + Environment.NewLine;
|
||||
|
@ -249,6 +259,7 @@ namespace RevokeMsgPatcher
|
|||
|
||||
private void radioButtons_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
ga.RequestPageView(GetCheckedRadioButtonNameEn() + "_switch");
|
||||
EnableAllButton(false);
|
||||
RadioButton radioButton = sender as RadioButton;
|
||||
// 切换使用不同的防撤回对象
|
||||
|
@ -275,6 +286,23 @@ namespace RevokeMsgPatcher
|
|||
}
|
||||
}
|
||||
|
||||
private string GetCheckedRadioButtonNameEn()
|
||||
{
|
||||
if (rbtWechat.Checked)
|
||||
{
|
||||
return "wechat";
|
||||
}
|
||||
else if (rbtQQ.Checked)
|
||||
{
|
||||
return "qq";
|
||||
}
|
||||
else if (rbtTIM.Checked)
|
||||
{
|
||||
return "tim";
|
||||
}
|
||||
return "none";
|
||||
}
|
||||
|
||||
private void EnableAllButton(bool state)
|
||||
{
|
||||
foreach (Control c in this.Controls)
|
||||
|
|
|
@ -66,6 +66,8 @@
|
|||
<Compile Include="Modifier\TIMModifier.cs" />
|
||||
<Compile Include="Modifier\WechatModifier.cs" />
|
||||
<Compile Include="Utils\FileUtil.cs" />
|
||||
<Compile Include="Utils\GAHelper.cs" />
|
||||
<Compile Include="Utils\HttpUtil.cs" />
|
||||
<Compile Include="Utils\PathUtil.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
|
67
RevokeMsgPatcher/Utils/GAHelper.cs
Normal file
67
RevokeMsgPatcher/Utils/GAHelper.cs
Normal file
|
@ -0,0 +1,67 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace RevokeMsgPatcher.Utils
|
||||
{
|
||||
/// <summary>
|
||||
/// 用于软件的 Google Analytics 实现 By huiyadanli
|
||||
/// 相关文档:
|
||||
/// 指南 https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide
|
||||
/// 参数 https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
|
||||
/// 测试 https://ga-dev-tools.appspot.com/hit-builder/
|
||||
/// </summary>
|
||||
public class GAHelper
|
||||
{
|
||||
// 根据实际情况修改
|
||||
private static readonly HttpClient client = HttpUtil.Client;
|
||||
|
||||
private const string GAUrl = "https://www.google-analytics.com/collect";
|
||||
|
||||
// 根据实际使用分析账号设置
|
||||
private const string tid = "UA-80358493-2"; // GA Tracking ID / Property ID.
|
||||
|
||||
private static readonly string cid = Guid.NewGuid().ToString(); // Anonymous Client ID.
|
||||
|
||||
// 屏幕分辨率(可选)
|
||||
private static readonly string sr = Screen.PrimaryScreen.Bounds.Width + "x" + Screen.PrimaryScreen.Bounds.Height;
|
||||
|
||||
public string UserAgent { get; set; }
|
||||
|
||||
public GAHelper()
|
||||
{
|
||||
UserAgent = string.Format("Hui Google Analytics Tracker/1.0 ({0}; {1}; {2})", Environment.OSVersion.Platform.ToString(), Environment.OSVersion.Version.ToString(), Environment.OSVersion.VersionString);
|
||||
}
|
||||
|
||||
public async Task RequestPageViewAsync(string page, string title = null)
|
||||
{
|
||||
if (!page.StartsWith("/"))
|
||||
{
|
||||
page = "/" + page;
|
||||
}
|
||||
// 请求参数
|
||||
var values = new Dictionary<string, string>
|
||||
{
|
||||
{ "v", "1" }, // 当前必填1
|
||||
{ "tid", tid },
|
||||
{ "cid", cid },
|
||||
{ "ua", UserAgent },
|
||||
{ "t", "pageview" },
|
||||
{ "sr", sr },
|
||||
{ "dp", page },
|
||||
{ "dt", title },
|
||||
};
|
||||
var content = new FormUrlEncodedContent(values);
|
||||
var response = await client.PostAsync(GAUrl, content);
|
||||
}
|
||||
|
||||
public void RequestPageView(string page, string title = null)
|
||||
{
|
||||
Task.Run(() => RequestPageViewAsync(page, title));
|
||||
}
|
||||
}
|
||||
}
|
14
RevokeMsgPatcher/Utils/HttpUtil.cs
Normal file
14
RevokeMsgPatcher/Utils/HttpUtil.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RevokeMsgPatcher.Utils
|
||||
{
|
||||
public class HttpUtil
|
||||
{
|
||||
public static HttpClient Client { get; } = new HttpClient();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user