summaryrefslogtreecommitdiff
path: root/love2dToAPK/adb.cs
blob: 08aed78c87927012fbe057963717e065e883390c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace love2dToAPK {

    class adb {
        
        public adb() {
        }

        public void install(string apkPath) {
            var processInfo = new ProcessStartInfo();
            processInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory + "tools\\tools\\adb";
            processInfo.FileName = "cmd.exe";
            processInfo.Arguments = "/c adb.exe install -r \"" + apkPath + "\"";  // This will install a new version of the app
            processInfo.CreateNoWindow = true;
            processInfo.UseShellExecute = false;
            processInfo.RedirectStandardError = true;
            processInfo.RedirectStandardOutput = true;

            var process = Process.Start(processInfo);
            process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => log(e.Data);
            process.BeginOutputReadLine();

            process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => log("error>> " + e.Data);
            process.BeginErrorReadLine();

            process.WaitForExit();

            //Console.WriteLine("ExitCode: {0}", process.ExitCode);
            log("Exitcode: " + process.ExitCode.ToString());
            process.Close();
            return;
        }

        public void uninstall(string bundleIdentifier) {
            var processInfo = new ProcessStartInfo();
            processInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory + "tools\\tools\\adb";
            processInfo.FileName = "cmd.exe";
            processInfo.Arguments = "/c adb.exe uninstall \"" + bundleIdentifier + "\"";
            processInfo.CreateNoWindow = true;
            processInfo.UseShellExecute = false;
            processInfo.RedirectStandardError = true;
            processInfo.RedirectStandardOutput = true;

            var process = Process.Start(processInfo);
            process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => log(e.Data);
            process.BeginOutputReadLine();

            process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => log("error>> " + e.Data);
            process.BeginErrorReadLine();

            process.WaitForExit();

            //Console.WriteLine("ExitCode: {0}", process.ExitCode);
            log("Exitcode: " + process.ExitCode.ToString());
            process.Close();
            return;
        }

        public void launchApp(string bundleIdentifier) {
            var processInfo = new ProcessStartInfo();
            processInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory + "tools\\tools\\adb";
            processInfo.FileName = "cmd.exe";
            processInfo.Arguments = "/c adb.exe shell monkey -p " + bundleIdentifier + " -c android.intent.category.LAUNCHER 1";
            processInfo.CreateNoWindow = true;
            processInfo.UseShellExecute = false;
            processInfo.RedirectStandardError = true;
            processInfo.RedirectStandardOutput = true;

            var process = Process.Start(processInfo);
            process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => log(e.Data);
            process.BeginOutputReadLine();

            process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => log("error>> " + e.Data);
            process.BeginErrorReadLine();

            process.WaitForExit();

            //Console.WriteLine("ExitCode: {0}", process.ExitCode);
            log("Exitcode: " + process.ExitCode.ToString());
            process.Close();
            return;
        }

        private void log(string str) {
            Program.frmOutput.log(str);
        }

    }

}