void UDeviceProfileManager::SaveProfiles(bool bSaveToDefaults) { if( !HasAnyFlags( RF_ClassDefaultObject ) ) { if(bSaveToDefaults) { for (int32 DeviceProfileIndex = 0; DeviceProfileIndex < Profiles.Num(); ++DeviceProfileIndex) { UDeviceProfile* CurrentProfile = CastChecked<UDeviceProfile>(Profiles[DeviceProfileIndex]); CurrentProfile->UpdateDefaultConfigFile(); } } else { TArray< FString > DeviceProfileMapArray; for (int32 DeviceProfileIndex = 0; DeviceProfileIndex < Profiles.Num(); ++DeviceProfileIndex) { UDeviceProfile* CurrentProfile = CastChecked<UDeviceProfile>(Profiles[DeviceProfileIndex]); FString DeviceProfileTypeNameCombo = FString::Printf(TEXT("%s,%s"), *CurrentProfile->GetName(), *CurrentProfile->DeviceType); DeviceProfileMapArray.Add(DeviceProfileTypeNameCombo); CurrentProfile->SaveConfig(CPF_Config, *DeviceProfileFileName); } GConfig->SetArray(TEXT("DeviceProfiles"), TEXT("DeviceProfileNameAndTypes"), DeviceProfileMapArray, DeviceProfileFileName); GConfig->Flush(false, DeviceProfileFileName); } ManagerUpdatedDelegate.Broadcast(); } }
UDeviceProfile& UDeviceProfileManager::FindProfile( const FString& ProfileName ) { UDeviceProfile* FoundProfile = nullptr; for( int32 Idx = 0; Idx < Profiles.Num(); Idx++ ) { UDeviceProfile* CurrentDevice = CastChecked<UDeviceProfile>( Profiles[Idx] ); if( CurrentDevice->GetName() == ProfileName ) { FoundProfile = CurrentDevice; break; } } return FoundProfile != nullptr ? *FoundProfile : CreateProfile(ProfileName, FPlatformProperties::PlatformName()); }
void UDeviceProfileManager::InternalSaveProfiles() { TArray< FString > DeviceProfileMapArray; for(int32 DeviceProfileIndex = 0; DeviceProfileIndex < Profiles.Num(); ++DeviceProfileIndex) { UDeviceProfile* CurrentProfile = CastChecked<UDeviceProfile>( Profiles[DeviceProfileIndex] ); FString DeviceProfileTypeNameCombo = FString::Printf( TEXT("%s,%s"), *CurrentProfile->GetName(), *CurrentProfile->DeviceType ); DeviceProfileMapArray.Add( DeviceProfileTypeNameCombo ); CurrentProfile->SaveConfig(CPF_Config, *DeviceProfileFileName); } GConfig->SetArray( TEXT( "DeviceProfiles" ), TEXT( "DeviceProfileNameAndTypes" ), DeviceProfileMapArray, DeviceProfileFileName ); GConfig->Flush( false, DeviceProfileFileName ); }
UDeviceProfile* UDeviceProfileManager::FindProfile( const FString& ProfileName ) { UDeviceProfile* FoundProfile = NULL; for( int32 Idx = 0; Idx < Profiles.Num(); Idx++ ) { UDeviceProfile* CurrentDevice = CastChecked<UDeviceProfile>( Profiles[Idx] ); if( CurrentDevice->GetName() == ProfileName ) { FoundProfile = CurrentDevice; break; } } return FoundProfile; }
void UDeviceProfile::GatherParentCVarInformationRecursively(OUT TMap<FString, FString>& CVarInformation) const { // Recursively build the parent tree if (BaseProfileName != TEXT("")) { UDeviceProfile* ParentProfile = FindObject<UDeviceProfile>(GetTransientPackage(), *BaseProfileName); check(ParentProfile != NULL); for (auto& CurrentCVar : ParentProfile->CVars) { FString CVarKey, CVarValue; if (CurrentCVar.Split(TEXT("="), &CVarKey, &CVarValue)) { if (CVarInformation.Find(CVarKey) == NULL) { CVarInformation.Add(CVarKey, *CurrentCVar); } } } ParentProfile->GatherParentCVarInformationRecursively(CVarInformation); } }
UDeviceProfile* UDeviceProfileManager::CreateProfile( const FString& ProfileName, const FString& ProfileType, const FString& ParentName ) { UDeviceProfile* DeviceProfile = FindObject<UDeviceProfile>( GetTransientPackage(), *ProfileName ); if( DeviceProfile == NULL ) { DeviceProfile = ConstructObject<UDeviceProfile>( UDeviceProfile::StaticClass(), GetTransientPackage(), *ProfileName, RF_Transient|RF_Public); DeviceProfile->LoadConfig( UDeviceProfile::StaticClass(), *DeviceProfileFileName ); DeviceProfile->BaseProfileName = ParentName != TEXT("") ? ParentName : DeviceProfile->BaseProfileName; DeviceProfile->DeviceType = ProfileType; UDeviceProfile* ObjectTemplate = NULL; // Recursively build the parent tree if( DeviceProfile->BaseProfileName != TEXT("") ) { DeviceProfile->Parent = FindObject<UDeviceProfile>( GetTransientPackage(), *DeviceProfile->BaseProfileName ); if( DeviceProfile->Parent == NULL ) { DeviceProfile->Parent = CreateProfile( DeviceProfile->BaseProfileName, ProfileType ); } ObjectTemplate = CastChecked<UDeviceProfile>(DeviceProfile->Parent); } if( ObjectTemplate ) { DeviceProfile->ClearFlags( RF_AllFlags ); DeviceProfile->Rename( *FString::Printf(TEXT("RedundantDeviceProfile_%d"), RenameIndex++), GetTransientPackage()); DeviceProfile->SetFlags( RF_PendingKill ); DeviceProfile = ConstructObject<UDeviceProfile>( UDeviceProfile::StaticClass(), GetTransientPackage(), *ProfileName, RF_Transient|RF_Public, ObjectTemplate); DeviceProfile->BaseProfileName = ObjectTemplate->GetName(); DeviceProfile->DeviceType = ProfileType; } Profiles.Add( DeviceProfile ); // Inform the UI that the device list has changed ManagerUpdatedDelegate.Broadcast(); } return DeviceProfile; }
void UDeviceProfile::PostEditChangeProperty( FPropertyChangedEvent& PropertyChangedEvent ) { Super::PostEditChangeProperty( PropertyChangedEvent ); if( PropertyChangedEvent.Property->GetFName() == TEXT("BaseProfileName") ) { FString NewParentName = *PropertyChangedEvent.Property->ContainerPtrToValuePtr<FString>( this ); if( UObject* ParentRef = FindObject<UDeviceProfile>( GetTransientPackage(), *NewParentName ) ) { // Generation and profile reference TMap<UDeviceProfile*,int32> DependentProfiles; int32 NumGenerations = 1; DependentProfiles.Add(this,0); for( TObjectIterator<UDeviceProfile> DeviceProfileIt; DeviceProfileIt; ++DeviceProfileIt ) { UDeviceProfile* ParentProfile = *DeviceProfileIt; if( !ParentProfile->HasAnyFlags(RF_PendingKill) ) { int32 ProfileGeneration = 1; while( ParentProfile != NULL ) { if( this->GetName() == ParentProfile->BaseProfileName ) { NumGenerations = NumGenerations > ProfileGeneration ? NumGenerations : ProfileGeneration; DependentProfiles.Add(*DeviceProfileIt,ProfileGeneration); break; } ParentProfile = FindObject<UDeviceProfile>( GetTransientPackage(), *ParentProfile->BaseProfileName ); ++ProfileGeneration; } } } UDeviceProfile* ClassCDO = CastChecked<UDeviceProfile>(GetClass()->GetDefaultObject()); for( int32 CurrentGeneration = 0; CurrentGeneration < NumGenerations; CurrentGeneration++ ) { for( TMap<UDeviceProfile*,int32>::TIterator DeviceProfileIt(DependentProfiles); DeviceProfileIt; ++DeviceProfileIt ) { if( CurrentGeneration == DeviceProfileIt.Value() ) { UDeviceProfile* CurrentGenerationProfile = DeviceProfileIt.Key(); UDeviceProfile* ParentProfile = FindObject<UDeviceProfile>( GetTransientPackage(), *CurrentGenerationProfile->BaseProfileName ); if( ParentProfile == NULL ) { ParentProfile = ClassCDO; } for (TFieldIterator<UProperty> CurrentObjPropertyIter( GetClass() ); CurrentObjPropertyIter; ++CurrentObjPropertyIter) { bool bIsSameParent = CurrentObjPropertyIter->Identical_InContainer( ClassCDO, CurrentGenerationProfile ); if( bIsSameParent ) { void* CurrentGenerationProfilePropertyAddress = CurrentObjPropertyIter->ContainerPtrToValuePtr<void>( CurrentGenerationProfile ); void* ParentPropertyAddr = CurrentObjPropertyIter->ContainerPtrToValuePtr<void>( ParentRef ); CurrentObjPropertyIter->CopyCompleteValue( CurrentGenerationProfilePropertyAddress, ParentPropertyAddr ); } } } } } } OnCVarsUpdated().ExecuteIfBound(); } else if(PropertyChangedEvent.Property->GetFName() == TEXT("CVars")) { OnCVarsUpdated().ExecuteIfBound(); } }