int CCrashDescReader::Load(CString sFileName) { TiXmlDocument doc; FILE* f = NULL; strconv_t strconv; if(m_bLoaded) return 1; // already loaded // Check that the file exists #if _MSC_VER<1400 f = _tfopen(sFileName, _T("rb")); #else _tfopen_s(&f, sFileName, _T("rb")); #endif if(f==NULL) return -1; // File can't be opened // Open XML document bool bLoaded = doc.LoadFile(f); if(!bLoaded) { fclose(f); return -2; // XML is corrupted } TiXmlHandle hDoc(&doc); TiXmlHandle hRoot = hDoc.FirstChild("CrashRpt").ToElement(); if(hRoot.ToElement()==NULL) { if(LoadXmlv10(hDoc)==0) { fclose(f); return 0; } return -3; // Invalid XML structure } // Get generator version const char* szCrashRptVersion = hRoot.ToElement()->Attribute("version"); if(szCrashRptVersion!=NULL) { m_dwGeneratorVersion = atoi(szCrashRptVersion); } // Get CrashGUID TiXmlHandle hCrashGUID = hRoot.ToElement()->FirstChild("CrashGUID"); if(hCrashGUID.ToElement()) { TiXmlText* pTextElem = hCrashGUID.FirstChild().Text(); if(pTextElem) { const char* text = pTextElem->Value(); if(text) m_sCrashGUID = strconv.utf82t(text); } } // Get AppName TiXmlHandle hAppName = hRoot.ToElement()->FirstChild("AppName"); if(hAppName.ToElement()) { TiXmlText* pTextElem = hAppName.FirstChild().Text(); if(pTextElem) { const char* text = pTextElem->Value(); if(text) m_sAppName = strconv.utf82t(text); } } // Get AppVersion TiXmlHandle hAppVersion = hRoot.ToElement()->FirstChild("AppVersion"); if(hAppVersion.ToElement()) { TiXmlText* pTextElem = hAppVersion.FirstChild().Text(); if(pTextElem) { const char* text = pTextElem->Value(); if(text) m_sAppVersion = strconv.utf82t(text); } } // Get ImageName TiXmlHandle hImageName = hRoot.ToElement()->FirstChild("ImageName"); if(hImageName.ToElement()) { TiXmlText* pTextElem = hImageName.FirstChild().Text(); if(pTextElem) { const char* text = pTextElem->Value(); if(text) m_sImageName = strconv.utf82t(text); } } // Get OperatingSystem TiXmlHandle hOperatingSystem = hRoot.ToElement()->FirstChild("OperatingSystem"); if(hOperatingSystem.ToElement()) { TiXmlText* pTextElem = hOperatingSystem.FirstChild().Text(); if(pTextElem) { const char* text = pTextElem->Value(); if(text) m_sOperatingSystem = strconv.utf82t(text); } } // Get GeoLocation TiXmlHandle hGeoLocation = hRoot.ToElement()->FirstChild("GeoLocation"); if(hGeoLocation.ToElement()) { TiXmlText* pTextElem = hGeoLocation.FirstChild().Text(); if(pTextElem) { const char* text = pTextElem->Value(); if(text) m_sGeoLocation = strconv.utf82t(text); } } // Get OSIs64Bit m_bOSIs64Bit = FALSE; TiXmlHandle hOSIs64Bit = hRoot.ToElement()->FirstChild("OSIs64Bit"); if(hOSIs64Bit.ToElement()) { TiXmlText* pTextElem = hOSIs64Bit.FirstChild().Text(); if(pTextElem) { const char* text = pTextElem->Value(); if(text) m_bOSIs64Bit = atoi(text); } } // Get SystemTimeUTC TiXmlHandle hSystemTimeUTC = hRoot.ToElement()->FirstChild("SystemTimeUTC"); if(hSystemTimeUTC.ToElement()) { TiXmlText* pTextElem = hSystemTimeUTC.FirstChild().Text(); if(pTextElem) { const char* text = pTextElem->Value(); if(text) m_sSystemTimeUTC = strconv.utf82t(text); } } // Get ExceptionType TiXmlHandle hExceptionType = hRoot.ToElement()->FirstChild("ExceptionType"); if(hExceptionType.ToElement()) { TiXmlText* pTextElem = hExceptionType.FirstChild().Text(); if(pTextElem) { const char* text = pTextElem->Value(); if(text) m_dwExceptionType = atoi(text); } } // Get UserEmail TiXmlHandle hUserEmail = hRoot.ToElement()->FirstChild("UserEmail"); if(hUserEmail.ToElement()) { TiXmlText* pTextElem = hUserEmail.FirstChild().Text(); if(pTextElem) { const char* text = pTextElem->Value(); if(text) m_sUserEmail = strconv.utf82t(text); } } // Get ProblemDecription TiXmlHandle hProblemDescription = hRoot.ToElement()->FirstChild("ProblemDescription"); if(hProblemDescription.ToElement()) { TiXmlText* pTextElem = hProblemDescription.FirstChild().Text(); if(pTextElem) { const char* text = pTextElem->Value(); if(text) m_sProblemDescription = strconv.utf82t(text); } } // Get ExceptionCode (for SEH exceptions only) if(m_dwExceptionType==CR_SEH_EXCEPTION) { TiXmlHandle hExceptionCode = hRoot.ToElement()->FirstChild("ExceptionCode"); if(hExceptionCode.ToElement()) { TiXmlText* pTextElem = hExceptionCode.FirstChild().Text(); if(pTextElem) { const char* text = pTextElem->Value(); if(text) m_dwExceptionCode = atoi(text); } } } // Get FPESubcode (for FPE exceptions only) if(m_dwExceptionType==CR_CPP_SIGFPE) { TiXmlHandle hFPESubcode = hRoot.ToElement()->FirstChild("FPESubcode"); if(hFPESubcode.ToElement()) { TiXmlText* pTextElem = hFPESubcode.FirstChild().Text(); if(pTextElem) { const char* text = pTextElem->Value(); if(text) m_dwFPESubcode = atoi(text); } } } // Get InvParamExpression, InvParamFunction, InvParamFile, InvParamLine // (for invalid parameter exceptions only) if(m_dwExceptionType==CR_CPP_INVALID_PARAMETER) { TiXmlHandle hInvParamExpression = hRoot.ToElement()->FirstChild("InvParamExpression"); if(hInvParamExpression.ToElement()) { TiXmlText* pTextElem = hInvParamExpression.FirstChild().Text(); if(pTextElem) { const char* text = pTextElem->Value(); if(text) m_sInvParamExpression = strconv.utf82t(text); } } TiXmlHandle hInvParamFunction = hRoot.ToElement()->FirstChild("InvParamFunction"); if(hInvParamFunction.ToElement()) { TiXmlText* pTextElem = hInvParamFunction.FirstChild().Text(); if(pTextElem) { const char* text = pTextElem->Value(); if(text) m_sInvParamFunction = strconv.utf82t(text); } } TiXmlHandle hInvParamFile = hRoot.ToElement()->FirstChild("InvParamFile"); if(hInvParamFile.ToElement()) { TiXmlText* pTextElem = hInvParamFile.FirstChild().Text(); if(pTextElem) { const char* text = pTextElem->Value(); if(text) m_sInvParamFile = strconv.utf82t(text); } } TiXmlHandle hInvParamLine = hRoot.ToElement()->FirstChild("InvParamLine"); if(hInvParamLine.ToElement()) { TiXmlText* pTextElem = hInvParamLine.FirstChild().Text(); if(pTextElem) { const char* text = pTextElem->Value(); if(text) m_dwInvParamLine = atoi(text); } } } // Get GUI resource count TiXmlHandle hGUIResourceCount = hRoot.ToElement()->FirstChild("GUIResourceCount"); if(hGUIResourceCount.ToElement()) { TiXmlText* pTextElem = hGUIResourceCount.FirstChild().Text(); if(pTextElem) { const char* text = pTextElem->Value(); if(text) m_sGUIResourceCount = strconv.utf82t(text); } } // Get open handle count TiXmlHandle hOpenHandleCount = hRoot.ToElement()->FirstChild("OpenHandleCount"); if(hOpenHandleCount.ToElement()) { TiXmlText* pTextElem = hOpenHandleCount.FirstChild().Text(); if(pTextElem) { const char* text = pTextElem->Value(); if(text) m_sOpenHandleCount = strconv.utf82t(text); } } // Get memory usage in KB TiXmlHandle hMemoryUsageKbytes = hRoot.ToElement()->FirstChild("MemoryUsageKbytes"); if(hMemoryUsageKbytes.ToElement()) { TiXmlText* pTextElem = hMemoryUsageKbytes.FirstChild().Text(); if(pTextElem) { const char* text = pTextElem->Value(); if(text) m_sMemoryUsageKbytes = strconv.utf82t(text); } } // Get file items list TiXmlHandle hFileList = hRoot.ToElement()->FirstChild("FileList"); if(!hFileList.ToElement()) { // This may work for reports generated by v1.2.1 hFileList = hRoot.ToElement()->FirstChild("FileItems"); } if(hFileList.ToElement()) { TiXmlHandle hFileItem = hFileList.ToElement()->FirstChild("FileItem"); while(hFileItem.ToElement()) { const char* szFileName = hFileItem.ToElement()->Attribute("name"); const char* szFileDescription = hFileItem.ToElement()->Attribute("description"); CString sFileName, sFileDescription; if(szFileName!=NULL) sFileName = strconv.utf82t(szFileName); if(szFileName!=NULL) sFileDescription = strconv.utf82t(szFileDescription); m_aFileItems[sFileName]=sFileDescription; hFileItem = hFileItem.ToElement()->NextSibling(); } } // Get custom property list TiXmlHandle hCustomProps = hRoot.ToElement()->FirstChild("CustomProps"); if(hCustomProps.ToElement()) { TiXmlHandle hProp = hCustomProps.ToElement()->FirstChild("Prop"); while(hProp.ToElement()) { const char* szName = hProp.ToElement()->Attribute("name"); const char* szValue = hProp.ToElement()->Attribute("value"); CString sName, sValue; if(szName!=NULL) sName = strconv.utf82t(szName); if(szValue!=NULL) sValue = strconv.utf82t(szValue); m_aCustomProps[sName]=sValue; hProp = hProp.ToElement()->NextSibling(); } } fclose(f); // OK m_bLoaded = true; return 0; }
int CCrashInfoReader::ParseCrashDescription(CString sFileName, BOOL bParseFileItems, CErrorReportInfo& eri) { strconv_t strconv; FILE* f = NULL; #if _MSC_VER<1400 f = _tfopen(sFileName, _T("rb")); #else _tfopen_s(&f, sFileName, _T("rb")); #endif if(f==NULL) return 1; TiXmlDocument doc; bool bOpen = doc.LoadFile(f); if(!bOpen) return 1; TiXmlHandle hRoot = doc.FirstChild("CrashRpt"); if(hRoot.ToElement()==NULL) { fclose(f); return 1; } { TiXmlHandle hCrashGUID = hRoot.FirstChild("CrashGUID"); if(hCrashGUID.ToElement()!=NULL) { if(hCrashGUID.FirstChild().ToText()!=NULL) { const char* szCrashGUID = hCrashGUID.FirstChild().ToText()->Value(); if(szCrashGUID!=NULL) eri.m_sCrashGUID = strconv.utf82t(szCrashGUID); } } } { TiXmlHandle hAppName = hRoot.FirstChild("AppName"); if(hAppName.ToElement()!=NULL) { const char* szAppName = hAppName.FirstChild().ToText()->Value(); if(szAppName!=NULL) eri.m_sAppName = strconv.utf82t(szAppName); } } { TiXmlHandle hAppVersion = hRoot.FirstChild("AppVersion"); if(hAppVersion.ToElement()!=NULL) { TiXmlText* pText = hAppVersion.FirstChild().ToText(); if(pText!=NULL) { const char* szAppVersion = pText->Value(); if(szAppVersion!=NULL) eri.m_sAppVersion = strconv.utf82t(szAppVersion); } } } { TiXmlHandle hImageName = hRoot.FirstChild("ImageName"); if(hImageName.ToElement()!=NULL) { TiXmlText* pText = hImageName.FirstChild().ToText(); if(pText!=NULL) { const char* szImageName = pText->Value(); if(szImageName!=NULL) eri.m_sImageName = strconv.utf82t(szImageName); } } } { TiXmlHandle hSystemTimeUTC = hRoot.FirstChild("SystemTimeUTC"); if(hSystemTimeUTC.ToElement()!=NULL) { TiXmlText* pText = hSystemTimeUTC.FirstChild().ToText(); if(pText!=NULL) { const char* szSystemTimeUTC = pText->Value(); if(szSystemTimeUTC!=NULL) eri.m_sSystemTimeUTC = strconv.utf82t(szSystemTimeUTC); } } } if(bParseFileItems) { // Get directory name CString sReportDir = sFileName; int pos = sFileName.ReverseFind('\\'); if(pos>=0) sReportDir = sFileName.Left(pos); if(sReportDir.Right(1)!=_T("\\")) sReportDir += _T("\\"); TiXmlHandle fl = hRoot.FirstChild("FileList"); if(fl.ToElement()==0) { fclose(f); return 1; } TiXmlHandle fi = fl.FirstChild("FileItem"); while(fi.ToElement()!=0) { const char* pszDestFile = fi.ToElement()->Attribute("name"); const char* pszDesc = fi.ToElement()->Attribute("description"); const char* pszOptional = fi.ToElement()->Attribute("optional"); if(pszDestFile!=NULL) { CString sDestFile = strconv.utf82t(pszDestFile); ERIFileItem item; item.m_sDestFile = sDestFile; item.m_sSrcFile = sReportDir + sDestFile; if(pszDesc) item.m_sDesc = strconv.utf82t(pszDesc); item.m_bMakeCopy = FALSE; if(pszOptional && strcmp(pszOptional, "1")==0) item.m_bAllowDelete = true; // Check that file really exists DWORD dwAttrs = GetFileAttributes(item.m_sSrcFile); if(dwAttrs!=INVALID_FILE_ATTRIBUTES && (dwAttrs&FILE_ATTRIBUTE_DIRECTORY)==0) { eri.m_FileItems[sDestFile] = item; } } fi = fi.ToElement()->NextSibling("FileItem"); } } fclose(f); return 0; }
BOOL CCrashInfoReader::RemoveFilesFromCrashReport(int nReport, std::vector<CString> FilesToRemove) { strconv_t strconv; TiXmlDocument doc; CString sFileName = m_Reports[nReport].m_sErrorReportDirName + _T("\\crashrpt.xml"); FILE* f = NULL; #if _MSC_VER<1400 f = _tfopen(sFileName, _T("rb")); #else _tfopen_s(&f, sFileName, _T("rb")); #endif if(f==NULL) { return FALSE; } bool bLoad = doc.LoadFile(f); fclose(f); if(!bLoad) { return FALSE; } TiXmlNode* root = doc.FirstChild("CrashRpt"); if(!root) { return FALSE; } TiXmlHandle hFileItems = root->FirstChild("FileList"); if(hFileItems.ToElement()==NULL) { hFileItems = new TiXmlElement("FileList"); root->LinkEndChild(hFileItems.ToNode()); } unsigned i; for(i=0; i<FilesToRemove.size(); i++) { std::map<CString, ERIFileItem>::iterator it = m_Reports[nReport].m_FileItems.find(FilesToRemove[i]); if(it==m_Reports[nReport].m_FileItems.end()) continue; // Such file item name does not exists, skip strconv_t strconv; TiXmlHandle hElem = hFileItems.ToElement()->FirstChild(strconv.t2a(FilesToRemove[i])); if(hElem.ToElement()!=NULL) hFileItems.ToElement()->RemoveChild(hElem.ToElement()); if(it->second.m_bMakeCopy) { Utility::RecycleFile(it->second.m_sSrcFile, TRUE); } m_Reports[nReport].m_FileItems.erase(it); } #if _MSC_VER<1400 f = _tfopen(sFileName, _T("w")); #else _tfopen_s(&f, sFileName, _T("w")); #endif if(f==NULL) return FALSE; bool bSave = doc.SaveFile(f); if(!bSave) return FALSE; fclose(f); return TRUE; }
BOOL CCrashInfoReader::AddFilesToCrashReport(int nReport, std::vector<ERIFileItem> FilesToAdd) { strconv_t strconv; TiXmlDocument doc; CString sFileName = m_Reports[nReport].m_sErrorReportDirName + _T("\\crashrpt.xml"); FILE* f = NULL; #if _MSC_VER<1400 f = _tfopen(sFileName, _T("rb")); #else _tfopen_s(&f, sFileName, _T("rb")); #endif if(f==NULL) { return FALSE; } bool bLoad = doc.LoadFile(f); fclose(f); if(!bLoad) { return FALSE; } TiXmlNode* root = doc.FirstChild("CrashRpt"); if(!root) { return FALSE; } TiXmlHandle hFileItems = root->FirstChild("FileList"); if(hFileItems.ToElement()==NULL) { hFileItems = new TiXmlElement("FileList"); root->LinkEndChild(hFileItems.ToNode()); } unsigned i; for(i=0; i<FilesToAdd.size(); i++) { if(m_Reports[0].m_FileItems.find(FilesToAdd[i].m_sDestFile)!=m_Reports[0].m_FileItems.end()) continue; // Such file item already exists, skip TiXmlHandle hFileItem = new TiXmlElement("FileItem"); hFileItem.ToElement()->SetAttribute("name", strconv.t2utf8(FilesToAdd[i].m_sDestFile)); hFileItem.ToElement()->SetAttribute("description", strconv.t2utf8(FilesToAdd[i].m_sDesc)); if(FilesToAdd[i].m_bAllowDelete) hFileItem.ToElement()->SetAttribute("optional", "1"); hFileItems.ToElement()->LinkEndChild(hFileItem.ToNode()); m_Reports[nReport].m_FileItems[FilesToAdd[i].m_sDestFile] = FilesToAdd[i]; if(FilesToAdd[i].m_bMakeCopy) { CString sDestPath = m_Reports[nReport].m_sErrorReportDirName + _T("\\") + FilesToAdd[i].m_sDestFile; CopyFile(FilesToAdd[i].m_sSrcFile, sDestPath, TRUE); m_Reports[nReport].m_FileItems[FilesToAdd[i].m_sDestFile].m_sSrcFile = sDestPath; } } #if _MSC_VER<1400 f = _tfopen(sFileName, _T("w")); #else _tfopen_s(&f, sFileName, _T("w")); #endif if(f==NULL) return FALSE; bool bSave = doc.SaveFile(f); if(!bSave) return FALSE; fclose(f); return TRUE; }
BOOL CCrashInfoReader::AddUserInfoToCrashDescriptionXML(CString sEmail, CString sDesc) { strconv_t strconv; TiXmlDocument doc; CString sFileName = m_Reports[0].m_sErrorReportDirName + _T("\\crashrpt.xml"); FILE* f = NULL; #if _MSC_VER<1400 f = _tfopen(sFileName, _T("rb")); #else _tfopen_s(&f, sFileName, _T("rb")); #endif if(f==NULL) return FALSE; bool bLoad = doc.LoadFile(f); fclose(f); if(!bLoad) { return FALSE; } TiXmlNode* root = doc.FirstChild("CrashRpt"); if(!root) { return FALSE; } // Write user e-mail TiXmlHandle hEmail = NULL; hEmail = root->FirstChild("UserEmail"); if(hEmail.ToElement()==NULL) { hEmail = new TiXmlElement("UserEmail"); root->LinkEndChild(hEmail.ToElement()); } TiXmlText* email_text = NULL; if(hEmail.FirstChild().ToText()!=NULL) { email_text = hEmail.FirstChild().ToText(); email_text->SetValue(strconv.w2utf8(sEmail)); } else { email_text = new TiXmlText(strconv.t2utf8(sEmail)); hEmail.ToElement()->LinkEndChild(email_text); } // Write problem description TiXmlHandle hDesc = NULL; hDesc = root->FirstChild("ProblemDescription"); if(hDesc.ToElement()==NULL) { hDesc = new TiXmlElement("ProblemDescription"); root->LinkEndChild(hDesc.ToElement()); } TiXmlText* desc_text = NULL; if(hDesc.FirstChild().ToText()!=NULL) { desc_text = hDesc.FirstChild().ToText(); desc_text->SetValue(strconv.w2utf8(sDesc)); } else { desc_text = new TiXmlText(strconv.t2utf8(sDesc)); hDesc.ToElement()->LinkEndChild(desc_text); } #if _MSC_VER<1400 f = _tfopen(sFileName, _T("w")); #else _tfopen_s(&f, sFileName, _T("w")); #endif if(f==NULL) return FALSE; bool bSave = doc.SaveFile(f); fclose(f); if(!bSave) return FALSE; return TRUE; }
bool sCentre::LoadCentreXML(TiXmlHandle hBrothel) { //no need to init this, we just created it TiXmlElement* pBrothel = hBrothel.ToElement(); if (pBrothel == 0) { return false; } if (pBrothel->Attribute("Name")) { m_Name = pBrothel->Attribute("Name"); } int tempInt = 0; std::string message = "Loading centre: "; message += m_Name; g_LogFile.write(message); pBrothel->QueryIntAttribute("id", &m_id); pBrothel->QueryIntAttribute("NumRooms", &tempInt); m_NumRooms = tempInt; tempInt = 0; pBrothel->QueryIntAttribute("MaxNumRooms", &tempInt); m_MaxNumRooms = tempInt; tempInt = 0; if (m_MaxNumRooms < 200) m_MaxNumRooms = 200; else if (m_MaxNumRooms > 600) m_MaxNumRooms = 600; pBrothel->QueryIntAttribute("Filthiness", &m_Filthiness); pBrothel->QueryIntAttribute("SecurityLevel", &m_SecurityLevel); // load variables for sex restrictions pBrothel->QueryValueAttribute<bool>("RestrictAnal", &m_RestrictAnal); pBrothel->QueryValueAttribute<bool>("RestrictBDSM", &m_RestrictBDSM); pBrothel->QueryValueAttribute<bool>("RestrictBeast", &m_RestrictBeast); pBrothel->QueryValueAttribute<bool>("RestrictFoot", &m_RestrictFoot); pBrothel->QueryValueAttribute<bool>("RestrictGroup", &m_RestrictGroup); pBrothel->QueryValueAttribute<bool>("RestrictHand", &m_RestrictHand); pBrothel->QueryValueAttribute<bool>("RestrictLesbian", &m_RestrictLesbian); pBrothel->QueryValueAttribute<bool>("RestrictNormal", &m_RestrictNormal); pBrothel->QueryValueAttribute<bool>("RestrictOral", &m_RestrictOral); pBrothel->QueryValueAttribute<bool>("RestrictStrip", &m_RestrictStrip); pBrothel->QueryValueAttribute<bool>("RestrictTitty", &m_RestrictTitty); pBrothel->QueryValueAttribute<unsigned short>("AdvertisingBudget", &m_AdvertisingBudget); pBrothel->QueryIntAttribute("AntiPregPotions", &m_AntiPregPotions); pBrothel->QueryIntAttribute("AntiPregUsed", &m_AntiPregUsed); pBrothel->QueryValueAttribute<bool>("KeepPotionsStocked", &m_KeepPotionsStocked); // Load girls m_NumGirls = 0; TiXmlElement* pGirls = pBrothel->FirstChildElement("Girls"); if (pGirls) { for (TiXmlElement* pGirl = pGirls->FirstChildElement("Girl"); pGirl != 0; pGirl = pGirl->NextSiblingElement("Girl"))// load each girl and add her { sGirl* girl = new sGirl(); bool success = girl->LoadGirlXML(TiXmlHandle(pGirl)); if (success == true) { girl->m_InCentre = true; AddGirl(girl); } else { delete girl; continue; } } } //commented out before the conversion to XML //building.load(ifs); return true; }