Esempio n. 1
0
///////////////////////////////////////////////////////////////////////////
// CServiceProviderUI::providerRemove
//
// This method is invoked when the TSP is being removed from the
// system.  It should remove all its files and .INI settings.
//
// This method should be overriden by the derived class.
//
LONG CServiceProviderUI::providerRemove(
DWORD dwPermanentProviderID,        // Provider ID (unique across providers)
CWnd* /*pwndOwner*/)                // Owner window to supply and UI for.
{                                   
	// Open the TELEPHONY key
    HKEY hKeyTelephony;
    if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, gszTelephonyKey, 0, KEY_ALL_ACCESS, &hKeyTelephony)
		!= ERROR_SUCCESS)
		return LINEERR_OPERATIONFAILED;

	// Delete our pointer to our section from TAPI
	CString strKey;
	strKey.Format(gszDevice, dwPermanentProviderID);
	LONG lResult = RegDeleteValue (hKeyTelephony, strKey);

	// Get the current device count.  This was written by the providerInstall
	// and also by the stream serialization each time it is used.
	DWORD dwCount = ReadProfileDWord(0, gszTotalDevices, 0L);
	if (dwCount > 1)
	{
		// Decrement the device count
		WriteProfileDWord(0, gszTotalDevices, dwCount-1);

		// Condense down the DeviceXX entries in the registry; these are
		// used by the stream to identify the device sections when loading.
		TCHAR chBuff[50]; DWORD dwIndex = 0;
		for (DWORD dwCurrIndex = 0; dwCurrIndex < dwCount; ++dwCurrIndex, ++dwIndex)
		{
			wsprintf(chBuff, gszDevice, dwCurrIndex);
			DWORD dwDeviceID = ReadProfileDWord(0, chBuff, 0);
			if (dwIndex != dwCurrIndex)
			{
				wsprintf(chBuff, gszDevice, dwIndex);
				WriteProfileDWord(0, chBuff, dwDeviceID);
			}
			else if (dwDeviceID == dwPermanentProviderID)
				--dwIndex;
		}

		// Delete the final entry which is no longer in use.
		wsprintf(chBuff, gszDevice, dwCount-1);
		DeleteProfile(0, chBuff);

		// Delete the device specific information used by streams
		DeleteProfile(0, strKey);
	}
	else
	{
		// Delete our section from the profile - last device.
		IntRegDeleteKey(hKeyTelephony, m_pszProviderInfo);
	}

    RegCloseKey (hKeyTelephony);
    return (lResult == ERROR_SUCCESS) ? S_OK : LINEERR_OPERATIONFAILED;

}// CServiceProviderUI::providerRemove
Esempio n. 2
0
bool MapiProfiles::update(const QString &profile, const QString &username, const QString &password, const QString &domain, const QString &server)
{
    if (!init()) {
        return false;
    }
    qDebug() << "Updating profile:"<<profile;
    QString tmpProfile = QLatin1String("_t_m_p_");

    // Save the profile to a temporary name.
    if (MAPI_E_SUCCESS != DuplicateProfile(m_context, profile.toUtf8(), tmpProfile.toUtf8(), username.toUtf8())) {
        error() << "cannot duplicate tmp profile:" << profile << mapiError();
        return false;
    }
    if (!updateInterim(tmpProfile.toUtf8(), username, password, domain, server)) {
        if (!remove(tmpProfile)) {
            return false;
        }
        return false;
    }

    // Rename the temporary modified profile to the original name.
    if (MAPI_E_SUCCESS != DeleteProfile(m_context, profile.toUtf8())) {
        error() << "cannot delete original profile:" << profile << mapiError();
        if (!remove(tmpProfile)) {
            return false;
        }
        return false;
    }
    if (MAPI_E_SUCCESS != RenameProfile(m_context, tmpProfile.toUtf8(), profile.toUtf8())) {
        error() << "cannot rename tmp profile:" << profile << mapiError();
        return false;
    }
    return true;
}
Esempio n. 3
0
	void ExecuteMenu(LPARAM lParam)
	{
		LVHITTESTINFO lvht = { 0 };
		lvht.pt.x = GET_X_LPARAM(lParam);
		lvht.pt.y = GET_Y_LPARAM(lParam);
		ScreenToClient(m_profileList.GetHwnd(), &lvht.pt);

		if (m_profileList.HitTest(&lvht) == -1)
			return;

		if (lvht.iItem == -1)
			return;

		LVITEM tvi = { 0 };
		tvi.mask = LVIF_IMAGE;
		tvi.iItem = lvht.iItem;
		if (!m_profileList.GetItem(&tvi))
			return;

		bool bConvert = (tvi.iImage == 2);

		lvht.pt.x = GET_X_LPARAM(lParam);
		lvht.pt.y = GET_Y_LPARAM(lParam);

		HMENU hMenu = CreatePopupMenu();
		if (tvi.iImage < 2) {
			AppendMenu(hMenu, MF_STRING, 1, TranslateT("Run"));
			AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
		}
		if (tvi.iImage != 3 && ServiceExists(MS_DB_CHECKPROFILE)) {
			if (bConvert)
				AppendMenu(hMenu, MF_STRING, 2, TranslateT("Convert database"));
			else
				AppendMenu(hMenu, MF_STRING, 2, TranslateT("Check database"));
			AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
		}
		AppendMenu(hMenu, MF_STRING, 3, TranslateT("Delete"));
		int index = TrackPopupMenu(hMenu, TPM_RETURNCMD, lvht.pt.x, lvht.pt.y, 0, m_hwnd, NULL);
		switch (index) {
		case 1:
			SendMessage(GetParent(m_hwndParent), WM_COMMAND, IDOK, 0);
			break;

		case 2:
			CheckProfile(lvht.iItem);
			break;

		case 3:
			DeleteProfile(lvht.iItem);
			break;
		}
		DestroyMenu(hMenu);
	}
