mirror of
https://e.coding.net/circlecloud/YumCore.git
synced 2024-12-24 06:58:51 +00:00
fix: 修复插件备份配置错误
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
c1a8830eca
commit
33ef4ffe5a
@ -86,6 +86,9 @@ public class AbstractConfig extends YamlConfiguration {
|
|||||||
public void save(final File file) throws IOException {
|
public void save(final File file) throws IOException {
|
||||||
Validate.notNull(file, "文件不得为 null");
|
Validate.notNull(file, "文件不得为 null");
|
||||||
Files.createParentDirs(file);
|
Files.createParentDirs(file);
|
||||||
|
if (!file.exists()) {
|
||||||
|
file.createNewFile();
|
||||||
|
}
|
||||||
final Writer writer = new OutputStreamWriter(new FileOutputStream(file), UTF_8);
|
final Writer writer = new OutputStreamWriter(new FileOutputStream(file), UTF_8);
|
||||||
try {
|
try {
|
||||||
writer.write(data);
|
writer.write(data);
|
||||||
|
@ -20,8 +20,6 @@ import org.bukkit.configuration.InvalidConfigurationException;
|
|||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import com.google.common.io.Files;
|
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
import pw.yumc.YumCore.bukkit.P;
|
import pw.yumc.YumCore.bukkit.P;
|
||||||
|
|
||||||
@ -354,7 +352,6 @@ public class FileConfig extends AbstractConfig {
|
|||||||
@Override
|
@Override
|
||||||
public void save(final File file) throws IOException {
|
public void save(final File file) throws IOException {
|
||||||
Validate.notNull(file, "文件不得为 null");
|
Validate.notNull(file, "文件不得为 null");
|
||||||
Files.createParentDirs(file);
|
|
||||||
if (commentConfig != null) {
|
if (commentConfig != null) {
|
||||||
data = commentConfig.saveToString();
|
data = commentConfig.saveToString();
|
||||||
} else {
|
} else {
|
||||||
@ -383,8 +380,7 @@ public class FileConfig extends AbstractConfig {
|
|||||||
*/
|
*/
|
||||||
private boolean needUpdate(final FileConfig newcfg, final FileConfig oldcfg) throws IOException {
|
private boolean needUpdate(final FileConfig newcfg, final FileConfig oldcfg) throws IOException {
|
||||||
final String newver = newcfg.getString(CHECK_FIELD);
|
final String newver = newcfg.getString(CHECK_FIELD);
|
||||||
final String oldver = oldcfg.getString(CHECK_FIELD);
|
return newver != null && !newver.equalsIgnoreCase(oldcfg.getString(CHECK_FIELD));
|
||||||
return newver != null && !newver.equalsIgnoreCase(oldver);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -396,8 +392,8 @@ public class FileConfig extends AbstractConfig {
|
|||||||
final String filename = file.getName();
|
final String filename = file.getName();
|
||||||
final InputStream filestream = plugin.getResource(file.getName());
|
final InputStream filestream = plugin.getResource(file.getName());
|
||||||
final String errFileName = this.getErrName(filename);
|
final String errFileName = this.getErrName(filename);
|
||||||
loger.warning("错误的配置文件: " + filename + " 已备份为 " + errFileName);
|
|
||||||
file.renameTo(new File(file.getParent(), errFileName));
|
file.renameTo(new File(file.getParent(), errFileName));
|
||||||
|
loger.warning(String.format("错误的配置文件: %s 已备份为 %s !", filename, errFileName));
|
||||||
if (filestream == null) {
|
if (filestream == null) {
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
} else {
|
} else {
|
||||||
@ -416,10 +412,11 @@ public class FileConfig extends AbstractConfig {
|
|||||||
final String filename = oldcfg.getConfigName();
|
final String filename = oldcfg.getConfigName();
|
||||||
try {
|
try {
|
||||||
final String newCfgName = this.getBakName(filename);
|
final String newCfgName = this.getBakName(filename);
|
||||||
oldcfg.save(new File(file.getParent(), newCfgName));
|
final File newcfg = new File(file.getParent(), newCfgName);
|
||||||
loger.warning("配置: " + filename + " 已备份为 " + newCfgName);
|
oldcfg.save(newcfg);
|
||||||
|
loger.warning(String.format("配置: %s 已备份为 %s !", filename, newCfgName));
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
loger.warning("配置: " + filename + "备份失败!");
|
loger.warning(String.format("配置: %s 备份失败 异常: %s !", filename, e.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user