aboutsummaryrefslogtreecommitdiff
path: root/src/FileUtil.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-04-22 05:58:44 +0200
committerdec05eba <dec05eba@protonmail.com>2018-04-22 05:59:18 +0200
commit1e0e68f9cda51c881b32a54d9eece71c1428f7ac (patch)
treeb8faa1d971c245e3fcf046aa1d2daa1fa601e0f9 /src/FileUtil.cpp
parent424b02609fa34175a4e2aadb95e68b3c9c8dc93c (diff)
Add video and gif support
Gif streams from url. Todo: Add play controls to video
Diffstat (limited to 'src/FileUtil.cpp')
-rw-r--r--src/FileUtil.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/FileUtil.cpp b/src/FileUtil.cpp
new file mode 100644
index 0000000..53687dd
--- /dev/null
+++ b/src/FileUtil.cpp
@@ -0,0 +1,35 @@
+#include "../include/FileUtil.hpp"
+#include "../include/env.hpp"
+#include <cstdio>
+
+using namespace std;
+
+namespace dchat
+{
+ StringView getFileContent(const boost::filesystem::path &filepath)
+ {
+#if OS_FAMILY == OS_FAMILY_POSIX
+ FILE *file = fopen(filepath.c_str(), "rb");
+#else
+ FILE *file = _wfopen(filepath.c_str(), L"rb");
+#endif
+ if(!file)
+ {
+ int error = errno;
+ string errMsg = "Failed to open file: ";
+ errMsg += filepath.string();
+ errMsg += "; reason: ";
+ errMsg += strerror(error);
+ throw FileException(errMsg);
+ }
+
+ fseek(file, 0, SEEK_END);
+ size_t fileSize = ftell(file);
+ fseek(file, 0, SEEK_SET);
+
+ char *fileData = new char[fileSize];
+ fread(fileData, 1, fileSize, file);
+ fclose(file);
+ return { fileData, fileSize };
+ }
+}