Пример #1
0
WCHAR *U8toW(const char *src, int max_len) {
	WCHAR	*wbuf = NULL;
	int		len = U8toW(src, NULL, 0, max_len) + 1;

	if (len > 0) {
		wbuf = new WCHAR [len];
		U8toW(src, wbuf, len, max_len);
	}
	return	wbuf;
}
Пример #2
0
BOOL GetOpenFileNameU8Core(LPOPENFILENAME ofn, BOOL (WINAPI *ofn_func)(OPENFILENAMEW*))
{
	OPENFILENAMEW	ofn_w;
	Wstr	filter_w(MAX_PATH), cfilter_w(ofn->nMaxCustFilter),
			file_w(ofn->nMaxFile), ftitle_w(ofn->nMaxFileTitle),
			idir_w(MAX_PATH), title_w(MAX_PATH), defext_w(MAX_PATH), template_w(MAX_PATH);

	memcpy(&ofn_w, ofn, sizeof(OPENFILENAME));

	WCHAR *wp=filter_w.Buf();
	for (const char *p=ofn->lpstrFilter; p && *p; p+=strlen(p)+1) {
		wp += U8toW(p, wp, (int)(MAX_PATH - (wp - filter_w.Buf()))) + 1;
	}
	*wp = 0;
	U8toW(ofn->lpstrCustomFilter, cfilter_w.Buf(), ofn->nMaxCustFilter);
	U8toW(ofn->lpstrFile, file_w.Buf(), ofn->nMaxFile);
	U8toW(ofn->lpstrFileTitle, ftitle_w.Buf(), ofn->nMaxFileTitle);
	U8toW(ofn->lpstrInitialDir, idir_w.Buf(), MAX_PATH);
	U8toW(ofn->lpstrTitle, title_w.Buf(), MAX_PATH);
	U8toW(ofn->lpstrDefExt, defext_w.Buf(), MAX_PATH);
	U8toW(ofn->lpTemplateName, template_w.Buf(), MAX_PATH);

	if (ofn->lpstrFilter)		ofn_w.lpstrFilter		= filter_w.s();
	if (ofn->lpstrCustomFilter)	ofn_w.lpstrCustomFilter	= cfilter_w.Buf();
	if (ofn->lpstrFile)			ofn_w.lpstrFile			= file_w.Buf();
	if (ofn->lpstrFileTitle)	ofn_w.lpstrFileTitle	= ftitle_w.Buf();
	if (ofn->lpstrInitialDir)	ofn_w.lpstrInitialDir	= idir_w.s();
	if (ofn->lpstrTitle)		ofn_w.lpstrTitle		= title_w.s();
	if (ofn->lpstrDefExt)		ofn_w.lpstrDefExt		= defext_w.s();
	if (ofn->lpTemplateName)	ofn_w.lpTemplateName	= template_w.s();

	BOOL	ret = ofn_func(&ofn_w);

	if (ofn->lpstrCustomFilter) {
		WtoU8(cfilter_w.s(), ofn->lpstrCustomFilter, ofn->nMaxCustFilter);
	}
	if (ofn->lpstrFileTitle) {
		WtoU8(ftitle_w.s(), ofn->lpstrFileTitle, ofn->nMaxFileTitle);
	}
	if (ofn->lpstrFile) {
		if (ofn_w.Flags & OFN_ALLOWMULTISELECT) {
			const WCHAR *wp=file_w.s();
			char *p;
			for (p=ofn->lpstrFile; wp && *wp; wp+=wcslen(wp)+1) {
				p += WtoU8(wp, p, (int)(ofn->nMaxFile - (p - ofn->lpstrFile))) + 1;
			}
			*p = 0;
		}
		else {
			WtoU8(file_w.s(), ofn->lpstrFile, ofn->nMaxFile);
		}
	}
//	if (ofn_w.lpstrFile[ofn_w.nFileOffset])
		ofn->nFileOffset = ::WideCharToMultiByte(CP_UTF8, 0, ofn_w.lpstrFile, ofn_w.nFileOffset,
							0, 0, 0, 0);

	return	ret;
}
Пример #3
0
/*
	ディレクトリダイアログ用汎用ルーチン
*/
void BrowseDirDlg(TWin *parentWin, UINT editCtl, char *title)
{ 
	IMalloc			*iMalloc = NULL;
	BROWSEINFOW		brInfo;
	LPITEMIDLIST	pidlBrowse;
	char			buf[MAX_PATH_U8];
	WCHAR			wbuf[MAX_PATH];
	Wstr			wtitle(title);

	parentWin->GetDlgItemTextU8(editCtl, buf, sizeof(buf));
	U8toW(buf, wbuf, MAX_PATH);
	if (!SUCCEEDED(SHGetMalloc(&iMalloc)))
		return;

	TBrowseDirDlg	dirDlg(buf);
	brInfo.hwndOwner = parentWin->hWnd;
	brInfo.pidlRoot = 0;
	brInfo.pszDisplayName = wbuf;
	brInfo.lpszTitle = wtitle.Buf();
	brInfo.ulFlags = BIF_RETURNONLYFSDIRS;
	brInfo.lpfn = BrowseDirDlg_Proc;
	brInfo.lParam = (LPARAM)&dirDlg;
	brInfo.iImage = 0;

	do {
		if ((pidlBrowse = ::SHBrowseForFolderW(&brInfo))) {
			if (::SHGetPathFromIDListW(pidlBrowse, wbuf))
				::SetDlgItemTextW(parentWin->hWnd, editCtl, wbuf);
			iMalloc->Free(pidlBrowse);
			break;
		}
	} while (dirDlg.IsDirty());

	iMalloc->Release();
}
Пример #4
0
/*
	ディレクトリダイアログ用汎用ルーチン
*/
BOOL BrowseDirDlg(TWin *parentWin, const char *title, const char *defaultDir, char *buf)
{ 
	IMalloc			*iMalloc = NULL;
	BROWSEINFOW		brInfo;
	LPITEMIDLIST	pidlBrowse;
	BOOL			ret = FALSE;
	Wstr			buf_w(MAX_PATH), defaultDir_w(MAX_PATH), title_w(title);

	if (!SUCCEEDED(SHGetMalloc(&iMalloc)))
		return FALSE;

	U8toW(defaultDir, defaultDir_w.Buf(), MAX_PATH);
	brInfo.hwndOwner = parentWin->hWnd;
	brInfo.pidlRoot = 0;
	brInfo.pszDisplayName = buf_w.Buf();
	brInfo.lpszTitle = title_w;
	brInfo.ulFlags = BIF_RETURNONLYFSDIRS;
	brInfo.lpfn = BrowseDirDlgProc;
	brInfo.lParam = (LPARAM)defaultDir_w.Buf();
	brInfo.iImage = 0;

	if ((pidlBrowse = SHBrowseForFolderV((BROWSEINFO *)&brInfo)))
	{
		ret = SHGetPathFromIDListV(pidlBrowse, buf_w.Buf());
		iMalloc->Free(pidlBrowse);
		if (ret)
			WtoU8(buf_w, buf, MAX_PATH_U8);
	}

	iMalloc->Release();
	return	ret;
}
Пример #5
0
/*
	リンクの解決
	あらかじめ、CoInitialize(NULL); を実行しておくこと
*/
BOOL ReadLinkU8(LPCSTR src, LPSTR dest, LPSTR arg)
{
	IShellLink		*shellLink;
	IPersistFile	*persistFile;
	WCHAR			wbuf[MAX_PATH];
	BOOL			ret = FALSE;

	if (SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW,
		(void **)&shellLink)))
	{
		if (SUCCEEDED(shellLink->QueryInterface(IID_IPersistFile, (void **)&persistFile)))
		{
			U8toW(src, wbuf, wsizeof(wbuf));
			if (SUCCEEDED(persistFile->Load(wbuf, STGM_READ)))
			{
				if (SUCCEEDED(shellLink->GetPath((char *)wbuf, MAX_PATH, NULL, SLGP_SHORTPATH)))
				{
					WtoU8(wbuf, dest, MAX_PATH_U8);
					shellLink->GetArguments((char *)wbuf, MAX_PATH);
					WtoU8(wbuf, arg, MAX_PATH_U8);
					ret = TRUE;
				}
			}
			persistFile->Release();
		}
		shellLink->Release();
	}
	return	ret;
}
Пример #6
0
/*=========================================================================
	UCS2(W) - UTF-8(U8) - ANSI(A) 相互変換
=========================================================================*/
WCHAR *U8toW(const char *src, BOOL noStatic) {
	static	WCHAR	*_wbuf = NULL;

	WCHAR	*wtmp = NULL;
	WCHAR	*&wbuf = noStatic ? wtmp : _wbuf;

	if (wbuf) {
		delete [] wbuf;
		wbuf = NULL;
	}

	int		len;
	if ((len = U8toW(src, NULL, 0)) > 0) {
		wbuf = new WCHAR [len + 1];
		U8toW(src, wbuf, len);
	}
	return	wbuf;
}
Пример #7
0
int TListViewEx::SetSubItem(int idx, int subIdx, char *str)
{
	LV_ITEMW		lvi = {0};
	lvi.mask		= LVIF_TEXT;
	lvi.iItem		= idx;
	lvi.iSubItem	= subIdx;
	lvi.pszText		= U8toW(str);
	return	SendMessage(LVM_SETITEMW, 0, (LPARAM)&lvi);
}
Пример #8
0
int TListViewEx::InsertItem(int idx, char *str, LPARAM lParam)
{
	LV_ITEMW		lvi = {0};
	lvi.mask		= LVIF_TEXT|LVIF_PARAM;
	lvi.iItem		= idx;
	lvi.pszText		= U8toW(str);
	lvi.lParam		= lParam;
	return	SendMessage(LVM_INSERTITEMW, 0, (LPARAM)&lvi);
}
Пример #9
0
WCHAR *U8toWs(const char *src, int max_len) {
	static	WCHAR	*wbuf[MAX_STATIC_ARRAY];
	static	u_long	idx;

	WCHAR	*&cur_buf = wbuf[idx++ % MAX_STATIC_ARRAY];
	if (cur_buf) {
		delete [] cur_buf;
	}
	return	(cur_buf = U8toW(src, max_len));
}
Пример #10
0
int TListViewEx::InsertColumn(int idx, char *title, int width, int fmt)
{
	LV_COLUMNW	lvC;
	memset(&lvC, 0, sizeof(lvC));
	lvC.fmt      = fmt;
	lvC.mask     = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
	lvC.pszText  = U8toW(title);
	lvC.cx       = width;
	lvC.iSubItem = idx;
	return	SendMessage(LVM_INSERTCOLUMNW, idx, (LPARAM)&lvC);
}
Пример #11
0
char *U8toA(const char *src, int max_len) {
	char	*buf = NULL;

	WCHAR	*wsrc = U8toW(src, max_len);
	if (wsrc) {
		buf = WtoA(wsrc, max_len);
	}
	delete [] wsrc;

	return	buf;
}
Пример #12
0
void DebugU8(char *fmt,...)
{
	char buf[8192];

	va_list	ap;
	va_start(ap, fmt);
	_vsnprintf(buf, sizeof(buf), fmt, ap);
	va_end(ap);

	WCHAR *wbuf = U8toW(buf, TRUE);
	::OutputDebugStringW(wbuf);
	delete [] wbuf;
}
Пример #13
0
BOOL Cfg::IniStrToW(char *str, WCHAR *wstr)
{
	int		len = (int)strlen(str) + 1;

	if (needIniConvert && *str == '|') { // old style
		hexstr2bin(str + 1, (BYTE *)wstr, len, &len);
	}
	else {
		if (needIniConvert && !IsUTF8(str)) {
			AtoW(str, wstr, len);
		} else {
			U8toW(str, wstr, len);
		}
	}

	return	TRUE;
}
Пример #14
0
char *U8toA(const char *src, BOOL noStatic) {
	static	char	*_buf = NULL;

	char	*tmp = NULL;
	char	*&buf = noStatic ? tmp : _buf;

	if (buf) {
		delete [] buf;
		buf = NULL;
	}

	WCHAR	*wsrc = U8toW(src, TRUE);
	if (wsrc) {
		buf = WtoA(wsrc, TRUE);
	}
	delete [] wsrc;
	return	buf;
}
Пример #15
0
static TCHAR* getPatchDescByLangcode(FILE* fp, int langcode)
{
	TCHAR* result = NULL;
	char* desc = NULL;
	char langtag[8];

	sprintf(langtag, "[%s]", ui_lang_info[langcode].name);

	fseek(fp, 0, SEEK_SET);

	while (!feof(fp))
	{
		char s[4096];

		if (fgets(s, sizeof s, fp) != NULL)
		{
			if (strncmp(langtag, s, strlen(langtag)) != 0)
				continue;

			while (fgets(s, sizeof s, fp) != NULL)
			{
				if (*s == '[')
				{
					if (desc)
					{
						result = U8toW(desc);
						free(desc);
						return result;
					}
					else
						return NULL;
				}

				char* p = s;
				getLine(p);

//				if (*s == '\0')
//					continue;

				if (desc)
				{
					size_t len = strlen(desc);
					len += strlen(s) + 2;

					char* p = (char*)malloc(len + 1);
					sprintf(p, "%s\r\n%s", desc, s);
					free(desc);
					desc = p;
				}
				else
				{
					desc = (char*)malloc(strlen(s) + 1);
					if (desc != NULL)
						strcpy(desc, s);
				}
			}
		}
	}

	if (desc)
	{
		result = U8toW(desc);
		free(desc);
		return result;
	}
	else
		return NULL;
}
Пример #16
0
// need thread safe (from WriteLogToFileProc)
int LogMng::MakeMsgHead(LogMsg *msg, WCHAR *wbuf, int max_len, BOOL with_self)
{
	int			len = 0;
	BOOL		is_memo = (msg->flags & DB_FLAG_MEMO) ? TRUE : FALSE;
	const WCHAR	*from_to = (msg->flags & DB_FLAG_FROM) ? L" From: " : L" To: ";
	const WCHAR	*next_to = (msg->flags & DB_FLAG_FROM) ? L"   Cc: " : NULL;

	len = U8toW(LOGMSG_HEAD_TOP, wbuf, max_len);

	if (is_memo) {
		len += wcsncpyz(wbuf + len, msg->host[0].nick.s(), max_len - len);
		len += wcsncpyz(wbuf + len, L"\r\n", max_len - len);
	}
	else {
		for (auto host=msg->host.begin(); host != msg->host.end(); host++) {
			WCHAR	host_str[MAX_LISTBUF];

			if (host == msg->host.begin() || !with_self || !cfg->selfHost.IsSameUidHost(*host)) {
				len += wcsncpyz(wbuf + len, from_to, max_len - len);
				MakeHostFormat(&(*host), host_str, wsizeof(host_str));
				len += wcsncpyz(wbuf + len, host_str, max_len - len);
				len += wcsncpyz(wbuf + len, L"\r\n", max_len - len);
			}

			if (next_to) {
				from_to = next_to;
			}
		}
		if (with_self) {
			const WCHAR	*self_from_to = (msg->flags & DB_FLAG_FROM) ? L" To:   " : L" From: ";
			WCHAR	host_str[MAX_LISTBUF];

			len += wcsncpyz(wbuf + len, self_from_to, max_len - len);
			MakeHostFormat(&cfg->selfHost, host_str, wsizeof(host_str));
			len += wcsncpyz(wbuf + len, host_str, max_len - len);
			len += wcsncpyz(wbuf + len, L"\r\n", max_len - len);
		}
	}
	len += wcsncpyz(wbuf + len, L"  at ", max_len - len);
	len += wcsncpyz(wbuf + len, CtimeW(msg->date), max_len - len);

#ifdef IPMSG_PRO
#define LOGMNG_MAKEMSGHEAD
#include "miscext.dat"
#undef  LOGMNG_MAKEMSGHEAD
#endif

	len += wcsncpyz(wbuf + len, L"\r\n", max_len - len);

	if (msg->clip.size() || msg->files.size()) {
		len += wcsncpyz(wbuf + len, msg->clip.size() ? msg->files.size() ?
			L"  (files/image)" : L"  (image)" : L"  (files)", max_len - len);

		for (auto &f: msg->files) {
			len += wcsncpyz(wbuf + len, L" ", max_len - len);
			len += wcsncpyz(wbuf + len, f.s(), max_len - len);
		}
		for (auto &c: msg->clip) {
			len += wcsncpyz(wbuf + len, L" ", max_len - len);
			len += wcsncpyz(wbuf + len, c.fname.s(), max_len - len);
		}
		len += wcsncpyz(wbuf + len, L"\r\n", max_len - len);
	}

	len += U8toW(LOGMSG_HEAD_END, wbuf + len, max_len - len);

	return	len;
}
Пример #17
0
void TInifile::Init(const char *_ini_file)
{
	InitCore(IsUTF8(_ini_file) ? U8toW(_ini_file) : AtoW(_ini_file));
}