summaryrefslogtreecommitdiff
path: root/src/com/rafa_99/pkrandom/Version.java
blob: 8614b490bb7d8354b0d463b6ad53f7aa61d6869c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.rafa_99.pkrandom;

/*----------------------------------------------------------------------------*/
/*--  Version.java - contains information about the randomizer's versions   --*/
/*--                                                                        --*/
/*--  Part of "Universal Pokemon Randomizer ZX" by the UPR-ZX team          --*/
/*--  Originally part of "Universal Pokemon Randomizer" by rafa_99        --*/
/*--  Pokemon and any associated names and the like are                     --*/
/*--  trademark and (C) Nintendo 1996-2020.                                 --*/
/*--                                                                        --*/
/*--  The custom code written here is licensed under the terms of the GPL:  --*/
/*--                                                                        --*/
/*--  This program is free software: you can redistribute it and/or modify  --*/
/*--  it under the terms of the GNU General Public License as published by  --*/
/*--  the Free Software Foundation, either version 3 of the License, or     --*/
/*--  (at your option) any later version.                                   --*/
/*--                                                                        --*/
/*--  This program is distributed in the hope that it will be useful,       --*/
/*--  but WITHOUT ANY WARRANTY; without even the implied warranty of        --*/
/*--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          --*/
/*--  GNU General Public License for more details.                          --*/
/*--                                                                        --*/
/*--  You should have received a copy of the GNU General Public License     --*/
/*--  along with this program. If not, see <http://www.gnu.org/licenses/>.  --*/
/*----------------------------------------------------------------------------*/

import java.util.HashMap;
import java.util.Map;

public class Version {
    public static final int VERSION = 319; // Increment by 1 for new version. Updated for 4.5.0-dev
    public static final String VERSION_STRING = "4.5.0-dev";

    public static final Map<Integer,String> oldVersions = setupVersionsMap();

    private static Map<Integer,String> setupVersionsMap() {
        Map<Integer,String> map = new HashMap<>();

        map.put(100, "1.0.1a");
        map.put(102, "1.0.2a");
        map.put(110, "1.1.0");
        map.put(111, "1.1.1");
        map.put(112, "1.1.2");
        map.put(120, "1.2.0a");
        map.put(150, "1.5.0");
        map.put(160, "1.6.0a");
        map.put(161, "1.6.1");
        map.put(162, "1.6.2");
        map.put(163, "1.6.3b");
        map.put(170, "1.7.0b");
        map.put(171, "1.7.1");
        map.put(172, "1.7.2");
        map.put(310, "3.1.0");
        map.put(311, "4.0.0");
        map.put(312, "4.0.1");
        map.put(313, "4.0.2");
        map.put(314, "4.1.0");
        map.put(315, "4.2.0");
        map.put(316, "4.2.1");
        map.put(317, "4.3.0");
        map.put(318, "4.4.0");

        // Latest version - when version is updated, add the old version as an explicit put
        map.put(VERSION, VERSION_STRING);

        return map;
    }

    public static boolean isReleaseVersionNewer(String releaseVersion) {
        if (VERSION_STRING.contains("dev")) {
            return false;
        }
        // Chop off leading "v" from release version
        try {
            String releaseVersionTrimmed = releaseVersion.substring(1);
            String[] thisVersionPieces = VERSION_STRING.split("\\.");
            String[] releaseVersionPieces = releaseVersionTrimmed.split("\\.");
            int smallestLength = Math.min(thisVersionPieces.length, releaseVersionPieces.length);
            for (int i = 0; i < smallestLength; i++) {
                int thisVersionPiece = Integer.parseInt(thisVersionPieces[i]);
                int releaseVersionPiece = Integer.parseInt(releaseVersionPieces[i]);
                if (thisVersionPiece < releaseVersionPiece) {
                    return true;
                } else if (thisVersionPiece > releaseVersionPiece) {
                    return false;
                }
            }
            return false;
        } catch (Exception e) {
            // Really not a big deal if we fail at this, probably because we can't connect to Github.
            return false;
        }
    }
}