Exemplo n.º 1
0
 private void EntryPoint(ILeafUI ui, IClassTextDictionary texts)
 {
     using (ui)
     {
         ui.Title = this.GetName();
         ui.Show();
         if (TryGetInputEndPoint(ui, texts, out IPEndPoint endpoint))
         {
             using (var executor = new CommandExecutor())
             {
                 ui.Tip = texts["ConnectingDevice"];
                 ui.WriteLine(texts["ConnectingDevice"]);
                 executor.To(e => ui.WriteOutput(e.Text));
                 var result = executor.Adb($"connect {endpoint.Address}:{endpoint.Port}");
                 if (result.Output.Contains("fail", true))
                 {
                     ui.WriteLine(texts["fail"]);
                     ui.Finish(texts["Fail"]);
                 }
                 else
                 {
                     ui.Finish(result.ExitCode);
                 }
             }
         }
         else
         {
             ui.Shutdown();
         }
     }
 }
Exemplo n.º 2
0
 public void EntryPoint(ILeafUI ui, IDevice device, IClassTextDictionary text, ITemporaryFloder tmp, IEmbeddedFileManager emb)
 {
     using (ui)
     {
         ui.Icon  = this.GetIconBytes();
         ui.Title = this.GetName();
         ui.Show();
         ui.EAgree(text["warn"]);
         ui.EAgree(text["warn"]);
         ui.EAgree(text["warn"]);
         using (var executor = new CommandExecutor())
         {
             executor.To(e => ui.WriteOutput(e.Text));
             var dpm = new DpmPro(executor, emb, tmp, device);
             ui.WriteLine(text["extracting"]);
             dpm.Extract();
             ui.WriteLine(text["pushing"]);
             dpm.PushToDevice();
             ui.WriteLine(text["removing"]);
             int exitCode = dpm.RemoveUsers();
             if (exitCode == 0 && ui.DoYN(text["reboot"]))
             {
                 device.Reboot2System();
             }
             ui.Finish(exitCode);
         }
     }
 }
Exemplo n.º 3
0
        private bool TryGetInputEndPoint(ILeafUI ui, IClassTextDictionary texts, out IPEndPoint endPoint)
        {
            Task <object> dialogTask = ui.ShowDialogById("inputIpEndPoint");

            dialogTask.Wait();
            while (dialogTask.Result != null)
            {
                dynamic result = dialogTask.Result;
                SLogger <ENetDeviceConnecter> .Info(result.Result);

                if (result.IsInputRight == false)
                {
                    ui.ShowMessage(texts["PleaseInputRightIP"]);
                    dialogTask = ui.ShowDialogById("inputIpEndPoint");
                    dialogTask.Wait();
                }
                else
                {
                    endPoint = (IPEndPoint)result.Result;
                    return(true);
                }
            }
            endPoint = null;
            return(false);
        }
 private void EntryPoint(ILeafUI ui, IDevice device, IClassTextDictionary texts)
 {
     using (ui)
     {
         ui.Title = this.GetName();
         ui.Show();
         var    dev  = (UsbDevice)device;
         ushort?port = null;
         do
         {
             var input = ui.InputString(texts["Hint"], "5555");
             if (input == null)
             {
                 return;
             }
             if (ushort.TryParse(input, out ushort _port))
             {
                 port = _port;
             }
             else
             {
                 ui.EWarn(texts["InputError"]);
             }
         } while (port == null);
         dev.OpenNetDebugging((ushort)port, true);
     }
 }
