1 Star 2 Fork 0

轮回/vivo-tools-3

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ApkInstall.cs 7.67 KB
一键复制 编辑 原始数据 按行查看 历史
轮回 提交于 2022-04-27 18:19 +08:00 . 更新3.0.0
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using Sunny.UI;
namespace vivo_tools_3
{
public partial class ApkInstall : UIPage
{
public override bool SetParam(int fromPageIndex, params object[] objects)
{
if (objects.Length == 1)
{
isConnected = objects[0].ToString();
this.label1.Text = isConnected;
this.label1.Left = this.Width - this.label1.Width - 15;
return true;
}
else
{
return false;
}
}
public ApkInstall(string isConnected, string text = null)
{
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.None;
if (text != null)
{
this.Text = text;
}
else
{
this.Text = "安装APK文件";
}
this.button1.Text = "开始安装";
this.button2.Text = "选择APK文件";
this.isConnected = isConnected;
this.textBox1.Text += "\r\n未选择APK文件!\r\n";
this.textBox1.Text += "\r\n------------------------------------------------------------\r\n";
}
public string isConnected = "";
public void Form_InstallApk_Load(object sender, EventArgs e)
{
this.label1.ForeColor = Color.IndianRed;
this.label1.Text = "设备未连接";
this.label1.Top = this.label1.Parent.Height / 2 - this.label1.Height / 2;
this.label1.Left = this.label1.Parent.Width - this.label1.Width - this.label1.Top;
}
private void Label_MouseHover(object sender, EventArgs e)
{
(sender as Label).ForeColor = Color.FromArgb(255, 200, 200, 200);
}
private void Label_MouseLeave(object sender, EventArgs e)
{
(sender as Label).ForeColor = Color.White;
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if (!string.IsNullOrEmpty(ApkName) && !string.IsNullOrEmpty(filepath))
{
if (this.ApkName == "" || this.filepath == "")
{
ShowAskDialog("提示", "请先选择APK文件!");
}
else
{
this.textBox1.Text += "\r\n正在安装APK,请稍后......\r\n";
this.textBox1.Text += "\r\n安装过程中程序会卡住,请继续等待......\r\n";
timer1.Enabled = true;
}
}
else
{
ShowAskDialog("提示", "请先选择APK文件!");
}
}
catch (Exception)
{
}
}
private void button2_Click(object sender, EventArgs e)
{
Getfiles();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
this.textBox1.Focus();//获取焦点
this.textBox1.Select(this.textBox1.TextLength, 0);//光标定位到文本最后
this.textBox1.ScrollToCaret();//滚动到光标处
}
private string filepath = "";
private string ApkName = "";
private void Getfiles()
{
OpenFileDialog op = new OpenFileDialog();
op.Title = "请选择APK文件!";
//设置文件的类型
op.Filter = "apk文件|*.apk";
//如果用户点击了打开按钮、选择了正确的文件路径则进行如下操作:
if (op.ShowDialog() == DialogResult.OK)
{
filepath = System.IO.Path.GetFileName(op.FileName);
//警告:刷机之前请双清!否则会导致死机、无限重启或手机变砖!!!
ApkName = op.FileName;
this.textBox1.Text += "\r\n当前APK文件:" + ApkName + "\r\n";
}
else
{
this.textBox1.Text += "\r\n未选择APK文件!\r\n";
ApkName = "";
filepath = "";
}
this.textBox1.Text += "\r\n------------------------------------------------------------\r\n";
this.Focus();
}
public string executeCmd(string Command)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardError = false;
p.Start();
p.StandardInput.WriteLine(Command);
p.StandardInput.WriteLine("exit");
string str = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
return str;
}
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
string str = executeCmd("adb install " + ApkName);
if (!string.IsNullOrEmpty(str))
{
if (str.Contains("INSTALL_FAILED_ALREADY_EXISTS"))
{
this.textBox1.Text += "\r\n安装失败,你的设备已拥有该软件......\r\n";
}
else if(str.Contains("INSTALL_FAILED_NO_MATCHING_ABIS"))
{
this.textBox1.Text += "\r\n安装失败,该应用不支持你的设备处理器架构......\r\n";
}
else if (str.Contains("Error") || str.Contains("Install canceled by user"))
{
this.textBox1.Text += "\r\n安装失败,出现错误......\r\n";
}
else
{
this.textBox1.Text += "\r\n安装成功\r\n";
}
this.textBox1.Text += "\r\n安装结束......\r\n";
this.textBox1.Text += "\r\n------------------------------------------------------------\r\n";
}
}
private void panel_button_SizeChanged(object sender, EventArgs e)
{
this.label1.Top = this.label1.Parent.Height / 2 - this.label1.Height / 2;
this.label1.Left = this.label1.Parent.Width - this.label1.Width - this.label1.Top;
}
private void label1_TextChanged(object sender, EventArgs e)
{
if (this.label1.Text.Contains("已连接"))
{
if (this.label1.Text != "FastBoot设备已连接")
{
this.button1.Enabled = false;
this.label1.ForeColor = Color.DarkGreen;
}
}
else if (this.label1.Text.Contains("连接中"))
{
this.button1.Enabled = false;
this.label1.ForeColor = Color.DarkOrange;
}
else if (this.label1.Text.Contains("未连接"))
{
this.button1.Enabled = false;
this.label1.ForeColor = Color.IndianRed;
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/PeopleCarWorld/vivo-tools-3.git
[email protected]:PeopleCarWorld/vivo-tools-3.git
PeopleCarWorld
vivo-tools-3
vivo-tools-3
master

搜索帮助