Skip to content

Commit

Permalink
feat: bak data
Browse files Browse the repository at this point in the history
每当存档用户数据时均备份上次自动保存
  • Loading branch information
mystringEmpty committed Aug 10, 2024
1 parent 29f065a commit 340f506
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 25 deletions.
5 changes: 4 additions & 1 deletion Dice/BlackListManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include "DiceAttrVar.h"

using std::pair;
using std::unordered_set;
using std::unordered_map;
using std::multimap;

class DiceEvent;

Expand Down Expand Up @@ -64,7 +67,7 @@ class DDBlackMark

class DDBlackManager
{
vector<DDBlackMark> vBlackList;
std::vector<DDBlackMark> vBlackList;
//云端编号映射表
unordered_map<int, unsigned int> mCloud;
unordered_set<unsigned int> sIDEmpty;
Expand Down
55 changes: 36 additions & 19 deletions Dice/Dice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,16 @@ void readUserData(){
fs::copy_options::overwrite_existing, ec);
log << "读取用户记录" + to_string(cnt) + "";
}
else if (fs::exists(dir / "UserConf.bak")) {
cnt = loadBFile(dir / "UserConf.bak", UserList);
if (cnt > 0)log << "恢复用户记录" + to_string(cnt) + "";
else if (fs::exists(dir / "UserConf.dat.bak")
&& (cnt = loadBFile(dir / "UserConf.dat.bak", UserList)) > 0) {
log << "恢复用户记录" + to_string(cnt) + "";
}
else {
cnt = loadBFile<long long, User, &User::old_readb>(dir / "UserConf.RDconf", UserList);
if (cnt > 0)log << "迁移用户记录" + to_string(cnt) + "";
else if (fs::exists(dir / "UserConf.bak")
&& (cnt = loadBFile(dir / "UserConf.bak", UserList)) > 0) {
log << "恢复用户记录" + to_string(cnt) + "";
}
else if ((cnt = loadBFile<long long, User, &User::old_readb>(dir / "UserConf.RDconf", UserList)) > 0) {
log << "迁移用户记录" + to_string(cnt) + "";
}
//for QQ Channel
if (User& self{ getUser(console.DiceMaid) }; !self.get_ll("tinyID")) {
Expand All @@ -162,9 +165,13 @@ void readUserData(){
fs::copy_options::overwrite_existing, ec);
log << "读取玩家记录" + to_string(cnt) + "";
}
else if (fs::exists(dir / "PlayerCards.bak")) {
cnt = loadBFile(dir / "PlayerCards.bak", PList);
if (cnt > 0)log << "恢复玩家记录" + to_string(cnt) + "";
else if (fs::exists(dir / "PlayerCards.RDconf.bak")
&& (cnt = loadBFile(dir / "PlayerCards.RDconf.bak", PList)) > 0) {
log << "恢复玩家记录" + to_string(cnt) + "";
}
else if (fs::exists(dir / "PlayerCards.bak")
&& (cnt = loadBFile(dir / "PlayerCards.bak", PList)) > 0) {
log << "恢复玩家记录" + to_string(cnt) + "";
}
for (const auto& pl : PList) {
if (!UserList.count(pl.first))getUser(pl.first);
Expand All @@ -181,13 +188,16 @@ void readUserData(){
fs::copy_options::overwrite_existing, ec);
log << "读取群聊记录" + to_string(cnt) + "";
}
else if (fs::exists(dir / "ChatConf.bak")) {
cnt = loadBFile(dir / "ChatConf.bak", ChatList);
if (cnt > 0)log << "恢复群聊记录" + to_string(cnt) + "";
else if (fs::exists(dir / "ChatConf.dat.bak")
&& (cnt = loadBFile(dir / "ChatConf.dat.bak", ChatList)) > 0) {
log << "恢复群聊记录" + to_string(cnt) + "";
}
else {
cnt = loadBFile(dir / "ChatConf.RDconf", ChatList);
if (cnt > 0)log << "迁移群聊记录" + to_string(cnt) + "";
else if (fs::exists(dir / "ChatConf.bak")
&& (cnt = loadBFile(dir / "ChatConf.bak", ChatList)) > 0) {
log << "恢复群聊记录" + to_string(cnt) + "";
}
else if ((cnt = loadBFile(dir / "ChatConf.RDconf", ChatList)) > 0) {
log << "迁移群聊记录" + to_string(cnt) + "";
}
}
catch (const std::exception& e) {
Expand All @@ -207,12 +217,19 @@ void dataBackUp()
{
std::error_code ec;
std::filesystem::create_directory(DiceDir / "conf", ec);
std::filesystem::create_directory(DiceDir / "user", ec);
static auto dirUser{ DiceDir / "user" };
std::filesystem::create_directory(dirUser, ec);
std::filesystem::create_directory(DiceDir / "audit", ec);
//备份列表
saveBFile(DiceDir / "user" / "UserConf.dat", UserList);
saveBFile(DiceDir / "user" / "PlayerCards.RDconf", PList);
saveBFile(DiceDir / "user" / "ChatConf.dat", ChatList);
static auto pathUser{ dirUser / "UserConf.dat" };
fs::copy_file(pathUser, dirUser / "UserConf.dat.bak", fs::copy_options::update_existing);
saveBFile(pathUser, UserList);
static auto pathPlayer{ dirUser / "PlayerCards.RDconf" };
fs::copy_file(pathPlayer, dirUser / "PlayerCards.RDconf.bak", fs::copy_options::update_existing);
saveBFile(pathPlayer, PList);
static auto pathChat{ dirUser / "ChatConf.dat" };
fs::copy_file(pathChat, dirUser / "ChatConf.dat.bak", fs::copy_options::update_existing);
saveBFile(pathChat, ChatList);
}

atomic_flag isIniting = ATOMIC_FLAG_INIT;
Expand Down
13 changes: 8 additions & 5 deletions Dice/DiceEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3354,6 +3354,14 @@ int DiceEvent::InnerOrder() {
replyHelp("pc");
return 1;
}
else if (strOption == "clr") {
if (PList.count(fromChat.uid)) {
PList.erase(fromChat.uid);
replyMsg("strPcClr");
}
else replyMsg("strPcNotExistErr");
return 1;
}
Player& pl = getPlayer(fromChat.uid);
int resno = 0;
if (strOption == "tag") {
Expand Down Expand Up @@ -3490,11 +3498,6 @@ int DiceEvent::InnerOrder() {
}
return 1;
}
else if (strOption == "clr") {
PList.erase(fromChat.uid);
replyMsg("strPcClr");
return 1;
}
else if (strOption == "type") {
if ((at("new_type") = strip(readRest())).str_empty()) {
set("attr","模板类");
Expand Down

0 comments on commit 340f506

Please sign in to comment.