Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Autoupdater (jar)

Featured Replies

This might not be the best way to write an autoupdater, but it's the way I've done it:

 

Setup:

 

On server, have the jar file (CMHEssMiner.jar) and a versioninfo file.

  • CMHEssMiner.jar is the jar file (duh)
  • versioninfo contains one line with the version (eg. "0.8.3 BETA" -- no quotes)

In the code, create a constant:

public final String version = "0.8.3 BETA"

in the onStart method:

URL url = null;
try {
	url = new URL("http://osbot.no-ip.org/distfiles/versioninfo");
} catch (MalformedURLException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
InputStream is = null;
try {
	is = url.openConnection().getInputStream();
} catch (IOException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
try {
	String line = reader.readLine();
	if (!line.equals(currentVersion)) {
		updateScript(line);
		canStart = false;
		return;
	}
} catch (IOException e) {
}

I created a separate method for the updating part:

private void updateScript(String version) {
	try {
		URL url = new URL(
				"http://osbot.no-ip.org/distfiles/CMHEssMiner.jar");
		InputStream in = url.openStream();
		int bytesRead;
		byte[] buf = new byte[4 * 1024];
		String filename;
		if (System.getProperty("os.name").startsWith("Window")) {
			filename = "\\OSBot\\scripts\\CMHEssMiner.jar";
		} else {
			filename = "/OSBot/scripts/CMHEssMiner.jar";
		}
		OutputStream os = (new FileOutputStream(
				System.getProperty("user.home") + filename));
		while ((bytesRead = in.read(buf)) != -1) {
			os.write(buf, 0, bytesRead);
		}
		os.flush();
		os.close();
		in.close();
		JOptionPane.showMessageDialog(null, "Script has been automatically updated to version" + version + ". Please refresh your scripts list and run the script again.");
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}

If anyone has a better way to do this or suggestions, I'd love to hear them :D

Eric

Looks nice, only thing I can think to suggest is using getVersion() and update the version in the script manifest instead of making a new variable to hold the version

  • Author

Looks nice, only thing I can think to suggest is using getVersion() and update the version in the script manifest instead of making a new variable to hold the version

 

The version variable in the script manifest is a double right? That wouldn't allow me to number my versions as things like 0.8.3 because 0.8.3 can't be stored as a double. But yeah it does get annoying to change the version number in three different places instead of just updating the version in the script manifest :P

 

Eric

Yeah and also say I was releasing version 30 of my script, I would write the version as 1.30 but it becomes 1.3

Edited by Diclonius

Yeah and also say I was releasing version 30 of my script, I would write the version as 1.30 but it becomes 1.3

Time to release 2.0 then xD

Nice updater!

I'll test this out and improve if I can!

Thx for thx for the snippet!

Grtz

H0ppy

This part of the script is useless

		if (System.getProperty("os.name").startsWith("Window")) {
			filename = "\\OSBot\\scripts\\CMHEssMiner.jar";
		} else {
			filename = "/OSBot/scripts/CMHEssMiner.jar";
		}

just use "/" for both.

  • Author

This part of the script is useless

		if (System.getProperty("os.name").startsWith("Window")) {
			filename = "\\OSBot\\scripts\\CMHEssMiner.jar";
		} else {
			filename = "/OSBot/scripts/CMHEssMiner.jar";
		}

just use "/" for both.

 

Does windows take both? I didn't know that. Thanks :D

 

Eric

 

This part of the script is useless

		if (System.getProperty("os.name").startsWith("Window")) {
			filename = "\\OSBot\\scripts\\CMHEssMiner.jar";
		} else {
			filename = "/OSBot/scripts/CMHEssMiner.jar";
		}

just use "/" for both.

 

Does windows take both? I didn't know that. Thanks biggrin.png

 

Eric

 

 

If you really wanted it to be cross platform, just use

System.getProperty("file.separator")

If you really wanted it to be cross platform, just use

System.getProperty("file.separator")

 

The only correct answer I've seen on this topic smile.png

 

Also "user.dir" will give you OSBot's directory:

String fs = System.getProperty("file.separator");
String dir = System.getProperty("user.dir") + fs + "scripts" + fs + jarName;

All in all quite a good updater though. A bit sad that this isn't already included in the client.

Normally you would write the file to a temp location just in case the existing one is currently being used, but in OSBot's case you don't need to.

Edited by Kronos

Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.