예제 #1
0
int LoadDatabaseModule(void)
{
	TCHAR szProfile[MAX_PATH];
	PathToAbsoluteT(_T("."), szProfile);
	_tchdir(szProfile);
	szProfile[0] = 0;

	LoadDatabaseServices();

	// find out which profile to load
	if (!getProfile(szProfile, SIZEOF(szProfile)))
		return 1;

	EnsureCheckerLoaded(false); // unload dbchecker

	if (arDbPlugins.getCount() == 0) {
		TCHAR buf[256];
		TCHAR* p = _tcsrchr(szProfile, '\\');
		mir_sntprintf(buf, SIZEOF(buf), TranslateT("Miranda is unable to open '%s' because you do not have any profile plugins installed.\nYou need to install dbx_mmap.dll"), p ? ++p : szProfile);
		MessageBox(0, buf, TranslateT("No profile support installed!"), MB_OK | MB_ICONERROR);
	}

	// find a driver to support the given profile
	bool retry;
	int rc;
	do {
		retry = false;
		if ( _taccess(szProfile, 0) && shouldAutoCreate(szProfile))
			rc = tryCreateDatabase(szProfile);
		else
			rc = tryOpenDatabase(szProfile);

		if (rc > 0) {
			// if there were drivers but they all failed cos the file is locked, try and find the miranda which locked it
			if (fileExist(szProfile)) {
				// file isn't locked, just no driver could open it.
				TCHAR buf[256];
				TCHAR* p = _tcsrchr(szProfile, '\\');
				mir_sntprintf(buf, SIZEOF(buf), TranslateT("Miranda was unable to open '%s', it's in an unknown format.\nThis profile might also be damaged, please run DbChecker which should be installed."), p ? ++p : szProfile);
				MessageBox(0, buf, TranslateT("Miranda can't understand that profile"), MB_OK | MB_ICONERROR);
			}
			else if (!FindMirandaForProfile(szProfile)) {
				TCHAR buf[256];
				TCHAR* p = _tcsrchr(szProfile, '\\');
				mir_sntprintf(buf, SIZEOF(buf), TranslateT("Miranda was unable to open '%s'\nIt's inaccessible or used by other application or Miranda instance"), p ? ++p : szProfile);
				retry = MessageBox(0, buf, TranslateT("Miranda can't open that profile"), MB_RETRYCANCEL | MB_ICONERROR) == IDRETRY;
			}
		}
	}
		while (retry);

	if (rc == ERROR_SUCCESS) {
		InitIni();
		return 0;
	}

	return rc;
}
예제 #2
0
// returns 1 if a default profile should be selected instead of showing the manager.
static int getProfileAutoRun(TCHAR * szProfile)
{
	TCHAR Mgr[32];
	GetPrivateProfileString(_T("Database"), _T("ShowProfileMgr"), _T(""), Mgr, SIZEOF(Mgr), mirandabootini);
	if (_tcsicmp(Mgr, _T("never")))
		return 0;

	return fileExist(szProfile) || shouldAutoCreate(szProfile);
}
예제 #3
0
int LoadDatabaseModule(void)
{
	TCHAR szProfile[MAX_PATH];
	pathToAbsoluteT(_T("."), szProfile, NULL);
	_tchdir(szProfile);
	szProfile[0] = 0;

	// load the older basic services of the db
	InitUtils();

	// find out which profile to load
	if ( !getProfile( szProfile, SIZEOF( szProfile )))
		return 1;

	PLUGIN_DB_ENUM dbe;
	dbe.cbSize = sizeof(PLUGIN_DB_ENUM);
	dbe.lParam = (LPARAM)szProfile;

	if ( _taccess(szProfile, 0) && shouldAutoCreate( szProfile ))
		dbe.pfnEnumCallback=( int(*) (const char*,void*,LPARAM) )FindDbPluginAutoCreate;
	else
		dbe.pfnEnumCallback=( int(*) (const char*,void*,LPARAM) )FindDbPluginForProfile;

	// find a driver to support the given profile
	int rc = CallService(MS_PLUGINS_ENUMDBPLUGINS, 0, (LPARAM)&dbe);
	switch ( rc ) {
	case -1: {
		// no plugins at all
		TCHAR buf[256];
		TCHAR* p = _tcsrchr(szProfile,'\\');
		mir_sntprintf(buf,SIZEOF(buf),TranslateT("Miranda is unable to open '%s' because you do not have any profile plugins installed.\nYou need to install dbx_3x.dll or equivalent."), p ? ++p : szProfile );
		MessageBox(0,buf,TranslateT("No profile support installed!"),MB_OK | MB_ICONERROR);
		break;
	}
	case 1:
		// if there were drivers but they all failed cos the file is locked, try and find the miranda which locked it
		if (fileExist(szProfile)) {
			// file isn't locked, just no driver could open it.
			TCHAR buf[256];
			TCHAR* p = _tcsrchr(szProfile,'\\');
			mir_sntprintf(buf,SIZEOF(buf),TranslateT("Miranda was unable to open '%s', it's in an unknown format.\nThis profile might also be damaged, please run DB-tool which should be installed."), p ? ++p : szProfile);
			MessageBox(0,buf,TranslateT("Miranda can't understand that profile"),MB_OK | MB_ICONERROR);
		}
		else if (!FindMirandaForProfile(szProfile)) {
			TCHAR buf[256];
			TCHAR* p = _tcsrchr(szProfile,'\\');
			mir_sntprintf(buf,SIZEOF(buf),TranslateT("Miranda was unable to open '%s'\nIt's inaccessible or used by other application or Miranda instance"), p ? ++p : szProfile);
			MessageBox(0,buf,TranslateT("Miranda can't open that profile"),MB_OK | MB_ICONERROR);
		}
		break;
	}
	return (rc != 0);
}
예제 #4
0
// returns 1 if a single profile (full path) is found within the profile dir
static int getProfile1(TCHAR * szProfile, size_t cch, TCHAR * profiledir, BOOL * noProfiles)
{
	unsigned int found = 0;

	if (IsInsideRootDir(profiledir, false))
		moveProfileDirProfiles(profiledir);
	moveProfileDirProfiles(profiledir, FALSE);

	bool nodprof = szProfile[0] == 0;
	bool reqfd = !nodprof && (_taccess(szProfile, 0) == 0 || shouldAutoCreate(szProfile));
	bool shpm = showProfileManager();

	if (reqfd)
		found++;

	if (shpm || !reqfd) {
		TCHAR searchspec[MAX_PATH];
		mir_sntprintf(searchspec, SIZEOF(searchspec), _T("%s\\*.*"), profiledir);

		WIN32_FIND_DATA ffd;
		HANDLE hFind = FindFirstFile(searchspec, &ffd);
		if (hFind != INVALID_HANDLE_VALUE) {
			do {
				// make sure the first hit is actually a *.dat file
				if ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && _tcscmp(ffd.cFileName, _T(".")) && _tcscmp(ffd.cFileName, _T("..")))  {
					TCHAR newProfile[MAX_PATH];
					mir_sntprintf(newProfile, MAX_PATH, _T("%s\\%s\\%s.dat"), profiledir, ffd.cFileName, ffd.cFileName);
					if (_taccess(newProfile, 0) == 0)
						if (++found == 1 && nodprof)
							_tcscpy(szProfile, newProfile);
				}
			}
				while (FindNextFile(hFind, &ffd));

			FindClose(hFind);
		}
		reqfd = !shpm && found == 1 && nodprof;
	}

	if ( noProfiles )
		*noProfiles = found == 0;

	if ( nodprof && !reqfd )
		szProfile[0] = 0;

	return reqfd;
}
예제 #5
0
    virtual void OnInitDialog()
    {
        // what, no plugins?!
        if (arDbPlugins.getCount() == 0) {
            m_driverList.Enable(false);
            m_profileName.Enable(false);
            ShowWindow(m_warning.GetHwnd(), TRUE);
        }
        else {
            for (int i = 0; i < arDbPlugins.getCount(); i++) {
                DATABASELINK *p = arDbPlugins[i];
                m_driverList.AddString(TranslateTS(p->szFullName), (LPARAM)p);
            }
        }

        // default item
        m_driverList.SetCurSel(0);

        // subclass the profile name box
        mir_subclassWindow(m_profileName.GetHwnd(), ProfileNameValidate);

        // decide if there is a default profile name given in the INI and if it should be used
        if (m_pd->noProfiles || (shouldAutoCreate(m_pd->ptszProfile) && _taccess(m_pd->ptszProfile, 0))) {
            TCHAR *profile = _tcsrchr(m_pd->ptszProfile, '\\');
            if (profile) ++profile;
            else profile = m_pd->ptszProfile;

            TCHAR *p = _tcsrchr(profile, '.');
            TCHAR c = 0;
            if (p) {
                c = *p;
                *p = 0;
            }

            m_profileName.SetText(profile);
            if (c) *p = c;
        }

        // focus on the textbox
        PostMessage(m_hwnd, WM_FOCUSTEXTBOX, 0, 0);
    }
