Thread: CacheDownloader.java UPDATED

Page 1 of 2 12 LastLast
Results 1 to 10 of 18
  1. #1 CacheDownloader.java UPDATED 
    Google it ffs

    Reich's Avatar
    Join Date
    Mar 2011
    Age
    20
    Posts
    659
    Thanks given
    88
    Thanks received
    153
    Rep Power
    83
    Was deciding to use this for my new upcoming server but I just decided to release the code anyway.

    This is compatible with any Project Insanity client.
    As quoted from How to make your Project Insanity client a Webclient!
    "Thank-you openice123 for this. Thank-you Onlyme for a quick fix."
    And thank you JUSTINNN for the original post! FROM Run3-S3rv3r

    If you already have the original CacheDownloader.java and wish to update to V2:
    If you don't have the CacheDownlaoder.java follow the tutorial here

    1. Go into your client.java and search
    Code:
    new CacheDownloader(this).downloadCache();
    Replace that with
    Code:
    new CacheDownloaderV2(this).downloadCache();
    Save and close client.java

    2. now open CacheDownloader.java and replace the whole file with this:
    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 javax.swing.*;
    import java.awt.event.*;
    import sign.signlink;
    
    /*************************************
     *All edits to CacheDownloaderV2.java*
     *     go to m13rz | mod cody        *
     *       Please give credits         *
     *************************************/
    
    
    public class CacheDownloaderV2 {
    		
            private client client;
    
            private final int BUFFER = 1024;
    
            private final int VERSION = 1; // Version of cache (Change on client updates)
            private String cacheLink = "YOUR CACHE LINK"; // 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()) {
                            downloadFile(getCacheLink(), getArchivedName());
                            BufferedWriter versionFile = new BufferedWriter(new FileWriter(getCacheDir() + "/cacheVersion" + getCacheVersion() + ".dat"));
                            versionFile.close();
                    } else {
                            if(!version.exists()) {
                                    downloadFile(getCacheLink(), getArchivedName());
                                    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) {
                            }
                    }
    				fileExists();
            }
    
            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());
                        }
    					drawLoadingText("[UN-ZIP]: " + e.getName());				
                    }
                    zin.close();
    
                } catch(Exception e) {
                    e.printStackTrace();
                }
    			oneSec();
    			unNeededCacheExists();
            }
    
            private void unzip(ZipInputStream zin, String s) 
                    throws IOException {
    
                    FileOutputStream out = new FileOutputStream(s);
                    byte [] b = new byte[BUFFER];
                    int len = 0;
    
                    while ((len = zin.read(b)) != -1) {
                            out.write(b,0,len);
    				}
            }
    	
    		public void fileExists() {
    			File file=new File("CACHE DIRECTORY LINK");
    				boolean exists = file.exists();
    			if (!exists) {
    				System.out.println("The cache was not downloaded correctly.");
    				System.out.println("Please download it manually at:");
    				System.out.println("YOUR CACHE LINK");
    				manySec();
    				cacheDownloadError();
        }		else 
    	{
    				System.out.println("Your cache is downloaded and ready to un-zip!");
    				oneSec();
    				unZip();	  
    			}
    	}
    	
    	public void unNeededCacheExists() {
    			File file=new File("CACHE DIRECTORY LINK");
    		boolean exists = file.exists();
    				if (!exists) {
    			System.out.println("Your Client Just Hates You");
    				System.out.println("You are GARBAGE TODAY AYE?!");
    			}else {
    					System.out.println("Your cache is still on your HDD");
    					System.out.println("Attempting to delete...");
    					oneSec();
    						delete();	  
    				}
    	}
    	
    	    public void delete() {	
        	try{
     
        		File file = new File("CACHE DIRECTORY LINK");
     
        		if(file.delete()){
        			System.out.println("[SUCCESS]" +file.getName()+ " was deleted!");
        		}else{
        			System.out.println("[ERROR]" +file.getName()+ " was not deleted.");
        		}
     
        	}catch(Exception e){
     
        		e.printStackTrace();
     
        	}
        }
    	
    	public void cacheDownloadError() {
    		try {
                System.out.println("Cache Download Error: 0x21V82");
    			}
    			catch(Exception e){
     
        		e.printStackTrace();
     
        	}
    			}
    			
      public void oneSec() {
         try {
           Thread.currentThread().sleep(1000);
           }
         catch (InterruptedException e) {
           e.printStackTrace();
           }
         }  
      public void manySec() {
         try {
           Thread.currentThread().sleep(1500);
           }
         catch (InterruptedException e) {
           e.printStackTrace();
           }
         }
    }
    2. Search
    Code:
    YOUR CACHE LINK
    replace that with your actual cache link

    Example:
    Code:
    http://google.com/cache.zip
    3. Search
    Code:
    CACHE DIRECTORY LINK
    Replace that with your cache link on your computer

    Example
    Code:
    C:/.Google_File_store_32/

    Save, close, and compile!

    DONE

    If I left anything out please let me know and I will fix it up ASAP


    CacheDownloaderV2.java
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Feb 2011
    Posts
    90
    Thanks given
    0
    Thanks received
    3
    Rep Power
    2
    May I ask, what are the differences with the normal kind of cachedownloader?
    Reply With Quote  
     

  3. #3  
    Google it ffs

    Reich's Avatar
    Join Date
    Mar 2011
    Age
    20
    Posts
    659
    Thanks given
    88
    Thanks received
    153
    Rep Power
    83
    Quote Originally Posted by syncro View Post
    May I ask, what are the differences with the normal kind of cachedownloader?
    First CacheDownlaoder did not delete the cache.zip file
    That leaves, depending on how big your cache is, quite a bit of space being wasted.

    I believe this is just a little bit more useful than the original one
    Reply With Quote  
     

  4. #4  
    なぜこのテキストは日本語で書かれている ?

    Kenneh's Avatar
    Join Date
    Dec 2009
    Age
    20
    Posts
    2,752
    Thanks given
    64
    Thanks received
    302
    Rep Power
    453
    A lot of stupid, useless code. I'm not sure why my other comment was removed.


    Reply With Quote  
     

  5. #5  
    Donator

    Char Char's Avatar
    Join Date
    Oct 2010
    Posts
    1,697
    Thanks given
    56
    Thanks received
    94
    Rep Power
    103
    my cachedownloader always deleted the cache
    Reply With Quote  
     

  6. #6  
    Google it ffs

    Reich's Avatar
    Join Date
    Mar 2011
    Age
    20
    Posts
    659
    Thanks given
    88
    Thanks received
    153
    Rep Power
    83
    are you all really going to just say hey nice piece of crap?
    does everyone have a heart of coal?
    Reply With Quote  
     

  7. Thankful user:


  8. #7  
    Donator

    Char Char's Avatar
    Join Date
    Oct 2010
    Posts
    1,697
    Thanks given
    56
    Thanks received
    94
    Rep Power
    103
    k sorry man nice release
    Reply With Quote  
     

  9. #8  
    なぜこのテキストは日本語で書かれている ?

    Kenneh's Avatar
    Join Date
    Dec 2009
    Age
    20
    Posts
    2,752
    Thanks given
    64
    Thanks received
    302
    Rep Power
    453
    Quote Originally Posted by Google411 View Post
    are you all really going to just say hey nice piece of crap?
    does everyone have a heart of coal?
    Its not that. Its just that you should try to do something better than add a few lines to someone elses work before you release it.


    Reply With Quote  
     

  10. #9  
    Banned

    Join Date
    May 2008
    Posts
    2,327
    Thanks given
    55
    Thanks received
    67
    Rep Power
    0
    Quote Originally Posted by Google411 View Post
    are you all really going to just say hey nice piece of crap?
    does everyone have a heart of coal?
    Nice piece of crap mate!






    OT: both of these things have been released, the 'v1' has all these features, and the cache downloading bug had a bug fix post in snippets quite some time ago.
    Reply With Quote  
     

  11. #10  
    Banned

    Join Date
    Sep 2010
    Age
    19
    Posts
    568
    Thanks given
    147
    Thanks received
    197
    Rep Power
    0
    What's the difference other than it deletes the .zip file?
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

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

Similar Threads

  1. Problems with cachedownloader.
    By CommunityX in forum Help
    Replies: 1
    Last Post: 03-18-2011, 06:06 AM
  2. 508 CacheDownloader Screen
    By Quise in forum Help
    Replies: 2
    Last Post: 12-19-2010, 12:26 AM
  3. Basics of Java [Updated Regularly]
    By Roger in forum Application Development
    Replies: 18
    Last Post: 11-27-2009, 02:04 AM
  4. Newest Updated Item.Java for Miss Silabsoft
    By BLooDHounD in forum Tutorials
    Replies: 11
    Last Post: 09-16-2007, 02:36 AM
  5. Full Compiler Fix [Updated Java 6u2]!
    By Icepkz in forum Tutorials
    Replies: 5
    Last Post: 08-17-2007, 09:29 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
  •