/// <summary> /// 主函数 /// </summary> /// <param name="toolKit"></param> /// <returns></returns> protected override Output MainMethod(ToolKit <DeviceImageFlasherArgs> toolKit) { var outputBuilder = new AdvanceOutputBuilder(); /*push image file to sdcard*/ var pushArgs = new FilePusherArgs() { DevBasicInfo = toolKit.Args.DevBasicInfo, SavePath = _savePath, SourceFile = toolKit.Args.SourceFile, }; var pushResult = new FilePusher().Run(pushArgs); outputBuilder.Append(pushResult.OutputData); /*move file to img path*/ string path = DeviceImageFinder.PathOf(toolKit.Args.DevBasicInfo.Serial, toolKit.Args.ImageType); using (AndroidShell shell = new AndroidShell(toolKit.Args.DevBasicInfo.Serial)) { shell.Connect(); shell.Switch2Su(); moveResult = shell.SafetyInput($"mv {_savePath} {path}"); outputBuilder.Append(moveResult); } return(outputBuilder.Result); }
/// <summary> /// 主函数 /// </summary> /// <param name="toolKit"></param> /// <returns></returns> protected override Output MainMethod(ToolKit <DeviceImageExtractorArgs> toolKit) { var outBuilder = new AdvanceOutputBuilder(); string path = DeviceImageFinder.PathOf(toolKit.Args.DevBasicInfo.Serial, toolKit.Args.ImageType); if (path == null) { return(null); } _getPathSuccessful = true; using (AndroidShell shell = new AndroidShell(toolKit.Args.DevBasicInfo.Serial)) { shell.Connect(); shell.Switch2Su(); //复制到程序根目录 string copyPath = $"/sdcard/{tempFileName}"; var copyResult = shell.SafetyInput($"cp {path} {copyPath}"); outBuilder.Append(copyResult); if (copyResult.IsSuccessful) { _copySuccessful = copyResult.IsSuccessful; var filePullerArgs = new FilePullerArgs() { DevBasicInfo = toolKit.Args.DevBasicInfo, SavePath = toolKit.Args.SavePath + $"\\{toolKit.Args.ImageType.ToString().ToLower()}.img", FilePathOnDevice = copyPath, }; var pullResult = new FilePuller().Run(filePullerArgs); _pullSuccessful = (pullResult.ExitCode == 0); toolKit.Ae("rm -rf " + copyPath); outBuilder.Append(pullResult.OutputData); } } return(outBuilder.Result); }
private static bool InstallUsePnPUtil(string fileName) { try { var startInfo = new ProcessStartInfo("pnputil", $"-i -a {fileName}") { Verb = "runas", CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, }; var outputBuilder = new AdvanceOutputBuilder(); using (var proc = Process.Start(startInfo)) { proc.OutputDataReceived += (s, e) => { outputBuilder.AppendOut(e.Data); }; proc.ErrorDataReceived += (s, e) => { outputBuilder.AppendError(e.Data); }; proc.Start(); proc.BeginOutputReadLine(); proc.BeginErrorReadLine(); proc.WaitForExit(); outputBuilder.Result.PrintOnLog(ctx); return(proc.ExitCode == 0); } } catch (Exception ex) { OpenApi.Log.Warn(ctx, "failed", ex); return(false); } }
unsafe static int Main(string[] cmdargs) { var builder = new AdvanceOutputBuilder(); var builder2 = new AdvanceOutputBuilder(); builder.ExitCode = 0; builder2.ExitCode = 0; builder.AppendOut("xx"); builder2.AppendOut("xx"); Console.WriteLine(builder.Result.GetHashCode() == builder2.Result.GetHashCode()); Console.ReadKey(); return(0); }
/// <summary> /// 主方法 /// </summary> /// <param name="toolKit"></param> /// <returns></returns> protected override Output MainMethod(ToolKit <ShScriptExecuterArgs> toolKit) { _tooKit = toolKit; var ob = new AdvanceOutputBuilder(); if (AppPackageName != null && AppActivity != null) { Logger.Info(this, Activity.Start(toolKit.Args.Serial, AppPackageName, AppActivity)); Thread.Sleep(Delay); } int retCode = 0; using (AndroidShell shell = new AndroidShell(toolKit.Args.DevBasicInfo.Serial)) { shell.Connect(); ob.Register(shell); retCode = shell.SafetyInput($"sh {ScriptPath}").GetExitCode(); } ob.ExitCode = retCode; _result = ob.Result; return(_result); }
/// <summary> /// 主方法 /// </summary> /// <param name="toolKit"></param> /// <returns></returns> protected override Output MainMethod(ToolKit <FlowArgs> toolKit) { AndroidShellV2 shell = new AndroidShellV2(toolKit.Args.DevBasicInfo.Serial); AdvanceOutputBuilder builder = new AdvanceOutputBuilder(); Version crtVersion = new DeviceBuildPropGetter(toolKit.Args.DevBasicInfo.Serial).GetAndroidVersion(); builder.Register(shell); allSuccessful = shell.Execute("pm grant com.oasisfeng.greenify android.permission.WRITE_SECURE_SETTINGS").IsSuccessful; allSuccessful = shell.Execute("pm grant com.oasisfeng.greenify android.permission.DUMP").IsSuccessful; allSuccessful = shell.Execute("pm grant com.oasisfeng.greenify android.permission.READ_LOGS").IsSuccessful; if (crtVersion?.Major >= 8) { allSuccessful = shell.Execute("pm grant com.oasisfeng.greenify android.permission.READ_APP_OPS_STATS").IsSuccessful; } allSuccessful = shell.Execute("am force-stop com.oasisfeng.greenify").IsSuccessful; return(builder.Result); }