/**
 * name:	fromIni
 * class:	CExImContactBase
 * desc:	get contact information from a row of a ini file
 * param:	row	- the rows data
 * return:	TRUE if successful or FALSE otherwise
 **/
BYTE CExImContactBase::fromIni(LPSTR& row)
{
	LPSTR p1, p2 = NULL;
	LPSTR pszUIDValue, pszUIDSetting, pszProto = NULL;
	LPSTR pszBuf = &row[0];
	size_t cchBuf = strlen(row);

	MIR_FREE(_pszProtoOld);
	MIR_FREE(_pszProto);
	MIR_FREE(_pszAMPro);
	MIR_FREE(_pszNick);
	MIR_FREE(_pszDisp);
	MIR_FREE(_pszGroup);
	MIR_FREE(_pszUIDKey);
	db_free(&_dbvUID);
	ZeroMemory(&_dbvUID, sizeof(DBVARIANT));
	_dbvUIDHash = 0;

	// read uid value
	if (cchBuf > 10 && (p1 = mir_strrchr(pszBuf, '*{')) && (p2 = mir_strchr(p1, '}*')) && p1 + 2 < p2) {
		pszUIDValue = p1 + 1;
		*p1 = *(p2 - 1) = 0;

		// insulate the uid setting from buffer pointer
		if (cchBuf > 0 && (p1 = mir_strrchr(pszBuf, '*<')) && (p2 = mir_strchr(p1, '>*')) && p1 + 2 < p2) {
			pszUIDSetting = p1 + 1;
			*p1 = *(p2 - 1) = 0;

			// insulate the protocol name from buffer pointer
			if (cchBuf > 0 && (p1 = mir_strrchr(pszBuf, '*(')) && (p2 = mir_strchr(p1, ')*')) && p1 + 2 < p2) {
				pszProto = p1 + 1;
				*(--p1) = *(p2 - 1) = 0;

				// DBVT_DWORD
				if (strspn(pszUIDValue, "0123456789") == mir_strlen(pszUIDValue)) {
					_dbvUID.dVal = _atoi64(pszUIDValue);
					_dbvUID.type = DBVT_DWORD;
				}
				else {
				// DBVT_UTF8
					_dbvUID.pszVal = mir_strdup(pszUIDValue);
					_dbvUID.type = DBVT_UTF8;
				}
				_pszUIDKey = mir_strdup(pszUIDSetting);
				_pszProto = mir_strdup(pszProto);
			} //end insulate the protocol name from buffer pointer
		} //end insulate the uid setting from buffer pointer
	} //end read uid value

	// create valid nickname
	_pszNick = mir_strdup(pszBuf);
	size_t i = strlen(_pszNick)-1;
	while (i > 0 && (_pszNick[i] == ' ' || _pszNick[i] == '\t')) {
		_pszNick[i] = 0;
		i--;
	}
	// finally try to find contact in contact list
	findHandle();
	return FALSE;
}
Пример #2
0
/**
 * name:	ItemLabel
 * class:	CPsTreeItem
 * desc:	returns the label for a given item. The returned value must be freed after use!
 * param:	pszName		- uniquely identifiing string for a propertypage encoded with utf8 (e.g.: {group\item})
 * return:	Label in a newly allocated piece of memory
 **/
int CPsTreeItem::ItemLabel(const BYTE bReadDBValue)
{
	DBVARIANT dbv;

	// clear existing
	if (_ptszLabel)
		mir_free(_ptszLabel);

	// try to get custom label from database
	if (!bReadDBValue || DB::Setting::GetTString(NULL, MODNAME, GlobalPropertyKey(SET_ITEM_LABEL), &dbv) || (_ptszLabel = dbv.ptszVal) == NULL) {
		// extract the name
		LPSTR pszName = mir_strrchr(_pszName, '\\');
		if (pszName && pszName[1])
			pszName++;
		else
			pszName = _pszName;

		LPTSTR ptszLabel = mir_utf8decodeT(pszName);
		if (ptszLabel) {
			_ptszLabel = mir_tstrdup(TranslateTS(ptszLabel));
			mir_free(ptszLabel);
		}
	}
	// return nonezero if label is invalid
	return _ptszLabel == NULL;
}
Пример #3
0
/**
 * name:	ParentItemName()
 * class:	CPsTreeItem
 * desc:	returns the unique name for the parent item
 * param:	nothing
 * return:	length of group name
 **/
