BOOL CCheckRuleXMLParse::Load(CheckRuleArray &arrCheckRuleList) { BOOL bRet = FALSE; // 检查旧版本生成的未加密xml文件是否存在 CString strOldXmlPath = m_strRuleFilePath; strOldXmlPath.Replace(L".bpxml", L"xml"); if (IsFileExist(strOldXmlPath)) { // 读取老版本生成的未加密xml if (CheckVersion(m_strRuleFilePath).CompareNoCase(L"1.0") == 0) bRet = Load(m_strRuleFilePath, arrCheckRuleList); if (CheckVersion(m_strRuleFilePath).CompareNoCase(L"1.1") == 0) bRet = LoadNew(m_strRuleFilePath, arrCheckRuleList); } else { if (IsFileExist(m_strRuleFilePath)) { // 先解密再读取 CString strTempXmlFile; GetTempFile(strTempXmlFile, L"xml"); DecodeFileEx(m_strRuleFilePath, strTempXmlFile); if (CheckVersion(strTempXmlFile).CompareNoCase(L"1.0") == 0) bRet = Load(strTempXmlFile, arrCheckRuleList); if (CheckVersion(strTempXmlFile).CompareNoCase(L"1.1") == 0) bRet = LoadNew(strTempXmlFile, arrCheckRuleList); // 结束后删除临时xml文件 SafeDeleteFile(strTempXmlFile); } } return bRet; }
bool ResourceGUIBackend::OnCommand(const string& cmd,const string& args) { if(cmd == "set_resource") { resources->Select(args); return true; } else if(cmd == "get_resource") { stringstream ss; ss<<resources->selected->Identifier(); SendCommand("current_resource",ss.str()); return true; } else if(cmd == "set_resource_name") { if(resources->selected) resources->selected->resource->name = args; printf("Updating name to %s\n",args.c_str()); } else if(cmd == "delete_resource") { resources->DeleteSelected(); } else if(cmd == "add_resource") { string type,name; stringstream ss(args); if(!SafeInputString(ss,type)) { cout<<"Error reading resource type from args \""<<args<<"\""<<endl; return true; } if(!SafeInputString(ss,name)) { cout<<"Error reading resource name from args \""<<args<<"\""<<endl; return true; } last_added = Add(name,type); } else if(cmd == "load_resource") { if(LoadNew(args)) { SendCommand("new_resource",last_added->Identifier()); } } else if(cmd == "save_resource") { SaveCur(args); } else if(cmd == "load_resource_dir") { if(LoadAll(args)) { SendCommand("refresh_resources",""); } } else if(cmd == "save_resource_dir") { SaveAll(args); } else if(cmd == "convert") { ResourcePtr r=CurrentResource(); ResourcePtr res = CastResource(r,args.c_str()); if(!res) { fprintf(stderr,"Conversion failed\n"); return true; } Add(res); SetLastActive(); } else if(cmd == "extract") { ResourcePtr r=CurrentResource(); if(!r) return true; vector<ResourcePtr> res = ExtractResources(r,args.c_str()); for(size_t i=0;i<res.size();i++){ Add(res[i]); } if(!res.empty()) SetLastActive(); } else if(cmd == "set_path_time") { stringstream ss(args); double time; ss>>time; SetPathTime(time); SendRefresh(); }
// 支持version = 1.0版本 BOOL CCheckRuleXMLParse::Load(const CString &strFilePath, CheckRuleArray &arrCheckRuleList) { // 判断版本 if (CheckVersion(strFilePath).CompareNoCase(L"1.1") == 0) return LoadNew(strFilePath, arrCheckRuleList); arrCheckRuleList.RemoveAll(); if (!IsFileExist(strFilePath)) return FALSE; BOOL bResult = TRUE; // 初始化 Init(); // 打开xml文件 if (!m_pXMLDocument->OpenXMLForDocument(strFilePath)) bResult = FALSE; // 读取数据 if (bResult) { CheckRule checkRule; CString strValue; IBpXMLNode* pRootNode = m_pXMLDocument->GetRootElement(); pRootNode->GetName(strValue); if (strValue.Compare(L"CheckRule") == 0) { IBpXMLNode *pChildNode = NULL; int nNodeCount = pRootNode->GetElementCount(); for (int i = 1; i <= nNodeCount; i++) { IBpXMLNode *pRuleNode = pRootNode->GetElementChildByIndex(i); if (pRuleNode->GetElementCount() >= 3) { pRuleNode->GetAttributeByName(L"id", strValue); checkRule.nID = _wtoi(strValue); // 检查类型 pRuleNode->GetAttributeByName(L"ruletype", strValue); checkRule.nRuleType = _wtoi(strValue); // 检查描述 pChildNode = pRuleNode->GetElementChildByIndex(1); pChildNode->GetText(checkRule.strRuleDesc); DestroyXMLNode(pChildNode); // 检查名称 pChildNode = pRuleNode->GetElementChildByIndex(2); pChildNode->GetText(checkRule.strRuleName); DestroyXMLNode(pChildNode); // 检查内容 pChildNode = pRuleNode->GetElementChildByIndex(3); pChildNode->GetText(strValue); RuleConvertor(checkRule.nRuleType, strValue, checkRule.arrRuleContent); DestroyXMLNode(pChildNode); if (pRuleNode->GetElementCount() >= 4) { // 检查模型过滤 pChildNode = pRuleNode->GetElementChildByIndex(4); pChildNode->GetText(strValue); checkRule.dwMdlFilter = _wtoi(strValue); DestroyXMLNode(pChildNode); } arrCheckRuleList.Add(checkRule); } DestroyXMLNode(pRuleNode); } } else { AfxMessageBox(L"XML文件不匹配!"); bResult = FALSE; } DestroyXMLNode(pRootNode); } // 释放资源 Uninit(); return bResult; }