bool CustomPropertyStorage::SetProperty(const CStdString& sName, const CStdString& sValue ) { if( sName.IsEmpty() || sValue.IsEmpty() ) { CStdString sError; sError.Format(_T("Invalid arguments passed to SetProperty , Property name is %s , Value is %s") , sName.c_str() , sValue.c_str()); LOG_WS_ERROR(sError.c_str()); return false; } try { USES_CONVERSION; HRESULT hr = S_OK; IPropertySetStoragePtr pPropSetStg = NULL; IPropertyStoragePtr pPropStg = NULL; hr = StgOpenStorageEx( T2W((LPTSTR)m_sFileName.c_str()), STGM_SHARE_EXCLUSIVE | STGM_READWRITE | STGFMT_STORAGE , STGFMT_DOCFILE , 0, NULL, NULL, IID_IPropertySetStorage, reinterpret_cast<void**>(&pPropSetStg) ); if( FAILED(hr) || (pPropSetStg == NULL) ) { LOG_WS_ERROR(_T("Failed StgCreateStorageEx")); return false; } hr = pPropSetStg->Create( FMTID_UserDefinedProperties, NULL, PROPSETFLAG_DEFAULT, STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE , &pPropStg ); if( FAILED(hr) || (pPropStg == NULL)) { LOG_WS_ERROR(_T("Failed IPropertySetStorage::Create")); return false; } PROPSPEC propspec; ZeroMemory(&propspec, sizeof(PROPSPEC)); propspec.ulKind = PRSPEC_LPWSTR; propspec.lpwstr = T2OLE((LPTSTR)sName.c_str()); PROPVARIANT propvarWrite; PropVariantInit(&propvarWrite); propvarWrite.vt = VT_LPWSTR; propvarWrite.pwszVal = T2W((LPTSTR)sValue.c_str()); hr = pPropStg->WriteMultiple( 1, &propspec, &propvarWrite, PID_FIRST_USABLE ); if( FAILED(hr) ) { LOG_WS_ERROR(_T("Failed IPropertyStorage::WriteMultiple")); return false; } PROPID propidDictionary = PID_DICTIONARY; WCHAR *pwszFriendlyName = L"Workshare Custom Document Property"; hr = pPropStg->WritePropertyNames( 1, &propidDictionary, &pwszFriendlyName ); if( FAILED(hr) ) { LOG_WS_ERROR(_T("Failed to write propertynames")); return false; } return SUCCEEDED(pPropStg->Commit(STGC_DEFAULT)); } catch(...) { CStdString sError; sError.Format(_T("Unexpected error while trying to SetCustomProperty for %s .") , sName.c_str() ); LOG_WS_ERROR(sError); return false; } }
bool CMFCMDIPrintPreviewView::LoadUrl(LPCTSTR url) { USES_CONVERSION; ASSERT(::IsWindow(m_hWnd)); return (::HTMLayoutLoadFile(m_hWnd, T2W(url)) != 0); }
bool CustomPropertyStorage::DoesPropertyExist(const CStdString sName) const { if(sName.IsEmpty()) { LOG_WS_ERROR(_T("we have been passed an empty custom document property.")); return false; } try { USES_CONVERSION; HRESULT hr = S_OK; IPropertySetStoragePtr pPropSetStg = NULL; IPropertyStoragePtr pPropStg = NULL; hr = StgOpenStorageEx( CStdStringW(m_sFileName.c_str()), STGM_READ|STGM_SHARE_DENY_WRITE, STGFMT_ANY, 0, NULL, NULL, IID_IPropertySetStorage, reinterpret_cast<void**>(&pPropSetStg) ); if( FAILED(hr) || (pPropSetStg == NULL)) { LOG_WS_ERROR(_T("Failed StgOpenStorageEx")); return false; } hr = pPropSetStg->Open(FMTID_UserDefinedProperties, STGM_READ|STGM_SHARE_EXCLUSIVE, &pPropStg ); if( FAILED(hr) || (pPropStg == NULL)) { LOG_WS_ERROR(_T("Failed StgOpenStorageEx")); return false; } PROPVARIANT propvar; PropVariantInit(&propvar); PROPSPEC propspec; ZeroMemory(&propspec, sizeof(PROPSPEC)); PropVariantInit( &propvar ); propspec.ulKind = PRSPEC_LPWSTR; propspec.lpwstr = T2W((LPTSTR)sName.c_str()); hr = pPropStg->ReadMultiple( 1, &propspec, &propvar ); if( FAILED(hr) ) { LOG_WS_ERROR(_T("Failed to ReadMultiple.")); return false; } CStdString sValue = ComConvertUtils::PropVariantToString(propvar); if(sValue.IsEmpty()) return false; return true; } catch(...) { CStdString sError; sError.Format(_T("Unexpected error while determining %s property exists ") , sName.c_str() ); LOG_WS_ERROR(sError); return false; } return false; }
void AudioRendererSettings::LoadSettingsFromRegistry() { USES_CONVERSION; // this is required for T2W macro Log("Loading settings from registry"); HKEY hKey; char* lpData = new char[MAX_REG_LENGTH]; // settings from Reclock - watch CPU usage when enabling these! /*bool usequickseek = false; bool useaafilter = false; //seems clearer without it int aafiltertaps = 56; //Def=32 doesnt matter coz its not used int seqms = 120; //reclock original is 82 int seekwinms = 28; //reclock original is 28 int overlapms = seekwinms; //reduces cutting sound if this is large int seqmslfe = 180; //larger value seems to preserve low frequencies better int seekwinmslfe = 42; //as percentage of seqms int overlapmslfe = seekwinmslfe; //reduces cutting sound if this is large */ LPCTSTR WASAPIPreferredDeviceData = new TCHAR[MAX_REG_LENGTH]; ZeroMemory((void*)WASAPIPreferredDeviceData, MAX_REG_LENGTH); // Try to access the setting root "Software\Team MediaPortal\Audio Renderer" RegOpenKeyEx(HKEY_CURRENT_USER, folder, NULL, KEY_ALL_ACCESS, &hKey); if (hKey) { ReadRegistryKeyDword(hKey, enableTimestretching, enableTimestretchingData); ReadRegistryKeyDword(hKey, WASAPIExclusive, WASAPIExclusiveData); ReadRegistryKeyDword(hKey, WASAPIUseEventMode, WASAPIUseEventModeData); ReadRegistryKeyDword(hKey, devicePeriod, devicePeriodData); ReadRegistryKeyDword(hKey, AC3Encoding, AC3EncodingData); ReadRegistryKeyDword(hKey, AC3bitrate, AC3bitrateData); ReadRegistryKeyDword(hKey, maxBias, maxBiasData); ReadRegistryKeyDword(hKey, minBias, minBiasData); ReadRegistryKeyDword(hKey, audioDelay, audioDelayData); ReadRegistryKeyDword(hKey, logSampleTimes, logSampleTimesData); ReadRegistryKeyDword(hKey, logDebug, logDebugData); ReadRegistryKeyDword(hKey, HWBasedRefClock, HWBasedRefClockData); ReadRegistryKeyDword(hKey, enableSyncAdjustment, enableSyncAdjustmentData); ReadRegistryKeyDword(hKey, forceSamplingRate, forceSamplingRateData); ReadRegistryKeyDword(hKey, forceBitDepth, forceBitDepthData); ReadRegistryKeyDword(hKey, resamplingQuality, resamplingQualityData); ReadRegistryKeyDword(hKey, speakerConfig, speakerConfigData); ReadRegistryKeyDword(hKey, forceChannelMixing, forceChannelMixingData); ReadRegistryKeyDword(hKey, releaseDeviceOnStop, releaseDeviceOnStopData); ReadRegistryKeyDword(hKey, expandMonoToStereo, expandMonoToStereoData); // SoundTouch quality settings ReadRegistryKeyDword(hKey, quality_USE_QUICKSEEK, quality_USE_QUICKSEEKData); ReadRegistryKeyDword(hKey, quality_USE_AA_FILTER, quality_USE_AA_FILTERData); ReadRegistryKeyDword(hKey, quality_AA_FILTER_LENGTH, quality_AA_FILTER_LENGTHData); ReadRegistryKeyDword(hKey, quality_SEQUENCE_MS, quality_SEQUENCE_MSData); ReadRegistryKeyDword(hKey, quality_SEEKWINDOW_MS, quality_SEEKWINDOW_MSData); ReadRegistryKeyDword(hKey, quality_OVERLAP_MS, quality_OVERLAP_MSData); ReadRegistryKeyString(hKey, WASAPIPreferredDevice, WASAPIPreferredDeviceData); Log(" EnableTimestrecthing: %d", enableTimestretchingData); Log(" WASAPIExclusive: %d", WASAPIExclusiveData); Log(" WASAPIUseEventMode: %d", WASAPIUseEventModeData); Log(" AC3Encoding: %d (0 = disabled, 1 = auto, 2 = forced)", AC3EncodingData); Log(" AC3bitrate: %d", AC3bitrateData); Log(" MaxBias: %d", maxBiasData); Log(" MinBias: %d", minBiasData); Log(" AudioDelay: %d", audioDelayData); Log(" LogSampleTimes: %d", logSampleTimesData); Log(" LogDebug: %d", logDebugData); Log(" HWBasedRefClock: %d", HWBasedRefClockData); Log(" EnableSyncAdjustment: %d", enableSyncAdjustmentData); Log(" ForceSamplingRate: %d", forceSamplingRateData); Log(" ForceBitDepth: %d", forceBitDepthData); Log(" ResamplingQuality: %s", ResamplingQualityAsString(resamplingQualityData)); Log(" SpeakerConfig: %d", speakerConfigData); Log(" ForceChannelMixing: %d", forceChannelMixingData); Log(" ReleaseDeviceOnStop: %d", releaseDeviceOnStopData); Log(" ExpandMonoToStereo: %d", expandMonoToStereoData); Log(" quality_USE_QUICKSEEK: %d", quality_USE_QUICKSEEKData); Log(" quality_USE_AA_FILTER: %d", quality_USE_AA_FILTERData); Log(" quality_AA_FILTER_LENGTH: %d", quality_AA_FILTER_LENGTHData); Log(" quality_SEQUENCE_MS: %d", quality_SEQUENCE_MSData); Log(" quality_SEEKWINDOW_MS: %d", quality_SEEKWINDOW_MSData); Log(" quality_OVERLAP_MS: %d", quality_OVERLAP_MSData); Log(" DevicePeriod: %d (1 = minimal, 0 = driver default, other user defined)", devicePeriodData); Log(" WASAPIPreferredDevice: %s", WASAPIPreferredDeviceData); m_bUseWASAPI = true; if (enableTimestretchingData > 0) m_bUseTimeStretching = true; else m_bUseTimeStretching = false; if (WASAPIExclusiveData > 0) m_WASAPIShareMode = AUDCLNT_SHAREMODE_EXCLUSIVE; else m_WASAPIShareMode = AUDCLNT_SHAREMODE_SHARED; if (WASAPIUseEventModeData > 0) m_bWASAPIUseEventMode = true; else m_bWASAPIUseEventMode = false; if (expandMonoToStereoData > 0) m_bExpandMonoToStereo = true; else m_bExpandMonoToStereo = false; if (AC3EncodingData == DISABLED || AC3EncodingData == AUTO || AC3EncodingData == FORCED) m_lAC3Encoding = AC3EncodingData; else m_lAC3Encoding = 0; m_dMaxBias = (double)maxBiasData / 10000.0; m_dMinBias = (double)minBiasData / 10000.0; m_lAudioDelay = audioDelayData; if (logSampleTimesData > 0) m_bLogSampleTimes = true; else m_bLogSampleTimes = false; if (logDebugData > 0) m_bLogDebug = true; else m_bLogDebug = false; if (HWBasedRefClockData > 0) m_bHWBasedRefClock = true; else m_bHWBasedRefClock = false; if (enableSyncAdjustmentData > 0) m_bEnableSyncAdjustment = true; else m_bEnableSyncAdjustment = false; bool AC3EncodingForced = AC3EncodingData == FORCED; bool sampleRateAllowed = AllowedValue(gAllowedSampleRates, sizeof(gAllowedSampleRates) / sizeof(int), forceSamplingRateData); bool bitDepthAllowed = AllowedValue(gAllowedBitDepths, sizeof(gAllowedBitDepths) / sizeof(int), forceBitDepthData); if (AC3EncodingForced) { if (sampleRateAllowed && (forceSamplingRateData != 48000 && forceSamplingRateData != 44100)) { Log(" Warning: AC3 encoding forced and sampling rate set to non-matching!"); sampleRateAllowed = false; } } else if (AC3EncodingData == AUTO && (forceSamplingRateData != 48000 && forceSamplingRateData != 44100 && forceSamplingRateData != 0)) Log(" Warning: Using other than 48000 hz or 44100 hz sampling rates will disable AC3 encoding!"); if (sampleRateAllowed || forceSamplingRateData == 0) m_nForceSamplingRate = forceSamplingRateData; else { m_nForceSamplingRate = 0; if (forceSamplingRateData != 0) Log(" invalid forced sample rate!"); } if (bitDepthAllowed && !AC3EncodingForced || forceBitDepthData == 0) m_nForceBitDepth = forceBitDepthData; else { m_nForceBitDepth = 0; if (forceBitDepthData != 0) Log(" invalid forced bit depth!"); } if (AllowedValue(gAllowedResamplingQualities, sizeof(gAllowedResamplingQualities) / sizeof(int), resamplingQualityData)) m_nResamplingQuality = resamplingQualityData; else { m_nResamplingQuality = 4; Log(" invalid resampling quality setting, using 4 (SRC_LINEAR)"); } if (AllowedValue(gAllowedAC3bitrates, sizeof(gAllowedAC3bitrates) / sizeof(int), AC3bitrateData)) m_AC3bitrate = AC3bitrateData * 1000; else { m_AC3bitrate = DEFAULT_AC3_BITRATE; Log(" invalid AC3 bitrate, using 448"); } m_hnsPeriod = devicePeriodData; if (forceChannelMixingData > 0) m_bForceChannelMixing = true; else m_bForceChannelMixing = false; // TODO validate channel mask if (speakerConfigData > 0) { m_lSpeakerConfig = speakerConfigData; m_lSpeakerCount = ChannelCount(m_lSpeakerConfig); if (AC3EncodingForced && m_lSpeakerCount > 6 && m_bForceChannelMixing) { m_lSpeakerConfig = KSAUDIO_SPEAKER_5POINT1_SURROUND; m_lSpeakerCount = 6; Log(" Warning: incompatible settings. ForceChannelMixing + AC3 encoding forced + more than 6 channels"); } } else m_lSpeakerConfig = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; if (releaseDeviceOnStopData > 0) m_bReleaseDeviceOnStop = true; else m_bReleaseDeviceOnStop = false; if (quality_USE_QUICKSEEKData > 0) m_bQuality_USE_QUICKSEEK = true; else m_bQuality_USE_QUICKSEEK = false; if (quality_USE_AA_FILTERData > 0) m_bQuality_USE_AA_FILTER = true; else m_bQuality_USE_AA_FILTER = false; delete[] m_wWASAPIPreferredDeviceId; m_wWASAPIPreferredDeviceId = new WCHAR[MAX_REG_LENGTH]; wcsncpy(m_wWASAPIPreferredDeviceId, T2W(WASAPIPreferredDeviceData), MAX_REG_LENGTH); delete[] WASAPIPreferredDeviceData; } else // no settings in registry, create default values { Log("Failed to open %s", folder); Log("Initializing registry with default settings"); LONG result = RegCreateKeyEx(HKEY_CURRENT_USER, folder, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL); if (result == ERROR_SUCCESS) { Log("Success creating master key"); WriteRegistryKeyDword(hKey, enableTimestretching, enableTimestretchingData); WriteRegistryKeyDword(hKey, WASAPIExclusive, WASAPIExclusiveData); WriteRegistryKeyDword(hKey, WASAPIUseEventMode, WASAPIUseEventModeData); WriteRegistryKeyDword(hKey, devicePeriod, devicePeriodData); WriteRegistryKeyDword(hKey, AC3Encoding, AC3EncodingData); WriteRegistryKeyDword(hKey, AC3bitrate, AC3bitrateData); WriteRegistryKeyDword(hKey, maxBias, maxBiasData); WriteRegistryKeyDword(hKey, minBias, minBiasData); WriteRegistryKeyDword(hKey, audioDelay, audioDelayData); WriteRegistryKeyDword(hKey, logSampleTimes, logSampleTimesData); WriteRegistryKeyDword(hKey, logDebug, logDebugData); WriteRegistryKeyDword(hKey, HWBasedRefClock, HWBasedRefClockData); WriteRegistryKeyDword(hKey, enableSyncAdjustment, enableSyncAdjustmentData); WriteRegistryKeyDword(hKey, forceSamplingRate, forceSamplingRateData); WriteRegistryKeyDword(hKey, forceBitDepth, forceBitDepthData); WriteRegistryKeyDword(hKey, resamplingQuality, resamplingQualityData); WriteRegistryKeyDword(hKey, speakerConfig, speakerConfigData); WriteRegistryKeyDword(hKey, forceChannelMixing, forceChannelMixingData); WriteRegistryKeyDword(hKey, releaseDeviceOnStop, releaseDeviceOnStopData); WriteRegistryKeyDword(hKey, expandMonoToStereo, expandMonoToStereoData); WriteRegistryKeyDword(hKey, quality_USE_QUICKSEEK, quality_USE_QUICKSEEKData); WriteRegistryKeyDword(hKey, quality_USE_AA_FILTER, quality_USE_AA_FILTERData); WriteRegistryKeyDword(hKey, quality_AA_FILTER_LENGTH, quality_AA_FILTER_LENGTHData); WriteRegistryKeyDword(hKey, quality_SEQUENCE_MS, quality_SEQUENCE_MSData); WriteRegistryKeyDword(hKey, quality_SEEKWINDOW_MS, quality_SEEKWINDOW_MSData); WriteRegistryKeyDword(hKey, quality_OVERLAP_MS, quality_OVERLAP_MSData); delete[] m_wWASAPIPreferredDeviceId; m_wWASAPIPreferredDeviceId = new WCHAR[MAX_REG_LENGTH]; wcsncpy(m_wWASAPIPreferredDeviceId, T2W(WASAPIPreferredDeviceData), MAX_REG_LENGTH); WriteRegistryKeyString(hKey, WASAPIPreferredDevice, WASAPIPreferredDeviceData); } else Log("Error creating master key %d", result); } delete[] lpData; RegCloseKey (hKey); }