From c1f491712ab071030ed8ca9587c896ca2856ab97 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 5 Oct 2023 21:01:39 +0800 Subject: ... --- src/common/io/CFileStream.cpp | 42 -------------------------------------- src/ui/ThemeResourceDictionary.cpp | 4 ++-- 2 files changed, 2 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/common/io/CFileStream.cpp b/src/common/io/CFileStream.cpp index 133cd8f6..de195538 100644 --- a/src/common/io/CFileStream.cpp +++ b/src/common/io/CFileStream.cpp @@ -1,6 +1,5 @@ #include "cru/common/io/CFileStream.h" #include "cru/common/Exception.h" -#include "cru/common/io/OpenFileFlag.h" #include "cru/common/io/Stream.h" #include @@ -45,47 +44,6 @@ CFileStream::CFileStream(std::FILE* file, bool readable, bool writable, } } -namespace { -/** - * Generally the fopen will return a NULL ptr if the file does not exist. Then - * we must throw FileNotExistException. However, there are cases we have to - * check existence explicitly before. The case is OpenFileFlags::Write is - * specified but OpenFileFlags::Create is not, in which fopen usually create a - * new file automatically but we want a FileNotExistException to be thrown. - */ -std::string ConvertOpenFileFlagToCFileFlag(OpenFileFlag flags, - bool* explicit_check_exist) { - *explicit_check_exist = false; - - std::string result; - - bool need_read = flags & OpenFileFlags::Read; - bool need_write = flags & OpenFileFlags::Write; - - if (!need_write) { - // No need to write? The simplest - // Note even OpenFileFlags::Create is set, we still have to check exist. - return "r"; - } - - // Now we need writing. - - bool create = OpenFileFlags::Create; - - if (!create) { - *explicit_check_exist = true; - } - - bool append = flags & OpenFileFlags::Append; - - if (!need_read) { - return "w"; - } -} -} // namespace - -CFileStream::CFileStream(String path, OpenFileFlag flags) {} - CFileStream::~CFileStream() { if (auto_close_ && file_ != nullptr) { std::fclose(file_); diff --git a/src/ui/ThemeResourceDictionary.cpp b/src/ui/ThemeResourceDictionary.cpp index 6720626e..f91fcb1c 100644 --- a/src/ui/ThemeResourceDictionary.cpp +++ b/src/ui/ThemeResourceDictionary.cpp @@ -1,5 +1,5 @@ #include "cru/ui/ThemeResourceDictionary.h" -#include "cru/common/io/FileStream.h" +#include "cru/common/io/CFileStream.h" #include "cru/common/log/Logger.h" #include "cru/xml/XmlNode.h" #include "cru/xml/XmlParser.h" @@ -8,7 +8,7 @@ namespace cru::ui { std::unique_ptr ThemeResourceDictionary::FromFile( const String& file_path) { - io::FileStream stream(file_path, io::OpenFileFlags::Read); + io::CFileStream stream(file_path.ToUtf8().c_str(), "r"); auto xml_string = stream.ReadAllAsString(); auto parser = xml::XmlParser(xml_string); return std::make_unique(parser.Parse(), false); -- cgit v1.2.3