Files
coco df489d5640 a
2026-07-03 16:05:30 +08:00

1221 lines
37 KiB
C++

// GeoMative.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "GeoMative.h"
#include "Constant.h"
#include "MainFrm.h"
#include "Splash.h"
#include "UpdateDataBase.h"
#include "InputPasswordDial.h"
#include "DialCfgTerrain.h"
#include <DbgHelp.h>
#include "TaskDataOper.h"
#include "FileOperTools.h"
#include <utility>
#include "DailLogin.h"
#include "GD10OperCmd.h"
#include <afxole.h>
#include "geo_meta_helper.h"
#include <icrsint.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern BOOL g_bScanFun;
extern CString g_szMacAddress;
extern CRITICAL_SECTION g_ScanTabSection;
extern BOOL DevLinkScanThreadFunction(LPVOID pParam);
extern bool GetSysTimeFunction(LPVOID pParam);
extern CDevLinkRecord* aDevLinkTable[256];
extern SYSTEMTIME g_sysCurTime;
extern int g_iTransFileMode;
extern int g_iOnLineVersion;
extern BOOL g_bIsOnlineTransfer;
extern int g_iTimeZone;
extern HHOOK hHook;
extern LRESULT __stdcall CBTHookProc(long nCode, WPARAM wParam, LPARAM lParam);
extern int g_iUILanguage;
/////////////////////////////////////////////////////////////////////////////
// CGeoMativeApp
BEGIN_MESSAGE_MAP(CGeoMativeApp, CWinApp)
//{{AFX_MSG_MAP(CGeoMativeApp)
ON_COMMAND(IDM_FILE_EXIT, OnFileExit)
ON_COMMAND(IDM_HELP_ABOUT, OnHelpAbout)
ON_COMMAND(IDM_TERRAIN_SET, OnCfgTerrain)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGeoMativeApp construction
CGeoMativeApp::CGeoMativeApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
m_pConnection = NULL;
m_pTdManager = NULL;
m_pProManager = NULL;
m_pDevManager = NULL;
m_pExecManager = NULL;
m_pSptManager = NULL;
m_pIOManager = NULL;
m_dwSysTimeThreadID = 0;
m_strRemAnalyFolder.RemoveAll();
m_strUpgUrl = _T("");
m_strHomePage = _T("");
m_i2dDataExpStyle = 0;
m_ucMaxChannel = 1;
m_iCableType = 0;
m_uiUserID = 0;
m_ucIsMultiChannel = EN_MULTI_CHANNEL;
}
CGeoMativeApp::~CGeoMativeApp()
{
if (m_pConnection != NULL)
{
delete m_pConnection;
m_pConnection = NULL;
}
if (m_pMainWnd != NULL)
{
delete m_pMainWnd;
m_pMainWnd = NULL;
}
if (m_pTdManager != NULL)
{
delete m_pTdManager;
m_pTdManager = NULL;
}
if (m_pProManager != NULL)
{
delete m_pProManager;
m_pProManager = NULL;
}
if (m_pDevManager != NULL)
{
delete m_pDevManager;
m_pDevManager = NULL;
}
if (m_pExecManager != NULL)
{
delete m_pExecManager;
m_pExecManager = NULL;
}
if (m_pSptManager != NULL)
{
delete m_pSptManager;
m_pSptManager = NULL;
}
if (m_pIOManager != NULL)
{
delete m_pIOManager;
m_pIOManager = NULL;
}
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CGeoMativeApp object
/////////////////////////////////////////////////////////////////////////////
// CGeoMativeApp initialization
BOOL CGeoMativeApp::InitInstance()
{
// CG: The following block was added by the Splash Screen component.
\
{
\
CCommandLineInfo cmdInfo;
\
ParseCommandLine(cmdInfo);
\
\
CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);
\
}
HRESULT hResult;
if ( !AfxOleInit() )
{
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("初始化OLE失败"));
else
MessageBoxEx(NULL, _T("Initialize Ole failed!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return FALSE;
}
AfxOleGetMessageFilter()->EnableBusyDialog(FALSE);
AfxOleGetMessageFilter()->SetBusyReply(SERVERCALL_RETRYLATER);
AfxOleGetMessageFilter()->EnableNotRespondingDialog(TRUE);
AfxOleGetMessageFilter()->SetMessagePendingDelay(-1);
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
//_CrtSetBreakAlloc(8903);
// To create the main window, this code creates a new frame window
// object and then sets it as the application's main window object.
CString strExePath;
CString strPath;
GetModuleFileName(NULL, strPath.GetBufferSetLength(MAX_PATH + 1), MAX_PATH + 1);
int nPos = strPath.ReverseFind(_T('\\'));
strExePath = strPath.Left(nPos + 1);
SetCurrentDirectory(strExePath);
if (!PathFileExistsA(strExePath+"CACHE")) {
::CreateDirectoryA(strExePath + "CACHE", nullptr);
}
if (!PathFileExistsA(strExePath + "CACHE\\projects")) {
::CreateDirectoryA(strExePath + "CACHE\\projects", nullptr);
}
if (!PathFileExistsA(strExePath + "CACHE\\scripts")) {
::CreateDirectoryA(strExePath + "CACHE\\scripts", nullptr);
}
CMDIFrameWnd* pFrame = new CMainFrame;
m_pMainWnd = pFrame;
// create main MDI frame window
if (!pFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
// try to load shared MDI menus and accelerator table
//TODO: add additional member variables and load calls for
// additional menu types your application may need.
// HINSTANCE hInst = AfxGetResourceHandle();
// m_hMDIMenu = ::LoadMenu(hInst, MAKEINTRESOURCE(IDR_GEOMATTYPE));
// m_hMDIAccel = ::LoadAccelerators(hInst, MAKEINTRESOURCE(IDR_GEOMATTYPE));
// The main window has been initialized, so show and update it.
m_nCmdShow = SW_SHOWMAXIMIZED;
pFrame->ShowWindow(m_nCmdShow);
pFrame->UpdateWindow();
::CoInitialize(NULL);
m_mapCrossHole.clear();
CString strText = _T("");
try
{
hResult = m_pConnection.CreateInstance(_uuidof(Connection));
// hResult = m_pCatalog.CreateInstance(_uuidof(ADOX::Catalog));
CString szDBPath = _T("");
CString szConn = _T("");
::GetCurrentDirectory(256, szDBPath.GetBuffer(256));
szDBPath.ReleaseBuffer();
//for test
// CString strLogPath = szDBPath + _T("\\LOG\\");
// if (!MakeSureDirectoryPathExists(strLogPath))
// {
// AfxMessageBox(_T("create log folder error,please check your enviorment!"));
// ExitInstance();
// return FALSE;
// }
// CString strTestFile = strLogPath + _T("commLog.txt");
// FILE* pTestFile = fopen(strTestFile,"a+");
// if (NULL == pTestFile)
// {
// AfxMessageBox(_T("please make sure install folder is have enough authority!"));
// ExitInstance();
// return FALSE;
// }
// CString strInfoTest = _T("this is a test!!!");
// if (fwrite(strInfoTest.GetBuffer(0), 1, strInfoTest.GetLength(), pTestFile) < strInfoTest.GetLength())
// {
// AfxMessageBox(_T("please make sure install folder is have enough authority!!!"));
// fclose(pTestFile);
// ExitInstance();
// return FALSE;
// }
// if (EOF == fflush(pTestFile))
// {
// AfxMessageBox(_T("please make sure install folder is have enough authority..."));
// fclose(pTestFile);
// ExitInstance();
// return FALSE;
// }
// fclose(pTestFile);
//
szConn = _T("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=") + szDBPath + _T("\\DB\\GeoMativeDB.accdb;Jet OLEDB:Database Password=bsgeomative;");
if (m_pConnection != NULL)
{
m_pConnection->Open(szConn.AllocSysString(), "", "", adModeUnknown);
m_pConnection->GetProperties()->GetItem(_variant_t("Jet OLEDB:Max Locks Per File"))->PutValue(_variant_t((long)100000, VT_I4));
}
else
{
strText.Format(_T("0 == %d数据库指针返回空"), hResult);
AfxMessageBox(strText, MB_ICONINFORMATION);
}
// m_pCatalog->PutActiveConnection(_variant_t((IDispatch *)m_pConnection));
}
catch (_com_error e)
{
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
strText.Empty();
if (LANG_ZHCN == g_iUILanguage)
{
strText.Format(_T("连接到数据库失败!Errmsg = %s, Descmsg = %s"), (LPCTSTR)e.ErrorMessage(), (LPCTSTR)e.Description());
AfxMessageBox(strText, MB_ICONINFORMATION);
}
else
{
strText.Format(_T("Connect to database failed!Errmsg = %s, Descmsg = %s"), (LPCTSTR)e.ErrorMessage(), (LPCTSTR)e.Description());
MessageBoxEx(NULL, strText, STRING_MESSAGEBOXEX_TITLE, MB_ICONINFORMATION, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
ExitInstance();
return FALSE;
}
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2,2), &wsaData))
{
// m_bIsSocketIniti = false;
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("初始化socket失败"));
else
MessageBoxEx(NULL, _T("Intitial windows socket failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
//GeoMetaHelper helper;
//helper.Login("geomative456", "123456");
//std::vector<ProjectInfo> project_list;
//auto r = helper.GetProjectList(GeoMetaHelper::GeoMetaSceneId::id_seis, project_list);
//r = helper.GetGsList(project_list[0].id_, project_list[0].gs_list_);
//r = helper.GetTmList(project_list[0].gs_list_[0].id_, 19, project_list[0].gs_list_[0].tm_list_);
//初始化日志文件名,以及删除多余日志
CFileOperTools::GetInstance()->GeneralLogName();
CFileOperTools::GetInstance()->DealGeneralLogFunc();
GetDBPasswordInfo();
InitalDiagnosisInfo();
GeCrossHoleCfg();
std::map<CString,STDBPasswordInfo>::iterator iter = m_mapPasswordInfo.find(_T("Geomative"));
if (iter != m_mapPasswordInfo.end())
{
if (!iter->second.strPassword.IsEmpty())
{
CInputPasswordDial InputPassDial;
InputPassDial.SetGeoPassword(iter->second.strPassword);
if (IDOK != InputPassDial.DoModal())
{
ExitInstance();
return FALSE;
}
}
}
DWORD dwParam = 1;
//create get systime time thread, added by lsq 20150516
memset(&g_sysCurTime, 0, sizeof(SYSTEMTIME));
m_dwSysTimeThreadID = 0;
m_hSysTimeThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)GetSysTimeFunction, &dwParam, 0, &m_dwSysTimeThreadID);
if (INVALID_HANDLE_VALUE == m_hSysTimeThread)
{
// hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("创建获取系统时间线程失败"));
else
MessageBoxEx(NULL, _T("To create GetSystime thread fail!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return FALSE;
}
CloseHandle(m_hSysTimeThread);
//end
//数据库的更新
CString strVer = ((CMainFrame*)pFrame)->GetGeoMativeVersion();
if (0 == strVer.Compare("NULL"))
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("获取Geomative Studio版本失败"));
else
MessageBoxEx(NULL, _T("Get Geomative Studio Version Failed!!!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
ExitInstance();
return FALSE;
}
((CMainFrame*)pFrame)->SetStatusText(_T("Updates DB info..."));
CUpdateDataBase OperDBInfo(m_pConnection, strVer);
int nRes = OperDBInfo.UpdateDBInfo();
if (enResFail == nRes)
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("数据库更新失败!"));
else
MessageBoxEx(NULL, _T("Database update failed!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
ExitInstance();
return FALSE;
}
else if (enResSuccess == nRes)
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("数据库更新成功!"));
else
MessageBoxEx(NULL, _T("Database update success!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
else if(enResNoUpdate == nRes)
{
((CMainFrame*)pFrame)->SetStatusText(_T("ready"));
}
else
{
CString strTips;
if (LANG_ZHCN == g_iUILanguage)
{
strTips.Format(_T("未知错误更新数据库信息,错误码(%d) !"), nRes);
AfxMessageBox(strTips);
}
else
{
strTips.Format(_T("Unknow UpdateDBInfo result, res = %d !"), nRes);
MessageBoxEx(NULL, strTips, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
ExitInstance();
return FALSE;
}
SetDBAttributeUpdateInfo();
m_pTdManager = new CTdManager(m_pConnection);
m_pProManager = new CProManager(m_pConnection);
m_pDevManager = new CDevManager(m_pConnection);
m_pExecManager = new CExecManager(m_pConnection);
m_pSptManager = new CSptManager(m_pConnection);
m_pIOManager = new CIOManager(m_pConnection, m_pCatalog);
g_iTransFileMode = GetPrivateProfileInt(_T("ONLINE_DEVICE"), _T("RemoteType"), EN_TRANSFER_FILE_BY_USB, _T("./config.ini"));
m_uiUserID = GetPrivateProfileInt(_T("USER_INFO"), _T("UserID"), 12345622, _T("./config.ini"));
m_ucIsMultiChannel = (EN_CHANNEL_INFO)GetPrivateProfileInt(_T("CHANNEL_INFO"), _T("IsMultiChannel"), EN_MULTI_CHANNEL, _T("./config.ini"));
BYTE ucAutoLoginFlg = GetPrivateProfileInt(_T("USER_Auto"), _T("UserAuto"), 0, _T("./config.ini"));
char ucPwd[31];
GetPrivateProfileString(_T("USER_Pwd"), _T("UserPwd"), "123456", ucPwd,30,_T("./config.ini"));
CString csPwd = ucPwd;
BYTE ucSavePwd = GetPrivateProfileInt(_T("USER_Save"), _T("UserSave"), 0, _T("./config.ini"));
g_iOnLineVersion = GetPrivateProfileInt(_T("ONLINE_VERSION"), _T("VERID"), EN_ON_LIEN_VERSION_1, _T("./config.ini"));
g_iTimeZone = GetPrivateProfileInt(_T("ONLINE_TIMEZONE"), _T("TIMEZONE"), 8, _T("./config.ini"));//默认北京时区
LCID lcidNew = GetThreadLocale();////http://qiusuoge.com/10483.html
//获取配置文件
int iLanguage = GetPrivateProfileInt(_T("UI"), _T("Language"), 0, _T("./config.ini"));
//if (LANG_ZHCN == iLanguage)
if (LANG_ZHCN == iLanguage && (LANG_CHINESE_SIMPLIFIED == PRIMARYLANGID(LANGIDFROMLCID(lcidNew))))
{
WritePrivateProfileString(_T("UI"), _T("Language"), _T("1"), _T("./config.ini"));
m_pMainWnd->SendMessage(WM_CHANGE_LANGUAGE, (WPARAM)LANG_ZHCN, 0);
}
else
{
WritePrivateProfileString(_T("UI"), _T("Language"), _T("2"), _T("./config.ini"));
m_pMainWnd->SendMessage(WM_CHANGE_LANGUAGE, (WPARAM)LANG_ENUS, 0);
}
//在线登录框
if (EN_TRANSFER_FILE_BY_CLOUND == g_iTransFileMode)
{
CDailLogin dlg(m_uiUserID, csPwd, ucAutoLoginFlg, ucSavePwd);
if (IDOK != dlg.DoModal())
{
return FALSE;
}
switch (g_iTransFileMode)
{
case EN_TRANSFER_FILE_BY_CLOUND:
::SetTimer(m_pMainWnd->GetSafeHwnd(), ID_UPLOAD_DEVICE_MARKET_DATA, UPLOAD_MARKET_DATA_INTERVAL, NULL);
break;
default:
break;
}
//启动心跳包
::SetTimer(m_pMainWnd->GetSafeHwnd(), ID_TIMER_HEARTBEAT_PACKET, HEARTBEAT_INTERVAL, NULL);
}
//登录成功后usb模式读取GD日志或者usb模式直接读取
if (EN_TRANSFER_FILE_BY_USB == g_iTransFileMode)
{
bool bRes = CGD10OperCmd::GetInstance()->loadDeviceMarkDataFromGD();
if (!bRes)
{
CFileOperTools::GetInstance()->WriteComLog(_T("Failed to read device market data from GD device"));
}
}
if (EN_TRANSFER_FILE_BY_CLOUND == g_iTransFileMode || EN_TRANSFER_FILE_BY_WIFI == g_iTransFileMode)
{
char chIP[30]="NULL";
GetPrivateProfileString(_T("ONLINE_DEVICE"),_T("IP"), "NULL",chIP, sizeof(chIP),_T("./config.ini"));
WORD wPort = GetPrivateProfileInt(_T("ONLINE_DEVICE"), _T("Port"), 0, _T("./config.ini"));
if (0 == wPort || 0 == strcmp(chIP,"NULL"))
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("IP或端口配置错误"));
else
MessageBoxEx(NULL, _T("IP or port config error"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return FALSE;
}
if (!m_NetWorkOper.Initialize())
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("创建套接字失败"));
else
MessageBoxEx(NULL, _T("To create socket failed"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return FALSE;
}
if (!m_NetWorkOper.StartConnect(chIP,wPort))
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("连接远程地址错误!请检查网络或者离线登录"));
else
MessageBoxEx(NULL, _T("Connect to remote address failed!Please check the network or select the offline login!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
WritePrivateProfileString(_T("USER_Auto"), _T("UserAuto"), 0, _T("./config.ini"));
return FALSE;
}
//在线二期转发,用于区分是否需要转发0x06透传的测试数据
if (EN_ON_LIEN_VERSION_1 == g_iOnLineVersion)
{
g_bIsOnlineTransfer = FALSE;
}
else
{
g_bIsOnlineTransfer = TRUE;
}
if (EN_TRANSFER_FILE_BY_CLOUND == g_iTransFileMode)
{
/*
if (!m_NetWorkOper.SendCtrlMsgDirect(EN_CTRL_USER_LOGIN, 0xFFFFFFFF, 1, (char*)(&m_uiUserID), sizeof(UINT32)))
{
AfxMessageBox(_T("user login information send failed"));
return 0;
}
char chMsg[200] = {0};
int ilen = 0;
if (EN_RECV_SUCCESS ==m_NetWorkOper.RecvMsgDirect(chMsg, &ilen, 200, 2000))
{
short usDevNum = ntohs(*((short*)chMsg));
if (ilen != (2+usDevNum*sizeof(STSigRemoteDev)))
{
CString strErr = _T("");
strErr.Format(_T("recv device number error.total_len = %d, device_number = %d"), ilen, usDevNum);
AfxMessageBox(strErr);
return 0;
}
STSigRemoteDev stRemDev;
for (int i = 0; i < usDevNum; i++)
{
memcpy(&stRemDev,chMsg+2+i*sizeof(STSigRemoteDev), sizeof(STSigRemoteDev));
stRemDev.uiDevID = ntohl(stRemDev.uiDevID);
m_pDevManager->AddRemoteDevice(stRemDev);
}
}
*/
}
else if (EN_TRANSFER_FILE_BY_WIFI == g_iTransFileMode)
{
m_NetWorkOper.SendLoginMsgBrocast();
}
m_NetWorkOper.RegisterDevNotify(CMainFrame::NotifyDevInfo, m_pMainWnd);
if (!m_NetWorkOper.StartWork())
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("线程启动失败"));
else
MessageBoxEx(NULL, _T("Thread startup failed!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return 0;
}
}
try
{
m_pDevManager->InitialDevLinkList();
}
catch (_com_error e)
{
if (LANG_ZHCN == g_iUILanguage)
{
strText.Format(_T("不能找到设备!Errmsg = %s, Descmsg = %s"), (LPCTSTR)e.ErrorMessage(), (LPCTSTR)e.Description());
AfxMessageBox(strText);
}
else
{
strText.Format(_T("Can not find Device!Errmsg = %s, Descmsg = %s"), (LPCTSTR)e.ErrorMessage(), (LPCTSTR)e.Description());
MessageBoxEx(NULL, strText, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
ExitInstance();
return FALSE;
}
g_szMacAddress = m_pProManager->m_guCodeCreator.GenerateMacAddress();
InitializeCriticalSection(&g_ScanTabSection);
dwParam = 1;
m_dwScanThreadID = 0;
m_hScanThread = NULL;
if (EN_TRANSFER_FILE_BY_COM == g_iTransFileMode ||
EN_TRANSFER_FILE_BY_USB == g_iTransFileMode)
{
m_hScanThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)DevLinkScanThreadFunction, &dwParam, 0, &m_dwScanThreadID);
if (INVALID_HANDLE_VALUE == m_hScanThread)
{
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("创建线程失败"));
else
MessageBoxEx(NULL, _T("To create thread fail!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return FALSE;
}
CloseHandle(m_hScanThread);
}
GetCfgUrl();
m_i2dDataExpStyle = GetPrivateProfileInt(_T("EXPORT_DATA"), _T("2dDataExpStyle"), 0, _T("./config.ini"));
//////////////////////////////////////////////////////////////////////////
CTaskDataOper dataOper;
dataOper.DeleteOldPlcStatusData();
HWND hMainWnd = m_pMainWnd->GetSafeHwnd();
CString strLog;
strLog.Format(_T("[CGeoMativeApp][%d] hMainWnd=%d"), __LINE__, hMainWnd);
CFileOperTools::GetInstance()->WriteComLog(strLog);
//usb模式更新菜单
if (EN_TRANSFER_FILE_BY_USB == g_iTransFileMode)
{
((CMainFrame*)AfxGetMainWnd())->SendMessage(WM_MSG_REFRESH_MAIN_MAIN_MENU, 0, 0);
}
//m_NetWorkOper.RegeditRealMsgCall(hMainWnd);
//////////////////////////////////////////////////////////////////////////
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CGeoMativeApp message handlers
int CGeoMativeApp::ExitInstance()
{
//TODO: handle additional resources you may have added
try
{
//m_NetWorkOper.UnRegeditRealMsgCall(m_pMainWnd->GetSafeHwnd());
if (m_pMainWnd != NULL)
{
delete m_pMainWnd;
m_pMainWnd = NULL;
}
if (m_pTdManager != NULL)
{
delete m_pTdManager;
m_pTdManager = NULL;
}
if (m_pProManager != NULL)
{
delete m_pProManager;
m_pProManager = NULL;
}
if (m_pDevManager != NULL)
{
delete m_pDevManager;
m_pDevManager = NULL;
}
if (m_pExecManager != NULL)
{
delete m_pExecManager;
m_pExecManager = NULL;
}
if (m_pSptManager != NULL)
{
delete m_pSptManager;
m_pSptManager = NULL;
}
if (m_pIOManager != NULL)
{
delete m_pIOManager;
m_pIOManager = NULL;
}
if (m_hMDIMenu != NULL)
FreeResource(m_hMDIMenu);
if (m_hMDIAccel != NULL)
FreeResource(m_hMDIAccel);
if (NULL != m_pConnection)
{
try
{
m_pConnection->Close();
m_pConnection = NULL;
}
catch (_com_error e)
{
CString strErrInfo = _T("");
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
AfxMessageBox(e.Description()+_T("..."));
ProcConPtrCloseExpect();
throw;
}
}
if (NULL != m_pCatalog)
{
m_pCatalog.Release();
m_pCatalog = NULL;
}
::g_bScanFun = TRUE;
Sleep(50);
::CoUninitialize();
DeleteCriticalSection(&g_ScanTabSection);
return CWinApp::ExitInstance();
}
catch(...)
{
DWORD dwError = GetLastError();
return CWinApp::ExitInstance();
}
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
/////////////////////////////////////////////////////////////////////////////
// CGeoMativeApp message handlers
void CGeoMativeApp::OnFileExit()
{
// TODO: Add your command handler code here
CDevice* pDevice = NULL;
CString szDevSN = _T("");
szDevSN.Empty();
for (int n = 0; n < 256; n++)
{
if (aDevLinkTable[n])
{
pDevice = m_pDevManager->GetDevice(aDevLinkTable[n]->aDevSN);
pDevice->Reset();
pDevice->m_sComPort.CloseComm();
}
}
PostQuitMessage(0);
}
void CGeoMativeApp::OnHelpAbout()
{
// TODO: Add your command handler code here
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
void CGeoMativeApp::GetDevPassword(CString strDevName, STDBPasswordInfo &strDBPassInfo)
{
strDBPassInfo.nTableID = 0;
strDBPassInfo.strPassword.Empty();
std::map<CString,STDBPasswordInfo>::iterator iter = m_mapPasswordInfo.find(strDevName);
if (iter != m_mapPasswordInfo.end())
{
strDBPassInfo = iter->second;
}
}
BOOL CGeoMativeApp::PreTranslateMessage(MSG* pMsg)
{
// CG: The following lines were added by the Splash Screen component.
if (CSplashWnd::PreTranslateAppMessage(pMsg))
return TRUE;
return CWinApp::PreTranslateMessage(pMsg);
}
// void CGeoMativeApp::GetGeoPassword(CString& strPassword)
// {
// strPassword.Empty();
// _RecordsetPtr pRecInfo= NULL;
// pRecInfo.CreateInstance(_uuidof(Recordset));
// try
// {
// pRecInfo->Open(_T("select Password from password_info where DevType = 1"), _variant_t((IDispatch*)m_pConnection, true),
// adOpenStatic, adLockOptimistic, adCmdText);
// while ((short)VAL_ZERO == pRecInfo->adoEOF)
// {
// strPassword = (CString)(LPCTSTR)(_bstr_t)pRecInfo->GetCollect(_T("Password"));
// break;
// }
// }
// catch (_com_error e)
// {
// hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
// AfxMessageBox(e.Description());
// }
// pRecInfo->Close();
// return;
//
// }
void CGeoMativeApp::GetDBPasswordInfo()
{
m_mapPasswordInfo.clear();
_RecordsetPtr pRecInfo= NULL;
pRecInfo.CreateInstance(_uuidof(Recordset));
m_mapPasswordInfo.clear();
CString strDevName;
CString strGeoName = _T("Geomative");
try
{
pRecInfo->Open(_T("select * from password_info"), _variant_t((IDispatch*)m_pConnection, true),
adOpenStatic, adLockOptimistic, adCmdText);
bool bFirstGeo = false;
STDBPasswordInfo stDBPassInfo;
while ((short)VAL_ZERO == pRecInfo->adoEOF)
{
//只获取第一个Geomative的密码
if (!bFirstGeo && (1 == pRecInfo->GetCollect(_T("DevType")).iVal) )
{
stDBPassInfo.nTableID = (int)(pRecInfo->GetCollect(_T("ID")).iVal);
stDBPassInfo.strPassword.Empty();
stDBPassInfo.strPassword = (CString)(LPCTSTR)(_bstr_t)pRecInfo->GetCollect(_T("DevPassword"));
bFirstGeo = true;
m_mapPasswordInfo.insert(std::make_pair(strGeoName,stDBPassInfo));
}
//获取GD10主机的密码,如果这里存在相同的主机名,则只获取第一个主机的密码
if (2 == pRecInfo->GetCollect(_T("DevType")).iVal)
{
stDBPassInfo.strPassword.Empty();
strDevName.Empty();
stDBPassInfo.nTableID = (int)(pRecInfo->GetCollect(_T("ID")).iVal);
strDevName = (CString)(LPCTSTR)(_bstr_t)pRecInfo->GetCollect(_T("DevName"));
stDBPassInfo.strPassword = (CString)(LPCTSTR)(_bstr_t)pRecInfo->GetCollect(_T("DevPassword"));
m_mapPasswordInfo.insert(std::make_pair(strDevName,stDBPassInfo));
}
pRecInfo->MoveNext();
}
}
catch (_com_error e)
{
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
AfxMessageBox(e.Description());
m_pConnection->RollbackTrans();
}
pRecInfo->Close();
return;
}
void CGeoMativeApp::SetDBAttributeUpdateInfo()
{
_CommandPtr pCmdUpdateInfo = NULL;
_RecordsetPtr pRecMeidum = NULL;
_RecordsetPtr pRecCm = NULL;
pCmdUpdateInfo.CreateInstance(_uuidof(Command));
pRecMeidum.CreateInstance(_uuidof(Recordset));
pRecCm.CreateInstance(_uuidof(Recordset));
try
{
//在这里只暂时更新了英语语言环境中的装置的特殊字符
pCmdUpdateInfo->ActiveConnection = m_pConnection;
m_pConnection->BeginTrans();
CString strSql = _T("");
strSql.Format(_T("update medium set MEname = '%s' where AR = 1 and LANG = 2"), _T("Wenner(alpha)"));
pCmdUpdateInfo->CommandText = strSql.AllocSysString();
pCmdUpdateInfo->Execute(NULL, NULL, adCmdText);
strSql.Empty();
strSql.Format(_T("update medium set MEname = '%s' where AR = 2 and LANG = 2"), _T("Wenner(beta)"));
pCmdUpdateInfo->CommandText = strSql.AllocSysString();
pCmdUpdateInfo->Execute(NULL, NULL, adCmdText);
strSql.Empty();
strSql.Format(_T("update medium set MEname = '%s' where AR = 3 and LANG = 2"), _T("Wenner(gamma)"));
pCmdUpdateInfo->CommandText = strSql.AllocSysString();
pCmdUpdateInfo->Execute(NULL, NULL, adCmdText);
strSql.Empty();
strSql.Format(_T("update medium set MEname = '%s' where AR = 11 and LANG = 2"), _T("Schlumberger(alpha2)"));
pCmdUpdateInfo->CommandText = strSql.AllocSysString();
pCmdUpdateInfo->Execute(NULL, NULL, adCmdText);
strSql = _T("update cm set Clabel = 'Conventional Res Mode' where Cname = 'Clayout' and Cvalue =4 and LANG = 2");
pCmdUpdateInfo->CommandText = strSql.AllocSysString();
pCmdUpdateInfo->Execute(NULL, NULL, adCmdText);
strSql = _T("update cm set Clabel = 'Conventional Res Mode' where Cname = 'Clayout' and Cvalue =5 and LANG = 2");
pCmdUpdateInfo->CommandText = strSql.AllocSysString();
pCmdUpdateInfo->Execute(NULL, NULL, adCmdText);
//插入Medium, 在这里暂时只添加英文的联合剖面
strSql.Empty();
strSql.Format(_T("select * from medium where AR = 33 and LANG = 2"));
pRecMeidum->Open(strSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
//如果没有联合剖面装置,则进行添加
if ((long)VAL_ZERO == pRecMeidum->GetRecordCount())
{
strSql.Empty();
strSql.Format(_T("insert into medium(AR,MEname,LANG) values(%d,'%s', %d)"),33, _T("Composite Profiling"),2);
pCmdUpdateInfo->CommandText = strSql.AllocSysString();
pCmdUpdateInfo->Execute(NULL, NULL, adCmdText);
}
pRecMeidum->Close();
//添加边缘梯度装置
strSql.Empty();
strSql.Format(_T("select * from medium where AR = 41 and LANG = 2"));
pRecMeidum->Open(strSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
//如果没有联合剖面装置,则进行添加
if ((long)VAL_ZERO == pRecMeidum->GetRecordCount())
{
strSql.Empty();
strSql.Format(_T("insert into medium(AR,MEname,LANG) values(%d,'%s', %d)"),41, _T("Edge Gradient"),2);
pCmdUpdateInfo->CommandText = strSql.AllocSysString();
pCmdUpdateInfo->Execute(NULL, NULL, adCmdText);
}
pRecMeidum->Close();
//添加井地井
strSql.Empty();
strSql.Format(_T("select * from medium where AR = 42 and LANG = 2"));
pRecMeidum->Open(strSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
//如果没有联合剖面装置,则进行添加
if ((long)VAL_ZERO == pRecMeidum->GetRecordCount())
{
strSql.Empty();
strSql.Format(_T("insert into medium(AR,MEname,LANG) values(%d,'%s', %d)"),42, _T("Bipole Up-Hole"),2);
pCmdUpdateInfo->CommandText = strSql.AllocSysString();
pCmdUpdateInfo->Execute(NULL, NULL, adCmdText);
}
pRecMeidum->Close();
//添加双边三极
strSql.Empty();
strSql.Format(_T("select * from medium where AR = 43 and LANG = 2"));
pRecMeidum->Open(strSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
//如果没有联合剖面装置,则进行添加
if ((long)VAL_ZERO == pRecMeidum->GetRecordCount())
{
strSql.Empty();
strSql.Format(_T("insert into medium(AR,MEname,LANG) values(%d,'%s', %d)"),43, _T("DoubleSide-3P"),2);
pCmdUpdateInfo->CommandText = strSql.AllocSysString();
pCmdUpdateInfo->Execute(NULL, NULL, adCmdText);
}
pRecMeidum->Close();
//添加中梯扫面
strSql.Empty();
strSql.Format(_T("select * from medium where AR = 29 and LANG = 2"));
pRecMeidum->Open(strSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
//如果没有联合剖面装置,则进行添加
if ((long)VAL_ZERO == pRecMeidum->GetRecordCount())
{
strSql.Empty();
strSql.Format(_T("insert into medium(AR,MEname,LANG) values(%d,'%s', %d)"),29, _T("Mid-Gradient-Scan"),2);
pCmdUpdateInfo->CommandText = strSql.AllocSysString();
pCmdUpdateInfo->Execute(NULL, NULL, adCmdText);
}
pRecMeidum->Close();
//查询cm表,添加发射波形为0+0-
strSql.Empty();
strSql.Format(_T("select * from cm where Cname = '%s' and Cvalue = 6 and LANG = 2"), _T("Trwave"));
pRecCm->Open(strSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if ((long)VAL_ZERO == pRecCm->GetRecordCount())
{
strSql.Empty();
strSql.Format(_T("insert into cm(Cname, Clabel, Cvalue, LANG) values('%s','%s', %d, %d)"),
_T("Trwave"), _T("0+0- Tx"), 6, 2);
pCmdUpdateInfo->CommandText = strSql.AllocSysString();
pCmdUpdateInfo->Execute(NULL, NULL, adCmdText);
}
pRecCm->Close();
//查询cm表,添加发射频率也9(0.03125)Trfrequency
strSql.Empty();
strSql.Format(_T("select * from cm where Cname = '%s' and Cvalue = 9 and LANG = 2"), _T("Trfrequency"));
pRecCm->Open(strSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if ((long)VAL_ZERO == pRecCm->GetRecordCount())
{
strSql.Empty();
strSql.Format(_T("insert into cm(Cname, Clabel, Cvalue, LANG) values('%s','%s', %d, %d)"),
_T("Trfrequency"), _T("0.03125Hz"), 9, 2);
pCmdUpdateInfo->CommandText = strSql.AllocSysString();
pCmdUpdateInfo->Execute(NULL, NULL, adCmdText);
}
pRecCm->Close();
strSql.Empty();
strSql.Format(_T("select * from cm where Cname = '%s' and Cvalue = 9 and LANG = 1"), _T("Trfrequency"));
pRecCm->Open(strSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if ((long)VAL_ZERO == pRecCm->GetRecordCount())
{
strSql.Empty();
strSql.Format(_T("insert into cm(Cname, Clabel, Cvalue, LANG) values('%s','%s', %d, %d)"),
_T("Trfrequency"), _T("0.03125Hz"), 9, 1);
pCmdUpdateInfo->CommandText = strSql.AllocSysString();
pCmdUpdateInfo->Execute(NULL, NULL, adCmdText);
}
pRecCm->Close();
}
catch(_com_error e)
{
hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
AfxMessageBox(e.Description());
AfxMessageBox(e.ErrorMessage());
m_pConnection->RollbackTrans();
return;
}
m_pConnection->CommitTrans();
}
void CGeoMativeApp::InitalDiagnosisInfo()
{
//初始化远程诊断信息
m_strRemAnalyFolder.RemoveAll();
m_strRemAnalyFolder.Add(_T("/sd/users"));
m_strRemAnalyFolder.Add(_T("/sd/equipment"));
m_strRemAnalyFolder.Add(_T("/logs"));
}
void CGeoMativeApp::OnCfgTerrain()
{
CDialCfgTerrain dialCfgTerran;
dialCfgTerran.DoModal();
}
void CGeoMativeApp::ProcConPtrCloseExpect()
{
try
{
m_pConnection->CommitTrans();
m_pConnection->Close();
m_pConnection = NULL;
}
catch(_com_error e)
{
CString strErrInfo = _T("");
strErrInfo.Format(_T("%s!!!"),e.Description());
AfxMessageBox(strErrInfo);
}
}
bool CGeoMativeApp::GetCfgUrl()
{
char chUrl[150] = {0};
char chHomePage[150] = {0};
::GetPrivateProfileString(_T("TRANSFER_INFO"), _T("Url"),_T("NULL"), chUrl, 150,_T("./config.ini"));
::GetPrivateProfileString(_T("TRANSFER_INFO"), _T("HomePage"),_T("NULL"), chHomePage, 150,_T("./config.ini"));
if ((0 == strcmp(chUrl, _T("NULL"))) || (0 == strcmp(chHomePage, _T("NULL"))))
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("获取url配置失败"));
else
MessageBoxEx(NULL, _T("Get url config failed"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return false;
}
m_strUpgUrl.Empty();
m_strUpgUrl.Format(_T("%s"),chUrl);
if (_T("/")!=m_strUpgUrl.Right(1))
{
m_strUpgUrl += _T("/");
}
m_strHomePage.Empty();
m_strHomePage.Format(_T("%s"),chHomePage);
return true;
}
bool CGeoMativeApp::ParserSigCrossHole(int iIndex)
{
CString strSec = "";
strSec.Format(_T("CFG_%d"),iIndex);
char chVal[50] = {0};
GetPrivateProfileString(strSec, "Name", "NUL", chVal, sizeof(chVal), _T("./config.ini"));
CString strErr = "";
if (0==strcmp(chVal, "NUL"))
{
strErr.Format("Find %s name failed",strSec);
CFileOperTools::GetInstance()->WriteComLog(strErr);
return false;
}
CString strKey = chVal;
STCorssHoleCfgInfo stCrossHole;
GetPrivateProfileString(strSec, "FirstPoleDep", "NUL", chVal, sizeof(chVal), _T("./config.ini"));
if (0==strcmp(chVal, "NUL"))
{
strErr.Format(_T("Find %s FirstPoleDep failed"),strSec);
CFileOperTools::GetInstance()->WriteComLog(strSec);
return false;
}
stCrossHole.fFirstPoleDep = atof(chVal);
memset(chVal, 0, sizeof(chVal));
GetPrivateProfileString(strSec, "HoleSpace", "NUL", chVal, sizeof(chVal), _T("./config.ini"));
if (0==strcmp(chVal, "NUL"))
{
strErr.Format(_T("Find %s HoleSpace failed"),strSec);
CFileOperTools::GetInstance()->WriteComLog(strErr);
return false;
}
stCrossHole.fHoleSpace = atof(chVal);
m_mapCrossHole.insert(std::make_pair(strKey, stCrossHole));
return true;
}
bool CGeoMativeApp::GeCrossHoleCfg()
{
// char chUrl[150] = {0};
// char chHomePage[150] = {0};
// //
int iNumber = ::GetPrivateProfileInt(_T("CROSS_HOLE_CFG"), _T("Number"),255,_T("./config.ini"));
// ::GetPrivateProfileString(_T("TRANSFER_INFO"), _T("HomePage"),_T("NULL"), chHomePage, 150,_T("./config.ini"));
// if ((0 == strcmp(chUrl, _T("NULL"))) || (0 == strcmp(chHomePage, _T("NULL"))))
// {
// AfxMessageBox(_T("Get url config failed"));
// return false;
// }
// m_strUpgUrl.Empty();
// m_strUpgUrl.Format(_T("%s"),chUrl);
// if (_T("/")!=m_strUpgUrl.Right(1))
// {
// m_strUpgUrl += _T("/");
// }
// m_strHomePage.Empty();
// m_strHomePage.Format(_T("%s"),chHomePage);
if (255 == iNumber)
{
CFileOperTools::GetInstance()->WriteComLog("Parser [CROSS_HOLE_CFG] number failed");
return false;
}
bool bRes = true;
for (int i = 1; i <= iNumber; i++)
{
if (!ParserSigCrossHole(i))
{
bRes = false;
break;
}
}
if (!bRes)
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("解析CROSS_HOLE_CFG失败"));
else
MessageBoxEx(NULL, _T("Parser CROSS_HOLE_CFG failed"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return bRes;
}