示例#1
0
HRESULT ProfileUtils::ReadProfiles(CArray<ProfileInfo *, ProfileInfo *> &aProfileInformation) {
    HRESULT hr = S_OK;

    // Search for profiles in All Users application directory
    CString csAllUserApplicationData;
    hr = GetProfileDirectory(HKEY_LOCAL_MACHINE, csAllUserApplicationData, false);

    if (SUCCEEDED(hr)) {
        CString csAllUserApplicationDataFiles = csAllUserApplicationData + _T("\\*.lpp");

        WIN32_FIND_DATA ffd;
        HANDLE hFile = FindFirstFile((LPCTSTR)csAllUserApplicationDataFiles, &ffd);

        if (hFile != INVALID_HANDLE_VALUE) {             
            do {
                CString csFile = csAllUserApplicationData + _T("\\") + ffd.cFileName;
                ProfileInfo *pNewProfileInfo = new ProfileInfo(csFile);
                pNewProfileInfo->Read();
                pNewProfileInfo->SetCreatedByAdmin(true);
                aProfileInformation.Add(pNewProfileInfo);
            } while (FindNextFile(hFile, &ffd));
        } 
        FindClose(hFile);
    }

    // Search for profiles in user application directory
    CString csUserApplicationData;
    if (SUCCEEDED(hr)) {
        hr = GetProfileDirectory(HKEY_CURRENT_USER, csUserApplicationData, false);
    }

    if (SUCCEEDED(hr)) {
        CString csUserApplicationDataFiles = csUserApplicationData + _T("\\*.lpp");

        WIN32_FIND_DATA ffd;
        HANDLE hFile = FindFirstFile((LPCTSTR)csUserApplicationDataFiles, &ffd);

        if (hFile != INVALID_HANDLE_VALUE) {  
            do {
                CString csFile = csUserApplicationData + _T("\\") + ffd.cFileName;
                ProfileInfo *pNewProfileInfo = new ProfileInfo(csFile);
                pNewProfileInfo->Read();
                pNewProfileInfo->SetCreatedByAdmin(false);
                aProfileInformation.Add(pNewProfileInfo);
            } while (FindNextFile(hFile, &ffd));
        } 

        FindClose(hFile);
    }

    return hr;
}
示例#2
0
extern "C" int __declspec(dllexport) Load(void)
{
	mir_getLP(&pluginInfo);

	YAMN_STATUS = ID_STATUS_OFFLINE;

	//	we get the Miranda Root Path
	PathToAbsoluteT( _T("."), szMirandaDir);

	// retrieve the current profile name
	CallService(MS_DB_GETPROFILENAMET, (WPARAM)_countof(ProfileName), (LPARAM)ProfileName);	//not to pass entire array to fcn
	TCHAR *fc = _tcsrchr(ProfileName, '.');
	if ( fc != NULL ) *fc = 0;

	//	we get the user path where our yamn-account.book.ini is stored from mirandaboot.ini file
	GetProfileDirectory(UserDirectory, _countof(UserDirectory));

	// Enumerate all the code pages available for the System Locale
	EnumSystemCodePages(EnumSystemCodePagesProc, CP_INSTALLED);
	CodePageNamesSupp = new _tcptable[CPLENSUPP];
	for (int i = 0, k = 0; i < CPLENALL; i++) {
		if (CodePageNamesAll[i].isValid) {
			CodePageNamesSupp[k] = CodePageNamesAll[i];
			k++;
	}	}

	// Registering YAMN as protocol
	PROTOCOLDESCRIPTOR pd = { PROTOCOLDESCRIPTOR_V3_SIZE };
	pd.szName = YAMN_DBMODULE;
	pd.type = PROTOTYPE_VIRTUAL;
	Proto_RegisterModule(&pd);

	InitializeCriticalSection(&AccountStatusCS);
	InitializeCriticalSection(&FileWritingCS);
	InitializeCriticalSection(&PluginRegCS);

	if (NULL == (NoWriterEV = CreateEvent(NULL, TRUE, TRUE, NULL)))
		return 1;
	if (NULL == (WriteToFileEV = CreateEvent(NULL, FALSE, FALSE, NULL)))
		return 1;
	if (NULL == (ExitEV = CreateEvent(NULL, TRUE, FALSE, NULL)))
		return 1;

	PosX = db_get_dw(NULL, YAMN_DBMODULE, YAMN_DBPOSX, 0);
	PosY = db_get_dw(NULL, YAMN_DBMODULE, YAMN_DBPOSY, 0);
	SizeX = db_get_dw(NULL, YAMN_DBMODULE, YAMN_DBSIZEX, 800);
	SizeY = db_get_dw(NULL, YAMN_DBMODULE, YAMN_DBSIZEY, 200);

	HeadPosX = db_get_dw(NULL, YAMN_DBMODULE, YAMN_DBMSGPOSX, 0);
	HeadPosY = db_get_dw(NULL, YAMN_DBMODULE, YAMN_DBMSGPOSY, 0);
	HeadSizeX = db_get_dw(NULL, YAMN_DBMODULE, YAMN_DBMSGSIZEX, 690);
	HeadSizeY = db_get_dw(NULL, YAMN_DBMODULE, YAMN_DBMSGSIZEY, 300);
	HeadSplitPos = db_get_w(NULL, YAMN_DBMODULE, YAMN_DBMSGPOSSPLIT, 250);

	optDateTime = db_get_b(NULL, YAMN_DBMODULE, YAMN_DBTIMEOPTIONS, optDateTime);

	// Create new window queues for broadcast messages
	YAMNVar.MessageWnds = WindowList_Create();
	YAMNVar.NewMailAccountWnd = WindowList_Create();
	YAMNVar.Shutdown = FALSE;

	hCurSplitNS = LoadCursor(NULL, IDC_SIZENS);
	hCurSplitWE = LoadCursor(NULL, IDC_SIZEWE);

#ifdef _DEBUG
	InitDebug();
#endif

	CreateServiceFunctions();

	SkinAddNewSoundEx(YAMN_NEWMAILSOUND, YAMN_DBMODULE, YAMN_NEWMAILSNDDESC);
	SkinAddNewSoundEx(YAMN_CONNECTFAILSOUND, YAMN_DBMODULE, YAMN_CONNECTFAILSNDDESC);

	HookEvents();

	LoadIcons();
	LoadPlugins();

	HOTKEYDESC hkd = {0};
	hkd.cbSize = sizeof(hkd);
	hkd.pszName = "YAMN_hotkey";
	hkd.pszService = MS_YAMN_FORCECHECK;
	hkd.pszSection = YAMN_DBMODULE;
	hkd.pszDescription = LPGEN("Check mail");
	hkd.DefHotKey = HOTKEYCODE(HOTKEYF_CONTROL, VK_F11);
	Hotkey_Register(&hkd);

	//Create thread that will be executed every second
	if (!(SecTimer = SetTimer(NULL, 0, 1000, TimerProc)))
		return 1;

	return 0;
}
INT_PTR CALLBACK SelectDbDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam)
{
	INT_PTR bReturn;
	if ( DoMyControlProcessing( hdlg, message, wParam, lParam, &bReturn ))
		return bReturn;

	switch ( message ) {
		case WM_INITDIALOG:
		{
			TCHAR szMirandaPath[MAX_PATH];
			szMirandaPath[ 0 ] = 0;
			{	HIMAGELIST hIml;
				hIml=ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
					(IsWinVerXPPlus() ? ILC_COLOR32 : ILC_COLOR16) | ILC_MASK, 3, 3);
				ImageList_AddIcon(hIml,LoadIcon(hInst,MAKEINTRESOURCE(IDI_PROFILEGREEN)));
				ImageList_AddIcon(hIml,LoadIcon(hInst,MAKEINTRESOURCE(IDI_PROFILEYELLOW)));
				ImageList_AddIcon(hIml,LoadIcon(hInst,MAKEINTRESOURCE(IDI_PROFILERED)));
				ImageList_AddIcon(hIml,LoadIcon(hInst,MAKEINTRESOURCE(IDI_BAD)));
				ListView_SetImageList(GetDlgItem(hdlg,IDC_DBLIST),hIml,LVSIL_SMALL);
			}
			ListView_SetExtendedListViewStyleEx(GetDlgItem(hdlg,IDC_DBLIST),LVS_EX_FULLROWSELECT,LVS_EX_FULLROWSELECT);
			{	LV_COLUMN lvc;
				lvc.mask = LVCF_WIDTH | LVCF_FMT | LVCF_TEXT;
				lvc.cx = 205;
				lvc.fmt = LVCFMT_LEFT;
				lvc.pszText = TranslateT("Database");
				ListView_InsertColumn( GetDlgItem(hdlg,IDC_DBLIST), 0, &lvc );
				lvc.cx = 68;
				lvc.fmt = LVCFMT_RIGHT;
				lvc.pszText = TranslateT("Total size");
				ListView_InsertColumn(GetDlgItem(hdlg,IDC_DBLIST), 1, &lvc );
				lvc.pszText = TranslateT("Wasted");
				ListView_InsertColumn(GetDlgItem(hdlg,IDC_DBLIST), 2, &lvc );
			}
			{
				TCHAR *str2;
				GetModuleFileName(NULL,szMirandaPath,SIZEOF(szMirandaPath));
				str2 = _tcsrchr(szMirandaPath,'\\');
				if( str2 != NULL )
					*str2=0;
			}
			{
				int i = 0;
				HKEY hKey;
				TCHAR szProfileDir[MAX_PATH];
				DWORD cbData = SIZEOF(szMirandaPath);
				TCHAR szMirandaProfiles[MAX_PATH];

				_tcscpy(szMirandaProfiles, szMirandaPath);
				_tcscat(szMirandaProfiles, _T("\\Profiles"));
				GetProfileDirectory(szMirandaPath,szProfileDir,SIZEOF(szProfileDir));

				// search in profile dir (using ini file)
				if( lstrcmpi(szProfileDir,szMirandaProfiles) )
					FindAdd(hdlg, szProfileDir, _T("[ini]\\"));

				FindAdd(hdlg, szMirandaProfiles, _T("[prf]\\"));
				// search in current dir (as DBTOOL)
        FindAdd(hdlg, szMirandaPath, _T("[ . ]\\"));

				// search in profile dir (using registry path + ini file)
				if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\miranda32.exe"),0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS) {
					if(RegQueryValueEx(hKey,_T("Path"),NULL,NULL,(PBYTE)szMirandaPath,&cbData) == ERROR_SUCCESS) {
						if( lstrcmp(szProfileDir,szMirandaPath) ) {
							GetProfileDirectory(szMirandaPath,szProfileDir,SIZEOF(szProfileDir));
							FindAdd(hdlg, szProfileDir, _T("[reg]\\"));
						}
					}
					RegCloseKey(hKey);
				}
				// select
				if ( opts.filename[0] )
					i = AddDatabaseToList( GetDlgItem( hdlg, IDC_DBLIST ), opts.filename, _T("") );
				if ( i == -1 )
					i = 0;
				ListView_SetItemState( GetDlgItem(hdlg,IDC_DBLIST), i, LVIS_SELECTED, LVIS_SELECTED );
			}
			if ( opts.hFile != NULL && opts.hFile != INVALID_HANDLE_VALUE ) {
				CloseHandle( opts.hFile );
				opts.hFile = NULL;
			}
			TranslateDialog( hdlg );
			return TRUE;
		}

		case WZN_PAGECHANGING:
			GetDlgItemText( hdlg, IDC_FILE, opts.filename, SIZEOF(opts.filename));
			break;

		case WM_COMMAND:
			switch(LOWORD(wParam)) {
				case IDC_FILE:
					if(HIWORD(wParam)==EN_CHANGE)
						EnableWindow(GetDlgItem(GetParent(hdlg),IDOK),GetWindowTextLength(GetDlgItem(hdlg,IDC_FILE)));
					break;
				case IDC_OTHER:
				{	OPENFILENAME ofn={0};
					TCHAR str[MAX_PATH];

					// _T("Miranda Databases (*.dat)\0*.DAT\0All Files (*)\0*\0");
					TCHAR *filter, *tmp, *tmp1, *tmp2;
					tmp1 = TranslateT("Miranda Databases (*.dat)");
					tmp2 = TranslateT("All Files");
					filter = tmp = (TCHAR*)_alloca((_tcslen(tmp1)+_tcslen(tmp2)+11)*sizeof(TCHAR));
					tmp = addstring(tmp, tmp1);
					tmp = addstring(tmp, _T("*.DAT"));
					tmp = addstring(tmp, tmp2);
					tmp = addstring(tmp, _T("*"));
					*tmp = 0;

					GetDlgItemText( hdlg, IDC_FILE, str, SIZEOF( str ));
					ofn.lStructSize = sizeof(ofn);
					ofn.hwndOwner = hdlg;
					ofn.hInstance = NULL;
					ofn.lpstrFilter = filter;
					ofn.lpstrDefExt = _T("dat");
					ofn.lpstrFile = str;
					ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
					ofn.nMaxFile = SIZEOF(str);
					ofn.nMaxFileTitle = MAX_PATH;
					if ( GetOpenFileName( &ofn )) {
						int i;
						i = AddDatabaseToList( GetDlgItem(hdlg,IDC_DBLIST), str, _T("") );
						if ( i == -1 )
							i=0;
						ListView_SetItemState( GetDlgItem(hdlg,IDC_DBLIST), i, LVIS_SELECTED, LVIS_SELECTED );
					}
					break;
				}
				case IDC_BACK:
					SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_WELCOME,(LPARAM)WelcomeDlgProc);
					break;
				case IDOK:
					opts.hFile = CreateFile( opts.filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL );
					if ( opts.hFile == INVALID_HANDLE_VALUE ) {
						opts.hFile = NULL;
						opts.error = GetLastError();
						SendMessage( GetParent(hdlg), WZM_GOTOPAGE, IDD_OPENERROR, ( LPARAM )OpenErrorDlgProc );
					}
					else SendMessage( GetParent(hdlg), WZM_GOTOPAGE, IDD_FILEACCESS, (LPARAM)FileAccessDlgProc );
					break;
			}
			break;
		case WM_NOTIFY:
			switch(((LPNMHDR)lParam)->idFrom) {
				case IDC_DBLIST:
					switch(((LPNMLISTVIEW)lParam)->hdr.code) {
						case LVN_ITEMCHANGED:
						{	LV_ITEM lvi;
							lvi.iItem=ListView_GetNextItem(GetDlgItem(hdlg,IDC_DBLIST),-1,LVNI_SELECTED);
							if(lvi.iItem==-1) break;
							lvi.mask=LVIF_PARAM;
							ListView_GetItem(GetDlgItem(hdlg,IDC_DBLIST),&lvi);
							SetDlgItemText(hdlg,IDC_FILE,(TCHAR*)lvi.lParam);
							SendMessage(hdlg,WM_COMMAND,MAKEWPARAM(IDC_FILE,EN_CHANGE),(LPARAM)GetDlgItem(hdlg,IDC_FILE));
							break;
						}
					}
					break;
			}
			break;
		case WM_DESTROY:
			{	LV_ITEM lvi;
				lvi.mask=LVIF_PARAM;
				for(lvi.iItem=ListView_GetItemCount(GetDlgItem(hdlg,IDC_DBLIST))-1;lvi.iItem>=0;lvi.iItem--) {
					ListView_GetItem(GetDlgItem(hdlg,IDC_DBLIST),&lvi);
					free((char*)lvi.lParam);
				}
			}
			break;
	}
	return FALSE;
}