Exemplo n.º 5
0
 public void EntryPoint(ILeafUI ui, IDevice device, IClassTextDictionary text)
 {
     using (ui)
     {
         ui.Title = this.GetName();
         ui.Show();
         bool?  dialogResult = null;
         string seleFile     = null;
         ui.RunOnUIThread(() =>
         {
             Microsoft.Win32.OpenFileDialog fileDialog = new Microsoft.Win32.OpenFileDialog();
             fileDialog.Reset();
             fileDialog.Title       = text["title"];
             fileDialog.Filter      = text["filter"];
             fileDialog.Multiselect = false;
             dialogResult           = fileDialog.ShowDialog();
             seleFile = fileDialog.FileName;
         });
         if (dialogResult != true)
         {
             ui.EShutdown();
         }
         FileInfo        fileInfo = new FileInfo(seleFile);
         CommandExecutor executor = new CommandExecutor();
         executor.OutputReceived += (s, e) => ui.WriteLine(e.Text);
         var result = executor.Adb(device, $"push \"{fileInfo.FullName}\" \"/sdcard/{fileInfo.Name}\"");
         ui.Finish(result.ExitCode);
     }
 }
Exemplo n.º 6
0
 public void Main(IDevice device, ILeafUI ui, IClassTextDictionary text)
 {
     using (ui)
     {
         ui.Icon  = this.GetIconBytes();
         ui.Title = this.GetName();
         //ui.Closing += (s, e) =>
         //{
         //    executor.Dispose();
         //    return true;
         //};
         //executor.OutputReceived += (s, e) =>
         //{
         //    ui.WriteLine(e.Text);
         //};
         ui.Show();
         string[] options = new string[] {
             text["sys"],
             text["rec"],
             text["fb"],
             text["9008"],
         };
         var result = ui.SelectFrom(text["modehint"], options);
         if (result == null)
         {
             ui.EShutdown();
         }
         if (result.Equals(options[0]))
         {
             device.Reboot2System();
         }
         else if (result.Equals(options[1]))
         {
             device.Reboot2Recovery();
         }
         else if (result.Equals(options[2]))
         {
             device.Reboot2Fastboot();
         }
         else if (result.Equals(options[3]))
         {
             device.Reboot29008();
         }
         else
         {
             device.Reboot2System();
         }
         ui.Shutdown();
     }
 }
Exemplo n.º 7
0
 public void EntryPoint(ILeafUI ui, IDevice device, IClassTextDictionary text)
 {
     using (ui)
     {
         ui.Title = this.GetName();
         ui.Icon  = this.GetIconBytes();
         ui.Show();
         ui.AppPropertyCheck(device, PKG_NAME);
         ui.ShowMessage(text["launchFirst"]);
         CommandExecutor executor = new CommandExecutor();
         var             result   = executor.AdbShell(device, $"sh {SH_PATH}");
         ui.Finish(result.ExitCode);
     }
 }
Exemplo n.º 8
0
 private void EntryPoint(ILeafUI ui, IDevice device, IClassTextDictionary texts)
 {
     using (ui)
     {
         ui.Title = this.GetName();
         ui.Icon  = this.GetIconBytes();
         ui.Show();
         bool?choice = ui.DoChoice(texts["ChoiceMessage"], texts["OptionDis"], texts["OptionsOD"]);
         if (choice == null)
         {
             return;
         }
         (device as NetDevice).Disconnect((bool)choice);
     }
 }
Exemplo n.º 9
0
 public void EntryPoint(ILeafUI ui, IDevice device, IClassTextDictionary text)
 {
     using (ui)
     {
         ui.Title = this.GetName();
         ui.Icon  = this.GetIconBytes();
         ui.Show();
         CommandExecutor executor = new CommandExecutor();
         executor.OutputReceived += (s, e) => ui.WriteLine(e.Text);
         executor.Adb(device, "root");
         var result = executor.Adb(device, "disable-verity");
         if (result.ExitCode == 0 && ui.DoYN(text["reboot"]))
         {
             device.Reboot2System();
         }
         ui.Finish(result.ExitCode);
     }
 }
Exemplo n.º 10
0
 public void EntryPoint(ILeafUI ui, IDevice device, IClassTextDictionary text)
 {
     using (ui)
     {
         ui.Title = this.GetName();
         ui.Icon  = this.GetIconBytes();
         ui.Show();
         ui.AppPropertyCheck(device, "me.piebridge.brevent");
         CommandExecutor executor = new CommandExecutor();
         executor.OutputReceived += (s, e) => ui.WriteLine(e.Text);
         if (executor.AdbShell(device, $"cat {SH_PATH}").ExitCode != 0)
         {
             ui.ShowMessage(text["firstMsg"]);
             Thread.Sleep(2000);
         }
         var result = executor.AdbShell(device, $"sh {SH_PATH}");
         ui.Finish(result.ExitCode);
     }
 }
