Skip to content

Commit 51a25ff

Browse files
committed
修正多渠道转发bug,优化源码结构
1 parent b26c08e commit 51a25ff

File tree

14 files changed

+2012
-1816
lines changed

14 files changed

+2012
-1816
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#ifndef CONFIGFILEPROCESS_H
2+
#define CONFIGFILEPROCESS_H
3+
4+
#include <regex>
5+
#include <iostream>
6+
#include <fstream>
7+
#include "../MyHelper/myhelper.h"
8+
9+
using namespace std;
10+
extern string configFilePath;
11+
12+
map<string, string> readConfigFile();
13+
void writeConfigFile(const map<string, string>& configMap);
14+
15+
// 读取配置文件并存储到一个键值对映射中
16+
map<string, string> readConfigFile() {
17+
string filename = "";
18+
if (configFilePath != "") {
19+
filename = configFilePath;
20+
}
21+
else {
22+
filename = "config.txt";
23+
}
24+
map<string, string> configMap;
25+
ifstream configFile(filename);
26+
27+
if (configFile.is_open()) {
28+
string line;
29+
while (getline(configFile, line)) {
30+
// 解析每一行的配置项和值
31+
size_t delimiterPos = line.find('=');
32+
if (delimiterPos != string::npos) {
33+
string key = trim(line.substr(0, delimiterPos));
34+
string value = trim(line.substr(delimiterPos + 1));
35+
configMap[key] = value;
36+
}
37+
}
38+
configFile.close();
39+
}
40+
return configMap;
41+
}
42+
// 将配置项写入配置文件
43+
void writeConfigFile(const map<string, string>& configMap) {
44+
string filename = "";
45+
if (configFilePath != "") {
46+
filename = configFilePath;
47+
}
48+
else {
49+
filename = "config.txt";
50+
}
51+
ofstream configFileClear(filename, ofstream::trunc);
52+
configFileClear.close();
53+
ofstream configFile(filename);
54+
if (configFile.is_open())
55+
{
56+
for (const auto& pair : configMap) {
57+
configFile << pair.first << " = " << pair.second << endl;
58+
}
59+
configFile.close();
60+
}
61+
else {
62+
printf("无法打开配置文件。\n");
63+
}
64+
}
65+
66+
//检查配置文件是否存在并初始化
67+
void checkConfig(string configFilePath) {
68+
//string fileName = "config.txt";
69+
//ifstream file(configFilePath);
70+
if (configFilePath == "")
71+
{
72+
string fileName = "config.txt";
73+
ifstream file(fileName);
74+
if (!file) {
75+
// 配置文件不存在,创建它
76+
ofstream configFile("config.txt"); // 创建配置文件
77+
if (configFile.is_open()) {
78+
// 写入配置项
79+
configFile << "smtpHost = " << endl;
80+
configFile << "smtpPort = " << endl;
81+
configFile << "emailKey = " << endl;
82+
configFile << "sendEmial = " << endl;
83+
configFile << "reciveEmial = " << endl;
84+
configFile << "pushPlusToken = " << endl;
85+
configFile << "WeChatQYID = " << endl;
86+
configFile << "WeChatQYApplicationSecret = " << endl;
87+
configFile << "WeChatQYApplicationID = " << endl;
88+
configFile << "TGBotToken = " << endl;
89+
configFile << "TGBotChatID = " << endl;
90+
configFile << "IsEnableCustomTGBotApi = " << endl;
91+
configFile << "CustomTGBotApi = " << endl;
92+
configFile << "DingTalkAccessToken = " << endl;
93+
configFile << "DingTalkSecret = " << endl;
94+
configFile << "BarkUrl = " << endl;
95+
configFile << "BrakKey = " << endl;
96+
configFile << "ShellPath = " << endl;
97+
configFile << "apiPort = " << endl;
98+
configFile << "ForwardDeviceName = " << endl;
99+
configFile << "smsCodeKey = 验证码±verification±code±인증±代码±随机码" << endl;
100+
configFile << "forwardIgnoreStorageType = sm" << endl;
101+
configFile.close();
102+
}
103+
else {
104+
cout << "无法打开配置文件。" << endl;
105+
}
106+
}
107+
}
108+
}
109+
#endif // CONFIGFILEPROCESS_H

DbusSmsForwardCPlus/DbusSmsForwardCPlus.vcxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,17 @@
7979
<ClCompile Include="main.cpp" />
8080
</ItemGroup>
8181
<ItemGroup>
82+
<ClInclude Include="ConfigFileProcess\configfileprocess.h" />
83+
<ClInclude Include="DbusSmsMethod\dbussmsmethod.h" />
84+
<ClInclude Include="InitWebPageAndApi\initwebpageandapi.h" />
85+
<ClInclude Include="ProcessInitArgs\processinitargs.h" />
86+
<ClInclude Include="ProcessSetup\processsetup.h" />
8287
<ClInclude Include="httplib.h" />
8388
<ClInclude Include="mail.h" />
89+
<ClInclude Include="MyHelper\myhelper.h" />
90+
<ClInclude Include="ProcessSmsSend\sendoptionprocess.h" />
91+
<ClInclude Include="ProcessSmsSend\smsforwardmethod.h" />
92+
<ClInclude Include="ProcessUserChoose\processuserchoose.h" />
8493
<ClInclude Include="rapidjson\allocators.h" />
8594
<ClInclude Include="rapidjson\cursorstreamwrapper.h" />
8695
<ClInclude Include="rapidjson\document.h" />
@@ -119,6 +128,7 @@
119128
<ClInclude Include="rapidjson\stringbuffer.h" />
120129
<ClInclude Include="rapidjson\uri.h" />
121130
<ClInclude Include="rapidjson\writer.h" />
131+
<ClInclude Include="SmsCodeProcess\smscodeprocess.h" />
122132
</ItemGroup>
123133
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
124134
<CustomBuildStep>

0 commit comments

Comments
 (0)