Thread: [PI]Perfect UpdateCache

Page 2 of 11 FirstFirst 1234 ... LastLast
Results 11 to 20 of 109
  1. #11  
    Developer

    Holy Symbol's Avatar
    Join Date
    Dec 2011
    Age
    25
    Posts
    1,763
    Thanks given
    1,093
    Thanks received
    239
    Rep Power
    365
    Thanked and repped
    Spoiler for big sig:


    Reply With Quote  
     

  2. #12  
    Registered Member

    Join Date
    Feb 2012
    Posts
    336
    Thanks given
    3
    Thanks received
    29
    Rep Power
    101
    Nice work mate Repped


    VOUCHES
    [SPOIL]
    Quote Originally Posted by SacredPK View Post
    Vouch for African
    Quote Originally Posted by Raw Envy View Post
    Vouch for African seems like a nice guy and trustworthy
    [/SPOIL]
    Reply With Quote  
     

  3. #13  
    Super Donator


    Join Date
    Sep 2011
    Posts
    1,446
    Thanks given
    138
    Thanks received
    284
    Rep Power
    260

    how do i fix it?

    it automatically gives .db when i zip cache lol
    Reply With Quote  
     

  4. #14  
    GANGNAM STYLE!

    Ohad's Avatar
    Join Date
    Aug 2011
    Posts
    3,179
    Thanks given
    152
    Thanks received
    352
    Rep Power
    1671
    awesome job
    Reply With Quote  
     

  5. #15  
    Remember The Name
    .Chris's Avatar
    Join Date
    May 2009
    Posts
    346
    Thanks given
    9
    Thanks received
    32
    Rep Power
    460
    Willl be using good job.
    Reply With Quote  
     

  6. #16  
    Donator


    Join Date
    Sep 2007
    Age
    27
    Posts
    2,426
    Thanks given
    125
    Thanks received
    505
    Rep Power
    386
    This isn't perfect. Perfect would be using crc checks on individual cache files and requesting them if they don't match.
    Reply With Quote  
     

  7. #17  
    Google it ffs

    Reich's Avatar
    Join Date
    Mar 2011
    Age
    30
    Posts
    825
    Thanks given
    120
    Thanks received
    174
    Rep Power
    105
    Quote Originally Posted by -Null Code- View Post

    how do i fix it?

    it automatically gives .db when i zip cache lol
    make sure your signlink findcachedir() is setup correct.. looks like its not for one and for two

    delete all the Thumbs.db in your cache

    its a "system" file so theres permission issues
    Reply With Quote  
     

  8. #18  
    Extreme Donator

    woof woof bish's Avatar
    Join Date
    May 2011
    Age
    26
    Posts
    2,444
    Thanks given
    2,212
    Thanks received
    1,019
    Rep Power
    5000
    Spoiler for :
    Quote Originally Posted by Google411 View Post
    Thanks to Kurt Cobain for the original post

    Much simpler works amazing!
    Stupid GUI is removed and integrated into to the loading bar



    Spoiler for Media:






    Create a file called "UpdateCache.java" inside your source add this
    Code:
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.zip.*;
    import sign.signlink;
    import java.io.*;
    import javax.swing.JOptionPane;
    
    public class UpdateCache implements Runnable {
    
    	public static final String ZIP_URL = "http://YOUR_SITE.com/cache.zip";
    	public static final String VERSION_URL = "http://YOUR_SITE.com/cacheVersion.txt";
    	public static final String VERSION_FILE = sign.signlink.findcachedir()+"cacheVersion.dat";
    	private client client;
    	client frame;
        public UpdateCache(client client) {
                    this.client = client;
        }
    		
        private void drawLoadingText(int amount, String text) {
                    client.drawLoadingText(amount, text);
        }
    	
    	public double getCurrentVersion(){
    		try {
    			BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(VERSION_FILE)));
    			return Double.parseDouble(br.readLine());
    		} catch (Exception e) {
    			return 0.1;
    		}
    	}
    	
    	public double getNewestVersion(){
    		try {
    			URL tmp = new URL(VERSION_URL);
    			BufferedReader br = new BufferedReader(new InputStreamReader(tmp.openStream()));
    			return Double.parseDouble(br.readLine());
    		} catch (Exception e) {
    			handleException(e);
    			return -1;
    		}
    	}
    	
    	private void handleException(Exception e){
    		StringBuilder strBuff = new StringBuilder();
    		strBuff.append("Please Screenshot this message, and send it to an admin!\r\n\r\n");
            StringBuilder append = strBuff.append(e.getClass().getName()).append(" \"").append(e.getMessage()).append("\"\r\n");
    		for(StackTraceElement s : e.getStackTrace())
    			strBuff.append(s.toString()).append("\r\n");
    		alert("Exception [" + e.getClass().getSimpleName() + "]",strBuff.toString(),true);
    	}
    	
    	private void alert(String msg){
    		alert("Message",msg,false);
    	}
    	
    	private void alert(String title,String msg,boolean error){
    		JOptionPane.showMessageDialog(null,
    			   msg,
    			   title,
    			    (error ? JOptionPane.ERROR_MESSAGE : JOptionPane.PLAIN_MESSAGE));
    	}
    	
    	@Override
    	public void run() {
    	drawLoadingText(0, "Checking Versions");
    		try{
    		double newest = getNewestVersion();
    		if(newest > this.getCurrentVersion()){
    			int n = JOptionPane.showConfirmDialog(
    				    null,
    				    "There is an update to version " + newest + "\n" +
    					"Would you like to update?",
    				    "Current version: "+ getCurrentVersion(),
    				    JOptionPane.YES_NO_OPTION);
    			if(n == 0){
    				updateClient();
    				drawLoadingText(0, "Cache has been updated, please restart the client!");
    				alert("Cache has been updated, please restart the client!");
    				OutputStream out = new FileOutputStream(VERSION_FILE);
    				out.write(String.valueOf(newest).getBytes());;
    				System.exit(0);
    			}else{
    				alert(" Your client may not load correct " +
    				getCurrentVersion());
    				//System.exit(0);
    			}
    		}
    		}catch(Exception e){
    			handleException(e);
    		}
    	}
    	
    	private void updateClient() {
    		File clientZip = downloadClient();
    		if(clientZip != null){
    		unZip(clientZip);
    		}
    	}
    	
    	private void unZip(File clientZip) {
    		try {
    			unZipFile(clientZip,new File(sign.signlink.findcachedir()));
    			clientZip.delete();
    		} catch (IOException e) {
    			handleException(e);
    		}
    	}
    	
    	private void unZipFile(File zipFile,File outFile) throws IOException{
    		ZipInputStream zin = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile)));
    		ZipEntry e;
    		long max = 0;
    		long curr = 0;
    		while((e = zin.getNextEntry()) != null)
    			max += e.getSize();
    		zin.close();
    		ZipInputStream in = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile)));
    		while((e = in.getNextEntry()) != null){
    			if(e.isDirectory())
    				new File(outFile,e.getName()).mkdirs();
    			else{
    				FileOutputStream out = new FileOutputStream(new File(outFile,e.getName()));
    				byte[] b = new byte[1024];
    				int len;
    				while((len = in.read(b,0,b.length)) > -1){
    					curr += len;
    						out.write(b, 0, len);
    						setUnzipPercent((int)((curr * 100) / max));
    				}
    				out.flush();
    				out.close();
    			}
    		}
    	}
    
    	public int percent = 0;
    	
    	public void setDownloadPercent(int amount){
    	        percent = amount;
    			drawLoadingText(amount, "Downloading Cache" + " - " + amount + "%");
    	}
    	
    	public int percent2 = 0;
    	
    	public void setUnzipPercent(int amount2){
    	        percent2 = amount2;
    			drawLoadingText(amount2, "Extracting Cache" + " - " + amount2 + "%");
    	}
    
    	private File downloadClient(){
    		File ret = new File(signlink.findcachedir()+"cache.zip");
    		try{
    		OutputStream out = new FileOutputStream(ret);
    		URLConnection conn = new URL(ZIP_URL).openConnection();
    		InputStream in = conn.getInputStream();
    		long max = conn.getContentLength();
    		long curr = 0;
    		byte[] b = new byte[1024];
    		int len;
    		while((len = in.read(b, 0, b.length)) > -1){
    			out.write(b,0,len);
    			curr += len;
    			setDownloadPercent((int)((curr * 100) / max));
    		}
    		out.flush();
    		out.close();
    		in.close();
    		return ret;
    		}catch(Exception e){
    			handleException(e);
    				ret.delete();
    			return null;
    		}
    	}
    }
    Remove all other traces of cache updating you used in the past

    Open client.java and search
    Code:
    void startUp()
    Under the first { add
    Code:
    new UpdateCache(this).run();
    On your webhost make sure you have the cacheVersion.txt uploaded with the correct cache version.

    Any questions ask. Post errors etc



    Omg this is fucking amazingggggg

    rep++
    Reply With Quote  
     

  9. #19  
    Registered Member
    Join Date
    Feb 2012
    Posts
    30
    Thanks given
    0
    Thanks received
    5
    Rep Power
    15

    How could I go about on fixing this error? Thank you +
    Reply With Quote  
     

  10. #20  
    I'm Baack...


    Join Date
    Mar 2011
    Posts
    1,663
    Thanks given
    281
    Thanks received
    202
    Rep Power
    324
    Looks great, Might use

    Bookmarked
    I'm back
    Reply With Quote  
     

Page 2 of 11 FirstFirst 1234 ... 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. Replies: 44
    Last Post: 04-12-2012, 12:04 PM
  2. Replies: 17
    Last Post: 07-05-2011, 11:59 PM
  3. Replies: 5
    Last Post: 10-08-2010, 02:00 PM
  4. Replies: 53
    Last Post: 09-12-2009, 05:56 PM
  5. Replies: 48
    Last Post: 08-26-2008, 09:09 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •