Improve translate-no-internet-connection error - thx PM :)

This commit is contained in:
niksedk 2021-09-18 09:46:04 +02:00
parent f926305499
commit c703bcaa68
3 changed files with 21 additions and 1 deletions

View File

@ -815,6 +815,7 @@ Note: Do check free disk space.</WaveFileMalformed>
<Preset>Preset</Preset>
<Crf>CRF</Crf>
<TuneFor>Tune for</TuneFor>
<AlignRight>Align right</AlignRight>
</GenerateVideoWithBurnedInSubs>
<GetDictionaries>
<Title>Need dictionaries?</Title>

View File

@ -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);
}

View File

@ -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;