/**OpenAtlasForAndroid Project

The MIT License (MIT) 
Copyright (c) 2015 Bunny Blue

Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software 
without restriction, including without limitation the rights to use, copy, modify, 
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 
permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies 
or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@author BunnyBlue
* **/
package com.openAtlas.bundleInfo.maker;

import java.io.File;
import java.util.Collection;

/**
 * @author BunnyBlue
 *
 */
public class ApkPreProcess {
	public static void preProcess(String mDir) {
	Collection<File>  apkFiles=	org.apache.commons.io.FileUtils.listFiles(new File(mDir), new String[]{"apk"}	, true);
		
		for (File file : apkFiles) {
		String pkgName=	PackageLite.parse(file.getAbsolutePath()).packageName;
		
		pkgName="lib"+pkgName.replaceAll("\\.", "_")+".so";
		File  targetFile=new File(mDir+File.separator+pkgName);
		targetFile.delete();
		file.renameTo(targetFile);
		System.out.println("ApkPreProcess.preProcess() processed "+pkgName);
		}
	}

}

@@ -1,11 +1,15 @@
 /**
+%0A * 
 OpenAtla
@@ -28,17 +28,27 @@
 Project%0A
-%0A
+ * %3Cp/%3E%0A * 
 The MIT 
@@ -60,18 +60,20 @@
 se (MIT)
- 
 %0A
+ * 
 Copyrigh
@@ -94,17 +94,27 @@
 ny Blue%0A
-%0A
+ * %3Cp/%3E%0A * 
 Permissi
@@ -199,16 +199,19 @@
 oftware%0A
+ * 
 and asso
@@ -278,18 +278,20 @@
 Software
- 
 %0A
+ * 
 without 
@@ -364,18 +364,20 @@
  modify,
- 
 %0A
+ * 
 merge, p
@@ -450,18 +450,20 @@
 , and to
- 
 %0A
+ * 
 permit p
@@ -550,17 +550,27 @@
 itions:%0A
-%0A
+ * %3Cp/%3E%0A * 
 The abov
@@ -646,18 +646,20 @@
 l copies
- 
 %0A
+ * 
 or subst
@@ -691,17 +691,27 @@
 ftware.%0A
-%0A
+ * %3Cp/%3E%0A * 
 THE SOFT
@@ -785,18 +785,20 @@
 IMPLIED,
- 
 %0A
+ * 
 INCLUDIN
@@ -878,16 +878,19 @@
 TICULAR%0A
+ * 
 PURPOSE 
@@ -974,10 +974,12 @@
 ABLE
- 
 %0A
+ * 
 FOR 
@@ -1070,16 +1070,19 @@
 ERWISE,%0A
+ * 
 ARISING 
@@ -1175,16 +1175,22 @@
 FTWARE.%0A
+ *%0A * 
 @author 
@@ -1203,11 +1203,14 @@
 lue%0A
+ 
 * *
+%0A 
 */%0Ap
@@ -1361,17 +1361,20 @@
 ocess %7B%0A
-%09
+    
 public s
@@ -1410,17 +1410,24 @@
 mDir) %7B%0A
-%09
+        
 Collecti
@@ -1434,17 +1434,16 @@
 on%3CFile%3E
- 
  apkFile
@@ -1443,18 +1443,19 @@
 apkFiles
-=%09
+ = 
 org.apac
@@ -1523,17 +1523,16 @@
 %5D%7B%22apk%22%7D
-%09
 , true);
@@ -1532,21 +1532,25 @@
  true);%0A
-%09%09%0A%09%09
+%0A        
 for (Fil
@@ -1570,18 +1570,28 @@
 iles) %7B%0A
-%09%09
+            
 String p
@@ -1600,10 +1600,11 @@
 Name
-=%09
+ = 
 Pack
@@ -1658,27 +1658,39 @@
 me;%0A
-%09%09%0A%09%09
+%0A            
 pkgName
-=
+ = 
 %22lib%22
-+
+ + 
 pkgN
@@ -1719,24 +1719,35 @@
 %22_%22)
-+
+ + 
 %22.so%22;%0A
-%09%09
+            
 File 
- 
 targ
@@ -1752,17 +1752,19 @@
 rgetFile
-=
+ = 
 new File
@@ -1768,17 +1768,19 @@
 ile(mDir
-+
+ + 
 File.sep
@@ -1785,17 +1785,19 @@
 eparator
-+
+ + 
 pkgName)
@@ -1802,62 +1802,298 @@
 e);%0A
-%09%09targetFile.delete();%0A%09%09file.renameTo(targetFile);%0A%09%09
+            if (targetFile.exists())%0A                targetFile.delete();%0A%0A            System.out.println(%22rename: %22 + file.getName() + %22 -%3E %22 + pkgName);%0A            while(!file.renameTo(targetFile)) %7B%0A                System.gc();%0A                Thread.yield();%0A            %7D%0A            
 Syst
@@ -2146,17 +2146,19 @@
 cessed %22
-+
+ + 
 pkgName)
@@ -2163,14 +2163,22 @@
 e);%0A
-%09%09%7D%0A%09%7D%0A
+        %7D%0A    %7D
 %0A%7D%0A

rename fail on Windows