alroyso 3 лет назад
Родитель
Сommit
4ecbae5251

+ 0 - 2
Base/CBaseGloabl.cpp

@@ -4,8 +4,6 @@
 
 CBaseGloabl::CBaseGloabl()
 {
-
-	 
 	m_Ref = 0;
 
 	m_Networ = new CNetwork();

+ 64 - 1
Base/CUtils.cpp

@@ -177,4 +177,67 @@ bool CUtils::SafeFNMatch(const char* pattern, size_t patt_len, const char* str,
 
 		return false;
 	}
-}
+}
+
+
+std::string  CUtils::CvtA2A(const
+	std::string& str, unsigned int cpFrom/*=CP_UTF8*/, unsigned int cpTo/*=CP_ACP*/)
+{
+	if (cpTo == cpFrom)
+		return str;
+	std::wstring strw = CvtA2W(str, cpFrom);
+	return CvtW2A(strw, cpTo);
+}
+
+std::wstring CUtils::CvtW2W(const std::wstring& str, unsigned int cp)
+{
+	return str; 
+}
+
+
+
+std::wstring CUtils::CvtA2W(const std::string& str, unsigned int cp, unsigned int cp2)
+{
+	UNREFERENCED_PARAMETER(cp2);
+	wchar_t szBuf[1024];
+	int nRet = MultiByteToWideChar(cp, 0, str.c_str(), str.length(), szBuf, 1024);
+	if (nRet > 0)
+	{
+		return std::wstring(szBuf, nRet);
+	}
+	if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
+	{
+		int nRet = MultiByteToWideChar(cp, 0, str.c_str(), str.length(), NULL, 0);
+		if (nRet > 0)
+		{
+			wchar_t* pBuf = new wchar_t[nRet];
+			MultiByteToWideChar(cp, 0, str.c_str(), str.length(), pBuf, nRet);
+			std::wstring strRet(pBuf, nRet);
+			delete[]pBuf;
+			return strRet;
+		}
+	}
+	return L"";
+}
+
+
+
+std::string CUtils::CvtW2A(const std::wstring& str, unsigned int cp/*=CP_ACP*/)
+{
+	char szBuf[1024];
+	int nRet = WideCharToMultiByte(cp, 0, str.c_str(), str.length(), szBuf, 1024, NULL, NULL);
+	if (nRet > 0) return std::string(szBuf, nRet);
+	if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
+	{
+		int nRet = WideCharToMultiByte(cp, 0, str.c_str(), str.length(), NULL, 0, NULL, NULL);
+		if (nRet > 0)
+		{
+			char* pBuf = new char[nRet];
+			WideCharToMultiByte(cp, 0, str.c_str(), str.length(), pBuf, nRet, NULL, NULL);
+			std::string strRet(pBuf, nRet);
+			delete[]pBuf;
+			return strRet;
+		}
+	}
+	return "";
+}


+ 152 - 26
Base/basecurl/CNetwork.cpp

@@ -1,6 +1,8 @@
 #include "pch.h"
 #include "CNetwork.h"
 #include <nlohmann/json.hpp>
+#include "CUtils.h"
+
 CNetwork::CNetwork() : m_http_ret(http_no), m_http_status(0)
 {
 	Init();
@@ -11,6 +13,126 @@ CNetwork::~CNetwork(void)
 	UnInit();
 }
 
+void CNetwork::SetUrl(LPCSTR url)
+{
+	m_url = url;
+}
+
+
+char* mystrcpy(char* dst, const char* src)
+{
+	assert(dst != NULL);
+	assert(src != NULL);
+
+	if (dst == src)
+		return dst;
+
+	int size = strlen(src) + 1;
+
+	if (dst < src || src + size <= dst)
+	{
+		char* d = dst;
+		const char* s = src;
+
+		while (size--)
+			*d++ = *s++;
+	}
+	else
+	{
+		char* d = dst + size - 1;
+		const char* s = src + size - 1;
+
+		while (size--)
+			*d-- = *s--;
+	}
+	return dst;
+}
+
+
+HTTPRET CNetwork::PostLogin(LPCSTR username, LPCSTR password, LPCSTR& data)
+{
+	CUtils cutils;
+	//请求
+	std::vector<cpr::Pair> p;
+	p.push_back({ "email",username });
+	p.push_back({ "password",password });
+	std::string text = PostUrl("/api/client/v2/login", p);
+	if (text.empty()) {
+		
+		return http_f;
+	}
+
+	data = text.c_str();
+	//USERINFO userinf;
+	////memset(&userinf, NULL, sizeof(USERINFO));
+	////解析
+	//try
+	//{
+	//	nlohmann::json j = nlohmann::json::parse(data.begin(), data.end());
+
+	//	if (j["ret"].get<int>() == 1)
+	//	{
+ //
+	//		auto userinfo = j["data"]["user"];
+	//		
+	//		userinf.id = userinfo.at("id").get<int>();
+
+	//		/*auto username = S_CA2W(userinfo.at("account").get<std::string>(), CP_UTF8);
+
+	//		memset(userinf.username, NULL, sizeof(wchar_t));*/
+	//		mystrcpy(userinf.username, userinfo.at("account").get<std::string>().c_str());
+	//		mystrcpy(userinf.password, userinfo.at("passwd").get<std::string>().c_str());
+	//		mystrcpy(userinf.expiretime, userinfo.at("expired_at").get<std::string>().c_str());
+	//		mystrcpy(userinf.unusedTraffic, userinfo.at("unusedTraffic").get<std::string>().c_str());
+	//		mystrcpy(userinf.uuid, userinfo.at("uuid").get<std::string>().c_str());
+	//		mystrcpy(userinf.level, userinfo.at("level").get<std::string>().c_str());
+	//		
+	//		//strcpy(userinf.port, userinfo.at("port").get<std::string>().c_str());
+
+	//		userinf.port = userinfo.at("port").get<int>();
+
+	//		//lstrcpynW(username.c_str(), userinf.username, username.length());
+	//		//std::copy(username.begin(), username.end(), userinf.username);
+	//		 
+	//		/*userinf.username = userinfo.at("account").get<std::string>();
+	//		userinf.expiretime = userinfo.at("expired_at").get<std::string>();
+	//		userinf.password = userinfo.at("passwd").get<std::string>();
+	//		userinf.unusedTraffic = userinfo.at("unusedTraffic").get<std::string>();
+	//		userinf.uuid = userinfo.at("uuid").get<std::string>();
+	//		userinf.level = userinfo.at("level").get<std::string>();
+	//		userinf.port = userinfo.at("port").get<int>();*/
+
+	//	
+	//		mystrcpy(userinf.access_token, j["data"]["access_token"].get<std::string>().c_str());
+
+	//	
+
+
+	//		return &userinf;
+
+	//	}
+	//	else
+	//	{
+	//		wchar_t* msg = NULL;
+
+
+	//		m_error_msg = S_CA2A(j["msg"].get<std::string>(),CP_UTF8);
+	//		return NULL;
+	//	}
+
+
+	//}
+	//catch (...)
+	//{
+	//	m_error_msg = "解析登录数据错误,未知错误";
+	//	return NULL;
+	//}
+
+
+	/*char* p = data.c_str();*/
+	return http_yes;
+}
+
  
 
 //void CNetwork::GetServerlist()
