Skip to content

Commit 3af63af

Browse files
authored
Merge pull request #6 from StringCare/develop
Develop
2 parents fae371c + 2b0ed89 commit 3af63af

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ root_project/build.gradle
1414
buildscript {
1515
1616
ext {
17-
stringcare_version = '0.5'
17+
stringcare_version = '0.6'
1818
}
1919
2020
repositories {

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ apply plugin: 'java'
2424
apply plugin: 'com.jfrog.bintray'
2525

2626
group 'com.stringcare'
27-
version '0.5'
27+
version '0.6'
2828

2929
sourceCompatibility = 1.8
3030

src/main/groovy/FileUtils.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public static String getTextFromFilePath(String path) {
3737
}
3838

3939
private static String getCurrentPath(String module) {
40-
String path = new File(".").getAbsolutePath().replace(".", "").replace(module + File.separator,"");
41-
return path;
40+
File mod = new File(module);
41+
return mod.exists() && mod.isDirectory() ? mod.getAbsolutePath() + File.separator : null;
4242
}
4343

4444
public static String getString(BufferedReader br) {
@@ -60,15 +60,19 @@ public static String getString(BufferedReader br) {
6060
// detect multiple sourceSet res.srcDirs
6161
public static void backupStringResources(String module, Config config, boolean debug) {
6262
String path = getCurrentPath(module);
63+
if (path == null) {
64+
PrintUtils.print(module, "module " + module + " not found", true);
65+
return;
66+
}
6367
for (String folder : config.getSrcFolders()) {
64-
String currentPath = path + module + File.separator + folder + File.separator + "res" + File.separator;
68+
String currentPath = path + folder + File.separator + "res" + File.separator;
69+
6570
File file = new File(currentPath);
6671
String[] directories = file.list((current, name) -> new File(current, name).isDirectory());
6772
if (directories != null) {
6873
for (String dir : directories) {
6974
String pathToCopy = currentPath + dir + File.separator;
70-
String pathToCheck = getCurrentPath(module) + module + File.separator + "resbackup" + File.separator + dir + File.separator;
71-
75+
String pathToCheck = getCurrentPath(module) + "resbackup" + File.separator + dir + File.separator;
7276
for (String sFile : config.getStringFiles()) {
7377
try {
7478
File toCopy = new File(pathToCopy + sFile);
@@ -94,14 +98,19 @@ public static void backupStringResources(String module, Config config, boolean d
9498
PrintUtils.print(module, "source folder not found: " + currentPath, true);
9599
} else {
96100
PrintUtils.print(module, "source folder not found: " + folder, true);
97-
} }
101+
}
102+
}
98103
}
99104
}
100105

101106
public static void encryptStringResources(String module, Config config, String key, boolean debug) {
102107
String path = getCurrentPath(module);
108+
if (path == null) {
109+
PrintUtils.print(module, "module " + module + " not found", true);
110+
return;
111+
}
103112
for (String folder : config.getSrcFolders()) {
104-
String currentPath = path + module + File.separator + folder + File.separator + "res" + File.separator;
113+
String currentPath = path + folder + File.separator + "res" + File.separator;
105114
File file = new File(currentPath);
106115
String[] directories = file.list((current, name) -> new File(current, name).isDirectory());
107116
if (directories != null) {
@@ -132,15 +141,19 @@ public static void encryptStringResources(String module, Config config, String k
132141
}
133142

134143
public static void restoreStringResources(String module, Config config, boolean debug) {
135-
String currentPath = getCurrentPath(module) + module + File.separator + "resbackup" + File.separator;
144+
if (getCurrentPath(module) == null) {
145+
PrintUtils.print(module, "module " + module + " not found", true);
146+
return;
147+
}
148+
String currentPath = getCurrentPath(module) + "resbackup" + File.separator;
136149
File file = new File(currentPath);
137150
String[] directories = file.list((current, name) -> new File(current, name).isDirectory());
138151
if (directories != null) {
139152
File toRestore;
140153
for (String dir : directories) {
141154
String pathToRestore = currentPath + dir + File.separator;
142155
for (String folder : config.getSrcFolders()) {
143-
String pathRes = getCurrentPath(module) + module + File.separator + folder + File.separator + "res" + File.separator + dir + File.separator;
156+
String pathRes = getCurrentPath(module) + folder + File.separator + "res" + File.separator + dir + File.separator;
144157

145158
for (String sFile : config.getStringFiles()) {
146159
toRestore = new File(pathToRestore + sFile);

0 commit comments

Comments
 (0)