Magisk/app/src/main/java/com/topjohnwu/magisk/model/Module.java

75 lines
1.7 KiB
Java
Raw Normal View History

2016-08-20 17:26:49 +02:00
package com.topjohnwu.magisk.model;
2016-08-17 13:00:55 +02:00
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
public class Module {
private final boolean isValid;
private final boolean isCache;
private File mPropFile;
private String mName;
private String mVersion;
private String mDescription;
public Module(File file) {
this.isCache = file.getPath().contains("cache");
this.isValid = new File(file + "/module.prop").exists();
if (isValid) {
mPropFile = new File(file + "/module.prop");
}
}
public boolean isValid() {
return isValid && mPropFile != null;
}
public boolean isCache() {
return isCache;
}
public String getName() {
return mName;
}
public String getVersion() {
return mVersion;
}
public String getDescription() {
return mDescription;
}
public void parse() throws Exception {
BufferedReader reader = new BufferedReader(new FileReader(mPropFile));
String line;
while ((line = reader.readLine()) != null) {
String[] parts = line.split("=", 2);
if (parts.length != 2) {
continue;
}
String key = parts[0].trim();
if (key.charAt(0) == '#') {
continue;
}
String value = parts[1].trim();
switch (key) {
case "name":
mName = value;
break;
case "version":
mVersion = value;
break;
case "description":
mDescription = value;
break;
}
}
reader.close();
}
}