Remove charset detection from AssFile::Load

All of the subtitle formats also already do charset detection when
needed, so doing it in it AssFile::Load is pointless and results in
performing the auto-detection even when it's pointless (because the
format isn't text-based or always uses a single encoding).

Originally committed to SVN as r6459.
This commit is contained in:
Thomas Goyne 2012-02-10 00:04:05 +00:00
parent e20bc09052
commit 51a3831794
2 changed files with 3 additions and 12 deletions

View file

@ -51,7 +51,6 @@
#include "ass_file.h" #include "ass_file.h"
#include "ass_override.h" #include "ass_override.h"
#include "ass_style.h" #include "ass_style.h"
#include "charset_detect.h"
#include "compat.h" #include "compat.h"
#include "main.h" #include "main.h"
#include "standard_paths.h" #include "standard_paths.h"
@ -79,21 +78,15 @@ AssFile::~AssFile() {
} }
/// @brief Load generic subs /// @brief Load generic subs
void AssFile::Load(const wxString &_filename,wxString charset,bool addToRecent) { void AssFile::Load(const wxString &_filename, wxString charset, bool addToRecent) {
try { try {
if (charset.empty()) {
charset = CharSetDetect::GetEncoding(_filename);
}
// Get proper format reader // Get proper format reader
const SubtitleFormat *reader = SubtitleFormat::GetReader(_filename); const SubtitleFormat *reader = SubtitleFormat::GetReader(_filename);
if (!reader) { if (!reader) {
wxMessageBox("Unknown file type","Error loading file",wxICON_ERROR | wxOK); wxMessageBox("Unknown file type","Error loading file",wxICON_ERROR | wxOK);
return; return;
} }
// Read file
AssFile temp; AssFile temp;
reader->ReadFile(&temp, _filename, charset); reader->ReadFile(&temp, _filename, charset);
swap(temp); swap(temp);
@ -106,7 +99,6 @@ void AssFile::Load(const wxString &_filename,wxString charset,bool addToRecent)
wxMessageBox(lagi_wxString(e.GetChainedMessage()), "Error loading file", wxICON_ERROR|wxOK); wxMessageBox(lagi_wxString(e.GetChainedMessage()), "Error loading file", wxICON_ERROR|wxOK);
return; return;
} }
// Other error // Other error
catch (...) { catch (...) {
wxMessageBox("Unknown error","Error loading file",wxICON_ERROR | wxOK); wxMessageBox("Unknown error","Error loading file",wxICON_ERROR | wxOK);
@ -116,8 +108,7 @@ void AssFile::Load(const wxString &_filename,wxString charset,bool addToRecent)
// Set general data // Set general data
loaded = true; loaded = true;
filename = _filename; filename = _filename;
wxFileName fn(filename); StandardPaths::SetPathValue("?script", wxFileName(filename).GetPath());
StandardPaths::SetPathValue("?script", fn.GetPath());
// Save backup of file // Save backup of file
if (CanSave() && OPT_GET("App/Auto/Backup")->GetBool()) { if (CanSave() && OPT_GET("App/Auto/Backup")->GetBool()) {

View file

@ -79,7 +79,7 @@ bool MicroDVDSubtitleFormat::CanReadFile(wxString const& filename) const {
} }
void MicroDVDSubtitleFormat::ReadFile(AssFile *target, wxString const& filename, wxString const& encoding) const { void MicroDVDSubtitleFormat::ReadFile(AssFile *target, wxString const& filename, wxString const& encoding) const {
TextFileReader file(filename); TextFileReader file(filename, encoding);
wxRegEx exp("^[\\{\\[]([0-9]+)[\\}\\]][\\{\\[]([0-9]+)[\\}\\]](.*)$", wxRE_ADVANCED); wxRegEx exp("^[\\{\\[]([0-9]+)[\\}\\]][\\{\\[]([0-9]+)[\\}\\]](.*)$", wxRE_ADVANCED);
target->LoadDefault(false); target->LoadDefault(false);