Skip to content

Commit 2dc1dd7

Browse files
committed
Update SuperLocalPluginTracker.java
1 parent 36eadcb commit 2dc1dd7

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

src/main/java/org/hydev/mcpm/client/database/SuperLocalPluginTracker.java

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.hydev.mcpm.utils.PluginJarFile;
2020

2121
import java.io.*;
22+
import java.nio.file.Paths;
2223
import java.util.*;
2324
import java.util.stream.Collectors;
2425

@@ -80,6 +81,8 @@ public class SuperLocalPluginTracker implements SuperPluginTracker {
8081
// Directory containing the plugins
8182
private String pluginDirectory = "plugins";
8283

84+
final ObjectMapper mapper = new ObjectMapper();
85+
8386
/*
8487
* Instantiates a LocalPluginTracker with default parameters for general use
8588
*/
@@ -136,9 +139,49 @@ private ArrayList<PluginTrackerModel> readCsv() {
136139
}
137140

138141
/**
139-
* Save a hashmap's contents, overwriting a CSV file
142+
* Read a JSON file at the given location file and return a mapping between
143+
* plugin names and install
144+
* status
145+
*
146+
* @param csv The mapping between plugin name and boolean status
147+
*/
148+
private ArrayList<PluginTrackerModel> readJson() {
149+
try {
150+
// ObjectMapper mapper = new ObjectMapper();
151+
// Reads the json file and converts it to a list of PluginTrackerModel objects
152+
return this.mapper.readValue(new File(mainLockFile), mapper.getTypeFactory()
153+
.constructCollectionType(ArrayList.class, PluginTrackerModel.class));
154+
} catch (FileNotFoundException e) {
155+
156+
return (new ArrayList<PluginTrackerModel>());
157+
} catch (JsonParseException | JsonMappingException e) {
158+
throw new RuntimeException(e);
159+
} catch (IOException e) {
160+
throw new RuntimeException(e);
161+
}
162+
163+
}
164+
165+
/**
166+
* Save an ArrayList's contents into a JSON file by replacing all contents
167+
*
168+
* @param list ArrayList of PluginTrackerModel instances to save
169+
*
170+
*/
171+
private void saveJson(ArrayList<PluginTrackerModel> list) {
172+
try {
173+
this.mapper.writeValue(Paths.get(mainLockFile).toFile(), list);
174+
} catch (IOException e) {
175+
throw new RuntimeException(e);
176+
} catch (Exception ex) {
177+
ex.printStackTrace();
178+
}
179+
}
180+
181+
/**
182+
* Save an ArrayList's contents, overwriting a CSV file
140183
*
141-
* @param map Hashmap to save
184+
* @param list ArrayList of PluginTrackerModel instances to save
142185
*
143186
*/
144187
private void saveCsv(ArrayList<PluginTrackerModel> listToSave) {

0 commit comments

Comments
 (0)