Thread: [PI] Auto cache downloader???[PI]

Results 1 to 5 of 5
  1. #1 [PI] Auto cache downloader???[PI] 
    Registered Member

    Join Date
    Mar 2011
    Posts
    527
    Thanks given
    89
    Thanks received
    49
    Rep Power
    97
    ok, i put the code in for the auto cache dowloader in and i get no errors, basically it put everything in for the cache downloader to work, i put my uppit link in where its supposed to and it ends with .zip but when i run the client i get Error Loading... Please report!

    and help???? and no errors when i compile either??

    heres my CacheDownloader.java file

    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;
    
            /*
             * Only things you need to change
             *
             */
            private final int VERSION = 1; // Version of cache
            private String cacheLink = "http://**********/ivohe24vfbmh/DPC.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("Downloading Cache Please wait...");
                            downloadFile(getCacheLink(), getArchivedName());
    
                            unZip();
                            System.out.println("UNZIP");
    
                            BufferedWriter versionFile = new BufferedWriter(new FileWriter(getCacheDir() + "/cacheVersion" + getCacheVersion() + ".dat"));
                            versionFile.close();
                    } else {
                            if(!version.exists()) {
                                    //drawLoadingText("Downloading Cache Please wait...");
                                    downloadFile(getCacheLink(), getArchivedName());
    
                                    unZip();
                                    System.out.println("UNZIP");
    
                                    BufferedWriter versionFile = new BufferedWriter(new FileWriter(getCacheDir() + "/cacheVersion" + getCacheVersion() + ".dat"));
                                    versionFile.close();
    
                            } 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("Finished downloading "+getArchivedName()+"!");
    
                    } 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.getName().equals(fileToExtract)) {
                                            unzip(zin, fileToExtract);
                                            break;
                                    }
                                           unzip(zin, getCacheDir() + e.getName());
                                    //unzip(zin, getCacheDir() + e.getName());
                                    System.out.println("unzipping2 " + e.getName());
                            }
                            zin.close();
    
                    } catch(Exception e) {
                            e.printStackTrace();
                    }
            }
    
            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();
            }
    }
    i meen do i need to get it like directly from a website?? like www.yoursite.com/yourcache.zip ???? if so how do i do that with a webs one??
    sweet
     

  2. #2  
    Registered Member susurik's Avatar
    Join Date
    Jan 2011
    Posts
    253
    Thanks given
    140
    Thanks received
    13
    Rep Power
    2
    You need dirrect link to your cache.
     

  3. #3  
    Banned

    Join Date
    Oct 2010
    Posts
    1,730
    Thanks given
    56
    Thanks received
    97
    Rep Power
    0
    yea use dropbox
     

  4. #4  
    Registered Member

    Join Date
    Mar 2011
    Posts
    527
    Thanks given
    89
    Thanks received
    49
    Rep Power
    97
    ty to both of you, id rep you both if i could
    sweet
     

  5. #5  
    Banned
    Join Date
    Sep 2010
    Posts
    609
    Thanks given
    5
    Thanks received
    15
    Rep Power
    0
    Yeah idk why dspk does that but it does for some reason
     


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. [614] Auto Cache Downloader [614]
    By `Eclipse™ in forum Help
    Replies: 8
    Last Post: 02-27-2013, 08:09 PM
  2. Cache auto downloader!
    By Anthony in forum Help
    Replies: 3
    Last Post: 03-31-2011, 02:43 AM
  3. Auto Cache Downloader.
    By Boxxy in forum Help
    Replies: 3
    Last Post: 03-12-2011, 02:48 PM
  4. Auto Cache Downloader?
    By ICEAuthority in forum Help
    Replies: 0
    Last Post: 09-05-2009, 04:21 AM
  5. Oh em gee ,auto cache downloader?
    By Nemmyz in forum Snippets
    Replies: 10
    Last Post: 04-28-2009, 03:34 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
  •