Sorry to bump, but I've recently started up on the project again. I ended up starting over as the gui didn't scale -_- (forgot about that)
My new save method
...
protected void saveSettings(){
try{
File oldFile = new File(settingsFile.toString() + ".old");
if(oldFile.exists()){
oldFile.delete();
}
settingsFile.renameTo(oldFile);
Gson constructor = new Gson();
BufferedWriter out2 = new BufferedWriter(new FileWriter(settingsFile));
out2.write(constructor.toJson(settings));
out2.close();
}catch(Exception ex){
cout.err("Unable to write settings file!");
ex.printStackTrace();
}
}
...
Would churn out this atm:
Originally Posted by
settings.mcnn
{"REPOSITORIES":{"Test Repository":"http://dl.dropbox.com/u/1650058/test.repo","Test 2":"http://dl.dropbox.com/u/1650058/test.repo"},"checkForUpdates":false,"warnBadLinks" :true,"autoRefresh":false,"refreshRate":182601,"MC NN_VERSION":"0.8-beta","SETTINGS_FILE_VERSION":"3","REPO_FILE_VERSI ON":"2"}
I'm trying to make it more user friendly for a user to manually edit it if needed. Is there anything built into Gson (or realitvely easy to add) to make it more along the lines of:
{
"REPOSITORIES":
{
"Test Repository":"http://dl.dropbox.com/u/1650058/test.repo",
"Test 2":"http://dl.dropbox.com/u/1650058/test.repo"
},
"checkForUpdates":false,
"warnBadLinks":true,
"autoRefresh":false,
"refreshRate":182601,
"MCNN_VERSION":"0.8-beta",
"SETTINGS_FILE_VERSION":"3",
"REPO_FILE_VERSION":"2"
}
I'm thinking about manually adding System.getProperty("line.separator") after each "," but that wouldn't work for
every case, and it wouldn't handle indentation. It's not critical to my program (it functions fine now), but again, trying to add polish to it.