MCPcopy Index your code
hub / github.com/10cks/fofaEX / settingInit

Method settingInit

src/main/java/Main.java:2015–2191  ·  view source on GitHub ↗
(BufferedReader rules, File accountsFile, JPanel initPanel, JTextField initTextField, JTextField fofaEmail, JTextField fofaKey, Map<String, JButton> initButtonsMap)

Source from the content-addressed store, hash-verified

2013
2014 // 账户设置
2015 static public void settingInit(BufferedReader rules, File accountsFile, JPanel initPanel, JTextField initTextField, JTextField fofaEmail, JTextField fofaKey, Map<String, JButton> initButtonsMap) {
2016 // 使用Gson
2017 Gson gson = new Gson();
2018 try {
2019 if (accountsFile.exists() && accountsFile.length() != 0) {
2020 BufferedReader br = new BufferedReader(new FileReader(accountsFile));
2021 //转换为哈希映射类型
2022 Map<String, JsonElement> accounts = gson.fromJson(br, new TypeToken<Map<String, JsonElement>>(){}.getType());
2023 // 从哈希映射中获取数据并设置
2024 if (accounts.get("fofaEmail") != null && accounts.get("fofaKey") != null) {
2025 fofaEmail.setText(accounts.get("fofaEmail").getAsString());
2026 fofaKey.setText(accounts.get("fofaKey").getAsString());
2027 }
2028 if (accounts.get("queryNumber") != null) {
2029 sizeSetting = accounts.get("queryNumber").getAsInt();
2030 }
2031 if(accounts.get("queryFull") != null) {
2032 setFull = accounts.get("queryFull").getAsBoolean();
2033 }
2034 }
2035 } catch (IOException e) {
2036 e.printStackTrace();
2037 }
2038 // 读取文件内容,并创建新的按钮
2039 try {
2040 Map<String, String> newMap = new LinkedHashMap<>();
2041 String line;
2042 while ((line = rules.readLine()) != null) {
2043 line = line.trim();
2044
2045 // 跳过井号注释
2046 if (line.startsWith("#")) {
2047 continue;
2048 }
2049
2050 if (line.startsWith("\"") && line.contains("{") && line.contains("}")) {
2051 String[] parts = line.split(":", 2);
2052
2053 String key = parts[0].substring(1, parts[0].length() - 1).trim();
2054
2055 String value = parts[1].substring(1, parts[1].length() - 2).trim();
2056 newMap.put(key, value);
2057 }
2058 }
2059 rules.close();
2060
2061 // 移除按钮
2062 Iterator<Map.Entry<String, JButton>> iterator = initButtonsMap.entrySet().iterator();
2063 while (iterator.hasNext()) {
2064 Map.Entry<String, JButton> entry = iterator.next();
2065 if (!newMap.containsKey(entry.getKey())) {
2066 initPanel.remove(entry.getValue());
2067 iterator.remove();
2068 }
2069 }
2070
2071 // 更新并新增按钮
2072 for (Map.Entry<String, String> entry : newMap.entrySet()) {

Callers 1

mainMethod · 0.95

Calls 1

containsMethod · 0.80

Tested by

no test coverage detected