#pragma once
#include <map>
#include <string>
#include "rctools.h"
#include "resource.h"
#define MAKENAMEIDMAP(_Res_Name_) {#_Res_Name_, _Res_Name_}
std::map <std::string, unsigned> g_nameToId = {
	MAKENAMEIDMAP (IDS_WINTITLE),
	MAKENAMEIDMAP (IDS_PLEASEWAIT),
	MAKENAMEIDMAP (IDS_PUBLISHER),
	MAKENAMEIDMAP (IDS_VERSION),
	MAKENAMEIDMAP (IDS_MSAPP),
	MAKENAMEIDMAP (IDS_FUNCTIONNAME),
	MAKENAMEIDMAP (IDS_MOREINFO),
	MAKENAMEIDMAP (IDS_SELECT_TITLE),
	MAKENAMEIDMAP (IDS_SELECT_DLGTITLE),
	MAKENAMEIDMAP (IDS_SELECT_DLGAPPX),
	MAKENAMEIDMAP (IDS_SELECT_DLGALL),
	MAKENAMEIDMAP (IDS_SELECT_OPENFILE),
	MAKENAMEIDMAP (IDS_PREINSTALL_TITLE),
	MAKENAMEIDMAP (IDS_PREINSTALL_TUPDATE),
	MAKENAMEIDMAP (IDS_PREINSTALL_TREINSTALL),
	MAKENAMEIDMAP (IDS_PREINSTALL_TINSTALL),
	MAKENAMEIDMAP (IDS_PREINSTALL_CUPDATE),
	MAKENAMEIDMAP (IDS_PREINSTALL_CREINSTALL),
	MAKENAMEIDMAP (IDS_PREINSTALL_CANCEL),
	MAKENAMEIDMAP (IDS_PREINSTALL_MTTITLE),
	MAKENAMEIDMAP (IDS_PREINSTALL_MSELECT),
	MAKENAMEIDMAP (IDS_PREINSTALL_MPKGNAME),
	MAKENAMEIDMAP (IDS_INSTALLING_TITLE),
	MAKENAMEIDMAP (IDS_INSTALLING_SLOADING),
	MAKENAMEIDMAP (IDS_INSTALLING_SLOADCER),
	MAKENAMEIDMAP (IDS_INSTALLING_SINSTALLING),
	MAKENAMEIDMAP (IDS_INSTALLING_SINSTALLING_PROGRESS),
	MAKENAMEIDMAP (IDS_INSTALLING_MTITLE),
	MAKENAMEIDMAP (IDS_INSTALLING_MPKGNAME),
	MAKENAMEIDMAP (IDS_INSTALLING_MSINSTALLING_PROGRESS),
	MAKENAMEIDMAP (IDS_LAUNCHWHENREADY),
	MAKENAMEIDMAP (IDS_SUCCESS_TITLE),
	MAKENAMEIDMAP (IDS_SUCCESS_MTITLE),
	MAKENAMEIDMAP (IDS_FAILED_MTITLE),
	MAKENAMEIDMAP (IDS_FAILED_REASONNAME),
	MAKENAMEIDMAP (IDS_SUCCESS_LAUNCH),
	MAKENAMEIDMAP (IDS_COMMAND_CANCEL),
	MAKENAMEIDMAP (IDS_CMDPARAM_SILENT),
	MAKENAMEIDMAP (IDS_CMDPARAM_VERYSILENT),
	MAKENAMEIDMAP (IDS_CMDPARAM_MULTIPLE),
	MAKENAMEIDMAP (IDS_DEFAULTWIDTH),
	MAKENAMEIDMAP (IDS_DEFAULTHEIGHT),
	MAKENAMEIDMAP (IDS_MINWIDTH),
	MAKENAMEIDMAP (IDS_MINHIEHGT),
	MAKENAMEIDMAP (IDS_SPLASH_MLOAD),
	MAKENAMEIDMAP (IDS_MOREINFO_IDNAME),
	MAKENAMEIDMAP (IDS_MOREINFO_IDPUBLISHER),
	MAKENAMEIDMAP (IDS_MOREINFO_IDVERSION),
	MAKENAMEIDMAP (IDS_MOREINFO_IDFAMILY),
	MAKENAMEIDMAP (IDS_MOREINFO_IDFULL),
	MAKENAMEIDMAP (IDS_MOREINFO_IDARCH),
	MAKENAMEIDMAP (IDS_MOREINFO_PROPFREAMWORK),
	MAKENAMEIDMAP (IDS_MOREINFO_PROPRESPKG),
	MAKENAMEIDMAP (IDS_MOREINFO_PROPYES),
	MAKENAMEIDMAP (IDS_MOREINFO_PROPNO),
	MAKENAMEIDMAP (IDS_MOREINFO_INFOSYS),
	MAKENAMEIDMAP (IDS_MOREINFO_INFOSYS_VALUE),
	MAKENAMEIDMAP (IDS_MOREINFO_INFOLANG),
	MAKENAMEIDMAP (IDS_MOREINFO_ID),
	MAKENAMEIDMAP (IDS_MOREINFO_PROP),
	MAKENAMEIDMAP (IDS_MOREINFO_INFO),
	MAKENAMEIDMAP (IDS_CMDPARAM_HELP),
	MAKENAMEIDMAP (IDS_CMDTIP_PRETEXT),
	MAKENAMEIDMAP (IDS_DEFAULTWIDTH),
	MAKENAMEIDMAP (IDS_DEFAULTHEIGHT),
	MAKENAMEIDMAP (IDS_MINWIDTH),
	MAKENAMEIDMAP (IDS_MINHIEHGT),
	MAKENAMEIDMAP (IDS_INSTALLING_MLOADCER),
	MAKENAMEIDMAP (IDS_FAILED_MSUCCESS),
	MAKENAMEIDMAP (IDS_FAILED_STITLE),
	MAKENAMEIDMAP (IDS_APPLIST_WINTITLE),
	MAKENAMEIDMAP (IDS_APPLIST_TITLE),
	MAKENAMEIDMAP (IDS_APPLIST_CANCEL),
	MAKENAMEIDMAP (IDS_MSGBOX_OK),
	MAKENAMEIDMAP (IDS_MSGBOX_CANCEL),
	MAKENAMEIDMAP (IDS_MSGBOX_ABORT),
	MAKENAMEIDMAP (IDS_MSGBOX_RETRY),
	MAKENAMEIDMAP (IDS_MSGBOX_IGNORE),
	MAKENAMEIDMAP (IDS_MSGBOX_YES),
	MAKENAMEIDMAP (IDS_MSGBOX_NO),
	MAKENAMEIDMAP (IDS_MSGBOX_CLOSE),
	MAKENAMEIDMAP (IDS_MSGBOX_HELP),
	MAKENAMEIDMAP (IDS_MSGBOX_TRYAGAIN),
	MAKENAMEIDMAP (IDS_MSGBOX_CONTINUE),
	MAKENAMEIDMAP (IDS_PREINSTALL_SUPPOS),
	MAKENAMEIDMAP (IDS_PREINSTALL_NOSUPPOS)
};

