Commit 2ead8eca authored by 王炳鑫's avatar 王炳鑫

功能完成

Signed-off-by: 王炳鑫's avatarwangbingxin <imbald@magicare.me>
parent 9fa9d892
// Config.cpp : 实现文件
//
#include "stdafx.h"
#include "HealthHutUi.h"
#include "Config.h"
#include "afxdialogex.h"
#include "utils.h"
#include "types.h"
#include "RegegitKey.h"
// CConfig 对话框
IMPLEMENT_DYNAMIC(CConfig, CDialogEx)
CConfig::CConfig(CWnd* pParent /*=NULL*/)
: CDialogEx(CConfig::IDD, pParent)
{
}
CConfig::~CConfig()
{
}
void CConfig::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_COMBO1, mCombo);
}
BOOL CConfig::OnInitDialog()
{
CDialogEx::OnInitDialog();
for (int i = 0; i < 4; i++)
{
mCombo.AddString(item_list[i]);
}
return TRUE;
}
BEGIN_MESSAGE_MAP(CConfig, CDialogEx)
ON_BN_CLICKED(IDC_BUTTON1, &CConfig::OnBnClickedButton1)
END_MESSAGE_MAP()
// CConfig 消息处理程序
void CConfig::OnBnClickedButton1()
{
int index = mCombo.GetCurSel();
int type = 0;
CString strCBText;
mCombo.GetLBText(index, strCBText);
for (int i = 0; i < 4; i++)
{
if (strCBText == item_list[i])
{
type = i + 1;
}
}
CRegegitKey::insert_device_type(type, get_windows_version());
CDialogEx::OnOK();
}
#pragma once
#include "afxwin.h"
// CConfig 对话框
class CConfig : public CDialogEx
{
DECLARE_DYNAMIC(CConfig)
public:
CConfig(CWnd* pParent = NULL); // 标准构造函数
virtual ~CConfig();
enum { IDD = IDD_DIALOG_CONFIG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
virtual BOOL OnInitDialog();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedButton1();
CComboBox mCombo;
};
......@@ -47,7 +47,6 @@ BOOL CFileList::list_files(LPCTSTR pstr) {
continue;
}
DEBUG_OUTW(finder.GetFilePath().GetString());
if (rename_files(finder.GetFilePath(), newPath)) {
mFiles.push_back(CString(newPath));
}
......@@ -76,24 +75,18 @@ bool SortByCreateTime(const CString &v1, const CString &v2)
CFile::GetStatus(v2.GetString(), status);
CTime t2 = status.m_atime;
return t1 < t2;
}
BOOL CFileList::sort_files()
{
std::sort(mFiles.begin(), mFiles.end(), SortByCreateTime);
return true;
}
CString& CFileList::getPath()
CFileList::file_array& CFileList::getPath()
{
CString path("");
if (mFiles.empty())
return path;
else
return mFiles.at(0);
return mFiles;
}
BOOL CFileList::rename_files(const CString& path, char *newPath)
......
......@@ -4,14 +4,15 @@
class CFileList
{
public:
typedef std::vector<CString> file_array;
CFileList(void);
~CFileList(void);
BOOL list_files(LPCTSTR pstr);
CString& getPath();
file_array& getPath();
private:
BOOL sort_files();
BOOL rename_files(const CString& path, char *newPath);
private:
std::vector<CString> mFiles;
file_array mFiles;
};
......@@ -28,10 +28,10 @@ CHealthHutUiApp theApp;
#ifdef _DEBUG
void init_console()
{
AllocConsole();
freopen("CON", "r", stdin );
freopen("CON", "w", stdout);
freopen("CON", "w", stderr);
// AllocConsole();
// freopen("CON", "r", stdin );
// freopen("CON", "w", stdout);
// freopen("CON", "w", stderr);
}
#endif // _DEBUG
......
B// Microsoft Visual C++ generated resource script.
......
......@@ -26,7 +26,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<PlatformToolset>v110_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
......@@ -81,14 +81,18 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_CRT_SECURE_NO_WARNINGS;BUILDING_LIBCURL;HTTP_ONLY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>D:\workspace\git\HealthHut\HealthHutUi\curl;D:\workspace\git\HealthHut\HealthHutUi\HealthHutUi;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>D:\workspace\git\HealthHut\HealthHutUi\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>libcurl.lib;ws2_32.lib;winmm.lib;wldap32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
......@@ -105,11 +109,14 @@
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Config.h" />
<ClInclude Include="MD5Checksum.h" />
<ClInclude Include="FileList.h" />
<ClInclude Include="HealthHutUi.h" />
<ClInclude Include="HealthHutUiDlg.h" />
<ClInclude Include="MainApp.h" />
<ClInclude Include="More.h" />
<ClInclude Include="ProcessDialog.h" />
<ClInclude Include="RegegitKey.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="sqlite3.h" />
......@@ -117,10 +124,12 @@
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="MD5ChecksumDefines.h" />
<ClInclude Include="types.h" />
<ClInclude Include="Upload.h" />
<ClInclude Include="utils.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Config.cpp" />
<ClCompile Include="FileList.cpp" />
<ClCompile Include="HealthHutUi.cpp" />
<ClCompile Include="HealthHutUiDlg.cpp" />
......@@ -129,6 +138,8 @@
<ClCompile Include="json_writer.cpp" />
<ClCompile Include="MainApp.cpp" />
<ClCompile Include="MD5Checksum.cpp" />
<ClCompile Include="More.cpp" />
<ClCompile Include="ProcessDialog.cpp" />
<ClCompile Include="RegegitKey.cpp" />
<ClCompile Include="sqlite3.c" />
<ClCompile Include="SqliteUtil.cpp" />
......
......@@ -60,6 +60,18 @@
<ClInclude Include="Upload.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="types.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="ProcessDialog.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="Config.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="More.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="HealthHutUi.cpp">
......@@ -104,6 +116,15 @@
<ClCompile Include="json_writer.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="ProcessDialog.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="Config.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="More.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="HealthHutUi.rc">
......
......@@ -10,6 +10,11 @@
#include "RegegitKey.h"
#include "Upload.h"
#include "utils.h"
#include "ProcessDialog.h"
#include "types.h"
#include "curl.h"
#include "More.h"
#include "Config.h"
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
......@@ -27,6 +32,8 @@ public:
// 实现
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedOk();
};
CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
......@@ -39,12 +46,15 @@ void CAboutDlg::DoDataExchange(CDataExchange* pDX)
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
ON_BN_CLICKED(IDOK, &CAboutDlg::OnBnClickedOk)
END_MESSAGE_MAP()
CHealthHutUiDlg::CHealthHutUiDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CHealthHutUiDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
mProcess = NULL;
mCount = 0;
}
void CHealthHutUiDlg::DoDataExchange(CDataExchange* pDX)
......@@ -64,17 +74,92 @@ BEGIN_MESSAGE_MAP(CHealthHutUiDlg, CDialogEx)
ON_WM_CREATE()
ON_WM_CLOSE()
ON_NOTIFY(NM_CLICK, IDC_LIST1, &CHealthHutUiDlg::OnNMClickList1)
ON_MESSAGE(ON_WM_SEND_PROCESS, OnWmProcess)
ON_MESSAGE(ON_WM_SEND_ERROR, OnSendError)
ON_MESSAGE(ON_WM_FILE_FINISH, OnFileFinish)
ON_BN_CLICKED(IDC_BUTTON2, &CHealthHutUiDlg::OnBnClickedButton2)
END_MESSAGE_MAP()
// CHealthHutUiDlg 消息处理程序
BOOL CHealthHutUiDlg::OnInitDialog()
LRESULT CHealthHutUiDlg::OnSendError(WPARAM wParam, LPARAM lParam)
{
CDialogEx::OnInitDialog();
int number = lParam;
CURLcode code = (CURLcode)number;
switch (code)
{
case CURLE_COULDNT_RESOLVE_PROXY:
case CURLE_COULDNT_RESOLVE_HOST:
case CURLE_COULDNT_CONNECT:
MessageBox(_T("解析服务失败,请检查网络!"),_T("提示"),MB_OK);
exit(0);
case CURLE_HTTP_RETURNED_ERROR:
MessageBox(_T("HTTP出错,请联系技术支持"),_T("提示"),MB_OK);
exit(0);
case CURLE_OPERATION_TIMEDOUT:
MessageBox(_T("连接服务器超时,请联系技术支持"),_T("提示"),MB_OK);
exit(0);
case CURLE_HTTP_POST_ERROR:
MessageBox(_T("内部请求错误,请联系技术支持"),_T("提示"),MB_OK);
exit(0);
case CURLE_GOT_NOTHING:
MessageBox(_T("服务器无返回内容,请联系技术支持"),_T("提示"),MB_OK);
exit(0);
}
}
// 将“关于...”菜单项添加到系统菜单中。
void CHealthHutUiDlg::upload_finish()
{
for (std::size_t i = 0; i < mMain.getPath().size(); i++)
{
DeleteFile(mMain.getPath().at(i).GetString());
}
mProcess->Close();
MessageBox(_T("数据上传成功"),_T("提示"),MB_OK);
exit(0);
}
// IDM_ABOUTBOX 必须在系统命令范围内。
LRESULT CHealthHutUiDlg::OnFileFinish(WPARAM wParam, LPARAM lParam)
{
mCount++;
if (mCount == mMain.getPath().size())
{
upload_finish();
}
return 0;
}
LRESULT CHealthHutUiDlg::OnWmProcess(WPARAM wParam, LPARAM lParam)
{
if (NULL == mProcess) {
mProcess = new CProcessDialog();
mProcess->DoModal();
mProcess->SetRange(0, 100);
}
else
{
if (wParam ==0 || lParam == 0) return 0;
if (mCount == mMain.getPath().size())
{
upload_finish();
}
on_process_data *data = (on_process_data *)lParam;
double now_upload = lParam;
double to_upload = wParam;
int tag = (now_upload / to_upload / (double)mMain.getPath().size()) * (mCount + 1) * 100;
mProcess->SetTag(tag);
}
return 0;
}
BOOL CHealthHutUiDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
......@@ -97,6 +182,8 @@ BOOL CHealthHutUiDlg::OnInitDialog()
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
set_hwnd(GetSafeHwnd());
TCHAR rgtsz[3][10] = {_T("姓名"), _T("身份证"), _T(" ")};
LV_COLUMN lvcolumn;
CRect rect;
......@@ -121,14 +208,16 @@ BOOL CHealthHutUiDlg::OnInitDialog()
result = CSqliteUtil::instance()->read_all(&row, &column);
int l = 0;
for (int j = 0; j < row; j++) {
mList.InsertItem(j , CString(result[(j+1) * column + 2]).GetString());
mList.SetItemText(j, 1, CString(result[(j+1) * column + 3]).GetString());
mList.SetItemText(j, 2, _T("选择"));
mList.InsertItem(j , CString(result[(j+1) * column + 3]).GetString());
mList.SetItemText(j, 1, CString(result[(j+1) * column + 1]).GetString());
mList.SetItemText(j, 2, _T("上传"));
}
CSqliteUtil::instance()->clear(result);
if (CRegegitKey::check_reg()) {
MessageBox(_T("初始化完成"),_T("欢迎使用"),MB_OK);
CConfig config;
config.DoModal();
MessageBox(_T("配置完成"),_T("欢迎使用"),MB_OK);
CDialogEx::OnOK();
return TRUE;
}
......@@ -235,7 +324,7 @@ void CHealthHutUiDlg::OnBnClickedOk()
{
mList.InsertItem(i, names.at(i));
mList.SetItemText(i, 1, ids.at(i));
mList.SetItemText(i, 2, _T("选择"));
mList.SetItemText(i, 2, _T("上传"));
}
}
......@@ -248,8 +337,6 @@ int CHealthHutUiDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
if (CDialogEx::OnCreate(lpCreateStruct) == -1)
return -1;
SetTimer(LOCAL_TIMER, 3000, 0);
mMain.init();
CSqliteUtil::instance()->init();
......@@ -265,7 +352,7 @@ void CHealthHutUiDlg::OnNMClickList1(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
DWORD dwPos = GetMessagePos();
CPoint point( LOWORD(dwPos), HIWORD(dwPos) );
CPoint point( LOWORD(dwPos), HIWORD(dwPos));
mList.ScreenToClient(&point);
......@@ -282,15 +369,28 @@ void CHealthHutUiDlg::OnNMClickList1(NMHDR *pNMHDR, LRESULT *pResult)
CString name = mList.GetItemText(lvinfo.iItem, 0);
CString idCard = mList.GetItemText(lvinfo.iItem, 1);
CString path = mMain.getPath();
if (CUpload::upload(path, name, idCard)) {
MessageBox(_T("数据上传成功"),_T("提示"),MB_OK);
}
else {
MessageBox(_T("数据上传失败"),_T("提示"),MB_OK);
CFileList::file_array files = mMain.getPath();
if (files.size() == 0)
{
MessageBox(_T("当前没有报告需要上传!"),_T("提示"),MB_OK);
CDialogEx::OnOK();
}
util_upload_all(files, name, idCard);
OnWmProcess(0, 0);
}
CDialogEx::OnOK();
*pResult = 0;
}
void CAboutDlg::OnBnClickedOk()
{
CDialogEx::OnOK();
}
void CHealthHutUiDlg::OnBnClickedButton2()
{
CMore more_dialog;
more_dialog.DoModal();
}
......@@ -7,6 +7,7 @@
#include "MainApp.h"
#include "afxcmn.h"
#include "afxwin.h"
#include "ProcessDialog.h"
// CHealthHutUiDlg 对话框
class CHealthHutUiDlg : public CDialogEx
......@@ -20,7 +21,8 @@ public:
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
private:
void upload_finish();
// 实现
protected:
HICON m_hIcon;
......@@ -31,6 +33,9 @@ protected:
afx_msg void OnPaint();
afx_msg void OnTimer(UINT_PTR nIDEvent);
afx_msg HCURSOR OnQueryDragIcon();
afx_msg LRESULT OnWmProcess(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnSendError(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnFileFinish(WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedOk();
......@@ -44,4 +49,7 @@ public:
afx_msg void OnNMClickList1(NMHDR *pNMHDR, LRESULT *pResult);
CEdit mName;
CEdit mCard;
CProcessDialog *mProcess;
int mCount;
afx_msg void OnBnClickedButton2();
};
......@@ -28,15 +28,13 @@ BOOL CMainApp::start()
CString imagePath;
LpbyteToCString(value, imagePath, dataLength);
//imagePath.Append(IMAGE_PATH_SUBSTREET);
DEBUG_OUTW(imagePath.GetString());
BOOL ret = mFiles.list_files(imagePath.GetString());
safe_delete(value);
return ret;
}
CString& CMainApp::getPath()
CFileList::file_array& CMainApp::getPath()
{
return mFiles.getPath();
}
......
......@@ -11,7 +11,7 @@ public:
BOOL start();
void stop();
void init();
CString& getPath();
CFileList::file_array& getPath();
private:
CFileList mFiles;
};
......
// More.cpp : 实现文件
//
#include "stdafx.h"
#include "HealthHutUi.h"
#include "More.h"
#include "afxdialogex.h"
#include "types.h"
#include "utils.h"
#include "RegegitKey.h"
// CMore 对话框
IMPLEMENT_DYNAMIC(CMore, CDialogEx)
CMore::CMore(CWnd* pParent /*=NULL*/)
: CDialogEx(CMore::IDD, pParent)
{
}
CMore::~CMore()
{
}
BOOL CMore::OnInitDialog()
{
CDialogEx::OnInitDialog();
LPBYTE value = new BYTE[512];
DWORD dataLength = 256;
CRegegitKey::read_app_key(DEVICE_TYPE, value, &dataLength);
int type = _ttoi(CString(value));
if (type > 4)
{
return FALSE;
}
mDeviceType.ReplaceSel(CString(item_list[type]));
return TRUE;
}
void CMore::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT1, mAgency);
DDX_Control(pDX, IDC_EDIT2, mDeviceType);
}
BEGIN_MESSAGE_MAP(CMore, CDialogEx)
END_MESSAGE_MAP()
// CMore 消息处理程序
#pragma once
#include "afxwin.h"
// CMore 对话框
class CMore : public CDialogEx
{
DECLARE_DYNAMIC(CMore)
public:
CMore(CWnd* pParent = NULL); // 标准构造函数
virtual ~CMore();
virtual BOOL OnInitDialog();
// 对话框数据
enum { IDD = IDD_DIALOG_MORE };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
DECLARE_MESSAGE_MAP()
private:
CEdit mDeviceType;
CEdit mAgency;
};
// ProcessDialog.cpp : 实现文件
//
#include "stdafx.h"
#include "HealthHutUi.h"
#include "ProcessDialog.h"
#include "afxdialogex.h"
// CProcessDialog 对话框
IMPLEMENT_DYNAMIC(CProcessDialog, CDialogEx)
CProcessDialog::CProcessDialog(CWnd* pParent /*=NULL*/)
: CDialogEx(CProcessDialog::IDD, pParent)
{
}
CProcessDialog::~CProcessDialog()
{
}
void CProcessDialog::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_PROGRESS1, mProcess);
}
void CProcessDialog::SetRange(short start, short end)
{
mProcess.SetRange(start, end);
}
void CProcessDialog::SetTag(int tag)
{
mProcess.SetPos(tag);
}
void CProcessDialog::Close()
{
OnClose();
}
BEGIN_MESSAGE_MAP(CProcessDialog, CDialogEx)
END_MESSAGE_MAP()
// CProcessDialog 消息处理程序
#pragma once
#include "afxcmn.h"
class CProcessDialog : public CDialogEx
{
DECLARE_DYNAMIC(CProcessDialog)
public:
CProcessDialog(CWnd* pParent = NULL);
virtual ~CProcessDialog();
void SetRange(short start, short end);
void SetTag(int tag);
void Close();
enum { IDD = IDD_PROCESS_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX);
DECLARE_MESSAGE_MAP()
public:
CProgressCtrl mProcess;
};
......@@ -11,64 +11,86 @@ CRegegitKey::~CRegegitKey(void)
{
}
void CRegegitKey::insert_exe(HKEY hKEY)
void CRegegitKey::insert_exe(HKEY hKEY, windows_version version)
{
WCHAR pFileName[MAX_PATH];
int nPos = GetCurrentDirectory(MAX_PATH, pFileName);
CString exeName = CString(pFileName) + EXE_NAME;
LPCTSTR strUserValue = exeName.GetString();
CString exePath;
GetExePath(exePath);
TCHAR *exe_path = NULL;
if (version > windows_7)
exe_path = _T("extapp");
else
exe_path = _T("exe_app_name");
long ret = ::RegSetValueEx(hKEY, exe_path, 0, REG_SZ, (const BYTE *) exePath.GetString(), (exePath.GetLength() + 1) * sizeof(TCHAR));
}
long ret = ::RegSetValueEx(hKEY, REGEDIT_EXE_PATH, 0, REG_SZ, (const BYTE *) strUserValue, wcslen(strUserValue) * 2+1);
void CRegegitKey::insert_jpg(HKEY hKEY, windows_version version)
{
CString substrim(_T("jpg"));
if (version > windows_7) {
::RegSetValueEx(hKEY, _T("bw_ext"), 0, REG_SZ, (const BYTE *) substrim.GetString(), (substrim.GetLength() + 1) * sizeof(TCHAR));
::RegSetValueEx(hKEY, _T("bw_format"), 0, REG_SZ, (const BYTE *) substrim.GetString(), (substrim.GetLength() + 1) * sizeof(TCHAR));
::RegSetValueEx(hKEY, _T("color_ext"), 0, REG_SZ, (const BYTE *) substrim.GetString(), (substrim.GetLength() + 1) * sizeof(TCHAR));
::RegSetValueEx(hKEY, _T("color_format"), 0, REG_SZ, (const BYTE *) substrim.GetString(), (substrim.GetLength() + 1) * sizeof(TCHAR));
}
else {
::RegSetValueEx(hKEY, _T("format"), 0, REG_SZ, (const BYTE *) substrim.GetString(), (substrim.GetLength() + 1) * sizeof(TCHAR));
}
}
void CRegegitKey::insert_flag(HKEY hKEY)
void CRegegitKey::insert_flag(HKEY hKEY, windows_version version)
{
LPCTSTR strUserValue = _T("true");
long ret = ::RegSetValueEx(hKEY, LOAD_APP_FLAG, 0, REG_SZ, (const BYTE *) strUserValue, wcslen (strUserValue) * 2+1);
CString value(_T("true"));
TCHAR *app_flag = NULL;
if (version > windows_7)
app_flag = _T("load_extapp");
else
app_flag = _T("ext_app");
long ret = ::RegSetValueEx(hKEY, app_flag, 0, REG_SZ, (const BYTE *) value.GetString(), (value.GetLength() + 1) * sizeof(TCHAR));
}
void CRegegitKey::insert_out(HKEY hKEY)
{
WCHAR pFileName[MAX_PATH];
CString pFileName;
GetAppPath(pFileName);
CString path = pFileName + "\\";
CString exeName = CString(pFileName) + _T("\\image");
CString strUser = _T("path");
LPCTSTR strUserValue = exeName.GetString();
long ret = ::RegSetValueEx(hKEY, strUser, 0, REG_SZ, (const BYTE *) strUserValue, wcslen(strUserValue) * 2+1);
long ret = ::RegSetValueEx(hKEY, _T("path"), 0, REG_SZ, (const BYTE *) path.GetString(), (path.GetLength() + 1) * sizeof(TCHAR));
}
BOOL CRegegitKey::check_reg()
//NOTE: win10ʾ͵
bool CRegegitKey::check_win10()
{
HKEY hKEY;
long ret0=(RegOpenKeyEx(KEY_ROOT, SUB_KEY_PARENT, 0, KEY64 | KEY_READ |KEY_WRITE, &hKEY));
long ret0=(RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\VirtualPrinter"), 0, KEY_WOW64_64KEY | KEY_READ |KEY_WRITE, &hKEY));
if (ret0 != ERROR_SUCCESS) {
return FALSE;
return false;
}
LPBYTE getValue = new BYTE[80];//得到的键值
DWORD keyType = REG_SZ;//定义数据类型
DWORD DataLen = 80;//定义数据长度
CString strUser = LOAD_APP_FLAG;//要查询的键名称
LPBYTE getValue = new BYTE[80];
DWORD keyType = REG_SZ;
DWORD DataLen = 80;
CString strUser = _T("load_extapp");
long ret1 = RegQueryValueEx(hKEY, strUser, NULL, &keyType, getValue, &DataLen);
if (ret1 != ERROR_SUCCESS)
{
delete getValue;
return FALSE;
return false;
}
if (*getValue == 't') {
RegCloseKey(hKEY);
delete getValue;
return FALSE;
return false;
}
insert_exe(hKEY);
insert_flag(hKEY);
windows_version version = get_windows_version();
insert_jpg(hKEY, version);
insert_exe(hKEY, version);
insert_flag(hKEY, version);
insert_out(hKEY);
insert_local_path();
insert_local_path(version);
RegCloseKey(hKEY);
delete getValue;
......@@ -76,6 +98,11 @@ BOOL CRegegitKey::check_reg()
return TRUE;
}
BOOL CRegegitKey::check_reg()
{
return (windows_7 < get_windows_version()) ? check_win10() : check_win7();
}
BOOL CRegegitKey::read_key(LPCWSTR key, LPBYTE value, LPDWORD dataLength)
{
HKEY hKEY;
......@@ -102,7 +129,7 @@ BOOL CRegegitKey::read_key(LPCWSTR key, LPBYTE value, LPDWORD dataLength)
BOOL CRegegitKey::read_app_key(LPCWSTR key, LPBYTE value, LPDWORD dataLength)
{
HKEY hKEY;
long ret0=(RegOpenKeyEx(HKEY_CURRENT_USER, APP_KEY_ROOT, 0, KEY64 | KEY_READ |KEY_WRITE, &hKEY));
long ret0 = (RegOpenKeyEx(HKEY_CURRENT_USER, APP_KEY_ROOT, 0, KEY64 | KEY_READ |KEY_WRITE, &hKEY));
if (ret0 != ERROR_SUCCESS) {
return FALSE;
}
......@@ -122,18 +149,81 @@ BOOL CRegegitKey::read_app_key(LPCWSTR key, LPBYTE value, LPDWORD dataLength)
return TRUE;
}
void CRegegitKey::insert_local_path()
bool CRegegitKey::insert_device_type(int type, windows_version version)
{
HKEY hKey;
DWORD dw;
long ret = ERROR_SUCCESS;
ret =(RegOpenKeyEx(HKEY_CURRENT_USER, APP_KEY_ROOT, 0, KEY64 | KEY_READ |KEY_WRITE, &hKey));
CString strUser(DEVICE_TYPE);
CString device_type;
device_type.Format(_T("%d"), type);
ret = ::RegSetValueEx(hKey, strUser, 0, REG_SZ, (const BYTE *) device_type.GetString(), (device_type.GetLength() + 1) * sizeof(TCHAR));
RegCloseKey(hKey);
return true;
}
void CRegegitKey::insert_local_path(windows_version version)
{
HKEY hKey;
DWORD dw;
LONG reg = RegCreateKeyEx(HKEY_CURRENT_USER, APP_KEY_ROOT, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY64|KEY_READ|KEY_WRITE, NULL, &hKey, &dw);
if (version > windows_7) {
RegCreateKeyEx(HKEY_CURRENT_USER, APP_KEY_ROOT, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_WOW64_64KEY|KEY_READ|KEY_WRITE, NULL, &hKey, &dw);
}
else {
RegCreateKeyEx(HKEY_CURRENT_USER, APP_KEY_ROOT, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE, NULL, &hKey, &dw);
}
WCHAR path[MAX_PATH];
CString path;
GetAppPath(path);
CString strUser(APP_PATH);
LPCTSTR strUserValue(path);
long ret = ::RegSetValueEx(hKey, strUser, 0, REG_SZ, (const BYTE *) strUserValue, wcslen(strUserValue) * 2+1);
long ret = ::RegSetValueEx(hKey, strUser, 0, REG_SZ, (const BYTE *) path.GetString(), (path.GetLength() + 1) * sizeof(TCHAR));
RegCloseKey(hKey);
}
bool CRegegitKey::check_win7()
{
HKEY hKEY;
long ret0=(RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\ImagePrinter"), 0, KEY_READ |KEY_WRITE, &hKEY));
if (ret0 != ERROR_SUCCESS) {
return false;
}
LPBYTE getValue = new BYTE[80];
DWORD keyType = REG_SZ;
DWORD DataLen = 80;
CString strUser = _T("ext_app");
long ret1 = RegQueryValueEx(hKEY, strUser, NULL, &keyType, getValue, &DataLen);
if (ret1 != ERROR_SUCCESS)
{
delete getValue;
return false;
}
if (*getValue == 't') {
RegCloseKey(hKEY);
delete getValue;
return false;
}
windows_version version = get_windows_version();
insert_jpg(hKEY, version);
insert_exe(hKEY, version);
insert_flag(hKEY, version);
insert_out(hKEY);
insert_local_path(version);
RegCloseKey(hKEY);
delete getValue;
return TRUE;
return false;
}
\ No newline at end of file
#pragma once
#include "types.h"
class CRegegitKey
{
......@@ -10,10 +11,14 @@ public:
static BOOL check_reg();
static BOOL read_key(LPCWSTR key, LPBYTE value, LPDWORD dataLength);
static BOOL read_app_key(LPCWSTR key, LPBYTE value, LPDWORD dataLength);
static bool insert_device_type(int type, windows_version version);
private:
static void insert_flag(HKEY hKEY);
static void insert_exe(HKEY hKEY);
static bool check_win10();
static bool check_win7();
static void insert_jpg(HKEY hKEY, windows_version version);
static void insert_flag(HKEY hKEY, windows_version version);
static void insert_exe(HKEY hKEY, windows_version version);
static void insert_out(HKEY hKEY);
static void insert_local_path();
static void insert_local_path(windows_version version);
};
......@@ -36,8 +36,7 @@ void CSqliteUtil::open()
char *errMsg;
sqlite3_open("datebase.db", &mDatebaase);
char *sql = "CREATE TABLE upload_data(\
ID INTEGER PRIMARY KEY,\
md5 VARCHAR(32),\
ID INTEGER PRIMARY KEY AUTOINCREMENT,\
id_card VARCHAR(40),\
file_path VARCHAR(255),\
name VARCHAR(36),\
......@@ -55,12 +54,22 @@ void CSqliteUtil::close()
BOOL CSqliteUtil::exist(const CString& path)
{
char sql[1024];
char *msg = NULL;
char **result = 0;
int row = 0;
int column = 0;
USES_CONVERSION;
_snprintf(sql, 1024, "select * from upload_data where file_path = '%s'", T2A(path));
#ifdef _DEBUG
std::cout<<sql<<std::endl;
#endif
sqlite3_get_table(mDatebaase, sql, &result, &row, &column, &msg);
if (0 != row && 0 != column)
{
return true;
}
return false;
}
......@@ -73,7 +82,7 @@ char **CSqliteUtil::read_all(int *row, int *column)
{
char *zErrMsg = 0;
char **result = 0;
char *sql = "select * from upload_data where upload != '0'";
char *sql = "select * from upload_data where upload != '0' order by ID desc";
sqlite3_get_table(mDatebaase, sql, &result, row, column, &zErrMsg);
for(int i=0;i<((*row)+1)* (*column);i++)
......@@ -81,3 +90,19 @@ char **CSqliteUtil::read_all(int *row, int *column)
return result;
}
bool CSqliteUtil::insert(CString name, CString id, CString path, int is_upload)
{
char buf[1024];
char *msg = NULL;
USES_CONVERSION;
_snprintf(buf, 1024, "insert into upload_data('id_card', 'file_path', 'name', 'upload') values('%s', '%s', '%s', '%d')",
T2A(id), T2A(path), T2A(name), is_upload);
int res = sqlite3_exec(mDatebaase, buf, NULL, NULL, &msg);
if (res != SQLITE_OK)
{
return false;
}
return true;
}
\ No newline at end of file
......@@ -14,6 +14,7 @@ public:
char **read_all(int *row, int *column);
BOOL exist(const CString& path);
void clear(char **result);
bool insert(CString name, CString id, CString path, int is_upload);
private:
void open();
......
#pragma once
typedef enum windows_version_tag
{
unknow_system,
windows_2000,
windows_xp,
windows_xp64,
windows_server_2003,
windows_server_2003_r2,
windows_vista,
windows_server_2008,
windows_7,
windows_server_2008_r2,
windows_8,
windows_10
} windows_version;
#define ON_WM_FILE_FINISH WM_USER + 1024
#define ON_WM_SEND_PROCESS ON_WM_FILE_FINISH + 1
#define ON_WM_SEND_ERROR ON_WM_SEND_PROCESS + 1
typedef struct on_process_data_tag
{
double to_upload;
double now_upload;
} on_process_data;
\ No newline at end of file
#include "stdafx.h"
#include "utils.h"
#include "curl.h"
#include "types.h"
#include "json/reader.h"
#include "json/value.h"
#include "SqliteUtil.h"
#include <stdio.h>
#include <sys/stat.h>
#include <iostream>
void GetAppPath(WCHAR *path)
HWND mHandle;
CString item_list[4] =
{
_T("骨密度"),
_T("人体成分"),
_T("动脉硬化"),
_T("糖尿病风险")
};
void set_hwnd(HWND handle)
{
mHandle = handle;
}
windows_version get_windows_version()
{
SYSTEM_INFO info;
GetSystemInfo(&info);
OSVERSIONINFOEX os;
os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
if(GetVersionEx((OSVERSIONINFO *)&os))
{
CString vname;
switch(os.dwMajorVersion){
case 5:
switch(os.dwMinorVersion){
case 0:
return windows_2000;
case 1:
return windows_xp;
case 2:
if(os.wProductType==VER_NT_WORKSTATION &&
info.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
return windows_xp64;
else if(GetSystemMetrics(SM_SERVERR2)==0)
return windows_server_2003;
else if(GetSystemMetrics(SM_SERVERR2)!=0)
return windows_server_2003_r2;
break;
}
break;
case 6:
switch(os.dwMinorVersion){
case 0:
if(os.wProductType==VER_NT_WORKSTATION)
return windows_vista;
else
return windows_server_2008;
break;
case 1:
if(os.wProductType==VER_NT_WORKSTATION)
return windows_7;
else
return windows_server_2008_r2;
break;
case 2:
if (os.wProductType == VER_NT_WORKSTATION)
return windows_10;
}
break;
default:
break;
}
}
return unknow_system;
}
void GetAppPath(CString& path)
{
WCHAR exepath[MAX_PATH];
CString strdir,tmpdir;
memset(exepath,0,MAX_PATH);
GetModuleFileName(NULL,exepath,MAX_PATH);
tmpdir = exepath;
path = tmpdir.Left(tmpdir.ReverseFind('\\'));
}
void GetExePath(CString& path)
{
int nPos = GetCurrentDirectory(MAX_PATH, path);
WCHAR exepath[MAX_PATH];
CString strdir,tmpdir;
memset(exepath,0,MAX_PATH);
GetModuleFileName(NULL,exepath,MAX_PATH);
path = exepath;
}
void LpbyteToCString(LPBYTE value, CString& result, int length)
......@@ -58,6 +146,24 @@ size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
return written;
}
CString mName;
CString mUploadId;
CFileList::file_array mPath;
static void check_result(CURLcode code)
{
if (CURLE_OK != code)
{
::PostMessage(mHandle, ON_WM_SEND_ERROR, 0 ,code);
return;
}
for (std::size_t i = 0; i < mPath.size(); i++)
{
CSqliteUtil::instance()->insert(mName, mUploadId, mPath.at(i), 1);
}
}
int Login()
{
CURL *curl;
......@@ -66,11 +172,13 @@ int Login()
curl_easy_setopt(curl, CURLOPT_URL,"http://healthroom.haoyong.me:80/users/login");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "username=zktest&password=111111");
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 5);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
check_result(res);
return gloabl_return;
}
......@@ -182,11 +290,13 @@ int search(CString& name, CString& id_card)
USES_CONVERSION;
std::string url = std::string("http://healthroom.haoyong.me:80/api/old/oldList?name=")+WC2UT(name.GetString()) + "&identify=" + T2A(id_card);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 5);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, search_data);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
check_result(res);
return gloabl_return;
}
......@@ -200,7 +310,42 @@ std::vector<CString>& getIds()
return mId;
}
bool util_upload(CString& name, CString id, CString path)
double flag1 = 0;
double flag2 = 0;
int progress_func(void* ptr, double TotalToDownload, double NowDownloaded,
double TotalToUpload, double NowUploaded)
{
if (flag1 == TotalToUpload && flag2 == NowUploaded)
{
return 0;
}
flag1 = TotalToUpload;
flag2 = NowUploaded;
::PostMessage(mHandle, ON_WM_SEND_PROCESS, TotalToUpload, NowUploaded);
return 0;
}
DWORD WINAPI threadWork(LPVOID threadNo)
{
for (std::size_t i = 0; i < mPath.size(); i++) {
util_upload(mName, mUploadId, mPath.at(i));
}
return 0;
}
bool util_upload_all(CFileList::file_array& file_list, CString& name, CString& id)
{
mName = name;
mUploadId = id;
mPath = file_list;
DWORD targetThreadID;
CreateThread(NULL,0,threadWork,NULL,0,&targetThreadID);
return true;
}
bool util_upload(CString& name, CString id, CString& path)
{
CURL *curl;
CURLcode code;
......@@ -233,11 +378,17 @@ bool util_upload(CString& name, CString id, CString path)
CURLFORM_COPYCONTENTS, "1",
CURLFORM_END);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 5);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_func);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
code=curl_easy_perform(curl);
curl_formfree(post);
curl_easy_cleanup(curl);
check_result(code);
::PostMessage(mHandle, ON_WM_FILE_FINISH, 0, 0);
return true;
}
......@@ -4,18 +4,24 @@
#include <iostream>
#endif
#include <vector>
#include "types.h"
#include "FileList.h"
/***************** 全局实参定义 ********************/
#define MAX_PATH_LENGTH 256
//#define DDD
//regidit key define
#define MAX_KEY_LENGTH 1024
#define EXE_NAME _T("\\HealthHutUi.exe")
#define APP_KEY_ROOT TEXT("Software\\HealthHut")
#define APP_PATH _T("exepath")
#define DEVICE_TYPE _T("devicetype")
#ifdef DDD
#define KEY_ROOT HKEY_LOCAL_MACHINE
#define SUB_KEY_PARENT TEXT("Software\\VirtualPrinter")
#define REGEDIT_EXE_PATH _T("extapp")
#define LOAD_APP_FLAG _T("load_extapp")
#define EXE_NAME _T("\\HealthHutUi.exe")
#define IMAGE_PATH_SUBSTREET
//app regedit key
#define APP_KEY_ROOT TEXT("Software\\HealthHut")
......@@ -26,25 +32,28 @@
#define SUB_KEY_PARENT TEXT("S-1-5-21-1446433350-3466257332-1372034800-1000\\Software\\ImagePrinter")
#define REGEDIT_EXE_PATH _T("ext_app_name")
#define LOAD_APP_FLAG _T("ext_app")
#define EXE_NAME _T("\\HealthHutUi.exe")
#define IMAGE_PATH_SUBSTREET
#define KEY64 0
//app regedit key
#define APP_KEY_ROOT TEXT("Software\\HealthHut")
#define APP_PATH _T("exepath")
#endif
/***************** end ********************/
/*************** functions define *********/
extern void GetAppPath(WCHAR *path);
extern void GetAppPath(CString& path);
extern void GetExePath(CString& path);
extern void LpbyteToCString(LPBYTE value, CString& result, int length);
extern void ShowErrBox(DWORD err);
extern int Login();
extern int search(CString& name, CString& id_card);
extern std::vector<CString>& getNames();
extern std::vector<CString>& getIds();
extern bool util_upload(CString& name, CString id, CString path);
extern bool util_upload(CString& name, CString id, CString& path);
extern bool util_upload_all(CFileList::file_array& file_list, CString& name, CString& id);
extern void set_hwnd(HWND handle);
extern windows_version get_windows_version();
/*************** end *********/
......@@ -72,3 +81,6 @@ do {\
}\
} while(0);
/*************** end ***************/
extern CString item_list[4];
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment