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<Version> newer;
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 {
+ Version version = new Version();
for (String line = reader.readLine(); line != null; line = reader
.readLine()) {
if (line.startsWith("## Version ")) {
- String v = line.substring("## Version ".length());
- Version version = new Version(v);
+ version = new Version(line.substring("## Version "
+ .length()));
if (version.isNewerThan(current)) {
newer.add(version);
changes.put(version, new ArrayList<String>());
+ } else {
+ version = new Version();
}
- } else if (!newer.isEmpty() && !line.isEmpty()) {
- Version version = newer.get(newer.size() - 1);
- List<String> ch = changes.get(version);
+ } else if (!version.isEmpty() && !newer.isEmpty()
+ && !line.isEmpty()) {
+ List<String> ch = changes.get(newer.get(newer
+ .size() - 1));
if (!ch.isEmpty() && !line.startsWith("- ")) {
int i = ch.size() - 1;
ch.set(i, ch.get(i) + " " + line.trim());
reader.close();
}
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler()
+ .error(new IOException(
+ "Cannot download latest changelist on github.com",
+ e));
}
}