Skip to content

Commit 263ad54

Browse files
author
xausky
committed
初步修改模组目录格式
1 parent f0ccdb9 commit 263ad54

File tree

5 files changed

+42
-33
lines changed

5 files changed

+42
-33
lines changed

app/build.gradle

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ android {
4343
release {
4444
signingConfig signingConfigs.releaseConfig
4545
}
46+
debug {
47+
jniDebuggable true
48+
}
4649
}
4750
lintOptions {
4851
checkReleaseBuilds false
@@ -53,23 +56,27 @@ android {
5356
}
5457

5558
dependencies {
56-
implementation 'commons-io:commons-io:2.4' //最新版2.6使用新的JavaFileAPI,无法在目前Android版本上使用。
59+
implementation 'commons-io:commons-io:2.4'
60+
//最新版2.6使用新的JavaFileAPI,无法在目前Android版本上使用。
5761
implementation 'com.android.support:design:28.0.0'
5862
implementation 'com.android.support:cardview-v7:28.0.0'
5963
implementation 'com.android.support:appcompat-v7:28.0.0'
60-
61-
implementation 'com.hzy:libp7zip:1.5.0' //https://github.com/hzy3774/AndroidP7zip
62-
implementation 'com.github.topjohnwu:libsu:2.0.2' //https://github.com/topjohnwu/libsu
63-
64-
implementation ('com.daimajia.slider:library:1.1.5'){ //https://github.com/daimajia/AndroidImageSlider
64+
implementation 'com.hzy:libp7zip:1.5.0'
65+
//https://github.com/hzy3774/AndroidP7zip
66+
implementation 'com.github.topjohnwu:libsu:2.0.2'
67+
//https://github.com/topjohnwu/libsu
68+
implementation('com.daimajia.slider:library:1.1.5') {
69+
//https://github.com/daimajia/AndroidImageSlider
6570
exclude group: 'com.android.support', module: 'support-v4'
6671
}
67-
68-
implementation 'com.github.medyo:android-about-page:1.2.4' //https://github.com/medyo/android-about-page
69-
implementation 'com.github.xausky:VirtualXposed:8d2abfc77a' //https://github.com/xausky/VirtualXposed
70-
implementation 'com.github.bartwell:ExFilePicker:0c5a7c83ae' //https://github.com/bartwell/ExFilePicker
71-
implementation 'com.github.xausky:CheckVersionLib:ac25f0874e' //https://github.com/xausky/CheckVersionLib
72-
72+
implementation 'com.github.medyo:android-about-page:1.2.4'
73+
//https://github.com/medyo/android-about-page
74+
implementation 'com.github.xausky:VirtualXposed:8d2abfc77a'
75+
//https://github.com/xausky/VirtualXposed
76+
implementation 'com.github.bartwell:ExFilePicker:0c5a7c83ae'
77+
//https://github.com/bartwell/ExFilePicker
78+
implementation 'com.github.xausky:CheckVersionLib:ac25f0874e'
79+
//https://github.com/xausky/CheckVersionLib
7380
implementation 'com.crashlytics.sdk.android:answers:1.4.6'
7481
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.8'
7582
}

app/src/main/java/io/github/xausky/unitymodmanager/adapter/ModsAdapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ private void process(final String path, final String name, final Iterator<String
193193
FileUtils.forceMkdir(temp);
194194
int p7zip = P7ZipApi.executeCommand(String.format("7z x '%s' '-o%s' '-p%s' -aoa", sourceFile.getAbsolutePath(), temp.getAbsolutePath(), password));
195195
if(p7zip == 0){
196-
result = ModUtils.Standardization(temp, targetFile);
196+
result = ModUtils.Standardization(temp.getAbsolutePath(), "", targetFile);
197197
}
198198
FileUtils.deleteDirectory(temp);
199199
if(p7zip == 2){
@@ -204,7 +204,7 @@ private void process(final String path, final String name, final Iterator<String
204204
result = ModUtils.RESULT_STATE_INTERNAL_ERROR;
205205
}
206206
}else if(sourceFile.isDirectory()){
207-
result = ModUtils.Standardization(sourceFile, targetFile);
207+
result = ModUtils.Standardization(sourceFile.getAbsolutePath(), "", targetFile);
208208
}
209209
if(result >= 0){
210210
if(result == 0){
@@ -285,7 +285,7 @@ public void addExternalMod(String path, List<String> names) {
285285
}
286286
try {
287287
FileUtils.write(targetFile, sourceFile.getAbsolutePath());
288-
int result = ModUtils.Standardization(sourceFile, cacheFile);
288+
int result = ModUtils.Standardization(sourceFile.getAbsolutePath(), "", cacheFile);
289289
mods.add(new Mod(name, false, Integer.MAX_VALUE, result, targetFile.getAbsolutePath(), null));
290290
notifyDataSetChanged();
291291
} catch (IOException e) {

app/src/main/java/io/github/xausky/unitymodmanager/fragment/HomeFragment.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import java.net.MalformedURLException;
5858
import java.net.URL;
5959
import java.util.HashMap;
60+
import java.util.HashSet;
6061

6162
import javax.net.ssl.HttpsURLConnection;
6263

@@ -212,7 +213,7 @@ public void onRequestVersionFailure(String message) {
212213
}
213214

214215
public void ImportMapFile() {
215-
ModUtils.map = new HashMap<>();
216+
ModUtils.effectiveFiles = new HashSet<>();
216217
File persistentMap = new File(getBase().getFilesDir() + "/persistent.map");
217218
if (persistentMap.exists() && persistentSupport) {
218219
FileReader reader = null;
@@ -224,7 +225,7 @@ public void ImportMapFile() {
224225
while ((line = bufferedReader.readLine()) != null) {
225226
String[] column = line.split(":");
226227
if (column.length == 2) {
227-
ModUtils.map.put(column[0], column[1]);
228+
ModUtils.effectiveFiles.add(column[1]);
228229
}
229230
}
230231
} catch (FileNotFoundException e1) {
@@ -259,7 +260,7 @@ public void ImportMapFile() {
259260
while ((line = bufferedReader.readLine()) != null) {
260261
String[] column = line.split(":");
261262
if (column.length == 2) {
262-
ModUtils.map.put(column[0], column[1]);
263+
ModUtils.effectiveFiles.add(column[1]);
263264
}
264265
}
265266
} catch (FileNotFoundException e1) {
@@ -294,7 +295,7 @@ public void ImportMapFile() {
294295
while ((line = bufferedReader.readLine()) != null) {
295296
String[] column = line.split(":");
296297
if (column.length == 2) {
297-
ModUtils.map.put(column[0], column[1]);
298+
ModUtils.effectiveFiles.add(column[1]);
298299
}
299300
}
300301
} catch (FileNotFoundException e1) {
@@ -360,8 +361,8 @@ private void clientUpdate() {
360361
clientState.setText(getText(R.string.home_client_uninstalled));
361362
clientState.setCompoundDrawablesWithIntrinsicBounds(ContextCompat.getDrawable(context, R.drawable.ic_clear), null, null, null);
362363
}
363-
mapFile.setText(String.format(context.getString(R.string.map_file_size), ModUtils.map.size()));
364-
if (ModUtils.map.size() > 0) {
364+
mapFile.setText(String.format(context.getString(R.string.map_file_size), ModUtils.effectiveFiles.size()));
365+
if (ModUtils.effectiveFiles.size() > 0) {
365366
mapFile.setCompoundDrawablesWithIntrinsicBounds(ContextCompat.getDrawable(context, R.drawable.ic_check), null, null, null);
366367
}
367368
String summaryString = String.format(getString(R.string.home_summary_context),

app/src/main/java/io/github/xausky/unitymodmanager/fragment/ModFragment.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public int actionButtonVisibility() {
180180

181181
@Override
182182
public void OnActionButtonClick() {
183-
if(ModUtils.map == null){
183+
if(ModUtils.effectiveFiles == null){
184184
Toast.makeText(context, R.string.install_client_and_generate_map_file_first, Toast.LENGTH_LONG).show();
185185
return;
186186
}
@@ -192,7 +192,7 @@ public void OnActionButtonClick() {
192192

193193
@Override
194194
public void OnActionButtonLongClick() {
195-
if(ModUtils.map == null){
195+
if(ModUtils.effectiveFiles == null){
196196
Toast.makeText(context, R.string.install_client_and_generate_map_file_first, Toast.LENGTH_LONG).show();
197197
return;
198198
}
@@ -267,7 +267,7 @@ public int patch(String apkPath, String baseApkPath, String persistentPath, Stri
267267
try {
268268
if(modFile.isFile()){
269269
File externalFile = new File(FileUtils.readFileToString(modFile));
270-
int result = ModUtils.Standardization(externalFile, fusionFile);
270+
int result = ModUtils.Standardization(externalFile.getAbsolutePath(), "", fusionFile);
271271
mod.fileCount = result;
272272
} else {
273273
mod.conflict = new TreeSet<>();

app/src/main/java/io/github/xausky/unitymodmanager/utils/ModUtils.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class ModUtils {
3232
public static final int RESULT_STATE_PASSWORD_ERROR = -2;
3333
public static final int RESULT_STATE_ROOT_ERROR = -3;
3434
public static final int RESULT_STATE_OBB_ERROR = -4;
35-
public static Map<String, String> map;
35+
public static Set<String> effectiveFiles;
3636
public static Set<String> supportImageType = new TreeSet<>();
3737

3838
static {
@@ -65,45 +65,46 @@ public static List<String> copyDirectory(File srcDir, File destDir){
6565
return result;
6666
}
6767

68-
public static int Standardization(File input, File output){
68+
public static int Standardization(String root, String current, File output){
6969
int result = 0;
70+
File input = new File(root + File.separator + current);
7071
if(!input.isDirectory()){
7172
return RESULT_STATE_INTERNAL_ERROR;
7273
}
7374
File[] files = input.listFiles();
7475
for(File file : files){
7576
String path = null;
7677
String name = file.getName();
77-
path = map.get(input.getName() + "/" + name);
78-
if(path != null){
78+
path = current + name;
79+
if(effectiveFiles.contains(path)){
7980
try {
8081
if(file.isDirectory()){
81-
FileUtils.copyDirectory(file, new File(output + "/" + path));
82+
FileUtils.copyDirectory(file, new File(output + File.separator + path));
8283
} else {
83-
FileUtils.copyFile(file, new File(output + "/" + path));
84+
FileUtils.copyFile(file, new File(output +File.separator + path));
8485
}
8586
result++;
8687
} catch (IOException e) {
8788
e.printStackTrace();
8889
return RESULT_STATE_INTERNAL_ERROR;
8990
}
9091
} else if(file.isDirectory()){
91-
int r = Standardization(new File(input + "/" + name), output);
92+
int r = Standardization(root, path + File.separator, output);
9293
if(r == RESULT_STATE_INTERNAL_ERROR){
9394
return RESULT_STATE_INTERNAL_ERROR;
9495
}
9596
result += r;
9697
} else if(name.length() > 4 && supportImageType.contains(name.substring(name.length() - 4))){
9798
if(file.length() < 1024 * 1024){
9899
try {
99-
FileUtils.copyFile(file, new File(output + "/images/" + System.currentTimeMillis() + "-" + name));
100+
FileUtils.copyFile(file, new File(output + File.separator + "images" + File.separator + System.currentTimeMillis() + "-" + name));
100101
} catch (IOException e) {
101102
e.printStackTrace();
102103
}
103104
}
104105
} else if(name.equals("info.json")){
105106
try {
106-
FileUtils.copyFile(file, new File(output + "/info.json"));
107+
FileUtils.copyFile(file, new File(output + File.separator + "info.json"));
107108
} catch (IOException e) {
108109
e.printStackTrace();
109110
}

0 commit comments

Comments
 (0)