-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
210 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
api/src/main/java/com/lunarclient/apollo/version/ApolloVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* This file is part of Apollo, licensed under the MIT License. | ||
* | ||
* Copyright (c) 2023 Moonsworth | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package com.lunarclient.apollo.version; | ||
|
||
import java.util.Arrays; | ||
import lombok.Getter; | ||
|
||
/** | ||
* Represents an Apollo version. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
@Getter | ||
public class ApolloVersion { | ||
|
||
private final int major; | ||
private final int minor; | ||
private final int patch; | ||
|
||
/** | ||
* Constructs the {@link ApolloVersion} by the | ||
* provided version string. | ||
* | ||
* <p>Divides the version string by the major, minor & patch version.</p> | ||
* | ||
* @param version the version | ||
* @since 1.0.0 | ||
*/ | ||
public ApolloVersion(String version) { | ||
System.out.println(version); | ||
|
||
String[] versions = version | ||
.replaceAll("[^0-9.]", "") | ||
.split("\\."); | ||
|
||
System.out.println(Arrays.toString(versions)); // TODO: remove | ||
|
||
if (versions.length != 3) { | ||
throw new RuntimeException("Failed to parse Apollo version."); | ||
} | ||
|
||
try { | ||
this.major = Integer.parseInt(versions[0]); | ||
this.minor = Integer.parseInt(versions[1]); | ||
this.patch = Integer.parseInt(versions[2]); | ||
} catch (NumberFormatException e) { | ||
throw new RuntimeException("Failed to parse Apollo version."); | ||
} | ||
} | ||
|
||
/** | ||
* Checks the current and the latest available for updates. | ||
* | ||
* @param version the latest available version | ||
* @return whether the update is available | ||
* @see com.lunarclient.apollo.version.ApolloVersionManager | ||
* @since 1.0.0 | ||
*/ | ||
public boolean isUpdateAvailable(ApolloVersion version) { | ||
if (this.major > version.getMajor()) { | ||
return true; | ||
} else if (this.minor > version.getMinor()) { | ||
return true; | ||
} | ||
|
||
return this.patch > version.getPatch(); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
api/src/main/java/com/lunarclient/apollo/version/ApolloVersionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* This file is part of Apollo, licensed under the MIT License. | ||
* | ||
* Copyright (c) 2023 Moonsworth | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package com.lunarclient.apollo.version; | ||
|
||
import com.lunarclient.apollo.Apollo; | ||
|
||
/** | ||
* Manages Apollo versioning. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public class ApolloVersionManager { | ||
|
||
// TODO: add message toggle to config | ||
|
||
private static final String DOWNLOAD_URL = "https://lunarclient.dev/apollo/downloads"; | ||
private static final String UPDATE_MESSAGE = "[Apollo] You’re running an outdated version, update to the latest version here: " + DOWNLOAD_URL; | ||
|
||
/** | ||
* Constructs the {@link ApolloVersionManager}. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public ApolloVersionManager() { | ||
this.checkForUpdates(); | ||
} | ||
|
||
private void checkForUpdates() { | ||
ApolloVersion currentVersion = new ApolloVersion(Apollo.getPlatform().getApolloVersion()); | ||
ApolloVersion latestVersion = new ApolloVersion("v1.0.1"); // TODO: fetch | ||
|
||
if (currentVersion.isUpdateAvailable(latestVersion)) { | ||
Apollo.getPlatform().getPlatformLogger().warning(UPDATE_MESSAGE); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters