-
Notifications
You must be signed in to change notification settings - Fork 6
/
mainForm.cs
216 lines (193 loc) · 7.45 KB
/
mainForm.cs
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Windows.Forms;
using System.IO.Compression;
using System.Diagnostics;
namespace QuestSideloader
{
public partial class mainForm : Form
{
private string adburl = "https://dl.google.com/android/repository/platform-tools-latest-windows.zip";
public mainForm()
{
InitializeComponent();
this.AllowDrop = true;
this.DragEnter += new DragEventHandler(dragEnter);
this.DragDrop += new DragEventHandler(dragDrop);
linkToOculus.LinkBehavior = LinkBehavior.NeverUnderline;
var b = SystemIcons.Information.ToBitmap();
pictureBox1.Image = b;
this.Show();
init();
}
public void init()
{
getadb();
}
private void dragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
}
private void dragDrop(object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files)
{
if (file.EndsWith(".apk"))
{
installApk(file);
break;
}
}
}
private void installApk(string path)
{
if (MessageBox.Show("Do you wish to install this app?\nWarning: You should only install apps from developers you trust!", "Install APK", MessageBoxButtons.OKCancel) == DialogResult.OK){
lStatus.Text = "Installing "+path+"...";
var o = adbCmd("install -r "+path);
checkInstallOutput(o);
}
}
private void getadb()
{
if (!System.IO.File.Exists(Application.LocalUserAppDataPath + "/platform-tools/adb.exe"))
{
lStatus.Text = "ADB not found.";
if (MessageBox.Show("To sideload apps, a program called ADB must be downloaded from Google. Click OK to continue...", "Download ADB?", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
lStatus.Text = "Please wait...\nThe program may look like it has frozen but be patient!";
lDrop.Text = "Downloading: "+adburl;
WebClient Client = new WebClient();
Application.DoEvents();
try {
Client.DownloadFile(adburl, Application.LocalUserAppDataPath + "/adb.zip");
}
catch (WebException we)
{
MessageBox.Show("An error occurred downloading ADB. Please try again or contact the developer: " + we.ToString());
Application.Exit();
}
try
{
ZipFile.ExtractToDirectory(Application.LocalUserAppDataPath + "/adb.zip", Application.LocalUserAppDataPath + "/");
}
catch (Exception e)
{
MessageBox.Show("An error occurred extracting ADB. Please try again or contact the developer: "+e.ToString());
Application.Exit();
}
if (!System.IO.File.Exists(Application.LocalUserAppDataPath + "/platform-tools/adb.exe"))
{
MessageBox.Show("An error occurred extracting ADB. Please try again or contact the developer.");
Application.Exit();
}
else
getdevices();
}
else
Application.Exit();
}
else
{
getdevices();
}
}
private void getdevices()
{
lDrop.Text = "...";
lStatus.Text = "Getting devices, please plug in your Quest/Go...";
//adb devices
var o = adbCmd("devices");
if (o.ToLower().Contains("unauthorized"))
{
lDrop.Text = "Device found. Please leave your Quest/Go plugged in, put it on and authorize this computer when prompted...";
devicesTimer.Enabled = true;
}
else if (o.Replace("List of devices","").Contains("device"))
{
lDrop.Text = "Device found.";
checkautoinstall();
}
else
{
lDrop.Text = "Getting devices, please plug in your Quest/Go...";
devicesTimer.Enabled = true;
}
}
private string adbCmd(string options)
{
Application.DoEvents();
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.WorkingDirectory = "./";
p.StartInfo.FileName = Application.LocalUserAppDataPath + "/platform-tools/adb.exe";
p.StartInfo.Arguments = options;
p.StartInfo.CreateNoWindow = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
return output;
}
private void checkautoinstall()
{
//check for auto-install package apk
if (System.IO.File.Exists("./autoinstall.apk"))
{
lStatus.Text = "Device found.";
lDrop.Text = "";
if (MessageBox.Show("Auto-install APK detected. Do you wish to install this app?\nWarning: You should only install apps from developers you trust!", "Confirm Install", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
lStatus.Text = "Auto installing, please wait.";
var o = adbCmd("install -r ./autoinstall.apk");
checkInstallOutput(o);
setupdragndrop();
lStatus.Text = "App installed successfully!";
}
else
{
setupdragndrop();
}
}
else
{
setupdragndrop();
}
}
private void checkInstallOutput(string output)
{
if (output.Contains("Success"))
{
lStatus.Text = "App installed successfully!";
}
else
{
lStatus.Text = "App NOT installed!\nInfo: "+output;
}
}
private void setupdragndrop()
{
lStatus.Text = "Device found.";
lDrop.Text = "Drag your app's APK file\nhere to install.";
}
private void linkToOculus_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("https://developer.oculus.com/documentation/mobilesdk/latest/concepts/mobile-device-setup-go/");
}
private void devicesTimer_Tick(object sender, EventArgs e)
{
devicesTimer.Enabled = false;
getdevices();
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}