Skip to content

Commit

Permalink
Merge '[GUI] Fix isVersionNewer handling and remove some legacy code' (
Browse files Browse the repository at this point in the history
  • Loading branch information
fenhl committed Nov 18, 2024
2 parents 0aa742b + a6988b7 commit 5ff79d6
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 34 deletions.
138 changes: 105 additions & 33 deletions GUI/src/app/providers/GUIGlobal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ export class GUIGlobal implements OnDestroy {
result.latestVersion = remote.fullVersion;

//Compare versions
result.hasUpdate = this.isVersionNewer(remote.baseVersion, local.baseVersion, remote.supplementaryVersion, local.supplementaryVersion);
result.hasUpdate = this.isVersionNewer(`${remote.baseVersion}-${remote.supplementaryVersion}`, `${local.baseVersion}-${local.supplementaryVersion}`);

return result;
}
Expand All @@ -735,47 +735,119 @@ export class GUIGlobal implements OnDestroy {
}
}

isVersionNewer(newVersion: string, oldVersion: string, newSubVersion: number = 0, oldSubVersion: number = 0) {
//Split up a string version into distinct chunks
getVersionParts(versionText) {

//Strip away dev strings
if (oldVersion.startsWith("dev") && oldVersion.includes("_"))
oldVersion = oldVersion.split("_")[1];
let data = { branch: null, master: null, minor: null, revision: null, supplemental: null, supplementalFound: false, parts: [], rawInput: versionText, rawParts: [] };

if (newVersion.startsWith("dev") && newVersion.includes("_"))
newVersion = newVersion.split("_")[1];
if (versionText.startsWith("dev") && versionText.includes("_")) { //Handle dev versions

let oldSplit = oldVersion.replace('v', '').replace(' ', '.').split('.');
let newSplit = newVersion.replace('v', '').replace(' ', '.').split('.');
//Extract dev branch name and version
let branchParts = versionText.split("_");
data.branch = branchParts[0];

//Version is not newer if the new version doesn't satisfy the format
if (newSplit.length < 3)
return false;
else if (newSplit.length == 4)
newSubVersion = newSubVersion == 0 ? Number(newSplit[3]) : 0;
versionText = branchParts[1];
}

//Version is newer if the old version doesn't satisfy the format
if (oldSplit.length < 3)
return true;
else if (oldSplit.length == 4)
oldSubVersion = oldSubVersion == 0 ? Number(oldSplit[3]) : 0;
//Extract version major.minor.rev section
let versionSections = versionText.split("-");
let versionParts = versionSections[0].split(".");

//Compare major.minor.revision
if (Number(newSplit[0]) > Number(oldSplit[0])) {
return true;
}
else if (Number(newSplit[0]) == Number(oldSplit[0])) {
if (Number(newSplit[1]) > Number(oldSplit[1])) {
return true;
switch (versionParts.length) {

case 3: { //Rev
data.revision = Number.parseInt(versionParts[2]);

//Not a number protection
if (data.revision !== Number(versionParts[2])) {
data.revision = null;
data.parts = [];
}
else {
data.parts.push(data.revision);
}

//falls through
}
else if (Number(newSplit[1]) == Number(oldSplit[1])) {
if (Number(newSplit[2]) > Number(oldSplit[2])) {
return true;
case 2: { //Minor
data.minor = Number.parseInt(versionParts[1]);

if (data.minor !== Number(versionParts[1])) {
data.minor = data.revision = null;
data.parts = [];
}
else if (Number(newSplit[2]) == Number(oldSplit[2])) {
if (newSubVersion > oldSubVersion) {
return true;
}
else {
data.parts.push(data.minor);
}

//falls through
}
case 1: { //Master
data.master = Number.parseInt(versionParts[0]);

if (data.master !== Number(versionParts[0])) {
data.master = data.minor = data.revision = null;
data.parts = [];
}
else {
data.parts.push(data.master);
}

break;
}
default: {
break;
}
}

//Reverse for proper order
data.parts.reverse();
data.rawParts = [...data.parts];

//Check for supplemental version (only if valid semver version is available first)
if (data.parts.length == 3) {

if (versionSections.length == 2) {

data.supplemental = Number.parseInt(versionSections[1]);

if (data.supplemental !== Number(versionSections[1])) {
data.supplemental = null;
}
else {
data.parts.push(data.supplemental);
data.rawParts.push(data.supplemental);
data.supplementalFound = true;
}
}
else {
//For backwards compatibility reasons, assume supplemental version of 0 when only a semver version is specified
data.supplemental = 0;
data.parts.push(0);
data.supplementalFound = false;
}
}

return data;
}

isVersionNewer(newVersion: string, oldVersion: string) { //version raw text or getVersionParts object

let versionSplit = typeof (newVersion) == "string" ? this.getVersionParts(newVersion) : newVersion;
let oldVersionSplit = typeof (oldVersion) == "string" ? this.getVersionParts(oldVersion) : oldVersion;

//Compare every version part against each other
for (let versionPartIndex = 0; versionPartIndex < versionSplit.parts.length; versionPartIndex++) {

//The tested version has more parts than the old version while everything else matched, this version is newer!
if (versionPartIndex >= oldVersionSplit.parts.length)
return true;

if (oldVersionSplit.parts[versionPartIndex] > versionSplit.parts[versionPartIndex]) {
return false;
}
else if (oldVersionSplit.parts[versionPartIndex] < versionSplit.parts[versionPartIndex]) {
return true;
}
}

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ issue. You should always Hard Reset to avoid this issue entirely.
* Fix key rings being hinted as small keys when keys are in their own dungeons.
* Fix a crash when pressing down on the D-pad on the inventory screen in some settings combinations.
* Fix a possible void out at the Forest Temple boss door.
* Fix importing settings from older versions on web.

#### Other Changes
* Now supports custom music written for the Majora's Mask Randomizer.
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '8.2.23'
__version__ = '8.2.24'

# This is a supplemental version number for branches based off of main dev.
supplementary_version = 0
Expand Down

0 comments on commit 5ff79d6

Please sign in to comment.