无聊发个自己写的备份存档的命令行程序
如题,用于自动备份存档,运行的话请先运行游戏再运行此程序。刚开启时会让你输入自定义的备份周期时间,备份的存档都在Saved Games\Metro_Exodus_Save_Backup文件下。
周期备份在Auto文件夹下,手动备份在Manual文件夹下,Epic正版离线模式的存档在Offline文件夹下,其他版本的在Online文件夹下。
***注***
1. 周期时间输入0会禁用自动备份功能
2. F5为手动备份,F6为恢复存档
3. 目前有事会因无法覆写user.cfg而卡住,所以尽量手动恢复
***下方为源码,打包好的exe在附件***
// AutoBackupMetroExodusSaves.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <Windows.h>
#include <iostream>
#include <chrono>
#include <filesystem>
#include <conio.h>
namespace fs = std::filesystem;
bool isRunning()
{
HWND ME_Process = FindWindowA(NULL, "4A Engine");
if (ME_Process != 0)
{
return true;
}
else
{
std::cout << "游戏未启动,请先启动游戏再启动本程序." << std::endl;
Sleep(10000);
return false;
}
}
int main()
{
int Sleep_Time, Current_Auto_Backup_Round_Count = 1, Current_Manual_Backup_Round_Count = 1, Last_Auto_Save_Time = 0, Last_Manual_Save_Time = 0;
std::cout << "请输入自动备份周期,以分钟为单位(输入0禁用)\n";
std::cin >> Sleep_Time;
bool Auto_Backup_Switch;
if (Sleep_Time == 0) { Auto_Backup_Switch = false; }
else { Auto_Backup_Switch = true; }
std::string W_D_V = std::getenv("SYSTEMDRIVE");
std::string U_N_V = std::getenv("USERNAME");
std::string Save_Base_Location = "";
Save_Base_Location += W_D_V;
Save_Base_Location += "/Users/";
Save_Base_Location += U_N_V;
Save_Base_Location += "/Saved Games/";
std::string Offline_Save_Check = Save_Base_Location + "m3_auto_save";
std::string Online_Save_Check = Save_Base_Location + "metro exodus";
auto Start_Time = std::chrono::high_resolution_clock::now();
auto Start_Time_For_Auto = Start_Time;
while (isRunning())
{
auto Curr_Time_For_Auto = std::chrono::high_resolution_clock::now();
//如输入了时间,周期自动备份
if (((std::chrono::duration_cast<std::chrono::minutes>(Curr_Time_For_Auto - Start_Time_For_Auto).count() == Sleep_Time)||(Current_Auto_Backup_Round_Count == 1)) && Auto_Backup_Switch)
{
if (fs::exists(Offline_Save_Check))
{
// The file exists, and is open for input
std::string Auto_Offline_Save_Backup_S_1 = Offline_Save_Check;
std::string Auto_Offline_Save_Backup_D_1 = Save_Base_Location + "Metro_Exodus_Save_Backup";
if (fs::exists(Auto_Offline_Save_Backup_D_1) == false)
{
fs::create_directory(Auto_Offline_Save_Backup_D_1);
}
Auto_Offline_Save_Backup_D_1 +="/Auto";
if (fs::exists(Auto_Offline_Save_Backup_D_1) == false)
{
fs::create_directory(Auto_Offline_Save_Backup_D_1);
}
Auto_Offline_Save_Backup_D_1 += "/Offline_Bak";
if (fs::exists(Auto_Offline_Save_Backup_D_1) == false)
{
fs::create_directory(Auto_Offline_Save_Backup_D_1);
}
Auto_Offline_Save_Backup_D_1 += "/Bak_";
Auto_Offline_Save_Backup_D_1 += std::to_string(Current_Auto_Backup_Round_Count);
if (fs::exists(Auto_Offline_Save_Backup_D_1) == false)
{
fs::create_directory(Auto_Offline_Save_Backup_D_1);
}
Auto_Offline_Save_Backup_D_1 += "/m3_auto_save";
fs::copy(Auto_Offline_Save_Backup_S_1, Auto_Offline_Save_Backup_D_1, fs::copy_options::overwrite_existing);
std::string Auto_Offline_Save_Backup_S_2 = Save_Base_Location + "user.cfg";
std::string Auto_Offline_Save_Backup_D_2 = Save_Base_Location + "Metro_Exodus_Save_Backup/Auto/Offline_Bak/Bak_";
Auto_Offline_Save_Backup_D_2 += std::to_string(Current_Auto_Backup_Round_Count);
Auto_Offline_Save_Backup_D_2 += "/user.cfg";
fs::copy(Auto_Offline_Save_Backup_S_2, Auto_Offline_Save_Backup_D_2, fs::copy_options::overwrite_existing);
std::cout << "地铁:离去Epic离线模式存档 第 " << Current_Auto_Backup_Round_Count << " 次 周期备份完成.\n";
}
else
{
printf("地铁:离去Epic离线模式存档 不存在!\n");
}
if (fs::exists(Online_Save_Check))
{
// The file exists, and is open for input
std::string Auto_Online_Save_Backup_S = Online_Save_Check;
std::string Auto_Online_Save_Backup_D = Save_Base_Location + "Metro_Exodus_Save_Backup";
if (fs::exists(Auto_Online_Save_Backup_D) == false)
{
fs::create_directory(Auto_Online_Save_Backup_D);
}
Auto_Online_Save_Backup_D += "/Auto";
if (fs::exists(Auto_Online_Save_Backup_D) == false)
{
fs::create_directory(Auto_Online_Save_Backup_D);
}
Auto_Online_Save_Backup_D += "/Online_Bak";
if (fs::exists(Auto_Online_Save_Backup_D) == false)
{
fs::create_directory(Auto_Online_Save_Backup_D);
}
Auto_Online_Save_Backup_D += "/Bak_";
Auto_Online_Save_Backup_D += std::to_string(Current_Auto_Backup_Round_Count);
if (fs::exists(Auto_Online_Save_Backup_D) == false)
{
fs::create_directory(Auto_Online_Save_Backup_D);
}
fs::copy(Auto_Online_Save_Backup_S, Auto_Online_Save_Backup_D, fs::copy_options::overwrite_existing | fs::copy_options::recursive);
std::cout << "地铁:离去Epic在线模式/Steam版/CPY版存档 第 " << Current_Auto_Backup_Round_Count << " 次 周期备份完成.\n";
}
else
{
printf("地铁:离去Epic在线模式/Steam版/CPY版存档 不存在!\n");
}
if(Current_Auto_Backup_Round_Count==1)
{
Last_Auto_Save_Time = 0;
}
else
{
Last_Auto_Save_Time = (Sleep_Time-1) * Current_Auto_Backup_Round_Count*60;
}
Current_Auto_Backup_Round_Count++;
Start_Time_For_Auto = std::chrono::high_resolution_clock::now();
}
//按F5手动备份
if (GetKeyState(VK_F5) & 0x8000)
{
bool Save_Manual_Backuped = false;
if (fs::exists(Offline_Save_Check))
{
// The file exists, and is open for input
std::string Manual_Offline_Save_Backup_S_1 = Offline_Save_Check;
std::string Manual_Offline_Save_Backup_D_1 = Save_Base_Location + "Metro_Exodus_Save_Backup";
if (fs::exists(Manual_Offline_Save_Backup_D_1) == false)
{
fs::create_directory(Manual_Offline_Save_Backup_D_1);
}
Manual_Offline_Save_Backup_D_1 += "/Manual";
if (fs::exists(Manual_Offline_Save_Backup_D_1) == false)
{
fs::create_directory(Manual_Offline_Save_Backup_D_1);
}
Manual_Offline_Save_Backup_D_1 += "/Offline_Bak";
if (fs::exists(Manual_Offline_Save_Backup_D_1) == false)
{
fs::create_directory(Manual_Offline_Save_Backup_D_1);
}
Manual_Offline_Save_Backup_D_1 += "/Bak_";
Manual_Offline_Save_Backup_D_1 += std::to_string(Current_Manual_Backup_Round_Count);
if (fs::exists(Manual_Offline_Save_Backup_D_1) == false)
{
fs::create_directory(Manual_Offline_Save_Backup_D_1);
}
Manual_Offline_Save_Backup_D_1 += "/m3_auto_save";
fs::copy(Manual_Offline_Save_Backup_S_1, Manual_Offline_Save_Backup_D_1, fs::copy_options::overwrite_existing);
std::string Manual_Offline_Save_Backup_S_2 = Save_Base_Location + "user.cfg";
std::string Manual_Offline_Save_Backup_D_2 = Save_Base_Location + "Metro_Exodus_Save_Backup/Manual/Offline_Bak/Bak_";
Manual_Offline_Save_Backup_D_2 += std::to_string(Current_Manual_Backup_Round_Count);
Manual_Offline_Save_Backup_D_2 += "/user.cfg";
fs::copy(Manual_Offline_Save_Backup_S_2, Manual_Offline_Save_Backup_D_2, fs::copy_options::overwrite_existing);
std::cout << "地铁:离去Epic离线模式存档 第 " << Current_Manual_Backup_Round_Count << " 次 手动备份完成.\n";
Save_Manual_Backuped = true;
}
else
{
printf("地铁:离去Epic离线模式存档 不存在!\n");
}
if (fs::exists(Online_Save_Check))
{
// The file exists, and is open for input
std::string Manual_Online_Save_Backup_S = Online_Save_Check;
std::string Manual_Online_Save_Backup_D = Save_Base_Location + "Metro_Exodus_Save_Backup";
if (fs::exists(Manual_Online_Save_Backup_D) == false)
{
fs::create_directory(Manual_Online_Save_Backup_D);
}
Manual_Online_Save_Backup_D += "/Manual";
if (fs::exists(Manual_Online_Save_Backup_D) == false)
{
fs::create_directory(Manual_Online_Save_Backup_D);
}
Manual_Online_Save_Backup_D += "/Online_Bak";
if (fs::exists(Manual_Online_Save_Backup_D) == false)
{
fs::create_directory(Manual_Online_Save_Backup_D);
}
Manual_Online_Save_Backup_D += "/Bak_";
Manual_Online_Save_Backup_D += std::to_string(Current_Manual_Backup_Round_Count);
if (fs::exists(Manual_Online_Save_Backup_D) == false)
{
fs::create_directory(Manual_Online_Save_Backup_D);
}
fs::copy(Manual_Online_Save_Backup_S, Manual_Online_Save_Backup_D, fs::copy_options::overwrite_existing | fs::copy_options::recursive);
std::cout << "地铁:离去Epic在线模式/Steam版/CPY版存档 第 " << Current_Manual_Backup_Round_Count << " 次 手动备份完成.\n";
Save_Manual_Backuped = true;
}
else
{
printf("地铁:离去Epic在线模式/Steam版/CPY版存档 不存在!\n");
}
if(Save_Manual_Backuped)
{
auto Curr_Time_For_Manual = std::chrono::high_resolution_clock::now();
Last_Manual_Save_Time = std::chrono::duration_cast<std::chrono::seconds>(Curr_Time_For_Manual - Start_Time).count();
Current_Manual_Backup_Round_Count++;
}
}
//按F6手动还原
if (GetKeyState(VK_F6) & 0x8000)
{
if(Last_Auto_Save_Time==0 && Last_Manual_Save_Time==0)
{
std::cout << "无可供恢复的备份存档!" << std::endl;
}
else
{
if(Last_Manual_Save_Time > Last_Auto_Save_Time)
{
std::string Offline_Backup_Save_Check = Save_Base_Location + "Metro_Exodus_Save_Backup/Auto/Offline_Bak/Bak_";
Offline_Backup_Save_Check += std::to_string(Current_Auto_Backup_Round_Count-1);
std::string Online_Backup_Save_Check = Save_Base_Location + "Metro_Exodus_Save_Backup/Manual/Online_Bak/Bak_";
Online_Backup_Save_Check += std::to_string(Current_Manual_Backup_Round_Count-1);
if (fs::exists(Offline_Backup_Save_Check))
{
std::string Manual_Offline_Save_Restore_S_1 = Offline_Backup_Save_Check + "/m3_auto_save";
std::string Manual_Offline_Save_Restore_D_1 = Offline_Save_Check;
fs::copy(Manual_Offline_Save_Restore_S_1, Manual_Offline_Save_Restore_D_1, fs::copy_options::overwrite_existing);
std::string Manual_Offline_Save_Restore_S_2 = Offline_Backup_Save_Check + "user.cfg";
std::string Manual_Offline_Save_Restore_D_2 = Offline_Save_Check;
fs::copy(Manual_Offline_Save_Restore_S_2, Manual_Offline_Save_Restore_D_2, fs::copy_options::overwrite_existing);
std::cout << "地铁:离去Epic离线模式存档 以第 " << Current_Manual_Backup_Round_Count << " 次 手动备份恢复完成.\n";
}
else
{
printf("地铁:离去Epic离线模式 手动备份存档不存在!\n");
}
if (fs::exists(Online_Backup_Save_Check))
{
fs::copy(Online_Backup_Save_Check, Online_Save_Check, fs::copy_options::overwrite_existing & fs::copy_options::recursive);
std::cout << "地铁:离去Epic在线模式/Steam版/CPY版存档 以第 " << Current_Manual_Backup_Round_Count << " 次 手动备份恢复完成.\n";
}
else
{
printf("地铁:离去Epic在线模式/Steam版/CPY版 手动备份存档不存在!\n");
}
}
else
{
std::string Offline_Backup_Save_Check = Save_Base_Location + "Metro_Exodus_Save_Backup/Manual/Offline_Bak/Bak_";
Offline_Backup_Save_Check += std::to_string(Current_Manual_Backup_Round_Count-1);
std::string Online_Backup_Save_Check = Save_Base_Location + "Metro_Exodus_Save_Backup/Auto/Online_Bak/Bak_";
Online_Backup_Save_Check += std::to_string(Current_Auto_Backup_Round_Count-1);
if (fs::exists(Offline_Backup_Save_Check))
{
std::string Auto_Offline_Save_Backup_S_1 = Offline_Backup_Save_Check + "/m3_auto_save";
std::string Auto_Offline_Save_Backup_D_1 = Offline_Save_Check;
fs::copy(Auto_Offline_Save_Backup_S_1, Auto_Offline_Save_Backup_D_1, fs::copy_options::overwrite_existing);
std::string Auto_Offline_Save_Backup_S_2 = Offline_Backup_Save_Check + "user.cfg";
std::string Auto_Offline_Save_Backup_D_2 = Save_Base_Location + "user.cfg";
fs::copy(Auto_Offline_Save_Backup_S_2, Auto_Offline_Save_Backup_D_2, fs::copy_options::overwrite_existing);
std::cout << "地铁:离去Epic离线模式存档 以第 " << Current_Auto_Backup_Round_Count << " 次 自动备份恢复完成.\n";
}
else
{
printf("地铁:离去Epic离线模式 周期存档备份不存在!\n");
}
if (fs::exists(Online_Backup_Save_Check))
{
fs::copy(Online_Backup_Save_Check, Online_Save_Check, fs::copy_options::overwrite_existing & fs::copy_options::recursive);
std::cout << "地铁:离去Epic在线模式/Steam版/CPY版存档以第 " << Current_Auto_Backup_Round_Count << " 次 自动备份恢复完成.\n";
}
else
{
printf("地铁:离去Epic在线模式/Steam版/CPY版 周期存档备份不存在!\n");
}
}
}
}
//按F12退出程序
if (GetKeyState(VK_F12) & 0x8000)
{
break;
}
}
return 0;
}
**** Hidden Message *****
备份存档的命令行程序备份存档的命令行程序备份存档的命令行程序
试一试,感谢分享
C++玩家的血泪啊,这个用py可能都不需要50行 多谢啊,好东西
谢谢分享
为什么无法使用? 多谢分享
LZ能不能做个最高难度即时存档mod啊 感谢楼主的分享!!! 感谢分享!!
感谢分享
111111111111 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
惺惺惜惺惺想寻寻寻寻寻寻寻寻
萨达萨达萨达撒
感谢分享~~~~~~~!!!!!!!!!!!!!!
谢谢分享啊啊
感谢分享! 感谢楼主分享
谢谢分享,支持3DM 感谢楼主分享{:3_119:} 感谢分享 下载看看 很好的帖
非常感謝分享
大推推推! 这个不错啊,谢谢楼主分享
必须支持一下6666666666666
加油6666666666666666666666
66666666666666666
666666666666666666666666666666
6666666666666
页:
[1]
2