2017-07-02 20:53:03 +01:00
|
|
|
#include "StdAfx.h"
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2020-07-12 09:55:51 +01:00
|
|
|
#include <libgen.h>
|
2017-07-02 20:53:03 +01:00
|
|
|
|
|
|
|
#include "Log.h"
|
|
|
|
|
2020-07-12 09:55:51 +01:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
std::string getResourcePath()
|
|
|
|
{
|
|
|
|
std::string resource;
|
|
|
|
char self[1024] = {0};
|
|
|
|
const int ch = readlink("/proc/self/exe", self, sizeof(self));
|
|
|
|
if (ch != -1)
|
|
|
|
{
|
|
|
|
const char * path = dirname(self);
|
|
|
|
resource.assign(path);
|
|
|
|
resource += "/../resource/";
|
|
|
|
}
|
|
|
|
// else?
|
|
|
|
return resource;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string resourcePath = getResourcePath();
|
|
|
|
}
|
|
|
|
|
2020-07-07 20:13:26 +01:00
|
|
|
HRSRC FindResource(void *, const char * filename, const char *)
|
2017-07-02 20:53:03 +01:00
|
|
|
{
|
|
|
|
HRSRC result;
|
|
|
|
|
2020-07-07 20:13:26 +01:00
|
|
|
if (filename)
|
2017-07-02 20:53:03 +01:00
|
|
|
{
|
2020-07-12 09:55:51 +01:00
|
|
|
const std::string path = resourcePath + filename;
|
2017-07-02 20:53:03 +01:00
|
|
|
|
|
|
|
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())
|
|
|
|
{
|
2020-07-07 20:13:26 +01:00
|
|
|
LogFileOutput("FindResource: could not load resource %s\n", filename);
|
2017-07-02 20:53:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2019-11-20 21:23:27 +00:00
|
|
|
|
2020-07-07 20:13:26 +01:00
|
|
|
HBITMAP LoadBitmap(HINSTANCE hInstance, const char * filename)
|
2019-11-20 21:23:27 +00:00
|
|
|
{
|
2020-07-07 20:13:26 +01:00
|
|
|
LogFileOutput("LoadBitmap: not loading resource %s\n", filename);
|
2019-11-20 21:23:27 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG GetBitmapBits(HBITMAP hbit, LONG cb, LPVOID lpvBits)
|
|
|
|
{
|
2019-11-23 18:17:44 +00:00
|
|
|
memset(lpvBits, 0, cb);
|
|
|
|
return cb;
|
2019-11-20 21:23:27 +00:00
|
|
|
}
|