From ed1dd95352456ed7e41ff0d449115af001d984c3 Mon Sep 17 00:00:00 2001 From: vfyjxf <2331007009@qq.com> Date: Wed, 28 Jul 2021 16:08:05 +0800 Subject: [PATCH] Update CrashRepot uploader --- README.md | 10 +-- build.gradle | 64 +++++++++---------- gradle.properties | 2 +- .../vfyjxf/bettercrashes/BetterCrashes.java | 9 +++ .../bettercrashes/BetterCrashesConfig.java | 19 ++++++ .../utils/CrashReportUpload.java | 35 ++++++++++ .../bettercrashes/utils/GuiProblemScreen.java | 26 ++++++-- .../assets/bettercrashes/lang/en_US.lang | 3 +- .../assets/bettercrashes/lang/zh_CN.lang | 1 + 9 files changed, 126 insertions(+), 43 deletions(-) create mode 100644 src/main/java/vfyjxf/bettercrashes/BetterCrashesConfig.java create mode 100644 src/main/java/vfyjxf/bettercrashes/utils/CrashReportUpload.java diff --git a/README.md b/README.md index e10e811..269ea29 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,17 @@ BetterCrashes is a port of VanillaFix's crash improvement features to Minecraft 1.7.10. +BetterCrashes makes Minecraft return you to the main menu when it crashes,and offer to upload + +your CrashReport to [ubuntu Pastebin](http://paste.ubuntu.com/) (closed by default). + Most of the code comes from VanillaFix, I just make them work on Minecraft 1.7.10. Requires [Grimoire](https://github.com/CrucibleMC/Grimoire) mod to work ## Known Issues -Not compatible with hodgepodge mod,you need go to hodgepodge mod's config file to to turn off fixGuiGameOver,if you don't do this, it may cause a crash. - - -## Credits +Not compatible with hodgepodge mod,you need go to hodgepodge mod's config file to turn off fixGuiGameOver,if you don't do this, it may cause a crash. +## Credits Thanks VanillaFix and Grimoire diff --git a/build.gradle b/build.gradle index b4c357a..50955ca 100644 --- a/build.gradle +++ b/build.gradle @@ -1,16 +1,16 @@ buildscript { - repositories { - mavenCentral() - jcenter() + repositories { + mavenCentral() + jcenter() maven { name = "github" url = "https://github.com/juanmuscaria/maven/raw/master" } - } - dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-1.4.0-SNAPSHOT' - classpath 'com.integral.grimoire:GrimoireShenanigans:[1.3.0,)' - } + } + dependencies { + classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-1.4.0-SNAPSHOT' + classpath 'com.integral.grimoire:GrimoireShenanigans:[1.3.0,)' + } } @@ -26,16 +26,15 @@ group = mod_group archivesBaseName = mod_archives_name minecraft { - version = "1.7.10-10.13.4.1614-1.7.10" - runDir = "eclipse" - replace "@VERSION@", project.version + version = "1.7.10-10.13.4.1614-1.7.10" + runDir = "eclipse" + replace "@VERSION@", project.version } repositories { - - flatDir { - dirs 'libs' - } + flatDir { + dirs 'libs' + } } processResources { @@ -43,13 +42,13 @@ processResources { from(sourceSets.main.resources.srcDirs) { include 'mcmod.info' expand 'version': project.version, - 'mod_id': mod_id, - 'mod_name': mod_name, - 'mod_author': mod_author, - 'mod_description': mod_description, - 'mc_version': mc_version, - 'mod_version': mod_version, - 'mod_icon': mod_icon + 'mod_id': mod_id, + 'mod_name': mod_name, + 'mod_author': mod_author, + 'mod_description': mod_description, + 'mc_version': mc_version, + 'mod_version': mod_version, + 'mod_icon': mod_icon } from(sourceSets.main.resources.srcDirs) { @@ -58,24 +57,25 @@ processResources { } task devJar(type: Jar) { - classifier = 'dev' - from sourceSets.main.output + classifier = 'dev' + from sourceSets.main.output } task sourcesJar(type: Jar) { - classifier = 'sources' - from sourceSets.main.allSource + classifier = 'sources' + from sourceSets.main.allSource } -jar{ - appendix project.minecraft.version -} reobf { - addExtraSrgFile project.mixinSrg + addExtraSrgFile project.mixinSrg +} + +jar { + appendix project.minecraft.version } artifacts { - archives devJar - archives sourcesJar + archives devJar + archives sourcesJar } diff --git a/gradle.properties b/gradle.properties index 94f2bb7..5418dd4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.daemon=false # General Specifications mc_version=1.7.10 -mod_version=1.0.0 +mod_version=1.1.0 forge_version=10.13.4.1614 mod_group=vfyjxf.bettercrashes mod_id=bettercrashes diff --git a/src/main/java/vfyjxf/bettercrashes/BetterCrashes.java b/src/main/java/vfyjxf/bettercrashes/BetterCrashes.java index a25fc7e..4fdd8cc 100644 --- a/src/main/java/vfyjxf/bettercrashes/BetterCrashes.java +++ b/src/main/java/vfyjxf/bettercrashes/BetterCrashes.java @@ -1,11 +1,15 @@ package vfyjxf.bettercrashes; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import net.minecraft.client.Minecraft; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import cpw.mods.fml.common.Mod; +import java.io.File; + @Mod(modid = BetterCrashes.MODID, version = BetterCrashes.VERSION, name = BetterCrashes.NAME,dependencies = BetterCrashes.DEPENDENCIES) public class BetterCrashes { public static final String MODID = "bettercrashes"; @@ -13,4 +17,9 @@ public class BetterCrashes { public static final String VERSION = "@VERSION@"; public static final String DEPENDENCIES = "required-after:grimoire"; public static final Logger logger = LogManager.getLogger("BetterCrashes"); + + @Mod.EventHandler + public void preInit(FMLPreInitializationEvent event){ + BetterCrashesConfig.loadConfig(new File(Minecraft.getMinecraft().mcDataDir,"config/BetterCrashes.cfg")); + } } diff --git a/src/main/java/vfyjxf/bettercrashes/BetterCrashesConfig.java b/src/main/java/vfyjxf/bettercrashes/BetterCrashesConfig.java new file mode 100644 index 0000000..a9d0aff --- /dev/null +++ b/src/main/java/vfyjxf/bettercrashes/BetterCrashesConfig.java @@ -0,0 +1,19 @@ +package vfyjxf.bettercrashes; + +import net.minecraftforge.common.config.Configuration; + +import java.io.File; + +public class BetterCrashesConfig { + + public static boolean enableUploadCrash = false; + + public static void loadConfig(File configFile){ + Configuration config = new Configuration(configFile); + config.load(); + enableUploadCrash = config.get("upload","enableUploadCrash",false, + "if true,we will use \"https://paste.ubuntu.com\" to upload crash report.").getBoolean(); + config.save(); + } + +} diff --git a/src/main/java/vfyjxf/bettercrashes/utils/CrashReportUpload.java b/src/main/java/vfyjxf/bettercrashes/utils/CrashReportUpload.java new file mode 100644 index 0000000..aecc17b --- /dev/null +++ b/src/main/java/vfyjxf/bettercrashes/utils/CrashReportUpload.java @@ -0,0 +1,35 @@ +package vfyjxf.bettercrashes.utils; + + +import java.io.IOException; +import java.io.PrintWriter; +import java.net.HttpURLConnection; +import java.net.URL; + +public class CrashReportUpload { + + + public static String uploadToUbuntuPastebin(String url, String crashReport) throws IOException { + URL pasteUrl = new URL(url); + HttpURLConnection connection = (HttpURLConnection) pasteUrl.openConnection(); + connection.setInstanceFollowRedirects(false); + connection.setRequestMethod("POST"); + connection.setUseCaches(false); + connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + connection.setDoInput(true); + connection.setDoOutput(true); + connection.setReadTimeout(1000000); + connection.setConnectTimeout(500000); + PrintWriter out = new PrintWriter(connection.getOutputStream()); + String params = "poster=CrashReport&syntax=text&content=" + crashReport; + out.write(params); + out.flush(); + String resultUrl = null; + resultUrl = connection.getHeaderField("Location"); + if (resultUrl == null) { + resultUrl = connection.getHeaderField("location"); + } + return url + resultUrl; + } + +} diff --git a/src/main/java/vfyjxf/bettercrashes/utils/GuiProblemScreen.java b/src/main/java/vfyjxf/bettercrashes/utils/GuiProblemScreen.java index bae2d53..23554cd 100644 --- a/src/main/java/vfyjxf/bettercrashes/utils/GuiProblemScreen.java +++ b/src/main/java/vfyjxf/bettercrashes/utils/GuiProblemScreen.java @@ -14,7 +14,7 @@ import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.resources.I18n; import net.minecraft.crash.CrashReport; import org.apache.commons.lang3.StringUtils; -import vfyjxf.bettercrashes.BetterCrashes; +import vfyjxf.bettercrashes.BetterCrashesConfig; import java.io.IOException; import java.util.ArrayList; @@ -23,7 +23,7 @@ import java.util.Set; @SideOnly(Side.CLIENT) -public abstract class GuiProblemScreen extends GuiScreen { +public abstract class GuiProblemScreen extends GuiScreen{ protected final CrashReport report; private String hasteLink = null; @@ -37,18 +37,34 @@ public abstract class GuiProblemScreen extends GuiScreen { public void initGui() { mc.setIngameNotInFocus(); buttonList.clear(); - buttonList.add(new GuiButton(1, width / 2 - 155 + 160, height / 4 + 120 + 12, 150, 20, I18n.format("bettercrashes.gui.openCrashReport"))); + if(BetterCrashesConfig.enableUploadCrash) { + buttonList.add(new GuiButton(1, width / 2 - 155 + 160, height / 4 + 120 + 12, 150, 20, I18n.format("bettercrashes.gui.uploadReportAndCopyLink"))); + }else { + buttonList.add(new GuiButton(1, width / 2 - 155 + 160, height / 4 + 120 + 12, 150, 20, I18n.format("bettercrashes.gui.openCrashReport"))); + } } + @Override protected void actionPerformed(GuiButton button) { - if(button.id == 1){ + if(button.id == 1 && BetterCrashesConfig.enableUploadCrash){ + if(hasteLink == null){ + try { + hasteLink = CrashReportUpload.uploadToUbuntuPastebin("https://paste.ubuntu.com",report.getCompleteReport()); + } catch (IOException e) { + button.displayString = I18n.format("bettercrashes.gui.failed"); + button.enabled = false; + e.printStackTrace(); + } + } + setClipboardString(hasteLink); + }else if (button.id == 1){ try { CrashUtils.openCrashReport(report); } catch (IOException e) { - BetterCrashes.logger.error("Can't open crashreoprt",e); button.displayString = I18n.format("bettercrashes.gui.failed"); button.enabled = false; + e.printStackTrace(); } } } diff --git a/src/main/resources/assets/bettercrashes/lang/en_US.lang b/src/main/resources/assets/bettercrashes/lang/en_US.lang index 5949539..1b59a28 100644 --- a/src/main/resources/assets/bettercrashes/lang/en_US.lang +++ b/src/main/resources/assets/bettercrashes/lang/en_US.lang @@ -1,4 +1,5 @@ -bettercrashes.gui.openCrashReport=Open CrashReport +bettercrashes.gui.uploadReportAndCopyLink=Copy Link +bettercrashes.gui.openCrashReport=Open Crash Report bettercrashes.gui.failed=[Failed] bettercrashes.crashscreen.identificationErrored=[Error identifying] bettercrashes.crashscreen.unknownCause=Unknown diff --git a/src/main/resources/assets/bettercrashes/lang/zh_CN.lang b/src/main/resources/assets/bettercrashes/lang/zh_CN.lang index cfef474..b2b7d03 100644 --- a/src/main/resources/assets/bettercrashes/lang/zh_CN.lang +++ b/src/main/resources/assets/bettercrashes/lang/zh_CN.lang @@ -1,3 +1,4 @@ +bettercrashes.gui.uploadReportAndCopyLink=复制链接到剪贴板 bettercrashes.gui.openCrashReport=打开崩溃报告 bettercrashes.gui.failed=[失败] bettercrashes.crashscreen.identificationErrored=[鉴别错误]