Files
UnrealEngineUWP/Engine/Source/Editor/DeviceProfileServices/Private/DeviceProfileServicesUIManager.cpp
Andrew Rodham 8ff0d8b98b Added config migration path for newer versions of the engine.
Newly installed versions of the engine will now attempt to copy the project-agnostic config settings from a previous engine installation. This happens by way of a versioned manifest that copies old versions when the manifest does not exist, or is a different version. This code path is benign for non-installed versions of the engine (or FPaths::ShouldSaveToUserDir() is false).

EditorGameAgnosticSettings and EditorUserSettings ini paths have been renamed to EditorSettings and EditorPerProjectUserSettings respectively to better convey their purpose. In general, most settings should be saved in EditorSettings (project-agnostic) so that they apply regardless of which project is open. We have some way to go migrating existing settings for this to be the case, however.

Some previously per-project configuration files are now project-agnostic (such as Editor.ini, EditorKeyBindings.ini, and EditorLayout.ini)

GEditor->Access...Settings and GEditor->Get...Settings have been removed in favor of direct access of the CDO through GetMutableDefault<> and GetDefault<> respectively. Global config ini filenames that are not set up are now neither loaded nor saved on build machines, to handle the problem of indeterminate state more generically.

This addresses UETOOL-270 (Most editor preferences should be project-agnostic)

[CL 2517558 by Andrew Rodham in Main branch]
2015-04-20 10:12:55 -04:00

138 lines
4.0 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "DeviceProfileServicesPCH.h"
#include "DeviceProfiles/DeviceProfileManager.h"
#include "DeviceProfiles/DeviceProfile.h"
DEFINE_LOG_CATEGORY_STATIC(LogDeviceProfileServices, Log, All);
FDeviceProfileServicesUIManager::FDeviceProfileServicesUIManager()
{
UDeviceProfileManager::Get().OnManagerUpdated().AddRaw(this, &FDeviceProfileServicesUIManager::HandleRefreshUIData);
HandleRefreshUIData();
CreatePlatformMap();
}
const FName FDeviceProfileServicesUIManager::GetDeviceIconName( const FString& DeviceName ) const
{
FName IconName = NAME_None;
const FString* PlatformName = DeviceToPlatformMap.Find( DeviceName );
if ( PlatformName )
{
IconName = GetPlatformIconName( *PlatformName );
}
return IconName;
}
const TArray<TSharedPtr<FString> > FDeviceProfileServicesUIManager::GetPlatformList()
{
return PlatformList;
}
void FDeviceProfileServicesUIManager::GetProfilesByType( TArray<UDeviceProfile*>& OutDeviceProfiles, const FString& InType )
{
for( int32 Idx = 0; Idx < UDeviceProfileManager::Get().Profiles.Num(); Idx++ )
{
UDeviceProfile* CurrentDevice = CastChecked<UDeviceProfile>( UDeviceProfileManager::Get().Profiles[Idx] );
if ( CurrentDevice->DeviceType == InType )
{
OutDeviceProfiles.Add( CurrentDevice );
}
}
}
const FName FDeviceProfileServicesUIManager::GetPlatformIconName( const FString& PlatformName ) const
{
const FName* PlatformNameTemp = DeviceTypeToIconMap.Find( PlatformName );
if ( PlatformNameTemp )
{
return *PlatformNameTemp;
}
return NAME_None;
}
void FDeviceProfileServicesUIManager::HandleRefreshUIData()
{
// Rebuild profile to platform map
DeviceToPlatformMap.Empty();
for( int32 Idx = 0; Idx < UDeviceProfileManager::Get().Profiles.Num(); Idx++ )
{
UDeviceProfile* CurrentDevice = CastChecked<UDeviceProfile>( UDeviceProfileManager::Get().Profiles[Idx] );
DeviceToPlatformMap.Add( CurrentDevice->GetName(), CurrentDevice->DeviceType );
}
}
void FDeviceProfileServicesUIManager::CreatePlatformMap()
{
PlatformList.Reset();
DeviceTypeToIconMap.Empty();
TArray<ITargetPlatform*> Platforms = GetTargetPlatformManager()->GetTargetPlatforms();
for (int32 Index = 0; Index < Platforms.Num(); ++Index)
{
PlatformList.Add(MakeShareable(new FString(Platforms[Index]->PlatformName())));
DeviceTypeToIconMap.Add( Platforms[Index]->PlatformName(), Platforms[Index]->GetPlatformInfo().GetIconStyleName(PlatformInfo::EPlatformIconSize::Normal) );
}
}
void FDeviceProfileServicesUIManager::SetProfile( const FString& DeviceProfileName )
{
// Save the profile name to an ini file
if ( DeviceProfileName != TEXT( "Default" ) )
{
const FString INISection = "SelectedProfile"; // Section in the game ini to store our selections
const FString INIKeyBase = "ProfileItem"; // Key to the stored device profiles
const int32 MaxItems = 4; // Max history
// Array to store the existing items
TArray< FString > CurItems;
FString CurItem;
// Get the existing items
for( int32 ItemIdx = 0 ; ItemIdx < MaxItems; ++ItemIdx )
{
if ( GConfig->GetString( *INISection, *FString::Printf( TEXT("%s%d"), *INIKeyBase, ItemIdx ), CurItem, GEditorPerProjectIni ) )
{
CurItems.Add( CurItem );
}
}
// Remove the current item if it exists - we will re-add it at the top of the array later
const int32 ItemIndex = CurItems.Find( DeviceProfileName );
if ( ItemIndex != INDEX_NONE )
{
CurItems.RemoveAt( ItemIndex );
}
else if ( CurItems.Num() == MaxItems )
{
// else remove the last item
CurItems.RemoveAt( MaxItems -1 );
}
// Add the new profile to the top of the array
CurItems.Insert( DeviceProfileName, 0 );
// Clear the ini section
GConfig->EmptySection( *INISection, GEditorPerProjectIni );
// Re-write the .ini file
for ( int32 ItemIdx = 0; ItemIdx < CurItems.Num(); ++ItemIdx )
{
GConfig->SetString( *INISection, *FString::Printf( TEXT("%s%d"), *INIKeyBase, ItemIdx ), *CurItems[ItemIdx], GEditorPerProjectIni );
}
GConfig->Flush( false, GEditorPerProjectIni );
}
}