mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-21 18:52:36 +01:00
Replaced Encoding.GetEncodings with Configuration.AvailableEncodings
This commit is contained in:
parent
1accfff68e
commit
6b3f183a3d
@ -22,13 +22,13 @@ namespace Nikse.SubtitleEdit.Core.DetectEncoding
|
||||
/// </summary>
|
||||
static EncodingTools()
|
||||
{
|
||||
List<int> streamEcodings = new List<int>();
|
||||
List<int> streamEncodings = new List<int>();
|
||||
List<int> allEncodings = new List<int>();
|
||||
List<int> mimeEcodings = new List<int>();
|
||||
List<int> mimeEncodings = new List<int>();
|
||||
|
||||
// asscii - most simple so put it in first place...
|
||||
streamEcodings.Add(Encoding.ASCII.CodePage);
|
||||
mimeEcodings.Add(Encoding.ASCII.CodePage);
|
||||
streamEncodings.Add(Encoding.ASCII.CodePage);
|
||||
mimeEncodings.Add(Encoding.ASCII.CodePage);
|
||||
allEncodings.Add(Encoding.ASCII.CodePage);
|
||||
|
||||
// add default 2nd for all encodings
|
||||
@ -37,66 +37,61 @@ namespace Nikse.SubtitleEdit.Core.DetectEncoding
|
||||
if (Encoding.Default.IsSingleByte)
|
||||
{
|
||||
// put it in second place
|
||||
streamEcodings.Add(Encoding.Default.CodePage);
|
||||
mimeEcodings.Add(Encoding.Default.CodePage);
|
||||
streamEncodings.Add(Encoding.Default.CodePage);
|
||||
mimeEncodings.Add(Encoding.Default.CodePage);
|
||||
}
|
||||
|
||||
// prefer JIS over JIS-SHIFT (JIS is detected better than JIS-SHIFT)
|
||||
// this one does include cyrilic (strange but true)
|
||||
allEncodings.Add(50220);
|
||||
mimeEcodings.Add(50220);
|
||||
mimeEncodings.Add(50220);
|
||||
|
||||
// always allow unicode flavours for streams (they all have a preamble)
|
||||
streamEcodings.Add(Encoding.Unicode.CodePage);
|
||||
foreach (EncodingInfo enc in Encoding.GetEncodings())
|
||||
streamEncodings.Add(Encoding.Unicode.CodePage);
|
||||
foreach (var encoding in Configuration.AvailableEncodings)
|
||||
{
|
||||
if (!streamEcodings.Contains(enc.CodePage))
|
||||
if (!streamEncodings.Contains(encoding.CodePage))
|
||||
{
|
||||
Encoding encoding = Encoding.GetEncoding(enc.CodePage);
|
||||
if (encoding.GetPreamble().Length > 0)
|
||||
streamEcodings.Add(enc.CodePage);
|
||||
streamEncodings.Add(encoding.CodePage);
|
||||
}
|
||||
}
|
||||
|
||||
// stream is done here
|
||||
PreferredEncodingsForStream = streamEcodings.ToArray();
|
||||
PreferredEncodingsForStream = streamEncodings.ToArray();
|
||||
|
||||
// all singlebyte encodings
|
||||
foreach (EncodingInfo enc in Encoding.GetEncodings())
|
||||
foreach (var encoding in Configuration.AvailableEncodings)
|
||||
{
|
||||
if (!enc.GetEncoding().IsSingleByte)
|
||||
continue;
|
||||
|
||||
if (!allEncodings.Contains(enc.CodePage))
|
||||
allEncodings.Add(enc.CodePage);
|
||||
|
||||
// only add iso and IBM encodings to mime encodings
|
||||
if (enc.CodePage <= 1258)
|
||||
if (encoding.IsSingleByte)
|
||||
{
|
||||
mimeEcodings.Add(enc.CodePage);
|
||||
if (!allEncodings.Contains(encoding.CodePage))
|
||||
allEncodings.Add(encoding.CodePage);
|
||||
|
||||
// only add iso and IBM encodings to mime encodings
|
||||
if (encoding.CodePage <= 1258)
|
||||
mimeEncodings.Add(encoding.CodePage);
|
||||
}
|
||||
}
|
||||
|
||||
// add the rest (multibyte)
|
||||
foreach (EncodingInfo enc in Encoding.GetEncodings())
|
||||
foreach (var encoding in Configuration.AvailableEncodings)
|
||||
{
|
||||
if (!enc.GetEncoding().IsSingleByte)
|
||||
if (!encoding.IsSingleByte)
|
||||
{
|
||||
if (!allEncodings.Contains(enc.CodePage))
|
||||
allEncodings.Add(enc.CodePage);
|
||||
if (!allEncodings.Contains(encoding.CodePage))
|
||||
allEncodings.Add(encoding.CodePage);
|
||||
|
||||
// only add iso and IBM encodings to mime encodings
|
||||
if (enc.CodePage <= 1258)
|
||||
{
|
||||
mimeEcodings.Add(enc.CodePage);
|
||||
}
|
||||
if (encoding.CodePage <= 1258)
|
||||
mimeEncodings.Add(encoding.CodePage);
|
||||
}
|
||||
}
|
||||
|
||||
// add unicodes
|
||||
mimeEcodings.Add(Encoding.Unicode.CodePage);
|
||||
mimeEncodings.Add(Encoding.Unicode.CodePage);
|
||||
|
||||
PreferredEncodings = mimeEcodings.ToArray();
|
||||
PreferredEncodings = mimeEncodings.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -338,7 +333,7 @@ namespace Nikse.SubtitleEdit.Core.DetectEncoding
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rerurns up to maxEncodings codpages that are assumed to be apropriate
|
||||
/// Returns up to maxEncodings codepages that are assumed to be apropriate
|
||||
/// </summary>
|
||||
/// <param name="input">array containing the raw data</param>
|
||||
/// <param name="maxEncodings">maxiumum number of encodings to detect</param>
|
||||
|
@ -577,13 +577,13 @@ namespace Nikse.SubtitleEdit.Core
|
||||
|
||||
try
|
||||
{
|
||||
foreach (EncodingInfo ei in Encoding.GetEncodings())
|
||||
foreach (var enc in Configuration.AvailableEncodings)
|
||||
{
|
||||
if (ei.CodePage + ": " + ei.DisplayName == Configuration.Settings.General.DefaultEncoding &&
|
||||
ei.Name != Encoding.UTF8.BodyName &&
|
||||
ei.Name != Encoding.Unicode.BodyName)
|
||||
if (enc.CodePage + ": " + enc.EncodingName == Configuration.Settings.General.DefaultEncoding &&
|
||||
enc.WebName != Encoding.UTF8.WebName &&
|
||||
enc.WebName != Encoding.Unicode.WebName)
|
||||
{
|
||||
encoding = ei.GetEncoding();
|
||||
encoding = enc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -170,12 +170,12 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
comboBoxEncoding.Items.Clear();
|
||||
int encodingSelectedIndex = 0;
|
||||
comboBoxEncoding.Items.Add(Encoding.UTF8.EncodingName);
|
||||
foreach (EncodingInfo ei in Encoding.GetEncodings())
|
||||
foreach (var encoding in Configuration.AvailableEncodings)
|
||||
{
|
||||
if (ei.Name != Encoding.UTF8.BodyName && ei.CodePage >= 949 && !ei.DisplayName.Contains("EBCDIC") && ei.CodePage != 1047)
|
||||
if (encoding.CodePage >= 949 && encoding.CodePage != 1047 && !encoding.EncodingName.Contains("EBCDIC") && !encoding.WebName.Equals(Encoding.UTF8.WebName))
|
||||
{
|
||||
comboBoxEncoding.Items.Add(ei.CodePage + ": " + ei.DisplayName);
|
||||
if (ei.Name == Configuration.Settings.General.DefaultEncoding)
|
||||
comboBoxEncoding.Items.Add(encoding.CodePage + ": " + encoding.EncodingName);
|
||||
if (encoding.WebName == Configuration.Settings.General.DefaultEncoding)
|
||||
encodingSelectedIndex = comboBoxEncoding.Items.Count - 1;
|
||||
}
|
||||
}
|
||||
@ -510,10 +510,10 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
return Encoding.UTF8;
|
||||
}
|
||||
|
||||
foreach (EncodingInfo ei in Encoding.GetEncodings())
|
||||
foreach (var encoding in Configuration.AvailableEncodings)
|
||||
{
|
||||
if (ei.CodePage + ": " + ei.DisplayName == comboBoxEncoding.Text)
|
||||
return ei.GetEncoding();
|
||||
if (encoding.CodePage + ": " + encoding.EncodingName == comboBoxEncoding.Text)
|
||||
return encoding;
|
||||
}
|
||||
|
||||
return Encoding.UTF8;
|
||||
|
@ -54,12 +54,12 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
_fileBuffer = new byte[0];
|
||||
}
|
||||
|
||||
Encoding encoding = LanguageAutoDetect.DetectAnsiEncoding(_fileBuffer);
|
||||
foreach (EncodingInfo ei in Encoding.GetEncodings())
|
||||
var encoding = LanguageAutoDetect.DetectAnsiEncoding(_fileBuffer);
|
||||
foreach (var enc in Configuration.AvailableEncodings)
|
||||
{
|
||||
var item = new ListViewItem(new[] { ei.CodePage.ToString(), ei.Name, ei.DisplayName });
|
||||
var item = new ListViewItem(new[] { enc.CodePage.ToString(), enc.WebName, enc.EncodingName });
|
||||
listView1.Items.Add(item);
|
||||
if (ei.CodePage == encoding.CodePage)
|
||||
if (enc.CodePage == encoding.CodePage)
|
||||
item.Selected = true;
|
||||
}
|
||||
|
||||
|
@ -33,16 +33,17 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
comboBoxEncoding.Items.Clear();
|
||||
int encodingSelectedIndex = 0;
|
||||
comboBoxEncoding.Items.Add(Encoding.UTF8.EncodingName);
|
||||
foreach (EncodingInfo ei in Encoding.GetEncodings())
|
||||
foreach (var encoding in Configuration.AvailableEncodings)
|
||||
{
|
||||
if (ei.Name != Encoding.UTF8.BodyName && ei.CodePage >= 949 && !ei.DisplayName.Contains("EBCDIC") && ei.CodePage != 1047)
|
||||
if (encoding.CodePage >= 949 && encoding.CodePage != 1047 && !encoding.EncodingName.Contains("EBCDIC") && !encoding.WebName.Equals(Encoding.UTF8.WebName))
|
||||
{
|
||||
comboBoxEncoding.Items.Add(ei.CodePage + ": " + ei.DisplayName);
|
||||
if (ei.Name == Configuration.Settings.General.DefaultEncoding)
|
||||
comboBoxEncoding.Items.Add(encoding.CodePage + ": " + encoding.EncodingName);
|
||||
if (encoding.WebName == Configuration.Settings.General.DefaultEncoding)
|
||||
encodingSelectedIndex = comboBoxEncoding.Items.Count - 1;
|
||||
}
|
||||
}
|
||||
comboBoxEncoding.SelectedIndex = encodingSelectedIndex;
|
||||
|
||||
if (string.IsNullOrEmpty(Configuration.Settings.Tools.ExportCustomTemplates))
|
||||
{
|
||||
_templates.Add("SubRipÆÆ{number}\r\n{start} --> {end}\r\n{text}\r\n\r\nÆhh:mm:ss,zzzÆ[Do not modify]Æ");
|
||||
@ -187,10 +188,10 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
return Encoding.UTF8;
|
||||
}
|
||||
|
||||
foreach (EncodingInfo ei in Encoding.GetEncodings())
|
||||
foreach (var encoding in Configuration.AvailableEncodings)
|
||||
{
|
||||
if (ei.CodePage + ": " + ei.DisplayName == comboBoxEncoding.Text)
|
||||
return ei.GetEncoding();
|
||||
if (encoding.CodePage + ": " + encoding.EncodingName == comboBoxEncoding.Text)
|
||||
return encoding;
|
||||
}
|
||||
|
||||
return Encoding.UTF8;
|
||||
|
@ -50,12 +50,12 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
comboBoxEncoding.Items.Clear();
|
||||
int encodingSelectedIndex = 0;
|
||||
comboBoxEncoding.Items.Add(Encoding.UTF8.EncodingName);
|
||||
foreach (EncodingInfo ei in Encoding.GetEncodings())
|
||||
foreach (var encoding in Configuration.AvailableEncodings)
|
||||
{
|
||||
if (ei.Name != Encoding.UTF8.BodyName && ei.CodePage >= 949 && !ei.DisplayName.Contains("EBCDIC") && ei.CodePage != 1047)
|
||||
if (encoding.CodePage >= 949 && encoding.CodePage != 1047 && !encoding.EncodingName.Contains("EBCDIC") && !encoding.WebName.Equals(Encoding.UTF8.WebName))
|
||||
{
|
||||
comboBoxEncoding.Items.Add(ei.CodePage + ": " + ei.DisplayName);
|
||||
if (ei.Name == Configuration.Settings.General.DefaultEncoding)
|
||||
comboBoxEncoding.Items.Add(encoding.CodePage + ": " + encoding.EncodingName);
|
||||
if (encoding.WebName == Configuration.Settings.General.DefaultEncoding)
|
||||
encodingSelectedIndex = comboBoxEncoding.Items.Count - 1;
|
||||
}
|
||||
}
|
||||
@ -142,10 +142,10 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
return Encoding.UTF8;
|
||||
}
|
||||
|
||||
foreach (EncodingInfo ei in Encoding.GetEncodings())
|
||||
foreach (var encoding in Configuration.AvailableEncodings)
|
||||
{
|
||||
if (ei.CodePage + ": " + ei.DisplayName == comboBoxEncoding.Text)
|
||||
return ei.GetEncoding();
|
||||
if (encoding.CodePage + ": " + encoding.EncodingName == comboBoxEncoding.Text)
|
||||
return encoding;
|
||||
}
|
||||
|
||||
return Encoding.UTF8;
|
||||
|
@ -334,17 +334,10 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
|
||||
comboBoxEncoding.Items.Clear();
|
||||
comboBoxEncoding.Items.Add(Encoding.UTF8.EncodingName);
|
||||
foreach (var ei in Encoding.GetEncodings())
|
||||
foreach (var encoding in Configuration.AvailableEncodings)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ei.Name != Encoding.UTF8.BodyName && ei.CodePage >= 949 && !ei.DisplayName.Contains("EBCDIC") && ei.CodePage != 1047) //Configuration.Settings.General.EncodingMinimumCodePage)
|
||||
comboBoxEncoding.Items.Add(ei.CodePage + ": " + ei.DisplayName);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Work-around for issue #1285
|
||||
}
|
||||
if (encoding.CodePage >= 949 && encoding.CodePage != 1047 && !encoding.EncodingName.Contains("EBCDIC") && !encoding.WebName.Equals(Encoding.UTF8.WebName)) //Configuration.Settings.General.EncodingMinimumCodePage
|
||||
comboBoxEncoding.Items.Add(encoding.CodePage + ": " + encoding.EncodingName);
|
||||
}
|
||||
SetEncoding(Configuration.Settings.General.DefaultEncoding);
|
||||
|
||||
@ -613,10 +606,10 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
return Encoding.UTF8;
|
||||
}
|
||||
|
||||
foreach (EncodingInfo ei in Encoding.GetEncodings())
|
||||
foreach (var encoding in Configuration.AvailableEncodings)
|
||||
{
|
||||
if (ei.CodePage + ": " + ei.DisplayName == comboBoxEncoding.Text)
|
||||
return ei.GetEncoding();
|
||||
if (encoding.CodePage + ": " + encoding.EncodingName == comboBoxEncoding.Text)
|
||||
return encoding;
|
||||
}
|
||||
|
||||
return Encoding.UTF8;
|
||||
|
@ -99,12 +99,12 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
comboBoxEncoding.Items.Clear();
|
||||
int encodingSelectedIndex = 0;
|
||||
comboBoxEncoding.Items.Add(Encoding.UTF8.EncodingName);
|
||||
foreach (var ei in Encoding.GetEncodings())
|
||||
foreach (var encoding in Configuration.AvailableEncodings)
|
||||
{
|
||||
if (ei.Name != Encoding.UTF8.BodyName && ei.CodePage >= 949 && !ei.DisplayName.Contains("EBCDIC") && ei.CodePage != 1047)
|
||||
if (encoding.CodePage >= 949 && encoding.CodePage != 1047 && !encoding.EncodingName.Contains("EBCDIC") && !encoding.WebName.Equals(Encoding.UTF8.WebName))
|
||||
{
|
||||
comboBoxEncoding.Items.Add(ei.CodePage + ": " + ei.DisplayName);
|
||||
if (ei.Name == gs.DefaultEncoding || ei.CodePage + ": " + ei.DisplayName == gs.DefaultEncoding)
|
||||
comboBoxEncoding.Items.Add(encoding.CodePage + ": " + encoding.EncodingName);
|
||||
if (encoding.WebName == gs.DefaultEncoding || encoding.CodePage + ": " + encoding.EncodingName == gs.DefaultEncoding)
|
||||
encodingSelectedIndex = comboBoxEncoding.Items.Count - 1;
|
||||
}
|
||||
}
|
||||
@ -1066,9 +1066,9 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
gs.DefaultFrameRate = outFrameRate;
|
||||
|
||||
gs.DefaultEncoding = Encoding.UTF8.BodyName;
|
||||
foreach (var ei in Encoding.GetEncodings())
|
||||
foreach (var encoding in Configuration.AvailableEncodings)
|
||||
{
|
||||
if (ei.CodePage + ": " + ei.DisplayName == comboBoxEncoding.Text)
|
||||
if (encoding.CodePage + ": " + encoding.EncodingName == comboBoxEncoding.Text)
|
||||
gs.DefaultEncoding = comboBoxEncoding.Text;
|
||||
}
|
||||
|
||||
|
@ -89,12 +89,12 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
comboBoxEncoding.Items.Clear();
|
||||
int encodingSelectedIndex = 0;
|
||||
comboBoxEncoding.Items.Add(Encoding.UTF8.EncodingName);
|
||||
foreach (EncodingInfo ei in Encoding.GetEncodings())
|
||||
foreach (var encoding in Configuration.AvailableEncodings)
|
||||
{
|
||||
if (ei.Name != Encoding.UTF8.BodyName && ei.CodePage >= 949 && !ei.DisplayName.Contains("EBCDIC") && ei.CodePage != 1047)
|
||||
if (encoding.CodePage >= 949 && encoding.CodePage != 1047 && !encoding.EncodingName.Contains("EBCDIC") && !encoding.WebName.Equals(Encoding.UTF8.WebName))
|
||||
{
|
||||
comboBoxEncoding.Items.Add(ei.CodePage + ": " + ei.DisplayName);
|
||||
if (ei.Name == Configuration.Settings.General.DefaultEncoding)
|
||||
comboBoxEncoding.Items.Add(encoding.CodePage + ": " + encoding.EncodingName);
|
||||
if (encoding.WebName == Configuration.Settings.General.DefaultEncoding)
|
||||
encodingSelectedIndex = comboBoxEncoding.Items.Count - 1;
|
||||
}
|
||||
}
|
||||
@ -282,10 +282,10 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
return Encoding.UTF8;
|
||||
}
|
||||
|
||||
foreach (EncodingInfo ei in Encoding.GetEncodings())
|
||||
foreach (var encoding in Configuration.AvailableEncodings)
|
||||
{
|
||||
if (ei.CodePage + ": " + ei.DisplayName == comboBoxEncoding.Text)
|
||||
return ei.GetEncoding();
|
||||
if (encoding.CodePage + ": " + encoding.EncodingName == comboBoxEncoding.Text)
|
||||
return encoding;
|
||||
}
|
||||
|
||||
return Encoding.UTF8;
|
||||
|
Loading…
Reference in New Issue
Block a user