This repository was archived by the owner on Jan 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
293 lines (239 loc) · 10.8 KB
/
Form1.cs
File metadata and controls
293 lines (239 loc) · 10.8 KB
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
using System;
using System.Net;
using System.IO;
using System.Windows.Forms;
using Newtonsoft.Json;
using System.ComponentModel;
using System.Threading;
using System.Diagnostics;
namespace dotManager
{
public partial class Form1 : Form
{
public static string appdatafolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
public static string appfolder = Path.Combine(appdatafolder, "dotGame\\");
private bool downloadComplete = false;
public Form1()
{
InitializeComponent();
this.AllowDrop = true;
this.DragEnter += new DragEventHandler(Form1_DragEnter);
this.DragDrop += new DragEventHandler(Form1_DragDrop);
}
private void Form1_Load(object sender, EventArgs e)
{
Thread.Sleep(1);
this.Show();
prepareWorkDir();
}
void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
}
void Form1_DragDrop(object sender, DragEventArgs e)
{
dropMeta.Hide();
gpanel.Show();
downloadBtn.Enabled = true;
installBtn.Enabled = false;
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
metadata gameinfo = JsonConvert.DeserializeObject<metadata>(File.ReadAllText(files[0]));
if (System.IO.File.Exists(appfolder + gameinfo.archivename))
{
installBtn.Enabled = true;
}
if (gameinfo.host == "offline")
{
downloadBtn.Enabled = false;
gameinfo.title = gameinfo.title + " | Offline | ";
}
typeGameInfo(gameinfo);
}
public String garc = null;
public String ghost = null;
public String gname = null;
public String gexec = null;
public String gtype = null;
public void typeGameInfo(metadata gameinfo)
{
garc = gameinfo.archivename;
gname = gameinfo.title;
ghost = gameinfo.host;
gexec = gameinfo.executable;
gtype = gameinfo.setup;
gtitle.Text = gameinfo.title;
originalsize.Text = gameinfo.originalsize;
repacksize.Text = gameinfo.repacksize;
setuptype.Text = gameinfo.setup;
otherinfo.Text = gameinfo.comment;
}
public void downloadArchive(String archivename, String host)
{
bool canDownload = true;
this.AllowDrop = false;
Uri hostUri = new Uri(host, UriKind.Absolute);
if (System.IO.File.Exists(appfolder + archivename))
{
DialogResult dialogResult = MessageBox.Show("Game archive already exists, do you want to redownload?", "dotGame | File Exists", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
System.IO.File.Delete(archivename);
canDownload = true;
}
else
{
canDownload = false;
}
}
// download
if (canDownload == true)
{
WebClient client = new WebClient();
System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(Client_DownloadProgressChanged);
client.DownloadFileAsync(hostUri, appfolder + archivename);
}
}
private void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar1.Minimum = 0;
double recive = double.Parse(e.BytesReceived.ToString());
double total = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = recive / total * 100;
lstatus.Text = percentage.ToString()+"%";
if (int.Parse(Math.Truncate(percentage).ToString()) < 0 )
{
progressBar1.Value = 0;
}
else { progressBar1.Value = int.Parse(Math.Truncate(percentage).ToString()); }
lstatus.Text = Math.Round((e.BytesReceived / 1024d / 1024d),2).ToString() + "MB's / " + Math.Round((e.TotalBytesToReceive / 1024d / 1024d),2).ToString() + " MB's downloaded";
}
public async void prepareWorkDir()
{
System.IO.Directory.CreateDirectory(appfolder);
System.IO.Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\dotTemp\\");
if (!System.IO.File.Exists(appfolder + "linker.bat"))
{
string[] linkerCode =
{
"set lnn=%1", "set ldd=%2", "set lnn=%lnn:\"=%", "set ldd=%ldd:\"=%", "mklink /H \"%userprofile%\\Desktop\\%lnn%\" \"%ldd%\""
};
File.WriteAllLines(appfolder + "linker.bat", linkerCode);
}
if (!System.IO.File.Exists(appfolder + "arc.exe"))
{
dropMeta.Text = "Downloading arc.exe this may take some time";
this.AllowDrop = false;
Uri arcUri = new Uri("https://files.exefiles.com/a/arc.exe/B57977528C92003A4BF710A735663065/Arc.exe", UriKind.Absolute);
WebClient pwebClient = new WebClient();
pwebClient.DownloadFileCompleted += new AsyncCompletedEventHandler(arc_dfc);
pwebClient.DownloadFileAsync(arcUri, appfolder+"arc.exe");
while (!downloadComplete)
{
Application.DoEvents();
}
downloadComplete = false;
}
}
void arc_dfc(object sender, AsyncCompletedEventArgs e)
{
downloadComplete = true;
dropMeta.Text = "Drop Metadata file here to begin!";
this.AllowDrop = true;
}
//this needs to be here, othervise designer breaks lol
private void label2_Click(object sender, EventArgs e)
{
}
private void quitbtn_Click(object sender, EventArgs e)
{
Application.Exit();
}
public class metadata
{
public string title { get; set; }
public string originalsize { get; set; }
public string repacksize { get; set; }
public string host { get; set; }
public string archivename { get; set; }
public string setup { get; set; }
public string executable { get; set; }
public string comment { get; set; }
}
private void downloadBtn_Click(object sender, EventArgs e)
{
downloadArchive(garc, ghost);
this.AllowDrop = false;
installBtn.Enabled = true;
}
private void installBtn_Click(object sender, EventArgs e)
{
this.AllowDrop = false;
gpanel.Hide();
dropMeta.Visible = true;
if (gtype == "unpack") {
dropMeta.Text = "Select Installation Path";
DialogResult result = folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(folderBrowserDialog1.SelectedPath))
{
dropMeta.Text = "Installing to: \n" + folderBrowserDialog1.SelectedPath;
var inst = Process.Start(appfolder + "arc.exe", "x -o+ " + appfolder + garc + " --yes --display --diskpath\"" + folderBrowserDialog1.SelectedPath + "\"");
inst.WaitForExit();
dropMeta.Text = "Creating Desktop Shortcut...";
var link = Process.Start(appfolder + "linker.bat", "\"" + gname + "\" " + "\"" + folderBrowserDialog1.SelectedPath + @"\" + gexec + "\"");
Thread.Sleep(1);
dropMeta.Text = gname + "\nInstalled successfully!";
Thread.Sleep(3);
}
} else if (gtype == "external")
{
if (System.IO.Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\dotTemp\\"))
{
System.IO.Directory.Delete(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\dotTemp\\", true);
System.IO.Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\dotTemp\\");
}
dropMeta.Text = "Decompressing external installer";
string tempcode =
(
appfolder + "arc.exe x -o+ " + appfolder + garc + " --yes --display --diskpath" + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\dotTemp\\"
);
File.Delete(appfolder + garc + "_decompress.bat");
File.WriteAllText(appfolder + garc + "_decompress.bat", tempcode);
Process unpack = new Process();
ProcessStartInfo info = unpack.StartInfo;
info.FileName = "powershell.exe";
info.Arguments = appfolder + garc + "_decompress.bat";
info.Verb = "runas";
unpack.StartInfo = info;
unpack.Start();
unpack.WaitForExit();
dropMeta.Text = "Starting external installer";
var setupProcess = Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\dotTemp\\" + gexec);
setupProcess.WaitForExit();
dropMeta.Text = "Deleting external installer";
System.IO.Directory.Delete(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\dotTemp\\", true);
}
dropMeta.Visible = false;
gpanel.Show();
this.AllowDrop = true;
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult dialogResult = MessageBox.Show("Do you really want to delete all data and restart? \n( this doesn't uninstall your games, only archives )", "dotGame | Wipe Data", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
gpanel.Hide();
dropMeta.Visible = true;
dropMeta.Text = "Clearing data...\nApp will restart soon...";
Thread.Sleep(1);
System.IO.Directory.Delete(appfolder, true);
Thread.Sleep(1);
Application.Restart();
}
else
{
return;
}
}
}
}