Hello JGO, I got rather bored last night so I decided to program a “Game Updater”.
Earlier today I implemented alot more, so I figured I’d release it with the new updates:
- Calculating the current download percentage.
- Calculating the current KBS. (Kilobytes downloaded per second)
- Calculating the current ETA. (Estimated time of arrival in seconds)
- Constructor parameters for easier implementation.
Notes:
You must have a server to upload the files to E.G: http://www.yourwebsite.co.nf/upload_directory/.
In the upload directory should be your most recent .JAR of your game along with a .txt file in the same directory that should only contain your games current version E.G: “0.0.0.1” saved in “version.txt” file.
The .JARs name should be formatted like so: Game_Name_Here_0.0.0.1 (0.0.0.1 being the most recent version)
So everytime you update your game and pack it into a .JAR you need to upload the .JAR to the directory on your server and update the version number on the .JAR and inside the .TXT file
Usage:
/**
* Main entry point into the application
* @param args The arguments passed via the user (NONE)
* @throws IOException There was a error during reading / writing.
* @throws MalformedURLException URL is missing headers?
*/
public static void main(String[] args) throws MalformedURLException, IOException {
/* Parameters for the GameUpdater constructor */
String currentClientVersion = "0.0.0.1"; // the current version programmed into the client.
String versionDirectoryURL = "http://www.javatools.co.nf/releases/"; // the directory of your recent .JAR/.TXT.
String versionFileNameAndExt = "version.txt"; // the name of the version file / extension.
String gameName = "Block_Tamer_Client_"; // the name of your game ^_^
GameUpdater updater = new GameUpdater(currentClientVersion, versionDirectoryURL, versionFileNameAndExt, gameName);
if (updater.needsUpdating()) {
updater.downloadUpdatedJar(true); // true to print percentage while downloading
}
}
There are a few methods (Getters) implemented to make this game more easily implementable in your game.
(While updating you can show the ETA/KBS/percentage etc)
public int getDownloadPercentage() {
return downloadPercentage;
}
public double getETA() {
return ETA;
}
public int getKbs() {
return kbs;
}
Anyhow thanks for reading guys, here is the source code:
http://www.java-gaming.org/?action=pastebin&id=602