mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 11:15:12 -04:00
switched to scala's built-in json parser, because argo seems to be gone in 1.7
This commit is contained in:
parent
99059f016c
commit
c850cb52bb
@ -1,14 +1,13 @@
|
|||||||
package li.cil.oc
|
package li.cil.oc
|
||||||
|
|
||||||
import argo.jdom.JdomParser
|
|
||||||
import cpw.mods.fml.common.Loader
|
import cpw.mods.fml.common.Loader
|
||||||
import cpw.mods.fml.common.versioning.ComparableVersion
|
import cpw.mods.fml.common.versioning.ComparableVersion
|
||||||
import java.io.InputStreamReader
|
|
||||||
import java.net.{HttpURLConnection, URL}
|
import java.net.{HttpURLConnection, URL}
|
||||||
import java.util.logging.Level
|
import java.util.logging.Level
|
||||||
import net.minecraft.entity.player.EntityPlayerMP
|
import net.minecraft.entity.player.EntityPlayerMP
|
||||||
import net.minecraft.util.ChatMessageComponent
|
import net.minecraft.util.ChatMessageComponent
|
||||||
import scala.collection.convert.WrapAsScala._
|
import scala.io.Source
|
||||||
|
import scala.util.parsing.json.{JSONObject, JSONArray, JSON}
|
||||||
|
|
||||||
object UpdateCheck {
|
object UpdateCheck {
|
||||||
val releasesUrl = new URL("https://api.github.com/repos/MightyPirates/OpenComputers/releases")
|
val releasesUrl = new URL("https://api.github.com/repos/MightyPirates/OpenComputers/releases")
|
||||||
@ -34,20 +33,30 @@ object UpdateCheck {
|
|||||||
case conn: HttpURLConnection =>
|
case conn: HttpURLConnection =>
|
||||||
conn.setRequestMethod("GET")
|
conn.setRequestMethod("GET")
|
||||||
conn.setDoOutput(false)
|
conn.setDoOutput(false)
|
||||||
val json = new JdomParser().parse(new InputStreamReader(conn.getInputStream))
|
JSON.parseRaw(Source.fromInputStream(conn.getInputStream).mkString) match {
|
||||||
val candidates = json.getElements.filter(node => matchesVersion(node.getStringValue("tag_name")) && !node.getBooleanValue("prerelease"))
|
case Some(array: JSONArray) =>
|
||||||
if (candidates.nonEmpty) {
|
val candidates = array.list.filter(_.isInstanceOf[JSONObject]).map(node => {
|
||||||
val newest = candidates.maxBy(node => new ComparableVersion(node.getStringValue("tag_name").stripPrefix("v")))
|
val obj = node.asInstanceOf[JSONObject].obj
|
||||||
val tag = newest.getStringValue("tag_name")
|
(obj("tag_name").asInstanceOf[String], !obj("prerelease").asInstanceOf[Boolean])
|
||||||
val tagVersion = new ComparableVersion(tag.stripPrefix("v"))
|
}).filter {
|
||||||
val modVersion = new ComparableVersion(version)
|
case (tag, isRelease) => matchesVersion(tag) && isRelease
|
||||||
if (tagVersion.compareTo(modVersion) > 0) {
|
}
|
||||||
OpenComputers.log.info(s"A newer version is available: ($tag})")
|
if (candidates.nonEmpty) {
|
||||||
return (player: EntityPlayerMP) =>
|
val newest = candidates.maxBy {
|
||||||
player.sendChatToPlayer(ChatMessageComponent.createFromText("§aOpenComputers§f: ").addFormatted(Settings.namespace + "gui.Chat.NewVersion", tag))
|
case (tagName, _) => new ComparableVersion(tagName.stripPrefix("v"))
|
||||||
}
|
}
|
||||||
|
val tag = newest._1
|
||||||
|
val tagVersion = new ComparableVersion(tag.stripPrefix("v"))
|
||||||
|
val modVersion = new ComparableVersion(version)
|
||||||
|
if (tagVersion.compareTo(modVersion) > 0) {
|
||||||
|
OpenComputers.log.info(s"A newer version is available: ($tag})")
|
||||||
|
return (player: EntityPlayerMP) =>
|
||||||
|
player.sendChatToPlayer(ChatMessageComponent.createFromText("§aOpenComputers§f: ").addFormatted(Settings.namespace + "gui.Chat.NewVersion", tag))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
OpenComputers.log.info("Running the latest version.")
|
||||||
|
case _ => OpenComputers.log.warning("Unexpected response from Github.")
|
||||||
}
|
}
|
||||||
OpenComputers.log.info("Running the latest version.")
|
|
||||||
case _ => OpenComputers.log.warning("Failed to connect to Github.")
|
case _ => OpenComputers.log.warning("Failed to connect to Github.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user