Exemplo n.º 11
0
 public void EntryPoint(ILeafUI ui, IDevice device, IClassTextDictionary textManager)
 {
     using (ui)
     {
         ui.Title = this.GetName();
         ui.Icon  = this.GetIconBytes();
         ui.Show();
         if (!ui.DoYN(textManager["warn"]))
         {
             return;
         }
         if (!ui.DoYN(textManager["warn2"]))
         {
             return;
         }
         CommandExecutor executor = new CommandExecutor();
         executor.OutputReceived += (s, e) => ui.WriteOutput(e.Text);
         var exitCode = executor.Fastboot(device, "oem lock").ExitCode;
         ui.Finish(exitCode);
     }
 }
Exemplo n.º 12
0
        public int Main(IUx ux, IAppManager app, IClassTextDictionary text)
        {
            string       msg          = text["msg"];
            string       btnAdmin     = text["admin"];
            string       btnNormal    = text["user"];
            ChoiceResult choiceResult = ux.DoChoice(msg, btnAdmin, btnNormal);

            switch (choiceResult)
            {
            case ChoiceResult.Left:
                app.RestartAppAsAdmin();
                break;

            case ChoiceResult.Right:
                app.RestartApp();
                break;

            default:
                return(AutumnBoxExtension.ERR_CANCELED_BY_USER);
            }
            return(AutumnBoxExtension.OK);
        }
Exemplo n.º 13
0
 public void EntryPoint(ILeafUI ui, IDevice device, IClassTextDictionary text)
 {
     using (ui)
     {
         ui.Title = this.GetName();
         ui.Icon  = this.GetIconBytes();
         ui.Show();
         OpenFileDialog fileDialog = new OpenFileDialog();
         fileDialog.Reset();
         fileDialog.Title       = text["Title"];
         fileDialog.Filter      = text["Filter"];
         fileDialog.Multiselect = false;
         if (fileDialog.ShowDialog() != true)
         {
             ui.EFinish();
         }
         CommandExecutor executor = new CommandExecutor();
         executor.OutputReceived += (s, e) => ui.WriteOutput(e.Text);
         executor.Fastboot(device, $"flash recovery \"{fileDialog.FileName}\"");
         var result = executor.Fastboot(device, $"boot \"{fileDialog.FileName}\"");
         ui.Finish(result.ExitCode);
     }
 }
Exemplo n.º 14
0
 public void EntryPoint(ILeafUI ui, IDevice device, IClassTextDictionary text)
 {
     using (ui)
     {
         ui.Title = this.GetName();
         ui.Icon  = this.GetIconBytes();
         ui.Show();
         if (device is NetDevice)
         {
             ui.ShowMessage(text["isNet"]);
             ui.EFinish();
         }
         else if (device is UsbDevice usbDevice)
         {
             usbDevice.OpenNetDebugging(5555, true);
             ui.Finish();
         }
         else
         {
             ui.Finish(text["notsupport"]);
         }
     }
 }
Exemplo n.º 15
0
        public void Main(IDevice device, ILeafUI ui, IClassTextDictionary text)
        {
            using (ui)
            {
                ui.Icon  = this.GetIconBytes();
                ui.Title = this.GetName();
                ui.Show();
                var choiceResult = ui.DoChoice(text["msg"], text["modify"], text["reset"]);
                var wm           = new WindowManager(device);
                switch (choiceResult)
                {
                case null:
                    ui.EShutdown();
                    break;

                case true:
                    if (int.TryParse(ui.InputString(text["hint"]), out int target))
                    {
                        wm.Density = target;
                        device.Reboot2System();
                        ui.EFinish();
                    }
                    else
                    {
                        ui.Finish(LeafConstants.ERR_CANCELED_BY_USER);
                    }

                    break;

                case false:
                    wm.ResetDensity();
                    device.Reboot2System();
                    ui.EFinish();
                    break;
                }
            }
        }
