// GD10OperCmd.cpp: implementation of the CGD10OperCmd class. // ////////////////////////////////////////////////////////////////////// #include "geomative.h" #include "GD10OperCmd.h" #include "DetcGD10Dev.h" #include "Markup.h" #include "FileOperTools.h" #include #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// extern int g_iTransFileMode; CGD10OperCmd* CGD10OperCmd::m_pGD10Oper = NULL; extern void SplitterString(CStringArray &szArray,const CString& szSource, const CString& szSplitter); extern int g_iUILanguage; CGD10OperCmd::CGD10OperCmd() { } CGD10OperCmd::~CGD10OperCmd() { } CGD10OperCmd* CGD10OperCmd::GetInstance() { if (EN_TRANSFER_FILE_BY_USB != g_iTransFileMode) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("设备工作状态错误")); else MessageBoxEx(NULL, _T("Gd20 work status error!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return NULL; } if (NULL == m_pGD10Oper) { m_pGD10Oper = new CGD10OperCmd(); } return m_pGD10Oper; } //返回值的含义: //1:成功,0:失败,-1:新建目录失败 int CGD10OperCmd::project_add(const char *mac,const char *projectcn) { if (!CDetcGD10Dev::GetInstance()->IsGD10DevConnect()) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("请确保主机设备连上Geomative Studio!")); else MessageBoxEx(NULL, _T("Please make sure gd20 device was connected to Geomative Studio!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return 0; } if (NULL == mac || NULL == projectcn) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("添加工程参数错误")); else MessageBoxEx(NULL, _T("Add project paramter error!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return 0; } if (!AddProjectInLocalHost(projectcn)) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("添加工程到本机失败")); else MessageBoxEx(NULL, _T("Add project to localhost failed!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return -2; } if (!AddProjectInMacXml(mac, projectcn)) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("添加工程到mac失败")); else MessageBoxEx(NULL, _T("Add project to mac failed!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return -2; } CString strPath = _T(""); CString strInfo = _T(""); strPath.Format(_T("%s\\sd\\projects\\%s\\"),CDetcGD10Dev::GetInstance()->GetGD10DevAddr(),projectcn); if (!MakeSureDirectoryPathExists(strPath)) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("GD20设备创建工程失败")); else MessageBoxEx(NULL, _T("Create project in gd20 device failed"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); strInfo.Format(_T("[CGD10OperCmd][%d]create project in gd20 device failed!path = %s"),__LINE__, strPath); CFileOperTools::GetInstance()->WriteComLog(strPath); return -1; } return 1; } bool CGD10OperCmd::AddProjectInLocalHost(const char *pProjectCN) { CString strPath = _T(""); CString strInfo = _T(""); if (NULL == pProjectCN) { strInfo.Format(_T("[CGD10OperCmd][%d]pProjectCN can't be null!")); CFileOperTools::GetInstance()->WriteComLog(strInfo); return false; } strPath.Format(_T("%s\\%s"),CDetcGD10Dev::GetInstance()->GetGD10DevAddr(), _T("sd\\users\\localhost.xml")); CMarkup markup; bool bOperXml = false; if (markup.Load(strPath)) { if (markup.FindChildElem(_T("user_info"))) { markup.IntoElem(); if (markup.FindChildElem(_T("path_dictionary"))) { markup.IntoElem(); //操作成功 if (markup.AddChildElem(_T("path"), pProjectCN)) { bOperXml = true; markup.Save(strPath); } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]add elemet %s in file failed! filePath = %s"),__LINE__, pProjectCN,strPath); } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]find path_dictionary element failed!filePath = %s"),__LINE__, strPath); } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]find user_info element failed!filePath = %s"),__LINE__, strPath); } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]load file %s failed!"),__LINE__, strPath); } //只有操作失败时才写日志文件 if (!bOperXml) { CFileOperTools::GetInstance()->WriteComLog(strInfo); } return bOperXml; } bool CGD10OperCmd::AddProjectInMacXml(const char* pMac,const char *pProjectCN) { CString strPath = _T(""); CString strInfo = _T(""); if (NULL == pProjectCN || NULL == pMac) { strInfo.Format(_T("[CGD10OperCmd][%d]pProjectCN or pMac can't be null!")); CFileOperTools::GetInstance()->WriteComLog(strInfo); return false; } strPath.Format(_T("%s\\sd\\users\\%s.xml"),CDetcGD10Dev::GetInstance()->GetGD10DevAddr(), pMac); CMarkup markup; bool bOperXml = false; if (markup.Load(strPath)) { if (markup.FindChildElem(_T("user_info"))) { markup.IntoElem(); if (markup.FindChildElem(_T("path_dictionary"))) { markup.IntoElem(); //操作成功 if (markup.AddChildElem(_T("path"), pProjectCN)) { bOperXml = true; markup.Save(strPath); } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]add elemet %s in file failed! filePath = %s"),__LINE__, pProjectCN,strPath); } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]find path_dictionary element failed!filePath = %s"),__LINE__, strPath); } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]find user_info element failed!filePath = %s"),__LINE__, strPath); } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]load file %s failed!"),__LINE__, strPath); } //只有操作失败时才写日志文件 if (!bOperXml) { CFileOperTools::GetInstance()->WriteComLog(strInfo); } return bOperXml; } bool CGD10OperCmd::DelProjectInMacXml(const char* pMac,const char *pProjectCN) { CString strPath = _T(""); CString strInfo = _T(""); CString strText = _T(""); if (NULL == pProjectCN || NULL == pMac) { strInfo.Format(_T("[CGD10OperCmd][%d]pProjectCN or pMac can't be null!")); CFileOperTools::GetInstance()->WriteComLog(strInfo); return false; } strPath.Format(_T("%s\\sd\\users\\%s.xml"),CDetcGD10Dev::GetInstance()->GetGD10DevAddr(), pMac); CMarkup markup; bool bOperXml = false; if (markup.Load(strPath)) { if (markup.FindChildElem(_T("user_info"))) { markup.IntoElem(); if (markup.FindChildElem(_T("path_dictionary"))) { markup.IntoElem(); //在这里需要遍历整个path,如果遍历完,依然没有该projcetCN,也认为是成功的 //如果找到了并且删除失败,则置位标记位为false, while(markup.FindChildElem(_T("path"))) { strText.Empty(); strText = markup.GetChildData(); //如果找到了则进行删除操作 if (0 == strText.Compare(pProjectCN)) { if (!markup.RemoveChildElem()) { bOperXml = false; strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]delete element %s failed!filePath = %s"),__LINE__, pProjectCN, strPath); break; } } bOperXml = true; } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]find path_dictionary element failed!filePath = %s"),__LINE__, strPath); } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]find user_info element failed!filePath = %s"),__LINE__, strPath); } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]load file %s failed!"),__LINE__, strPath); } //只有操作失败时才写日志文件 if (!bOperXml) { CFileOperTools::GetInstance()->WriteComLog(strInfo); } //操作成功时,保存所做的修改 else { markup.Save(strPath); } return bOperXml; } bool CGD10OperCmd::DelProjectInLocalHost(const char *pProjectCN) { CString strPath = _T(""); CString strInfo = _T(""); CString strText = _T(""); if (NULL == pProjectCN) { strInfo.Format(_T("[CGD10OperCmd][%d]pProjectCN or pMac can't be null!")); CFileOperTools::GetInstance()->WriteComLog(strInfo); return false; } strPath.Format(_T("%s\\sd\\users\\localhost.xml"),CDetcGD10Dev::GetInstance()->GetGD10DevAddr()); CMarkup markup; bool bOperXml = false; if (markup.Load(strPath)) { if (markup.FindChildElem(_T("user_info"))) { markup.IntoElem(); if (markup.FindChildElem(_T("path_dictionary"))) { markup.IntoElem(); //在这里需要遍历整个path,如果遍历完,依然没有该projcetCN,也认为是成功的 //如果找到了并且删除失败,则置位标记位为false, while(markup.FindChildElem(_T("path"))) { strText.Empty(); strText = markup.GetChildData(); //如果找到了则进行删除操作 if (0 == strText.Compare(pProjectCN)) { if (!markup.RemoveChildElem()) { bOperXml = false; strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]delete element %s failed!filePath = %s"),__LINE__, pProjectCN, strPath); break; } } bOperXml = true; } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]find path_dictionary element failed!filePath = %s"),__LINE__, strPath); } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]find user_info element failed!filePath = %s"),__LINE__, strPath); } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]load file %s failed!"),__LINE__, strPath); } //只有操作失败时才写日志文件 if (!bOperXml) { CFileOperTools::GetInstance()->WriteComLog(strInfo); } //操作成功时,保存所做的修改 else { markup.Save(strPath); } return bOperXml; } bool CGD10OperCmd::project_delete(const char *mac,const char *projectcn) { if (!CDetcGD10Dev::GetInstance()->IsGD10DevConnect()) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("请确保主机设备连上Geomative Studio!")); else MessageBoxEx(NULL, _T("Please make sure gd20 device was connected to Geomative Studio!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return false; } if (NULL == mac || NULL == projectcn) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("添加工程参数错误")); else MessageBoxEx(NULL, _T("Add project paramter error!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return false; } //如果xml相应的记录信息都被成功删除的话,则此时删除相应的目录 if (DelProjectInLocalHost(projectcn) && DelProjectInMacXml(mac, projectcn)) { CString strPath = _T(""); strPath.Format(_T("%s\\sd\\projects\\%s\\"),CDetcGD10Dev::GetInstance()->GetGD10DevAddr(),projectcn); if (CFileOperTools::GetInstance()->DeleteDirectory(strPath)) { return true; } CString strInfo = _T(""); strInfo.Format(_T("[CGD10OperCmd][%d]DeleteDirectory %s failed!"), __LINE__, strPath); CFileOperTools::GetInstance()->WriteComLog(strInfo); } return false; } //模拟下微机进行测区的创建 //其中返回值的含义为1:成功 0:参数错误 -1:创建目录失败 -2:文件读写失败 int CGD10OperCmd::testzone_add(const char *projectcn,const char *testzonecn,const char *type) { if (!CDetcGD10Dev::GetInstance()->IsGD10DevConnect()) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("请确保主机设备连上Geomative Studio!")); else MessageBoxEx(NULL, _T("Please make sure gd20 device was connected to Geomative Studio!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return 0; } if (NULL == projectcn || NULL == testzonecn || NULL == type) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("tz_add中的输入参数错误!")); else MessageBoxEx(NULL, _T("Input parameter error in tz_add!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return 0; } CString strPath = _T(""); CString strInfo = _T(""); strPath.Format(_T("%s\\sd\\projects\\%s\\%s\\"),CDetcGD10Dev::GetInstance()->GetGD10DevAddr(), projectcn, testzonecn); //创建文件目录 if (!MakeSureDirectoryPathExists(strPath)) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("在gd20设备中创建tz失败!")); else MessageBoxEx(NULL, _T("Create tz in gd20 device failed!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); strInfo.Format(_T("[CGD10OperCmd][%d]create tz in gd20 device failed!path = %s"),__LINE__, strPath); CFileOperTools::GetInstance()->WriteComLog(strPath); return -1; } //修改相应的xml文件 strPath.Empty(); strPath.Format(_T("%s\\sd\\projects\\%s\\project.xml"), CDetcGD10Dev::GetInstance()->GetGD10DevAddr(), projectcn); CMarkup markup; bool bOperXml = false; if (markup.Load(strPath)) { if (markup.FindElem(_T("project"))) { markup.IntoElem(); if (markup.FindElem(_T("testzones"))) { //操作成功 if (markup.AddChildElem(_T("testzone"), testzonecn)) { markup.AddChildAttrib(_T("TYPE"),type); bOperXml = true; markup.Save(strPath); } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]add elemet %s in file failed! filePath = %s"),__LINE__, testzonecn,strPath); } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]find testzones element failed!filePath = %s"),__LINE__, strPath); } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]find project element failed!filePath = %s"),__LINE__, strPath); } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]load file %s failed!"),__LINE__, strPath); } if (!bOperXml) { CFileOperTools::GetInstance()->WriteComLog(strInfo); return -2; } return 1; } int CGD10OperCmd::testzone_delete(const char *projectcn,const char *testzonecn) { if (!CDetcGD10Dev::GetInstance()->IsGD10DevConnect()) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("请确保主机设备连上Geomative Studio!")); else MessageBoxEx(NULL, _T("Please make sure gd20 device was connected to Geomative Studio!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return 0; } if (NULL == projectcn || NULL == testzonecn) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("在tz_del中输入参数错误!")); else MessageBoxEx(NULL, _T("Input parameter error in tz_del!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return 0; } CString strPath = _T(""); CString strInfo = _T(""); CString strText = _T(""); strPath.Format(_T("%s\\sd\\projects\\%s\\project.xml"), CDetcGD10Dev::GetInstance()->GetGD10DevAddr(), projectcn); CMarkup markup; bool bOperXml = false; if (markup.Load(strPath)) { if (markup.FindElem(_T("project"))) { markup.IntoElem(); if (markup.FindElem(_T("testzones"))) { //在这里需要遍历整个testzone,如果遍历完,依然没有该testzonecn,也认为是成功的 //如果找到了并且删除失败,则置位标记位为false, while(markup.FindChildElem(_T("testzone"))) { strText.Empty(); strText = markup.GetChildData(); //如果找到了则进行删除操作 if (0 == strText.Compare(testzonecn)) { if (!markup.RemoveChildElem()) { bOperXml = false; strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]delete element %s failed!filePath = %s"),__LINE__, testzonecn, strPath); break; } } bOperXml = true; } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]find testzones element failed!filePath = %s"),__LINE__, strPath); } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]find project element failed!filePath = %s"),__LINE__, strPath); } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]load file %s failed!"),__LINE__, strPath); } //只有操作失败时才写日志文件 if (!bOperXml) { CFileOperTools::GetInstance()->WriteComLog(strInfo); return -2; } //操作成功时,保存所做的修改 else { markup.Save(strPath); } //删除相应的目录 strPath.Empty(); strPath.Format(_T("%s\\sd\\projects\\%s\\%s\\"),CDetcGD10Dev::GetInstance()->GetGD10DevAddr(), projectcn, testzonecn); if (CFileOperTools::GetInstance()->DeleteDirectory(strPath)) { return 1; } strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]delete directory %s failed!"),__LINE__, strPath); CFileOperTools::GetInstance()->WriteComLog(strInfo); return -1; } int CGD10OperCmd::script_add(const char *scriptcn,const char *scriptname,const char *mudiumid) { if (!CDetcGD10Dev::GetInstance()->IsGD10DevConnect()) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("请确保主机设备连上Geomative Studio!")); else MessageBoxEx(NULL, _T("Please make sure gd20 device was connected to Geomative Studio!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return 0; } if (NULL == scriptcn || NULL == scriptname || NULL == mudiumid) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("输入参数错误在spt_add!")); else MessageBoxEx(NULL, _T("Input parameter error in spt_add!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return 0; } CString strPath = _T(""); CString strInfo = _T(""); CString strCN = _T(""); CString strType = _T(""); strCN.Format(_T("%s"),scriptcn); strCN = strCN.Left(3); if (_T("VES") == strCN) { strType = _T("0"); } else if (_T("ERI") == strCN) { strType = _T("1"); } else if (_T("ERT") == strCN) { strType = _T("2"); } else { if (LANG_ZHCN == g_iUILanguage) { strInfo.Format(_T("未知脚本类型(%s)!"), strCN); AfxMessageBox(strInfo); } else { strInfo.Format(_T("Unknow script type(%s)!"), strCN); MessageBoxEx(NULL, strInfo, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return 0; } //修改相应的xml文件 strPath.Format(_T("%s\\sd\\scripts\\scripts.xml"), CDetcGD10Dev::GetInstance()->GetGD10DevAddr()); CMarkup markup; bool bOperXml = false; if (markup.Load(strPath)) { if (markup.FindElem(_T("scripts"))) { //操作成功 if (markup.AddChildElem(_T("script"), scriptcn)) { markup.AddChildAttrib(_T("type"), strType); markup.AddChildAttrib(_T("name"), scriptname); markup.AddChildAttrib(_T("mudium"),mudiumid); bOperXml = true; markup.Save(strPath); } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]add elemet %s in file failed! filePath = %s"),__LINE__, scriptcn,strPath); } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]find scripts element failed!filePath = %s"),__LINE__, strPath); } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]load file %s failed!"),__LINE__, strPath); } if (!bOperXml) { CFileOperTools::GetInstance()->WriteComLog(strInfo); return -2; } return 1; } bool CGD10OperCmd::script_delete(const char *scriptcn) { if (!CDetcGD10Dev::GetInstance()->IsGD10DevConnect()) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("请确保主机设备连上Geomative Studio!")); else MessageBoxEx(NULL, _T("Please make sure gd20 device was connected to Geomative Studio!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return 0; } if (NULL == scriptcn) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("输入参数错误在spt_del!")); else MessageBoxEx(NULL, _T("Input parameter error in spt_del!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return 0; } CString strPath = _T(""); CString strInfo = _T(""); CString strText = _T(""); strPath.Format(_T("%s\\sd\\scripts\\scripts.xml"), CDetcGD10Dev::GetInstance()->GetGD10DevAddr()); CMarkup markup; bool bOperXml = false; if (markup.Load(strPath)) { if (markup.FindElem(_T("scripts"))) { //在这里需要遍历整个testzone,如果遍历完,依然没有该testzonecn,也认为是成功的 //如果找到了并且删除失败,则置位标记位为false, while(markup.FindChildElem(_T("script"))) { strText.Empty(); strText = markup.GetChildData(); //如果找到了则进行删除操作 if (0 == strText.Compare(scriptcn)) { //如果删除的脚本是跨孔(Geomative)装置则需要删除对应的脚本坐标文件 CString strMedium = markup.GetChildAttrib(_T("mudium")); if (AR_CROSS_HOLE_GEOMATIVE == atoi(strMedium) || AR_CROSS_HOLE_GEOMATIVE_AM == atoi(strMedium)) { CString strScriptPath; CMarkup markupScript; strScriptPath.Format(_T("%ssd\\scripts\\%s.scr"), CDetcGD10Dev::GetInstance()->GetGD10DevAddr(),strText); if (markupScript.Load(strScriptPath)) { if (markupScript.FindElem(_T("script"))) { if (markupScript.FindChildElem(_T("C_H_Script"))) { CString strCoordinatesFile = markupScript.GetChildData(); CString strFilePath; strFilePath.Format(_T("%ssd\\scripts\\%s"), CDetcGD10Dev::GetInstance()->GetGD10DevAddr(), strCoordinatesFile); bool bRes = false; BYTE bTimes = 0; do { bRes = DeleteFile(strFilePath); if (false == bRes) { CFileOperTools::GetInstance()->WriteComLog(_T("zm:CGD10OperCmd::script_delete delete file Failed!")); Sleep(5000); } bTimes++; } while (!bRes && (bTimes <= 3)); if (bRes == false && bTimes > 3) { CFileOperTools::GetInstance()->WriteComLog(_T("zm:CGD10OperCmd::script_delete delete file Failed!")); } } } } } if (!markup.RemoveChildElem()) { bOperXml = false; strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]delete element %s failed!filePath = %s"),__LINE__, scriptcn, strPath); break; } } bOperXml = true; } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]find scripts element failed!filePath = %s"),__LINE__, strPath); } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]load file %s failed!"),__LINE__, strPath); } //只有操作失败时才写日志文件 if (!bOperXml) { CFileOperTools::GetInstance()->WriteComLog(strInfo); return false; } //操作成功时,保存所做的修改 else { markup.Save(strPath); } //删除脚本文件 strPath.Empty(); strPath.Format(_T("%s\\sd\\scripts\\%s.scr"), CDetcGD10Dev::GetInstance()->GetGD10DevAddr(),scriptcn); if (CFileOperTools::GetInstance()->DeleteFileDirect(strPath)) { return true; } return false; } bool CGD10OperCmd::meas_delete(const char *projectcn, const char *testzonecn, const char *measuringcn) { if (NULL == projectcn || NULL == testzonecn || NULL == measuringcn) { return false; } if (!CDetcGD10Dev::GetInstance()->IsGD10DevConnect()) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("请确保主机设备连上Geomative Studio!")); else MessageBoxEx(NULL, _T("Please make sure gd20 device was connected to Geomative Studio!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return false; } //首先删除测区文件中的任务的信息,再删除具体文件,此时如果删除关联成功而删除文件出错的话, //那么也认为是删除成功,因为此时最多只是产生些垃圾文件而已 CString strPath = _T(""); strPath.Format(_T("%s\\sd\\projects\\%s\\%s\\testzone.xml"),CDetcGD10Dev::GetInstance()->GetGD10DevAddr(), projectcn,testzonecn); if (!DeleteTaskInTz(strPath, measuringcn)) { return false; } //现在删除文件 strPath.Empty(); strPath.Format(_T("%s\\sd\\projects\\%s\\%s"),CDetcGD10Dev::GetInstance()->GetGD10DevAddr(), projectcn,testzonecn); DeleteTaskFile(strPath, measuringcn); return true; } bool CGD10OperCmd::DeleteTaskInTz(const CString &strTzPath, const char*pMeasuringcn) { if (strTzPath.IsEmpty()) { return false; } CString strTaskCN = _T(""); CString strTmp = _T(""); CString strElement = _T(""); CString strInfo = _T(""); CString strText = _T(""); strTaskCN.Format(_T("%s"), pMeasuringcn); CMarkup markup; bool bOperXml = false; if (markup.Load(strTzPath)) { strTmp = strTaskCN.Left(3); strTmp.MakeLower(); strElement = strTmp + _T("s"); if (markup.FindChildElem(strElement)) { markup.IntoElem(); //在这里需要遍历整个path,如果遍历完,依然没有该projcetCN,也认为是成功的 //如果找到了并且删除失败,则置位标记位为false, while(markup.FindChildElem(strTmp)) { strText.Empty(); strText = markup.GetChildData(); //如果找到了则进行删除操作 if (0 == strText.Compare(strTaskCN)) { if (!markup.RemoveChildElem()) { bOperXml = false; strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]delete element %s failed!filePath = %s"),__LINE__, strTaskCN, strTzPath); break; } } bOperXml = true; } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]find %s element failed!filePath = %s"),__LINE__, strElement, strTzPath); } } else { strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]load file %s failed!"),__LINE__, strTzPath); } //只有操作失败时才写日志文件 if (!bOperXml) { CFileOperTools::GetInstance()->WriteComLog(strInfo); return false; } //操作成功时,保存所做的修改 else { if (markup.Save(strTzPath)) { return true; } strInfo.Empty(); strInfo.Format(_T("[CGD10OperCmd][%d]save test_zone file failed when delete task!task_cn = %s, file_path = %s"),__LINE__, strTaskCN, strTzPath); CFileOperTools::GetInstance()->WriteComLog(strInfo); return false; } } bool CGD10OperCmd::DeleteTaskFile(const CString &strTzFolderPath, const char*pMeasuringcn) { if (strTzFolderPath.IsEmpty()) { return false; } if (NULL == pMeasuringcn) { return false; } //同时删除相应的文件名的 *.dat *.idx *.org *.rec *.res *.xml CString strDelFile = _T(""); strDelFile.Format(_T("%s\\%s.dat"),strTzFolderPath,pMeasuringcn); bool bRes = true; if (!CFileOperTools::GetInstance()->DeleteFileDirect(strDelFile)) { bRes = false; } strDelFile.Empty(); strDelFile.Format(_T("%s\\%s.idx"),strTzFolderPath,pMeasuringcn); if (!CFileOperTools::GetInstance()->DeleteFileDirect(strDelFile)) { bRes = false; } strDelFile.Empty(); strDelFile.Format(_T("%s\\%s.org"),strTzFolderPath,pMeasuringcn); if (!CFileOperTools::GetInstance()->DeleteFileDirect(strDelFile)) { bRes = false; } strDelFile.Empty(); strDelFile.Format(_T("%s\\%s.rec"),strTzFolderPath,pMeasuringcn); if (!CFileOperTools::GetInstance()->DeleteFileDirect(strDelFile)) { bRes = false; } strDelFile.Empty(); strDelFile.Format(_T("%s\\%s.res"),strTzFolderPath,pMeasuringcn); if (!CFileOperTools::GetInstance()->DeleteFileDirect(strDelFile)) { bRes = false; } strDelFile.Empty(); strDelFile.Format(_T("%s\\%s.xml"),strTzFolderPath,pMeasuringcn); if (!CFileOperTools::GetInstance()->DeleteFileDirect(strDelFile)) { bRes = false; } return bRes; } bool CGD10OperCmd::set_param(const CString& strParam) { if (strParam.IsEmpty()) { return false; } if (!CDetcGD10Dev::GetInstance()->IsGD10DevConnect()) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("请确保主机设备连上Geomative Studio!")); else MessageBoxEx(NULL, _T("Please make sure gd20 device was connected to Geomative Studio!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return false; } CString strLog = _T(""); CStringArray strCmdArr; strCmdArr.RemoveAll(); CString strFilePath = _T(""); strFilePath.Format(_T("%s\\sd\\equipment\\equipment.xml"),CDetcGD10Dev::GetInstance()->GetGD10DevAddr()); SplitterString(strCmdArr, strParam, _T(";")); if (strCmdArr.GetSize() < 1) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("输入参数错误!")); else MessageBoxEx(NULL, _T("Input paramter error!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return false; } CMarkup markup; if (!markup.Load(strFilePath)) { strLog.Empty(); strLog.Format(_T("[CGD10OperCmd][%d]load file %s failed!"),__LINE__, strFilePath); CFileOperTools::GetInstance()->WriteComLog(strLog); return false; } CStringArray strParamArr; CString strNode,strFlag, strVal; for (int i = 0; i < strCmdArr.GetSize(); i++) { strParamArr.RemoveAll(); strFlag.Empty(); strVal.Empty(); strNode.Empty(); SplitterString(strParamArr, strCmdArr.GetAt(i), _T(",")); int iSize = strParamArr.GetSize(); switch (iSize) { case 2: strFlag = strParamArr.GetAt(0); strVal = strParamArr.GetAt(1); break; case 3: strFlag = strParamArr.GetAt(0); strVal.Format(_T("%s,%s"),strParamArr.GetAt(1),strParamArr.GetAt(2)); break; default: strLog.Empty(); strLog.Format(_T("[CGD10OperCmd][%d]Parser input paramter error!error_paramter = %s"),__LINE__,strParam); CFileOperTools::GetInstance()->WriteComLog(strLog); if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("解析输入参数错误!")); else MessageBoxEx(NULL, _T("Parser input paramter error!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return false; } //用这*个条件来判断是否为修改时窗 if (_T("*") == strFlag.Left(1)) { strNode = _T("apparent_chargeability"); strFlag.TrimLeft(_T("*")); } else { strNode = _T("parameter"); } if (markup.FindChildElem(strNode)) { markup.IntoElem(); if (markup.FindChildElem(strFlag)) { if (!markup.SetChildData(strVal)) { strLog.Empty(); strLog.Format(_T("[CGD10OperCmd][%d]set %s element value failed!value = %s,filePath = %s"),__LINE__, strFlag, strVal,strFilePath); CFileOperTools::GetInstance()->WriteComLog(strLog); return false; } } else { strLog.Empty(); strLog.Format(_T("[CGD10OperCmd][%d]find %s element failed!filePath = %s"),__LINE__, strFlag, strFilePath); CFileOperTools::GetInstance()->WriteComLog(strLog); return false; } } else { strLog.Empty(); strLog.Format(_T("[CGD10OperCmd][%d]find %s element failed!filePath = %s"),__LINE__, strNode, strFilePath); CFileOperTools::GetInstance()->WriteComLog(strLog); return false; } markup.ResetPos(); } if (markup.Save(strFilePath)) { return true; } strLog.Empty(); strLog.Format(_T("[CGD10OperCmd][%d]save file failed when set param! file_path = %s"),__LINE__, strFilePath); CFileOperTools::GetInstance()->WriteComLog(strLog); return false; } bool CGD10OperCmd::unregister_user(CString strMacAddr) { if (strMacAddr.IsEmpty()) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("输入参数不能为空")); else MessageBoxEx(NULL, _T("Input paramter can not be empty!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return false; } if (!CDetcGD10Dev::GetInstance()->IsGD10DevConnect()) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("请确保主机设备连上Geomative Studio!")); else MessageBoxEx(NULL, _T("Please make sure gd20 device was connected to Geomative Studio!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return false; } CString strPath = _T(""); strPath.Format(_T("%s\\sd\\users\\%s.xml"),CDetcGD10Dev::GetInstance()->GetGD10DevAddr(),strMacAddr); if (CFileOperTools::GetInstance()->DeleteFileDirect(strPath)) { return true; } return false; } UINT CGD10OperCmd::LoadDevMarkDataFormGDThread(LPVOID lParam) { bool bRes = false; CString strSDRecordDir = _T(""); CString strSDRecordFile = _T(""); strSDRecordDir = CDetcGD10Dev::GetInstance()->GetGD10DevAddr(); if (strSDRecordDir.IsEmpty()) { return bRes; } strSDRecordDir.Format(_T("%sSD\\record"), strSDRecordDir); strSDRecordFile.Format(_T("%s\\record.log"), strSDRecordDir); WIN32_FIND_DATA wfd; HANDLE hFind = FindFirstFile(strSDRecordFile, &wfd); if (INVALID_HANDLE_VALUE == hFind) { CFileOperTools::GetInstance()->WriteComLog(_T("CGD10OperCmd::LoadDevMarkDataFormGDThread() The record.log file was not found on the GD device!")); return bRes; } CString szCurFilePath = _T(""); szCurFilePath.Empty(); szCurFilePath.GetBufferSetLength(256); ::GetCurrentDirectory(szCurFilePath.GetLength(), szCurFilePath.GetBuffer(szCurFilePath.GetLength())); szCurFilePath.ReleaseBuffer(); CString strDestPath = _T(""); strDestPath.Format(_T("%s\\record"), szCurFilePath); if (0 == CreateDirectory(strDestPath, NULL)) { DWORD dwErr = GetLastError(); CString strLog; strLog.Format(_T("zm: Load Dev Mark Data Form GD (CreateDirectory err=%d)"),dwErr); CFileOperTools::GetInstance()->WriteComLog(strLog); return bRes; } int iTimes = 0; SYSTEMTIME st; GetLocalTime(&st); strDestPath.Format(_T("%s\\%04d%02d%02d%02d%02d%02d.log"), strDestPath, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond); do { bRes = CopyFile(strSDRecordFile, strDestPath, TRUE); if (false == bRes) { CFileOperTools::GetInstance()->WriteComLog(_T("CGD10OperCmd::LoadDevMarkDataFormGDThread() CopyFile record.log file failed!")); Sleep(5000); } iTimes++; } while (!bRes && (iTimes <= 3)); if (bRes == false && iTimes > 3) { CFileOperTools::GetInstance()->WriteComLog(_T("CGD10OperCmd::LoadDevMarkDataFormGDThread() Failed to copy the record.log file!")); return bRes; } iTimes = 0; do { bRes = DeleteFile(strSDRecordFile); //bRes = CFileOperTools::GetInstance()->DeleteDirectory(strSDRecordFile); if (false == bRes) { CFileOperTools::GetInstance()->WriteComLog(_T("CGD10OperCmd::LoadDevMarkDataFormGDThread() delete GD dev record.log file failed!")); Sleep(5000); } iTimes++; } while (!bRes && (iTimes <= 3)); if (bRes == false && iTimes > 3) { CFileOperTools::GetInstance()->WriteComLog(_T("CGD10OperCmd::LoadDevMarkDataFormGDThread() Failed to delete the record.log file!")); } return bRes; } //从GD获取设备市场数据 bool CGD10OperCmd::loadDeviceMarkDataFromGD() { HANDLE hThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)LoadDevMarkDataFormGDThread, NULL, 0, 0); if (INVALID_HANDLE_VALUE == hThread) { CFileOperTools::GetInstance()->WriteComLog(_T("Create Thread failed to upload device market data to Cloud")); return false; } CloseHandle(hThread); return true; }