Beispiel #1
0
void MenuFileToList(DList<UserMenuItem> *Menu, File& MenuFile, GetFileString& GetStr, uintptr_t MenuCP = CP_UNICODE)
{
	INT64 Pos = MenuFile.GetPointer();
	if (!Pos)
	{
		if (!GetFileFormat(MenuFile,MenuCP))
			MenuCP = CP_OEMCP;
	}

	LPWSTR MenuStr = nullptr;
	int MenuStrLength = 0;
	UserMenuItem *MenuItem = nullptr;

	while (GetStr.GetString(&MenuStr, MenuCP, MenuStrLength))
	{
		RemoveTrailingSpaces(MenuStr);

		if (!*MenuStr)
			continue;

		if (*MenuStr==L'{' && MenuItem && MenuItem->Menu)
		{
			MenuFileToList(MenuItem->Menu, MenuFile, GetStr, MenuCP);
			MenuItem = nullptr;
			continue;
		}

		if (*MenuStr==L'}')
			break;

		if (!IsSpace(*MenuStr))
		{
			wchar_t *ChPtr = nullptr;

			if (!(ChPtr=wcschr(MenuStr,L':')))
				continue;

			MenuItem = Menu->Push();

			*ChPtr = 0;
			MenuItem->strHotKey = MenuStr;
			MenuItem->strLabel = ChPtr+1;
			RemoveLeadingSpaces(MenuItem->strLabel);
			MenuItem->Submenu = (GetStr.PeekString(&MenuStr, MenuCP, MenuStrLength) && *MenuStr==L'{');

			if (MenuItem->Submenu)
				MenuItem->Menu = new DList<UserMenuItem>();

			// Support for old 1.x separator format
			if (MenuCP==CP_OEMCP && MenuItem->strHotKey==L"-" && MenuItem->strLabel.IsEmpty())
			{
				MenuItem->strHotKey += L"-";
			}
		}
		else if (MenuItem)
		{
			RemoveLeadingSpaces(MenuStr);
			string *str = MenuItem->Commands.Push();
			*str = MenuStr;
		}
	}
}