Skip to content
This repository has been archived by the owner on Nov 26, 2022. It is now read-only.

Commit

Permalink
Important Update 1.6.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasonzyt committed Sep 20, 2020
1 parent aa7cb38 commit cf836a9
Show file tree
Hide file tree
Showing 11 changed files with 558 additions and 107 deletions.
2 changes: 1 addition & 1 deletion Visual Studio Project/AutoBackup/AutoBackup.rc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ END

// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1 ICON "C:\\Users\\Administrator\\Desktop\\C++\\AutoBackup.del\\Timer\\ͼ��.ico"
IDI_ICON1 ICON "icon.ico"

#endif // ����(���壬�й�) resources
/////////////////////////////////////////////////////////////////////////////
Expand Down
9 changes: 6 additions & 3 deletions Visual Studio Project/AutoBackup/AutoBackup.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,22 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="getConfig.h" />
<ClInclude Include="Main.h" />
<ClInclude Include="operate_config.h" />
<ClInclude Include="operate_config.del.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="getConfig.cpp" />
<ClCompile Include="Main.cpp" />
<ClCompile Include="operate_config.cpp" />
<ClCompile Include="Main.h.cpp" />
<ClCompile Include="operate_config.del.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="AutoBackup.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="..\..\AutoBackup.del\Timer\图标.ico" />
<Image Include="icon.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
25 changes: 17 additions & 8 deletions Visual Studio Project/AutoBackup/AutoBackup.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
<ClInclude Include="resource.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="operate_config.h">
<ClInclude Include="Main.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="Main.h">
<ClInclude Include="getConfig.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="operate_config.del.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
Expand All @@ -30,17 +33,23 @@
<Filter>资源文件</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Image Include="..\..\AutoBackup.del\Timer\图标.ico">
<Filter>资源文件</Filter>
</Image>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Main.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="operate_config.cpp">
<ClCompile Include="getConfig.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="operate_config.del.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="Main.h.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Image Include="icon.ico">
<Filter>资源文件</Filter>
</Image>
</ItemGroup>
</Project>
35 changes: 25 additions & 10 deletions Visual Studio Project/AutoBackup/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include<stdio.h>
#include<string>
#include<Windows.h>
#include"getConfig.h"
#include"main.h"
#pragma warning(disable:6001)
#pragma warning(disable:6031)
Expand All @@ -14,27 +15,41 @@ int backuptime, backupms;

