Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Forms;
- using System.IO;
- using System.IO.Compression;
- using System.Net;
- using System.Diagnostics;
- 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.Threading;
- using System.Net.Http;
- using System.Web;
- using Newtonsoft.Json;
- namespace WindowsFormsApp2
- {
- public partial class Form1 : Form
- {
- private Process process;
- public Form1()
- {
- InitializeComponent();
- string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
- if (Directory.Exists(appdata + "/WiAD_Launcher/") == false)
- {
- Directory.CreateDirectory(appdata + "/WiAD_Launcher/");
- }
- if (Directory.Exists(appdata + "/WiAD_Launcher/temp/") == false)
- {
- Directory.CreateDirectory(appdata + "/WiAD_Launcher/temp/");
- }
- if (Directory.Exists(appdata + "/WiAD_Launcher/modpacks/") == false)
- {
- Directory.CreateDirectory(appdata + "/WiAD_Launcher/modpacks/");
- }
- button1.Enabled = false;
- }
- private void password_TextChanged(object sender, EventArgs e)
- {
- string contents = this.username.Text + this.password.Text;
- if (contents.Length == 0)
- {
- Console.WriteLine("Please login in!");
- }
- else
- {
- button1.Enabled = true;
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
- string templocation = appdata + "/WiAD_Launcher/temp/";
- string packlocation = appdata + "/WiAD_Launcher/modpacks/";
- if (checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
- {
- button1.Enabled = false;
- checkBox1.Enabled = false;
- checkBox2.Enabled = false;
- checkBox3.Enabled = false;
- var client = new WebClient();
- var text = client.DownloadString("https://wad0.000webhostapp.com/uploads/test.json");
- SCJSON1 post = JsonConvert.DeserializeObject<SCJSON1>(text);
- string mp1 = post.MP1Name;
- if (Directory.Exists(packlocation + mp1) == false)
- {
- using (var webClient = new WebClient())
- {
- WebClient downloader = new WebClient();
- Console.WriteLine("Downloading from " + post.MP1Url);
- this.Update();
- downloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloader_DownloadProgressChanged);
- downloader.DownloadFileCompleted += new AsyncCompletedEventHandler(downloader_DownloadFileComplete);
- downloader.DownloadFileAsync(new Uri(post.MP1Url), templocation + mp1 + ".zip");
- label4.Text = "Downloading " + mp1 + "....";
- }
- }
- else
- {
- label4.Text = "Starting" + mp1 + "....";
- bool authed = false;
- string[] res = Auth(username.Text, password.Text, out AuthReasons Reason);
- if (authed)
- {
- Console.WriteLine("starting");
- Console.WriteLine(findJavaVersion());
- StartMinecraft();
- Application.Exit();
- }
- }
- }
- else if (!checkBox1.Checked && checkBox2.Checked && !checkBox3.Checked)
- {
- button1.Enabled = false;
- checkBox1.Enabled = false;
- checkBox2.Enabled = false;
- checkBox3.Enabled = false;
- var client = new WebClient();
- var text = client.DownloadString("https://wad0.000webhostapp.com/uploads/test.json");
- SCJSON2 post = JsonConvert.DeserializeObject<SCJSON2>(text);
- string mp2 = post.MP2Name;
- if (Directory.Exists(packlocation + mp2) == false)
- {
- using (var webClient = new WebClient())
- {
- String rawJSON2 = webClient.DownloadString(post.MP2Url);
- WebClient downloader = new WebClient();
- Console.WriteLine("Downloading from " + rawJSON2);
- this.Update();
- downloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloader_DownloadProgressChanged);
- downloader.DownloadFileCompleted += new AsyncCompletedEventHandler(downloader_DownloadFileComplete);
- downloader.DownloadFileAsync(new Uri(rawJSON2), templocation + mp2 + ".zip");
- label4.Text = "Downloading " + mp2 + "....";
- }
- }
- else
- {
- label4.Text = "Starting" + mp2 + "....";
- string[] res = Auth(username.Text, password.Text, out AuthReasons Reason);
- {
- Console.WriteLine("starting");
- Application.Exit();
- }
- }
- }
- else if (!checkBox1.Checked && !checkBox2.Checked && checkBox3.Checked)
- {
- button1.Enabled = false;
- checkBox1.Enabled = false;
- checkBox2.Enabled = false;
- checkBox3.Enabled = false;
- var client = new WebClient();
- var text = client.DownloadString("https://wad0.000webhostapp.com/uploads/test.json");
- SCJSON3 post = JsonConvert.DeserializeObject<SCJSON3>(text);
- string mp3 = post.MP3Name;
- if (Directory.Exists(packlocation + mp3) == false)
- {
- using (var webClient = new WebClient())
- {
- String rawJSON3 = webClient.DownloadString(post.MP3Url);
- WebClient downloader = new WebClient();
- Console.WriteLine("Downloading from " + rawJSON3);
- this.Update();
- downloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloader_DownloadProgressChanged);
- downloader.DownloadFileCompleted += new AsyncCompletedEventHandler(downloader_DownloadFileComplete);
- downloader.DownloadFileAsync(new Uri(rawJSON3), templocation + mp3 + ".zip");
- label4.Text = "Downloading " + mp3 + "....";
- }
- }
- else
- {
- label4.Text = "Starting" + mp3 + "....";
- bool AuthReasons = false;
- string[] res = Auth(username.Text, password.Text, out AuthReasons Reason);
- if (AuthReasons == true)
- {
- Console.WriteLine("starting");
- Application.Exit();
- }
- }
- }
- }
- void downloader_DownloadFileComplete(object sender, AsyncCompletedEventArgs e)
- {
- string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
- string templocation = appdata + "/WiAD_Launcher/temp/";
- string packlocation = appdata + "/WiAD_Launcher/modpacks/";
- if (e.Error == null)
- {
- if (checkBox1.Checked)
- {
- var client = new WebClient();
- var text = client.DownloadString("https://wad0.000webhostapp.com/uploads/test.json");
- SCJSON1 post = JsonConvert.DeserializeObject<SCJSON1>(text);
- string mp1 = post.MP1Name;
- label4.Text = "Extracting....";
- Directory.CreateDirectory(packlocation + mp1);
- ZipFile.ExtractToDirectory(templocation + mp1 + ".zip", packlocation + mp1);
- Thread.Sleep(5000);
- progressBar1.Value = 0;
- Console.WriteLine("Deleting file from Temp folder");
- File.Delete(templocation + mp1 + ".zip");
- button1.Enabled = true;
- checkBox1.Enabled = true;
- checkBox2.Enabled = true;
- checkBox3.Enabled = true;
- label4.Text = "Ready to run " + mp1 + "....";
- }
- else if (checkBox2.Checked)
- {
- var client = new WebClient();
- var text = client.DownloadString("https://wad0.000webhostapp.com/uploads/test.json");
- SCJSON2 post = JsonConvert.DeserializeObject<SCJSON2>(text);
- string mp2 = post.MP2Name;
- label4.Text = "Extracting....";
- Directory.CreateDirectory(packlocation + mp2);
- ZipFile.ExtractToDirectory(templocation + mp2 + ".zip", packlocation + mp2);
- Thread.Sleep(5000);
- progressBar1.Value = 0;
- Console.WriteLine("Deleting file from Temp folder");
- File.Delete(templocation + mp2 + ".zip");
- button1.Enabled = true;
- checkBox1.Enabled = true;
- checkBox2.Enabled = true;
- checkBox3.Enabled = true;
- label4.Text = "Ready to run " + mp2 + "....";
- }
- else if (checkBox3.Checked)
- {
- var client = new WebClient();
- var text = client.DownloadString("https://wad0.000webhostapp.com/uploads/test.json");
- SCJSON3 post = JsonConvert.DeserializeObject<SCJSON3>(text);
- string mp3 = post.MP3Name;
- label4.Text = "Extracting....";
- Directory.CreateDirectory(packlocation + mp3);
- ZipFile.ExtractToDirectory(templocation + mp3 + ".zip", packlocation + mp3);
- Thread.Sleep(5000);
- progressBar1.Value = 0;
- Console.WriteLine("Deleting file from Temp folder");
- File.Delete(templocation + mp3 + ".zip");
- button1.Enabled = true;
- checkBox1.Enabled = true;
- checkBox2.Enabled = true;
- checkBox3.Enabled = true;
- label4.Text = "Ready to run " + mp3 + "....";
- }
- }
- else
- {
- MessageBox.Show(e.Error.Message);
- }
- }
- void downloader_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
- {
- progressBar1.Maximum = (int)e.TotalBytesToReceive / 100;
- progressBar1.Value = (int)e.BytesReceived / 100;
- }
- private void btnExit_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void checkBox1_Click(object sender, EventArgs e)
- {
- checkBox2.Checked = false;
- checkBox3.Checked = false;
- var client = new WebClient();
- var text = client.DownloadString("https://wad0.000webhostapp.com/uploads/modpack1.json");
- SCJSON1 post = JsonConvert.DeserializeObject<SCJSON1>(text);
- string mp1 = post.MP1Name;
- string mp1ow = post.MP1Creator;
- if (checkBox1.Checked)
- {
- label6.Text = mp1;
- label7.Text = mp1ow;
- string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
- string packlocation = appdata + "/WiAD_Launcher/modpacks/";
- label8.Text = packlocation + mp1 + "/";
- }
- else if (!checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
- {
- label6.Text = "None selected";
- label7.Text = ".......";
- }
- }
- private void checkBox2_Click(object sender, EventArgs e)
- {
- checkBox1.Checked = false;
- checkBox3.Checked = false;
- var client = new WebClient();
- var text = client.DownloadString("https://wad0.000webhostapp.com/uploads/modpack2.json");
- SCJSON2 post = JsonConvert.DeserializeObject<SCJSON2>(text);
- string mp2 = post.MP2Name;
- string mp2ow = post.MP2Creator;
- if (checkBox2.Checked)
- {
- label6.Text = mp2;
- label7.Text = mp2ow;
- string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
- string packlocation = appdata + "/WiAD_Launcher/modpacks/";
- label8.Text = packlocation + mp2 + "/";
- }
- else if (!checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
- {
- label6.Text = "None selected";
- label7.Text = ".......";
- }
- }
- private void checkBox3_Click(object sender, EventArgs e)
- {
- checkBox1.Checked = false;
- checkBox2.Checked = false;
- var client = new WebClient();
- var text = client.DownloadString("https://wad0.000webhostapp.com/uploads/modpack3.json");
- SCJSON3 post = JsonConvert.DeserializeObject<SCJSON3>(text);
- string mp3 = post.MP3Name;
- string mp3ow = post.MP3Creator;
- if (checkBox3.Checked)
- {
- label6.Text = mp3;
- label7.Text = mp3ow;
- string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
- string packlocation = appdata + "/WiAD_Launcher/modpacks/";
- label8.Text = packlocation + mp3 + "/";
- }
- else if (!checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
- {
- label6.Text = "None selected";
- label7.Text = ".......";
- }
- }
- private string[] Auth(String Username, String Password, out AuthReasons Reason)
- {
- HttpClient HClient = new HttpClient();
- if (String.IsNullOrWhiteSpace(Username) || String.IsNullOrWhiteSpace(Password)) { Reason = AuthReasons.NoInfoProvided; return null; }
- string json = JsonConvert.SerializeObject(new { password = Password, username = Username });
- using (HttpRequestMessage reqmsg = new HttpRequestMessage())
- {
- reqmsg.RequestUri = new Uri("https://authserver.mojang.com/authenticate");
- reqmsg.Content = new StringContent(json, Encoding.UTF8, "application/json");
- reqmsg.Method = HttpMethod.Post;
- if ((HClient.SendAsync(reqmsg).GetAwaiter().GetResult()).IsSuccessStatusCode)
- {
- Reason = AuthReasons.LoginSuccess;
- Console.WriteLine("succesful");
- StartMinecraft();
- return json.Split(new char[] { ':' });
- }
- else
- {
- Reason = AuthReasons.InvalidAuth;
- Console.WriteLine("invalid");
- return null;
- }
- }
- }
- public enum AuthReasons
- {
- LoginSuccess = 1,
- NoInfoProvided = 2,
- InvalidAuth = 3,
- }
- private void Options_Click(object sender, EventArgs e)
- {
- if (Directory.Exists(label8.Text) == false)
- label8.Text = "Modpack not installed!";
- string m = label8.Text;
- string mpS = label6.Text;
- string mpO = label7.Text;
- Form2 f2 = new Form2(mpS, mpO, m);
- f2.Show();
- }
- private string findJavaVersion()
- {
- try
- {
- ProcessStartInfo psi = new ProcessStartInfo();
- psi.FileName = "java.exe";
- psi.Arguments = " -version";
- psi.RedirectStandardError = true;
- psi.UseShellExecute = false;
- Process pr = Process.Start(psi);
- string strOutput = pr.StandardError.ReadLine().Split(' ')[2].Replace("\"", "");
- Console.WriteLine(strOutput);
- string filePath = strOutput + "/bin/Javaw.exe";
- return filePath;
- }
- catch (Exception ex)
- {
- Console.WriteLine("Exception is " + ex.Message);
- return null;
- }
- }
- private void StartMinecraft()
- {
- string filePath = findJavaVersion();
- string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
- string packlocation = appdata + "/WiAD_Launcher/modpacks/";
- var client = new WebClient();
- var text = client.DownloadString("https://wad0.000webhostapp.com/uploads/modpack1.json");
- SCJSON1 post = JsonConvert.DeserializeObject<SCJSON1>(text);
- string mp1 = post.MP1Name;
- Process process = new Process();
- ProcessStartInfo info = new ProcessStartInfo();
- string dir = packlocation + mp1 + "/bin/";
- info.FileName = filePath;
- info.CreateNoWindow = true;
- info.Arguments = "-cp \"" + dir + "minecraft.jar;" + dir + "lwjgl.jar;" + dir + "lwjgl_util.jar;" + dir + "jinput.jar;\" ";
- info.Arguments += "\"-Djava.library.path=" + dir + "natives\" -Xmx1024M -Xms512M net.minecraft.client.Minecraft " + username + " " + password;
- process.StartInfo = info;
- process.Start();
- Console.WriteLine("process");
- }
- private void process_Exited(object sender, EventArgs e)
- {
- button1.Enabled = true;
- checkBox1.Enabled = true;
- checkBox2.Enabled = true;
- checkBox3.Enabled = true;
- }
- private string CheckOS()
- {
- switch (Environment.OSVersion.Platform)
- {
- case PlatformID.Unix:
- return (Directory.Exists("/Applications") & Directory.Exists("/System") & Directory.Exists("/Users") & Directory.Exists("/Volumes")) ? "osx" : "linux";
- case PlatformID.MacOSX:
- return "osx";
- default:
- return "windows";
- }
- }
- public class SCJSON1
- {
- public string MP1Name { get; set; }
- public string MP1Url { get; set; }
- public string MP1Creator { get; set; }
- public string MP1Latest { get; set; }
- }
- public class SCJSON2
- {
- public string MP2Name { get; set; }
- public string MP2Url { get; set; }
- public string MP2Creator { get; set; }
- public string MP2Latest { get; set; }
- }
- public class SCJSON3
- {
- public string MP3Name { get; set; }
- public string MP3Url { get; set; }
- public string MP3Creator { get; set; }
- public string MP3Latest { get; set; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement