add:添加支持直接使用最后一次使用的服务器选项。
This commit is contained in:
parent
e2d66a64e7
commit
23d9ecee8a
@ -136,6 +136,27 @@ bool CServerConfig::get_ini(const std::vector<TransmSet>& set, long num, TransmS
|
|||||||
return find;
|
return find;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CServerConfig::save_last_use(const std::string& ip, long port)
|
||||||
|
{
|
||||||
|
assert(init_ == true);
|
||||||
|
ini_handle_.SetValue("Base", "LastUseIP", ip.c_str());
|
||||||
|
ini_handle_.SetLongValue("Base", "LastUsePort", port);
|
||||||
|
ini_handle_.SaveFile(config_path_.c_str());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CServerConfig::get_last_use(std::string& ip, long& port)
|
||||||
|
{
|
||||||
|
assert(init_ == true);
|
||||||
|
if (!ini_handle_.KeyExists("Base", "LastUseIP") || !ini_handle_.KeyExists("Base", "LastUsePort")) {
|
||||||
|
TLOGE("Not Found Last Use Record.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ip = ini_handle_.GetValue("Base", "LastUseIP");
|
||||||
|
port = ini_handle_.GetLongValue("Base", "LastUsePort");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void CServerConfig::gen_default_ini(const std::string& path)
|
void CServerConfig::gen_default_ini(const std::string& path)
|
||||||
{
|
{
|
||||||
TLOGW("Gen Default Setting Ini in [{}].", path);
|
TLOGW("Gen Default Setting Ini in [{}].", path);
|
||||||
|
@ -20,6 +20,7 @@ struct CmdParam {
|
|||||||
long use_config{-1};
|
long use_config{-1};
|
||||||
bool parsed{false};
|
bool parsed{false};
|
||||||
bool direct_use{false};
|
bool direct_use{false};
|
||||||
|
bool last_use{false};
|
||||||
};
|
};
|
||||||
|
|
||||||
class CServerConfig
|
class CServerConfig
|
||||||
@ -37,6 +38,10 @@ public:
|
|||||||
bool remove_ini(long num);
|
bool remove_ini(long num);
|
||||||
static bool get_ini(const std::vector<TransmSet>& set, long num, TransmSet& use);
|
static bool get_ini(const std::vector<TransmSet>& set, long num, TransmSet& use);
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool save_last_use(const std::string& ip, long port);
|
||||||
|
bool get_last_use(std::string&ip, long& port);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void gen_default_ini(const std::string& path);
|
void gen_default_ini(const std::string& path);
|
||||||
|
|
||||||
|
@ -23,11 +23,12 @@ int parse_cmd(int argc, char** argv, CmdParam& param)
|
|||||||
fmt::format("tsc cmd introduce, version: {}\nopensource: {}", VERSION_NUM, VERSION_URL));
|
fmt::format("tsc cmd introduce, version: {}\nopensource: {}", VERSION_NUM, VERSION_URL));
|
||||||
CLI::App app(intro);
|
CLI::App app(intro);
|
||||||
|
|
||||||
app.add_option("-n, --number", param.use_config, "使用服务器地址组(值为使用--show中显示的序号)");
|
app.add_option("-u, --use", param.use_config, "使用服务器地址组(值为使用--show中显示的序号)");
|
||||||
app.add_option("-a, --append", param.appendValue, "添加服务器地址组(地址格式:127.0.0.1:9898:注释)");
|
app.add_option("-a, --append", param.appendValue, "添加服务器地址组(地址格式:127.0.0.1:9898:注释)");
|
||||||
app.add_flag("-s, --show", param.showValue, "查看服务器地址组");
|
app.add_flag("-s, --show", param.showValue, "查看服务器地址组");
|
||||||
app.add_option("-r, --remove", param.removeValue, "移除服务器地址组(值为使用--show中显示的序号)");
|
app.add_option("-r, --remove", param.removeValue, "移除服务器地址组(值为使用--show中显示的序号)");
|
||||||
app.add_flag("-d, --direct", param.direct_use, "添加服务器时直接使用此服务器。");
|
app.add_flag("-d, --direct", param.direct_use, "添加服务器时直接使用此服务器。");
|
||||||
|
app.add_flag("-l, --last", param.last_use, "直接使用之前最后一次使用的服务器。");
|
||||||
|
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
std::cout << app.help() << std::endl;
|
std::cout << app.help() << std::endl;
|
||||||
@ -92,6 +93,9 @@ bool exec_cmd(CmdParam& param, bool& run)
|
|||||||
TLOGI("remove config num=[{}] success!", param.removeValue);
|
TLOGI("remove config num=[{}] success!", param.removeValue);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (param.last_use) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
TLOGW("not matched!", param.removeValue);
|
TLOGW("not matched!", param.removeValue);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -126,23 +130,34 @@ int main(int argc, char* argv[])
|
|||||||
TLOGW("exec_cmd failed!");
|
TLOGW("exec_cmd failed!");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!run && !param.direct_use) {
|
if (!run && !param.direct_use && !param.last_use) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<TransmSet> set;
|
std::string ip;
|
||||||
if (!g_Config->read_ini(set)) {
|
long port{};
|
||||||
return -1;
|
if (param.last_use) {
|
||||||
}
|
if (!g_Config->get_last_use(ip, port)) {
|
||||||
TransmSet use;
|
return -1;
|
||||||
if (!g_Config->get_ini(set, param.use_config, use)) {
|
}
|
||||||
TLOGW("Not found config by num:[{}]", param.use_config);
|
} else {
|
||||||
return -1;
|
std::vector<TransmSet> set;
|
||||||
|
if (!g_Config->read_ini(set)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
TransmSet use;
|
||||||
|
if (!g_Config->get_ini(set, param.use_config, use)) {
|
||||||
|
TLOGW("Not found config by num:[{}]", param.use_config);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
ip = use.ip;
|
||||||
|
port = use.port;
|
||||||
}
|
}
|
||||||
|
g_Config->save_last_use(ip, port);
|
||||||
TLOGI("Build At {} {} under {} on {}", __DATE__, __TIME__, VERSION_GIT_COMMIT, VERSION_GIT_BRANCH);
|
TLOGI("Build At {} {} under {} on {}", __DATE__, __TIME__, VERSION_GIT_COMMIT, VERSION_GIT_BRANCH);
|
||||||
TLOGI("use ip => [{}], port => [{}]", use.ip, use.port);
|
TLOGI("use ip => [{}], port => [{}]", ip, port);
|
||||||
CClient client;
|
CClient client;
|
||||||
client.run(use.ip, std::to_string(use.port));
|
client.run(ip, std::to_string(port));
|
||||||
TLOGI("exit ==========");
|
TLOGI("exit ==========");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user