int main() {
SetConsoleTitle(L"自动备份 AutoBackup");
cout << "AutoBackup v1.0.4(Release x64) - Autobackup tool. Copyright (C)2020 JasonZYT" << endl;
cout << "AutoBackup v1.6.6(Release x64) - Autobackup tool. Copyright (C)2020 JasonZYT" << endl;
cout << "GitHub Repository:https://www.github.com/Jasonzyt/AutoBackup" << endl;
_PR(0, "Starting...");
string opp = getConfig("config.ini", "OutputPath");
string tp = getConfig("config.ini", "TargetPath");
string bt = getConfig("config.ini", "BackupTime");
_PR(0, "Reading Config...");
string opp = getConfig("config.ini", "OutputPath", "backup\\");
string tp = getConfig("config.ini", "TargetPath", "");
string bt = getConfig("config.ini", "BackupTime", "60");
int debug = StringToInt(getConfig("config.ini", "Debug", "0"));
string opfn = getConfig("config.ini", "OutputFilname","%Y-%m-%d %H.zip");
if ((findFile("./config.ini")) == false) {
_PR(2, "Config Read Fail.");
getchar();
return 0;
}
else {
_PR(0, "Config Read Success.");
}
string opf = editZIPFilename(opfn);
int backuptime = StringToInt(bt);
int backupms = backuptime * 60 * 1000;
string d0 = getCmdStr(opp,tp);
cout << "[DEBUG]" << endl << "已读取配置:" << endl << "OutputPath=" << opp << endl << "TargetPath=" << tp << endl << "BackupTime=Every " << backuptime << " Minute(s)(Every " << backupms << " ms)" << endl << "Command : " << d0 << endl;
if (opp == "")
if (debug == 1)
{
opp = "backup\\";
ostringstream op;
string d0 = getCmdStr(opp, tp, opf);
op << "已读取配置:" << endl << "OutputPath=" << opp << endl << "TargetPath=" << tp << endl << "BackupTime=Every " << backuptime << " Minute(s)(Every " << backupms << " ms)" << endl << "OutputFilename=" << opf << "," << opfn << endl << "Debug=" << debug << endl << "Command : " << d0 << endl;
string pr = op.str();
_PR(3, pr);
}
if (tp=="")
{
_PR(2, "Undefined TargetPath , Please Check config.ini. 未定义的目标文件夹 , 请检查config.ini");
getchar();
return 0;
}
if (backuptime > 35791||backuptime<1)
if (backuptime > 35791 || backuptime<1)
{
_PR(2, "BackupTime参数不能大于35791分钟或小于1分钟 , 请修改config.ini");
getchar();
Expand All @@ -45,7 +60,7 @@ int main() {
while (1) {
_PR(0, "Starting Backup. 开始备份");
_PR(0, "Starting Compress. 开始压缩");
system(StringToChar(getCmdStr(opp,tp)));
system((getCmdStr(opp,tp,opf)).c_str());
_PR(0, "Backup Successful. 备份成功");
Sleep(backupms);
}
Expand Down
100 changes: 17 additions & 83 deletions Visual Studio Project/AutoBackup/Main.h
Original file line number Diff line number Diff line change
@@ -1,94 +1,28 @@
/* FILENAME = head.h */
/* FILENAME = Main.h */
#pragma once
#ifndef _MAIN_H_
#define _MAIN_H_
#include <iostream>
#include <string>
#include <time.h>
#include <sstream>
#include <stdio.h>
#include "operate_config.h"
#include "operate_config.del.h"
#include "getConfig.h"
#pragma warning(disable:4996)

using namespace std;

string getTime()
{
time_t timep;
time(&timep);
char tmp[64];
strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S", localtime(&timep));
return tmp;
}
string getZIPFilename()
{
time_t timep;
time(&timep);
char tmp[64];
strftime(tmp, sizeof(tmp), "%Y-%m-%d %H.zip", localtime(&timep));
return tmp;
}
int _PR(int PRtype, string text)
{
ostringstream v1;
string time = getTime();
if (PRtype == 0)
{
v1 << "[" << time << " INFO] " << text;
cout << v1.str() << endl;
}
else if (PRtype == 1)
{
v1 << "[" << time << " WARN] " << text;
cout << v1.str() << endl;
}
else if (PRtype == 2)
{
v1 << "[" << time << " ERROR] " << text;
cout << v1.str() << endl;
}
else if (PRtype == 3)
{
v1 << "[" << time << "DEBUG]" << text;
cout << v1.str() << endl;
}
return 0;
}
//Variable Declaration
//Function Declaration
string getTime();
string editZIPFilename(string outputfilename);
int _PR(int PRtype, string text);
string getCmdStr(string p1/*OPP*/, string p2/*TP*/, string p3/*OPF*/);
//string getConfig(string configfile, string key);
string getConfig(string configfile, string key, string defaultvaule);
const char* StringToChar(string inputStr);
int StringToInt(string str);
bool findFile(string filename);

string getCmdStr(string p1/*OPP*/,string p2/*TP*/)
{
ostringstream v2;
/*拼合字符串 根据需求修改此部分为7-Zip.exe或bandzip.exe
*Bandzip
v2 << "[Bandzip目录] c -y -r -fmt:zip \"" << p1 << getZIPFilename() << "\" " << "\"" << p2 << "\" ";
*7-Zip
v2 << "[7-Zip目录] a \"" << p1 << getZIPFilename() << "\" " << "\"" << p2 << "\" -y -r";
*/

/*The splicing string is modified to 7-Zip.exe or bandzip.exe
*Bandzip
v2 << "[Bandzip Folder] c -y -r -fmt:zip \"" << p1 << getZIPFilename() << "\" " << "\"" << p2 << "\" ";
*7-Zip
v2 << "[7-Zip Folder] a \"" << p1 << getZIPFilename() << "\" " << "\"" << p2 << "\" -y -r";
*/
v2 << "bz.exe c -y -r -fmt:zip \"" << p1 << getZIPFilename() << "\" " << "\"" << p2 << "\" ";
string v3 = v2.str();
return v3;
}

string getConfig(string configfile, string key)
{
operate_config conf(configfile);
string r1=conf.getValue(key);
return r1;
}

const char* StringToChar(string inputStr)
{
const char* r114514 = inputStr.c_str();
return r114514;
}

int StringToInt(string str)
{
int r2 = atoi(str.c_str());
return r2;
}
#endif
113 changes: 113 additions & 0 deletions Visual Studio Project/AutoBackup/Main.h.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#include <iostream>
#include <string>
#include <time.h>
#include <sstream>
#include <stdio.h>
#include <io.h>
#include <stdlib.h>
#include "operate_config.del.h"
#include "getConfig.h"
#include "Main.h"
#pragma warning(disable:4996)

using namespace std;

string getTime()
{
time_t timep;
time(&timep);
char tmp[64];
strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S", localtime(&timep));
return tmp;
}

string editZIPFilename(string p5)
{
time_t timepp;
time(&timepp);
char tmp[64];
strftime(tmp, sizeof(tmp), p5.c_str(), localtime(&timepp));
return tmp;
}

int _PR(int PRtype, string text)
{
ostringstream v1;
string time = getTime();
if (PRtype == 0)
{
v1 << "[" << time << " INFO] " << text;
cout << v1.str() << endl;
}
else if (PRtype == 1)
{
v1 << "[" << time << " WARN] " << text;
cout << v1.str() << endl;
}
else if (PRtype == 2)
{
v1 << "[" << time << " ERROR] " << text;
cout << v1.str() << endl;
}
else if (PRtype == 3)
{
v1 << "[" << time << " DEBUG]" << text;
cout << v1.str() << endl;
}
return 0;
}

string getCmdStr(string p1/*OPP*/, string p2/*TP*/, string p3/*OPF*/)
{
ostringstream v2;
/*拼合字符串 根据需求修改此部分为7-Zip.exe或bandzip.exe
*Bandzip
v2 << "[Bandzip目录] c -y -r -fmt:zip \"" << p1 << p3 << "\" " << "\"" << p2 << "\" ";
*7-Zip
v2 << "[7-Zip目录] a \"" << p1 << p3 << "\" " << "\"" << p2 << "\" -y -r";
*/

/*The splicing string is modified to 7-Zip.exe or bandzip.exe
*Bandzip
v2 << "[Bandzip Folder] c -y -r -fmt:zip \"" << p1 << p3 << "\" " << "\"" << p2 << "\" ";
*7-Zip
v2 << "[7-Zip Folder] a \"" << p1 << p3 << "\" " << "\"" << p2 << "\" -y -r";
*/
v2 << "bz.exe c -y -r -fmt:zip \"" << p1 << p3 << "\" " << "\"" << p2 << "\" ";
string v3 = v2.str();
return v3;
}

/*
string getConfig(string configfile, string key)
{
operate_config conf(configfile);
string r1=conf.getValue(key);
return r1;
}
*/

string getConfig(string configfile, string key, string defaultvaule)
{
Config conf(configfile);
string r1 = conf.Read(key, defaultvaule/*默认值*/);
return r1;
}

const char* StringToChar(string inputStr)
{
const char* r114514 = inputStr.c_str();
return r114514;
}

int StringToInt(string str)
{
int r2 = atoi(str.c_str());
return r2;
}

bool findFile(string filename)
{
ifstream f(filename.c_str());
return f.good();
}
Loading

0 comments on commit cf836a9

Please sign in to comment.