Fix importing styles from files in non-local charsets (i.e. hopefully all of them)

This commit is contained in:
Thomas Goyne 2013-06-09 07:53:07 -07:00
parent ef2a39fc7b
commit 2a2a623bb4
2 changed files with 12 additions and 3 deletions

View file

@ -38,6 +38,7 @@
#include "ass_dialogue.h"
#include "ass_file.h"
#include "ass_style.h"
#include "charset_detect.h"
#include "compat.h"
#include "dialog_selected_choices.h"
#include "dialog_style_editor.h"
@ -565,13 +566,21 @@ void DialogStyleManager::OnCurrentImport() {
auto filename = OpenFileSelector(_("Open subtitles file"), "Path/Last/Subtitles", "", "", SubtitleFormat::GetWildcards(0), this);
if (filename.empty()) return;
std::string charset;
try {
charset = CharSetDetect::GetEncoding(filename);
}
catch (agi::UserCancelException const&) {
return;
}
AssFile temp;
try {
auto reader = SubtitleFormat::GetReader(filename);
if (!reader)
wxMessageBox("Unsupported subtitle format", "Error", wxOK | wxICON_ERROR | wxCENTER, this);
else
reader->ReadFile(&temp, filename);
reader->ReadFile(&temp, filename, charset);
}
catch (agi::Exception const& err) {
wxMessageBox(to_wx(err.GetChainedMessage()), "Error", wxOK | wxICON_ERROR | wxCENTER, this);

View file

@ -110,8 +110,8 @@ public:
/// Load a subtitle file
/// @param[out] target Destination to read lines into
/// @param filename File to load
/// @param forceEncoding Encoding to use or empty string for default
virtual void ReadFile(AssFile *target, agi::fs::path const& filename, std::string const& forceEncoding="") const { }
/// @param encoding Encoding to use. May be ignored by the reader.
virtual void ReadFile(AssFile *target, agi::fs::path const& filename, std::string const& encoding) const { }
/// Save a subtitle file
/// @param src Data to write