private void CompileTranslation(Translation translation, CompileMessages errors)
{
translation.LoadData();
if (translation.TranslatedLines.Count < 1)
{
errors.Add(new CompileError("Translation " + translation.FileName + " appears to be empty. You must update the source before compiling.", translation.FileName, 1));
return;
}
string compiledFile = Path.Combine(AGSEditor.OUTPUT_DIRECTORY,
Path.Combine(AGSEditor.DATA_OUTPUT_DIRECTORY, translation.CompiledFileName));
bool foundTranslatedLine = false;
using (BinaryWriter bw = new BinaryWriter(new FileStream(compiledFile, FileMode.Create, FileAccess.Write)))
{
bw.Write(Encoding.ASCII.GetBytes(COMPILED_TRANSLATION_FILE_SIGNATURE));
bw.Write(TRANSLATION_BLOCK_GAME_ID);
byte[] gameName = Factory.NativeProxy.TransformStringToBytes(_agsEditor.CurrentGame.Settings.GameName);
bw.Write(gameName.Length + 4);
bw.Write(_agsEditor.CurrentGame.Settings.UniqueID);
bw.Write(gameName);
bw.Write(TRANSLATION_BLOCK_TRANSLATION_DATA);
long offsetOfBlockSize = bw.BaseStream.Position;
bw.Write((int)0);
foreach (string line in translation.TranslatedLines.Keys)
{
if (translation.TranslatedLines[line].Length > 0)
{
foundTranslatedLine = true;
bw.Write(Factory.NativeProxy.TransformStringToBytes(ConvertEscapedCharacters(line)));
bw.Write(Factory.NativeProxy.TransformStringToBytes(ConvertEscapedCharacters(translation.TranslatedLines[line])));
}
}
bw.Write(Factory.NativeProxy.TransformStringToBytes(string.Empty));
bw.Write(Factory.NativeProxy.TransformStringToBytes(string.Empty));
long mainBlockSize = (bw.BaseStream.Position - offsetOfBlockSize) - 4;
bw.Write(TRANSLATION_BLOCK_OPTIONS);
bw.Write((int)12);
bw.Write(translation.NormalFont ?? -1);
bw.Write(translation.SpeechFont ?? -1);
bw.Write((translation.RightToLeftText == true) ? 2 : ((translation.RightToLeftText == false) ? 1 : -1));
bw.Write(TRANSLATION_BLOCK_END_OF_FILE);
bw.Write((int)0);
bw.Seek((int)offsetOfBlockSize, SeekOrigin.Begin);
bw.Write((int)mainBlockSize);
bw.Close();
}
if (!foundTranslatedLine)
{
errors.Add(new CompileError("Translation " + translation.FileName + " did not appear to have any translated lines. Make sure you translate some text before compiling the translation.", translation.FileName, 1));
File.Delete(compiledFile);
}
}