Exemplo n.º 16
0
        public void EntryPoint(ILeafUI ui, IDevice device, IClassTextDictionary text)
        {
            using (ui)
            {
                ui.Title = this.GetName();
                ui.Icon  = this.GetIconBytes();
                ui.Show();
                ui.EAgree(text["notice"]);
                using (var executor = new CommandExecutor())
                {
                    Version androidVersion = new DeviceBuildPropGetter(device).GetAndroidVersion();
                    executor.OutputReceived += (s, e) => ui.WriteOutput(e.Text);
                    ui.WriteLine("Accessibility service run-on-demand || Aggressive Doze on Android 7.0+ (non-root)");
                    var result = executor.AdbShell(device, GRANT_PRE, WRITE_SECURE_SETTINGS);
                    Count(result);

                    ui.WriteLine("Doze on the Go || Aggressive Doze");
                    result = executor.AdbShell(device, GRANT_PRE, DUMP);
                    Count(result);

                    ui.WriteLine("Wake-up Tracker");
                    result = executor.AdbShell(device, GRANT_PRE, READ_LOGS);
                    Count(result);

                    ui.WriteLine("Background-free enforcement on Android 8+ (non-root)");
                    if (androidVersion != null && androidVersion >= new Version("8.0"))
                    {
                        result = executor.AdbShell(device, GRANT_PRE, GET_APP_OPS_STATS);
                        Count(result);
                    }
                    result = executor.AdbShell(device, "am force-stop", PKG_NAME);
                    Count(result);
                    ui.WriteLine($"successed: {successed} failed:{error}");
                    ui.Finish(text["tip"]);
                }
            }
        }
