diff options
| author | Bent Bisballe Nyeng <deva@aasimon.org> | 2019-03-17 12:41:15 +0100 | 
|---|---|---|
| committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2019-03-17 12:41:15 +0100 | 
| commit | a0093df2f962b34289c545d85a2baad036b1bcc5 (patch) | |
| tree | 5bd714ca03abc8ef80a9a675b4505c77ba4c45e9 /plugingui | |
| parent | 5dee5069bc10ba3e190723aa68bb880183b1dc4c (diff) | |
A more general fix for resource loading when pointing to a directory.
Diffstat (limited to 'plugingui')
| -rw-r--r-- | plugingui/resource.cc | 32 | 
1 files changed, 31 insertions, 1 deletions
| diff --git a/plugingui/resource.cc b/plugingui/resource.cc index 432f25d..b70f84a 100644 --- a/plugingui/resource.cc +++ b/plugingui/resource.cc @@ -30,12 +30,37 @@  #include <cstdio>  #include <climits> +#include <platform.h> + +#if DG_PLATFORM != DG_PLATFORM_WINDOWS +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#endif +  // rcgen generated file containing rc_data declaration.  #include "resource_data.h"  namespace GUI  { +// TODO: Replace with std::filesystem::is_regular_file once we update the +// compiler to require C++17 +static bool pathIsFile(const std::string& path) +{ +#if DG_PLATFORM == DG_PLATFORM_WINDOWS +	return (GetFileAttributesA(path.data()) & FILE_ATTRIBUTE_DIRECTORY) == 0; +#else +	struct stat s; +	if(stat(path.data(), &s) != 0) +	{ +		return false; // error +	} + +	return (s.st_mode & S_IFREG) != 0; // s.st_mode & S_IFDIR => dir +#endif +} +  // Internal resources start with a colon.  static bool nameIsInternal(const std::string& name)  { @@ -74,8 +99,13 @@ Resource::Resource(const std::string& name)  	}  	else  	{ +		if(!pathIsFile(name)) +		{ +			return; +		} +  		// Read from file: -		std::FILE *fp = std::fopen(name.c_str(), "rb"); +		std::FILE *fp = std::fopen(name.data(), "rb");  		if(!fp)  		{  			return; | 
