Search in sources :

Example 1 with FileResource

use of com.djrapitops.plan.storage.file.FileResource in project Plan by plan-player-analytics.

the class LocaleSystem method convertFromLegacyFormat.

private void convertFromLegacyFormat() {
    File oldCustomFile = files.getFileFromPluginFolder("locale.txt");
    if (!files.getLocaleFile().exists() && oldCustomFile.exists()) {
        try {
            logger.info("Converting locale.txt to yml...");
            Locale loaded = new LocaleFileReader(new FileResource("locale.txt", oldCustomFile)).loadLegacy(LangCode.CUSTOM);
            new LocaleFileWriter(loaded).writeToFile(files.getLocaleFile());
        } catch (IOException e) {
            errorLogger.error(e, ErrorContext.builder().whatToDo("Fix write permissions to " + files.getLocaleFile().toString()).build());
        }
    }
    for (LangCode code : LangCode.values()) {
        if (code == LangCode.CUSTOM)
            continue;
        File oldFile = files.getFileFromPluginFolder("locale_" + code + ".txt");
        if (!files.getFileFromPluginFolder(code.getFileName()).exists() && oldFile.exists()) {
            try {
                logger.info("Converting " + oldFile.getName() + " to yml...");
                Locale loaded = new LocaleFileReader(new FileResource(oldFile.getName(), oldFile)).loadLegacy(LangCode.CUSTOM);
                new LocaleFileWriter(loaded).writeToFile(files.getFileFromPluginFolder(code.getFileName()));
            } catch (IOException e) {
                errorLogger.error(e, ErrorContext.builder().whatToDo("Fix write permissions to " + files.getFileFromPluginFolder(code.getFileName()).toString()).build());
            }
        }
    }
}
Also used : FileResource(com.djrapitops.plan.storage.file.FileResource) IOException(java.io.IOException) File(java.io.File)

Aggregations

FileResource (com.djrapitops.plan.storage.file.FileResource)1 File (java.io.File)1 IOException (java.io.IOException)1