Esempio n. 4
0
bool MapiProfiles::remove(QString profile)
{
    if (!init()) {
        return false;
    }

    if (MAPI_E_SUCCESS != DeleteProfile(m_context, profile.toUtf8())) {
        error() << "cannot delete profile:" << profile << mapiError();
        return false;
    }
    return true;
}
void OBSBasic::on_actionRenameProfile_triggered()
{
	std::string curDir = config_get_string(App()->GlobalConfig(),
			"Basic", "ProfileDir");
	std::string curName = config_get_string(App()->GlobalConfig(),
			"Basic", "Profile");

	/* Duplicate and delete in case there are any issues in the process */
	bool success = AddProfile(false, Str("RenameProfile.Title"),
			Str("AddProfile.Text"), curName.c_str());
	if (success) {
		DeleteProfile(curName.c_str(), curDir.c_str());
		RefreshProfiles();
	}
}
Esempio n. 6
0
void ProfileDlg::OnDelProfile() 
{
	CString selection;
	int iSel = m_profiles.GetCurSel();
	if(iSel==-1) return;
	m_profiles.GetLBText(iSel,selection);
	if(!selection.IsEmpty())
	{
		CString tmp;
		tmp.LoadString(IDS_PROFILE_DELETE);
		if(MessageBox(tmp, NULL, MB_YESNO) == IDNO)
			return;
		DeleteProfile(selection);
		UpdateProfilesCombo();
	}
}
Esempio n. 7
0
void ProfileDlg::OnDelAllProfiles() 
{
	CString tmp;
	tmp.LoadString(IDS_PROFILE_DELETE_ALL);
	if(MessageBox(tmp, NULL, MB_YESNO) == IDNO)
		return;
	for(int i=0; i<m_profiles.GetCount(); ++i)
	{
		CString selection;
		m_profiles.GetLBText(i,selection);
		if(!selection.IsEmpty())
		{
			DeleteProfile(selection);
		}
	}
	UpdateProfilesCombo();
}
void OBSBasic::on_actionRemoveProfile_triggered()
{
	std::string newName;
	std::string newPath;
	ConfigFile config;

	std::string oldDir = config_get_string(App()->GlobalConfig(),
			"Basic", "ProfileDir");
	std::string oldName = config_get_string(App()->GlobalConfig(),
			"Basic", "Profile");

	auto cb = [&](const char *name, const char *filePath)
	{
		if (strcmp(oldName.c_str(), name) != 0) {
			newName = name;
			newPath = filePath;
			return false;
		}

		return true;
	};

	EnumProfiles(cb);

	/* this should never be true due to menu item being grayed out */
	if (newPath.empty())
		return;

	QString text = QTStr("ConfirmRemove.Text");
	text.replace("$1", QT_UTF8(oldName.c_str()));

	QMessageBox::StandardButton button = QMessageBox::question(this,
			QTStr("ConfirmRemove.Title"), text);
	if (button == QMessageBox::No)
		return;

	size_t newPath_len = newPath.size();
	newPath += "/basic.ini";

	if (config.Open(newPath.c_str(), CONFIG_OPEN_ALWAYS) != 0) {
		blog(LOG_ERROR, "ChangeProfile: Failed to load file '%s'",
				newPath.c_str());
		return;
	}

	newPath.resize(newPath_len);

	const char *newDir = strrchr(newPath.c_str(), '/') + 1;

	config_set_string(App()->GlobalConfig(), "Basic", "Profile",
			newName.c_str());
	config_set_string(App()->GlobalConfig(), "Basic", "ProfileDir",
			newDir);

	config.Swap(basicConfig);
	InitBasicConfigDefaults();
	ResetProfileData();
	DeleteProfile(oldName.c_str(), oldDir.c_str());
	RefreshProfiles();
	config_save_safe(App()->GlobalConfig(), "tmp", nullptr);

	blog(LOG_INFO, "Switched to profile '%s' (%s)",
			newName.c_str(), newDir);
	blog(LOG_INFO, "------------------------------------------------");

	UpdateTitleBar();
}
Esempio n. 9
0
	void list_OnKeyDown(CCtrlListView::TEventInfo *evt)
	{
		if (evt->nmlvkey->wVKey == VK_DELETE)
			DeleteProfile(m_profileList.GetNextItem(-1, LVNI_SELECTED | LVNI_ALL));
	}
