Commit 566e737b authored by fallenstardust's avatar fallenstardust

调整ini读取内容过滤空格和等号

parent df8cbc22
...@@ -14,15 +14,17 @@ import com.file.zip.ZipFile; ...@@ -14,15 +14,17 @@ import com.file.zip.ZipFile;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.Scanner;
import cn.garymb.ygomobile.Constants; import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.bean.ServerInfo; import cn.garymb.ygomobile.bean.ServerInfo;
...@@ -113,15 +115,37 @@ public class ServerUtil { ...@@ -113,15 +115,37 @@ public class ServerUtil {
entry = entris.nextElement(); entry = entris.nextElement();
if (!entry.isDirectory()) { if (!entry.isDirectory()) {
if (entry.getName().endsWith(".ini")) { if (entry.getName().endsWith(".ini")) {
Scanner scanner = new Scanner(zipFile.getInputStream(entry)); InputStreamReader in = new InputStreamReader(zipFile.getInputStream(entry), StandardCharsets.UTF_8);
while (scanner.hasNextLine()) { BufferedReader reader = new BufferedReader(in);
content.append(scanner.nextLine() + "|"); String line = null;
while ((line = reader.readLine()) != null) {
if (line.startsWith("[YGOProExpansionPack]") ||
line.startsWith("FileName") ||
line.startsWith("PackName") ||
line.startsWith("PackAuthor") ||
line.startsWith("PackHomePage") ||
line.startsWith("[YGOMobileAddServer]")) {
continue;
}
if (line.startsWith("ServerName")) {
String[] words = line.trim().split("[\t| =]+");
if (words.length >= 2) {
serverName = words[1];
}
}
if (line.startsWith("ServerHost")) {
String[] words = line.trim().split("[\t| =]+");
if (words.length >= 2) {
serverHost = words[1];
}
}
if (line.startsWith("ServerPort")) {
String[] words = line.trim().split("[\t| =]+");
if (words.length >= 2) {
serverPort = words[1];
}
}
} }
scanner.close();
serverName = content.substring(0, content.indexOf("|"));
serverHost = content.substring(content.indexOf("|") + 1, content.indexOf(":"));
serverPort = content.substring(content.indexOf(":") + 1, content.lastIndexOf("|"));
} }
} }
...@@ -131,7 +155,7 @@ public class ServerUtil { ...@@ -131,7 +155,7 @@ public class ServerUtil {
} else { } else {
YGOUtil.showTextToast("can't parse ex-server properly"); YGOUtil.showTextToast("can't parse ex-server properly");
} }
LogUtil.w("看看", serverName + isHost(serverHost) + serverHost + isNumeric(serverPort) + serverPort); LogUtil.w("seesee", serverName + isHost(serverHost) + serverHost + isNumeric(serverPort) + serverPort);
zipFile.close(); zipFile.close();
} catch (IOException e) { } catch (IOException e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment