2019-12-26 23:01:54 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2016-01-14 08:11:47 -05:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using AutomationTool;
|
|
|
|
|
using UnrealBuildTool;
|
|
|
|
|
|
|
|
|
|
namespace EpicGames.OneSkyLocalization.Config
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class for retrieving OneSky localization configuration data
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class OneSkyConfigHelper
|
|
|
|
|
{
|
|
|
|
|
// List of configs is cached off for fetching from multiple times
|
|
|
|
|
private static Dictionary<string, OneSkyConfigData> Configs;
|
|
|
|
|
|
|
|
|
|
public static OneSkyConfigData Find(string ConfigName)
|
|
|
|
|
{
|
|
|
|
|
if (Configs == null)
|
|
|
|
|
{
|
|
|
|
|
// Load all secret configs by trying to instantiate all classes derived from OneSkyConfigData from all loaded DLLs.
|
|
|
|
|
// Note that we're using the default constructor on the secret config types.
|
|
|
|
|
Configs = new Dictionary<string, OneSkyConfigData>();
|
|
|
|
|
Assembly[] LoadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
|
|
|
|
|
foreach (var Dll in LoadedAssemblies)
|
|
|
|
|
{
|
|
|
|
|
Type[] AllTypes = Dll.GetTypes();
|
|
|
|
|
foreach (var PotentialConfigType in AllTypes)
|
|
|
|
|
{
|
|
|
|
|
if (PotentialConfigType != typeof(OneSkyConfigData) && typeof(OneSkyConfigData).IsAssignableFrom(PotentialConfigType))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
OneSkyConfigData Config = Activator.CreateInstance(PotentialConfigType) as OneSkyConfigData;
|
|
|
|
|
if (Config != null)
|
|
|
|
|
{
|
|
|
|
|
Configs.Add(Config.Name, Config);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
BuildCommand.LogWarning("Unable to create OneSky config data: {0}", PotentialConfigType.Name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
OneSkyConfigData LoadedConfig;
|
|
|
|
|
Configs.TryGetValue(ConfigName, out LoadedConfig);
|
|
|
|
|
if (LoadedConfig == null)
|
|
|
|
|
{
|
|
|
|
|
throw new AutomationException("Unable to find requested OneSky config data: {0}", ConfigName);
|
|
|
|
|
}
|
|
|
|
|
return LoadedConfig;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class for storing OneSky Localization configuration data
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class OneSkyConfigData
|
|
|
|
|
{
|
|
|
|
|
public OneSkyConfigData(string InName, string InApiKey, string InApiSecret)
|
|
|
|
|
{
|
|
|
|
|
Name = InName;
|
|
|
|
|
ApiKey = InApiKey;
|
|
|
|
|
ApiSecret = InApiSecret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name;
|
|
|
|
|
public string ApiKey;
|
|
|
|
|
public string ApiSecret;
|
|
|
|
|
|
|
|
|
|
public void SpewValues()
|
|
|
|
|
{
|
2018-08-14 18:32:34 -04:00
|
|
|
CommandUtils.LogInformation("Name : {0}", Name);
|
|
|
|
|
CommandUtils.LogInformation("ApiKey : {0}", ApiKey);
|
2016-01-14 08:11:47 -05:00
|
|
|
//CommandUtils.LogConsole("ApiSecret : {0}", ApiSecret); // This should probably never be revealed.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|