Skip to content

Commit

Permalink
试图修复macos无法正常回档
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuRuoLing committed Sep 28, 2024
1 parent 3b547e2 commit e108550
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
org.gradle.jvmargs=-Dfile.encoding=UTF-8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

import io.github.skydynamic.increment.storage.lib.util.IndexUtil;
import io.github.skydynamic.quickbackupmulti.QbmConstant;
import io.github.skydynamic.quickbackupmulti.i18n.Translate;
import io.github.skydynamic.quickbackupmulti.config.Config;

import io.github.skydynamic.quickbackupmulti.config.ConfigStorage;
import io.github.skydynamic.quickbackupmulti.i18n.Translate;
import net.fabricmc.api.EnvType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.NameFileFilter;
Expand All @@ -21,8 +19,11 @@
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

Expand All @@ -48,12 +49,20 @@ public static Path getBackupDir() {
public static void restoreClient(String slot) {
File targetBackupSlot = getBackupDir().resolve(slot).toFile();
try {
FileUtils.deleteDirectory(savePath.toFile());
final Iterator<Path> iterator = Files.walk(savePath)
.sorted(Comparator.reverseOrder())
.iterator();
while (iterator.hasNext()) {
Path p = iterator.next();
if (p.equals(savePath)) continue;
Files.delete(p);
}
//FileUtils.deleteDirectory(savePath.toFile());
FileUtils.copyDirectory(targetBackupSlot, savePath.toFile());
IndexUtil.copyIndexFile(
slot,
Path.of(Config.INSTANCE.getStoragePath()).resolve(Config.TEMP_CONFIG.worldName),
savePath.toFile()
slot,
Path.of(Config.INSTANCE.getStoragePath()).resolve(Config.TEMP_CONFIG.worldName),
savePath.toFile()
);
} catch (IOException e) {
LOGGER.error("Restore Failed", e);
Expand All @@ -68,9 +77,9 @@ public static void restore(String slot) {
}
FileUtils.copyDirectory(targetBackupSlot, savePath.toFile());
IndexUtil.copyIndexFile(
slot,
Path.of(Config.INSTANCE.getStoragePath()).resolve(Config.TEMP_CONFIG.worldName),
savePath.toFile()
slot,
Path.of(Config.INSTANCE.getStoragePath()).resolve(Config.TEMP_CONFIG.worldName),
savePath.toFile()
);
} catch (IOException e) {
LOGGER.error("Restore Failed", e);
Expand Down Expand Up @@ -111,7 +120,7 @@ public static ConfigStorage verifyConfig(ConfigStorage c, PlayerEntity player) {
// schedule enable
if (c.isScheduleBackup() && !Config.INSTANCE.getScheduleBackup()) {
ScheduleUtils.startSchedule(commandSource);
} else if (!c.isScheduleBackup() && Config.INSTANCE.getScheduleBackup()){
} else if (!c.isScheduleBackup() && Config.INSTANCE.getScheduleBackup()) {
ScheduleUtils.disableSchedule(commandSource);
}

Expand All @@ -125,7 +134,7 @@ public static ConfigStorage verifyConfig(ConfigStorage c, PlayerEntity player) {
ScheduleUtils.setScheduleCron(commandSource, c.getScheduleCron());
} catch (SchedulerException e) {
Messenger.sendMessage(commandSource,
Messenger.literal(tr("quickbackupmulti.schedule.cron.set_fail", e)));
Messenger.literal(tr("quickbackupmulti.schedule.cron.set_fail", e)));
}
}

Expand All @@ -135,7 +144,7 @@ public static ConfigStorage verifyConfig(ConfigStorage c, PlayerEntity player) {
ScheduleUtils.setScheduleInterval(commandSource, c.getScheduleInterval());
} catch (SchedulerException e) {
Messenger.sendMessage(commandSource,
Messenger.literal(tr("quickbackupmulti.schedule.cron.set_fail", e)));
Messenger.literal(tr("quickbackupmulti.schedule.cron.set_fail", e)));
}
}

Expand Down

0 comments on commit e108550

Please sign in to comment.