private void DownloadComplete(object sender, DownloadStringCompletedEventArgs e) { if (e.Error != null) { MessageBox.Show("Error downloading version information. Check your " + "internet connection and make sure the installer is allowed to " + "access the internet."); Application.Exit(); } var versions = new List <ModLoaderVersion>(); try { var releases = JSON.Parse(e.Result); for (int i = 0; i < releases.AsArray.Count; i++) { var version = new ModLoaderVersion(); version.Name = releases[i]["tag_name"]; version.ID = releases[i]["id"]; string[] downloads = { releases[i]["assets"][0]["browser_download_url"], releases[i]["assets"][1]["browser_download_url"] }; if (downloads[0].Contains("Developer")) { version.DeveloperDownload = downloads[0]; version.NormalDownload = downloads[1]; } else { version.DeveloperDownload = downloads[1]; version.NormalDownload = downloads[0]; } versions.Add(version); } } catch (Exception) { MessageBox.Show("Error parsing version information. Exiting."); Application.Exit(); } var form = new FormInstaller(); form.SetVersionList(versions); form.Show(); Close(); }
private void DownloadComplete(object sender, DownloadStringCompletedEventArgs e) { if (e.Error != null) { MessageBox.Show("Error downloading version information. Check your " + "internet connection and make sure the installer is allowed to " + "access the internet."); Application.Exit(); } var versions = new List<ModLoaderVersion>(); try { var releases = JSON.Parse(e.Result); for (int i = 0; i < releases.AsArray.Count; i++) { var version = new ModLoaderVersion(); version.Name = releases[i]["tag_name"]; version.ID = releases[i]["id"]; string[] downloads = { releases[i]["assets"][0]["browser_download_url"], releases[i]["assets"][1]["browser_download_url"] }; if (downloads[0].Contains("Developer")) { version.DeveloperDownload = downloads[0]; version.NormalDownload = downloads[1]; } else { version.DeveloperDownload = downloads[1]; version.NormalDownload = downloads[0]; } versions.Add(version); } } catch (Exception) { MessageBox.Show("Error parsing version information. Exiting."); Application.Exit(); } var form = new FormInstaller(); form.SetVersionList(versions); form.Show(); Close(); }
public static void InstallModLoader(string besiegeLocation, ModLoaderVersion version, bool developer) { UninstallModLoader(besiegeLocation); var besiegeDir = new DirectoryInfo(besiegeLocation); besiegeDir.CreateSubdirectory("Installer"); // Download and extract ZIP archive string url = developer ? version.DeveloperDownload : version.NormalDownload; string zipFile = besiegeDir.FullName + "/Installer/modloader-" + version.Name + ".zip"; string extractDir = besiegeDir.FullName + "/Installer/extracted"; var client = new WebClient(); client.Headers["user-agent"] = "Mozilla / 5.0(Windows NT 6.1; WOW64; rv: 40.0) Gecko / 20100101 Firefox / 40.1"; client.DownloadFile(new Uri(url), zipFile); if (Directory.Exists(extractDir)) { Directory.Delete(extractDir, true); } ZipFile.ExtractToDirectory(zipFile, extractDir); // Replace Assembly-UnityScript.dll, keeping the original around File.Move(besiegeDir + "/Besiege_Data/Managed/Assembly-UnityScript.dll", besiegeDir + "/Besiege_Data/Managed/Assembly-UnityScript.dll.original"); File.Copy(extractDir + "/Assembly-UnityScript.dll", besiegeDir + "/Besiege_Data/Managed/Assembly-UnityScript.dll"); // Create Mods directory and copy SpaarModLoader.dll Directory.CreateDirectory(besiegeDir + "/Besiege_Data/Mods/"); File.Copy(extractDir + "/SpaarModLoader.dll", besiegeDir + "/Besiege_Data/Mods/SpaarModLoader.dll"); if (Directory.Exists(extractDir + "/Resources/")) { Directory.CreateDirectory( besiegeDir + "/Besiege_Data/Mods/Resources/ModLoader/"); Directory.Delete( besiegeDir + "/Besiege_Data/Mods/Resources/ModLoader/", true); CopyFilesRecursively( new DirectoryInfo(extractDir + "/Resources/"), new DirectoryInfo(besiegeDir + "/Besiege_Data/Mods/Resources/")); } }
static void Main() { // The installer can be launched without GUI by directly specifying all necessary arguments. // This is mostly used by the installer itself to attempt an install with elevated privileges. var args = Environment.GetCommandLineArgs(); if (args.Length != 1) { for (int i = 0; i < args.Length; i++) { args[i] = args[i].Replace("'", ""); } var path = args[1]; var version = new ModLoaderVersion(); version.Name = args[2]; version.NormalDownload = args[3]; version.DeveloperDownload = args[3]; var dev = bool.Parse(args[4]); try { Installer.InstallModLoader(path, version, dev); } catch (Exception ex) when(ex is SecurityException || ex is UnauthorizedAccessException) { Environment.Exit(-2); } catch (Exception) { Environment.Exit(-3); } Environment.Exit(0); } else { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var form = new FormLoadingScreen(); form.Show(); Application.Run(); } }