diff --git a/aegisub/src/dialog_style_manager.cpp b/aegisub/src/dialog_style_manager.cpp index 4eb5e783e..5a285b0ec 100644 --- a/aegisub/src/dialog_style_manager.cpp +++ b/aegisub/src/dialog_style_manager.cpp @@ -583,7 +583,7 @@ void DialogStyleManager::OnCurrentImport() { AssFile temp; try { - auto reader = SubtitleFormat::GetReader(filename); + auto reader = SubtitleFormat::GetReader(filename, charset); if (!reader) wxMessageBox("Unsupported subtitle format", "Error", wxOK | wxICON_ERROR | wxCENTER, this); else diff --git a/aegisub/src/subs_controller.cpp b/aegisub/src/subs_controller.cpp index 9f8e69a9f..2cfa237a0 100644 --- a/aegisub/src/subs_controller.cpp +++ b/aegisub/src/subs_controller.cpp @@ -107,7 +107,7 @@ void SubsController::Load(agi::fs::path const& filename, std::string charset) { } } - const SubtitleFormat *reader = SubtitleFormat::GetReader(filename); + const SubtitleFormat *reader = SubtitleFormat::GetReader(filename, charset); try { AssFile temp; diff --git a/aegisub/src/subtitle_format.cpp b/aegisub/src/subtitle_format.cpp index 48b227609..d5f6f9fc2 100644 --- a/aegisub/src/subtitle_format.cpp +++ b/aegisub/src/subtitle_format.cpp @@ -76,7 +76,7 @@ SubtitleFormat::~SubtitleFormat() { formats.erase(remove(begin(formats), end(formats), this)); } -bool SubtitleFormat::CanReadFile(agi::fs::path const& filename) const { +bool SubtitleFormat::CanReadFile(agi::fs::path const& filename, std::string const&) const { auto wildcards = GetReadWildcards(); return any_of(begin(wildcards), end(wildcards), [&](std::string const& ext) { return agi::fs::HasExtension(filename, ext); }); @@ -335,9 +335,9 @@ SubtitleFormat *find_or_throw(Cont &container, Pred pred) { return *it; } -const SubtitleFormat *SubtitleFormat::GetReader(agi::fs::path const& filename) { +const SubtitleFormat *SubtitleFormat::GetReader(agi::fs::path const& filename, std::string const& encoding) { LoadFormats(); - return find_or_throw(formats, std::bind(&SubtitleFormat::CanReadFile, _1, filename)); + return find_or_throw(formats, std::bind(&SubtitleFormat::CanReadFile, _1, filename, encoding)); } const SubtitleFormat *SubtitleFormat::GetWriter(agi::fs::path const& filename) { diff --git a/aegisub/src/subtitle_format.h b/aegisub/src/subtitle_format.h index 7f0a1ed32..02ba14dae 100644 --- a/aegisub/src/subtitle_format.h +++ b/aegisub/src/subtitle_format.h @@ -93,7 +93,7 @@ public: /// /// Default implementation simply checks if the file's extension is in the /// format's wildcard list - virtual bool CanReadFile(agi::fs::path const& filename) const; + virtual bool CanReadFile(agi::fs::path const& filename, std::string const& encoding) const; /// @brief Check if the given file can be written by this format /// @@ -124,7 +124,7 @@ public: static std::string GetWildcards(int mode); /// Get a subtitle format that can read the given file or nullptr if none can - static const SubtitleFormat *GetReader(agi::fs::path const& filename); + static const SubtitleFormat *GetReader(agi::fs::path const& filename, std::string const& encoding); /// Get a subtitle format that can write the given file or nullptr if none can static const SubtitleFormat *GetWriter(agi::fs::path const& filename); /// Initialize subtitle formats diff --git a/aegisub/src/subtitle_format_microdvd.cpp b/aegisub/src/subtitle_format_microdvd.cpp index 6db8f0886..3733874d7 100644 --- a/aegisub/src/subtitle_format_microdvd.cpp +++ b/aegisub/src/subtitle_format_microdvd.cpp @@ -39,7 +39,6 @@ #include "ass_dialogue.h" #include "ass_file.h" #include "ass_time.h" -#include "charset_detect.h" #include "text_file_reader.h" #include "text_file_writer.h" #include "video_context.h" @@ -70,14 +69,11 @@ std::vector MicroDVDSubtitleFormat::GetWriteWildcards() const { static const boost::regex line_regex("^[\\{\\[]([0-9]+)[\\}\\]][\\{\\[]([0-9]+)[\\}\\]](.*)$"); -bool MicroDVDSubtitleFormat::CanReadFile(agi::fs::path const& filename) const { +bool MicroDVDSubtitleFormat::CanReadFile(agi::fs::path const& filename, std::string const& encoding) const { // Return false immediately if extension is wrong if (!agi::fs::HasExtension(filename, "sub")) return false; // Since there is an infinity of .sub formats, load first line and check if it's valid - auto encoding = CharSetDetect::GetEncoding(filename); - if (encoding == "binary") return false; - TextFileReader file(filename, encoding); if (file.HasMoreLines()) return regex_match(file.ReadLineFromFile(), line_regex); diff --git a/aegisub/src/subtitle_format_microdvd.h b/aegisub/src/subtitle_format_microdvd.h index 96fc4017a..b8ad7c51f 100644 --- a/aegisub/src/subtitle_format_microdvd.h +++ b/aegisub/src/subtitle_format_microdvd.h @@ -41,7 +41,7 @@ public: std::vector GetReadWildcards() const override; std::vector GetWriteWildcards() const override; - bool CanReadFile(agi::fs::path const& filename) const override; + bool CanReadFile(agi::fs::path const& filename, std::string const& encoding) const override; void ReadFile(AssFile *target, agi::fs::path const& filename, std::string const& forceEncoding) const override; void WriteFile(const AssFile *src, agi::fs::path const& filename, std::string const& encoding) const override;