void fsDownloads_GroupsMgr::DeleteGroup(LPCSTR pszGroup)
{
	int grp = FindGroupByName (pszGroup);
	if (grp == -1)
		return;

	m_vGroups.del (grp);

	CRegKey key;
	key.Attach (m_hGroups);
	key.RecurseDeleteKey (pszGroup);
	key.Detach ();
}
Exemple #2
0
void _ATL_OBJMAP_ENTRY::RemoveRegistry()
{
	USES_CONVERSION;
	CRegKey key;
	key.Attach(HKEY_CLASSES_ROOT);
    if (lpszProgID)
        {
	    key.RecurseDeleteKey(lpszProgID);
        }
    if (lpszVerIndProgID)
        {
	    key.RecurseDeleteKey(lpszVerIndProgID);
        }
	LPOLESTR lpOleStr;
	StringFromCLSID(*pclsid, &lpOleStr);
	LPTSTR lpsz = OLE2T(lpOleStr);
	key.Open(key, szCLSID);
	key.RecurseDeleteKey(lpsz);
	CoTaskMemFree(lpOleStr);
}
Exemple #3
0
bool CFileAssoc::RegisterFolderContextMenuEntries(bool bRegister)
{
    CRegKey key;
    bool success;

    if (bRegister) {
        success = false;

        CString appIcon = "\"" + GetProgramPath(true) + "\",0";

        if (ERROR_SUCCESS == key.Create(HKEY_CLASSES_ROOT, _T("Directory\\shell\\") PROGID _T(".enqueue"))) {
            key.SetStringValue(nullptr, ResStr(IDS_ADD_TO_PLAYLIST));
            key.SetStringValue(_T("Icon"), appIcon);

            if (ERROR_SUCCESS == key.Create(HKEY_CLASSES_ROOT, _T("Directory\\shell\\") PROGID _T(".enqueue\\command"))) {
                key.SetStringValue(nullptr, m_strEnqueueCommand);
                success = true;
            }
        }

        if (success && ERROR_SUCCESS == key.Create(HKEY_CLASSES_ROOT, _T("Directory\\shell\\") PROGID _T(".play"))) {
            success = false;

            key.SetStringValue(nullptr, ResStr(IDS_OPEN_WITH_MPC));
            key.SetStringValue(_T("Icon"), appIcon);

            if (ERROR_SUCCESS == key.Create(HKEY_CLASSES_ROOT, _T("Directory\\shell\\") PROGID _T(".play\\command"))) {
                key.SetStringValue(nullptr, m_strOpenCommand);
                success = true;
            }
        }

    } else {
        key.Attach(HKEY_CLASSES_ROOT);
        success  = (ERROR_SUCCESS == key.RecurseDeleteKey(_T("Directory\\shell\\") PROGID _T(".enqueue")));
        success &= (ERROR_SUCCESS == key.RecurseDeleteKey(_T("Directory\\shell\\") PROGID _T(".play")));
    }

    return success;
}
Exemple #4
0
// This will add the history of data used
LRESULT CToolBarCombo::AddtoHistory(const _bstr_t& bstrURL){
  CRegKey keyAppID;
  if(std::basic_string<TCHAR>(bstrURL).find_first_not_of(_T(" "))!=std::string::npos)  {
    int h = GetCount();
    int pos = FindStringExact(-1,bstrURL);
    if(pos == CB_ERR){
      if(h<50){
        InsertString(0,bstrURL);
      }else{
        DeleteString(h-1);
        InsertString(0,bstrURL);
      }
    }else{
      DeleteString(pos);
      InsertString(0,bstrURL);
    }

    {
      CRegKey keyAppID;
      keyAppID.Attach(Get6BeeAppRegistryKey());
      keyAppID.RecurseDeleteKey(_T("History"));
    }

    {
      CRegKey keyAppID;
      keyAppID.Create(Get6BeeAppRegistryKey(),_T("History"));

      for(int i=0;i < GetCount();i++)
      {
        TCHAR cValue[1024]={};
        GetLBText(i, cValue);
        keyAppID.SetDWORDValue(cValue,1);
      }
    }

    SetCurSel(0);
  }

  return 0;
}
Exemple #5
0
BOOL CPPageFormats::OnApply()
{
	UpdateData();

	{
		int i = m_list.GetSelectionMark();
		if(i >= 0) i = (int)m_list.GetItemData(i);
		if(i >= 0)
		{
			CMediaFormats& mf = AfxGetAppSettings().Formats;
			mf[i].SetExts(m_exts);
			m_exts = mf[i].GetExtsWithPeriod();
			UpdateData(FALSE);
		}
	}

	CMediaFormats& mf = AfxGetAppSettings().Formats;

	CString AppIcon = _T("");
	TCHAR buff[_MAX_PATH];

	if(::GetModuleFileName(AfxGetInstanceHandle(), buff, MAX_PATH))
	{
		AppIcon = buff;
		AppIcon = "\""+AppIcon+"\"";
		AppIcon += _T(",0");
	}

	if (m_pAAR)
	{
		// Register MPC for the windows "Default application" manager
		CRegKey		key;

		if(ERROR_SUCCESS == key.Open(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\RegisteredApplications")))
		{
			key.SetStringValue(_T("Media Player Classic"), g_strRegisteredKey);

			if(ERROR_SUCCESS != key.Create(HKEY_LOCAL_MACHINE, g_strRegisteredKey))
				return(false);

			// ==>>  TODO icon !!!
			key.SetStringValue(_T("ApplicationDescription"), ResStr(IDS_APP_DESCRIPTION), REG_EXPAND_SZ);
			key.SetStringValue(_T("ApplicationIcon"), AppIcon, REG_EXPAND_SZ);
			key.SetStringValue(_T("ApplicationName"), ResStr(IDR_MAINFRAME), REG_EXPAND_SZ);
		}
	}

	f_setContextFiles = m_fContextFiles.GetCheck();
	f_setAssociatedWithIcon = m_fAssociatedWithIcons.GetCheck();

	for(int i = 0; i < m_list.GetItemCount(); i++)
	{
		int iChecked = GetChecked(i);
		if(iChecked == 2) continue;

		CAtlList<CString> exts;
		Explode(mf[(int)m_list.GetItemData(i)].GetExtsWithPeriod(), exts, ' ');

		POSITION pos = exts.GetHeadPosition();
		while(pos)
			RegisterExt(exts.GetNext(pos), mf[(int)m_list.GetItemData(i)].GetLabel(), !!iChecked);
	}

	CRegKey	key;
	if(m_fContextDir.GetCheck())
	{
		if(ERROR_SUCCESS == key.Create(HKEY_CLASSES_ROOT, _T("Directory\\shell\\mplayerc.enqueue")))
		{
			key.SetStringValue(NULL, ResStr(IDS_ADD_TO_PLAYLIST));
		}

		if(ERROR_SUCCESS == key.Create(HKEY_CLASSES_ROOT, _T("Directory\\shell\\mplayerc.enqueue\\command")))
		{
			key.SetStringValue(NULL, GetEnqueueCommand());
		}

		if(ERROR_SUCCESS == key.Create(HKEY_CLASSES_ROOT, _T("Directory\\shell\\mplayerc.play")))
		{
			key.SetStringValue(NULL, ResStr(IDS_OPEN_WITH_MPC));
		}

		if(ERROR_SUCCESS == key.Create(HKEY_CLASSES_ROOT, _T("Directory\\shell\\mplayerc.play\\command")))
		{
			key.SetStringValue(NULL, GetOpenCommand());
		}
	}
	else
	{
		key.Attach(HKEY_CLASSES_ROOT);
		key.RecurseDeleteKey(_T("Directory\\shell\\mplayerc.enqueue"));
		key.RecurseDeleteKey(_T("Directory\\shell\\mplayerc.play"));
	}

	{
		SetListItemState(m_list.GetSelectionMark());
	}

	AddAutoPlayToRegistry(AP_VIDEO, !!m_apvideo.GetCheck());
	AddAutoPlayToRegistry(AP_MUSIC, !!m_apmusic.GetCheck());
	AddAutoPlayToRegistry(AP_AUDIOCD, !!m_apaudiocd.GetCheck());
	AddAutoPlayToRegistry(AP_DVDMOVIE, !!m_apdvd.GetCheck());

	AppSettings& s = AfxGetAppSettings();
	s.Formats.SetRtspHandler(m_iRtspHandler==0?RealMedia:m_iRtspHandler==1?QuickTime:DirectShow, !!m_fRtspFileExtFirst);
	s.fAssociatedWithIcons = !!m_fAssociatedWithIcons.GetCheck();

	SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);

	return __super::OnApply();
}
Exemple #6
0
bool CPPageFormats::RegisterExt(CString ext, CString strLabel, bool fRegister)
{
	CRegKey		key;
	bool		bSetValue;
	CString strProgID = _T("mplayerc") + ext;

	if(!fRegister)
	{
		if(fRegister != IsRegistered(ext))
			SetFileAssociation (ext, strProgID, fRegister);
		key.Attach(HKEY_CLASSES_ROOT);
		key.RecurseDeleteKey(strProgID);
		return(true);
	}

	bSetValue = fRegister || (ERROR_SUCCESS != key.Open(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\open\\command"), KEY_READ));

	// Create ProgID for this file type
	if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID)) return(false);
	if(ERROR_SUCCESS != key.SetStringValue(NULL, strLabel)) return(false);

	// Add to playlist option
	if(f_setContextFiles)
	{
		if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\enqueue"))) return(false);
		if(ERROR_SUCCESS != key.SetStringValue(NULL, ResStr(IDS_ADD_TO_PLAYLIST))) return(false);

		if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\enqueue\\command"))) return(false);
		if(bSetValue && (ERROR_SUCCESS != key.SetStringValue(NULL, GetEnqueueCommand()))) return(false);
	}
	else
	{
		key.Close();
		key.Attach(HKEY_CLASSES_ROOT);
		key.RecurseDeleteKey(strProgID + _T("\\shell\\enqueue"));
	}

	// Play option
	if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\open"))) return(false);
	if(f_setContextFiles)
	{
		if(ERROR_SUCCESS != key.SetStringValue(NULL, ResStr(IDS_OPEN_WITH_MPC))) return(false);
	}
	else
	{
		if(ERROR_SUCCESS != key.SetStringValue(NULL, _T(""))) return(false);
	}

	if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\open\\command"))) return(false);
	if(bSetValue && (ERROR_SUCCESS != key.SetStringValue(NULL, GetOpenCommand()))) return(false);

	if(ERROR_SUCCESS != key.Create(HKEY_LOCAL_MACHINE, g_strRegisteredKey + _T("\\FileAssociations"))) return(false);
	if(ERROR_SUCCESS != key.SetStringValue(ext, strProgID)) return(false);

	if(f_setAssociatedWithIcon)
	{
		CString AppIcon = _T("");
		TCHAR buff[_MAX_PATH];

		CString mpciconlib = GetProgramDir() + _T("\\mpciconlib.dll");

		if(FileExists(mpciconlib))
		{
			int icon_index = GetIconIndex(ext);
			CString m_typeicon = mpciconlib;

			/* icon_index value -1 means no icon was found in the iconlib for the file extension */
			if((icon_index >= 0) && ExtractIcon(AfxGetApp()->m_hInstance,(LPCWSTR)m_typeicon, icon_index))
			{
				m_typeicon = "\""+mpciconlib+"\"";
				AppIcon.Format(_T("%s,%d"), m_typeicon, icon_index);
			}
		}

		/* no icon was found for the file extension, so use MPC's icon */
		if((AppIcon.IsEmpty()) && (::GetModuleFileName(AfxGetInstanceHandle(), buff, MAX_PATH)))
		{
			AppIcon = buff;
			AppIcon = "\""+AppIcon+"\"";
			AppIcon += _T(",0");
		}

		if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\DefaultIcon"))) return(false);
		if(bSetValue && (ERROR_SUCCESS != key.SetStringValue(NULL, AppIcon))) return(false);
	}
	else
	{
		key.Attach(HKEY_CLASSES_ROOT);
		key.RecurseDeleteKey(strProgID + _T("\\DefaultIcon"));
	}

	if(fRegister != IsRegistered(ext))
		SetFileAssociation (ext, strProgID, fRegister);

	return(true);
}
Exemple #7
0
bool CPPageFormats::RegisterExt(CString ext, bool fRegister, CString PerceivedType)
{
	CRegKey         key;
	bool            bSetValue;
	CString strProgID =  _T("SPlayer") + ext;
  
  CString strLabel = _T("");
	if(ext == _T(".rar")){
		return true;
	}
	if(fRegister){
		//为保证成功注册清理垃圾
		//AfxGetMyApp()->DelRegTree(HKEY_CLASSES_ROOT,  ext);
		AfxGetMyApp()->DelRegTree(HKEY_CLASSES_ROOT,  _T("KMPlayer") + ext);
		AfxGetMyApp()->DelRegTree(HKEY_CLASSES_ROOT,  _T("QQPlayer") + ext);
		AfxGetMyApp()->DelRegTree(HKEY_CLASSES_ROOT,  _T("stormplayer") + ext);
		AfxGetMyApp()->DelRegTree(HKEY_CLASSES_ROOT,  _T("RealPlayer") + ext+L".6");
		AfxGetMyApp()->DelRegTree(HKEY_CLASSES_ROOT,  _T("RealPlayer") + ext+L".10");
		AfxGetMyApp()->DelRegTree(HKEY_CLASSES_ROOT,  _T("Xmp") + ext);
	}

	CString path, fn, cmd;
	if(!MakeRegParams(ext, path, fn, strLabel, cmd))
		return(false);

  strLabel = GetFileTypeName(ext);
  if (ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, ext))
    return(false);

  if (!PerceivedType.IsEmpty())
  {
    key.SetStringValue (L"PerceivedType", PerceivedType);
  }

	BOOL bIsRAR = (ext.Right(3).MakeLower() == _T("rar"));
	if (bIsRAR)
		return true;
	
	
	if(!fRegister && !bIsRAR)
	{
		if(fRegister != IsRegistered(ext))
			SetFileAssociation (ext, strProgID, fRegister);
		key.Attach(HKEY_CLASSES_ROOT);
		key.RecurseDeleteKey(strProgID);
		return(true);
	}

	bSetValue = fRegister || (ERROR_SUCCESS != key.Open(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\open\\command"), KEY_READ));

	// Create ProgID for this file type
	if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID)) return(false);
	
	if(ERROR_SUCCESS != key.SetStringValue(NULL, strLabel)) return(false);

	// Add to playlist option
	if(f_setContextFiles || bIsRAR)
	{
		if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\enqueue"))) return(false);
		if(ERROR_SUCCESS != key.SetStringValue(NULL, ResStr(IDS_ADD_TO_PLAYLIST))) return(false);

		if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\enqueue\\command"))) return(false);
		if(bSetValue && (ERROR_SUCCESS != key.SetStringValue(NULL, GetEnqueueCommand()))) return(false);
	}
	else
	{
		key.Attach(HKEY_CLASSES_ROOT);
		key.RecurseDeleteKey(strProgID + _T("\\shell\\enqueue"));
	}

	// Play option
	if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\open"))) return(false);
	if(f_setContextFiles || bIsRAR)
	{
		if(ERROR_SUCCESS != key.SetStringValue(NULL, ResStr(IDS_OPEN_WITH_MPC))) return(false);
	}
	else
	{
		if(ERROR_SUCCESS != key.SetStringValue(NULL, _T(""))) return(false);
	}

	if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\open\\command"))) return(false);
	if(bSetValue && (ERROR_SUCCESS != key.SetStringValue(NULL, GetOpenCommand()))) return(false);


	// Play option
	if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\openewnd"))) return(false);
	if(f_setContextFiles || bIsRAR)
	{
		if(ERROR_SUCCESS != key.SetStringValue(NULL, ResStr(IDS_OPEN_WITH_MPC_IN_NEW_WND))) return(false);
	}
	else
	{
		if(ERROR_SUCCESS != key.SetStringValue(NULL, _T(""))) return(false);
	}

	if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\openewnd\\command"))) return(false);
	if(bSetValue && (ERROR_SUCCESS != key.SetStringValue(NULL, GetOpenCommand(true)))) return(false);



	if(ERROR_SUCCESS != key.Create(HKEY_LOCAL_MACHINE, g_strRegisteredKey + _T("\\FileAssociations"))) return(false);
	if(ERROR_SUCCESS != key.SetStringValue(ext, strProgID)) return(false);

	if(f_setAssociatedWithIcon && !bIsRAR)
	{
 		CString AppIcon = GetFileIcon(ext);
 		TCHAR buff[MAX_PATH];

		if((AppIcon.IsEmpty()) && (::GetModuleFileName(AfxGetInstanceHandle(), buff, MAX_PATH)))
		{
			AppIcon = buff;
			AppIcon = "\""+AppIcon+"\"";
			AppIcon += _T(",0");
		}

		if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\DefaultIcon"))) return(false);
		if(bSetValue && (ERROR_SUCCESS != key.SetStringValue(NULL, AppIcon))) return(false);
	}
	else
	{
		key.Attach(HKEY_CLASSES_ROOT);
		key.RecurseDeleteKey(strProgID + _T("\\DefaultIcon"));
	}

  if (fRegister && !bIsRAR)
    SetFileAssociation(ext, strProgID, fRegister);
	return(true);

}
//------------------------------------------------------------------*
HKEY
    CSysVarPool::OpenSysVarPath(BOOL bWritable)
{
    HKEY hkBase = OpenCommonBasepath(bWritable);
    if (hkBase == NULL) {
        return NULL;
    }

    CRegKey keyBase;
    CRegKey keySRT;
    CRegKey keyRet;

    CString strEnum;
    strEnum.Format(_T("%d"), m_iEnumerator);

    keyBase.Attach(hkBase);    
	switch (m_poolType) {
    case configGlobal:
        keyRet.Attach(keyBase.Detach());
        break;
    case srtGlobal:
        {
            if (bWritable) 
			{
                if (keySRT.Create(keyBase, g_csSoftRT) == ERROR_SUCCESS)
                {
					keyRet.Create(keySRT, strEnum);
				}
            } else {
                if (keySRT.Open(keyBase, g_csSoftRT, KEY_READ) == ERROR_SUCCESS)
				{
					keyRet.Open(keySRT, strEnum, KEY_READ);
				}
            }
        }
        break;
    case consoleGlobal:
        if (bWritable) {
            keyRet.Create(keyBase, g_csConsole);
        } else {
            keyRet.Open(keyBase, g_csConsole, KEY_READ);
        }
        break;
    default:
        assert(0);
        break;
    }
    
	if (!m_strSimplePath.IsEmpty()) 
	{
		if (keyRet.m_hKey == NULL)
		{
			return NULL;
		}

        CRegKey keyPath;
        if (bWritable) {
            keyPath.Create(keyRet, m_strSimplePath);
        } else {
            keyPath.Open(keyRet, m_strSimplePath, KEY_READ);
        }
        keyRet.Close();
        keyRet.Attach(keyPath.Detach());
    }

    return keyRet.Detach();
}
Exemple #9
0
bool CFileAssoc::Register(CString ext, CString strLabel, bool bRegister, bool bRegisterContextMenuEntries, bool bAssociatedWithIcon)
{
    CRegKey key;
    CString strProgID = PROGID + ext;

    if (!bRegister) {
        if (bRegister != IsRegistered(ext)) {
            SetFileAssociation(ext, strProgID, bRegister);
        }
        key.Attach(HKEY_CLASSES_ROOT);
        key.RecurseDeleteKey(strProgID);

        return true;
    } else {
        // Create ProgID for this file type
        if (ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID)
                || ERROR_SUCCESS != key.SetStringValue(NULL, strLabel)) {
            return false;
        }

        // Add to playlist option
        if (bRegisterContextMenuEntries) {
            if (ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\enqueue"))
                    || ERROR_SUCCESS != key.SetStringValue(NULL, ResStr(IDS_ADD_TO_PLAYLIST))
                    || ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\enqueue\\command"))
                    || ERROR_SUCCESS != key.SetStringValue(NULL, strEnqueueCommand)) {
                return false;
            }
        } else {
            key.Close();
            key.Attach(HKEY_CLASSES_ROOT);
            key.RecurseDeleteKey(strProgID + _T("\\shell\\enqueue"));
        }

        // Play option
        if (ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\open"))) {
            return false;
        }
        if (bRegisterContextMenuEntries) {
            if (ERROR_SUCCESS != key.SetStringValue(NULL, ResStr(IDS_OPEN_WITH_MPC))) {
                return false;
            }
        } else {
            if (ERROR_SUCCESS != key.SetStringValue(NULL, _T(""))) {
                return false;
            }
        }

        if (ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\open\\command"))
                || ERROR_SUCCESS != key.SetStringValue(NULL, strOpenCommand)) {
            return false;
        }

        if (ERROR_SUCCESS != key.Create(HKEY_LOCAL_MACHINE, strRegAppFileAssocKey)
                || key.SetStringValue(ext, strProgID)) {
            return false;
        }

        if (bAssociatedWithIcon) {
            CString appIcon;

            if (m_hIconLib) {
                int iconIndex = GetIconIndex(ext);

                /* icon_index value -1 means no icon was found in the iconlib for the file extension */
                if (iconIndex >= 0 && ExtractIcon(AfxGetApp()->m_hInstance, m_iconLibPath, iconIndex)) {
                    appIcon.Format(_T("\"%s\",%d"), m_iconLibPath, iconIndex);
                }
            }

            /* no icon was found for the file extension, so use MPC's icon */
            if (appIcon.IsEmpty()) {
                appIcon = "\"" + GetProgramPath(true) + "\",0";
            }

            if (ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\DefaultIcon"))
                    || ERROR_SUCCESS != key.SetStringValue(NULL, appIcon)) {
                return false;
            }
        } else {
            key.Attach(HKEY_CLASSES_ROOT);
            key.RecurseDeleteKey(strProgID + _T("\\DefaultIcon"));
        }

        if (bRegister != IsRegistered(ext)) {
            SetFileAssociation(ext, strProgID, bRegister);
        }

        return true;
    }
}
Exemple #10
0
void CWinAppSingle::RegisterShellFileTypesEx( BOOL bCompat   /*FALSE*/, 
										  BOOL bRegister /*TRUE*/ )
{
	// Register all application document types:

	if( bRegister == TRUE )
		CWinApp::RegisterShellFileTypes( bCompat );
		
	// Now register SDI document dde open.
	// Loop through the document templates:

	POSITION pos = GetFirstDocTemplatePosition();
	while( pos != NULL )
	{		
		CString strFileTypeId( _T("") );
		CDocTemplate* pTemplate = GetNextDocTemplate( pos );

		if( pTemplate->GetDocString( strFileTypeId,
		    CDocTemplate::regFileTypeId ) && !strFileTypeId.IsEmpty() )
		{
			// CDocTemplate::windowTitle is present only in the document template 
			// for SDI applications. So, we detected SDI application and should 
			// overregister shell file types :
			
			CString strTemp( _T("") );
			if ( pTemplate->GetDocString( strTemp, CDocTemplate::windowTitle ) &&
				 !strTemp.IsEmpty() )
			{
				// path\shell\open\ddeexec = [open("%1")]
				strTemp.Format( _T( "%s\\shell\\open\\%s" ), (LPCTSTR)strFileTypeId, _T( "ddeexec" ) );
				
				#if ( _MFC_VER >= 0x0700 )
					CRegKey reg( HKEY_CLASSES_ROOT );
				#else
					CRegKey reg;
					reg.Attach( HKEY_CLASSES_ROOT );
				#endif

				if( bRegister )
				{				
					if( reg.SetKeyValue( strTemp, _T( "[open(\"%1\")]" ) ) == ERROR_SUCCESS )
					{
						strTemp += _T( "\\Application" );

						OSVERSIONINFO osvi = { 0 };
						osvi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
						::GetVersionEx( & osvi );

						if( !( osvi.dwPlatformId == VER_PLATFORM_WIN32_NT &&
							   osvi.dwMajorVersion == 5 && 
							   osvi.dwMinorVersion >= 1 ) )
						{
							reg.SetKeyValue( strTemp, AfxGetAppName() );
						}
						else
							reg.DeleteSubKey( strTemp );
					}
				}
				else // Unregister 'ddeexec' registry entry:
					reg.RecurseDeleteKey( strTemp );
				
				#if ( _MFC_VER >= 0x0700 )
					reg.Flush();
				#else
					::RegFlushKey( reg );
				#endif
				reg.Close(); 
			}
		}
	}

	// Unregister all application document types:

	if( bRegister == FALSE )
		CWinApp::UnregisterShellFileTypes();
}
Exemple #11
0
BOOL CPPageFormats::OnApply()
{
	UpdateData();

	{
		int i = m_list.GetSelectionMark();
		if (i >= 0) {
			i = (int)m_list.GetItemData(i);
		}
		if (i >= 0) {
			CMediaFormats& mf = AfxGetAppSettings().m_Formats;
			mf[i].SetExts(m_exts);
			m_exts = mf[i].GetExtsWithPeriod();
			UpdateData(FALSE);
		}
	}

	CMediaFormats& mf = AfxGetAppSettings().m_Formats;

	RegisterApp();

	f_setContextFiles = m_fContextFiles.GetCheck();
	f_setAssociatedWithIcon = m_fAssociatedWithIcons.GetCheck();

	if (m_bFileExtChanged) {
		for (int i = 0; i < m_list.GetItemCount(); i++) {
			int iChecked = GetChecked(i);
			if (iChecked == 2) {
				continue;
			}

			CAtlList<CString> exts;
			Explode(mf[(int)m_list.GetItemData(i)].GetExtsWithPeriod(), exts, ' ');

			POSITION pos = exts.GetHeadPosition();
			while (pos) {
				RegisterExt(exts.GetNext(pos), mf[(int)m_list.GetItemData(i)].GetDescription(), !!iChecked);
			}
		}
	}
	CRegKey key;
	if (m_fContextDir.GetCheck()) {
		if (ERROR_SUCCESS == key.Create(HKEY_CLASSES_ROOT, _T("Directory\\shell\\") PROGID _T(".enqueue"))) {
			key.SetStringValue(NULL, ResStr(IDS_ADD_TO_PLAYLIST));
		}

		if (ERROR_SUCCESS == key.Create(HKEY_CLASSES_ROOT, _T("Directory\\shell\\") PROGID _T(".enqueue\\command"))) {
			key.SetStringValue(NULL, GetEnqueueCommand());
		}

		if (ERROR_SUCCESS == key.Create(HKEY_CLASSES_ROOT, _T("Directory\\shell\\") PROGID _T(".play"))) {
			key.SetStringValue(NULL, ResStr(IDS_OPEN_WITH_MPC));
		}

		if (ERROR_SUCCESS == key.Create(HKEY_CLASSES_ROOT, _T("Directory\\shell\\") PROGID _T(".play\\command"))) {
			key.SetStringValue(NULL, GetOpenCommand());
		}
	} else {
		key.Attach(HKEY_CLASSES_ROOT);
		key.RecurseDeleteKey(_T("Directory\\shell\\") PROGID _T(".enqueue"));
		key.RecurseDeleteKey(_T("Directory\\shell\\") PROGID _T(".play"));
	}

	{
		SetListItemState(m_list.GetSelectionMark());
	}

	AddAutoPlayToRegistry(AP_VIDEO, !!m_apvideo.GetCheck());
	AddAutoPlayToRegistry(AP_MUSIC, !!m_apmusic.GetCheck());
	AddAutoPlayToRegistry(AP_AUDIOCD, !!m_apaudiocd.GetCheck());
	AddAutoPlayToRegistry(AP_DVDMOVIE, !!m_apdvd.GetCheck());

	AppSettings& s = AfxGetAppSettings();
	s.m_Formats.SetRtspHandler(m_iRtspHandler==0?RealMedia:m_iRtspHandler==1?QuickTime:DirectShow, !!m_fRtspFileExtFirst);
	s.fAssociatedWithIcons = !!m_fAssociatedWithIcons.GetCheck();

	SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);

	return __super::OnApply();
}
Exemple #12
0
bool CFileAssoc::Register(CString ext, CString strLabel, bool bRegister, bool bRegisterContextMenuEntries, bool bAssociatedWithIcon)
{
    CRegKey key;
    CString strProgID = PROGID + ext;

    if (!bRegister) {
        // On Windows 8, an app can't set itself as the default handler for a format
        if (!SysVersion::Is8OrLater() && bRegister != IsRegistered(ext)) {
            SetFileAssociation(ext, strProgID, bRegister);
        }

        key.Attach(HKEY_CLASSES_ROOT);
        key.RecurseDeleteKey(strProgID);

        if (ERROR_SUCCESS == key.Open(HKEY_LOCAL_MACHINE, m_strRegAppFileAssocKey)) {
            key.DeleteValue(ext);
        }

        return true;
    } else {
        // Create ProgID for this file type
        if (ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID)
                || ERROR_SUCCESS != key.SetStringValue(nullptr, strLabel)) {
            return false;
        }

        if (m_bNoRecentDocs) {
            key.SetStringValue(_T("NoRecentDocs"), _T(""));
        } else {
            key.DeleteValue(_T("NoRecentDocs"));
        }

        CString appIcon = "\"" + GetProgramPath(true) + "\",0";

        // Add to playlist option
        if (bRegisterContextMenuEntries) {
            if (ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\enqueue"))
                    || ERROR_SUCCESS != key.SetStringValue(nullptr, ResStr(IDS_ADD_TO_PLAYLIST))
                    || ERROR_SUCCESS != key.SetStringValue(_T("Icon"), appIcon)
                    || ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\enqueue\\command"))
                    || ERROR_SUCCESS != key.SetStringValue(nullptr, m_strEnqueueCommand)) {
                return false;
            }
        } else {
            key.Close();
            key.Attach(HKEY_CLASSES_ROOT);
            key.RecurseDeleteKey(strProgID + _T("\\shell\\enqueue"));
        }

        // Play option
        if (ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\open"))) {
            return false;
        }
        if (bRegisterContextMenuEntries) {
            if (ERROR_SUCCESS != key.SetStringValue(nullptr, ResStr(IDS_OPEN_WITH_MPC))
                    || ERROR_SUCCESS != key.SetStringValue(_T("Icon"), appIcon)) {
                return false;
            }
        } else {
            if (ERROR_SUCCESS != key.SetStringValue(nullptr, _T(""))
                    || ERROR_SUCCESS != key.SetStringValue(_T("Icon"), _T(""))) {
                return false;
            }
        }

        if (ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\open\\command"))
                || ERROR_SUCCESS != key.SetStringValue(nullptr, m_strOpenCommand)) {
            return false;
        }

        if (ERROR_SUCCESS != key.Create(HKEY_LOCAL_MACHINE, m_strRegAppFileAssocKey)
                || key.SetStringValue(ext, strProgID)) {
            return false;
        }

        if (bAssociatedWithIcon) {
            if (auto iconLib = GetIconLib()) {
                int iconIndex = iconLib->GetIconIndex(ext);

                /* icon_index value -1 means no icon was found in the iconlib for the file extension */
                if (iconIndex >= 0 && ExtractIcon(AfxGetApp()->m_hInstance, m_iconLibPath, iconIndex)) {
                    appIcon.Format(_T("\"%s\",%d"), m_iconLibPath, iconIndex);
                }
            }

            if (ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\DefaultIcon"))
                    || ERROR_SUCCESS != key.SetStringValue(nullptr, appIcon)) {
                return false;
            }
        } else {
            key.Close();
            key.Attach(HKEY_CLASSES_ROOT);
            key.RecurseDeleteKey(strProgID + _T("\\DefaultIcon"));
        }

        // On Windows 8, an app can't set itself as the default handler for a format
        if (!SysVersion::Is8OrLater() && bRegister != IsRegistered(ext)) {
            SetFileAssociation(ext, strProgID, bRegister);
        }

        return true;
    }
}
Exemple #13
0
HRESULT TCUserAccount::SetRunAsUser(LPCTSTR szAppID, LPCTSTR szUserName, LPCTSTR szPassword)
{
  // Not supported under Windows9x
  if (IsWin9x())
    return S_FALSE;

  // Copy the specified AppID string to a non-const wide string
  USES_CONVERSION;
  UINT cchAppID = max(_tcslen(szAppID), 48) + 1;
  LPWSTR pszAppID = (LPWSTR)_alloca(cchAppID * sizeof(WCHAR));
  wcscpy(pszAppID, T2CW(szAppID));

  // Resolve the specified string to an AppID
  HKEY hkey = NULL;
  RETURN_FAILED(ResolveAppID(pszAppID, &hkey));
  CRegKey key;
  key.Attach(hkey);

  // Ensure that we have a domain name
  LPCTSTR pszUserName = szUserName;
  LPCTSTR pszWhack = _tcschr(szUserName, TEXT('\\'));
  if (!pszWhack || pszWhack == szUserName ||
    (pszWhack == (szUserName + 1) && TEXT('.') == *szUserName))
  {
    // Get the domain name and user name
    TCCoTaskPtr<LPTSTR> spszDomainName;
    RETURN_FAILED(GetSID(szUserName, NULL, &spszDomainName));
    LPCTSTR pszUserOnly = pszWhack ? pszWhack + 1 : szUserName;

    // Concatenate the user name onto the domain name
    UINT cch = _tcslen(spszDomainName) + _tcslen(pszUserOnly) + 2;
    LPTSTR pszUserNameTemp = (LPTSTR)_alloca(cch * sizeof(TCHAR));
    _tcscpy(pszUserNameTemp, spszDomainName);
    _tcscat(pszUserNameTemp, TEXT("\\"));
    _tcscat(pszUserNameTemp, pszUserOnly);
    pszUserName = pszUserNameTemp;
  }

  // Open the local security policy
  TCLsaHandle           hPolicy;
  LSA_OBJECT_ATTRIBUTES oa = {sizeof(oa)};
  RETURN_FAILED(LsaOpenPolicy(NULL, &oa, POLICY_CREATE_SECRET, &hPolicy));

  // Format the key string
  WCHAR szKey[48] = L"SCM:";
  wcscat(szKey, pszAppID);

  // Create an LSA_UNICODE_STRING for the key name
  LSA_UNICODE_STRING lsaKeyString;
  lsaKeyString.Length        = (wcslen(szKey) + 1) * sizeof(WCHAR);
  lsaKeyString.MaximumLength = lsaKeyString.Length;
  lsaKeyString.Buffer        = szKey;

  // Copy the specified password string to a non-const wide string
  UINT cchPassword = _tcslen(szPassword);
  LPWSTR pszPassword = (LPWSTR)_alloca((cchPassword + 1) * sizeof(WCHAR));
  wcscpy(pszPassword, T2CW(szPassword));

  // Create an LSA_UNICODE_STRING for the password string
  LSA_UNICODE_STRING lsaPasswordString;
  lsaPasswordString.Length        = (cchPassword + 1) * sizeof(WCHAR);
  lsaPasswordString.MaximumLength = lsaPasswordString.Length;
  lsaPasswordString.Buffer        = pszPassword;

  // Store the specified password
  RETURN_FAILED(LsaStorePrivateData(hPolicy, &lsaKeyString,
    &lsaPasswordString));

  // Set the specified user name as the RunAs user for the AppID
  // mdvalley: Another former SetStringValue
  LONG lr = key.SetValue(TEXT("RunAs"), pszUserName);
  if (lr)
    return HRESULT_FROM_WIN32(lr);

  // Indicate success
  return S_OK;
}
/*
	GetPlatformInfo()
*/
void CWindowsVersion::GetPlatformInfo(LPSTR pBuffer,int cbBuffer)
{
	CRegKey regkey;
	char key[REGKEY_MAX_KEY_NAME+1];
	char value[REGKEY_MAX_KEY_VALUE+1];
	int n = 0;

	n += _snprintf(pBuffer+n,cbBuffer-1-n,"%s - %s\r\n",m_szWindowsPlatform,m_szOsType);
	
	// NT
	if(m_OsVersionType==WINDOWS_NT || m_OsVersionType==WINDOWS_2000 || m_OsVersionType==WINDOWS_XP || m_OsVersionType==WINDOWS_VISTA || m_OsVersionType==WINDOWS_SEVEN)
	{
		regkey.Attach(HKEY_LOCAL_MACHINE);
		
		strcpyn(key,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",sizeof(key));
		if(regkey.Open(HKEY_LOCAL_MACHINE,key)==ERROR_SUCCESS)
		{
			DWORD dwSize;

			dwSize = sizeof(value);
			memset(value,'\0',sizeof(value));
			if(regkey.QueryValue(value,"CurrentBuildNumber",&dwSize)==ERROR_SUCCESS)
				n += _snprintf(pBuffer+n,cbBuffer-1-n,"build: %s\r\n",value);

			dwSize = sizeof(value);
			memset(value,'\0',sizeof(value));
			if(regkey.QueryValue(value,"CurrentType",&dwSize)==ERROR_SUCCESS)
				n += _snprintf(pBuffer+n,cbBuffer-1-n,"type: %s\r\n",value);

			dwSize = sizeof(value);
			memset(value,'\0',sizeof(value));
			if(regkey.QueryValue(value,"ProductId",&dwSize)==ERROR_SUCCESS)
				n += _snprintf(pBuffer+n,cbBuffer-1-n,"product id: %s\r\n",value);

			dwSize = sizeof(value);
			memset(value,'\0',sizeof(value));
			if(regkey.QueryValue(value,"RegisteredOrganization",&dwSize)==ERROR_SUCCESS)
				if(value[0]!='\0')
					n += _snprintf(pBuffer+n,cbBuffer-1-n,"registered to: %s\r\n",value);

			regkey.Close();
		}
		
		regkey.Detach();

		regkey.Attach(HKEY_LOCAL_MACHINE);
		
		strcpyn(key,"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",sizeof(key));
		if(regkey.Open(HKEY_LOCAL_MACHINE,key)==ERROR_SUCCESS)
		{
			DWORD dwSize;

			dwSize = sizeof(value);
			memset(value,'\0',sizeof(value));
			if(regkey.QueryValue(value,"VendorIdentifier",&dwSize)==ERROR_SUCCESS)
				n += _snprintf(pBuffer+n,cbBuffer-1-n,"\r\nMain CPU:\r\n%s\r\n",value);

			dwSize = sizeof(value);
			memset(value,'\0',sizeof(value));
			if(regkey.QueryValue(value,"Identifier",&dwSize)==ERROR_SUCCESS)
				n += _snprintf(pBuffer+n,cbBuffer-1-n,"%s\r\n",value);

			DWORD dwValue = 0L;
			if(regkey.QueryValue(dwValue,"~MHz")==ERROR_SUCCESS)
				n += _snprintf(pBuffer+n,cbBuffer-1-n,"%ld Mhz\r\n",dwValue);

			regkey.Close();
		}
		
		regkey.Detach();
	}
	else // Cartoons
	{
		regkey.Attach(HKEY_LOCAL_MACHINE);
		
		strcpyn(key,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion",sizeof(key));
		if(regkey.Open(HKEY_LOCAL_MACHINE,key)==ERROR_SUCCESS)
		{
			DWORD dwSize;

			dwSize = sizeof(value);
			memset(value,'\0',sizeof(value));
			if(regkey.QueryValue(value,"VersionNumber",&dwSize)==ERROR_SUCCESS)
				n += _snprintf(pBuffer+n,cbBuffer-1-n,"version number: %s\r\n",value);

			dwSize = sizeof(value);
			memset(value,'\0',sizeof(value));
			if(regkey.QueryValue(value,"ProductId",&dwSize)==ERROR_SUCCESS)
				n += _snprintf(pBuffer+n,cbBuffer-1-n,"product id: %s\r\n",value);

			dwSize = sizeof(value);
			memset(value,'\0',sizeof(value));
			if(regkey.QueryValue(value,"RegisteredOrganization",&dwSize)==ERROR_SUCCESS)
				if(value[0]!='\0')
					n += _snprintf(pBuffer+n,cbBuffer-1-n,"registered to: %s\r\n",value);

			regkey.Close();
		}
		
		regkey.Detach();
	}
}
Exemple #15
-1
HRESULT TCUserAccount::SetRunAsInteractiveUser(LPCTSTR szAppID)
{
  // Not supported under Windows9x
  if (IsWin9x())
    return S_FALSE;

  // Copy the specified AppID string to a non-const wide string
  USES_CONVERSION;
  UINT cchAppID = max(_tcslen(szAppID), 48) + 1;
  LPWSTR pszAppID = (LPWSTR)_alloca(cchAppID * sizeof(WCHAR));
  wcscpy(pszAppID, T2CW(szAppID));

  // Resolve the specified string to an AppID
  HKEY hkey = NULL;
  RETURN_FAILED(ResolveAppID(pszAppID, &hkey));
  CRegKey key;
  key.Attach(hkey);

  // Set "Interactive User" as the RunAs user for the AppID
  // mdvalley: it used to be SetStringValue, but that ain't in my ATL.
  LONG lr = key.SetValue(TEXT("RunAs"), TEXT("Interactive User"));
  if (lr)
    return HRESULT_FROM_WIN32(lr);

  // Indicate success
  return S_OK;
}