12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using System;
- using System.IO;
- using System.Text;
- using System.Threading;
- using XUnity.AutoTranslator.Plugin.ExtProtocol;
- namespace Lec.ExtProtocol
- {
- class Program
- {
- static void Main( string[] args )
- {
- try
- {
- if( args.Length == 0 )
- {
- Console.WriteLine( "This program is automatically run during a game session if LEC is selected, and will be automatically stopped afterwards. This program cannot be run independently." );
- Console.WriteLine( "Press any key to exit." );
- Console.ReadKey();
- return;
- }
- var powerTranslatorPathPayload = args[ 0 ];
- var powerTranslatorPath = Encoding.UTF8.GetString( Convert.FromBase64String( powerTranslatorPathPayload ) );
- var dllPath = Path.Combine( powerTranslatorPath, @"Nova\JaEn\EngineDll_je.dll" );
- using( var translator = new LecTranslationLibrary( dllPath ) )
- {
- using( var stdout = Console.OpenStandardOutput() )
- using( var writer = new StreamWriter( stdout ) )
- using( var stdin = Console.OpenStandardInput() )
- using( var reader = new StreamReader( stdin ) )
- {
- writer.AutoFlush = true;
- while( true )
- {
- var receivedPayload = reader.ReadLine();
- if( string.IsNullOrEmpty( receivedPayload ) ) return;
- var message = ExtProtocolConvert.Decode( receivedPayload ) as TranslationRequest;
- if( message == null ) return;
- var translatedLine = translator.Translate( message.UntranslatedText );
- var response = new TranslationResponse
- {
- Id = message.Id,
- TranslatedText = translatedLine
- };
- var translatedPayload = ExtProtocolConvert.Encode( response );
- writer.WriteLine( translatedPayload );
- }
- }
- }
- }
- catch( Exception )
- {
- // "Graceful shutdown"
- }
- }
- }
- }
|