Beispiel #1
0
void GProfile::ProfileParse(const char *szBuffer, __int64 dwSize)
{
	GProfileSection *pSection = 0;

	// parse the file
	__int64 nIdx = 0;

	GString strLine;
	while (nIdx < dwSize)
	{
		GetLine(strLine, szBuffer, &nIdx, dwSize);

		strLine.TrimRightWS();
		strLine.TrimLeftWS();

		if ((strLine.IsEmpty()) || (strLine.GetAt(0) == ';'))
			continue;


		strLine.Replace("\\n", '\n');

		if (strLine.GetAt(0) == '[')
		{
			__int64 nIdx = strLine.Find(']');
			if (nIdx == -1)
				nIdx = strLine.Length();

			// new section
			pSection = new GProfileSection;
			pSection->m_strName = strLine.Mid(1, nIdx - 1);
			pSection->m_strName.TrimLeftWS();
			pSection->m_strName.TrimRightWS();

			m_lstSections.AddLast(pSection);
		}
		else if (pSection)
		{
			__int64 nIdx = strLine.Find('=');
			if (nIdx == -1)
				continue;
			GProfileEntry *pNVP = new GProfileEntry;
			pSection->m_lstNVP.AddLast(pNVP);
			pNVP->m_strName = strLine.Left(nIdx);
			pNVP->m_strName.TrimLeftWS();
			pNVP->m_strName.TrimRightWS();
			
			pNVP->m_strValue = strLine.Mid(nIdx + 1);
			pNVP->m_strValue.TrimLeftWS();
			pNVP->m_strValue.TrimRightWS();
		}
	}
	m_bCached = true;
}
void CFilePosterDlg::OnButton1() 
{
	char pzBuf[512];
	GetTempPath(512,pzBuf);
	GString strTempFile ( pzBuf );
	if ( strTempFile.GetAt(strTempFile.GetLength() - 1) != '\\')
		strTempFile << "\\";
	strTempFile << "FilePoster.Notes.txt";

	UnpackNotes(strTempFile);

	GString strCommand("notepad.exe ");
	strCommand << strTempFile;

	PROCESS_INFORMATION pInfo;
	STARTUPINFO         sInfo;

	sInfo.cb              = sizeof(STARTUPINFO);
	sInfo.lpReserved      = NULL;
	sInfo.lpReserved2     = NULL;
	sInfo.cbReserved2     = 0;
	sInfo.lpDesktop       = NULL;
	sInfo.lpTitle         = NULL;
	sInfo.dwFlags         = 0;
	sInfo.dwX             = 0;
	sInfo.dwY             = 0;
	sInfo.dwFillAttribute = 0;
	sInfo.wShowWindow     = SW_SHOW;
	CreateProcess(NULL, (char *)(const char *)strCommand, NULL, NULL, FALSE, 0,NULL, NULL, &sInfo, &pInfo);
	
}
Beispiel #3
0
gbool GJsonPair::Parse(const GString &jsonStr, gsize *cursor, GJsonParserMessage *msg)
{
	Destroy(); // 若已有数据,则先销毁
	GString parse_msg; // 如果发生了错误,返回可能的原因
	gsize _cursor = 0;
	if (cursor)
	{
		_cursor = *cursor;
	}

	gbool has_key = false;
	gsize key_start = GString::NULL_POS;

	while (true)
	{
		gchar c = jsonStr.GetAt(_cursor);
		if (c == '\0')
		{
			// 遇到字符串结束符,解析失败,直接退出
			if (cursor)
			{
				*cursor = _cursor;
			}
			if (msg)
			{
				msg->SetIsSuccess(false);
				msg->SetErrorCursor(_cursor);
				msg->SetErrorMessage("字符串提前结束");
			}
			Destroy();
			return false;
		}
		else if (!G_CHAR_IS_ASCII(c))
		{
			// 遇到非法的字符,解析失败,直接退出
			if (cursor)
			{
				*cursor = _cursor;
			}
			if (msg)
			{
				msg->SetIsSuccess(false);
				msg->SetErrorCursor(_cursor);
				msg->SetErrorMessage("非法的字符");
			}
			Destroy();
			return false;
		}
		else if (G_CHAR_IS_SPACE(c))
		{
			// 空白字符,不做任何操作
		}
		else if (c== '{' || c == '}' || 
			c == '[' || c == ']'||
			c == ',')
		{
			// 解析失败,直接退出
			if (cursor)
			{
				*cursor = _cursor;
			}
			if (msg)
			{
				msg->SetIsSuccess(false);
				msg->SetErrorCursor(_cursor);
				msg->SetErrorMessage("非法的构造字符");
			}
			Destroy();
			return false;
		}
		else if (c == ':')
		{
			if (!has_key)
			{
				// 还没有解析完成Key就遇到了':',解析失败,直接退出
				if (cursor)
				{
					*cursor = _cursor;
				}
				if (msg)
				{
					msg->SetIsSuccess(false);
					msg->SetErrorCursor(_cursor);
					msg->SetErrorMessage("非法的构造字符");
				}
				Destroy();
				return false;
			}
			else
			{
				// 已经解析了Key,说明应该解析JsonValue了
				_cursor++; // 先把光标后移,因为此时光标指向的是':'
				GJsonValue *value = new GJsonValue();
				if (!value->Parse(jsonStr, &_cursor, msg))
				{
					// JsonValue解析失败,释放内存,直接退出
					if (cursor)
					{
						*cursor = _cursor;
					}
					delete value;
					Destroy();
					return false;
				}

				// JsonValue解析成功,跳出循环
				m_pValue = value;
				break;
			}
		}
		else if (c == '"')
		{
			// 遇到了'"',解析Key
			if (has_key)
			{
				// Key已被解析过,解析失败,直接退出
				if (cursor)
				{
					*cursor = _cursor;
				}
				if (msg)
				{
					msg->SetIsSuccess(false);
					msg->SetErrorCursor(_cursor);
					msg->SetErrorMessage("非法的构造字符");
				}
				Destroy();
				return false;
			}
			else
			{
				if (key_start == GString::NULL_POS)
				{
					// Key开始
					key_start = _cursor;
				}
				else
				{
					// Key结束,Key可以为空
					if (_cursor <= key_start)
					{
						// 解析失败,直接退出
						if (cursor)
						{
							*cursor = _cursor;
						}
						if (msg)
						{
							msg->SetIsSuccess(false);
							msg->SetErrorCursor(_cursor);
							msg->SetErrorMessage("非法的构造字符");
						}
						Destroy();
						return false;
					}

					// 解析名称,注意应该去除掉'"'
					m_sKey = jsonStr.SubString(key_start + 1, _cursor - key_start - 1);
					has_key = true;
				}
			}
		}
		else
		{
			// 其他字符串,不做任何操作
		}

		// 光标后移
		_cursor++;
	} // while

	gbool success = (m_pValue != GNULL);
	if (!success)
	{
		// 操作失败,清理内存
		Destroy();
	}

	if (cursor)
	{
		// 将当前光标写入消息
		*cursor = _cursor;
	}
	if (msg)
	{
		// 将信息写入消息
		msg->SetIsSuccess(success);
		if (!success)
		{
			msg->SetErrorCursor(_cursor);
			if (!parse_msg.IsEmpty())
			{
				msg->SetErrorMessage(parse_msg);
			}
			else
			{
				msg->SetErrorMessage("未知的原因");
			}
		}
	}
	return success;
}