Thread: [PI] Cache Wont Unzipp [PI]

Results 1 to 10 of 10
  1. #1 [PI] Cache Wont Unzipp [PI] 
    Registered Member rammstien's Avatar
    Join Date
    Jul 2010
    Posts
    28
    Thanks given
    0
    Thanks received
    1
    Rep Power
    1
    In My PI Client The CacheDownloader Wont Unzipp The Cache... Help?


    Code:
    import java.io.File;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.io.FileWriter;
    import java.io.BufferedWriter;
    import java.io.BufferedOutputStream;
    import java.io.BufferedInputStream;
    import java.io.FileOutputStream;
    import java.io.FileInputStream;
    import java.io.InputStream;
    import java.net.URLConnection;
    import java.net.URL;
    import java.util.zip.ZipFile;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipInputStream;
    import java.util.Enumeration;
    
    import sign.signlink;
    
    public class CacheDownloader {
    
    	private client client;
    
    	private final int BUFFER = 1024;
    
    	private final int VERSION = 1; // Version of cache
    	private String cacheLink = "http://**********/edeklfdw30tl/Jester_cache_32.zip"; // Link to cache
    
    	private String fileToExtract = getCacheDir() + getArchivedName();
    
    	public CacheDownloader(client client) {
    		this.client = client;
    	}
    
    	private void drawLoadingText(String text) {
    		client.drawLoadingText(35, text);
    		//System.out.println(text);
    	}
    
    
    	private void drawLoadingText(int amount, String text) {
    		client.drawLoadingText(amount, text);
    		//System.out.println(text);
    	}
    
    	private String getCacheDir() {
    		return signlink.findcachedir();
    	}
    
    	private String getCacheLink() {
    		return cacheLink;
    	}
    
    	private int getCacheVersion() {
    		return VERSION;
    	}
    
    	public CacheDownloader downloadCache() {
    		try {
    		File location = new File(getCacheDir());
    		File version = new File(getCacheDir() + "/cacheVersion" + getCacheVersion() + ".dat");
    
    		if(!location.exists()) {
    			//drawLoadingText("Loading new Updates....");
    			downloadFile(getCacheLink(), getArchivedName());
    
    			unZip();
    			//System.out.println("UNZIP");
    
    			BufferedWriter versionFile = new BufferedWriter(new FileWriter(getCacheDir() + "/cacheVersion" + getCacheVersion() + ".dat"));
    			versionFile.close();
    			deleteZIP(getArchivedName());
    		} else {
    			if(!version.exists()) {
    				//drawLoadingText("~ First Time Installation, Only Once! ~");
    				downloadFile(getCacheLink(), getArchivedName());
    
    				unZip();
    				//System.out.println("UNZIP");
    
    				BufferedWriter versionFile = new BufferedWriter(new FileWriter(getCacheDir() + "/cacheVersion" + getCacheVersion() + ".dat"));
    				versionFile.close();
    				deleteZIP(getArchivedName());
    
    			} else {
    				return null;
    			}
    		}
    		} catch(Exception e) {
    
    		}
    		return null;
    	}
    
    	private void downloadFile(String adress, String localFileName) {
    		OutputStream out = null;
    		URLConnection conn;
    		InputStream in = null;
    
    		try {
    
    			URL url = new URL(adress);
    			out = new BufferedOutputStream(
    				new FileOutputStream(getCacheDir() + "/" +localFileName));
    
    			conn = url.openConnection();
    			in = conn.getInputStream();
    
    			byte[] data = new byte[BUFFER];
    
    			int numRead;
    			long numWritten = 0;
    			int length = conn.getContentLength();
    
    
    			while((numRead = in.read(data)) != -1) {
    				out.write(data, 0, numRead);
    				numWritten += numRead;
    
                			int percentage = (int)(((double)numWritten / (double)length) * 100D);
    				drawLoadingText(percentage, "Downloading Cache " + percentage + "%...");
    
    			}
    
    			System.out.println(localFileName + "\t" + numWritten);
    			drawLoadingText("Unpacking..");
    
    		} catch (Exception exception) {
    			exception.printStackTrace();
    		} finally {
    			try {
    				if (in != null) {
    					in.close();
    				}
    				if (out != null) {
    					out.close();
    				}
    			} catch (IOException ioe) {
    			}
    		}
    
    	}
    
    	private String getArchivedName() {
    		int lastSlashIndex = getCacheLink().lastIndexOf('/');
    		if (lastSlashIndex >= 0
    			&& lastSlashIndex < getCacheLink().length() -1) {
    			return getCacheLink().substring(lastSlashIndex + 1);
    		} else {
    			//System.err.println("error retreiving archivaed name.");
    		}
    		return "";
    	}
    
    
    
    
    	private void unZip() {
    
    		try {
        			InputStream in =
    				new BufferedInputStream(new FileInputStream(fileToExtract));
    			ZipInputStream zin = new ZipInputStream(in);
    			ZipEntry e;
    
    			while((e=zin.getNextEntry()) != null) {
    
                   			if(e.isDirectory()) {
    					(new File(getCacheDir() + e.getName())).mkdir();
                   			} else {
    
    				if (e.getName().equals(fileToExtract)) {
    					unzip(zin, fileToExtract);
    					break;
    				}
           					unzip(zin, getCacheDir() + e.getName());
    				}
    				//System.out.println("unzipping2 " + e.getName());
    			}
    			zin.close();
    
    		} catch(Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    private void deleteZIP(String fileName){
        // A File object to represent the filename
        File f = new File(getCacheDir() + fileName);
    
        // Make sure the file or directory exists and isn't write protected
        if (!f.exists())
          throw new IllegalArgumentException(
              "Delete: no such file or directory: " + fileName);
    
        if (!f.canWrite())
          throw new IllegalArgumentException("Delete: write protected: "
              + fileName);
    
        // If it is a directory, make sure it is empty
        if (f.isDirectory()) {
          String[] files = f.list();
          if (files.length > 0)
            throw new IllegalArgumentException(
                "Delete: directory not empty: " + fileName);
        }
    
        // Attempt to delete it
        boolean success = f.delete();
    
        if (!success)
          throw new IllegalArgumentException("Delete: deletion failed");
    
    	}
    
    	private void unzip(ZipInputStream zin, String s)
    		throws IOException {
    
    		FileOutputStream out = new FileOutputStream(s);
    		//System.out.println("unzipping " + s);
    		byte [] b = new byte[BUFFER];
    		int len = 0;
    
    		while ((len = zin.read(b)) != -1) {
    			out.write(b,0,len);
    		}
    		out.close();
    	}
    }
    Heres what it comes out to:


    Thanks...
    Reply With Quote  
     

  2. #2  
    arrowzftw
    Guest
    Firstly your cache downloaded is 6kb. which isn't a size of cache. Maybe you didnt upload the cache fully. If your sure you uploaded fully make sure that your download didn't time out because you might of uploaded it to a shit host. But it is not unzipping because the cache didnt download properly.
    Reply With Quote  
     

  3. #3  
    F*ck the rest join the best, WoR

    sigex's Avatar
    Join Date
    Mar 2008
    Age
    31
    Posts
    2,088
    Thanks given
    122
    Thanks received
    146
    Rep Power
    690
    I've created an auto updater / downloader I could install into yourclient for a fee


    The wor has begun.

    Reply With Quote  
     

  4. #4  
    Botnet admin

    HaVoK0321's Avatar
    Join Date
    Jan 2009
    Posts
    551
    Thanks given
    51
    Thanks received
    23
    Rep Power
    247
    I'll fix it for 3 dollars on paypal, send me a PM if you want.
    Reply With Quote  
     

  5. #5  
    Banned
    Join Date
    Jul 2010
    Age
    26
    Posts
    1,144
    Thanks given
    7
    Thanks received
    48
    Rep Power
    0
    Money money money omg...ill do it for free since you kids just want money.
    Reply With Quote  
     

  6. Thankful user:


  7. #6  
    Botnet admin

    HaVoK0321's Avatar
    Join Date
    Jan 2009
    Posts
    551
    Thanks given
    51
    Thanks received
    23
    Rep Power
    247
    Quote Originally Posted by KottonMouthKings View Post
    Money money money omg...ill do it for free since you kids just want money.
    Thats all this forum turned into, so I figured might as well join in.
    Reply With Quote  
     

  8. #7  
    Registered Member rammstien's Avatar
    Join Date
    Jul 2010
    Posts
    28
    Thanks given
    0
    Thanks received
    1
    Rep Power
    1
    Quote Originally Posted by KottonMouthKings View Post
    Money money money omg...ill do it for free since you kids just want money.
    Thank bro.. nice name btw
    Reply With Quote  
     

  9. #8  
    Registered Member rammstien's Avatar
    Join Date
    Jul 2010
    Posts
    28
    Thanks given
    0
    Thanks received
    1
    Rep Power
    1
    I added ur msn
    Reply With Quote  
     

  10. #9  
    Registered Member rammstien's Avatar
    Join Date
    Jul 2010
    Posts
    28
    Thanks given
    0
    Thanks received
    1
    Rep Power
    1
    Bump still need help
    Reply With Quote  
     

  11. #10  
    Donator
    Defiled-X's Avatar
    Join Date
    Jun 2010
    Posts
    1,434
    Thanks given
    52
    Thanks received
    78
    Rep Power
    27
    Okay, First of all let me tell you. Uppit wont download it.
    Reason:
    Uppit is not a direct download link, you want your cache to download directly.
    My best suggestion for you is use DropBox. Upload you cache there in a .zip format

    That should work out just fine for you. Happened to me before, but I used media fire
    Reply With Quote  
     


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. webclient wont unzip cache
    By Ta1nt3d in forum Help
    Replies: 0
    Last Post: 01-15-2011, 07:14 AM
  2. Replies: 3
    Last Post: 08-06-2010, 06:43 AM
  3. My cache downloader wont unzip?
    By Organic in forum Help
    Replies: 2
    Last Post: 05-30-2010, 08:55 AM
  4. Replies: 1
    Last Post: 05-26-2010, 12:28 AM
  5. Tom's cache editor wont edit.
    By Coder Alex in forum Help
    Replies: 3
    Last Post: 08-01-2009, 12:04 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
  •