@@ -81,9 +203,14 @@ LPCSTR CNetwork::GetLastErrorA()
 	return m_error_msg.c_str();
 }
 
+LPCWSTR CNetwork::GetLastErrorW()
+{
+	return S_CA2W(m_error_msg,CP_UTF8).c_str();
+}
+
  
 
-std::string CNetwork::GetUrl(std::string path,std::unordered_map<std::string, std::string> parame)
+std::string CNetwork::GetUrl(std::string path, std::vector<cpr::Parameter> parame)
 {
 	 
 
@@ -92,6 +219,7 @@ std::string CNetwork::GetUrl(std::string path,std::unordered_map<std::string, st
 	for (auto it = parame.begin(); it != parame.end(); ++it) {
 		//auto s = fmt::format("{0}", it->first);
 		/*p.AddParameter({ it->first, it->second }, {});*/
+		p.Add(*it);
 	}
 
 	for (auto it = vectorBaseurl.begin(); it != vectorBaseurl.end(); ++it) {
@@ -123,39 +251,37 @@ std::string CNetwork::GetUrl(std::string path,std::unordered_map<std::string, st
 	return std::string("");
 }
 
-std::string CNetwork::PostUrl(std::string path,std::unordered_map<std::string, std::string> parame, std::string data)
-{
-	std::vector<cpr::Pair> p;
-	for (auto it = parame.begin(); it != parame.end(); ++it) {
-		//auto s = fmt::format("{0}", it->first);
-		//p.AddPair(cpr::Pair{ it->first,it->second }, {});
-		p.push_back({ it->first,it->second });
+std::string CNetwork::PostUrl(std::string path, std::vector<cpr::Pair> parame)
+{ 
 
-	}
+	auto s = fmt::format("{0}{1}", m_url, path.c_str());
 
-	for (auto it = vectorBaseurl.begin(); it != vectorBaseurl.end(); ++it) {
-		auto s = fmt::format("{0}/{1}", *it, path.c_str());
+	cpr::Response r;
 
-		cpr::Response r;
+	if (parame.empty())
+	{
+		r = cpr::Get(cpr::Url{ s.c_str() });
+	}
+	else {
+		r = cpr::Post(cpr::Url{ s.c_str() }, cpr::Payload{ parame.begin(),parame.end() }, cpr::Header{ {"accept", "application/json"} });
+	}
 
-		if (parame.empty())
+	if (r.status_code == 200 || r.status_code == 201)
+	{
+		return std::move(r.text);
+	}
+	else {
+		m_http_status = r.status_code;
+		if (m_http_status == 0)
 		{
-			r = cpr::Get(cpr::Url{ s.c_str() });
-		}
-		else {
-			r = cpr::Post(cpr::Url{ s.c_str() }, cpr::Payload{ p.begin(),p.end() }, cpr::Header{ {"accept", "application/json"} });
+			m_error_msg = "获取数据失败,可能是您的网络问题更换备用尝试";
 		}
+		
+		return "";
+	}
+
 
-		if (r.status_code == 200 || r.status_code == 201)
-		{
-			return std::move(r.text);
-		}
-		else {
-			m_http_status = r.status_code;
-			return "";
-		}
 
-	}
 	return std::string("");
 }
 

+ 9 - 4
Base/basecurl/CNetwork.h

@@ -6,15 +6,18 @@ public:
 	CNetwork();
 	~CNetwork(void);
 
- 
+	void SetUrl(LPCSTR url);
+
+	HTTPRET PostLogin(LPCSTR username, LPCSTR password,LPCSTR& data);
 
 	HTTPRET GetHttpConnectstatus();
-	LPCSTR  GetLastErrorA();
  
+	LPCSTR  GetLastErrorA();
+	LPCWSTR  GetLastErrorW();
 
 private:
-	std::string GetUrl(std::string path,std::unordered_map<std::string, std::string> parame);
-	std::string PostUrl(std::string path,std::unordered_map<std::string, std::string> parame, std::string data);
+	std::string GetUrl(std::string path, std::vector<cpr::Parameter> parame);
+	std::string PostUrl(std::string path, std::vector<cpr::Pair> parame);
 	void Init();
 	void UnInit();
 private:
@@ -29,5 +32,7 @@ private:
 
 	int m_http_status;
 
+	std::string m_url;
+
 };
 

+ 37 - 1
SProxy/CApp.cpp

@@ -1,12 +1,48 @@
 #include "stdafx.h"
 #include "CApp.h"
+
+
 CApp* SSingleton<CApp>::ms_Singleton = NULL;
-CApp::CApp() : m_is_out(0)
+
+CApp::CApp() : m_is_out(0), m_userinfo(nullptr)
 {
+
 }
 
 CApp::~CApp()
 {
+	UnInit();
+}
+
+void CApp::Init()
+{
+	if (!m_userinfo)
+	{
+		m_userinfo = new CUserInfo();
+	}
+
+}
+
+void CApp::UnInit() {
+	if (m_userinfo)
+	{
+		delete m_userinfo;
+		m_userinfo = NULL;
+	}
+}
+
+bool CApp::DataToUserInfo(std::string data)
+{
+	if (m_userinfo)
+	{
+		return m_userinfo->Init(data);
+	}
+	return false;
+}
+
+CUserInfo* CApp::GetUserinfo()
+{
+	return m_userinfo;
 }
 
 void CApp::SetOut(int out)

+ 14 - 0
SProxy/CApp.h

@@ -1,5 +1,6 @@
 #pragma once
 
+#include "CUserInfo.h"
 
 enum PROXY_MODE {
 
@@ -23,11 +24,24 @@ public:
 	CApp();
 	~CApp();
 
+	void Init();
+
+	void UnInit();
+
+
+	bool DataToUserInfo(std::string data);
+
+
+	CUserInfo* GetUserinfo();
+
 	void SetOut(int out);
 
 	int GetOut();
 
 private:
 	int m_is_out;
+
+	CUserInfo*   m_userinfo;
+
 };
 

+ 135 - 0
SProxy/CManageNetWork.cpp

@@ -0,0 +1,135 @@
+#include "stdafx.h"
+#include "CManageNetWork.h"
+#include "CNetWork.h"
+#include "CApp.h"
+#include "FileOperate.h"
+#include <nlohmann/json.hpp>
+
+CManageNetWork::CManageNetWork() : m_base_curl(nullptr), m_Asyntask(4)
+{
+}
+
+CManageNetWork::~CManageNetWork()
+{
+	if (m_base_curl)
+	{
+		delete m_base_curl;
+		m_base_curl = nullptr;
+	}
+}
+
+void CManageNetWork::init()
+{
+
+
+	SNotifyCenter::getSingleton().addEvent(EVENTID(EventLogin));
+
+
+	if (!m_base_curl)
+	{
+		m_base_curl = new CNetWork();
+		//m_base_curl.Attach(new CNetWork());
+	}
+
+	LoadFileToData();
+}
+
+void CManageNetWork::Login(LPCSTR username, LPCSTR password)
+{
+	if (!m_base_curl)
+	{
+		return;
+	}
+
+	this->m_username = username;
+	this->m_password = password;
+
+	m_Asyntask.AddTask(&CManageNetWork::ThreadFun_login, this, (LPARAM)m_base_curl);
+
+	
+	 
+}
+
+void CManageNetWork::SetUrl(LPCSTR url)
+{
+	if (!m_base_curl)
+	{
+		return;
+	}
+
+	m_base_curl->SetUrl(url);
+}
+
+SStringA CManageNetWork::GetUsername()
+{
+	return m_username;
+}
+
+SStringA CManageNetWork::GetPassWord()
+{
+	return m_password;
+}
+
+void CManageNetWork::ThreadFun_login(LPARAM lParam)
+{
+	IBaseCurl* lpAsyncParam = reinterpret_cast<IBaseCurl*>(lParam);
+	int code = 200;
+	SStringW msg = L"";
+	std::string data;
+	HTTPRET httpstatus = m_base_curl->PostLogin(this->m_username, this->m_password, data);
+
+	if (httpstatus == http_f) {
+		code = 0;
+		msg = m_base_curl->GetLastErrorW();
+	}
+
+	if (!CApp::getSingletonPtr()->DataToUserInfo(data))
+	{
+		code = -1;
+		msg = CApp::getSingletonPtr()->GetUserinfo()->GetLastErrorW();
+	}
+	
+	DataToFile();
+
+	EventLogin* pEvt = new EventLogin(nullptr);
+	pEvt->status = code;
+	pEvt->msg = msg;
+	SNotifyCenter::getSingleton().FireEventAsync(pEvt);
+	pEvt->Release();
+}
+
+void CManageNetWork::LoadFileToData() {
+	FileOperate f;
+	std::string path = std::filesystem::current_path().string();
+	if (f.open(path + "\\user.txt", std::fstream::in | std::fstream::out | std::fstream::app)) {
+		std::string data = f.readAll();
+
+		nlohmann::json j3 = nlohmann::json::parse(data.begin(), data.end());
+		this->m_username = j3["username"].get<std::string>().c_str();
+		this->m_password = j3["password"].get<std::string>().c_str();
+
+	}
+	f.close();
+}
+
+void CManageNetWork::DataToFile()
+{
+
+	nlohmann::json j3;
+	j3["username"] = this->m_username;
+	j3["password"] = this->m_password;
+
+	auto str = j3.dump(4);
+
+	FileOperate f;
+
+	std::string path = std::filesystem::current_path().string();
+
+	f.create(path + "\\user.txt");
+
+	if (f.open(path + "\\user.txt", std::fstream::in | std::fstream::out | std::fstream::app)) {
+		f.write(str);
+	}
+
+	f.close();
+}

+ 38 - 0
SProxy/CManageNetWork.h

@@ -0,0 +1,38 @@
+#pragma once
+
+#include "IBaseCurl.h"
+
+#include "event.h"
+
+
+
+class CManageNetWork
+{
+public:
+	CManageNetWork();
+	~CManageNetWork();
+
+	void init();
+
+	void Login(LPCSTR username, LPCSTR password);
+
+	void SetUrl(LPCSTR url);
+
+	SStringA GetUsername();
+	SStringA GetPassWord();
+	
+
+private:
+	void ThreadFun_login(LPARAM lParam);
+
+	void LoadFileToData();
+
+	void DataToFile();
+
+private:
+	SStringA m_username;
+	SStringA m_password;
+	IBaseCurl* m_base_curl;
+	AsynTaskHandle<LPARAM>	m_Asyntask;
+};
+

+ 94 - 0
SProxy/CNetWork.cpp

@@ -0,0 +1,94 @@
+#include "stdafx.h"
+#include "CNetWork.h"
+#include <nlohmann/json.hpp>
+
+#include <fmt/format.h>
+
+
+CNetWork::CNetWork() : m_http_ret(http_f)
+{
+
+}
+
+CNetWork::~CNetWork(void)
+{
+
+}
+
+HTTPRET CNetWork::PostLogin(LPCSTR username, LPCSTR password, std::string& data)
+{
+	std::vector<cpr::Pair> p;
+	p.push_back({ "email",username });
+	p.push_back({ "password",password });
+	std::string text = PostUrl("/api/client/v2/login", p);
+	if (text.empty()) {
+
+		return http_f;
+	}
+
+	data = text.c_str();
+
+    return http_yes;
+}
+
+void CNetWork::SetUrl(LPCSTR url)
+{
+	m_url = url;
+}
+
+LPCSTR CNetWork::GetLastErrorA()
+{
+	return SStringA().Format("%s", m_error_msg.c_str()).GetBuffer(0);
+}
+
+LPCWSTR CNetWork::GetLastErrorW()
+{
+	return S_CA2W(m_error_msg.c_str(),CP_UTF8);
+}
+
+std::string CNetWork::GetUrl(std::string path, std::vector<cpr::Parameter> parame)
+{
+    return std::string();
+}
+
+std::string CNetWork::PostUrl(std::string path, std::vector<cpr::Pair> parame)
+{
+	auto s = fmt::format("{0}{1}", m_url, path.c_str());
+
+	cpr::Response r;
+
+	if (parame.empty())
+	{
+		r = cpr::Get(cpr::Url{ s.c_str() });
+	}
+	else {
+		r = cpr::Post(cpr::Url{ s.c_str() }, cpr::Payload{ parame.begin(),parame.end() }, cpr::Header{ {"accept", "application/json"} });
+	}
+
+	if (r.status_code == 200 || r.status_code == 201)
+	{
+		return std::move(r.text);
+	}
+	else {
+		m_http_status = r.status_code;
+		if (m_http_status == 0)
+		{
+			m_error_msg = "获取数据失败,可能是您的网络问题更换备用尝试";
+		}
+
+		return "";
+	}
+
+
+
+	return std::string("");
+}
+
+void CNetWork::Init()
+{
+
+}
+
+void CNetWork::UnInit()
+{
+}

+ 38 - 0
SProxy/CNetWork.h

@@ -0,0 +1,38 @@
+#pragma once
+
+#include "IBaseCurl.h"
+#include <cpr/cpr.h>
+class CNetWork : public IBaseCurl
+{
+public:
+	CNetWork();
+	~CNetWork(void);
+
+
+	HTTPRET PostLogin(LPCSTR username, LPCSTR password, std::string& data);
+	void SetUrl(LPCSTR url);
+
+	LPCSTR  GetLastErrorA();
+	LPCWSTR  GetLastErrorW();
+
+private:
+	std::string GetUrl(std::string path, std::vector<cpr::Parameter> parame);
+	std::string PostUrl(std::string path, std::vector<cpr::Pair> parame);
+	void Init();
+	void UnInit();
+private:
+
+	std::vector<std::string> vectorBaseurl;
+
+	std::unordered_map<std::string, std::string> keymap;
+
+	std::string m_error_msg;
+
+	HTTPRET m_http_ret;
+
+	int m_http_status;
+
+	std::string m_url;
+
+};
+

+ 66 - 0
SProxy/CUserInfo.cpp

@@ -0,0 +1,66 @@
+#include "stdafx.h"
+#include "CUserInfo.h"
+
+#include "FileOperate.h"
+
+CUserInfo::CUserInfo() : id(0), port(0)
+{
+}
+
+CUserInfo::~CUserInfo()
+{
+}
+
+bool CUserInfo::Init(std::string data)
+{
+	try
+	{
+		nlohmann::json j = nlohmann::json::parse(data.begin(), data.end());
+
+		if (j["ret"].get<int>() == 1)
+		{
+			auto userinfo = j["data"]["user"];
+			//
+			this->id = userinfo.at("id").get<int>();
+			this->username = userinfo.at("account").get<std::string>();
+			this->expiretime = userinfo.at("expired_at").get<std::string>();
+			this->password = userinfo.at("passwd").get<std::string>();
+			this->unusedTraffic = userinfo.at("unusedTraffic").get<std::string>();
+			this->uuid = userinfo.at("uuid").get<std::string>();
+			this->level = userinfo.at("level").get<std::string>();
+			this->port = userinfo.at("port").get<int>();
+
+			//
+			this->access_token = j["data"]["access_token"].get<std::string>();
+			this->token_type   = j["data"]["token_type"].get<std::string>();
+			return true;
+
+		}
+		else
+		{
+			this->m_error_msg = j["msg"].get<std::string>();
+
+			return false;
+		}
+
+
+	}
+	catch (...)
+	{
+		this->m_error_msg = "½âÎöÊý¾Ý´íÎó";
+		return false;
+	}
+    return false;
+}
+
+LPCSTR CUserInfo::GetLastErrorA()
+{
+	return SStringA().Format("%s", m_error_msg.c_str()).GetBuffer(0);
+}
+
+LPCWSTR CUserInfo::GetLastErrorW()
+{
+	return S_CA2W(m_error_msg.c_str(), CP_UTF8);
+}
+
+

+ 40 - 0
SProxy/CUserInfo.h

@@ -0,0 +1,40 @@
+#pragma once
+#include <nlohmann/json.hpp>
+
+ 
+
+class CUserInfo 
+{
+
+public:
+	CUserInfo();
+	~CUserInfo();
+
+
+	bool Init(std::string data);
+
+ 
+
+	LPCSTR GetLastErrorA();
+
+	LPCWSTR GetLastErrorW();
+ 
+	
+
+public:
+	std::string username;
+	std::string expiretime; //到期时间
+	std::string acctoken;
+	std::string password;
+	std::string unusedTraffic; //用户流量
+	std::string uuid;		   //uuid
+	std::string level;		   //用户级别
+	std::string access_token;
+	std::string token_type;
+	int id;
+	int port;
+
+private:
+	std::string m_error_msg;
+};
+

+ 183 - 0
SProxy/FileOperate.cpp

@@ -0,0 +1,183 @@
+#include "stdafx.h"
+#include "FileOperate.h"
+#include <filesystem>
+#include <stdio.h>
+
+FileOperate::FileOperate()
+{}
+
+FileOperate::FileOperate(const std::string &file) : mFile(file)
+{}
+
+FileOperate::~FileOperate()
+{
+	if (mFileStream.is_open()) {
+		close();
+	}
+}
+
+/*
+ * 创建文件
+ */
+bool FileOperate::create(const std::string &file)
+{
+	std::fstream out_file;
+	out_file.open(file.c_str(), std::ios::out);
+	if (!out_file) {
+		return false;
+	}
+	out_file.close();
+
+	return true;
+}
+
+/*
+ * 删除文件
+ */
+bool FileOperate::remove(const std::string &file)
+{
+	// 删除文件,成功返回0,否则返回-1
+	if (-1 == std::remove(file.c_str())) {
+		return false;
+	}
+
+	return true;
+}
+
+bool FileOperate::exist(const string &file)
+{
+	if (std::filesystem::exists(file))
+		return true;
+
+	return false;
+}
+
+bool FileOperate::open(ios_base::openmode __mode)
+{
+	mFileStream.open(mFile.c_str(), __mode);
+
+	return mFileStream.is_open();
+}
+
+bool FileOperate::open(const string &file, ios_base::openmode __mode)
+{
+	mFile = file;
+	return open(__mode);
+}
+
+void FileOperate::close()
+{
+	mFileStream.close();
+	mFileStream.clear();
+}
+
+/*
+ * 文件重命名
+ */
+bool FileOperate::rename(const std::string &newName)
+{
+	std::string newFile = fileDir() + newName;
+
+	int result = std::rename(mFile.c_str(), newFile.c_str());
+	if (result == 0)
+		return true;
+
+	return false;
+}
+
+/*
+ * 判断文件是否存在
+ */
+bool FileOperate::isExist()
+{
+	return FileOperate::exist(mFile);
+}
+
+/*
+ * 获取文件名
+ * 文件绝对路径: /home/root/.../Test/test1.txt
+ * 返回值     : test1.txt
+ */
+const string FileOperate::fileName()
+{
+	string name = mFile;
+
+	std::size_t pos = mFile.rfind('/');
+	if (pos != std::string::npos) {
+		name = mFile.substr(pos + 1);
+	}
+
+	return name;
+}
+
+/*
+ * 获取文件所在目录
+ * 文件绝对路径: /home/root/.../Test/test1.txt
+ * 返回值     : /home/root/.../Test/
+ */
+const string FileOperate::fileDir()
+{
+	string dir = "";
+
+	std::size_t pos = mFile.rfind('/');
+	if (pos != std::string::npos) {
+		dir = mFile.substr(0, pos + 1);
+	}
+
+	return dir;
+}
+
+/*
+ * 获取文件大小(总字节数)
+ */
+size_t FileOperate::fileSize()
+{
+#if 0
+	// 方式一
+	mFileStream.seekg(0, mFileStream.end);
+	int length = mFileStream.tellg();
+	mFileStream.seekg(0, mFileStream.beg);
+
+	return length;
+#endif
+
+	// 方式二
+	struct stat info;
+	stat(mFile.c_str(), &info);
+
+	return static_cast<std::size_t>(info.st_size);
+}
+
+bool FileOperate::atEnd()
+{
+	// peek函数的作用是获取下一个字符,但是指针不会移动
+	return mFileStream.peek() == EOF;
+}
+
+void FileOperate::read(string &buffer, size_t bufferSize)
+{
+	buffer.resize(bufferSize);
+	mFileStream.read(&buffer[0], bufferSize);
+}
+
+const string FileOperate::readLine()
+{
+	// 文件存在 读取数据
+	std::string dataStr = "";
+	getline(mFileStream, dataStr);
+	return dataStr;
+}
+
+const string FileOperate::readAll()
+{
+	std::string buffer;
+	size_t length = fileSize();
+	FileOperate::read(buffer, length);
+
+	return buffer;
+}
+
+void FileOperate::write(const string &data)
+{
+	mFileStream << data << '\n';
+}

+ 126 - 0
SProxy/FileOperate.h

@@ -0,0 +1,126 @@
+#pragma once
+// FileOperate.h
+#ifndef FILEOPERATE_H
+#define FILEOPERATE_H
+
+#include <iostream>
+#include <string>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fstream>
+ 
+
+using namespace std;
+
+class FileOperate
+{
+public:
+	FileOperate();
+	FileOperate(const std::string& file);
+	~FileOperate();
+
+	// 创建文件
+	static bool create(const std::string &file);
+
+	// 删除文件
+	static bool remove(const std::string &file);
+
+	// 文件是否存在
+	static bool exist(const std::string &file);
+
+	// 打开文件
+	bool open(ios_base::openmode __mode = std::fstream::in | std::fstream::out);
+	bool open(const std::string &file, ios_base::openmode __mode = std::fstream::in | std::fstream::out);
+
+	// 关闭文件
+	void close();
+
+	// 重命名文件
+	bool rename(const std::string &newName);
+
+	// 文件是否存在
+	bool isExist();
+
+	// 获取文件名
+	const std::string fileName();
+
+	// 获取文件所在目录
+	const std::string fileDir();
+
+	// 获取文件大小(总字节数)
+	std::size_t fileSize();
+
+	// 判断当前字符是否在最后
+	bool atEnd();
+
+	// 读取文件内容
+	void read(std::string &buffer, size_t bufferSize);
+	const std::string readLine();
+	const std::string readAll();
+
+	// 写数据到文件
+	void write(const std::string &data);
+
+private:
+	std::string mFile;
+	std::fstream mFileStream;
+};
+
+#endif // FILEOPERATE_H
+
+
+
+/*
+ *
+ // 方式一
+FileOperate mFileOperate("/home/Test/Test1.txt");
+if (!mFileOperate.open(std::fstream::in | std::fstream::out | std::fstream::app)) {
+    cout << "文件打开失败" << endl;
+    return 0;
+}
+
+// 方式二
+FileOperate mFileOperate;
+std::string fileStr = "/home/Test/Test1.txt";
+if (!mFileOperate.open(fileStr, std::fstream::in | std::fstream::out | std::fstream::app)) {
+    cout << "文件打开失败" << endl;
+    return 0;
+}
+
+
+FileOperate mFileOperate("/home/Test/Test1.txt");
+// 获取文件名
+cout << mFileOperate.fileName() << endl;  // 输出: Test1.txt
+
+// 获取文件所在目录
+cout << mFileOperate.fileDir() << endl;   // 输出: /home/xushuan/Test/
+
+// 获取文件大小
+cout << mFileOperate.fileSize() << endl;
+
+
+// 方式一 一行一行读取
+std::string data;
+while (!mFileOperate.atEnd()) {
+	data = mFileOperate.readLine();
+}
+
+// 方式二  读取指定字节大小的数据
+std::string data;
+mFileOperate.read(data, 100);
+
+// 方式三  一次性全部读取
+	// 方式一
+	std::string data = mFileOperate.readAll();
+
+	// 方式二
+	string data;
+	mFileOperate.read(data, mFileOperate.fileSize());
+
+
+	// 写入数据到文件
+mFileOperate.write("hello");
+
+ *
+ *
+ ***/

+ 2 - 0
SProxy/IBaseCurl.cpp

@@ -0,0 +1,2 @@
+#include "stdafx.h"
+#include "IBaseCurl.h"

+ 29 - 0
SProxy/IBaseCurl.h

@@ -0,0 +1,29 @@
+#pragma once
+
+enum HTTPRET
+{
+	http_no = 0,
+	http_f,
+	http_yes,
+	http_start,
+	http_end,
+};
+
+
+
+class IBaseCurl
+{
+public:
+	virtual ~IBaseCurl(void) {};
+
+	virtual void SetUrl(LPCSTR url) = 0;
+
+	//怬
+	virtual HTTPRET PostLogin(LPCSTR username, LPCSTR password, std::string& data) = 0;
+
+
+	virtual LPCSTR  GetLastErrorA() = 0;
+	virtual LPCWSTR  GetLastErrorW() = 0;
+
+};
+

BIN
SProxy/LoginDlg.cpp


BIN
SProxy/LoginDlg.h


BIN
SProxy/MainDlg.cpp


BIN
SProxy/SProxy.cpp


+ 16 - 1
SProxy/SProxy.vcxproj

@@ -87,6 +87,9 @@
     <OutDir>..\__bin\$(Platform)\$(Configuration)\</OutDir>
     <LinkIncremental>false</LinkIncremental>
   </PropertyGroup>
+  <PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <VcpkgUseStatic>true</VcpkgUseStatic>
+  </PropertyGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
       <PrecompiledHeader>Use</PrecompiledHeader>
@@ -152,7 +155,7 @@
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <SuppressStartupBanner>true</SuppressStartupBanner>
       <AdditionalLibraryDirectories>$(SOUIPATH)\bin64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
-      <AdditionalDependencies>utilitiesd.lib;souid.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>utilitiesd.lib;souid.lib;crypt32.lib;wldap32.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <SubSystem>Windows</SubSystem>
     </Link>
     <ResourceCompile>
@@ -189,6 +192,11 @@
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="CApp.cpp" />
+    <ClCompile Include="CManageNetWork.cpp" />
+    <ClCompile Include="CNetWork.cpp" />
+    <ClCompile Include="CUserInfo.cpp" />
+    <ClCompile Include="FileOperate.cpp" />
+    <ClCompile Include="IBaseCurl.cpp" />
     <ClCompile Include="LoginDlg.cpp" />
     <ClCompile Include="MainDlg.cpp" />
     <ClCompile Include="SouiInit.cpp" />
@@ -209,6 +217,13 @@
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="CApp.h" />
+    <ClInclude Include="CManageNetWork.h" />
+    <ClInclude Include="CNetWork.h" />
+    <ClInclude Include="comm.h" />
+    <ClInclude Include="CUserInfo.h" />
+    <ClInclude Include="event.h" />
+    <ClInclude Include="FileOperate.h" />
+    <ClInclude Include="IBaseCurl.h" />
     <ClInclude Include="LoginDlg.h" />
     <ClInclude Include="MainDlg.h" />
     <ClInclude Include="resource.h" />

+ 42 - 0
SProxy/SProxy.vcxproj.filters

@@ -23,6 +23,12 @@
     <Filter Include="control">
       <UniqueIdentifier>{c0ccef04-efce-48cb-bbd5-1ceab0ca4059}</UniqueIdentifier>
     </Filter>
+    <Filter Include="network">
+      <UniqueIdentifier>{099304f2-47cb-43b5-ae35-3bb80390269a}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="Model">
+      <UniqueIdentifier>{888c495a-cd33-4d46-98fe-0e8b624ae3c0}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
     <Text Include="license.txt" />
@@ -59,6 +65,21 @@
     <ClCompile Include="StabtypeControl.cpp">
       <Filter>control</Filter>
     </ClCompile>
+    <ClCompile Include="IBaseCurl.cpp">
+      <Filter>network</Filter>
+    </ClCompile>
+    <ClCompile Include="CNetWork.cpp">
+      <Filter>network</Filter>
+    </ClCompile>
+    <ClCompile Include="CUserInfo.cpp">
+      <Filter>Model</Filter>
+    </ClCompile>
+    <ClCompile Include="CManageNetWork.cpp">
+      <Filter>network</Filter>
+    </ClCompile>
+    <ClCompile Include="FileOperate.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="SProxy.rc">
@@ -96,6 +117,27 @@
     <ClInclude Include="SRadioBox2.h">
       <Filter>control</Filter>
     </ClInclude>
+    <ClInclude Include="IBaseCurl.h">
+      <Filter>network</Filter>
+    </ClInclude>
+    <ClInclude Include="CNetWork.h">
+      <Filter>network</Filter>
+    </ClInclude>
+    <ClInclude Include="event.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="comm.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="CUserInfo.h">
+      <Filter>Model</Filter>
+    </ClInclude>
+    <ClInclude Include="CManageNetWork.h">
+      <Filter>network</Filter>
+    </ClInclude>
+    <ClInclude Include="FileOperate.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="res\soui_res.rc2">

+ 2 - 0
SProxy/comm.h

@@ -0,0 +1,2 @@
+#pragma once
+

+ 21 - 0
SProxy/event.h

@@ -0,0 +1,21 @@
+#pragma once
+// ×Ô¶¨ÒåʼþÏûÏ¢
+
+
+#define EVT_LOGIN (SOUI::EVT_EXTERNAL_BEGIN + 1000)
+
+class EventLogin : public TplEventArgs<EventLogin>
+{
+	SOUI_CLASS_NAME(EventLogin, L"on_event_login")
+public:
+	EventLogin(SOUI::SWindow* pSender) : TplEventArgs<EventLogin>(pSender)
+	{
+
+	}
+	enum {
+		EventID = EVT_LOGIN
+	};
+
+	int		 status;
+	SStringW msg;
+};

BIN
SProxy/res/resource.h


BIN
SProxy/res/soui_res.rc2


BIN
SProxy/stdafx.h


+ 154 - 0
__INCLUDE/AsynFunctionT.hpp

@@ -0,0 +1,154 @@
+/*
+异步 任务 处理
+
+*/
+#include <process.h>
+#include <functional>
+#include <list>
+
+template<class ParamType=LPVOID>				// char* string void*
+class AsynTaskHandle
+{
+	typedef struct tagTask
+	{
+		std::function<void(ParamType)>		fun;
+		ParamType										lpParam;
+	}AsynTask, *PAsynTask;
+
+protected:
+	volatile bool							m_bQuit;
+	HANDLE*								m_phThread;
+	unsigned int							m_nThreadCount;
+	//UINT										m_dwThreadId;
+	//HANDLE									m_hListEvent;
+	HANDLE									m_hSemaphore;			//信号量 句柄
+	CRITICAL_SECTION					m_csLock;		//维持队列同步
+	std::list<PAsynTask>				m_TaskList;	
+public:
+	AsynTaskHandle(unsigned int nThreadCount=4)
+		: m_bQuit(false)
+		, m_nThreadCount(nThreadCount)
+	{
+		InitializeCriticalSection(&m_csLock);
+		m_hSemaphore = CreateSemaphore(NULL, 0, 100, NULL);
+		//m_hListEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL);
+
+		assert(m_nThreadCount);
+		m_phThread = new HANDLE[m_nThreadCount];
+		for (unsigned int i=0; i<m_nThreadCount; ++i)
+		{
+			m_phThread[i] = (HANDLE)_beginthreadex(NULL, 0, ThreadFun, this, NULL, NULL);
+		}
+	}
+	virtual ~AsynTaskHandle()
+	{		
+		if(NULL != m_hSemaphore)
+		{
+			CloseHandle(m_hSemaphore);
+			m_hSemaphore = NULL;
+		}
+
+		if(m_TaskList.size() > 0)		// 要退出了  且 任务没执行完 要清理缓存
+		{
+			for each (auto var in m_TaskList)
+			{
+				delete var;
+			}
+		}
+		
+		for (unsigned int i=0; i<m_nThreadCount; ++i)
+		{
+			CloseHandle(m_phThread[i]);
+		}
+		delete[] m_phThread;
+		m_phThread = NULL;
+		DeleteCriticalSection(&m_csLock);
+	}
+
+public:
+	
+	template<class Fun, class This>
+	void AddTask(Fun fun, This t, ParamType lpParam)
+	{
+		auto task = new AsynTask;
+		task->fun = std::bind(fun, t, std::placeholders::_1);
+		task->lpParam = lpParam;
+
+		EnterCriticalSection(&m_csLock);
+		m_TaskList.push_back(task);		//交换数据 
+		LeaveCriticalSection(&m_csLock);
+
+		//SetEvent(m_hListEvent);
+		ReleaseSemaphore(m_hSemaphore, 1, NULL);
+	}
+
+	void AddTask(std::function<void(ParamType)> fun, ParamType lpParam)
+	{
+		auto task = new AsynTask;
+		task->fun = fun;
+		task->lpParam = lpParam;
+
+		EnterCriticalSection(&m_csLock);
+		m_TaskList.push_back(task);		//交换数据 
+		LeaveCriticalSection(&m_csLock);
+
+		//SetEvent(m_hListEvent);
+		ReleaseSemaphore(m_hSemaphore, 1, NULL);
+	}
+	void Close(DWORD dwWait=1000)
+	{
+		m_bQuit = true;
+		//SetEvent(m_hListEvent);
+		ReleaseSemaphore(m_hSemaphore, m_nThreadCount, NULL);
+		//	
+		for (unsigned int i=0; i<m_nThreadCount; ++i)
+		{
+			WaitForSingleObject(m_hThread[i], dwWait);
+		}
+	}
+protected:
+	unsigned int Handle()
+	{
+		while (!m_bQuit)
+		{
+			::WaitForSingleObject(m_hSemaphore, INFINITE);
+			if(m_bQuit)
+				break;
+			
+			/*OutputDebugString(_T("AsyncFun"));*/
+
+			while (!m_bQuit)
+			{
+				PAsynTask pTask = NULL;
+				EnterCriticalSection(&m_csLock);
+				if(m_TaskList.size() > 0)
+				{
+					pTask = m_TaskList.front();
+					m_TaskList.pop_front();
+				}
+				
+				LeaveCriticalSection(&m_csLock);
+				
+
+				if(NULL == pTask)
+					break;
+
+				pTask->fun(pTask->lpParam);
+				delete pTask;
+			}			
+		}
+
+		return 0;
+	}
+private:
+	//静态 线程 函数 
+	static unsigned int __stdcall ThreadFun(void* lp)
+	{
+		AsynTaskHandle* pThis = (AsynTaskHandle*)lp;
+		if(NULL == pThis )
+			return 0;
+
+		return pThis->Handle();
+	}
+
+};

+ 26 - 64
__INCLUDE/BaseModule.h

@@ -13,6 +13,22 @@
 
 #pragma pack(push,1)
 
+
+typedef struct  USERINFO
+{
+	int id;
+	char username[64];
+	char expiretime[64];
+	char password[64];
+	char uuid[64];
+	char level[10];
+	char unusedTraffic[128];
+	char access_token[64];
+	int port;
+
+}USERINFO,*PUSERINFO;
+
+
 class IBaseCurl;
 class IServerList;
 class IUserinfo;
@@ -71,70 +87,7 @@ public:
 	T* m_pPrev;
 	T* m_pNext;
 };
-
-struct SPROXY_NET
-{
-	int  sid;
-	int  groupid;
-	char addproxy[64];
-	char username[64];
-	char password[64];
-	char processname[64];
-	char title[64];
-	int  port;
-	int  status;
-	int  id;
-	int  pid;
-	int  isros;
-	int  proxy_type;
-	bool select;
-	int  count;
-	int  mid;	//模拟器ID
-
-	 //查找结构体e是否存在
-	bool operator == (const SPROXY_NET& e) {
-		return (this->id == e.id);
-	}
-
-	//查找数值
-	bool operator == (const int& id) {
-		return (this->id == id);
-	}
-};
-
-struct PROESSSHOW
-{
-	char title[64];
-	int  pid;
-};
-
-struct ProcessInfo
-{
-	int		id;
-	wchar_t gnmae[256];
-	wchar_t proceessname[256];
-	int		select;
-};
-
-struct USERINFO
-{
-	char username[64];
-	char password[64];
-	char expiretime[64];
-	int	id;
-	int number;
-	int alreadycount;
-};
-
-/**
-服务器组
-*/
-struct ServerGroup
-{
-	int id;
-	char title[64];
-};
-
+ 
 class IServerListCallback
 {
 public:
@@ -165,15 +118,24 @@ enum HTTPRET
 	http_start,
 	http_end,
 };
+
 //请求网络接口
 class IBaseCurl
 	: public IInstanceList<IBaseCurl>
 {
 public:
 	virtual ~IBaseCurl(void) {};
+
+	virtual void SetUrl(LPCSTR url) = 0;
+
+	//登录
+	virtual HTTPRET PostLogin(LPCSTR username,LPCSTR password,LPCSTR& data) = 0;
+
+
 	virtual HTTPRET GetHttpConnectstatus() = 0;
 
 	virtual LPCSTR  GetLastErrorA() = 0;
+	virtual LPCWSTR  GetLastErrorW() = 0;
 };
 
 BASEMODULE IBaseGloablModule* WINAPI GetBaseGlobalInstance();

+ 0 - 78
__INCLUDE/SysModule.h

@@ -14,8 +14,6 @@
 #pragma pack(push,1)
 
 class IBaseCurl;
-class IServerList;
-class IUserinfo;
 //获取其他类的指针
 class IBaseGloablModule
 {
@@ -72,69 +70,6 @@ public:
 	T* m_pNext;
 };
 
-struct SPROXY_NET
-{
-	int  sid;
-	int  groupid;
-	char addproxy[64];
-	char username[64];
-	char password[64];
-	char processname[64];
-	char title[64];
-	int  port;
-	int  status;
-	int  id;
-	int  pid;
-	int  isros;
-	int  proxy_type;
-	bool select;
-	int  count;
-	int  mid;	//模拟器ID
-
-	 //查找结构体e是否存在
-	bool operator == (const SPROXY_NET& e) {
-		return (this->id == e.id);
-	}
-
-	//查找数值
-	bool operator == (const int& id) {
-		return (this->id == id);
-	}
-};
-
-struct PROESSSHOW
-{
-	char title[64];
-	int  pid;
-};
-
-struct ProcessInfo
-{
-	int		id;
-	wchar_t gnmae[256];
-	wchar_t proceessname[256];
-	int		select;
-};
-
-struct USERINFO
-{
-	char username[64];
-	char password[64];
-	char expiretime[64];
-	int	id;
-	int number;
-	int alreadycount;
-};
-
-/**
-服务器组
-*/
-struct ServerGroup
-{
-	int id;
-	char title[64];
-};
-
 class IServerListCallback
 {
 public:
@@ -143,19 +78,6 @@ public:
 	virtual void ServerListCallback() = 0;
 };
 
-class IServerList
-	: public IInstanceList<IServerList>
-{
-public:
-	virtual ~IServerList(void) {};
-};
-
-class IUserinfo
-	: public IInstanceList<IUserinfo>
-{
-public:
-	virtual ~IUserinfo(void) {};
-};
 
 enum HTTPRET
 {