Skip to content

Commit

Permalink
添加抽卡信息备份
Browse files Browse the repository at this point in the history
  • Loading branch information
leck995 committed Oct 23, 2024
1 parent 5fc6f25 commit f837013
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import cn.tealc.wutheringwavestool.model.message.MessageInfo;
import cn.tealc.wutheringwavestool.model.message.MessageType;
import cn.tealc.wutheringwavestool.thread.CardPoolRequestTask;
import cn.tealc.wutheringwavestool.util.FileIO;
import cn.tealc.wutheringwavestool.util.LanguageManager;
import cn.tealc.wutheringwavestool.util.LogFileUtil;
import com.fasterxml.jackson.core.type.TypeReference;
Expand All @@ -21,8 +22,12 @@
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.chart.PieChart;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;

/**
Expand All @@ -32,6 +37,7 @@
* @create: 2024-07-03 01:18
*/
public class AnalysisPoolViewModel implements ViewModel {
private static final Logger LOG= LoggerFactory.getLogger(AnalysisPoolViewModel.class);
private final List<String> baseSSRList;

private SimpleStringProperty gameRootDir = new SimpleStringProperty();
Expand Down Expand Up @@ -190,6 +196,24 @@ private void savePoolData(Map<String, String> params){
ObjectMapper mapper = new ObjectMapper();
File poolJson=new File(String.format("data/%s/pool.json",playerId));
File dateJson=new File(String.format("data/%s/data.json",playerId));


if (poolJson.exists()){ //存在则备份
long time = poolJson.lastModified();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
long todayStart = calendar.getTimeInMillis();
if (time < todayStart) {// 判断文件修改时间是否不是今天
LOG.info("文件的最后修改时间不是今天,进行备份");
FileIO.rename(poolJson,"pool.json.bak",true);
} else {
LOG.info("文件的最后修改时间是今天,跳过备份");
}
}

File parentDir = poolJson.getParentFile();
File dataDir = parentDir.getParentFile();
if (!dataDir.exists()){
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/cn/tealc/wutheringwavestool/util/FileIO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cn.tealc.wutheringwavestool.util;

import java.io.File;

/**
* @program: WutheringWavesTool
* @description:
* @author: Leck
* @create: 2024-10-23 23:02
*/
public class FileIO {
public static boolean rename(File file, String newName, boolean overwrite) {
if (!file.exists()) return false;
File newFile = new File(file.getParent(), newName);
if (overwrite && newFile.exists()) {
newFile.delete();
}
return file.renameTo(newFile);

}
}

0 comments on commit f837013

Please sign in to comment.