2 Star 7 Fork 0

乐园 / 异星工厂MOD汉化工具

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
CbaiduAPI.cpp 2.96 KB
一键复制 编辑 原始数据 按行查看 历史
乐园 提交于 2020-09-28 15:27 . 版本更新
// CbaiduAPI.cpp: 实现文件
//
#include "pch.h"
#include "ElyTranslator.h"
#include "CbaiduAPI.h"
#include "afxdialogex.h"
#include "string"
#include "direct.h"
#include <atlenc.h>
extern CString AK, SK;
extern int CK, bExit;
// CbaiduAPI 对话框
IMPLEMENT_DYNAMIC(CbaiduAPI, CDialogEx)
CbaiduAPI::CbaiduAPI(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_DIALOG1, pParent)
{
}
CbaiduAPI::~CbaiduAPI()
{
}
void CbaiduAPI::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT1, e_url);
DDX_Control(pDX, IDC_EDIT2, e_id);
DDX_Control(pDX, IDC_EDIT3, e_key);
}
BEGIN_MESSAGE_MAP(CbaiduAPI, CDialogEx)
ON_BN_CLICKED(IDOK, &CbaiduAPI::OnBnClickedOk)
END_MESSAGE_MAP()
// CbaiduAPI 消息处理程序
BOOL CbaiduAPI::OnInitDialog()
{
CDialogEx::OnInitDialog();
e_url.SetWindowTextW(_T("开通地址:https://api.fanyi.baidu.com/"));
e_id.SetWindowTextW(AK);
e_key.SetWindowTextW(SK);
return true;
}
void CbaiduAPI::OnBnClickedOk()
{
// 获取用户输入的APP ID和密钥
e_id.GetWindowTextW(AK);
e_key.GetWindowTextW(SK);
if (AK.IsEmpty() || SK.IsEmpty())
MessageBox(_T("请输入正确的APP ID和密钥"), _T("提示"), MB_OK);
else
{
CString fPath;
GetModuleFileName(NULL, fPath.GetBufferSetLength(MAX_PATH + 1), MAX_PATH);
fPath.ReleaseBuffer();
int nPos;
nPos = fPath.ReverseFind('\\');
fPath = fPath.Left(nPos + 1) + _T("settings.ini");
//将获取的AK和SK存放到程序目录的key.ini文件
CStdioFile file;
file.Open(fPath, CFile::modeCreate | CFile::modeWrite);
//将转码后的内容写入文件
CString strtemp = _T("AK=") + AK;
int nSrcLen = (int)wcslen(strtemp);
CStringA utf8String1(strtemp);
int nBufLen = (nSrcLen + 1) * 6;
//下面的函数AtlUnicodeToUTF8()需头文件:<atlenc.h>
LPSTR buffer = utf8String1.GetBufferSetLength(nBufLen);
int nLen = AtlUnicodeToUTF8(strtemp, nSrcLen, buffer, nBufLen);
buffer[nLen] = 0;
utf8String1.ReleaseBuffer();
file.Write(utf8String1.GetBuffer(), nLen);
file.Write("\n", 1);
strtemp = _T("SK=") + SK;
nSrcLen = (int)wcslen(strtemp);
CStringA utf8String2(strtemp);
nBufLen = (nSrcLen + 1) * 6;
//下面的函数AtlUnicodeToUTF8()需头文件:<atlenc.h>
buffer = utf8String2.GetBufferSetLength(nBufLen);
nLen = AtlUnicodeToUTF8(strtemp, nSrcLen, buffer, nBufLen);
file.Write(utf8String2.GetBuffer(), nLen);
file.Write("\n", 1);
CString cCK, cExit;
cCK.Format(_T("%d"), CK);
cExit.Format(_T("%d"), bExit);
strtemp = _T("CK=") + cCK + cExit;
nSrcLen = (int)wcslen(strtemp);
CStringA utf8String3(strtemp);
nBufLen = (nSrcLen + 1) * 6;
//下面的函数AtlUnicodeToUTF8()需头文件:<atlenc.h>
buffer = utf8String3.GetBufferSetLength(nBufLen);
nLen = AtlUnicodeToUTF8(strtemp, nSrcLen, buffer, nBufLen);
file.Write(utf8String3.GetBuffer(), nLen);
file.Close();
}
CDialogEx::OnOK();
}
C++
1
https://gitee.com/elysiumworks/ElyTranslator.git
git@gitee.com:elysiumworks/ElyTranslator.git
elysiumworks
ElyTranslator
异星工厂MOD汉化工具
master

搜索帮助