78 lines
3 KiB
C#
78 lines
3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using Amazon.S3.Model;
|
|
using TeaBox.Macros;
|
|
using TeaBox.Oasis.Exporters;
|
|
using TeaBox.OasisService;
|
|
using TeaBox.Scripts.AWS;
|
|
using TeaBox.Utilities.Secrets;
|
|
|
|
namespace TeaBox
|
|
{
|
|
[Module(Icon = "language")]
|
|
[Category("Data")]
|
|
[DisplayName("Localization")]
|
|
public static class LocalizationMacros
|
|
{
|
|
[Flags]
|
|
public enum Environments
|
|
{
|
|
PROD = 1 << 1,
|
|
DEV = 1 << 2
|
|
}
|
|
|
|
[DisplayName("Update Localization (Just Dance Now)")]
|
|
[Macro(ThreadAffinity.ExecuteAsync, Icon = "language.png")]
|
|
public static void GenerateLocalizationDataJdNow(IExecutionContext context,
|
|
[DefaultValue(true)] bool uploadToAmazon,
|
|
Environments environments)
|
|
{
|
|
const string oasisHost = "http://oasis-pdc2.ubisoft.org/justdancenow";
|
|
var jsFilePath = Path.Combine(Path.GetTempPath(), $"localization_jdnow_{DateTime.Now:yyyyMMddTHHmmss}.js");
|
|
context.ExecuteStep("Exporting localizations for Just Dance Now", step =>
|
|
{
|
|
var oasisExportJustDanceLiveCommand = new OasisExportJsCommand
|
|
{
|
|
Host = oasisHost,
|
|
OutputPath = jsFilePath,
|
|
SectionTypes = new[] { SectionType.Menu },
|
|
IsJDNowExport = true,
|
|
};
|
|
oasisExportJustDanceLiveCommand.Execute(context);
|
|
step.LogMessage($"localization file temporary exported to {jsFilePath}.");
|
|
});
|
|
|
|
if (uploadToAmazon && environments.FlagsDefined().Any())
|
|
{
|
|
context.ExecuteStep($"Uploading localizations ({environments}) to Amazon server", step =>
|
|
{
|
|
var secretsManager = SecretsManagement.GetSecretsManager();
|
|
var client = new AmazonClient(secretsManager.GetAwsCredentials(), AmazonEndpoint.EUWest1);
|
|
|
|
var bucketName = "jdn-localization";
|
|
|
|
var acl = client.S3Client.GetACL(new GetACLRequest { BucketName = bucketName }).AccessControlList;
|
|
var filenames = new List<String>();
|
|
if (environments.HasFlag(Environments.PROD)) filenames.Add("localisation.js");
|
|
if (environments.HasFlag(Environments.DEV)) filenames.Add("localisation-dev.js");
|
|
foreach (var filename in filenames)
|
|
{
|
|
var request = new PutObjectRequest
|
|
{
|
|
BucketName = bucketName,
|
|
Key = filename,
|
|
FilePath = jsFilePath,
|
|
ContentType = "application/json",
|
|
Grants = acl.Grants
|
|
};
|
|
|
|
client.S3Client.PutObject(request);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|