예제 #6
0
	virtual void OnInitDialog()
	{
		SendMessage(m_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadImage(g_hInst, MAKEINTRESOURCE(IDI_DETAILSLOGO), IMAGE_ICON, g_iIconSX, g_iIconSY, 0));
		SendMessage(m_hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadImage(g_hInst, MAKEINTRESOURCE(IDI_DETAILSLOGO), IMAGE_ICON, g_iIconX, g_iIconY, 0));

		if (m_pd->noProfiles || shouldAutoCreate(m_pd->ptszProfile))
			m_tab.ActivatePage(1);

		// service mode combobox
		if (servicePlugins.getCount() == 0) {
			ShowWindow(m_warning.GetHwnd(), FALSE);
			ShowWindow(m_servicePlugs.GetHwnd(), FALSE);
		}
		else {
			m_servicePlugs.AddStringA("", -1);
			m_servicePlugs.SetCurSel(0);

			for (int i = 0; i < servicePlugins.getCount(); i++) {
				pluginEntry *p = servicePlugins[i];
				m_servicePlugs.AddString(TranslateTS(p->pluginname), i);
			}
		}
	}
예제 #7
0
static INT_PTR CALLBACK DlgProfileManager(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	DetailsData *dat = (DetailsData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		{
			DlgProfData *prof = (struct DlgProfData*)lParam;
			PROPSHEETHEADER *psh = prof->psh;
			SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_DETAILSLOGO), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0));
			SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_DETAILSLOGO), IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0));
			dat = (DetailsData*)mir_alloc(sizeof(DetailsData));
			dat->prof = prof;
			prof->hwndOK = GetDlgItem(hwndDlg, IDOK);
			prof->hwndSM = GetDlgItem(hwndDlg, IDC_SM_COMBO);
			EnableWindow(prof->hwndOK, FALSE);
			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);

			TCHAR buf[512];
			mir_sntprintf(buf, SIZEOF(buf), _T("%s\n%s"), TranslateT("Miranda NG profile manager"), TranslateT("Manage your Miranda NG profile"));
			SetDlgItemText(hwndDlg, IDC_NAME, buf);

			dat->currentPage = 0;
			dat->pageCount = psh->nPages;
			dat->opd = (DetailsPageData*)mir_calloc(sizeof(DetailsPageData)*dat->pageCount);
			OPTIONSDIALOGPAGE *odp = (OPTIONSDIALOGPAGE*)psh->ppsp;

			TCITEM tci;
			tci.mask = TCIF_TEXT;
			for (int i = 0; i < dat->pageCount; i++) {
				dat->opd[i].pTemplate = (DLGTEMPLATE *)LockResource(LoadResource(odp[i].hInstance, FindResourceA(odp[i].hInstance, odp[i].pszTemplate, MAKEINTRESOURCEA(5))));
				dat->opd[i].dlgProc = odp[i].pfnDlgProc;
				dat->opd[i].hInst = odp[i].hInstance;
				dat->opd[i].hwnd = NULL;
				dat->opd[i].changed = 0;
				tci.pszText = (TCHAR*)odp[i].ptszTitle;
				if (dat->prof->pd->noProfiles || shouldAutoCreate(dat->prof->pd->szProfile))
					dat->currentPage = 1;
				TabCtrl_InsertItem(GetDlgItem(hwndDlg, IDC_TABS), i, &tci);
			}

			GetWindowRect(GetDlgItem(hwndDlg, IDC_TABS), &dat->rcDisplay);
			TabCtrl_AdjustRect(GetDlgItem(hwndDlg, IDC_TABS), FALSE, &dat->rcDisplay);

			POINT pt = { 0, 0 };
			ClientToScreen(hwndDlg, &pt);
			OffsetRect(&dat->rcDisplay, -pt.x, -pt.y);

			TabCtrl_SetCurSel(GetDlgItem(hwndDlg, IDC_TABS), dat->currentPage);
			dat->opd[dat->currentPage].hwnd = CreateDialogIndirectParam(dat->opd[dat->currentPage].hInst, dat->opd[dat->currentPage].pTemplate, hwndDlg, dat->opd[dat->currentPage].dlgProc, (LPARAM)dat->prof);
			ThemeDialogBackground(dat->opd[dat->currentPage].hwnd);
			SetWindowPos(dat->opd[dat->currentPage].hwnd, HWND_TOP, dat->rcDisplay.left, dat->rcDisplay.top, 0, 0, SWP_NOSIZE);

			PSHNOTIFY pshn;
			pshn.hdr.code = PSN_INFOCHANGED;
			pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd;
			pshn.hdr.idFrom = 0;
			pshn.lParam = 0;
			SendMessage(dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn);

			// service mode combobox
			if (servicePlugins.getCount() == 0) {
				ShowWindow(GetDlgItem(hwndDlg, IDC_SM_LABEL), FALSE);
				ShowWindow(GetDlgItem(hwndDlg, IDC_SM_COMBO), FALSE);
			}
			else {
				HWND hwndCombo = GetDlgItem(hwndDlg, IDC_SM_COMBO);
				LRESULT index = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)_T(""));
				SendMessage(hwndCombo, CB_SETITEMDATA, index, (LPARAM)-1);
				SendMessage(hwndCombo, CB_SETCURSEL, 0, 0);
				for (int i = 0; i < servicePlugins.getCount(); i++) {
					pluginEntry *p = servicePlugins[i];
					index = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)TranslateTS(p->pluginname));
					SendMessage(hwndCombo, CB_SETITEMDATA, index, (LPARAM)i);
				}
			}
			ShowWindow(dat->opd[dat->currentPage].hwnd, SW_SHOW);
		}
		return TRUE;

	case WM_CTLCOLORSTATIC:
		switch (GetDlgCtrlID((HWND)lParam)) {
		case IDC_WHITERECT:
			SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
			return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
		}
		break;

	case PSM_CHANGED:
		dat->opd[dat->currentPage].changed = 1;
		return TRUE;

	case PSM_FORCECHANGED:
		{
			PSHNOTIFY pshn;
			pshn.hdr.code = PSN_INFOCHANGED;
			pshn.hdr.idFrom = 0;
			pshn.lParam = 0;
			for (int i = 0; i < dat->pageCount; i++) {
				pshn.hdr.hwndFrom = dat->opd[i].hwnd;
				if (dat->opd[i].hwnd != NULL)
					SendMessage(dat->opd[i].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn);
			}
		}
		break;

	case WM_NOTIFY:
		switch (wParam) {
		case IDC_TABS:
			switch (((LPNMHDR)lParam)->code) {
			case TCN_SELCHANGING:
				if (dat->currentPage != -1 && dat->opd[dat->currentPage].hwnd != NULL) {
					PSHNOTIFY pshn;
					pshn.hdr.code = PSN_KILLACTIVE;
					pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd;
					pshn.hdr.idFrom = 0;
					pshn.lParam = 0;
					if (SendMessage(dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn)) {
						SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
						return TRUE;
					}
				}
				break;

			case TCN_SELCHANGE:
				if (dat->currentPage != -1 && dat->opd[dat->currentPage].hwnd != NULL)
					ShowWindow(dat->opd[dat->currentPage].hwnd, SW_HIDE);

				dat->currentPage = TabCtrl_GetCurSel(GetDlgItem(hwndDlg, IDC_TABS));
				if (dat->currentPage != -1) {
					if (dat->opd[dat->currentPage].hwnd == NULL) {
						PSHNOTIFY pshn;
						dat->opd[dat->currentPage].hwnd = CreateDialogIndirectParam(dat->opd[dat->currentPage].hInst, dat->opd[dat->currentPage].pTemplate, hwndDlg, dat->opd[dat->currentPage].dlgProc, (LPARAM)dat->prof);
						ThemeDialogBackground(dat->opd[dat->currentPage].hwnd);
						SetWindowPos(dat->opd[dat->currentPage].hwnd, HWND_TOP, dat->rcDisplay.left, dat->rcDisplay.top, 0, 0, SWP_NOSIZE);
						pshn.hdr.code = PSN_INFOCHANGED;
						pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd;
						pshn.hdr.idFrom = 0;
						pshn.lParam = 0;
						SendMessage(dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn);
					}
					ShowWindow(dat->opd[dat->currentPage].hwnd, SW_SHOW);
				}
				break;
			}
			break;
		}
		break;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDCANCEL:
			{
				PSHNOTIFY pshn;
				pshn.hdr.idFrom = 0;
				pshn.lParam = 0;
				pshn.hdr.code = PSN_RESET;
				for (int i = 0; i < dat->pageCount; i++) {
					if (dat->opd[i].hwnd == NULL || !dat->opd[i].changed)
						continue;

					pshn.hdr.hwndFrom = dat->opd[i].hwnd;
					SendMessage(dat->opd[i].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn);
				}
				EndDialog(hwndDlg, 0);
			}
			break;

		case IDC_REMOVE:
			if (!dat->prof->pd->noProfiles) {
				HWND hwndList = GetDlgItem(dat->opd[0].hwnd, IDC_PROFILELIST);
				DeleteProfile(hwndList, ListView_GetNextItem(hwndList, -1, LVNI_SELECTED | LVNI_ALL), dat->prof);
			}
			break;

		case IDOK:
			PSHNOTIFY pshn;
			pshn.hdr.idFrom = 0;
			pshn.lParam = 0;
			if (dat->currentPage != -1) {
				pshn.hdr.code = PSN_KILLACTIVE;
				pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd;
				if (SendMessage(dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn))
					break;
			}

			pshn.hdr.code = PSN_APPLY;
			for (int i = 0; i < dat->pageCount; i++) {
				if (dat->opd[i].hwnd == NULL || !dat->opd[i].changed)
					continue;

				pshn.hdr.hwndFrom = dat->opd[i].hwnd;
				SendMessage(dat->opd[i].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn);
				if (GetWindowLongPtr(dat->opd[i].hwnd, DWLP_MSGRESULT) == PSNRET_INVALID_NOCHANGEPAGE) {
					TabCtrl_SetCurSel(GetDlgItem(hwndDlg, IDC_TABS), i);
					if (dat->currentPage != -1)
						ShowWindow(dat->opd[dat->currentPage].hwnd, SW_HIDE);
					dat->currentPage = i;
					ShowWindow(dat->opd[dat->currentPage].hwnd, SW_SHOW);
					return 0;
				}
			}
			EndDialog(hwndDlg, 1);
		}
		break;

	case WM_DESTROY:
		if (dat->currentPage != 1) {
			LRESULT curSel = SendDlgItemMessage(hwndDlg, IDC_SM_COMBO, CB_GETCURSEL, 0, 0);
			if (curSel != CB_ERR) {
				int idx = SendDlgItemMessage(hwndDlg, IDC_SM_COMBO, CB_GETITEMDATA, (WPARAM)curSel, 0);
				SetServiceModePlugin(servicePlugins[idx]);
			}
		}
		DestroyIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, 0));
		DestroyIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0));
		DeleteObject(dat->hBoldFont);

		for (int i = 0; i < dat->pageCount; i++)
			if (dat->opd[i].hwnd != NULL)
				DestroyWindow(dat->opd[i].hwnd);

		mir_free(dat->opd);
		mir_free(dat);
		break;
	}
	return FALSE;
}
예제 #8
0
static INT_PTR CALLBACK DlgProfileNew(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	struct DlgProfData *dat = (struct DlgProfData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
		dat = (struct DlgProfData *)lParam;
		{
			HWND hwndCombo = GetDlgItem(hwndDlg, IDC_PROFILEDRIVERS);

			// what, no plugins?!
			if (arDbPlugins.getCount() == 0) {
				EnableWindow(hwndCombo, FALSE);
				EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILENAME), FALSE);
				ShowWindow(GetDlgItem(hwndDlg, IDC_NODBDRIVERS), TRUE);
			}
			else {
				for (int i = 0; i < arDbPlugins.getCount(); i++) {
					DATABASELINK *p = arDbPlugins[i];
					LRESULT index = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)TranslateTS(p->szFullName));
					SendMessage(hwndCombo, CB_SETITEMDATA, index, (LPARAM)p);
				}
			}

			// default item
			SendMessage(hwndCombo, CB_SETCURSEL, 0, 0);

			// subclass the profile name box
			mir_subclassWindow(GetDlgItem(hwndDlg, IDC_PROFILENAME), ProfileNameValidate);
		}

		// decide if there is a default profile name given in the INI and if it should be used
		if (dat->pd->noProfiles || (shouldAutoCreate(dat->pd->szProfile) && _taccess(dat->pd->szProfile, 0))) {
			TCHAR *profile = _tcsrchr(dat->pd->szProfile, '\\');
			if (profile) ++profile;
			else profile = dat->pd->szProfile;

			TCHAR *p = _tcsrchr(profile, '.');
			TCHAR c = 0;
			if (p) { c = *p; *p = 0; }

			SetDlgItemText(hwndDlg, IDC_PROFILENAME, profile);
			if (c) *p = c;
		}

		// focus on the textbox
		PostMessage(hwndDlg, WM_FOCUSTEXTBOX, 0, 0);
		return TRUE;

	case WM_FOCUSTEXTBOX:
		SetFocus(GetDlgItem(hwndDlg, IDC_PROFILENAME));
		break;

	case WM_INPUTCHANGED: // when input in the edit box changes
		SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
		EnableWindow(dat->hwndOK, GetWindowTextLength(GetDlgItem(hwndDlg, IDC_PROFILENAME)) > 0);
		break;

	case WM_SHOWWINDOW:
		if (wParam) {
			EnableWindow(dat->hwndSM, FALSE);
			SetWindowText(dat->hwndOK, TranslateT("&Create"));
			SendMessage(hwndDlg, WM_INPUTCHANGED, 0, 0);
		}
		break;

	case WM_NOTIFY:
		NMHDR *hdr = (NMHDR*)lParam;
		if (hdr && hdr->code == PSN_APPLY && dat && IsWindowVisible(hwndDlg)) {
			TCHAR szName[MAX_PATH];
			LRESULT curSel = SendDlgItemMessage(hwndDlg, IDC_PROFILEDRIVERS, CB_GETCURSEL, 0, 0);
			if (curSel == CB_ERR)
				break; // should never happen

			GetDlgItemText(hwndDlg, IDC_PROFILENAME, szName, SIZEOF(szName));
			if (szName[0] == 0)
				break;

			// profile placed in "profile_name" subfolder
			mir_sntprintf(dat->pd->szProfile, MAX_PATH, _T("%s\\%s\\%s.dat"), dat->pd->szProfileDir, szName, szName);
			dat->pd->newProfile = 1;
			dat->pd->dblink = (DATABASELINK *)SendDlgItemMessage(hwndDlg, IDC_PROFILEDRIVERS, CB_GETITEMDATA, (WPARAM)curSel, 0);

			if (CreateProfile(dat->pd->szProfile, dat->pd->dblink, hwndDlg) == 0)
				SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
		}
		break;
	}

	return FALSE;
}
예제 #9
0
static INT_PTR CALLBACK DlgProfileNew(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	struct DlgProfData * dat = (struct DlgProfData *)GetWindowLongPtr(hwndDlg,GWLP_USERDATA);
	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault( hwndDlg );
		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
		dat = (struct DlgProfData *)lParam;
		{
			// fill in the db plugins present
			PLUGIN_DB_ENUM dbe;
			dbe.cbSize = sizeof(dbe);
			dbe.pfnEnumCallback = (int(*)(const char*,void*,LPARAM))FindDbProviders;
			dbe.lParam = (LPARAM)hwndDlg;
			if ( CallService( MS_PLUGINS_ENUMDBPLUGINS, 0, ( LPARAM )&dbe ) == -1 ) {
				// no plugins?!
				EnableWindow( GetDlgItem(hwndDlg, IDC_PROFILEDRIVERS ), FALSE );
				EnableWindow( GetDlgItem(hwndDlg, IDC_PROFILENAME ), FALSE );
				ShowWindow( GetDlgItem(hwndDlg, IDC_NODBDRIVERS ), TRUE );
			}
			// default item
			SendDlgItemMessage(hwndDlg, IDC_PROFILEDRIVERS, CB_SETCURSEL, 0, 0);
		}
		// subclass the profile name box
		{
			HWND hwndProfile = GetDlgItem(hwndDlg, IDC_PROFILENAME);
			WNDPROC proc = (WNDPROC)GetWindowLongPtr(hwndProfile, GWLP_WNDPROC);
			SetWindowLongPtr(hwndProfile,GWLP_USERDATA,(LONG_PTR)proc);
			SetWindowLongPtr(hwndProfile,GWLP_WNDPROC,(LONG_PTR)ProfileNameValidate);
		}

		// decide if there is a default profile name given in the INI and if it should be used
		if (dat->pd->noProfiles || (shouldAutoCreate(dat->pd->szProfile) && _taccess(dat->pd->szProfile, 0))) 
        {
			TCHAR* profile = _tcsrchr(dat->pd->szProfile, '\\');
			if (profile) ++profile;
			else profile = dat->pd->szProfile;

			TCHAR *p = _tcsrchr(profile, '.');
			TCHAR c = 0;
			if (p) { c = *p; *p = 0; } 

			SetDlgItemText(hwndDlg, IDC_PROFILENAME, profile);
			if (c) *p = c;
		}

		// focus on the textbox
		PostMessage( hwndDlg, WM_FOCUSTEXTBOX, 0, 0 );
		return TRUE;

	case WM_FOCUSTEXTBOX:
		SetFocus( GetDlgItem( hwndDlg, IDC_PROFILENAME ));
		break;

	case WM_INPUTCHANGED: // when input in the edit box changes
		SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
		EnableWindow( dat->hwndOK, GetWindowTextLength( GetDlgItem( hwndDlg, IDC_PROFILENAME )) > 0 );
		break;

	case WM_SHOWWINDOW:
		if ( wParam ) {
			SetWindowText( dat->hwndOK, TranslateT("&Create"));
			SendMessage( hwndDlg, WM_INPUTCHANGED, 0, 0 );
		}
		break;

	case WM_NOTIFY:
		{
			NMHDR* hdr = ( NMHDR* )lParam;
			if ( hdr && hdr->code == PSN_APPLY && dat && IsWindowVisible( hwndDlg )) {
				TCHAR szName[MAX_PATH];
				LRESULT curSel = SendDlgItemMessage(hwndDlg,IDC_PROFILEDRIVERS,CB_GETCURSEL,0,0);
				if ( curSel == CB_ERR ) break; // should never happen
				GetDlgItemText(hwndDlg, IDC_PROFILENAME, szName, SIZEOF( szName ));
				if ( szName[0] == 0 )
					break;

				// profile placed in "profile_name" subfolder
				mir_sntprintf( dat->pd->szProfile, MAX_PATH, _T("%s\\%s\\%s.dat"), dat->pd->szProfileDir, szName, szName );
				dat->pd->newProfile = 1;
				dat->pd->dblink = (DATABASELINK *)SendDlgItemMessage( hwndDlg, IDC_PROFILEDRIVERS, CB_GETITEMDATA, ( WPARAM )curSel, 0 );

				if ( makeDatabase( dat->pd->szProfile, dat->pd->dblink, hwndDlg ) == 0 ) {
					SetWindowLongPtr( hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE );
		}	}	}
		break;
	}

	return FALSE;
}