Advertisement
Guest User

Untitled

a guest
Dec 20th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.92 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3. using System.IO;
  4. using System.IO.Compression;
  5. using System.Net;
  6. using System.Diagnostics;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Threading;
  15. using System.Net.Http;
  16. using System.Web;
  17. using Newtonsoft.Json;
  18.  
  19.  
  20.  
  21. namespace WindowsFormsApp2
  22. {
  23. public partial class Form1 : Form
  24. {
  25. private Process process;
  26. public Form1()
  27. {
  28. InitializeComponent();
  29.  
  30. string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
  31.  
  32. if (Directory.Exists(appdata + "/WiAD_Launcher/") == false)
  33. {
  34. Directory.CreateDirectory(appdata + "/WiAD_Launcher/");
  35. }
  36. if (Directory.Exists(appdata + "/WiAD_Launcher/temp/") == false)
  37. {
  38. Directory.CreateDirectory(appdata + "/WiAD_Launcher/temp/");
  39. }
  40. if (Directory.Exists(appdata + "/WiAD_Launcher/modpacks/") == false)
  41. {
  42. Directory.CreateDirectory(appdata + "/WiAD_Launcher/modpacks/");
  43. }
  44. button1.Enabled = false;
  45. }
  46.  
  47. private void password_TextChanged(object sender, EventArgs e)
  48. {
  49. string contents = this.username.Text + this.password.Text;
  50. if (contents.Length == 0)
  51. {
  52. Console.WriteLine("Please login in!");
  53. }
  54. else
  55. {
  56. button1.Enabled = true;
  57. }
  58. }
  59.  
  60. private void button1_Click(object sender, EventArgs e)
  61. {
  62. string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
  63. string templocation = appdata + "/WiAD_Launcher/temp/";
  64. string packlocation = appdata + "/WiAD_Launcher/modpacks/";
  65.  
  66.  
  67. if (checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
  68. {
  69. button1.Enabled = false;
  70. checkBox1.Enabled = false;
  71. checkBox2.Enabled = false;
  72. checkBox3.Enabled = false;
  73. var client = new WebClient();
  74. var text = client.DownloadString("https://wad0.000webhostapp.com/uploads/test.json");
  75.  
  76. SCJSON1 post = JsonConvert.DeserializeObject<SCJSON1>(text);
  77. string mp1 = post.MP1Name;
  78.  
  79. if (Directory.Exists(packlocation + mp1) == false)
  80. {
  81. using (var webClient = new WebClient())
  82. {
  83. WebClient downloader = new WebClient();
  84. Console.WriteLine("Downloading from " + post.MP1Url);
  85. this.Update();
  86. downloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloader_DownloadProgressChanged);
  87. downloader.DownloadFileCompleted += new AsyncCompletedEventHandler(downloader_DownloadFileComplete);
  88. downloader.DownloadFileAsync(new Uri(post.MP1Url), templocation + mp1 + ".zip");
  89. label4.Text = "Downloading " + mp1 + "....";
  90.  
  91. }
  92. }
  93. else
  94. {
  95. label4.Text = "Starting" + mp1 + "....";
  96. bool authed = false;
  97. string[] res = Auth(username.Text, password.Text, out AuthReasons Reason);
  98. if (authed)
  99. {
  100. Console.WriteLine("starting");
  101. Console.WriteLine(findJavaVersion());
  102.  
  103. StartMinecraft();
  104. Application.Exit();
  105. }
  106. }
  107. }
  108. else if (!checkBox1.Checked && checkBox2.Checked && !checkBox3.Checked)
  109. {
  110. button1.Enabled = false;
  111. checkBox1.Enabled = false;
  112. checkBox2.Enabled = false;
  113. checkBox3.Enabled = false;
  114. var client = new WebClient();
  115. var text = client.DownloadString("https://wad0.000webhostapp.com/uploads/test.json");
  116.  
  117. SCJSON2 post = JsonConvert.DeserializeObject<SCJSON2>(text);
  118. string mp2 = post.MP2Name;
  119.  
  120. if (Directory.Exists(packlocation + mp2) == false)
  121. {
  122. using (var webClient = new WebClient())
  123. {
  124. String rawJSON2 = webClient.DownloadString(post.MP2Url);
  125. WebClient downloader = new WebClient();
  126. Console.WriteLine("Downloading from " + rawJSON2);
  127. this.Update();
  128. downloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloader_DownloadProgressChanged);
  129. downloader.DownloadFileCompleted += new AsyncCompletedEventHandler(downloader_DownloadFileComplete);
  130. downloader.DownloadFileAsync(new Uri(rawJSON2), templocation + mp2 + ".zip");
  131. label4.Text = "Downloading " + mp2 + "....";
  132. }
  133. }
  134. else
  135. {
  136. label4.Text = "Starting" + mp2 + "....";
  137. string[] res = Auth(username.Text, password.Text, out AuthReasons Reason);
  138. {
  139. Console.WriteLine("starting");
  140. Application.Exit();
  141. }
  142. }
  143. }
  144. else if (!checkBox1.Checked && !checkBox2.Checked && checkBox3.Checked)
  145. {
  146. button1.Enabled = false;
  147. checkBox1.Enabled = false;
  148. checkBox2.Enabled = false;
  149. checkBox3.Enabled = false;
  150. var client = new WebClient();
  151. var text = client.DownloadString("https://wad0.000webhostapp.com/uploads/test.json");
  152.  
  153. SCJSON3 post = JsonConvert.DeserializeObject<SCJSON3>(text);
  154. string mp3 = post.MP3Name;
  155.  
  156.  
  157. if (Directory.Exists(packlocation + mp3) == false)
  158. {
  159. using (var webClient = new WebClient())
  160. {
  161. String rawJSON3 = webClient.DownloadString(post.MP3Url);
  162. WebClient downloader = new WebClient();
  163. Console.WriteLine("Downloading from " + rawJSON3);
  164. this.Update();
  165. downloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloader_DownloadProgressChanged);
  166. downloader.DownloadFileCompleted += new AsyncCompletedEventHandler(downloader_DownloadFileComplete);
  167. downloader.DownloadFileAsync(new Uri(rawJSON3), templocation + mp3 + ".zip");
  168. label4.Text = "Downloading " + mp3 + "....";
  169. }
  170. }
  171. else
  172. {
  173. label4.Text = "Starting" + mp3 + "....";
  174. bool AuthReasons = false;
  175. string[] res = Auth(username.Text, password.Text, out AuthReasons Reason);
  176. if (AuthReasons == true)
  177. {
  178. Console.WriteLine("starting");
  179.  
  180. Application.Exit();
  181. }
  182. }
  183. }
  184. }
  185.  
  186. void downloader_DownloadFileComplete(object sender, AsyncCompletedEventArgs e)
  187. {
  188. string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
  189. string templocation = appdata + "/WiAD_Launcher/temp/";
  190. string packlocation = appdata + "/WiAD_Launcher/modpacks/";
  191. if (e.Error == null)
  192. {
  193. if (checkBox1.Checked)
  194. {
  195. var client = new WebClient();
  196. var text = client.DownloadString("https://wad0.000webhostapp.com/uploads/test.json");
  197.  
  198. SCJSON1 post = JsonConvert.DeserializeObject<SCJSON1>(text);
  199. string mp1 = post.MP1Name;
  200. label4.Text = "Extracting....";
  201. Directory.CreateDirectory(packlocation + mp1);
  202. ZipFile.ExtractToDirectory(templocation + mp1 + ".zip", packlocation + mp1);
  203. Thread.Sleep(5000);
  204. progressBar1.Value = 0;
  205. Console.WriteLine("Deleting file from Temp folder");
  206. File.Delete(templocation + mp1 + ".zip");
  207. button1.Enabled = true;
  208. checkBox1.Enabled = true;
  209. checkBox2.Enabled = true;
  210. checkBox3.Enabled = true;
  211. label4.Text = "Ready to run " + mp1 + "....";
  212. }
  213. else if (checkBox2.Checked)
  214. {
  215. var client = new WebClient();
  216. var text = client.DownloadString("https://wad0.000webhostapp.com/uploads/test.json");
  217.  
  218. SCJSON2 post = JsonConvert.DeserializeObject<SCJSON2>(text);
  219. string mp2 = post.MP2Name;
  220. label4.Text = "Extracting....";
  221. Directory.CreateDirectory(packlocation + mp2);
  222. ZipFile.ExtractToDirectory(templocation + mp2 + ".zip", packlocation + mp2);
  223. Thread.Sleep(5000);
  224. progressBar1.Value = 0;
  225. Console.WriteLine("Deleting file from Temp folder");
  226. File.Delete(templocation + mp2 + ".zip");
  227. button1.Enabled = true;
  228. checkBox1.Enabled = true;
  229. checkBox2.Enabled = true;
  230. checkBox3.Enabled = true;
  231. label4.Text = "Ready to run " + mp2 + "....";
  232. }
  233. else if (checkBox3.Checked)
  234. {
  235. var client = new WebClient();
  236. var text = client.DownloadString("https://wad0.000webhostapp.com/uploads/test.json");
  237.  
  238. SCJSON3 post = JsonConvert.DeserializeObject<SCJSON3>(text);
  239. string mp3 = post.MP3Name;
  240. label4.Text = "Extracting....";
  241. Directory.CreateDirectory(packlocation + mp3);
  242. ZipFile.ExtractToDirectory(templocation + mp3 + ".zip", packlocation + mp3);
  243. Thread.Sleep(5000);
  244. progressBar1.Value = 0;
  245. Console.WriteLine("Deleting file from Temp folder");
  246. File.Delete(templocation + mp3 + ".zip");
  247. button1.Enabled = true;
  248. checkBox1.Enabled = true;
  249. checkBox2.Enabled = true;
  250. checkBox3.Enabled = true;
  251. label4.Text = "Ready to run " + mp3 + "....";
  252. }
  253. }
  254. else
  255. {
  256. MessageBox.Show(e.Error.Message);
  257. }
  258.  
  259. }
  260.  
  261. void downloader_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
  262. {
  263. progressBar1.Maximum = (int)e.TotalBytesToReceive / 100;
  264. progressBar1.Value = (int)e.BytesReceived / 100;
  265. }
  266.  
  267. private void btnExit_Click(object sender, EventArgs e)
  268. {
  269. Application.Exit();
  270. }
  271.  
  272. private void checkBox1_Click(object sender, EventArgs e)
  273. {
  274. checkBox2.Checked = false;
  275. checkBox3.Checked = false;
  276. var client = new WebClient();
  277. var text = client.DownloadString("https://wad0.000webhostapp.com/uploads/modpack1.json");
  278.  
  279. SCJSON1 post = JsonConvert.DeserializeObject<SCJSON1>(text);
  280. string mp1 = post.MP1Name;
  281. string mp1ow = post.MP1Creator;
  282.  
  283.  
  284. if (checkBox1.Checked)
  285. {
  286. label6.Text = mp1;
  287. label7.Text = mp1ow;
  288. string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
  289. string packlocation = appdata + "/WiAD_Launcher/modpacks/";
  290. label8.Text = packlocation + mp1 + "/";
  291.  
  292. }
  293. else if (!checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
  294. {
  295. label6.Text = "None selected";
  296. label7.Text = ".......";
  297. }
  298. }
  299. private void checkBox2_Click(object sender, EventArgs e)
  300. {
  301. checkBox1.Checked = false;
  302. checkBox3.Checked = false;
  303. var client = new WebClient();
  304. var text = client.DownloadString("https://wad0.000webhostapp.com/uploads/modpack2.json");
  305.  
  306. SCJSON2 post = JsonConvert.DeserializeObject<SCJSON2>(text);
  307. string mp2 = post.MP2Name;
  308. string mp2ow = post.MP2Creator;
  309.  
  310. if (checkBox2.Checked)
  311. {
  312. label6.Text = mp2;
  313. label7.Text = mp2ow;
  314. string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
  315. string packlocation = appdata + "/WiAD_Launcher/modpacks/";
  316. label8.Text = packlocation + mp2 + "/";
  317. }
  318. else if (!checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
  319. {
  320. label6.Text = "None selected";
  321. label7.Text = ".......";
  322. }
  323. }
  324. private void checkBox3_Click(object sender, EventArgs e)
  325. {
  326. checkBox1.Checked = false;
  327. checkBox2.Checked = false;
  328. var client = new WebClient();
  329. var text = client.DownloadString("https://wad0.000webhostapp.com/uploads/modpack3.json");
  330.  
  331. SCJSON3 post = JsonConvert.DeserializeObject<SCJSON3>(text);
  332. string mp3 = post.MP3Name;
  333. string mp3ow = post.MP3Creator;
  334.  
  335. if (checkBox3.Checked)
  336. {
  337. label6.Text = mp3;
  338. label7.Text = mp3ow;
  339. string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
  340. string packlocation = appdata + "/WiAD_Launcher/modpacks/";
  341. label8.Text = packlocation + mp3 + "/";
  342. }
  343. else if (!checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
  344. {
  345. label6.Text = "None selected";
  346. label7.Text = ".......";
  347. }
  348. }
  349. private string[] Auth(String Username, String Password, out AuthReasons Reason)
  350. {
  351. HttpClient HClient = new HttpClient();
  352. if (String.IsNullOrWhiteSpace(Username) || String.IsNullOrWhiteSpace(Password)) { Reason = AuthReasons.NoInfoProvided; return null; }
  353. string json = JsonConvert.SerializeObject(new { password = Password, username = Username });
  354. using (HttpRequestMessage reqmsg = new HttpRequestMessage())
  355. {
  356. reqmsg.RequestUri = new Uri("https://authserver.mojang.com/authenticate");
  357. reqmsg.Content = new StringContent(json, Encoding.UTF8, "application/json");
  358. reqmsg.Method = HttpMethod.Post;
  359. if ((HClient.SendAsync(reqmsg).GetAwaiter().GetResult()).IsSuccessStatusCode)
  360. {
  361. Reason = AuthReasons.LoginSuccess;
  362. Console.WriteLine("succesful");
  363. StartMinecraft();
  364. return json.Split(new char[] { ':' });
  365. }
  366. else
  367. {
  368. Reason = AuthReasons.InvalidAuth;
  369. Console.WriteLine("invalid");
  370. return null;
  371. }
  372. }
  373. }
  374. public enum AuthReasons
  375. {
  376. LoginSuccess = 1,
  377. NoInfoProvided = 2,
  378. InvalidAuth = 3,
  379. }
  380.  
  381.  
  382. private void Options_Click(object sender, EventArgs e)
  383. {
  384. if (Directory.Exists(label8.Text) == false)
  385. label8.Text = "Modpack not installed!";
  386. string m = label8.Text;
  387. string mpS = label6.Text;
  388. string mpO = label7.Text;
  389.  
  390. Form2 f2 = new Form2(mpS, mpO, m);
  391. f2.Show();
  392. }
  393.  
  394. private string findJavaVersion()
  395. {
  396. try
  397. {
  398. ProcessStartInfo psi = new ProcessStartInfo();
  399. psi.FileName = "java.exe";
  400. psi.Arguments = " -version";
  401. psi.RedirectStandardError = true;
  402. psi.UseShellExecute = false;
  403.  
  404. Process pr = Process.Start(psi);
  405. string strOutput = pr.StandardError.ReadLine().Split(' ')[2].Replace("\"", "");
  406.  
  407. Console.WriteLine(strOutput);
  408. string filePath = strOutput + "/bin/Javaw.exe";
  409. return filePath;
  410. }
  411. catch (Exception ex)
  412. {
  413. Console.WriteLine("Exception is " + ex.Message);
  414. return null;
  415. }
  416. }
  417. private void StartMinecraft()
  418. {
  419. string filePath = findJavaVersion();
  420. string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
  421. string packlocation = appdata + "/WiAD_Launcher/modpacks/";
  422.  
  423. var client = new WebClient();
  424. var text = client.DownloadString("https://wad0.000webhostapp.com/uploads/modpack1.json");
  425. SCJSON1 post = JsonConvert.DeserializeObject<SCJSON1>(text);
  426. string mp1 = post.MP1Name;
  427.  
  428. Process process = new Process();
  429. ProcessStartInfo info = new ProcessStartInfo();
  430. string dir = packlocation + mp1 + "/bin/";
  431. info.FileName = filePath;
  432. info.CreateNoWindow = true;
  433. info.Arguments = "-cp \"" + dir + "minecraft.jar;" + dir + "lwjgl.jar;" + dir + "lwjgl_util.jar;" + dir + "jinput.jar;\" ";
  434. info.Arguments += "\"-Djava.library.path=" + dir + "natives\" -Xmx1024M -Xms512M net.minecraft.client.Minecraft " + username + " " + password;
  435. process.StartInfo = info;
  436. process.Start();
  437.  
  438.  
  439. Console.WriteLine("process");
  440. }
  441. private void process_Exited(object sender, EventArgs e)
  442. {
  443. button1.Enabled = true;
  444. checkBox1.Enabled = true;
  445. checkBox2.Enabled = true;
  446. checkBox3.Enabled = true;
  447. }
  448. private string CheckOS()
  449. {
  450. switch (Environment.OSVersion.Platform)
  451. {
  452. case PlatformID.Unix:
  453. return (Directory.Exists("/Applications") & Directory.Exists("/System") & Directory.Exists("/Users") & Directory.Exists("/Volumes")) ? "osx" : "linux";
  454. case PlatformID.MacOSX:
  455. return "osx";
  456. default:
  457. return "windows";
  458. }
  459. }
  460.  
  461. public class SCJSON1
  462. {
  463. public string MP1Name { get; set; }
  464. public string MP1Url { get; set; }
  465. public string MP1Creator { get; set; }
  466. public string MP1Latest { get; set; }
  467. }
  468. public class SCJSON2
  469. {
  470. public string MP2Name { get; set; }
  471. public string MP2Url { get; set; }
  472. public string MP2Creator { get; set; }
  473. public string MP2Latest { get; set; }
  474. }
  475. public class SCJSON3
  476. {
  477. public string MP3Name { get; set; }
  478. public string MP3Url { get; set; }
  479. public string MP3Creator { get; set; }
  480. public string MP3Latest { get; set; }
  481. }
  482. }
  483. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement