Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit fbc570de authored by g4m4's avatar g4m4
Browse files

[CODE] Explicitly read from the configuration file at instantiation so it is...

[CODE] Explicitly read from the configuration file at instantiation so it is properly setup for the CRC, and do not mess with defaults
parent dac866cc
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,9 @@ UFixItSettings::UFixItSettings()
bAllowCustomisingLabels(false),
bTitleIsMandatory(true),
bContentIsMandatory(true)
{}
{
ReadSettingsFromConfig();
}
const UFixItSettings* UFixItSettings::GetSettings()
{
......@@ -47,13 +49,6 @@ bool UFixItSettings::SaveCredentials(const FString& NewLogin, const FString& New
Instance->SaveConfig();
#if ENGINE_MAJOR_VERSION <= 4
// In UE < 5.0 TryUpdateDefaultConfigFile() does not exist
Instance->UpdateDefaultConfigFile();
#else // ENGINE_MAJOR_VERSION <= 4
Instance->TryUpdateDefaultConfigFile();
#endif // ENGINE_MAJOR_VERSION <= 4
return true;
}
......@@ -102,3 +97,74 @@ void UFixItSettings::GetFromInternal(UFixItSettings* Instance) {
(void)Instance;
UE_LOG(LogFixItCore, Error, TEXT("Not implemented for now"));
}
void UFixItSettings::ReadSettingsFromConfig() {
// Inspired from Internationalization/TextLocalizationManager.cpp
auto ReadSettingsFromConfig = [this](const FString& InConfigFilename)
{
GConfig->LoadFile(InConfigFilename);
FString DefaultLogin;
if (GConfig->GetString(TEXT("/Script/FixItCore.FixItSettings"), TEXT("DefaultLogin"), DefaultLogin, InConfigFilename)) {
this->DefaultLogin = DefaultLogin;
}
FString Login;
if (GConfig->GetString(TEXT("/Script/FixItCore.FixItSettings"), TEXT("Login"), Login, InConfigFilename)) {
this->Login = Login;
}
FString Token;
if (GConfig->GetString(TEXT("/Script/FixItCore.FixItSettings"), TEXT("Token"), Token, InConfigFilename)) {
this->Token = Token;
}
FString ProjectName;
if (GConfig->GetString(TEXT("/Script/FixItCore.FixItSettings"), TEXT("ProjectName"), ProjectName, InConfigFilename)) {
this->ProjectName = ProjectName;
}
FString URL;
if (GConfig->GetString(TEXT("/Script/FixItCore.FixItSettings"), TEXT("URL"), URL, InConfigFilename)) {
this->URL = URL;
}
FString Backend;
if (GConfig->GetString(TEXT("/Script/FixItCore.FixItSettings"), TEXT("Backend"), Backend, InConfigFilename)) {
const int32 index = StaticEnum<EFixItBackendType>()->GetIndexByNameString(Backend);
if (index != INDEX_NONE) {
this->Backend = static_cast<EFixItBackendType>(index);
}
}
TArray<FString> DefaultLabels;
if (GConfig->GetValue(TEXT("/Script/FixItCore.FixItSettings"), TEXT("DefaultLabels"), DefaultLabels, InConfigFilename)) {
this->DefaultLabels = DefaultLabels;
}
bool LoginAtStartup;
if (GConfig->GetBool(TEXT("/Script/FixItCore.FixItSettings"), TEXT("bLoginAtStartup"), LoginAtStartup, InConfigFilename)) {
this->bLoginAtStartup = LoginAtStartup;
}
bool AllowCustomisingLabels;
if (GConfig->GetBool(TEXT("/Script/FixItCore.FixItSettings"), TEXT("bAllowCustomisingLabels"), AllowCustomisingLabels, InConfigFilename)) {
this->bAllowCustomisingLabels = AllowCustomisingLabels;
}
bool TitleIsMandatory;
if (GConfig->GetBool(TEXT("/Script/FixItCore.FixItSettings"), TEXT("bTitleIsMandatory"), TitleIsMandatory, InConfigFilename)) {
this->bTitleIsMandatory = TitleIsMandatory;
}
bool ContentIsMandatory;
if (GConfig->GetBool(TEXT("/Script/FixItCore.FixItSettings"), TEXT("bContentIsMandatory"), ContentIsMandatory, InConfigFilename)) {
this->bContentIsMandatory = ContentIsMandatory;
}
int32 MaxTitleLength = 64;
if (GConfig->GetInt(TEXT("/Script/FixItCore.FixItSettings"), TEXT("MaxTitleLength"), MaxTitleLength, InConfigFilename)) {
this->MaxTitleLength = MaxTitleLength;
}
};
// Read the default one first
const FString DefaultConfigIni = FConfigCacheIni::GetDestIniFilename(TEXT("DefaultFixIt"), TEXT(""), *FPaths::ProjectConfigDir());
ReadSettingsFromConfig(DefaultConfigIni);
// Then read the saved config file, if any
const FString SavedConfigIni = FConfigCacheIni::GetDestIniFilename(TEXT("FixIt"), nullptr, *FPaths::GeneratedConfigDir());
ReadSettingsFromConfig(SavedConfigIni);
if (Settings != nullptr)
{
CopyToInternal(this);
}
}
......@@ -94,6 +94,8 @@ private:
static void CopyToInternal(UFixItSettings* Instance);
static void GetFromInternal(UFixItSettings* Instance);
void ReadSettingsFromConfig();
/// <summary>
/// Non-owning pointer to internal settings data: might be null!
/// </summary>
......
......@@ -5,6 +5,7 @@ Date 2025/01/29
- Make issue title/content optionally not mandatory
- Upgrade to Fixit internal library 1.1
- Move settings to a dedicated file
## Version 1.4
Date 2025/01/27
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment