public override void Download() { ServicePointManager.DefaultConnectionLimit = 1000; MCVersion.InstallLaunchWrapper(); var url = this.Url; var versionText = string.Format("{0}_{1}_{2}", this.MCVersion, this.Type, this.Patch); var jarname = "Optifine-" + versionText + ".jar"; var dirpath = "optifine\\Optifine\\" + versionText + "\\"; var downloadDirPath = LauncherMain.Instance.Settings.MinecraftFolderName + "libraries\\" + dirpath; if (!Directory.Exists(downloadDirPath)) { Directory.CreateDirectory(downloadDirPath); } var path = dirpath + jarname; var downloadPath = downloadDirPath + jarname; var manifest = MinecraftManifest.AnalyzeFromVersion(this.MCVersion); using (var wc = new WebClient()) { OnProgressChanged("开始下载。。", 0); wc.DownloadProgressChanged += (sender, args) => OnProgressChanged(null, (int)(args.ProgressPercentage * 0.8)); Task downloadTask = wc.DownloadFileTaskAsync(url, downloadPath); while (!downloadTask.IsCompleted) { Thread.Sleep(500); } } OnProgressChanged("正在添加依赖项。。。", 80); var library = new MinecraftLibrary(); library.name = dirpath.Substring(0, dirpath.Length - 1).Replace('\\', ':'); library.downloads = new LibraryDownloads(); library.downloads.artifact = new DownloadInfo(); library.downloads.artifact.path = path.Replace('\\', '/'); library.downloads.artifact.url = url; manifest.libraries.Add(library); if (manifest.minecraftArguments == null) { manifest.arguments.game.Add("--tweakClass"); manifest.arguments.game.Add("optifine.OptiFineTweaker"); } else { manifest.minecraftArguments += " --tweakClass optifine.OptiFineTweaker"; } OnProgressChanged(null, 100); MCVersion.SaveManifest(manifest); }
public MinecraftLaunchMaker(MinecraftVersion version, string PlayerName, ConsoleWindow LogWindow) { Version = version; this.LogWindow = LogWindow; this.PlayerName = PlayerName; manifest = MinecraftManifest.AnalyzeFromVersion(Version); GameDir = LauncherMain.Instance.Settings.MinecraftFolderName; AssetsRoot = GameDir + "assets\\"; AssetsRoot = AssetsRoot.Substring(AssetsRoot.IndexOf('\\') + 1); LibRoot = GameDir + "libraries\\"; UserType = "mojang"; var jrepath = LauncherMain.Instance.Settings.JREPath; if (jrepath.Last() != '\\') { jrepath += '\\'; } JavaExe = jrepath + "bin\\java.exe"; ClassPath = this.GenerateClassPath(); }
public override void Download() { ServicePointManager.DefaultConnectionLimit = 1000; var jsonURL = this.Url; var id = this.Id; var MCVersion = new MinecraftVersion(id); Directory.CreateDirectory(MCVersion.VersionDirectory); MinecraftManifest info; // Solve json and download jar using (WebClient wc = new WebClient()) { wc.Proxy = null; wc.DownloadFile(jsonURL, MCVersion.VersionManifestPath); info = MinecraftManifest.AnalyzeFromVersion(MCVersion); OnProgressChanged("已获取版本下载信息", 0); string jarloc = info.downloads.client.url; if (UseBMCLAPI) { jarloc = string.Format("https://bmclapi2.bangbang93.com/version/{0}/client", id); } var DownloadHasDone = false; OnProgressChanged(string.Format("正在从{0}下载{1}.jar", jarloc, id), 0); wc.DownloadProgressChanged += (sender, e) => OnProgressChanged(null, e.ProgressPercentage); wc.DownloadFileCompleted += (sender, e) => DownloadHasDone = true; wc.DownloadFileAsync(new Uri(jarloc), MCVersion.JarPath); while (!DownloadHasDone) { Thread.Sleep(500); } OnProgressChanged("minecraft.jar已下载", 0); } // Analyze libraries and download OnProgressChanged("开始分析需要下载的前置库和本地化前置", 0); DownloadLibraries(info, MCVersion); OnProgressChanged("开始下载资源文件", 0); DownloadAssets(info); LauncherMain.Instance.AddMinecraftVersion(MCVersion); }
public override void Download() { bool NeedBranchName = !NetUtils.IsUrlExists(Url); if (NeedBranchName) { Url = string.Format( "http://files.minecraftforge.net/maven/net/minecraftforge/forge/{0}-{1}-{0}/forge-{0}-{1}-{0}-universal.jar", MCVersion.VersionName, ForgeVersion ); } if (UseBMCL) { Url = Url.Replace("files.minecraftforge.net", "bmclapi2.bangbang93.com"); } OnProgressChanged("正在检查launchwrapper安装情况并确保安装", 0); MCVersion.InstallLaunchWrapper(); string jarfile, folder; if (NeedBranchName) { jarfile = string.Format("forge-{0}-{1}-{0}.jar", this.MCVersion.VersionName, this.ForgeVersion); folder = string.Format("net/minecraftforge/forge/{0}-{1}-{0}/", this.MCVersion.VersionName, this.ForgeVersion); } else { jarfile = string.Format("forge-{0}-{1}.jar", this.MCVersion.VersionName, this.ForgeVersion); folder = string.Format("net/minecraftforge/forge/{0}-{1}/", this.MCVersion.VersionName, this.ForgeVersion); } var location = folder + jarfile; var realLocation = LauncherMain.Instance.Settings.MinecraftFolderName + "libraries\\" + location.Replace('/', '\\'); var realFolder = LauncherMain.Instance.Settings.MinecraftFolderName + "libraries\\" + folder.Replace('/', '\\'); if (!Directory.Exists(realFolder)) { Directory.CreateDirectory(realFolder); } using (var wc = new WebClient()) { OnProgressChanged("开始下载" + jarfile, 0); bool downloaded = false; wc.DownloadFileCompleted += (o, e) => { downloaded = true; wc.Dispose(); }; wc.DownloadProgressChanged += (o, e) => OnProgressChanged(null, e.ProgressPercentage); wc.DownloadFileAsync(new Uri(this.Url), realLocation); while (!downloaded) { Thread.Sleep(100); } } var zip = ZipFile.Open(realLocation, ZipArchiveMode.Read); var versionlistentry = zip.GetEntry("version.json"); var sr = new StreamReader(versionlistentry.Open()); var json = sr.ReadToEnd(); sr.Close(); zip.Dispose(); var matches = Regex.Matches(json, "\"name\"\\s*:\\s*\"(.*?)\""); var manifest = MinecraftManifest.AnalyzeFromVersion(MCVersion); int needDownload = 0; int downloadedCount = 0; foreach (Match match in matches) { var groups = EnumeratorUtils.MakeListFromEnumerator(match.Groups.GetEnumerator()); var libname = ((Group)groups[1]).Value; var names = new List <string>(libname.Split(':')); if (names[1] != "launchwrapper") { manifest.libraries.RemoveAll(m => { var ns = m.name.Split(':'); return(ns[1] == names[1]); }); var fnames = names[0].Split('.'); names.RemoveAt(0); names.InsertRange(0, fnames); string url; if (this.UseBMCL) { url = "http://bmclapi2.bangbang93.com/maven/"; } else { if (Regex.IsMatch( json, string.Format( "\"name\"\\s*:\\s*\"{0}\"\\n" + "\\s*?\"url\"\\s*:\\s*\"http://files\\.minecraftforge\\.net/maven/\"", libname.Replace(".", "\\.") ) )) { url = "http://files.minecraftforge.net/maven/"; } else { url = "https://libraries.minecraft.net/"; } } url += string.Join("/", names); var jarname = names[names.Count - 2] + "-" + names[names.Count - 1] + ".jar"; url += "/" + jarname; var localDir = LauncherMain.Instance.Settings.MinecraftFolderName + "libraries\\" + string.Join("\\", names) + "\\"; if (!Directory.Exists(localDir)) { Directory.CreateDirectory(localDir); } var localLoc = localDir + jarname; if (!File.Exists(localLoc)) { var wc = new WebClient(); wc.DownloadFileCompleted += (o, e) => { downloadedCount++; OnProgressChanged(jarname + "已下载", (int)(downloadedCount / (double)needDownload * 100)); wc.Dispose(); }; wc.DownloadProgressChanged += (o, e) => Debug.WriteLine(string.Format("{0} Downloaded {1}", jarname, e.ProgressPercentage)); wc.DownloadFileAsync(new Uri(url), localLoc); } var library = new MinecraftLibrary { name = libname }; manifest.libraries.Add(library); needDownload++; } } while (needDownload != downloadedCount) { Thread.Sleep(100); } if (manifest.arguments == null) { manifest.minecraftArguments += " --tweakClass cpw.mods.fml.common.launcher.FMLTweaker"; } else { manifest.arguments.game.Add("--tweakClass"); manifest.arguments.game.Add("cpw.mods.fml.common.launcher.FMLTweaker"); } MCVersion.SaveManifest(manifest); }
public override List <DownloadItem> GetAllItemsToDownload() { var list = new List <DownloadItem>(); var manifest = MinecraftManifest.AnalyzeFromVersion(this.Version); var id = manifest.id; downloadVersionInfos = new List <OptifineDownloadItem>(); using (var wc = new WebClient()) { if (UseBMCL) { var jsonurl = string.Format(BMCLAPI_OPTIFINE_LIST_FORMAT, id); var seri = new JavaScriptSerializer(); var itemList = seri.Deserialize <List <BMCLOptifineDownloadItem> >( wc.DownloadString(jsonurl) ); foreach (var item in itemList) { var MCVersion = this.Version; var Type = item.type; var Patch = item.patch; var Url = string.Format( "https://bmclapi2.bangbang93.com/optifine/{0}/{1}/{2}", item.mcversion, item.type, item.patch ); var listItem = new OptifineDownloadItem(MCVersion, Type, Patch, Url); downloadVersionInfos.Add(listItem); list.Add(listItem); } } else { var downloads = wc.DownloadString(OPTIFINE_OFFICAL_DOWNLOADS); Match main = Regex.Match( downloads, string.Format("<h2>Minecraft {0}</h2>((.|\n)*?)</table>", id.Replace(".", "\\.")) ); MatchCollection matches = Regex.Matches( main.Value, "<tr class='downloadLine.*?'>\\n<td class='downloadLineFile.*?'>(.*?)</td>\\n<td class='downloadLineDownload.*?'><a href=.*?>Download</a></td>\\n<td class='downloadLineMirror'><a href=\"(.*?)\"> \\(mirror\\)</a></td>" ); foreach (Match match in matches) { var groups = EnumeratorUtils.MakeListFromEnumerator( match.Groups.GetEnumerator() ); var name = ((Group)groups[1]).Value; var mirror = ((Group)groups[2]).Value; var t = EnumeratorUtils.MakeListFromEnumerator( Regex.Match( mirror, "http://optifine.net/adloadx\\?f=(.*)" ).Groups.GetEnumerator() ); var jar = ((Group)t[1]).Value; var adsite = wc.DownloadString(mirror); var uri = Regex.Match(adsite, string.Format("downloadx\\?f={0}&x=.*?'", jar.Replace(".", "\\."))).Value; uri = uri.Substring(0, uri.Length - 1); var url = "https://optifine.net/" + uri; var args = name.Split(' '); var type = args[2] + "_" + args[3]; var patch = args[4]; var info = new OptifineDownloadItem(Version, type, patch, url); downloadVersionInfos.Add(info); list.Add(info); } } } return(list); }