Example #1
0
			bool open(const std::experimental::filesystem::path& jpeg_file) override
			{
				auto fp = ::fopen(to_osmbstr(to_utf8(jpeg_file.native())).c_str(), "rb");
				if(nullptr == fp) return false;

				bool is_opened = false;

				struct ::jpeg_decompress_struct jdstru;
				error_mgr	jerr;

				jdstru.err = ::jpeg_std_error(&jerr.pub);
				jerr.pub.error_exit = _m_error_handler;

				if (!setjmp(jerr.setjmp_buf))
				{
					::jpeg_create_decompress(&jdstru);

					::jpeg_stdio_src(&jdstru, fp);

					_m_read_jpg(jdstru);

					jpeg_finish_decompress(&jdstru);
					is_opened = true;
				}

				::jpeg_destroy_decompress(&jdstru);
				::fclose(fp);
				return is_opened;
			}
Example #2
0
	static vector<char> read_file(const std::experimental::filesystem::path& p)
	{
		using namespace std;
		ifstream file(p.wstring(), ios::binary);
		auto size = std::experimental::filesystem::file_size(p);
		vector<char> buffer((size_t)size);
		if (0 < size)
			file.read(buffer.data(), size);
		file.close();
		return buffer;
	}
 size_t operator()(const fs::path& key) const
 {
     size_t ret = 5381;
     const fs::path::value_type* str = key.c_str();
     size_t c;
     while ( (c = *str++) )
     {
         ret = ((ret << 5) + ret) + c; /* hash * 33 + c */
     }
     return ret;
 }
Example #4
0
void OnTerminate() {
	try {
		std::rethrow_exception(std::current_exception());
		systemLogStream.Event(std::string("Terminate called, shutting down services."));
	}
	catch (Exception& ex) {
		systemLogStream.Event(std::string("Terminate called, shutting down services.") + ex.what() + "\n" + ex.StackTraceStr());
	}
	catch (std::exception& ex) {
		systemLogStream.Event(std::string("Terminate called, shutting down services.") + ex.what());
	}
	logger.Flush();
	logger.OpenStream(nullptr);
	logFile.close();
	int ans = MessageBoxA(NULL, "Open logs?", "Unhandled exception", MB_YESNO);
	if (ans == IDYES) {
		system(logFilePath.string().c_str());
	}

	std::abort();
}
Example #5
0
		std::shared_ptr<image::image_impl_interface> create_image(const fs::path & p)
		{
			std::shared_ptr<image::image_impl_interface> ptr;

			auto ext = p.extension().native();
			if (ext.empty())
				return ptr;

			std::transform(ext.begin(), ext.end(), ext.begin(), [](int ch)
			{
				if ('A' <= ch && ch <= 'Z')
					ch -= ('A' - 'a');
				return ch;
			});

#if defined(NANA_WINDOWS)
			const wchar_t* ext_ico = L".ico";
			const wchar_t* ext_png = L".png";
			const wchar_t* ext_jpg = L".jpg";
			const wchar_t* ext_jpeg = L".jpeg";
#else
			const char* ext_ico = ".ico";
			const char* ext_png = ".png";
			const char* ext_jpg = ".jpg";
			const char* ext_jpeg = ".jpeg";
#endif
			do
			{
				if (ext_ico == ext)
				{
					ptr = std::make_shared<detail::image_ico>();
					break;
				}

				if (ext_png == ext)
				{
#if defined(NANA_ENABLE_PNG)
					ptr = std::make_shared<detail::image_png>();
#else
					return ptr;
#endif
					break;
				}

				if (ext_jpg == ext || ext_jpeg == ext)
				{
#if defined(NANA_ENABLE_JPEG)
					ptr = std::make_shared<detail::image_jpeg>();
#else
					return ptr;
#endif
					break;
				}
			} while (false);

			//Check for BMP
			if (!ptr)
			{
#ifndef NANA_MINGW
				std::ifstream ifs(p.c_str(), std::ios::binary);
#else
				std::ifstream ifs(to_osmbstr(to_utf8(p.native())).c_str(), std::ios::binary);
#endif
				if (ifs)
				{
					unsigned short meta = 0;
					ifs.read(reinterpret_cast<char*>(&meta), 2);
					if (*reinterpret_cast<const short*>("BM") == meta)
						ptr = std::make_shared<detail::image_bmp>();
					else if (*reinterpret_cast<const short*>("MZ") == meta)
						ptr = std::make_shared<detail::image_ico_resource>();
				}
			}

			return ptr;
		}
Example #6
0
//===========================================================================
Path::Path(fs::path const & from)
    : m_data(from.generic_u8string())
{
    normalize(&m_data);
}
Example #7
0
 void FilePath::Pimpl::set(const std::experimental::filesystem::path& pPath)
 {
   path = pPath;
   name = pPath.string();
 }
		static std::string ToString(const FS::path& path)
		{
			auto pathString = path.string();
			std::replace(pathString.begin(), pathString.end(), '\\', '/');
			return pathString;
		}