LPSTR CPsTreeItem::ParentItemName()
{
	// try to read the parent item from the database
	DBVARIANT dbv;
	if (!DB::Setting::GetAString(NULL, MODNAME, PropertyKey(SET_ITEM_GROUP), &dbv))
		return dbv.pszVal;

	const CHAR* p = mir_strrchr(_pszName, '\\');
	if (p) {
		int cchGroup = p - _pszName + 1;
		return mir_strncpy((LPSTR)mir_alloc(cchGroup), _pszName, cchGroup);
	}
	return NULL;
}
/**
 * name:		SaveInitialDir
 * desc:		save the last vCard directory from database
 *				pszInitialDir	- buffer to store the initial dir to (size must be MAX_PATH)
 * return:		nothing
 **/
static void SaveInitialDir(LPSTR pszInitialDir)
{
	CHAR szRelative[MAX_PATH];
	LPSTR p;

	if (p = mir_strrchr(pszInitialDir, '\\')) {
		*p = 0;
		if ( PathToRelative(pszInitialDir, szRelative))
			db_set_s(0, MODNAME, "vCardPath", szRelative);
		else
			db_set_s(0, MODNAME, "vCardPath", pszInitialDir);
		*p = '\\';
	}	
}
/**
 * This function maps the current users registry to a dummy key and
 * changes the policy hive which is responsible for the places to be displayed,
 * so the desired places are visible.
 *
 * @param		nothing
 * @return		nothing
 **/
static void InitAlteredPlacesBar()
{
	HKEY hkMiranda;
	LONG result;

	// create or open temporary hive for miranda specific places
	result = RegCreateKey(HKEY_CURRENT_USER, HKEY_MIRANDA_PLACESBAR, &hkMiranda);
	if (SUCCEEDED(result)) 
	{
		HKEY hkPlacesBar;

		// map the current users registry
		RegOverridePredefKey(HKEY_CURRENT_USER, hkMiranda);
		// open the policy key
		result = RegCreateKey(HKEY_CURRENT_USER, HKEY_WINPOL_PLACESBAR, &hkPlacesBar);
		// install the places bar
		if (SUCCEEDED(result)) 
		{
			DWORD dwFolderID;
			LPSTR p;
			CHAR szMirandaPath[MAX_PATH];
			CHAR szProfilePath[MAX_PATH];

			// default places: Desktop, My Documents, My Computer
			dwFolderID = 0;	 RegSetValueEx(hkPlacesBar, _T("Place0"), 0, REG_DWORD, (PBYTE)&dwFolderID, sizeof(DWORD));
			dwFolderID = 5;	RegSetValueEx(hkPlacesBar, _T("Place1"), 0, REG_DWORD, (PBYTE)&dwFolderID, sizeof(DWORD));
			dwFolderID = 17; RegSetValueEx(hkPlacesBar, _T("Place2"), 0, REG_DWORD, (PBYTE)&dwFolderID, sizeof(DWORD));

			// Miranda's installation path
			GetModuleFileNameA(GetModuleHandle(NULL), szMirandaPath, SIZEOF(szMirandaPath)); 
			p = mir_strrchr(szMirandaPath, '\\');
			if (p) 
			{
				RegSetValueExA(hkPlacesBar, "Place3", 0, REG_SZ, (PBYTE)szMirandaPath, (p - szMirandaPath) + 1);
			}

			// Miranda's profile path
			if (!CallService(MS_DB_GETPROFILEPATH, SIZEOF(szProfilePath), (LPARAM)szProfilePath))
			{
				// only add if different from profile path
				RegSetValueExA(hkPlacesBar, "Place4", 0, REG_SZ, (PBYTE)szProfilePath, (DWORD)strlen(szProfilePath) + 1);
			}

			RegCloseKey(hkPlacesBar);
		}
		RegCloseKey(hkMiranda);
	}
}