Skip to content

Commit

Permalink
Fix #26
Browse files Browse the repository at this point in the history
  • Loading branch information
Guo Yunhe committed Aug 31, 2016
1 parent 8521c55 commit 066b3f2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/me/guoyunhe/fontweak/FontConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public InputSource resolveEntity(String publicId, String systemId) {
// Create default if no config file found
InputStream in = getClass().getResourceAsStream("/me/guoyunhe/fontweak/config/default.conf");
try {
Files.copy(in, file.toPath());
file.getParentFile().mkdirs(); // Make all parents folders if not exists
Files.copy(in, file.toPath()); // Copty default config file
} catch (IOException ex) {
Logger.getLogger(FontConfig.class.getName()).log(Level.SEVERE, null, ex);
}
Expand All @@ -127,6 +128,15 @@ public void readConfig() {
doc = builder.parse(file);
} catch (SAXException ex) {
Logger.getLogger(FontConfig.class.getName()).log(Level.SEVERE, null, ex);
// Copy default config file if the XML file is invalid
InputStream in = getClass().getResourceAsStream("/me/guoyunhe/fontweak/config/default.conf");
try {
file.delete();
Files.copy(in, file.toPath()); // Copty default config file
doc = builder.parse(file);
} catch (IOException | SAXException ex1) {
Logger.getLogger(FontConfig.class.getName()).log(Level.SEVERE, null, ex1);
}
} catch (IOException ex) {
Logger.getLogger(FontConfig.class.getName()).log(Level.SEVERE, null, ex);
}
Expand Down

0 comments on commit 066b3f2

Please sign in to comment.