Make resource interface based on "char *" as it is easier to detect a nullptr.

Can't change the return type to std::string.

Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
Andrea Odetti 2020-07-07 20:13:26 +01:00
parent a5eaf8a011
commit 40d3e822e9
7 changed files with 20 additions and 23 deletions

View file

@ -6,13 +6,13 @@
#include "Log.h" #include "Log.h"
HRSRC FindResource(void *, const std::string & filename, const char *) HRSRC FindResource(void *, const char * filename, const char *)
{ {
HRSRC result; HRSRC result;
if (!filename.empty()) if (filename)
{ {
const std::string path = "resource/" + filename; const std::string path = std::string("resource/") + filename;
int fd = open(path.c_str(), O_RDONLY); int fd = open(path.c_str(), O_RDONLY);
@ -31,15 +31,15 @@ HRSRC FindResource(void *, const std::string & filename, const char *)
if (result.data.empty()) if (result.data.empty())
{ {
LogFileOutput("FindResource: could not load resource %s\n", filename.c_str()); LogFileOutput("FindResource: could not load resource %s\n", filename);
} }
return result; return result;
} }
HBITMAP LoadBitmap(HINSTANCE hInstance, const std::string & filename) HBITMAP LoadBitmap(HINSTANCE hInstance, const char * filename)
{ {
LogFileOutput("LoadBitmap: not loading resource %s\n", filename.c_str()); LogFileOutput("LoadBitmap: not loading resource %s\n", filename);
return nullptr; return nullptr;
} }

View file

@ -5,13 +5,13 @@
#include "Log.h" #include "Log.h"
HRSRC FindResource(void *, const std::string & filename, const char *) HRSRC FindResource(void *, const char * filename, const char *)
{ {
HRSRC result; HRSRC result;
if (!filename.empty()) if (filename)
{ {
const std::string path = ":/resources/" + filename; const std::string path = std::string(":/resources/") + filename;
QFile res(QString::fromStdString(path)); QFile res(QString::fromStdString(path));
if (res.exists() && res.open(QIODevice::ReadOnly)) if (res.exists() && res.open(QIODevice::ReadOnly))
@ -23,7 +23,7 @@ HRSRC FindResource(void *, const std::string & filename, const char *)
if (result.data.empty()) if (result.data.empty())
{ {
LogFileOutput("FindResource: could not load resource %s\n", filename.c_str()); LogFileOutput("FindResource: could not load resource %s\n", filename);
} }
return result; return result;
@ -34,20 +34,20 @@ struct CBITMAP : public CHANDLE
QImage image; QImage image;
}; };
HBITMAP LoadBitmap(HINSTANCE hInstance, const std::string & filename) HBITMAP LoadBitmap(HINSTANCE hInstance, const char * filename)
{ {
Q_UNUSED(hInstance) Q_UNUSED(hInstance)
QImage image; QImage image;
if (!filename.empty()) if (filename)
{ {
const std::string path = ":/resources/" + filename + ".BMP"; const std::string path = std::string(":/resources/") + filename + ".BMP";
image = QImage(QString::fromStdString(path)); image = QImage(QString::fromStdString(path));
} }
if (image.isNull()) if (image.isNull())
{ {
LogFileOutput("LoadBitmap: could not load resource %s\n", filename.c_str()); LogFileOutput("LoadBitmap: could not load resource %s\n", filename);
return nullptr; return nullptr;
} }
else else

View file

@ -9,10 +9,10 @@
// Resources // Resources
HRSRC FindResource(void *, const std::string & filename, const char *); HRSRC FindResource(void *, const char * filename, const char *);
// Bitmap // Bitmap
HBITMAP LoadBitmap(HINSTANCE hInstance, const std::string & filename); HBITMAP LoadBitmap(HINSTANCE hInstance, const char * filename);
LONG GetBitmapBits(HBITMAP hbit, LONG cb, LPVOID lpvBits); LONG GetBitmapBits(HBITMAP hbit, LONG cb, LPVOID lpvBits);

View file

@ -38,7 +38,7 @@ typedef HANDLE HBITMAP;
typedef HANDLE HGDIOBJ; typedef HANDLE HGDIOBJ;
// Bitmap // Bitmap
HBITMAP LoadBitmap(HINSTANCE hInstance, const std::string & filename); HBITMAP LoadBitmap(HINSTANCE hInstance, const char * filename);
LONG GetBitmapBits(HBITMAP hbit, LONG cb, LPVOID lpvBits); LONG GetBitmapBits(HBITMAP hbit, LONG cb, LPVOID lpvBits);
BOOL DeleteObject(HGDIOBJ ho); BOOL DeleteObject(HGDIOBJ ho);

View file

@ -2,9 +2,6 @@
#include "../resource/resource.h" #include "../resource/resource.h"
#include "Log.h" #include "Log.h"
// forward declared
HRSRC FindResource(void *, const std::string & filename, const char *);
const char * MAKEINTRESOURCE(int x) const char * MAKEINTRESOURCE(int x)
{ {
switch (x) switch (x)

View file

@ -19,7 +19,7 @@ struct HRSRC : public CHANDLE
}; };
const char * MAKEINTRESOURCE(int x); const char * MAKEINTRESOURCE(int x);
HRSRC FindResource(void *, const std::string & filename, const char *); HRSRC FindResource(void *, const char * filename, const char *);
DWORD SizeofResource(void *, const HRSRC &); DWORD SizeofResource(void *, const HRSRC &);
HGLOBAL LoadResource(void *, HRSRC &); HGLOBAL LoadResource(void *, HRSRC &);
BYTE * LockResource(HGLOBAL); BYTE * LockResource(HGLOBAL);

View file

@ -10,7 +10,7 @@ void unregisterSoundBuffer(IDirectSoundBuffer * buffer)
// Resources // Resources
HRSRC FindResource(void *, const std::string & filename, const char *) HRSRC FindResource(void *, const char * filename, const char *)
{ {
return HRSRC(); return HRSRC();
} }
@ -51,7 +51,7 @@ int MessageBox(HWND, const char * text, const char * caption, UINT type) { retur
// Bitmap // Bitmap
HBITMAP LoadBitmap(HINSTANCE hInstance, const std::string & filename) HBITMAP LoadBitmap(HINSTANCE hInstance, const char * filename)
{ {
return nullptr; return nullptr;
} }