Esempio n. 10
0
HRESULT ExchangeAdmin::CreateProfile(wstring strProfileName, wstring strMailboxName, wstring
    strPassword)
{
    HRESULT hr = S_OK;
    Zimbra::Util::ScopedBuffer<char> strServer;
    Zimbra::Util::ScopedBuffer<char> strMBName;
    Zimbra::Util::ScopedBuffer<char> strProfName;
    Zimbra::Util::ScopedBuffer<char> strProfPwd;
    Zimbra::Util::ScopedInterface<IMsgServiceAdmin> pSvcAdmin;
    Zimbra::Util::ScopedInterface<IMAPITable> pMsgSvcTable;
    Zimbra::Util::ScopedRowSet pSvcRows;
    SPropValue rgval[2] = { 0 };
    SPropValue sProps = { 0 };
    SRestriction sres;
    WCHAR errDescrption[256] = {};

    // Columns to get from HrQueryAllRows.
    enum { iSvcName, iSvcUID, cptaSvc };

    SizedSPropTagArray(cptaSvc, sptCols) = { cptaSvc, PR_SERVICE_NAME, PR_SERVICE_UID };
    WtoA((LPWSTR)strProfileName.c_str(), strProfName.getref());
    WtoA((LPWSTR)strPassword.c_str(), strProfPwd.getref());
    // create new profile
    if (FAILED(hr = m_pProfAdmin->CreateProfile((LPTSTR)strProfName.get(),
            (LPTSTR)strProfPwd.get(), NULL, 0)))
    {
        throw ExchangeAdminException(hr, L"CreateProfile(): CreateProfile Failed.", 
			ERR_CREATE_EXCHPROFILE, __LINE__, __FILE__);
    }
    // Get an IMsgServiceAdmin interface off of the IProfAdmin interface.
    if (FAILED(hr = m_pProfAdmin->AdminServices((LPTSTR)strProfName.get(),
            (LPTSTR)strProfPwd.get(), NULL, 0, pSvcAdmin.getptr())))
    {
        wcscpy(errDescrption, L"CreateProfile(): AdminServices Failed.");
        goto CRT_PROFILE_EXIT;
    }
    // Create the new message service for Exchange.
    if (FAILED(hr = pSvcAdmin->CreateMsgService((LPTSTR)"MSEMS", (LPTSTR)"MSEMS", NULL, NULL)))
    {
        wcscpy(errDescrption, L"CreateProfile(): CreateMsgService Failed.");
        goto CRT_PROFILE_EXIT;
    }
    // Need to obtain the entry id for the new service. This can be done by getting the message service table
    // and getting the entry that corresponds to the new service.
    if (FAILED(hr = pSvcAdmin->GetMsgServiceTable(0, pMsgSvcTable.getptr())))
    {
        wcscpy(errDescrption, L"CreateProfile(): GetMsgServiceTable Failed.");
        goto CRT_PROFILE_EXIT;
    }
    sres.rt = RES_CONTENT;
    sres.res.resContent.ulFuzzyLevel = FL_FULLSTRING;
    sres.res.resContent.ulPropTag = PR_SERVICE_NAME;
    sres.res.resContent.lpProp = &sProps;

    sProps.ulPropTag = PR_SERVICE_NAME;
    sProps.Value.lpszA = "MSEMS";
    // Query the table to obtain the entry for the newly created message service.
    if (FAILED(hr = HrQueryAllRows(pMsgSvcTable.get(), (LPSPropTagArray) & sptCols, NULL, NULL,
            0, pSvcRows.getptr())))
    {
        wcscpy(errDescrption, L"CreateProfile(): HrQueryAllRows Failed.");
        goto CRT_PROFILE_EXIT;
    }
    // Set up a SPropValue array for the properties that you have to configure.
    if (pSvcRows->cRows > 0)
    {
        // First, the exchange server name.
        ZeroMemory(&rgval[0], sizeof (SPropValue));
        rgval[0].ulPropTag = PR_PROFILE_UNRESOLVED_SERVER;
        WtoA((LPWSTR)m_strServer.c_str(), strServer.getref());
        rgval[0].Value.lpszA = (LPSTR)strServer.get();

        // Next, the user's AD name.
        ZeroMemory(&rgval[1], sizeof (SPropValue));
        rgval[1].ulPropTag = PR_PROFILE_UNRESOLVED_NAME;
        WtoA((LPWSTR)strMailboxName.c_str(), strMBName.getref());
        rgval[1].Value.lpszA = (LPSTR)strMBName.get();

        // Configure the message service by using the previous properties.
        // int trials = 10;
        int trials = 2;
        int itrTrials = 0;

        hr = 0x81002746;                        // WSAECONNRESET
        while ((hr == 0x81002746) && (itrTrials < trials))
        {
            hr = pSvcAdmin->ConfigureMsgService(
                (LPMAPIUID)pSvcRows->aRow->lpProps[iSvcUID].Value.bin.lpb, NULL, 0, 2, rgval);
            //if (hr == 0x81002746)
                // Sleep(30000);
                //Sleep(10000);
            itrTrials++;
        }
        if (FAILED(hr))
        {
            /* =
             * pSvcAdmin->ConfigureMsgService((LPMAPIUID)pSvcRows->aRow->lpProps[iSvcUID].
             *   Value.bin.lpb,NULL, 0, 2, rgval)))*/
            wcscpy(errDescrption, L"CreateProfile(): ConfigureMsgService Failed.");
            goto CRT_PROFILE_EXIT;
        }
    }
CRT_PROFILE_EXIT: 
	if (hr != S_OK)
    {
        DeleteProfile(strProfileName);
        throw ExchangeAdminException(hr, errDescrption, ERR_CREATE_EXCHPROFILE, __LINE__, __FILE__);
    }
	else
	{
		//Create supporting OL profile entries else crash may happen!
		if(!Zimbra::MAPI::Util::SetOLProfileRegistryEntries(strProfileName.c_str()))
		{
			throw ExchangeAdminException(hr, L"ExchangeAdmin::CreateProfile()::SetOLProfileRegistryEntries Failed.",
				ERR_CREATE_EXCHPROFILE, __LINE__, __FILE__);
		}
/*		Zimbra::Util::ScopedBuffer<char> strProfName;
		WtoA((LPWSTR)strProfileName.c_str(), strProfName.getref());
		hr=m_pProfAdmin->SetDefaultProfile((LPTSTR)strProfName.get(),NULL);
*/
	}
    return hr;
}
Esempio n. 11
0
/* returns TRUE if a user profile was destroyed; otherwise, FALSE. 
It's private because it does not change the state of the profile 
object, so even though the profile object may think it is loaded,
in reality, it's completely gone. This is directly remedied by 
the code surrounding it, at its invocation. */
BOOL
OwnerProfile::destroy () const {

    dprintf ( D_FULLDEBUG, "In OwnerProfile::destroy()\n" );

    DWORD       last_error      = 0;
    priv_state  priv            = PRIV_UNKNOWN;
    PSID        user_sid        = NULL;
    LPSTR       user_sid_string = NULL;
    BOOL        got_user_sid    = FALSE,
                got_sid_string  = FALSE,
                profile_deleted = FALSE,
                ok              = FALSE;

    __try {

        /* we must do the following as condor */
        priv = set_condor_priv ();

        /* load the user's SID */
        got_user_sid = LoadUserSid ( 
            user_token_, 
            &user_sid );

        dprintf ( 
            D_FULLDEBUG, 
            "UserProfile::destroy: Loading %s's SID "
            "%s. (last-error = %u)\n", 
            user_name_,
            got_user_sid ? "succeeded" : "failed", 
            got_user_sid ? 0 : GetLastError () );

        if ( !got_user_sid ) {
            __leave;
        }

        /* convert the SID to a string */
        got_sid_string = ConvertSidToStringSid (
            user_sid,
            &user_sid_string );

        dprintf ( 
            D_FULLDEBUG, 
            "UserProfile::destroy: Converting SID to a string "
            "%s. (last-error = %u)\n", 
            got_sid_string ? "succeeded" : "failed", 
            got_sid_string ? 0 : GetLastError () );
        
        if ( !got_sid_string ) {
            __leave;
        }

        /* let Windows remove the profile for us */
        profile_deleted = DeleteProfile ( 
            user_sid_string,
            profile_directory_,
            NULL /* local computer */ );

        dprintf ( 
            D_FULLDEBUG, 
            "UserProfile::destroy: Removing %s's profile "
            "directory %s. (last-error = %u)\n", 
            user_name_,
            profile_deleted ? "succeeded" : "failed", 
            profile_deleted ? 0 : GetLastError () );
        
        if ( !profile_deleted ) {
            __leave;
        }

#if 0
        /* just make sure we have the profile's directory */
        if ( NULL == profile_directory_ ) {
            __leave;
        }

        /* if we have have a profile directory, let's blow it away */
        profile_deleted = 
            CondorRemoveDirectory ( profile_directory_ );

        dprintf ( 
            D_FULLDEBUG, 
            "UserProfile::destroy: Removing %s's profile "
            "directory %s. (last-error = %u)\n", 
            user_name_,
            profile_deleted ? "succeeded" : "failed", 
            profile_deleted ? 0 : GetLastError () );

        if ( !profile_deleted ) {
            __leave;
        }
#endif

        /* if we got here, all is well */
        ok = TRUE;
    
    }
    __finally {

        /* return to previous privilege level */
        set_priv ( priv );

        if ( user_sid ) {
            UnloadUserSid ( user_sid );
        }
        if ( user_sid_string ) {
            LocalFree ( user_sid_string );
        }

    }

    return ok;

}
Esempio n. 12
0
void ProfileDlg::OnImportProfile() 
{
	CString name;
	CString tmp;
	tmp.LoadString(IDS_PROFILE_FILEDIALOG);
	CFileDialog fd( TRUE, _T("prf"), NULL, OFN_ENABLESIZING|OFN_FILEMUSTEXIST, tmp + _T(" (*.xpas)|*.xpas||"), this);
	tmp.LoadString(IDS_PROFILE_LOAD);
	fd.m_ofn.lpstrTitle = tmp;
	if(fd.DoModal() == IDOK)
	{
		StringVec profiles = GetExistingProfiles();
		for(int i = 0; i < profiles.size(); ++i)
		{
			profiles[i].MakeLower();
			fd.GetFileName().MakeLower();
			if(profiles[i] == fd.GetFileTitle())
			{
				CString tmp;
				tmp.LoadString(IDS_PROFILE_EXISTS);
				if(MessageBox(tmp, NULL, MB_YESNO) == IDNO)
				{
					return;
				}
				else
				{
					DeleteProfile(fd.GetFileTitle());
				}
			}
		}

		CFile file(fd.GetPathName(), CFile::modeRead);
		SettingVec vec;
		
		CArchive* ar=new CArchive(&file,CArchive::load);
		try
		{
			while(1)
			{
				SETTING set;
				*ar>>set.settingID;
				*ar>>set.checked;
				if((set.settingID <= ITEMCOUNT && set.settingID >= 0)
					|| (set.checked >= 0 && set.checked <= 1))
				{
					vec.push_back(set);
				}
			}
		}
		catch(CArchiveException* e)
		{
			e->Delete();
			if(vec.size() > 0)
				CreateProfile(fd.GetFileTitle(),vec);
			else
			{
				CString tmp;
				tmp.LoadString(IDS_PROFILE_ERROR);
				AfxMessageBox(tmp);
			}
		}
		ar->Close();
		if(ar) delete ar;
		file.Close();
	}
Esempio n. 13
0
////////////////////////////////////////////////////////////////////////////
// CServiceProviderUI::RenameProfile
//
// Moves a profile from one area to another.
//
bool CServiceProviderUI::RenameProfile (DWORD dwOldDevice, DWORD dwNewDevice)
{
	// Ignore requests for the same profile.
	if (dwOldDevice == dwNewDevice)
		return TRUE;

	// First make sure the NEW device doesn't exist already
	if (dwNewDevice > 0 && !DeleteProfile(dwNewDevice))
		return FALSE;

    // Open the master registry key.
    HKEY hTelephonyKey;
    if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, gszTelephonyKey, 0, KEY_ALL_ACCESS, &hTelephonyKey) != ERROR_SUCCESS)
		return FALSE;

    // Open our Provider section
    HKEY hProviderKey;
    if (RegOpenKeyEx (hTelephonyKey, m_pszProviderInfo, 0, KEY_ALL_ACCESS, &hProviderKey) != ERROR_SUCCESS)
	{
		RegCloseKey (hTelephonyKey);
		return FALSE;
	}

	// Open our device section.
	HKEY hOldDeviceKey;
	TCHAR szBuff[20];
	if (dwOldDevice > 0)
	{
		wsprintf(szBuff, gszDevice, dwOldDevice);
		if (RegOpenKeyEx (hProviderKey, szBuff, 0, KEY_ALL_ACCESS, &hOldDeviceKey) != ERROR_SUCCESS)
		{
			RegCloseKey (hProviderKey);
			RegCloseKey (hTelephonyKey);
			return FALSE;
		}
	}
	else
		hOldDeviceKey = hProviderKey;

	// Create the new section
	HKEY hNewDeviceKey;
	if (dwNewDevice > 0)
	{
		DWORD dwDisposition;
		wsprintf(szBuff, gszDevice, dwNewDevice);
		if (RegCreateKeyEx (hProviderKey, szBuff, 0, _T(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
							NULL, &hNewDeviceKey, &dwDisposition) != ERROR_SUCCESS)
		{
			if (dwOldDevice > 0)
				RegCloseKey(hOldDeviceKey);
			RegCloseKey (hProviderKey);
			RegCloseKey (hTelephonyKey);
			return FALSE;
		}
	}
	else
		hNewDeviceKey = hProviderKey;

	// Get the max size of the name and values.
	DWORD dwNameSize, dwValueSize, dwType;
	if (RegQueryInfoKey (hOldDeviceKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
		                 &dwNameSize, &dwValueSize, NULL, NULL) != ERROR_SUCCESS)
	{
		dwNameSize = 1024;
		dwValueSize = 4096;
	}
	else
	{
		dwNameSize++;
		dwValueSize++;
	}

	// Alloc blocks to hold the information.
	LPTSTR pszName = (LPTSTR) GlobalAllocPtr (GHND, dwNameSize * sizeof(TCHAR));
	LPBYTE pszValue = (LPBYTE) GlobalAllocPtr (GHND, dwValueSize * sizeof(TCHAR));

	// Enumerate through all the values within the old key, and move them to the new section.
	DWORD dwIndex = 0;
	while (TRUE)
	{
		// Enumerate through the items.
		DWORD dwNewNameSize = dwNameSize, dwNewValueSize = dwValueSize;
		if (RegEnumValue (hOldDeviceKey, dwIndex++, pszName, &dwNewNameSize, NULL,
									   &dwType, pszValue, &dwNewValueSize) != ERROR_SUCCESS)
			break;

		// Delete the value.
		RegDeleteValue (hOldDeviceKey, pszName);

		// Create the key in our new subkey.
		RegSetValueEx (hNewDeviceKey, pszName, 0, dwType, (LPBYTE)pszValue, dwNewValueSize);
	}

	// We're done with the memory.
	GlobalFreePtr (pszName);
	GlobalFreePtr (pszValue);

	// Close all the used keys.
	if (dwNewDevice > 0)
		RegCloseKey(hNewDeviceKey);
	if (dwOldDevice > 0)
		RegCloseKey(hOldDeviceKey);
	RegCloseKey (hProviderKey);
	RegCloseKey (hTelephonyKey);

	// Now delete the original section
	if (dwOldDevice > 0)
		DeleteProfile(dwOldDevice);

	return TRUE;

}// CServiceProviderUI::RenameProfile
Esempio n. 14
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;
}
Esempio n. 15
0
static INT_PTR CALLBACK DlgProfileSelect(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	DlgProfData *dat = (struct DlgProfData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
	HWND hwndList = GetDlgItem(hwndDlg, IDC_PROFILELIST);

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		EnsureCheckerLoaded(true);
		{
			dat = (DlgProfData*)lParam;
			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);

			// set columns
			LVCOLUMN col;
			col.mask = LVCF_TEXT | LVCF_WIDTH;
			col.pszText = TranslateT("Profile");
			col.cx = 100;
			ListView_InsertColumn(hwndList, 0, &col);

			col.pszText = TranslateT("Driver");
			col.cx = 150 - GetSystemMetrics(SM_CXVSCROLL);
			ListView_InsertColumn(hwndList, 1, &col);

			col.pszText = TranslateT("Size");
			col.cx = 60;
			ListView_InsertColumn(hwndList, 2, &col);

			// icons
			HIMAGELIST hImgList = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 2, 1);
			ImageList_AddIcon_NotShared(hImgList, MAKEINTRESOURCE(IDI_USERDETAILS));
			ImageList_AddIcon_NotShared(hImgList, MAKEINTRESOURCE(IDI_DELETE));

			// LV will destroy the image list
			SetWindowLongPtr(hwndList, GWL_STYLE, GetWindowLongPtr(hwndList, GWL_STYLE) | LVS_SORTASCENDING);
			ListView_SetImageList(hwndList, hImgList, LVSIL_SMALL);
			ListView_SetExtendedListViewStyle(hwndList,
				ListView_GetExtendedListViewStyle(hwndList) | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_LABELTIP | LVS_EX_FULLROWSELECT);

			// find all the profiles
			ProfileEnumData ped = { hwndDlg, dat->pd->szProfile };
			findProfiles(dat->pd->szProfileDir, EnumProfilesForList, (LPARAM)&ped);
			PostMessage(hwndDlg, WM_FOCUSTEXTBOX, 0, 0);

			dat->hFileNotify = FindFirstChangeNotification(dat->pd->szProfileDir, TRUE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE);
			if (dat->hFileNotify != INVALID_HANDLE_VALUE)
				SetTimer(hwndDlg, 0, 1200, NULL);
			return TRUE;
		}

	case WM_DESTROY:
		KillTimer(hwndDlg, 0);
		FindCloseChangeNotification(dat->hFileNotify);
		break;

	case WM_TIMER:
		if (WaitForSingleObject(dat->hFileNotify, 0) == WAIT_OBJECT_0) {
			ListView_DeleteAllItems(hwndList);
			ProfileEnumData ped = { hwndDlg, dat->pd->szProfile };
			findProfiles(dat->pd->szProfileDir, EnumProfilesForList, (LPARAM)&ped);
			FindNextChangeNotification(dat->hFileNotify);
		}
		break;

	case WM_FOCUSTEXTBOX:
		SetFocus(hwndList);
		if (dat->pd->szProfile[0] == 0 || ListView_GetSelectedCount(hwndList) == 0)
			ListView_SetItemState(hwndList, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
		break;

	case WM_SHOWWINDOW:
		if (wParam) {
			SetWindowText(dat->hwndOK, TranslateT("&Run"));
			EnableWindow(dat->hwndSM, TRUE);
			EnableWindow(dat->hwndOK, ListView_GetSelectedCount(hwndList) == 1);
		}
		break;

	case WM_CONTEXTMENU:
		{
			LVHITTESTINFO lvht = { 0 };
			lvht.pt.x = GET_X_LPARAM(lParam);
			lvht.pt.y = GET_Y_LPARAM(lParam);
			ScreenToClient(hwndList, &lvht.pt);

			if (ListView_HitTest(hwndList, &lvht) < 0) {
				if (lParam != -1)
					break;

				lvht.iItem = ListView_GetSelectionMark(hwndList);
				RECT rc = { 0 };
				if (!ListView_GetItemRect(hwndList, lvht.iItem, &rc, LVIR_LABEL))
					break;
				
				lvht.pt.x = rc.left;
				lvht.pt.y = rc.bottom;
				ClientToScreen(hwndList, &lvht.pt);
			}
			else {
				lvht.pt.x = GET_X_LPARAM(lParam);
				lvht.pt.y = GET_Y_LPARAM(lParam);
			}

			HMENU hMenu = CreatePopupMenu();
			AppendMenu(hMenu, MF_STRING, 1, TranslateT("Run"));
			AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
			if (ServiceExists(MS_DB_CHECKPROFILE)) {
				AppendMenu(hMenu, MF_STRING, 2, TranslateT("Check database"));
				AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
			}
			AppendMenu(hMenu, MF_STRING, 3, TranslateT("Delete"));
			int index = TrackPopupMenu(hMenu, TPM_RETURNCMD, lvht.pt.x, lvht.pt.y, 0, hwndDlg, NULL);
			switch (index) {
			case 1:
				SendMessage(GetParent(hwndDlg), WM_COMMAND, IDOK, 0);
				break;

			case 2:
				CheckProfile(hwndList, lvht.iItem, dat);
				break;

			case 3:
				DeleteProfile(hwndList, lvht.iItem, dat);
				break;
			}
			DestroyMenu(hMenu);
		}
		break;

	case WM_NOTIFY:
		LPNMHDR hdr = (LPNMHDR)lParam;
		if (hdr && hdr->code == PSN_INFOCHANGED)
			break;

		if (hdr && hdr->idFrom == IDC_PROFILELIST) {
			switch (hdr->code) {
			case LVN_ITEMCHANGED:
				EnableWindow(dat->hwndOK, ListView_GetSelectedCount(hwndList) == 1);

			case NM_DBLCLK:
				if (dat != NULL) {
					TCHAR profile[MAX_PATH];
					LVITEM item = { 0 };
					item.mask = LVIF_TEXT;
					item.iItem = ListView_GetNextItem(hwndList, -1, LVNI_SELECTED | LVNI_ALL);
					item.pszText = profile;
					item.cchTextMax = SIZEOF(profile);

					if (ListView_GetItem(hwndList, &item)) {
						// profile is placed in "profile_name" subfolder
						TCHAR tmpPath[MAX_PATH];
						mir_sntprintf(tmpPath, SIZEOF(tmpPath), _T("%s\\%s.dat"), dat->pd->szProfileDir, profile);
						HANDLE hFile = CreateFile(tmpPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
						if (hFile == INVALID_HANDLE_VALUE)
							mir_sntprintf(dat->pd->szProfile, MAX_PATH, _T("%s\\%s\\%s.dat"), dat->pd->szProfileDir, profile, profile);
						else
							_tcscpy(dat->pd->szProfile, tmpPath);
						CloseHandle(hFile);
						if (hdr->code == NM_DBLCLK) EndDialog(GetParent(hwndDlg), 1);
					}
				}
				return TRUE;

			case LVN_KEYDOWN:
				if (((LPNMLVKEYDOWN)lParam)->wVKey == VK_DELETE)
					DeleteProfile(hwndList, ListView_GetNextItem(hwndList, -1, LVNI_SELECTED | LVNI_ALL), dat);
				break;

			case LVN_GETINFOTIP:
				NMLVGETINFOTIP *pInfoTip = (NMLVGETINFOTIP *)lParam;
				if (pInfoTip != NULL) {
					TCHAR profilename[MAX_PATH], fullpath[MAX_PATH];
					struct _stat statbuf;
					ListView_GetItemText(hwndList, pInfoTip->iItem, 0, profilename, MAX_PATH);
					mir_sntprintf(fullpath, SIZEOF(fullpath), _T("%s\\%s\\%s.dat"), dat->pd->szProfileDir, profilename, profilename);
					_tstat(fullpath, &statbuf);
					mir_sntprintf(pInfoTip->pszText, pInfoTip->cchTextMax, _T("%s\n%s: %s\n%s: %s"), fullpath, TranslateT("Created"), rtrimt(NEWTSTR_ALLOCA(_tctime(&statbuf.st_ctime))), TranslateT("Modified"), rtrimt(NEWTSTR_ALLOCA(_tctime(&statbuf.st_mtime))));
				}
			}
		}
		break;
	}

	return FALSE;
}