Home viewtut
User Name
passwordPassword
x
Hello guest!, by login to this site, you can add and edit your own server, if you haven't registered yet, click me

How to Add AutoUpdater to your client[Non]
August 21, 2015, 6:50PM Posted by: Thejuzo
Purpose: Adding Auto Updater to your client, that checks , if there is new version, and if there is really, it will download too


this updater downloads your client to your root folder of your client and replaces all old files in that folder.
This updater extract your client.zip, that client has downloaded, so you dont have to worry.

Difficulty: 2/10

Tested On: Project Fubergen clients since v4

Assumed Knowledge: Copy and Paste
Classes Modified: client.java, Gui.java

Compatible: Fubergen clients, bluurr clients with some modifications




Before you start doing anything stupid, take backup and shits.

+ You need your own website, i am not telling where to get that, you should know that. + I am not telling what is ftp and how to use, otherwise leave this


Lets start this shit





Make version.php with notepad

and put this


Code:
Code:
Code:
1.0

Note: 1.0 is your current client version, eg if you have been updated your client to v2, in this case you would put to version.php 2.0. So everyone who is using 1.0 is getting notice about, that new client is released, in this case it would be 2.0, simply ehh lol

after you have created version.php

Via ftp, upload it to your root [public_html].

after you have done, we starts editing client.java

so open client.java


add this string


Code:
Code:
Code:
public String Version="Your Client version here, eg 1.0";

so it should look like this


public String Version=1.0";

Add these to client.java






private Class30_Sub2_Sub1_Sub1 aClass30_Sub2_Sub1_Sub1_966;
private Class30_Sub2_Sub1_Sub1 aClass30_Sub2_Sub1_Sub1_967;




