X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2FVersionCheck.java;h=76758af85ca3daaa5ef4f5b8e5fcc799bbee6f2e;hb=aa8b74a318769354c5cb512ead428beb372503a2;hp=3f63bf5e8819621eabe3c4ebb9e0a022647d8778;hpb=7e191c686f6de7cecc3979dbff136e0bf263277d;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/VersionCheck.java b/src/be/nikiroo/fanfix/VersionCheck.java index 3f63bf5..76758af 100644 --- a/src/be/nikiroo/fanfix/VersionCheck.java +++ b/src/be/nikiroo/fanfix/VersionCheck.java @@ -8,12 +8,19 @@ import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import be.nikiroo.utils.Version; +/** + * Version checker: can check the current version of the program against a + * remote changelog, and list the missed updates and their description. + * + * @author niki + */ public class VersionCheck { - private static final String url = "https://github.com/nikiroo/fanfix/raw/master/changelog.md"; + private static final String base = "https://github.com/nikiroo/fanfix/raw/master/changelog${LANG}.md"; private Version current; private List newer; @@ -102,8 +109,27 @@ public class VersionCheck { if (Instance.isVersionCheckNeeded()) { try { - InputStream in = Instance.getCache().openNoCache(new URL(url), - null); + // Prepare the URLs according to the user's language + Locale lang = Instance.getTrans().getLocale(); + String fr = lang.getLanguage(); + String BE = lang.getCountry().replace(".UTF8", ""); + String urlFrBE = base.replace("${LANG}", "-" + fr + "_" + BE); + String urlFr = base.replace("${LANG}", "-" + fr); + String urlDefault = base.replace("${LANG}", ""); + + InputStream in = null; + for (String url : new String[] { urlFrBE, urlFr, urlDefault }) { + try { + in = Instance.getCache().openNoCache(new URL(url)); + break; + } catch (IOException e) { + } + } + + if (in == null) { + throw new IOException("No changelog found"); + } + BufferedReader reader = new BufferedReader( new InputStreamReader(in, "UTF-8")); try { @@ -135,7 +161,10 @@ public class VersionCheck { reader.close(); } } catch (IOException e) { - Instance.syserr(e); + Instance.getTraceHandler() + .error(new IOException( + "Cannot download latest changelist on github.com", + e)); } }