// RegDataItem.cpp: implementation of the CRegDataItem class. // ////////////////////////////////////////////////////////////////////// #include "RegDataItem.h" #include "RegFile.h" #include ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CRegDataItem::CRegDataItem() : m_DataLen(0), m_NameLen(0), m_pDataBuf(NULL), m_Type(0),m_bIsEmpty(true), m_bDontDeleteData(false) { } CRegDataItem::~CRegDataItem() { if (!m_bDontDeleteData) delete m_pDataBuf; // delete m_pName; } int CRegDataItem::CompareTo(const CRegDataItem &r) { if ((m_bIsEmpty) && (r.m_bIsEmpty)) return 0; else if ((m_bIsEmpty) && (!r.m_bIsEmpty)) return 2; else if ((!m_bIsEmpty) && (r.m_bIsEmpty)) return -1; else { int code = _tcscmp(m_Name, r.m_Name); if (code == 0) //names are the same, so compare item's data { if ((m_Type == r.m_Type) && (m_DataLen == r.m_DataLen) && (memcmp(m_pDataBuf, r.m_pDataBuf, m_DataLen) == 0)) return 0; else return 1; } else if (code > 0) return 2; else return -1; } } LPTSTR GetCopy(LPCTSTR str) { if (str == NULL) return NULL; int len = _tcsclen(str) + 1; LPTSTR temp = new TCHAR[len]; if (temp == NULL) { LOG0(LOG_ERROR,"Couldn't allocate buffer in GetCopy(LPCTSTR)"); return NULL; } else { _tcscpy(temp, str); return temp; } } void CRegDataItem::WriteToInfFile(CRegFile &file, bool bWriteValueData) { LPTSTR RootKeyName; LPTSTR SubKeyName; SplitString(m_KeyName, RootKeyName, SubKeyName, TEXT('\\')); file.WriteString(RootKeyName); file.WriteString(TEXT(",")); file.WriteString(SubKeyName); delete[] RootKeyName; delete[] SubKeyName; if (m_Name != NULL) { LPTSTR Name = GetQuotedString(m_Name); file.WriteString(TEXT(",")); file.WriteString(Name); delete[] Name; if (bWriteValueData) { file.WriteString(TEXT(",")); WriteDataString(file); } } file.WriteNewLine(); } LPTSTR CRegDataItem::GetQuotedString(LPCTSTR str) { int i=0, specialchars=0; TCHAR quote = TEXT('\"'); if (str == NULL) return NULL; while (str[i] != 0) { if (str[i] == quote) specialchars++; i++; } LPTSTR temp = new TCHAR[i+specialchars+3]; //include the chars of original string, // the escape characters needed for each specialchar // 1 char for the NULL // 2 chars for the quotes (") at the beginning and end of string int k=1; for (int j=0; j 0) { int len = _tcsclen(DataString); result = new TCHAR[len + 20]; _stprintf(result,TEXT("0x%08X,%s"), InfCode, DataString); } else { result = new TCHAR[20]; _stprintf(result,TEXT("0x%08X"), InfCode); } delete[] DataString; file.WriteString(result); delete[] result; } LPTSTR CRegDataItem::GetBinaryString() { if (m_DataLen == 0) return NULL; int len = m_DataLen*3+1; LPTSTR result = new TCHAR[len]; LPTSTR temp = result; for (DWORD i=0; i multi; LPCTSTR temp = (LPCTSTR)m_pData; multi.AddElement(GetQuotedString(temp)); int memneeded=0; for (DWORD i=0; i