Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (482)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Simple .JAR Updater  (Read 1745 times)
0 Members and 1 Guest are viewing this topic.
Offline GabrielBailey74
« Posted 2013-06-08 21:37:50 »

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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
   /**
    * 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)
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
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

Offline Sammidysam
« Reply #1 - Posted 2013-06-08 21:40:53 »

I think you should add support for updating via the update date, so that people don't have to increase the version for an update if they don't want to (it seems illogical, but if you are letting people play when you are not even ready to put a version number on the game it makes sense).

Also, it seems counter-intuitive to code the version of the client into the client.  I guess this doesn't require a separate launcher program, but if it were a launcher it would be more convenient to hold the version number in a file and update and check the file as necessary.  Oh wait, it sounds like you put it in the client and the text file, then it's okay.

It sounds better than my similar library, so nice job!
Offline GabrielBailey74
« Reply #2 - Posted 2013-06-08 21:45:32 »

I think you should add support for updating via the update date, so that people don't have to increase the version for an update if they don't want to (it seems illogical, but if you are letting people play when you are not even ready to put a version number on the game it makes sense).

That would be the way to go yes, or I could've compared the current .JAR size with the most recent .JAR size or went by dates like you suggested ^_^

This is just a little class i threw together in under a hour maybe so it's not super fancy Tongue
Barely even documented D:

Thanks for the feedback mate, I hope some people make use of this ^_^

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Sammidysam
« Reply #3 - Posted 2013-06-08 21:46:41 »

If it doesn't get used at all, don't worry about it.  My library didn't get used at all except by me and it worked extremely well for me.  Even if other people don't use it, if you can make this work extremely well for you then it is completely worth it Cheesy
Offline GabrielBailey74
« Reply #4 - Posted 2013-06-08 21:49:11 »

If it doesn't get used at all, don't worry about it.  My library didn't get used at all, except by me, and it worked extremely well for me.  Even if other people don't use it, if you can make this work extremely well for you then it is completely worth it Cheesy

Well, to be frank I have no use for this myself at the moment lol.

I programmed this version http://pastebin.com/6gu9ad63# for a member of JGO last night.
Earlier this morning I than implemented the KBS/ETA/Percentage etc and figured I'd release it before deleting it in hopes of other JGO members / web searchers finding a use for it ^_^

Offline Sammidysam
« Reply #5 - Posted 2013-06-08 21:52:22 »

Well, if it helps, I will definitely use its code as a reference to add a KB/s and ETD (estimated time done) to my library.  It's very well documented compared to mine, which will be very helpful.  Thanks!
Offline HeroesGraveDev

JGO Kernel


Medals: 245
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #6 - Posted 2013-06-08 21:53:13 »

The thing is, compared to writing a game, an auto-updater/launcher is extremely easy.
Which explains why no-one else uses it.

As in, a few files:

Main class - Manages the whole patching/launching process.
GUI handler.
Downloader.
Extractor (because I package in a .zip).
A class for loading and displaying an image in the GUI.
A separate class that writes the version number into a binary file for when I increment the version.

The only things missing is calculating the download size, and I personally don't need that. (I might add it anyway though)

EDIT: I'll give you appreciation for working out the download size. That was useful.

Offline GabrielBailey74
« Reply #7 - Posted 2013-06-08 21:56:04 »

The only things missing is calculating the download size, and I personally don't need that. (I might add it anyway though)

Rawr, It's implemented already BTW ^_^
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
   /* Obtaining the files size in kilobytes */
   private Double getURLSizeInKB(String urlStr) {
      double contentLength = 0;
      try {
         URL url = new URL(urlStr);
         HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
         contentLength = httpConn.getContentLength();
         httpConn.disconnect();
      } catch (Exception ex) {
         ex.printStackTrace();
      }
      return contentLength;
   }


The thing is, compared to writing a game, an auto-updater/launcher is extremely easy.
Which explains why no-one else uses it.

As in, a few files:

Main class - Manages the whole patching/launching process.
GUI handler.
Downloader.
Extractor (because I package in a .zip).
A class for loading and displaying an image in the GUI.
A separate class that writes the version number into a binary file for when I increment the version.
Thanks for the feedback mate ^_^

Offline HeroesGraveDev

JGO Kernel


Medals: 245
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #8 - Posted 2013-06-08 22:00:03 »

I meant the only thing missing in my patcher. Grin

Offline GabrielBailey74
« Reply #9 - Posted 2013-06-08 22:02:35 »

I meant the only thing missing in my patcher. Grin

Oh great lol. Cool
If people find this post and manage to find something to rip: yay for them :>
Mission complete.

Most of this code (ETA/KBS/Percentage) came out of a FileDownloader I made a while ago Tongue
Source code for that is here: http://www.java-gaming.org/?action=pastebin&id=603

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline HeroesGraveDev

JGO Kernel


Medals: 245
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #10 - Posted 2013-06-08 22:11:15 »

I have a list of errors that need to be handled while downloading:
  • ConnectException - Can't connect to the server. Probably because the server is down?
  • UnknownHostException - Can't find the file on the server. Possibly because of no internet connection. Possibly incorrect URL.
  • FileNotFoundException - No file associated with the URL. Maybe the file was removed or maybe the URL is wrong.
  • MalformedURLException - Incorrect URL. (syntax, not missing link)

Found by turning my internet connection on/off while downloading. Smiley

Offline GabrielBailey74
« Reply #11 - Posted 2013-06-08 22:34:33 »

I have a list of errors that need to be handled while downloading:
  • ConnectException - Can't connect to the server. Probably because the server is down?
  • UnknownHostException - Can't find the file on the server. Possibly because of no internet connection. Possibly incorrect URL.
  • FileNotFoundException - No file associated with the URL. Maybe the file was removed or maybe the URL is wrong.
  • MalformedURLException - Incorrect URL. (syntax, not missing link)

Found by turning my internet connection on/off while downloading. Smiley

Thanks mate, the only exception I managed to 'force' while fiddling with my internet was a:
1  
java.net.UnknownHostException: www.javatools.co.nf

And that only occurred while launching the updater with no internet lol.

I also launched the updater and killed the internet half way through the download and no exceptions occured :/
It just paused the download lol 0_0!

Thanks for the feedback ^_^

Offline Sammidysam
« Reply #12 - Posted 2013-06-08 22:39:08 »

Breaking the download mid-way through is the most evil thing ever.  It most of the time seems to stop the download rather than just pause it.

@HeroesGraveDev talking about the necessary files:  I don't think that having a GUI handler, extractor, or image display classes are necessary.  If you are just creating the framework to easily update files, then the person using it may want to make a custom GUI for it, or may not want one at all.
Offline HeroesGraveDev

JGO Kernel


Medals: 245
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #13 - Posted 2013-06-08 22:42:02 »

@HeroesGraveDev talking about the necessary files:  I don't think that having a GUI handler, extractor, or image display classes are necessary.  If you are just creating the framework to easily update files, then the person using it may want to make a custom GUI for it, or may not want one at all.

I wasn't referring to the framework.
I was referring to a Launcher/Patcher as a whole.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (27 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!