forked from j62/ctbrec
Code cleanup
This commit is contained in:
parent
d742756413
commit
a59313df49
|
@ -3,8 +3,8 @@ package ctbrec;
|
|||
import static java.nio.file.StandardOpenOption.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
@ -28,7 +28,7 @@ import ctbrec.sites.Site;
|
|||
|
||||
public class Config {
|
||||
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(Config.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Config.class);
|
||||
|
||||
private static Config instance;
|
||||
private Settings settings;
|
||||
|
@ -37,7 +37,7 @@ public class Config {
|
|||
private File configDir;
|
||||
public static final String RECORDING_DATE_FORMAT = "yyyy-MM-dd_HH-mm-ss_SSS";
|
||||
|
||||
private Config(List<Site> sites) throws FileNotFoundException, IOException {
|
||||
private Config(List<Site> sites) {
|
||||
this.sites = sites;
|
||||
if(System.getProperty("ctbrec.config.dir") != null) {
|
||||
configDir = new File(System.getProperty("ctbrec.config.dir"));
|
||||
|
@ -52,7 +52,7 @@ public class Config {
|
|||
}
|
||||
}
|
||||
|
||||
private void load() throws FileNotFoundException, IOException {
|
||||
private void load() throws IOException {
|
||||
Moshi moshi = new Moshi.Builder()
|
||||
.add(Model.class, new ModelJsonAdapter(sites))
|
||||
.build();
|
||||
|
@ -69,13 +69,13 @@ public class Config {
|
|||
fileContent[1] = ' ';
|
||||
fileContent[2] = ' ';
|
||||
}
|
||||
String json = new String(fileContent, "UTF-8").trim();
|
||||
String json = new String(fileContent, StandardCharsets.UTF_8.name()).trim();
|
||||
settings = adapter.fromJson(json);
|
||||
settings.httpTimeout = Math.max(settings.httpTimeout, 10_000);
|
||||
if (settings.recordingsDir.endsWith("/")) {
|
||||
settings.recordingsDir = settings.recordingsDir.substring(0, settings.recordingsDir.length() - 1);
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
} catch (Exception e) {
|
||||
settings = OS.getDefaultSettings();
|
||||
for (Site site : sites) {
|
||||
site.setEnabled(!settings.disabledSites.contains(site.getName()));
|
||||
|
@ -99,12 +99,12 @@ public class Config {
|
|||
String backup = source.getName() + '.' + timestamp;
|
||||
File target = new File(source.getParentFile(), backup);
|
||||
Files.copy(source.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
} catch(Throwable e) {
|
||||
} catch (Exception e) {
|
||||
LOG.error("Couldn't create backup of settings file", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void init(List<Site> sites) throws FileNotFoundException, IOException {
|
||||
public static synchronized void init(List<Site> sites) throws IOException {
|
||||
if (instance == null) {
|
||||
instance = new Config(sites);
|
||||
instance.load();
|
||||
|
|
Loading…
Reference in New Issue