[+] 重新布局界面,完成控件与方法的绑定

This commit is contained in:
huiyadanli
2019-10-05 12:26:39 +08:00
parent 6f397033fd
commit edc06cf769
14 changed files with 594 additions and 379 deletions

View File

@@ -1,6 +1,8 @@
using RevokeMsgPatcher.Modifier;
using RevokeMsgPatcher.Model;
using RevokeMsgPatcher.Modifier;
using RevokeMsgPatcher.Utils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Threading.Tasks;
@@ -10,7 +12,24 @@ namespace RevokeMsgPatcher
{
public partial class FormMain : Form
{
WechatModifier wechatModifier = new WechatModifier();
AppModifier modifier = null;
public void InitModifier()
{
Bag bag = new JsonData().Bag();
WechatModifier wechatModifier = new WechatModifier(bag.Apps["Wechat"]);
QQModifier qqModifier = new QQModifier(bag.Apps["QQ"]);
TIMModifier timModifier = new TIMModifier(bag.Apps["TIM"]);
rbtWechat.Tag = wechatModifier;
rbtQQ.Tag = qqModifier;
rbtTIM.Tag = timModifier;
// 默认微信
rbtWechat.Enabled = true;
modifier = wechatModifier;
}
public FormMain()
{
@@ -24,67 +43,86 @@ namespace RevokeMsgPatcher
}
this.Text += currentVersion;
InitModifier();
InitControls();
}
private void InitControls()
{
// 自动获取应用安装路径
txtPath.Text = wechatModifier.FindInstallPath();
txtPath.Text = modifier.FindInstallPath();
lblVersion.Text = modifier.GetVersion();
// 显示是否能够备份还原
if (!string.IsNullOrEmpty(txtPath.Text))
{
wechatModifier.InitEditors(txtPath.Text);
btnRestore.Enabled = wechatModifier.BackupExists();
modifier.InitEditors(txtPath.Text);
btnRestore.Enabled = modifier.BackupExists();
}
}
private void btnPatch_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtPath.Text) || !wechatModifier.IsAllFilesExist(txtPath.Text))
if (!modifier.IsAllFilesExist(txtPath.Text))
{
MessageBox.Show("请选择微信安装路径!");
MessageBox.Show("请选择正确的安装路径!");
return;
}
EnableAllButton(false);
// a.重新初始化编辑器
wechatModifier.InitEditors(txtPath.Text);
btnPatch.Enabled = false;
modifier.InitEditors(txtPath.Text);
// b.计算SHA1验证文件完整性寻找对应的补丁信息
try
{
wechatModifier.ValidateAndFindModifyInfo();
modifier.ValidateAndFindModifyInfo();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
EnableAllButton(true);
btnRestore.Enabled = modifier.BackupExists();
return;
}
// c.打补丁
try
{
wechatModifier.Patch();
modifier.Patch();
MessageBox.Show("补丁安装成功!");
EnableAllButton(true);
btnRestore.Enabled = modifier.BackupExists();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
MessageBox.Show(ex.Message + " 请以管理员权限启动本程序,并确认微信处于关闭状态。");
EnableAllButton(true);
btnRestore.Enabled = modifier.BackupExists();
}
btnPatch.Enabled = true;
}
private void txtPath_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtPath.Text))
if (modifier.IsAllFilesExist(txtPath.Text))
{
wechatModifier.InitEditors(txtPath.Text);
btnRestore.Enabled = wechatModifier.BackupExists();
modifier.InitEditors(txtPath.Text);
btnRestore.Enabled = modifier.BackupExists();
}
else
{
btnPatch.Enabled = false;
btnRestore.Enabled = false;
}
}
private void btnChoosePath_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择微信安装路径";
dialog.Description = "请选择安装路径";
if (dialog.ShowDialog() == DialogResult.OK)
{
if (string.IsNullOrEmpty(dialog.SelectedPath) || !wechatModifier.IsAllFilesExist(dialog.SelectedPath))
if (string.IsNullOrEmpty(dialog.SelectedPath) || !modifier.IsAllFilesExist(dialog.SelectedPath))
{
MessageBox.Show("无法找到微信关键文件,请选择正确的微信安装路径!");
MessageBox.Show("无法找到此应用的关键文件,请选择正确的安装路径!");
}
else
{
@@ -95,17 +133,19 @@ namespace RevokeMsgPatcher
private void btnRestore_Click(object sender, EventArgs e)
{
btnRestore.Enabled = false;
EnableAllButton(false);
try
{
wechatModifier.Restore();
modifier.Restore();
MessageBox.Show("还原成功!");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
MessageBox.Show(ex.Message);
}
btnRestore.Enabled = wechatModifier.BackupExists();
EnableAllButton(true);
btnRestore.Enabled = modifier.BackupExists();
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
@@ -122,16 +162,16 @@ namespace RevokeMsgPatcher
});
t.Start();
string json = await t;
if(string.IsNullOrEmpty(json))
if (string.IsNullOrEmpty(json))
{
lblUpdatePachJson.Text = "获取失败";
lblUpdatePachJson.Text = "[ 获取失败 ]";
} else
}
else
{
//patcher.SetNewPatchJson(json);
lblUpdatePachJson.Text = "获取成功";
lblUpdatePachJson.Text = "[ 获取成功 ]";
}
}
private void lblUpdatePachJson_Click(object sender, EventArgs e)
@@ -144,9 +184,42 @@ namespace RevokeMsgPatcher
MessageBox.Show("当前所支持的微信版本:" + Environment.NewLine + versions);
}
private void btnTest_Click(object sender, EventArgs e)
private void radioButtons_CheckedChanged(object sender, EventArgs e)
{
PathUtil.DisplayAllProgram();
EnableAllButton(false);
RadioButton radioButton = sender as RadioButton;
if (rbtWechat.Checked)
{
modifier = (WechatModifier)rbtWechat.Tag;
}
else if (rbtQQ.Checked)
{
modifier = (QQModifier)rbtQQ.Tag;
}
else if (rbtTIM.Checked)
{
modifier = (TIMModifier)rbtTIM.Tag;
}
txtPath.Text = modifier.FindInstallPath();
lblVersion.Text = modifier.GetVersion();
EnableAllButton(true);
// 显示是否能够备份还原
if (!string.IsNullOrEmpty(txtPath.Text))
{
modifier.InitEditors(txtPath.Text);
btnRestore.Enabled = modifier.BackupExists();
}
}
private void EnableAllButton(bool state)
{
foreach (Control c in this.Controls)
{
if (c is Button)
{
c.Enabled = state;
}
}
}
}
}