Skip to content

Configuring Self Update

sk89q edited this page Apr 17, 2015 · 40 revisions

The bootstrap program:

  1. Downloads the launcher from your website.
  2. Chooses a standard folder to store the launcher's files (in My Documents or the home folder).
  3. Updates the launcher automatically.

latest.json

One of the sample files is latest.json. In it, it contains a link to a pack-compressed version of the launcher for download, as well as the latest launcher version.

The file looks like:

{
    "version": "4.0.1",
    "url": "http://example.com/versions/4.0.1.jar.pack"
}

The version should correspond to the version in build.gradle (in the source code). Change "4.0.1" to whatever version is in build.gradle at the moment.

You can also change the version to build.gradle to whatever you want. Unlike the package/modpack version, this version must be a proper version string (X.Y.Z), and you should always increase it. Note that 1.1.10 is greater than 1.1.9, and 1.2.0 is greater than both 1.1.9 and 1.1.10.

Creating the .jar.pack

Take the launcher file and run it through the pack200 tool that comes with the JDK. Upload this to the website and also change the URL in latest.json (also on your site).

pack200 --no-gzip launcher.jar.pack launcher-X.Y.Z-all.jar

(That command makes launcher.jar.pack from launcher-X.Y.Z-all.jar in the same folder.)

Customizing the Bootstrapper

Inside the folder launcher-bootstrap/src/main/resources/com/skcraft/launcher/ will be:

  • lang/, which contains language files you should change
  • bootstrap.properties, which contain important settings you must change
  • bootstrapper_icon.png, which is the bootstrapper icon

Bootstrap Resources

The properties file is one of the most important. It looks like:

homeFolderWindows=Example Launcher
homeFolder=.examplelauncher
launcherClass=com.skcraft.launcher.Launcher
latestUrl=http://example.com/latest.json
  • "homeFolderWindows" is the folder in "My Documents" (i.e. C:\Users\Name\Documents\Example Launcher)
  • "homeFolder" is the folder in the user's home folder (i.e. /home/.examplelauncher)
  • "launcherClass" does not need to be changed unless you are using the Fancy Launcher
  • "latestUrl" should point to latest.json on your website

Recompiling

  1. Recompile the entire launcher again (using gradlew clean build).
  2. Double click the -all.jar file in launcher-bootstrap/build/libs to make sure it works.
  3. Check your home folder (BSD/Linux/Mac OS X users) or My Documents (Windows users) to see the folder name that you used.

My Documents

If everything works, you are done! Give players a copy of the bootstrapper -all.jar file.

Distributing Executables

While you can provide the .jar for download, it comes with two downfalls: (1) the file will be useless if Java is not already installed; and (2) your launcher will have no program icon.

There are two ways to solve the problem:

  1. Create .exe and .app wrappers for Windows and Mac OS X.
  2. Create an installer that automatically installs Java and sets up shortcuts.

.exe Wrapper

There are several tools that create an .exe from a .jar:

The author has personal experience with launch4j and can recommend it, but the other options may work even better.

Later versions of Internet Explorer and Google Chrome will mark executables as untrustworthy by default unless they have been downloaded thousands of times, the executable is downloaded from a trusted website (determined by the company behind each respective browser), or the executable has been been digitally signed (which involves the cost of a "code signing certificate"). To run an untrusted executable, the user has to find the hidden "ignore this warning" button.

Signing the executable is the easiest way to prevent these complications, but it does come with monetary costs. If you want to instead rely on your executable accruing many downloads, make sure to use the bootstrapper for your executable. You will probably only ever release one version of the bootstrapper, so you won't ever "clear" the download count.

With the bootstrapper, you can still release as many launcher updates as you want.

.app Wrapper

Apple provides tools to create .app bundles of .jar files.

Windows users without access to Mac OS X can create .zip.app bundles using Maven, Ant and Gradle, but this is outside the scope of the article. Since the launcher is already built using Gradle, modifying the build files to also produce .zip.apps is perhaps the easiest approach. Be aware, however, that the Gradle plugin for building these Mac OS X applications is pretty limited compared to its Maven plugin counterpart, and did not even work for the author.

Linux Package

It is possible to build a Linux package for every Linux distribution that you are interested in, but this is outside the scope of the article. It is easiest to just provide the .jar for Linux users.

Pushing Launcher Updates

Whenever you want to push an update:

  1. Update the version in build.gradle (NOTE: Unlike the versions for modpacks, this version should actually be a proper version like #.#.# or #.#, or #).
  2. Recompile the launcher.
  3. Upload the pack-compressed version of your .jar.
  4. Update the version number and URL in latest.json.

You never should need to update the bootstrapper.

Clone this wiki locally