Guest User

Untitled

a guest
Dec 10th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.91 KB | None | 0 0
  1. package themescleaner;
  2.  
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7. import java.nio.channels.FileChannel;
  8.  
  9. public class Main {
  10.  
  11.     private static final String VERSION_NAME = "0.1";
  12.     private static final String ROOT = "c:/AChep/themecleanup/";
  13.     private static final String RESOURCES = "resources";
  14.     private static final String THEMED = "themed";
  15.     private static final String DELETED = "deleted";
  16.     private static final String INPUT = "input";
  17.  
  18.     public static void main(String[] args) {
  19.         logln(3);
  20.         logln("Program:");
  21.         logln("   ThemeCleaner " + VERSION_NAME);
  22.         logln("Contact:");
  23.         logln("   2012 (C) AChep@xda");
  24.         logln("   <artemchep@gmail.com>");
  25.         logln(1);
  26.         log("Preparing folders... ");
  27. /*
  28.         for (int i = 0; i < 20000; i++) {
  29.             File test = new File(ROOT + RESOURCES + "/android_" + i + ".xml");
  30.             try {
  31.                 test.createNewFile();
  32.             } catch (IOException e) {
  33.                 logln("E:  Error copying file...");
  34.             }
  35.         }
  36. */
  37.         final File[] files = new File(ROOT + INPUT).listFiles();
  38.         final File themed = new File(ROOT + THEMED);
  39.         themed.delete();
  40.         themed.mkdir();
  41.         final File deleted = new File(ROOT + DELETED);
  42.         deleted.delete();
  43.         deleted.mkdir();
  44.  
  45.         logln("Successfully.");
  46.         log("Comparing files... ");
  47.         for (int i = 0; i < files.length; i++) {
  48.             File res = new File(ROOT + RESOURCES + "/" + files[i].getName());
  49.             try {
  50.                 copyFile(files[i], new File(ROOT + (res.exists() && res.length() != files[i].length() ? THEMED : DELETED) + "/" + files[i].getName()));
  51.             } catch (IOException e) {
  52.                 logln("E:  Error copying file...");
  53.             }
  54.         }
  55.         logln("Successfully.");
  56.     }
  57.  
  58.     public static void copyFile(File sourceFile, File destFile) throws IOException {
  59.         if (!destFile.exists()) {
  60.             destFile.createNewFile();
  61.         }
  62.  
  63.         FileChannel source = null;
  64.         FileChannel destination = null;
  65.  
  66.         try {
  67.             source = new FileInputStream(sourceFile).getChannel();
  68.             destination = new FileOutputStream(destFile).getChannel();
  69.             destination.transferFrom(source, 0, source.size());
  70.         } finally {
  71.             if (source != null) {
  72.                 source.close();
  73.             }
  74.             if (destination != null) {
  75.                 destination.close();
  76.             }
  77.         }
  78.     }
  79.  
  80.     private static void log(String str) {
  81.         System.out.print(str);
  82.     }
  83.  
  84.     private static void logln(int number) {
  85.         if (number > 1) {
  86.             logln(number - 1);
  87.         }
  88.         logln("");
  89.     }
  90.  
  91.     private static void logln(String str) {
  92.         System.out.println(str);
  93.     }
  94. }
Add Comment
Please, Sign In to add comment