Checks for new versions. @param ask ask for automatic update checks
(final boolean ask)
| 706 | * @param ask ask for automatic update checks |
| 707 | */ |
| 708 | void checkVersion(final boolean ask) { |
| 709 | // retrieve latest version |
| 710 | final Version version = new Version(gopts.get(GUIOptions.UPDATEVERSION)); |
| 711 | Version latest = version; |
| 712 | try { |
| 713 | final Matcher matcher = VERSION_CHECK.matcher(new IOUrl(VERSION_URL).readString()); |
| 714 | if(matcher.matches()) { |
| 715 | latest = new Version(matcher.group(2)); |
| 716 | gopts.set(GUIOptions.UPDATEVERSION, latest.toString()); |
| 717 | } |
| 718 | } catch(final IOException ex) { |
| 719 | Util.debug(ex); |
| 720 | } |
| 721 | |
| 722 | final boolean check = gopts.get(GUIOptions.CHECKUPDATES); |
| 723 | boolean chk = check; |
| 724 | if(version.compareTo(latest) < 0) { |
| 725 | if(BaseXDialog.confirm(this, Util.info(H_VERSION_NEW_X_X, Prop.NAME, latest))) { |
| 726 | // new version found: open browser page |
| 727 | BaseXDialog.browse(this, UPDATE_URL); |
| 728 | } else if(ask) { |
| 729 | // if page is not opened, ask for automatic check |
| 730 | chk = BaseXDialog.confirm(this, H_VERSION_CHECK); |
| 731 | gopts.set(GUIOptions.CHECKUPDATES, chk); |
| 732 | } |
| 733 | saveOptions(); |
| 734 | } else if(ask) { |
| 735 | // version is up-to-date: ask for automatic check |
| 736 | chk = BaseXDialog.confirm(this, Util.info(H_VERSION_LATEST_X, Prop.NAME) + '\n' + |
| 737 | H_VERSION_CHECK); |
| 738 | gopts.set(GUIOptions.CHECKUPDATES, chk); |
| 739 | } |
| 740 | |
| 741 | // save changed options |
| 742 | if(!version.equals(latest) || check != chk) saveOptions(); |
| 743 | } |
| 744 | } |