From c703bcaa68b208c2bc534f7d1da5f2314405ba63 Mon Sep 17 00:00:00 2001 From: niksedk Date: Sat, 18 Sep 2021 09:46:04 +0200 Subject: [PATCH] Improve translate-no-internet-connection error - thx PM :) --- LanguageMaster.xml | 1 + src/ui/Forms/Translate/GenericTranslate.cs | 18 +++++++++++++++++- src/ui/Logic/LanguageDeserializer.cs | 3 +++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/LanguageMaster.xml b/LanguageMaster.xml index 3ef0eeb1a..d4de2bbcc 100644 --- a/LanguageMaster.xml +++ b/LanguageMaster.xml @@ -815,6 +815,7 @@ Note: Do check free disk space. Preset CRF Tune for + Align right Need dictionaries? diff --git a/src/ui/Forms/Translate/GenericTranslate.cs b/src/ui/Forms/Translate/GenericTranslate.cs index 2a7b095da..a69fec4f4 100644 --- a/src/ui/Forms/Translate/GenericTranslate.cs +++ b/src/ui/Forms/Translate/GenericTranslate.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net.NetworkInformation; using System.Text; using System.Windows.Forms; @@ -313,6 +314,21 @@ namespace Nikse.SubtitleEdit.Forms.Translate Translate(); } + public static bool IsAvailableNetworkActive() + { + if (NetworkInterface.GetIsNetworkAvailable()) + { + var interfaces = NetworkInterface.GetAllNetworkInterfaces(); + return (from face in interfaces + where face.OperationalStatus == OperationalStatus.Up + where (face.NetworkInterfaceType != NetworkInterfaceType.Tunnel) && (face.NetworkInterfaceType != NetworkInterfaceType.Loopback) + select face.GetIPv4Statistics()).Any(statistics => (statistics.BytesReceived > 0) && (statistics.BytesSent > 0)); + } + + return false; + } + + private void Translate() { var translator = (ITranslationProcessor)comboBoxParagraphHandling.SelectedItem; @@ -340,7 +356,7 @@ namespace Nikse.SubtitleEdit.Forms.Translate } catch (TranslationException translationException) { - if (translationException.InnerException != null && translationException.InnerException.Message.Contains("The remote name could not be resolved")) + if (translationException.InnerException != null && !IsAvailableNetworkActive()) { ShowNetworkError(translationException.InnerException); } diff --git a/src/ui/Logic/LanguageDeserializer.cs b/src/ui/Logic/LanguageDeserializer.cs index ff36e6477..72ef50ed7 100644 --- a/src/ui/Logic/LanguageDeserializer.cs +++ b/src/ui/Logic/LanguageDeserializer.cs @@ -2170,6 +2170,9 @@ namespace Nikse.SubtitleEdit.Logic case "GenerateVideoWithBurnedInSubs/TuneFor": language.GenerateVideoWithBurnedInSubs.TuneFor = reader.Value; break; + case "GenerateVideoWithBurnedInSubs/AlignRight": + language.GenerateVideoWithBurnedInSubs.AlignRight = reader.Value; + break; case "GetDictionaries/Title": language.GetDictionaries.Title = reader.Value; break;