aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2023-10-05 21:01:39 +0800
committercrupest <crupest@outlook.com>2023-10-05 21:01:39 +0800
commitc1f491712ab071030ed8ca9587c896ca2856ab97 (patch)
treed2eef18f377a2b2ad93c6fbf56989de11789e77e /src
parent6cd1d68baf219b5d3c742ba5fb3a9ee04e830999 (diff)
downloadcru-c1f491712ab071030ed8ca9587c896ca2856ab97.tar.gz
cru-c1f491712ab071030ed8ca9587c896ca2856ab97.tar.bz2
cru-c1f491712ab071030ed8ca9587c896ca2856ab97.zip
...
Diffstat (limited to 'src')
-rw-r--r--src/common/io/CFileStream.cpp42
-rw-r--r--src/ui/ThemeResourceDictionary.cpp4
2 files changed, 2 insertions, 44 deletions
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 <cstdio>
@@ -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> 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<ThemeResourceDictionary>(parser.Parse(), false);