Exemplo n.º 1
0
        private string RequestAuthTokenWithRetry(XLocApiClient XLocApiClient)
        {
            const int MAX_COUNT = 3;

            int Count = 0;

            for (;;)
            {
                try
                {
                    return(RequestAuthToken(XLocApiClient));
                }
                catch (Exception Ex)
                {
                    if (++Count < MAX_COUNT)
                    {
                        BuildCommand.LogWarning("RequestAuthToken attempt {0}/{1} failed. Retrying...", Count, MAX_COUNT);
                        continue;
                    }

                    BuildCommand.LogWarning("RequestAuthToken attempt {0}/{1} failed.", Count, MAX_COUNT);
                    throw Ex;
                }
            }
        }
Exemplo n.º 2
0
 private string RequestLatestBuild(XLocApiClient XLocApiClient, string AuthToken, string LanguageId)
 {
     return(XLocApiClient.GetLatestBuild(Config.APIKey, AuthToken, XLocUtils.MD5HashString(Config.APIKey + Config.APISecret + Config.LocalizationId + LanguageId), Config.LocalizationId, LanguageId));
 }
Exemplo n.º 3
0
        private void DownloadLatestPOFile(XLocApiClient XLocApiClient, string AuthToken, string Culture, ProjectImportExportInfo ProjectImportInfo, int XLocDownloadedPOChangeList)
        {
            var XLocFilename = GetXLocFilename(ProjectImportInfo.PortableObjectName);

            // This will throw if the requested culture is invalid, but we don't want to let that kill the whole gather
            var LatestBuildXml = "";

            try
            {
                var EpicCultureToXLocLanguageId = GetEpicCultureToXLocLanguageId();
                LatestBuildXml = RequestLatestBuild(XLocApiClient, AuthToken, EpicCultureToXLocLanguageId[Culture]);
            }
            catch (Exception Ex)
            {
                BuildCommand.LogWarning("RequestLatestBuild failed for {0}. {1}", Culture, Ex);
                return;
            }

            var POFileUri    = "";
            var BuildsXmlDoc = new XmlDocument();

            BuildsXmlDoc.LoadXml(LatestBuildXml);

            var BuildElem = BuildsXmlDoc["Build"];

            if (BuildElem != null)
            {
                var BuildFilesElem = BuildElem["BuildFiles"];
                if (BuildFilesElem != null)
                {
                    foreach (XmlNode BuildFile in BuildFilesElem)
                    {
                        bool IsCorrectFile = false;

                        // Is this the file we want?
                        var GameFileElem = BuildFile["GameFile"];
                        if (GameFileElem != null)
                        {
                            var GameFileNameElem = GameFileElem["Name"];
                            if (GameFileNameElem != null && GameFileNameElem.InnerText == XLocFilename)
                            {
                                IsCorrectFile = true;
                            }
                        }

                        if (IsCorrectFile)
                        {
                            var BuildFileDownloadUriElem = BuildFile["DownloadUri"];
                            if (BuildFileDownloadUriElem != null)
                            {
                                POFileUri = BuildFileDownloadUriElem.InnerText;
                                break;
                            }
                        }
                    }
                }
            }

            if (!String.IsNullOrEmpty(POFileUri))
            {
                var DestinationDirectory = new DirectoryInfo(CommandUtils.CombinePaths(RootWorkingDirectory, ProjectImportInfo.DestinationPath));
                var CultureDirectory     = (ProjectImportInfo.bUseCultureDirectory) ? new DirectoryInfo(Path.Combine(DestinationDirectory.FullName, Culture)) : DestinationDirectory;
                if (!CultureDirectory.Exists)
                {
                    CultureDirectory.Create();
                }

                var HTTPRequest = WebRequest.Create(POFileUri);
                HTTPRequest.Method = "GET";
                using (var Response = (HttpWebResponse)XLocUtils.GetWebResponse(HTTPRequest))
                {
                    if (Response.StatusCode != HttpStatusCode.OK)
                    {
                        BuildCommand.LogWarning("HTTP Request to '{0}' failed. {1}", POFileUri, Response.StatusDescription);
                        return;
                    }

                    using (var ResponseStream = Response.GetResponseStream())
                    {
                        var ExportFile = new FileInfo(Path.Combine(CultureDirectory.FullName, ProjectImportInfo.PortableObjectName));

                        // Write out the updated PO file so that the gather commandlet will import the new data from it
                        {
                            var ExportFileWasReadOnly = false;
                            if (ExportFile.Exists)
                            {
                                // We're going to clobber the existing PO file, so make sure it's writable (it may be read-only if in Perforce)
                                ExportFileWasReadOnly = ExportFile.IsReadOnly;
                                ExportFile.IsReadOnly = false;
                            }

                            using (var FileStream = ExportFile.Open(FileMode.Create))
                            {
                                ResponseStream.CopyTo(FileStream);
                                Console.WriteLine("[SUCCESS] Exporting: '{0}' as '{1}' ({2})", XLocFilename, ExportFile.FullName, Culture);
                            }

                            if (ExportFileWasReadOnly)
                            {
                                ExportFile.IsReadOnly = true;
                            }
                        }

                        // Also update the back-up copy so we can diff against what we got from XLoc, and what the gather commandlet produced
                        {
                            var ExportFileCopy = new FileInfo(Path.Combine(ExportFile.DirectoryName, String.Format("{0}_FromXLoc{1}", Path.GetFileNameWithoutExtension(ExportFile.Name), ExportFile.Extension)));

                            var ExportFileCopyWasReadOnly = false;
                            if (ExportFileCopy.Exists)
                            {
                                // We're going to clobber the existing PO file, so make sure it's writable (it may be read-only if in Perforce)
                                ExportFileCopyWasReadOnly = ExportFileCopy.IsReadOnly;
                                ExportFileCopy.IsReadOnly = false;
                            }

                            ExportFile.CopyTo(ExportFileCopy.FullName, true);

                            if (ExportFileCopyWasReadOnly)
                            {
                                ExportFileCopy.IsReadOnly = true;
                            }

                            // Add/check out backed up POs from OneSky.
                            if (CommandUtils.P4Enabled)
                            {
                                UE4Build.AddBuildProductsToChangelist(XLocDownloadedPOChangeList, new List <string>()
                                {
                                    ExportFileCopy.FullName
                                });
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
 private string RequestAuthToken(XLocApiClient XLocApiClient)
 {
     return(XLocApiClient.GetAuthToken(Config.APIKey, XLocUtils.MD5HashString(Config.APIKey + Config.APISecret)));
 }
 protected string RequestLatestBuild(XLocApiClient XLocApiClient, string AuthToken, string LanguageId, string RemoteFilename)
 {
     return(XLocApiClient.GetLatestBuildByFile(Config.APIKey, AuthToken, XLocUtils.MD5HashString(Config.APIKey + Config.APISecret + Config.LocalizationId + LanguageId + RemoteFilename), Config.LocalizationId, LanguageId, RemoteFilename));
 }
	private string RequestLatestBuild(XLocApiClient XLocApiClient, string AuthToken, string LanguageId)
	{
		return XLocApiClient.GetLatestBuild(Config.APIKey, AuthToken, XLocUtils.MD5HashString(Config.APIKey + Config.APISecret + Config.LocalizationId + LanguageId), Config.LocalizationId, LanguageId);
	}
	private string RequestAuthTokenWithRetry(XLocApiClient XLocApiClient)
	{
		const int MAX_COUNT = 3;

		int Count = 0;
		for (;;)
		{
			try
			{
				return RequestAuthToken(XLocApiClient);
			}
			catch (Exception Ex)
			{
				if (++Count < MAX_COUNT)
				{
					BuildCommand.LogWarning("RequestAuthToken attempt {0}/{1} failed. Retrying...", Count, MAX_COUNT);
					continue;
				}

				BuildCommand.LogWarning("RequestAuthToken attempt {0}/{1} failed.", Count, MAX_COUNT);
				throw Ex;
			}
		}
	}
	private string RequestAuthToken(XLocApiClient XLocApiClient)
	{
		return XLocApiClient.GetAuthToken(Config.APIKey, XLocUtils.MD5HashString(Config.APIKey + Config.APISecret));
	}
	private void DownloadLatestPOFile(XLocApiClient XLocApiClient, string AuthToken, string Culture, ProjectImportExportInfo ProjectImportInfo, int XLocDownloadedPOChangeList)
	{
		var XLocFilename = GetXLocFilename(ProjectImportInfo.PortableObjectName);

		// This will throw if the requested culture is invalid, but we don't want to let that kill the whole gather
		var LatestBuildXml = "";
		try
		{
			var EpicCultureToXLocLanguageId = GetEpicCultureToXLocLanguageId();
			LatestBuildXml = RequestLatestBuild(XLocApiClient, AuthToken, EpicCultureToXLocLanguageId[Culture]);
		}
		catch (Exception Ex)
		{
			BuildCommand.LogWarning("RequestLatestBuild failed for {0}. {1}", Culture, Ex);
			return;
		}

		var POFileUri = "";
		var BuildsXmlDoc = new XmlDocument();
		BuildsXmlDoc.LoadXml(LatestBuildXml);

		var BuildElem = BuildsXmlDoc["Build"];
		if (BuildElem != null)
		{
			var BuildFilesElem = BuildElem["BuildFiles"];
			if (BuildFilesElem != null)
			{
				foreach (XmlNode BuildFile in BuildFilesElem)
				{
					bool IsCorrectFile = false;

					// Is this the file we want?
					var GameFileElem = BuildFile["GameFile"];
					if (GameFileElem != null)
					{
						var GameFileNameElem = GameFileElem["Name"];
						if (GameFileNameElem != null && GameFileNameElem.InnerText == XLocFilename)
						{
							IsCorrectFile = true;
						}
					}

					if (IsCorrectFile)
					{
						var BuildFileDownloadUriElem = BuildFile["DownloadUri"];
						if (BuildFileDownloadUriElem != null)
						{
							POFileUri = BuildFileDownloadUriElem.InnerText;
							break;
						}
					}
				}
			}
		}

		if (!String.IsNullOrEmpty(POFileUri))
		{
			var DestinationDirectory = new DirectoryInfo(CommandUtils.CombinePaths(RootWorkingDirectory, ProjectImportInfo.DestinationPath));
			var CultureDirectory = (ProjectImportInfo.bUseCultureDirectory) ? new DirectoryInfo(Path.Combine(DestinationDirectory.FullName, Culture)) : DestinationDirectory;
			if (!CultureDirectory.Exists)
			{
				CultureDirectory.Create();
			}

			var HTTPRequest = WebRequest.Create(POFileUri);
			HTTPRequest.Method = "GET";
			using (var Response = (HttpWebResponse)XLocUtils.GetWebResponse(HTTPRequest))
			{
				if (Response.StatusCode != HttpStatusCode.OK)
				{
					BuildCommand.LogWarning("HTTP Request to '{0}' failed. {1}", POFileUri, Response.StatusDescription);
					return;
				}

				using (var ResponseStream = Response.GetResponseStream())
				{
					var ExportFile = new FileInfo(Path.Combine(CultureDirectory.FullName, ProjectImportInfo.PortableObjectName));

					// Write out the updated PO file so that the gather commandlet will import the new data from it
					{
						var ExportFileWasReadOnly = false;
						if (ExportFile.Exists)
						{
							// We're going to clobber the existing PO file, so make sure it's writable (it may be read-only if in Perforce)
							ExportFileWasReadOnly = ExportFile.IsReadOnly;
							ExportFile.IsReadOnly = false;
						}

						using (var FileStream = ExportFile.Open(FileMode.Create))
						{
							ResponseStream.CopyTo(FileStream);
							Console.WriteLine("[SUCCESS] Exporting: '{0}' as '{1}' ({2})", XLocFilename, ExportFile.FullName, Culture);
						}

						if (ExportFileWasReadOnly)
						{
							ExportFile.IsReadOnly = true;
						}
					}

					// Also update the back-up copy so we can diff against what we got from XLoc, and what the gather commandlet produced
					{
						var ExportFileCopy = new FileInfo(Path.Combine(ExportFile.DirectoryName, String.Format("{0}_FromXLoc{1}", Path.GetFileNameWithoutExtension(ExportFile.Name), ExportFile.Extension)));

						var ExportFileCopyWasReadOnly = false;
						if (ExportFileCopy.Exists)
						{
							// We're going to clobber the existing PO file, so make sure it's writable (it may be read-only if in Perforce)
							ExportFileCopyWasReadOnly = ExportFileCopy.IsReadOnly;
							ExportFileCopy.IsReadOnly = false;
						}

						ExportFile.CopyTo(ExportFileCopy.FullName, true);

						if (ExportFileCopyWasReadOnly)
						{
							ExportFileCopy.IsReadOnly = true;
						}

						// Add/check out backed up POs from OneSky.
						if (CommandUtils.P4Enabled)
						{
							UE4Build.AddBuildProductsToChangelist(XLocDownloadedPOChangeList, new List<string>() { ExportFileCopy.FullName });
						}
					}
				}
			}
		}
	}