فهرست منبع

better error handling, fixed user agents

randoman 6 سال پیش
والد
کامیت
73f7bce916

+ 13 - 13
src/XUnity.AutoTranslator.Plugin.Core/Extensions/HarmonyInstanceExtensions.cs

@@ -12,25 +12,25 @@ namespace XUnity.AutoTranslator.Plugin.Core.Extensions
       {
          foreach( var type in types )
          {
-            try
-            {
-               instance.PatchType( type );
-            }
-            catch( Exception e )
-            {
-               Logger.Current.Warn( e, "An error occurred while patching a property/method on a class." );
-            }
+            instance.PatchType( type );
          }
       }
 
       public static void PatchType( this HarmonyInstance instance, Type type )
       {
-         var parentMethodInfos = type.GetHarmonyMethods();
-         if( parentMethodInfos != null && parentMethodInfos.Count() > 0 )
+         try
+         {
+            var parentMethodInfos = type.GetHarmonyMethods();
+            if( parentMethodInfos != null && parentMethodInfos.Count() > 0 )
+            {
+               var info = HarmonyMethod.Merge( parentMethodInfos );
+               var processor = new PatchProcessor( instance, type, info );
+               processor.Patch();
+            }
+         }
+         catch( Exception e )
          {
-            var info = HarmonyMethod.Merge( parentMethodInfos );
-            var processor = new PatchProcessor( instance, type, info );
-            processor.Patch();
+            Logger.Current.Warn( e, "An error occurred while patching a property/method on a class." );
          }
       }
    }

+ 1 - 1
src/XUnity.AutoTranslator.Plugin.Core/Web/BaiduTranslateEndpoint.cs

@@ -38,7 +38,7 @@ namespace XUnity.AutoTranslator.Plugin.Core.Web
 
       public override void ApplyHeaders( WebHeaderCollection headers )
       {
-         headers[ HttpRequestHeader.UserAgent ] = Settings.GetUserAgent( "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36" );
+         headers[ HttpRequestHeader.UserAgent ] = Settings.GetUserAgent( "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36" );
          headers[ HttpRequestHeader.AcceptCharset ] = "UTF-8";
       }
 

+ 1 - 1
src/XUnity.AutoTranslator.Plugin.Core/Web/GoogleTranslateEndpoint.cs

@@ -20,7 +20,7 @@ namespace XUnity.AutoTranslator.Plugin.Core.Web
       //protected static readonly ConstructorInfo WwwConstructor = Constants.Types.WWW?.GetConstructor( new[] { typeof( string ), typeof( byte[] ), typeof( Dictionary<string, string> ) } );
       private static readonly string HttpsServicePointTemplateUrl = "https://translate.googleapis.com/translate_a/single?client=t&dt=t&sl={0}&tl={1}&ie=UTF-8&oe=UTF-8&tk={2}&q={3}";
       private static readonly string HttpsTranslateUserSite = "https://translate.google.com";
-      private static readonly string DefaultUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36";
+      private static readonly string DefaultUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36";
       //private static readonly string UserAgentRepository = "https://techblog.willshouse.com/2012/01/03/most-common-user-agents/";
       private static readonly System.Random RandomNumbers = new System.Random();