@@ -58,10 +58,10 @@ public static String getString(BufferedReader br) {
5858 }
5959
6060 // detect multiple sourceSet res.srcDirs
61- public static void backupStringResources (String module , Config config ) {
62- String currentPath = getCurrentPath (module );
61+ public static void backupStringResources (String module , Config config , boolean debug ) {
62+ String path = getCurrentPath (module );
6363 for (String folder : config .getSrcFolders ()) {
64- currentPath += module + File .separator + folder + File .separator + "res" + File .separator ;
64+ String currentPath = path + module + File .separator + folder + File .separator + "res" + File .separator ;
6565 File file = new File (currentPath );
6666 String [] directories = file .list ((current , name ) -> new File (current , name ).isDirectory ());
6767 if (directories != null ) {
@@ -77,8 +77,11 @@ public static void backupStringResources(String module, Config config) {
7777 toCheck .delete ();
7878 }
7979 if (toCopy .exists ()) {
80- PrintUtils .print ("- " + toCopy .getParentFile ().getName () + File .separator + toCopy .getName (), true );
80+ PrintUtils .print (module , "- " + toCopy .getParentFile ().getName () + File .separator + toCopy .getName (), true );
8181 copyFile (toCopy , toCheck );
82+ if (debug ) {
83+ PrintUtils .print (module , "backuping file: " + toCopy .getPath (), true );
84+ }
8285 }
8386 } catch (IOException e ) {
8487 e .printStackTrace ();
@@ -87,15 +90,18 @@ public static void backupStringResources(String module, Config config) {
8790 }
8891 }
8992 } else {
90- PrintUtils .print (module , "source folder not found: " + folder , true );
91- }
93+ if (debug ) {
94+ PrintUtils .print (module , "source folder not found: " + currentPath , true );
95+ } else {
96+ PrintUtils .print (module , "source folder not found: " + folder , true );
97+ } }
9298 }
9399 }
94100
95- public static void encryptStringResources (String module , Config config , String key ) {
96- String currentPath = getCurrentPath (module );
101+ public static void encryptStringResources (String module , Config config , String key , boolean debug ) {
102+ String path = getCurrentPath (module );
97103 for (String folder : config .getSrcFolders ()) {
98- currentPath += module + File .separator + folder + File .separator + "res" + File .separator ;
104+ String currentPath = path + module + File .separator + folder + File .separator + "res" + File .separator ;
99105 File file = new File (currentPath );
100106 String [] directories = file .list ((current , name ) -> new File (current , name ).isDirectory ());
101107 if (directories != null ) {
@@ -104,19 +110,28 @@ public static void encryptStringResources(String module, Config config, String k
104110 for (String sFile : config .getStringFiles ()) {
105111 File toEncrypt = new File (pathToEncrypt + sFile );
106112 if (toEncrypt .exists ()) {
107- PrintUtils .print ("- " + toEncrypt .getParentFile ().getName () + File .separator + toEncrypt .getName (), true );
108- String encrypted = find (getTextFromFilePath (toEncrypt .getAbsolutePath ()), key );
113+ PrintUtils .print (module , "- " + toEncrypt .getParentFile ().getName () + File .separator + toEncrypt .getName (), true );
114+ String encrypted = find (module , getTextFromFilePath (toEncrypt .getAbsolutePath ()), key , debug );
109115 writeFile (toEncrypt , encrypted );
116+ if (debug ) {
117+ PrintUtils .print (module , "writing file: " + toEncrypt .getPath (), true );
118+ }
119+ } else if (debug ) {
120+ PrintUtils .print (module , "source file not exist: " + pathToEncrypt + sFile , true );
110121 }
111122 }
112123 }
113124 } else {
114- PrintUtils .print (module , "source folder not found: " + folder , true );
125+ if (debug ) {
126+ PrintUtils .print (module , "source folder not found: " + currentPath , true );
127+ } else {
128+ PrintUtils .print (module , "source folder not found: " + folder , true );
129+ }
115130 }
116131 }
117132 }
118133
119- public static void restoreStringResources (String module , Config config ) {
134+ public static void restoreStringResources (String module , Config config , boolean debug ) {
120135 String currentPath = getCurrentPath (module ) + module + File .separator + "resbackup" + File .separator ;
121136 File file = new File (currentPath );
122137 String [] directories = file .list ((current , name ) -> new File (current , name ).isDirectory ());
@@ -132,8 +147,11 @@ public static void restoreStringResources(String module, Config config) {
132147 File toCheck = new File (pathRes + sFile );
133148 if (toRestore .exists ()) {
134149 try {
135- PrintUtils .print ("- " + toCheck .getParentFile ().getName () + File .separator + toCheck .getName (), true );
150+ PrintUtils .print (module , "- " + toCheck .getParentFile ().getName () + File .separator + toCheck .getName (), true );
136151 copyFile (toRestore , toCheck );
152+ if (debug ) {
153+ PrintUtils .print (module , "restoring: " + toRestore .getPath (), true );
154+ }
137155 } catch (IOException e ) {
138156 e .printStackTrace ();
139157 }
@@ -146,9 +164,16 @@ public static void restoreStringResources(String module, Config config) {
146164 }
147165 if (file .isDirectory ()) {
148166 file .delete ();
167+ if (debug ) {
168+ PrintUtils .print (module , "temp source folder removed: " + file .getPath (), true );
169+ }
149170 }
150171 } else {
151- PrintUtils .print (module , "restore folder not found" , true );
172+ if (debug ) {
173+ PrintUtils .print (module , "restore folder not found: " + currentPath , true );
174+ } else {
175+ PrintUtils .print (module , "restore folder not found" , true );
176+ }
152177 }
153178 }
154179
@@ -168,7 +193,7 @@ public static boolean isEncrypted(String value, String key) {
168193 return encrypted ;
169194 }
170195
171- public static String find (String xmlO , String key ) {
196+ public static String find (String module , String xmlO , String key , boolean debug ) {
172197 String content = xmlO ;
173198 String toFind1 = "hidden=\" true\" " ;
174199
@@ -198,9 +223,9 @@ public static String find(String xmlO, String key) {
198223
199224 toShow = toShow .length () > maxToShow ? toShow .substring (0 , maxToShow ) + ".." : toShow ;
200225 encrypted = encrypted .length () > maxToShow ? encrypted .substring (0 , maxToShow ) + ".." : encrypted ;
201- PrintUtils .print ("\t [" + toShow + "] - [" + encrypted + "]" + (hasExtra ? extra : "" ), true );
226+ PrintUtils .print (module , "\t [" + toShow + "] - [" + encrypted + "]" + (hasExtra ? extra : "" ), true );
202227 } catch (Exception e ) {
203- PrintUtils .print ("error on " + result );
228+ PrintUtils .print (module , "error on " + result , true );
204229 e .printStackTrace ();
205230 }
206231
0 commit comments