Exemplo n.º 17
0
        public void Main(ILeafUI ui, IClassTextDictionary textManager)
        {
            /*
             * 一定要进行using,此处是为了确保LeafUI被正确释放
             * 否则当该函数内发生异常,LeafUI将无法被关闭
             */
            using (ui)
            {
                /*初始化UI,此时UI仍然不可见*/
                //将LeafUI的图标设置为本模块的图标
                ui.Icon = this.GetIconBytes();
                //将LeafUI的标题设置为本模块的名称
                ui.Title = this.GetName();
                //绑定LeafUI关闭事件,并非必要的操作
                ui.Closing += (s, e) =>
                {
                    /*
                     * 当用户点击停止按钮时发生
                     * 请在此处销毁你调用的资源
                     * 如果你不想你的模块被中途停止,请返回false
                     */
                    return(true);
                };

                /*完成初始化,调用展示方法后,UI将可见*/
                //显示UI
                ui.Show();

                if (ui.DoYN("是否需要参看本拓展源代码?", "是", "否"))
                {
                    Process.Start("https://github.com/zsh2401/AutumnBox/blob/master/AutumnBox.CoreModules/Extensions/NoMatter/ELeafUIDemo.cs");
                }

                if (ui.DoYN("是否需要开启右上角问号?", "是", "否"))
                {
                    ui.EnableHelpBtn(() =>
                    {
                        Process.Start("https://github.com/zsh2401/AutumnBox/blob/master/AutumnBox.CoreModules/Extensions/NoMatter/ELeafUIDemo.cs");
                    });
                }

                //在输出框打印东西
                ui.WriteLine("这是普通输出,用于对用户的提示等");

                /*设置进度与说明
                 * 当然,你也可以不进行设置
                 * LeafUI默认进度条是无限循环的(进度值为-1)
                 * 默认提示是正在进行中等类似话语
                 */
                Thread.Sleep(1000);
                ui.ShowMessage("进度条以及提示信息的演示");

                ui.Tip      = "第一步";
                ui.Progress = 10;
                Thread.Sleep(500);
                //设置进度与说明
                ui.Tip      = "第二步";
                ui.Progress = 40;
                Thread.Sleep(500);
                //设置进度与说明
                ui.Tip      = "第三步";
                ui.Progress = 60;
                Thread.Sleep(500);

                ui.ShowMessage("进度条将变回无限循环");
                ui.Progress = -1;

                //进行带有取消选项的选择
                var choiceResult = ui.DoChoice("这是一个选择示例,请做出选择", "ping测试", "启动别的拓展模块", "什么也不做");
                switch (choiceResult)
                {
                case true:
                    var executor = new CommandExecutor();
                    executor.To(e => ui.WriteOutput(e.Text));    //重定向输出
                    executor.Cmd("ping www.baidu.com");
                    //通过此函数,可以显示专业输出,但不建议调用,此权利应该尽可能交给用户
                    ui.WriteLine("显示专业输出!");
                    ui.ProOutputVisible = true;
                    executor.Dispose();
                    break;

                case false:
                    //var thread = context.NewExtensionThread("EHoldMyHand");
                    //thread.Data["wtf"] = "aaa";//可以传参数哦
                    //thread.Start();
                    //thread.WaitForExit();
                    break;

                default:
                    ui.ShowMessage("哼,气得我变大了!");
                    ui.WriteLine($"原大小:{ui.Width}x{ui.Height}");
                    ui.Width  += 200;
                    ui.Height += 200;
                    ui.WriteLine($"后大小:{ui.Width}x{ui.Height}");
                    break;
                }

                ui.ShowMessage($"让我们来看看根据语言自动匹配的语言值: {textManager["testkey"]}");

                //进行单选,让用户决定用那个方式结束
                const string hint   = "好了,该选择一个方式结束了";
                const string item0  = "默认的完成方式";
                const string item1  = "传入错误码1";
                const string item2  = "直接设定完成提示信息";
                const string item3  = "通过EFinish结束";
                var          result = ui.SelectFrom(hint,
                                                    item0,
                                                    item1,
                                                    item2,
                                                    item3);

                /*
                 * 当完成函数流程时.一定要手动调用Finish()函数
                 * 如果不进行调用,那么当C# using将调用LeafUI的Dispose函数时
                 * LeafUI将视本模块执行过程出现问题,将直接关闭
                 */
                switch (result as string)
                {
                case item0:
                    ui.Finish();    //LeafUI将视为本模块执行成功,显示成功提示
                    break;

                case item1:
                    ui.Finish(1);    //LeafUI将根据传入的错误码进行分析,并设置完成提示
                    break;

                case item2:
                    ui.Finish("功能结束");    //LeafUI不进行结果判断,而是将传入的字符串作为结束提示
                    break;

                default:
                    /*EFinish调用后将抛出一个可以信号异常
                     * 也就是说会立刻停止当前函数的流程,而不像
                     * 普通的Finish那样继续执行之后的语句
                     */
                    ui.EFinish();
                    //由于EFinish抛出异常,下面的代码无法被执行
                    System.Environment.Exit(1);
                    break;
                }
            }
        }
Exemplo n.º 18
0
        public void Main(IDevice device, [LFromData(KEY_REBOOT_OPTION)] int rebootOption, IClassTextDictionary text, IUx ux)
        {
            if (!ux.DoYN(text["aus"]))
            {
                return;
            }
            switch (rebootOption)
            {
            case RECOVERY:
                device.Reboot2Recovery();
                break;

            case FASTBOOT:
                device.Reboot2Fastboot();
                break;

            case _9008:
                device.Reboot29008();
                break;

            default:
                device.Reboot2System();
                break;
            }
        }
Exemplo n.º 19
0
 static LeafUIHelper()
 {
     text = LakeProvider.Lake.Get <IClassTextReader>().Read((typeof(LeafUIHelper)));
     SLogger.Debug(nameof(LeafUIHelper), $"{typeof(LeafUIHelper)}'s IClassTextManager created");
 }