@@ -19,6 +19,7 @@ namespace GooglePlayServices
19
19
using System . Collections . Generic ;
20
20
using System . Diagnostics ;
21
21
using System . IO ;
22
+ using System . Text ;
22
23
using System . Text . RegularExpressions ;
23
24
using System . Threading ;
24
25
using System ;
@@ -220,7 +221,7 @@ private void Read()
220
221
byte [ ] copy = new byte [ bytesRead ] ;
221
222
Array . Copy ( buffer , copy , copy . Length ) ;
222
223
DataReceived ( new StreamData (
223
- handle , System . Text . Encoding . UTF8 . GetString ( copy ) , copy ,
224
+ handle , Encoding . UTF8 . GetString ( copy ) , copy ,
224
225
complete ) ) ;
225
226
}
226
227
}
@@ -511,6 +512,11 @@ public static Result Run(string toolPath, string arguments, string workingDirect
511
512
envVars : envVars , ioHandler : ioHandler , useShellExecution : false ) ;
512
513
}
513
514
515
+ /// <summary>
516
+ /// Whether the console configuration warning has been displayed.
517
+ /// </summary>
518
+ private static bool displayedConsoleConfigurationWarning = false ;
519
+
514
520
/// <summary>
515
521
/// Execute a command line tool.
516
522
/// </summary>
@@ -537,19 +543,31 @@ public static Result RunViaShell(
537
543
Dictionary < string , string > envVars = null ,
538
544
IOHandler ioHandler = null , bool useShellExecution = false ,
539
545
bool stdoutRedirectionInShellMode = true ) {
540
- System . Text . Encoding inputEncoding = Console . InputEncoding ;
541
- System . Text . Encoding outputEncoding = Console . OutputEncoding ;
546
+ bool consoleConfigurationWarning = false ;
547
+ Encoding inputEncoding = Console . InputEncoding ;
548
+ Encoding outputEncoding = Console . OutputEncoding ;
542
549
// Android SDK manager requires the input encoding to be set to
543
550
// UFT8 to pipe data to the tool.
544
551
// Cocoapods requires the output encoding to be set to UTF8 to
545
552
// retrieve output.
546
553
try {
547
- Console . InputEncoding = System . Text . Encoding . UTF8 ;
548
- Console . OutputEncoding = System . Text . Encoding . UTF8 ;
554
+ var utf8Type = Encoding . UTF8 . GetType ( ) ;
555
+ // Only compare the type of the encoding class since the configuration shouldn't
556
+ // matter.
557
+ if ( inputEncoding . GetType ( ) != utf8Type ) {
558
+ Console . InputEncoding = Encoding . UTF8 ;
559
+ }
560
+ if ( outputEncoding . GetType ( ) != utf8Type ) {
561
+ Console . OutputEncoding = Encoding . UTF8 ;
562
+ }
549
563
} catch ( Exception e ) {
550
- UnityEngine . Debug . LogWarning ( String . Format (
551
- "Unable to set console input / output encoding to UTF8 (e.g en_US.UTF8-8). " +
552
- "Some commands may fail. {0}" , e ) ) ;
564
+ if ( ! displayedConsoleConfigurationWarning ) {
565
+ UnityEngine . Debug . LogWarning ( String . Format (
566
+ "Unable to set console input / output encoding from {0} & {1} to {2} " +
567
+ "(e.g en_US.UTF8-8). Some commands may fail. {3}" ,
568
+ inputEncoding , outputEncoding , Encoding . UTF8 , e ) ) ;
569
+ consoleConfigurationWarning = true ;
570
+ }
553
571
}
554
572
555
573
// Mono 3.x on Windows can't execute tools with single quotes (apostrophes) in the path.
@@ -655,13 +673,21 @@ public static Result RunViaShell(
655
673
result . message = FormatResultMessage ( toolPath , arguments , result . stdout ,
656
674
result . stderr , result . exitCode ) ;
657
675
try {
658
- Console . InputEncoding = inputEncoding ;
659
- Console . OutputEncoding = outputEncoding ;
676
+ if ( Console . InputEncoding != inputEncoding ) {
677
+ Console . InputEncoding = inputEncoding ;
678
+ }
679
+ if ( Console . OutputEncoding != outputEncoding ) {
680
+ Console . OutputEncoding = outputEncoding ;
681
+ }
660
682
} catch ( Exception e ) {
661
- UnityEngine . Debug . LogWarning ( String . Format (
662
- "Unable to restore console input / output encoding to {0} & {1}. {2}" ,
663
- inputEncoding , outputEncoding , e ) ) ;
683
+ if ( ! displayedConsoleConfigurationWarning ) {
684
+ UnityEngine . Debug . LogWarning ( String . Format (
685
+ "Unable to restore console input / output encoding to {0} & {1}. {2}" ,
686
+ inputEncoding , outputEncoding , e ) ) ;
687
+ consoleConfigurationWarning = true ;
688
+ }
664
689
}
690
+ if ( consoleConfigurationWarning ) displayedConsoleConfigurationWarning = true ;
665
691
return result ;
666
692
}
667
693
0 commit comments