From 0c37816c28b76711543c228cc46af84c7ae25a39 Mon Sep 17 00:00:00 2001 From: Andrea Odetti Date: Sun, 2 Jul 2017 20:53:03 +0100 Subject: [PATCH] Move FindResource to the interface as in QT it will be handled differently. Signed-off-by: Andrea Odetti --- CMakeLists.txt | 1 + source/frontends/ncurses/resources.cpp | 39 ++++++++++++++++++++++++++ source/linux/interface.h | 4 +++ source/linux/wwrapper.cpp | 31 -------------------- 4 files changed, 44 insertions(+), 31 deletions(-) create mode 100644 source/frontends/ncurses/resources.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 38a841ca..2e8e4316 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ add_executable(applen source/frontends/ncurses/asciiart.cpp source/frontends/ncurses/input.cpp source/frontends/ncurses/benchmark.cpp + source/frontends/ncurses/resources.cpp ) target_link_libraries(applen diff --git a/source/frontends/ncurses/resources.cpp b/source/frontends/ncurses/resources.cpp new file mode 100644 index 00000000..19f100d9 --- /dev/null +++ b/source/frontends/ncurses/resources.cpp @@ -0,0 +1,39 @@ +#include "StdAfx.h" + +#include +#include +#include + +#include "Log.h" +#include "linux/wwrapper.h" + +HRSRC FindResource(void *, const std::string & filename, const char *) +{ + HRSRC result; + + if (!filename.empty()) + { + const std::string path = "resource/" + filename; + + int fd = open(path.c_str(), O_RDONLY); + + if (fd != -1) + { + struct stat stdbuf; + if ((fstat(fd, &stdbuf) == 0) && S_ISREG(stdbuf.st_mode)) + { + const off_t size = stdbuf.st_size; + result.data.resize(size); + ssize_t rd = read(fd, result.data.data(), size); + } + close(fd); + } + } + + if (result.data.empty()) + { + LogFileOutput("FindResource: could not load resource %s\n", filename.c_str()); + } + + return result; +} diff --git a/source/linux/interface.h b/source/linux/interface.h index de9a08ff..5c08a5b7 100644 --- a/source/linux/interface.h +++ b/source/linux/interface.h @@ -1,5 +1,9 @@ #pragma once +// Resources + +HRSRC FindResource(void *, const std::string & filename, const char *); + // Frame void FrameDrawDiskLEDS(HDC x); diff --git a/source/linux/wwrapper.cpp b/source/linux/wwrapper.cpp index 08abe129..9b97c094 100644 --- a/source/linux/wwrapper.cpp +++ b/source/linux/wwrapper.cpp @@ -177,37 +177,6 @@ std::string MAKEINTRESOURCE(int x) return std::string(); } -HRSRC FindResource(void *, const std::string & filename, const char *) -{ - HRSRC result; - - if (!filename.empty()) - { - const std::string path = "resource/" + filename; - - int fd = open(path.c_str(), O_RDONLY); - - if (fd != -1) - { - struct stat stdbuf; - if ((fstat(fd, &stdbuf) == 0) && S_ISREG(stdbuf.st_mode)) - { - const off_t size = stdbuf.st_size; - result.data.resize(size); - ssize_t rd = read(fd, result.data.data(), size); - } - close(fd); - } - } - - if (result.data.empty()) - { - LogFileOutput("FindResource: could not load resource %s\n", filename.c_str()); - } - - return result; -} - DWORD SizeofResource(void *, const HRSRC & res) { return res.data.size();