Code:
Code:
Code:
public void CheckVer()
	    {
	    System.out.println("Version Checker");
	    System.out.println("Checking Client Version......");
	    String Outcome=checkVersion();
	    if(!Version.equalsIgnoreCase(Outcome))
	    {
	    System.out.println("LATEST VERSION: " + Outcome);
	    System.out.println("PLEASE DOWNLOAD FROM: Yourdomain.com or yourdomain.com");
	    System.out.println("===========================================================);
		System.out.println("If you still want use this version, then change this,");
System.out.println("public String Version=yourclientnumberhere; in client.java to Latest version's number");
	    System.out.println("--------------------------------------------------");
		System.out.println("We recommend to download latest client");
updateAvail();
	    
	    }
	    else {
	    System.out.println("Client is up to date. ");
		        System.out.println("Loading client!");
	    System.out.println("--------------------------------------------------");

	    }
	    }
public void omfg()
    {
        JOptionPane.showMessageDialog(this,  "No new version available at this time");

      
    }
public void updateAvail()
    {
   
        JOptionPane.showMessageDialog(this,  "There is New client Available to download via Update button");

   
}
public String checkVersion()
	    {
	    String s1="";
	        try
	        {
	            URL url=new URL("http://yourdomain.com/version.php");
	            URLConnection urlconnection=url.openConnection();
	            BufferedReader bufferedreader=null;
	            bufferedreader=new BufferedReader(new InputStreamReader(urlconnection.getInputStream()));
	            s1=bufferedreader.readLine();
	            bufferedreader.close();
	        }
	        catch(Exception exception) { }
	        return s1;
	    }
Remember replace yourdomain.com with your website url.

step 2

Search


Code:
Code:
Code:
aClass30_Sub2_Sub1_Sub1_967.method348(l - 73, 16083, k1 - 20);
under it you should see something like this


Code:
Code:
Code:
aClass30_Sub2_Sub1_Sub4_1272.method382
replace About or w.e its in your client with "Update"

in my client it would look like this.


Code:
Code:
Code:
aClass30_Sub2_Sub1_Sub4_1272.method382(0xffffff, l, anInt939, "Update", k1 + 5, true);

then search
" if(anInt833 == 3) "

Replace those two " if(anInt833 == 3)" with this


Code:
Code:
Code:
 if(anInt833 == 3) 
	    {
String Outcome=checkVersion();
Updater Updater=new Updater();
checkVersion();
	   if(!Version.equalsIgnoreCase(Outcome)) 
Updater.get("http://YOURDOMAINHERE.com/client.zip", "client.zip", "", "YOUR client"); 


aClass30_Sub2_Sub1_Sub4_1272.method382(0xffffff, c / 2, anInt939, "Project Fubergen Lite v1.1 Client ", c1 / 2 - 60, true);
            int k=c1 / 2 - 35;
            aClass30_Sub2_Sub1_Sub4_1272.method382(0xffffff, c / 2, anInt939, "", k, true);
            k += 15;
            aClass30_Sub2_Sub1_Sub4_1272.method382(0xffffff, c / 2, anInt939, "", k, true);
            k += 15;
            aClass30_Sub2_Sub1_Sub4_1272.method382(0xffffff, c / 2, anInt939, "No new version available", k, true);
            k += 15;
			   aClass30_Sub2_Sub1_Sub4_1272.method382(0xffffff, c / 2, anInt939, " ", k, true);
            k += 15;
				aClass30_Sub2_Sub1_Sub4_1272.method382(0xfffffF, c / 2, anInt939, "", k, true);
            k += 15;

			aClass30_Sub2_Sub1_Sub4_1272.method382(0x0099FF, c / 2, anInt939, "", k, true);
            k += 15;
            int j1=c / 2;
            int i2=c1 / 2 + 50;
            aClass30_Sub2_Sub1_Sub1_967.method348(j1 - 73, 16083, i2 - 20);
            aClass30_Sub2_Sub1_Sub4_1272.method382(0x33CCFF, j1, anInt939, "Back", i2 + 5, true);

 } else if(anInt833 == 3) { 
 aClass30_Sub2_Sub1_Sub4_1272.method382(0xffffff, c / 2, anInt939, "No New version available ", c1 / 2 - 60, true);
            int k=c1 / 2 - 35;
            aClass30_Sub2_Sub1_Sub4_1272.method382(0xffffff, c / 2, anInt939, "", k, true);
            k += 15;
            aClass30_Sub2_Sub1_Sub4_1272.method382(0xffffff, c / 2, anInt939, "", k, true);
            k += 15;
            aClass30_Sub2_Sub1_Sub4_1272.method382(0xffffff, c / 2, anInt939, "Yourdomain.com and register", k, true);
            k += 15;
			   aClass30_Sub2_Sub1_Sub4_1272.method382(0xffffff, c / 2, anInt939, " ", k, true);
            k += 15;
				aClass30_Sub2_Sub1_Sub4_1272.method382(0xfffffF, c / 2, anInt939, "", k, true);
            k += 15;

			aClass30_Sub2_Sub1_Sub4_1272.method382(0x0099FF, c / 2, anInt939, "", k, true);
            k += 15;
            int j1=c / 2;
            int i2=c1 / 2 + 50;
            aClass30_Sub2_Sub1_Sub1_967.method348(j1 - 73, 16083, i2 - 20);
            aClass30_Sub2_Sub1_Sub4_1272.method382(0x33CCFF, j1, anInt939, "Back", i2 + 5, true);
        }
step 3.

Open signlink.java

add this


Code:
Code:
Code:
public static final String updatedir()
    {
        String s;
        String s1;
        File file;
        s="";
        s1=".";
        file=new File((new StringBuilder()).append(s1).append(s).toString());
        if(file.exists() || file.mkdir())
        {
            return (new StringBuilder()).append(s1).append(s).append("/").toString();
        }
        return null;
    }
step 4.

make new java file called "Updater.java"

and paste this

Code:
Code:
Code:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import javax.swing.*;
import sign.signlink;
import java.net.*;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.swing.JOptionPane;
import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.*;
import java.io.*;
import java.math.BigInteger;
import java.net.*;
import java.util.zip.CRC32;
import sign.signlink;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.sound.midi.*;
import javax.sound.sampled.*;
import javax.swing.JOptionPane;
import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.*;
import java.io.*;
import java.math.BigInteger;
import java.net.*;
import java.util.zip.CRC32;
import sign.signlink;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.sound.midi.*;
import javax.sound.sampled.*;
import javax.swing.JOptionPane;

public class Updater extends Thread
{

    public String name;
    public String dir;


    public void get(String url, String name1, String dir1, String type)
    {
        dir=dir1;]true);
        JFrame frame=new JFrame("Fubergen client  Downloader");
        frame.setLocationRelativeTo(null);
        frame.setLayout(new BorderLayout());
        frame.setPreferredSize(new Dimension(500, 80));
        frame.setResizable(false);
        frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        client client=new client();
        ClassLoader cl=getClass().getClassLoader();
        try
        {
            URLConnection connection=(new URL(url)).openConnection();
            String f[]=url.split("/");
            File file=new File(f[f.length - 1]);
            int length=connection.getContentLength();
            InputStream instream=connection.getInputStream();
            try{new File(signlink.updatedir()+dir).mkdir();}catch(Exception e){}
            FileOutputStream outstream=new FileOutputStream(signlink.updatedir()+dir+file);
            int][size=0;
            int copy=0;
            JProgressBar bar=new JProgressBar();
            bar.setStringPainted(true);
            bar.setMaximum(length);
            frame.add(bar, "Center");
            frame.pack();
            frame.setVisible(true);
            while((copy=instream.read()) != -1)
            {
                outstream.write(copy);
                size++;
                int percentage=(int)(((double)size / (double)length) * 100D);
                bar.setValue(size);
                bar.setString("Downloading "+type+" "+percentage+"%");
            }
            if(length != size)
            {
                instream.close();
                outstream.close();
            } else
            {
                bar.setString("Unpacking files...");
                instream.close();
                outstream.close();
                   unZipFile(); 
deleteFile();  
System.exit(0);


                frame.setVisible(false);
            }
        }
        catch(Exception e)
        {
            System.err.println("Error connecting to update server.");
            e.printStackTrace();
        }
    }

    private void writeStream(InputStream In, OutputStream Out) throws IOException
    {
        byte Buffer[]=new byte[1024];
        int Len;
        while((Len=In.read(Buffer)) >= 0)
        {
            Out.write(Buffer, 0, Len);
        }
        In.close();
        Out.close();
    }

    private void unZipFile()
    {
        try
        {
            ZipFile ZipFile=new ZipFile(signlink.updatedir()+dir+name);
            for(Enumeration Entries=ZipFile.entries(); Entries.hasMoreElements();)
            {
                ZipEntry Entry=(ZipEntry)Entries.nextElement();
                if(Entry.isDirectory())
                {
                    (new File(signlink.updatedir()+dir+Entry.getName())).mkdir();
                } else
                {
                    
                writeStream(ZipFile.getInputStream(Entry), new BufferedOutputStream(new FileOutputStream(signlink.updatedir()+dir+Entry.getName())));
}
            }
            ZipFile.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

    private void deleteFile()
    {
        try
        {
            File file=new File(signlink.updatedir()+dir+name);		
            file.delete();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }


}
save.


step 5. [Updater menu to gui] you might need to modify this to make it work in your gui [this part is optional]


add this to there, where you see other similar code like this is


Code:
Code:
Code:
JMenu estemenu=new JMenu("Update?");
add this to there, where you see other similar code like this is

String[] esteButtons=new String[]
{
"Update", "Why update?"
};


add this to there, where you see other similar code like this is

Code:
Code:
Code:
for (String name : esteButtons)
						{
							JMenuItem menuItem=new JMenuItem(name);
							if (name.equalsIgnoreCase("-"))
								esteMenu.addSeparator();
							else
							{
								menuItem.addActionListener(this);
								estemenu.add(menuItem);
							}
			}
add this to there, where you see other similar code like this is


Code:
Code:
Code:
menuBar.add(estemenu);
search "public void actionPerformed(ActionEvent actionevent)"
there might be similar code like that

but if you found, add these


Code:
Code:
Code:
if(s.equalsIgnoreCase("Update"))
            {
                int k1;
                if((k1=JOptionPane.showConfirmDialog(this, "Do you want to check for latest updates?")) == 0)
                {
                    String Outcome=checkVersion();
                    Updater updater=new Updater();
                    checkVersion();
                    if(!Version.equalsIgnoreCase(Outcome))
                    {
CheckVer();
                        updater.get("http://yourdomain.com/client.zip", "client.zip", "", "Your client");
                    }
                    else 
omfg();

                }
                return;
            }

if (s.equalsIgnoreCase("Why update?"))
{
				JOptionPane.showMessageDialog(frame, "Updating is recommend to keep your client up to date");
}



Optional [To make client check if new update available at startup]


find in client.java


Code:
Code:
Code:
public final void method6()
under "method13(20, (byte)4, "Starting up Client");"

add this

CheckVer();



NOTE: There might be missed methods, report if there is and ill add those.

credits: Me, Dj Java , i justin i and Ricscape
  How to Add AutoUpdater to your client[Non] Comments (0)
No Comments
Post A Comment



Next server list update: 2 Minutes and 19 seconds (10:31:08 am)
92%

Newest Server: Psdaf
Newest member: devrandeniz
Last logged members in 24hours: