Patching/Updating games - How would it work?

i think the client would just get it with http or ftp. seems like thatd be easiest

You don’t send files. You have the files on the server, the updater queries for a version from the server, and downloads the new files using HTTP or FTP.

Basically, what you would do, is have a file on server. (Dropbox, etc.)

You would have a version file on the server, and a version file in the updater jar. When the jar launches you would have to download the version.txt from the server and compare that data to your version.txt. (I have source code to show in a minute)

If the versions do not match, update.

What you would do is then download the new game files from the server and they will replace the old ones. (You would also need to update the version file in the jar to the correct version so that it doesn’t constantly download the same update)

Now, your going to run into a problem if your resources for your jar are packaged outside of the jar and in a folder. There is no way for the updater to know that there is a new resource file because it has never heard of it before. (Atleast, from what i’ve learned there isn’t a way) So what I do is if im going to package a game with an auto-updater I put a few empty sprite sheets that it download automatically just incase you add more art. Now, I haven’t found a way with sound. I would suspect that you could just package everthing in the jar but, whatever.

Hope this helps.

Heres a little code:

TextFile Reader Class (Only reads one line)


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class TextFile {

	private static String line;
	
	public static String readFile(String path) {
		BufferedReader file;
		try {
			file = new BufferedReader(new FileReader(path));
			line = file.readLine();
			file.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return line;
	}
	
	public static void writeFile(String path, String text) {
		FileWriter file;
		try {
			file = new FileWriter(path);
			file.write(text);
			file.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
}

Updater Class


import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;

import javax.swing.JOptionPane;

public class Updater {

	private static String currentVersion, newVersion;
	public static int update = 0;
	
	public static void checkForUpdate(boolean isAuto) {
		currentVersion = TextFile.readFile("./version.txt"); //Change this to a read file later
		
		try {
			URL site = new URL("https://raw.githubusercontent.com/JacobPickens/ecsl-version/master/version.txt");
			ReadableByteChannel rbc = Channels.newChannel(site.openStream());
			FileOutputStream fos = new FileOutputStream("./version.txt");
			fos.getChannel().transferFrom(rbc, 0, 1 << 24);
			fos.close();
		} catch(IOException e) {
			e.printStackTrace();
		}
		
		newVersion = TextFile.readFile("./version.txt");
		
		if(currentVersion.equals(newVersion)) {
			TextFile.writeFile("./version.txt", newVersion);
			
			try {
				URL site = new URL("http://i.imgur.com/A67BGOv.gif?1");
				ReadableByteChannel rbc = Channels.newChannel(site.openStream());
				FileOutputStream fos = new FileOutputStream("./img.gif");
				fos.getChannel().transferFrom(rbc, 0, 1 << 24);
				fos.close();
			} catch(IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	public static void finishUpdate() {
		JOptionPane.showMessageDialog(null, "Game has been updated to " + newVersion, "Update Completed", JOptionPane.INFORMATION_MESSAGE);
		System.exit(0);
	}
	
	public static void doNotUpdate() {
		JOptionPane.showMessageDialog(null, "No Update Found", "Updater", JOptionPane.INFORMATION_MESSAGE);
		return;
	}
	
}


Jacob, why can’t you check if your resource files have changed? Its easy. First off, there’s some fundamental changes I would make to how you’re pulling updates.

Check the version against the server. If the server tells you to update the game, request an update text file from the server. The text file will contain a list of resources, including class files and actual image/sound files and where they are located on the server. The client will receive the text file, then request the new files to be downloaded. This way you can switch servers easily. If you send the URL of the file on the server, the client won’t care what server its downloading from or where. All it knows is that it needs to request a file from the URL specified.

Much more flexible than just guessing what files you need to be updated.

Thanks! That makes a lot of sense. I was wondering how to transfer files wireless.(wirelessly isn’t a word?) But yeah, this helps.

e resources in to one text file?

By a list of resources, do you mean somehow compressing all of th

No… You can’t “compress” files into a text file.

What I meant was have a list of URLs of where the files are located. For instance:

And so on.