diff --git a/aegisub/libaegisub/common/charset.cpp b/aegisub/libaegisub/common/charset.cpp index 8ad4df4b6..649353082 100644 --- a/aegisub/libaegisub/common/charset.cpp +++ b/aegisub/libaegisub/common/charset.cpp @@ -48,24 +48,24 @@ public: : nsUniversalDetector(NS_FILTER_ALL) { { - std::unique_ptr fp(agi::io::Open(file, true)); + std::ifstream fp(agi::io::Open(file, true)); // If it's over 100 MB it's either binary or big enough that we won't // be able to do anything useful with it anyway - fp->seekg(0, std::ios::end); - if (fp->tellg() > 100 * 1024 * 1024) { + fp.seekg(0, std::ios::end); + if (fp.tellg() > 100 * 1024 * 1024) { list.emplace_back(1.f, "binary"); return; } - fp->seekg(0, std::ios::beg); + fp.seekg(0, std::ios::beg); std::streamsize binaryish = 0; std::streamsize bytes = 0; - while (!mDone && *fp) { + while (!mDone && fp) { char buf[4096]; - fp->read(buf, sizeof(buf)); - std::streamsize read = fp->gcount(); + fp.read(buf, sizeof(buf)); + std::streamsize read = fp.gcount(); HandleData(buf, (PRUint32)read); // A dumb heuristic to detect binary files diff --git a/aegisub/libaegisub/common/io.cpp b/aegisub/libaegisub/common/io.cpp index 798b65923..80640cf2a 100644 --- a/aegisub/libaegisub/common/io.cpp +++ b/aegisub/libaegisub/common/io.cpp @@ -30,18 +30,16 @@ namespace agi { namespace io { -std::ifstream* Open(fs::path const& file, bool binary) { +std::ifstream Open(fs::path const& file, bool binary) { LOG_D("agi/io/open/file") << file; acs::CheckFileRead(file); - auto stream = new boost::filesystem::ifstream(file, (binary ? std::ios::binary : std::ios::in)); + boost::filesystem::ifstream stream(file, (binary ? std::ios::binary : std::ios::in)); - if (stream->fail()) { - delete stream; + if (stream.fail()) throw IOFatal("Unknown fatal error as occurred"); - } - return stream; + return std::move(stream); } Save::Save(fs::path const& file, bool binary) diff --git a/aegisub/libaegisub/common/json.cpp b/aegisub/libaegisub/common/json.cpp index dfa40e7d5..de5aec94f 100644 --- a/aegisub/libaegisub/common/json.cpp +++ b/aegisub/libaegisub/common/json.cpp @@ -21,22 +21,18 @@ #include "libaegisub/json.h" #include -#include #include #include "libaegisub/fs.h" #include "libaegisub/io.h" #include "libaegisub/log.h" -namespace agi { - namespace json_util { +namespace agi { namespace json_util { -json::UnknownElement parse(std::istream *stream) { +json::UnknownElement parse(std::istream&& stream) { try { - std::unique_ptr stream_deleter(stream); - json::UnknownElement root; - json::Reader::Read(root, *stream); + json::Reader::Read(root, stream); return root; } catch (json::Reader::ParseException& e) { LOG_E("json/parse") << "json::ParseException: " << e.what() << ", Line/offset: " << e.m_locTokenBegin.m_nLine + 1 << '/' << e.m_locTokenBegin.m_nLineOffset + 1; @@ -57,17 +53,16 @@ json::UnknownElement file(agi::fs::path const& file, const std::string &default_ } catch (fs::FileNotFound const&) { // Not an error - return parse(new std::istringstream(default_config)); + return parse(std::istringstream(default_config)); } catch (json::Exception&) { // Already logged in parse - return parse(new std::istringstream(default_config)); + return parse(std::istringstream(default_config)); } catch (agi::Exception& e) { LOG_E("json/file") << "Unexpected error when reading config file " << file << ": " << e.GetMessage(); - return parse(new std::istringstream(default_config)); + return parse(std::istringstream(default_config)); } } - } // namespace json_util -} // namespace agi +} } diff --git a/aegisub/libaegisub/common/keyframe.cpp b/aegisub/libaegisub/common/keyframe.cpp index fa98c41ca..c6bccc8e3 100644 --- a/aegisub/libaegisub/common/keyframe.cpp +++ b/aegisub/libaegisub/common/keyframe.cpp @@ -85,8 +85,7 @@ void Save(agi::fs::path const& filename, std::vector const& keyframes) { } std::vector Load(agi::fs::path const& filename) { - std::unique_ptr file(io::Open(filename)); - std::istream &is(*file); + std::ifstream is(io::Open(filename)); std::string header; getline(is, header); diff --git a/aegisub/libaegisub/common/option.cpp b/aegisub/libaegisub/common/option.cpp index f57bd6a91..d2393f72f 100644 --- a/aegisub/libaegisub/common/option.cpp +++ b/aegisub/libaegisub/common/option.cpp @@ -89,8 +89,8 @@ void Options::ConfigNext(std::istream& stream) { void Options::ConfigUser() { try { - std::unique_ptr stream(io::Open(config_file)); - LoadConfig(*stream, true); + std::ifstream stream(io::Open(config_file)); + LoadConfig(stream, true); } catch (fs::FileNotFound const&) { return; diff --git a/aegisub/libaegisub/common/thesaurus.cpp b/aegisub/libaegisub/common/thesaurus.cpp index 0c66368c5..56806ff46 100644 --- a/aegisub/libaegisub/common/thesaurus.cpp +++ b/aegisub/libaegisub/common/thesaurus.cpp @@ -35,15 +35,15 @@ namespace agi { Thesaurus::Thesaurus(agi::fs::path const& dat_path, agi::fs::path const& idx_path) : dat(io::Open(dat_path)) { - std::unique_ptr idx(io::Open(idx_path)); + std::ifstream idx(io::Open(idx_path)); std::string encoding_name; - getline(*idx, encoding_name); + getline(idx, encoding_name); std::string unused_entry_count; - getline(*idx, unused_entry_count); + getline(idx, unused_entry_count); // Read the list of words and file offsets for those words - for (line_iterator iter(*idx, encoding_name), end; iter != end; ++iter) { + for (line_iterator iter(idx, encoding_name), end; iter != end; ++iter) { std::vector chunks; boost::split(chunks, *iter, _1 == '|'); if (chunks.size() == 2) @@ -57,17 +57,17 @@ Thesaurus::~Thesaurus() { } void Thesaurus::Lookup(std::string const& word, std::vector *out) { out->clear(); - if (!dat.get()) return; + if (!dat) return; std::map::const_iterator it = offsets.find(word); if (it == offsets.end()) return; - dat->seekg(it->second, std::ios::beg); - if (!dat->good()) return; + dat.seekg(it->second, std::ios::beg); + if (!dat.good()) return; // First line is the word and meaning count std::string temp; - getline(*dat, temp); + getline(dat, temp); std::vector header; std::string converted(conv->Convert(temp)); boost::split(header, converted, _1 == '|'); @@ -77,7 +77,7 @@ void Thesaurus::Lookup(std::string const& word, std::vector *out) { out->resize(meanings); for (int i = 0; i < meanings; ++i) { std::vector line; - getline(*dat, temp); + getline(dat, temp); std::string converted(conv->Convert(temp)); boost::split(line, converted, _1 == '|'); diff --git a/aegisub/libaegisub/common/vfr.cpp b/aegisub/libaegisub/common/vfr.cpp index 39288741f..0e7bc9471 100644 --- a/aegisub/libaegisub/common/vfr.cpp +++ b/aegisub/libaegisub/common/vfr.cpp @@ -206,18 +206,18 @@ Framerate::Framerate(fs::path const& filename) : denominator(default_denominator) , numerator(0) { - scoped_ptr file(agi::io::Open(filename)); + std::ifstream file(agi::io::Open(filename)); std::string encoding = agi::charset::Detect(filename); - std::string line = *line_iterator(*file, encoding); + std::string line = *line_iterator(file, encoding); if (line == "# timecode format v2") { - copy(line_iterator(*file, encoding), line_iterator(), back_inserter(timecodes)); + copy(line_iterator(file, encoding), line_iterator(), back_inserter(timecodes)); SetFromTimecodes(); return; } if (line == "# timecode format v1" || line.substr(0, 7) == "Assume ") { if (line[0] == '#') - line = *line_iterator(*file, encoding); - numerator = v1_parse(line_iterator(*file, encoding), line, timecodes, last); + line = *line_iterator(file, encoding); + numerator = v1_parse(line_iterator(file, encoding), line, timecodes, last); return; } diff --git a/aegisub/libaegisub/include/libaegisub/io.h b/aegisub/libaegisub/include/libaegisub/io.h index b23d73a29..684d0a1f3 100644 --- a/aegisub/libaegisub/include/libaegisub/io.h +++ b/aegisub/libaegisub/include/libaegisub/io.h @@ -28,7 +28,7 @@ namespace agi { DEFINE_BASE_EXCEPTION_NOINNER(IOError, Exception) DEFINE_SIMPLE_EXCEPTION_NOINNER(IOFatal, IOError, "io/fatal") -std::ifstream* Open(fs::path const& file, bool binary = false); +std::ifstream Open(fs::path const& file, bool binary = false); class Save { std::ofstream *fp; diff --git a/aegisub/libaegisub/include/libaegisub/json.h b/aegisub/libaegisub/include/libaegisub/json.h index e132120fb..95303a5e7 100644 --- a/aegisub/libaegisub/include/libaegisub/json.h +++ b/aegisub/libaegisub/include/libaegisub/json.h @@ -24,9 +24,8 @@ namespace agi { namespace json_util { /// Parse a JSON stream. -/// @param stream JSON stream, this is deleted internally. /// @return json::UnknownElement -json::UnknownElement parse(std::istream *stream); +json::UnknownElement parse(std::istream&& stream); /// Parse a JSON file. /// @param file Path JSON to file diff --git a/aegisub/libaegisub/include/libaegisub/thesaurus.h b/aegisub/libaegisub/include/libaegisub/thesaurus.h index 88b2c4360..290c72209 100644 --- a/aegisub/libaegisub/include/libaegisub/thesaurus.h +++ b/aegisub/libaegisub/include/libaegisub/thesaurus.h @@ -18,7 +18,7 @@ #include "fs_fwd.h" -#include +#include #include #include #include @@ -32,13 +32,13 @@ class Thesaurus { /// Map of word -> byte position in the data file std::map offsets; /// Read handle to the data file - std::unique_ptr dat; + std::ifstream dat; /// Converter from the data file's charset to UTF-8 std::unique_ptr conv; public: /// A pair of a word and synonyms for that word - typedef std::pair > Entry; + typedef std::pair> Entry; /// Constructor /// @param dat_path Path to data file diff --git a/aegisub/src/ass_attachment.cpp b/aegisub/src/ass_attachment.cpp index 6217c7c61..87e53ac3b 100644 --- a/aegisub/src/ass_attachment.cpp +++ b/aegisub/src/ass_attachment.cpp @@ -40,11 +40,11 @@ AssAttachment::AssAttachment(agi::fs::path const& name, AssEntryGroup group) filename = filename.get().substr(0, filename.get().size() - 4) + "_0" + filename.get().substr(filename.get().size() - 4); std::vector data; - std::unique_ptr file(agi::io::Open(name, true)); - file->seekg(0, std::ios::end); - data.resize(file->tellg()); - file->seekg(0, std::ios::beg); - file->read(&data[0], data.size()); + std::ifstream file(agi::io::Open(name, true)); + file.seekg(0, std::ios::end); + data.resize(file.tellg()); + file.seekg(0, std::ios::beg); + file.read(&data[0], data.size()); entry_data = (group == ENTRY_FONT ? "fontname: " : "filename: ") + filename.get() + "\r\n"; entry_data = entry_data.get() + agi::ass::UUEncode(data); diff --git a/aegisub/src/ass_style_storage.cpp b/aegisub/src/ass_style_storage.cpp index aeae259d8..a3998f39c 100644 --- a/aegisub/src/ass_style_storage.cpp +++ b/aegisub/src/ass_style_storage.cpp @@ -66,8 +66,8 @@ void AssStyleStorage::Load(agi::fs::path const& filename) { Clear(); try { - std::unique_ptr in(agi::io::Open(file)); - for (auto const& line : agi::line_iterator(*in)) { + std::ifstream in(agi::io::Open(file)); + for (auto const& line : agi::line_iterator(in)) { try { style.push_back(new AssStyle(line)); } catch(...) { diff --git a/aegisub/src/auto4_lua_scriptreader.cpp b/aegisub/src/auto4_lua_scriptreader.cpp index 3e7f09028..4c79722ce 100644 --- a/aegisub/src/auto4_lua_scriptreader.cpp +++ b/aegisub/src/auto4_lua_scriptreader.cpp @@ -28,8 +28,6 @@ #include #include -#include - namespace Automation4 { LuaScriptReader::LuaScriptReader(agi::fs::path const& filename) : conv(new agi::charset::IconvWrapper(CharSetDetect::GetEncoding(filename).c_str(), "utf-8", false)) @@ -41,11 +39,11 @@ namespace Automation4 { const char *LuaScriptReader::Read(size_t *bytes_read) { char in_buf[512]; - file->read(in_buf, sizeof(in_buf)); + file.read(in_buf, sizeof(in_buf)); const char *in = in_buf; char *out = buf; - size_t in_bytes = file->gcount(); + size_t in_bytes = file.gcount(); size_t out_bytes = sizeof(buf); conv->Convert(&in, &in_bytes, &out, &out_bytes); diff --git a/aegisub/src/auto4_lua_scriptreader.h b/aegisub/src/auto4_lua_scriptreader.h index 5e8d1291e..065433695 100644 --- a/aegisub/src/auto4_lua_scriptreader.h +++ b/aegisub/src/auto4_lua_scriptreader.h @@ -19,7 +19,7 @@ #include -#include +#include #include #include @@ -29,7 +29,7 @@ namespace agi { namespace charset { class IconvWrapper; } } namespace Automation4 { class LuaScriptReader { std::unique_ptr conv; - std::unique_ptr file; + std::ifstream file; char buf[512]; const char *Read(size_t *bytes_read); diff --git a/aegisub/src/dialog_shift_times.cpp b/aegisub/src/dialog_shift_times.cpp index 72974ec6d..e043bb104 100644 --- a/aegisub/src/dialog_shift_times.cpp +++ b/aegisub/src/dialog_shift_times.cpp @@ -302,9 +302,9 @@ void DialogShiftTimes::LoadHistory() { history_box->Freeze(); try { - std::unique_ptr file(agi::io::Open(history_filename)); + std::ifstream file(agi::io::Open(history_filename)); json::UnknownElement root; - json::Reader::Read(root, *file); + json::Reader::Read(root, file); *history = root; for (auto& history_entry : *history) diff --git a/aegisub/src/dialog_version_check.cpp b/aegisub/src/dialog_version_check.cpp index 1437190c7..c0c2bfc51 100644 --- a/aegisub/src/dialog_version_check.cpp +++ b/aegisub/src/dialog_version_check.cpp @@ -304,7 +304,7 @@ void DoCheck(bool interactive) { throw VersionCheckError(from_wx(_("Could not connect to updates server."))); stream << boost::format( - "GET %s?rev=%d&rel=%d&os=%s&lang=%s&aegilang=%s HTTP/1.0\r\n" + "GET %s.json?rev=%d&rel=%d&os=%s&lang=%s&aegilang=%s HTTP/1.0\r\n" "User-Agent: Aegisub %s\r\n" "Host: %s\r\n" "Accept: */*\r\n" diff --git a/aegisub/src/main.cpp b/aegisub/src/main.cpp index cb588c1de..5cdd27d2d 100644 --- a/aegisub/src/main.cpp +++ b/aegisub/src/main.cpp @@ -140,7 +140,7 @@ bool AegisubApp::OnInit() { // Try loading configuration from the install dir if one exists there try { auto conf_local(config::path->Decode("?data/config.json")); - std::unique_ptr localConfig(agi::io::Open(conf_local)); + std::ifstream localConfig(agi::io::Open(conf_local)); config::opt = new agi::Options(conf_local, GET_DEFAULT_CONFIG(default_config)); // Local config, make ?user mean ?data so all user settings are placed in install dir diff --git a/aegisub/src/spellchecker_hunspell.cpp b/aegisub/src/spellchecker_hunspell.cpp index 794c69f92..1eb6119b6 100644 --- a/aegisub/src/spellchecker_hunspell.cpp +++ b/aegisub/src/spellchecker_hunspell.cpp @@ -91,9 +91,9 @@ void HunspellSpellChecker::ReadUserDictionary() { // Read the old contents of the user's dictionary try { - std::unique_ptr stream(agi::io::Open(userDicPath)); + std::ifstream stream(agi::io::Open(userDicPath)); copy_if( - ++agi::line_iterator(*stream), agi::line_iterator(), + ++agi::line_iterator(stream), agi::line_iterator(), inserter(customWords, customWords.end()), [](std::string const& str) { return !str.empty(); }); } diff --git a/aegisub/src/text_file_reader.cpp b/aegisub/src/text_file_reader.cpp index 5b5d61e5c..edc01e41f 100644 --- a/aegisub/src/text_file_reader.cpp +++ b/aegisub/src/text_file_reader.cpp @@ -36,8 +36,8 @@ TextFileReader::TextFileReader(agi::fs::path const& filename, std::string encodi { if (encoding.empty()) encoding = CharSetDetect::GetEncoding(filename); - file.reset(agi::io::Open(filename, true)); - iter = agi::line_iterator(*file, encoding); + file = agi::io::Open(filename, true); + iter = agi::line_iterator(file, encoding); } TextFileReader::~TextFileReader() { diff --git a/aegisub/src/text_file_reader.h b/aegisub/src/text_file_reader.h index 9b54cf3cf..df3f930b3 100644 --- a/aegisub/src/text_file_reader.h +++ b/aegisub/src/text_file_reader.h @@ -22,7 +22,6 @@ #pragma once #include -#include #include #include @@ -31,7 +30,7 @@ /// @class TextFileReader /// @brief A line-based text file reader class TextFileReader { - std::unique_ptr file; + std::ifstream file; bool trim; agi::line_iterator iter; diff --git a/aegisub/src/toolbar.cpp b/aegisub/src/toolbar.cpp index 40b772888..5ecf8debf 100644 --- a/aegisub/src/toolbar.cpp +++ b/aegisub/src/toolbar.cpp @@ -43,7 +43,7 @@ namespace { json::Object const& get_root() { static json::Object root; if (root.empty()) - root = agi::json_util::parse(new std::istringstream(GET_DEFAULT_CONFIG(default_toolbar))); + root = agi::json_util::parse(std::istringstream(GET_DEFAULT_CONFIG(default_toolbar))); return root; }