public bool downloadMod(LocalMod mod, String location) { Console.WriteLine(mod.source.url + "download/mod/" + mod.id); WebClientTimeOut wc = new WebClientTimeOut(); try { wc.DownloadFile(new Uri(mod.source.url + "download/mod/" + mod.id), location); } catch (WebException) { return(false); } // now check whether the downloaded file is actually a mod, and not an error String[] keys = wc.ResponseHeaders.AllKeys; String contentType = ""; for (int i = 0; i < keys.Length; i++) { if (keys[i].Equals("Content-Type")) { contentType = wc.ResponseHeaders.Get(i); } } if (contentType.Equals("application/x-msdos-program")) // success { return(true); } else // for example "application/json" or none at all, error { return(false); } }
public void PatchScrollsWindows() { String URL; if (Platform.getOS() == Platform.OS.Win) { URL = "http://download.scrolls.com/client/windows.zip"; } else { URL = "http://download.scrolls.com/client/mac.zip"; } String gameFolder = Path.GetFullPath(Directory.GetParent(Platform.getGlobalScrollsInstallPath()).Parent.Parent.Parent.FullName) + Path.DirectorySeparatorChar; //wait WebClientTimeOut webClient = new WebClientTimeOut(); if (File.Exists(gameFolder + "game.zip")) { File.Delete(gameFolder + "game.zip"); } try { webClient.DownloadFile(URL, gameFolder + "game.zip"); } catch (WebException) { App.Popups.KillCurrentPopup(); App.Popups.ShowOk(null, "info", "Error", "And error occured while downloading the update.", "OK"); return; } //backup assembly String backupPath = gameFolder + "ScrollsModLoader.dll"; if (File.Exists(backupPath)) { File.Delete(backupPath); } File.Copy(Platform.getGlobalScrollsInstallPath() + "ScrollsModLoader.dll", backupPath); //backup modloader folder String modBackupPath = gameFolder + "ModLoader" + Path.DirectorySeparatorChar; if (Directory.Exists(modBackupPath)) { Extensions.DeleteDirectory(modBackupPath); } Directory.Move(Platform.getGlobalScrollsInstallPath() + "ModLoader", modBackupPath); File.Delete(modBackupPath + "mods.ini"); File.Delete(modBackupPath + "Assembly-CSharp.dll"); if (Platform.getOS() == Platform.OS.Win) { Extensions.DeleteDirectory(gameFolder + "game"); } else { Extensions.DeleteDirectory(gameFolder + "MacScrolls.app"); } //extract ZipFile zip = ZipFile.Read(gameFolder + "game.zip"); foreach (ZipEntry e in zip) { e.Extract(gameFolder + "game"); } //move assembly File.Copy(backupPath, Platform.getGlobalScrollsInstallPath() + "ScrollsModLoader.dll"); // File.Delete(backupPath); //move modloader folder back Directory.Move(modBackupPath, Platform.getGlobalScrollsInstallPath() + "ModLoader"); //make new repatch backup File.Copy(Platform.getGlobalScrollsInstallPath() + "Assembly-CSharp.dll", Platform.getGlobalScrollsInstallPath() + "ModLoader" + Path.DirectorySeparatorChar + "Assembly-CSharp.dll"); //make sure mods get hooks set with new version File.Delete(Platform.getGlobalScrollsInstallPath() + "ModLoader" + Path.DirectorySeparatorChar + "mods.ini"); ScrollsFilter.clearHooks(); Console.WriteLine("Cleared Hooks"); //repatch Patcher patcher = new Patcher(); if (!patcher.patchAssembly(Platform.getGlobalScrollsInstallPath())) { if (!patcher.safeModePatchAssembly()) { Dialogs.showNotification("Summoner patch failed", "Summoner failed in patch itself into the updated files. It will uninstall itself. For more informations visit scrollsguide.com/summoner"); File.Delete(Platform.getGlobalScrollsInstallPath() + "ScrollsModLoader.dll"); Extensions.DeleteDirectory(Platform.getGlobalScrollsInstallPath() + "ModLoader"); } } Console.WriteLine("Now restarting the game..."); //restart the game Platform.RestartGame(); }
public void PatchScrollsMac() { String URL; if (Platform.getOS () == Platform.OS.Win) { URL = "http://download.scrolls.com/client/windows.zip"; } else { URL = "http://download.scrolls.com/client/mac.zip"; } String gameFolder = Path.GetFullPath(Directory.GetParent(Platform.getGlobalScrollsInstallPath()).Parent.Parent.Parent.Parent.FullName)+ Path.DirectorySeparatorChar; String modLoaderPath = Platform.getModLoaderPath (); String globalScrollsInstallPath = Platform.getGlobalScrollsInstallPath (); //wait WebClientTimeOut webClient = new WebClientTimeOut(); if (File.Exists (gameFolder + "game.zip")) { File.Delete (gameFolder + "game.zip"); } try { webClient.DownloadFile(URL, gameFolder + "game.zip"); } catch (WebException) { App.Popups.KillCurrentPopup(); App.Popups.ShowOk (null, "info", "Error", "And error occured while downloading the update.", "OK"); return; } //backup assembly String backupPath = gameFolder + "ScrollsModLoader.dll"; if (File.Exists(backupPath)){ File.Delete (backupPath); } File.Copy (globalScrollsInstallPath + "ScrollsModLoader.dll", backupPath); //backup modloader folder String modBackupPath = modLoaderPath+ Path.DirectorySeparatorChar; if (Directory.Exists (modBackupPath)){ Extensions.DeleteDirectory (modBackupPath); } Directory.Move (modLoaderPath , modBackupPath); File.Delete (modBackupPath + "mods.ini"); File.Delete (modBackupPath + "Assembly-CSharp.dll"); if (Platform.getOS () == Platform.OS.Win) { Extensions.DeleteDirectory (gameFolder + "game" + Path.DirectorySeparatorChar + "Scrolls_Data"); File.Delete (gameFolder + "game" + Path.DirectorySeparatorChar + "Scrolls.exe"); } else { Extensions.DeleteDirectory (gameFolder + "MacScrolls.app"); } //extract String zipLocation = gameFolder + "game.zip"; if (Platform.getOS() == Platform.OS.Win){ String newZipLocation = gameFolder + "game" + Path.DirectorySeparatorChar + "game.zip"; File.Move(zipLocation, newZipLocation); zipLocation = newZipLocation; } ZipFile zip = ZipFile.Read(zipLocation); foreach (ZipEntry e in zip) { e.Extract(); } //move assembly File.Copy (backupPath, globalScrollsInstallPath + "ScrollsModLoader.dll"); File.Delete (backupPath); //move modloader folder back Directory.Move (modBackupPath, modLoaderPath); //make new repatch backup File.Copy (globalScrollsInstallPath + "Assembly-CSharp.dll", modLoaderPath + Path.DirectorySeparatorChar + "Assembly-CSharp.dll"); //make sure mods get hooks set with new version File.Delete (modLoaderPath + Path.DirectorySeparatorChar + "mods.ini"); ScrollsFilter.clearHooks (); //repatch Patcher patcher = new Patcher (); if (!patcher.patchAssembly (globalScrollsInstallPath)) { if (!patcher.safeModePatchAssembly ()) { Dialogs.showNotification ("Summoner patch failed", "Summoner failed in patch itself into the updated files. It will uninstall itself. For more informations visit scrollsguide.com/summoner"); File.Delete (globalScrollsInstallPath + "ScrollsModLoader.dll"); Extensions.DeleteDirectory (modLoaderPath); } } //restart the game Platform.RestartGame (); }
public bool downloadMod(LocalMod mod, String location) { Console.WriteLine (mod.source.url + "download/mod/" + mod.id); WebClientTimeOut wc = new WebClientTimeOut(); try { wc.DownloadFile (new Uri(mod.source.url + "download/mod/" + mod.id), location); } catch (WebException) { return false; } // now check whether the downloaded file is actually a mod, and not an error String[] keys = wc.ResponseHeaders.AllKeys; String contentType = ""; for (int i = 0; i < keys.Length; i++) { if (keys[i].Equals("Content-Type")) { contentType = wc.ResponseHeaders.Get(i); } } if (contentType.Equals("application/x-msdos-program")) // success { return true; } else { // from github its an text/plain file if (mod.source.url.StartsWith ("https://raw.github.com/") && (contentType.Equals("text/plain") || contentType.Equals("application/octet-stream"))) { return true; } else // for example "application/json" or none at all, error { return false; } } }