#ifdef MAKENAMEIDMAP
#undef MAKENAMEIDMAP
#endif

#ifdef __cplusplus_cli
using namespace System;
using namespace System::Runtime::InteropServices;
[ComVisible (true)]
public ref class _I_Resources
{
	public:
	String ^GetById (unsigned int uiResId) { return GetRCStringCli (uiResId); }
	unsigned ToId (String ^lpResName)
	{
		auto it = g_nameToId.find (MPStringToStdA (lpResName));
		return (it != g_nameToId.end ()) ? it->second : 0;
	}
	String ^ToName (unsigned int ulResId)
	{
		for (auto &it : g_nameToId) { if (it.second == ulResId) return CStringToMPString (it.first); }
		return "";
	}
	String ^GetByName (String ^lpResId) { return GetById (ToId (lpResId)); }
	String ^operator [] (unsigned int uiResId) { return GetRCStringCli (uiResId); }
	String ^GetFromOthers (String ^filepath, unsigned int resid)
	{
		HMODULE module = nullptr;
		bool needrel = false;
		if (filepath && !IsNormalizeStringEmpty (MPStringToStdW (filepath)))
		{
			HMODULE hRes = LoadLibraryExW (
				MPStringToStdW (filepath).c_str (),
				NULL,
				LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE
			);
			needrel = hRes;
			module = hRes;
		}
		else module = GetModuleHandleW (NULL);
		auto ret = GetRCStringCli (resid, module);
		if (needrel && module) FreeLibrary (module);
		return ret;
	}
};
#endif