Thread: Auto Updater Best Yet v1.1

Page 1 of 9 123 ... LastLast
Results 1 to 10 of 87
  1. #1 Auto Updater Best Yet v1.7 
    Registered Member

    Join Date
    Sep 2009
    Posts
    201
    Thanks given
    0
    Thanks received
    17
    Rep Power
    147
    basically instead of zipping your cache you can use this to generate a xml whitch you upload to your webserver aswell as your open cache and it will check the crc32 to the client cache files and if there outdated it will update them aswell as sprites ect and once the cache files are downloaded the client starts first time without a restart

    in action:


    Updates:
    11/03/2011 - Added download speed updated Updater.java
    13/03/2011 - The gui now does not show unless there are updates
    14/03/2011 - Fixed up updater not downloading stuff in subfolders
    14/03/2011 - Fixed download speed
    14/03/2011 - Fixed crc genertator should fix all path errors
    28/01/2014 - Removed uid.dat from getting added to patch.xml and also any files containing .java, .class or .jar
    Patch Generator (this is not for the client):
    dont put this in the cache directory just set the path to it and run it then go there to get patch.xml
    or it will just add the classes and the batch to the update
    Code:
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.PrintWriter;
    import java.util.zip.CRC32;
    
    
    public class CrcGenerator {
         static PrintWriter out;
         static String Root = System.getProperty("user.home") + "/EpicPkz/";
    	  public static void main(String[] args) throws IOException {
    		  FileWriter outputFileReader = new FileWriter(Root + "Patch.xml");
    		 out = new PrintWriter(outputFileReader);
    		 out.println("<?xml version='1.0'?>");
    		 out.println("<Steven>");
    		    File aFile = new File(Root);
    		    Process(aFile);
    
    		    out.println("</Steven>");
    		    out.close();
    		  }
    	  static void Process(File aFile) {	
    	    if(aFile.isFile() && !aFile.getName().contains("uid.dat") && !aFile.getName().contains(".jar") && !aFile.getName().contains(".class") && !aFile.getName().contains(".bat") && !aFile.getName().contains("Thumbs.db") && !aFile.getName().contains("Patch.xml")) {
    	    	out.println("	<Update>");
    	    	out.println("		<name>" + aFile.getName() + "</name>");
    	    	String s = Root;
    	    	s = s.substring(0, s.length()-1);
    	    	out.println("		<dir>" + aFile.getParent().replace(Root.replace("/", "\\"), "").replace(s.replace("/", "\\"), "")+ "</dir>");
    	    	out.println("		<size>" + aFile.length() + "</size>");
    	    	out.println("		<crc>" + doConvert32(aFile) + "</crc>");
    	    	out.println("	</Update>");
    	    } else if (aFile.isDirectory()) {
    	      File[] listOfFiles = aFile.listFiles();
    	      if(listOfFiles!=null) {
    	        for (int i = 0; i < listOfFiles.length; i++)
    	          Process(listOfFiles[i]);
    	      }
    	    }
    	  }
    	  public static String doConvert32(File file)
    	    {
    	        byte[] bytes = readBytesFromFile(file);
    	        CRC32 x = new CRC32();
    	        x.update(bytes);
    	        return (Long.toHexString(x.getValue())).toUpperCase();
    	    }
    
    	    private static byte[] readBytesFromFile(File file)
    	    {
    	        try
    	        {
    	            InputStream is = new FileInputStream(file);
    	            long length = file.length(); 
    	            byte[] bytes = new byte[(int)length]; 
    	            int offset = 0; 
    	            int numRead = 0; 
    	            while (offset < bytes.length && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0)
    	            { 
    	                offset += numRead; 
    	            } 
    	            if (offset < bytes.length) { 
    	                System.out.println("Could not completely read file " + file.getName()); 
    	            } 
    	            is.close(); 
    	            return bytes;
    	        }
    	        catch (IOException e)
    	        {
    	            System.out.println("IOException " + file.getName()); 
    	            return null;
    	        }
    	    }
    }
    now for the client
    make a new java file called Updater.java in the sign folder if you have one

    copy and paste this:
    Code:
    package sign;
    
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.ArrayList;
    import java.util.zip.CRC32;
    
    import javax.swing.BoxLayout;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JProgressBar;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    
    
    public class Updater {
    	static String updateurl, Root;
    	static ArrayList<String> Name = new ArrayList<String>();
    	static ArrayList<String> Dir = new ArrayList<String>();
    	static int TotalSize, SizeNow;
    	static JLabel label1 = new JLabel();
    	static JLabel label2 = new JLabel("Total percent");
    	static JProgressBar progressBar,  progressBar1;
    	static JFrame frame = new JFrame("Cache Updater");
    	
        public static void addComponentsToPane(Container pane) {
            pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
            label1.setAlignmentX(Component.CENTER_ALIGNMENT);
    		pane.add(label1);
    		progressBar = new JProgressBar(0, 100);
    		progressBar.setValue(0);
    		progressBar.setStringPainted(true);
    		progressBar.setAlignmentX(Component.CENTER_ALIGNMENT);
    		pane.add(progressBar);
    		label2.setAlignmentX(Component.CENTER_ALIGNMENT);
    		pane.add(label2);
    		progressBar1 = new JProgressBar(0, 100);
    		progressBar1.setValue(0);
    		progressBar1.setStringPainted(true);
    		progressBar1.setAlignmentX(Component.CENTER_ALIGNMENT);
    		pane.add(progressBar1);
        }
        
    	public static void Update(String UpdateUrl, String CacheDirectory) {
        	updateurl = UpdateUrl;
        	Root = CacheDirectory;
    		frame.setResizable(false);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		addComponentsToPane(frame.getContentPane());
    		frame.setLocationRelativeTo(null);
    		frame.setPreferredSize(new Dimension(400, 120));
    		frame.pack();
    		download("", "Patch.xml", false);
    		 try {
    			  File file = new File(Root+ "Patch.xml");
    			  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    			  DocumentBuilder db = dbf.newDocumentBuilder();
    			  Document doc = db.parse(file);
    			  doc.getDocumentElement().normalize();
    			  NodeList nodeLst = doc.getElementsByTagName("Update");
    			  for (int s = 0; s < nodeLst.getLength(); s++) {
    			    Node fstNode = nodeLst.item(s);
    			    
    			    if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
    			      Element fstElmnt = (Element) fstNode;
    			      String name, dir, size, crc;
    			      NodeList name1 = fstElmnt.getElementsByTagName("name");
    			      Element name2 = (Element) name1.item(0);
    			      NodeList name3 = name2.getChildNodes();
    			      name = ((Node) name3.item(0)).getNodeValue();
    			      
    			      NodeList dir1 = fstElmnt.getElementsByTagName("dir");
    			      Element dir2 = (Element) dir1.item(0);
    			      NodeList dir3 = dir2.getChildNodes();
    				  if(((Node) dir3.item(0)) == null)
    				  dir = "";
    				  else
    			      dir = ((Node) dir3.item(0)).getNodeValue();
    			      
    			      NodeList size1 = fstElmnt.getElementsByTagName("size");
    			      Element size2 = (Element) size1.item(0);
    			      NodeList size3 = size2.getChildNodes();
    			      size = ((Node) size3.item(0)).getNodeValue();
    			      
    			      NodeList crc1 = fstElmnt.getElementsByTagName("crc");
    			      Element crc2 = (Element) crc1.item(0);
    			      NodeList crc3 = crc2.getChildNodes();
    			      crc = ((Node) crc3.item(0)).getNodeValue();
    			      File f = new File(Root+"\\"+dir+"\\"+name);
    			      if(f.exists()) {
    			      String crc21 = doConvert32(f);
    			      if(!crc21.contains(crc.toString())) {
    			    	  TotalSize += Integer.parseInt(size);
    			    	  Name.add(name);
    			    	  Dir.add(dir);
    			      }
    			    } else {
    			    	  TotalSize += Integer.parseInt(size);
    			    	  Name.add(name);
    			    	  Dir.add(dir);
    			    }
    			    }
    			  }
    			  } catch (Exception e) {
    			    e.printStackTrace();
    			  }
    			  if(Name.size() > 0){
    				  frame.setVisible(true);
    				  download(Dir.get(0), Name.get(0), true);
    			  } else {
    				frame.setVisible(false);
    				frame.dispose();
    			  }
    	}
    	
    	public static void download(String dir, String name, boolean check)
        {
            try
            {
                URLConnection connection = (new URL(updateurl+dir.replace("\\", "/").replace(" ", "%20")+"/"+name.replace(" ", "%20"))).openConnection();
                File file = new File(Root+dir+"\\"+name);
                int length = connection.getContentLength();
                InputStream instream = connection.getInputStream();
                try{
                        if(file.exists()){
                        file.delete();
                        }
                        String Dir[] = dir.split("\\\\");
                        String dict = "";
                        for(int i = 0; i < Dir.length; i++) {
                        	dict+= Dir[i] + "\\";
                        new File(Root+"\\"+dict).mkdir();
                        }
                    }
                    catch(Exception e)
                    {
                        e.printStackTrace();
                    }
                FileOutputStream outstream = new FileOutputStream(file);
                int size = 0;
                int copy;
                byte[] buffer = new byte[4096];
    			int previousAmount = 0;
                while((copy = instream.read(buffer)) != -1)
                {                
                	outstream.write(buffer, 0, copy);
                    size+= copy;
    				if(check) {            	
            	    int bytesPerSecond = (size-previousAmount);
            	    previousAmount = size;
                    SizeNow += copy;                
    				int percentage = (int)(((double)size / (double)length) * 100D);
                    int percentage2 = (int)(((double)SizeNow / (double)TotalSize) * 100D);
    				progressBar.setValue(percentage);
                    progressBar1.setValue(percentage2);
                    label1.setText("Downloading: " + name + " (" + bytesPerSecond + " Kb/s)");
    				}
                }
                if(length != size)
                {
                    instream.close();
                    outstream.close();
                    System.out.println("error");
                } else {
                	if(check) {
    				  if(Name.size() > 1){
    					  Name.remove(0);
    					  Dir.remove(0);
    			          instream.close();
    			          outstream.close();
    					  download(Dir.get(0), Name.get(0), true);
    				  } else {
                    instream.close();
                    outstream.close();
                    label1.setText("Done");
    				frame.setVisible(false);
    				frame.dispose();
    				  }
                	} else {
                        instream.close();
                        outstream.close();
                	}
                }
            }
            catch(Exception e)
            {
                System.err.println("Error connecting to server." + e);
                e.printStackTrace();
            }
        }
    	
        public static String doConvert32(File file)
        {
            byte[] bytes = readBytesFromFile(file);
            CRC32 x = new CRC32();
            x.update(bytes);
            return (Long.toHexString(x.getValue())).toUpperCase();
        }
    
        private static byte[] readBytesFromFile(File file)
        {
            try
            {
                InputStream is = new FileInputStream(file);
                long length = file.length(); 
                byte[] bytes = new byte[(int)length]; 
                int offset = 0; 
                int numRead = 0; 
                while (offset < bytes.length && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0)
                { 
                    offset += numRead; 
                } 
                if (offset < bytes.length) { 
                    System.out.println("Could not completely read file " + file.getName()); 
                } 
                is.close(); 
                return bytes;
            }
            catch (IOException e)
            {
                System.out.println("IOException " + file.getName()); 
                return null;
            }
        }
    
    }
    now in signlink.java under:
    Code:
    public final class signlink
        implements Runnable
    {
    add:
    Code:
    static boolean updated = false;
    now under:
    Code:
    socketip = inetaddress;
    add:
    Code:
    		if(updated == false) {
    		updated = true;
    		Updater.Update("http://lol.com/Patch/", System.getProperty("user.home") + "/EpicPkz/");
    		}
    Reply With Quote  
     


  2. #2  
    Banned

    Join Date
    Oct 2010
    Posts
    1,731
    Thanks given
    56
    Thanks received
    97
    Rep Power
    0
    W000000t 1st post!!! This is awesome i am soo using it!
    Reply With Quote  
     

  3. #3  
    Registered Member

    Join Date
    Sep 2009
    Posts
    201
    Thanks given
    0
    Thanks received
    17
    Rep Power
    147
    thanks no prob made something like it in c# years ago so i though why do u need to keep making cache folders just to update a few files and making all your players redownload again was just getting annoying
    Reply With Quote  
     

  4. #4  
    ̿ ̿̿ ̿̿ ̿̿̿'̿'\̵͇̿̿\=(•̪

    Dragonking's Avatar
    Join Date
    May 2008
    Posts
    2,011
    Thanks given
    16
    Thanks received
    31
    Rep Power
    567
    Good job man i might use idk yet though


    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  5. #5  
    Registered Member

    Join Date
    Sep 2009
    Posts
    201
    Thanks given
    0
    Thanks received
    17
    Rep Power
    147
    it checks for updates when the client is launched there is no differance really appart from a gui that starts up just before the client checking for updates
    Reply With Quote  
     

  6. #6  
    Banned

    Join Date
    Oct 2010
    Posts
    1,731
    Thanks given
    56
    Thanks received
    97
    Rep Power
    0
    Damn epicsauce xD
    Reply With Quote  
     

  7. #7  
    Donator Market Banned Market Banned

    Usaclub's Avatar
    Join Date
    Aug 2010
    Age
    25
    Posts
    512
    Thanks given
    119
    Thanks received
    37
    Rep Power
    29
    Nice!

    My Vouches..
    Spoiler for Vouches:

    Quote Originally Posted by Benes View Post
    Very good!
    Quote Originally Posted by Jesper_ View Post
    Big vouch for you!!! Thanks for your auto donation system.
    Quote Originally Posted by Light View Post
    vouch, Bought summoning & extra. Went first and was done smoothly. Rep++
    Quote Originally Posted by Grim Line View Post
    Brought all of it. Very good trade very good guy
    Quote Originally Posted by HyBriDPvP View Post
    Vouch for this guy (I bought scripts and now i got my domain up and running with the WC maker (Rsps-HQ.com)) Ty!!!
    Quote Originally Posted by chri55w View Post
    vouch bought vote4cash, was done very quickly and payment went smooth
    Rep++ too
    thanks
    Quote Originally Posted by muporz View Post
    Vouch, bought vote4points $5, he even went first.
    Thanks .

    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  8. #8  
    Registered Member
    Chiief's Avatar
    Join Date
    Jun 2010
    Posts
    1,546
    Thanks given
    69
    Thanks received
    238
    Rep Power
    611
    Not bad.

    Reply With Quote  
     

  9. #9  
    Banned

    Join Date
    Oct 2010
    Posts
    1,731
    Thanks given
    56
    Thanks received
    97
    Rep Power
    0
    This is posted the day I actually start looking for one without avail
    Reply With Quote  
     

  10. #10  
    Registered Member

    Join Date
    Sep 2009
    Posts
    201
    Thanks given
    0
    Thanks received
    17
    Rep Power
    147
    lol thats quite funny, thanks guys
    Reply With Quote  
     

Page 1 of 9 123 ... LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Auto Client Updater
    By silabgarza in forum Help
    Replies: 12
    Last Post: 03-11-2011, 12:43 AM
  2. Auto Cache Updater? Help
    By Defiled-X in forum Help
    Replies: 0
    Last Post: 02-18-2011, 11:06 PM
  3. Auto Updater
    By Jinrake in forum Requests
    Replies: 3
    Last Post: 10-16-2009, 05:07 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •