Bool BonkEnc::CDDBBatch::ReadEntries()
{
	String	 inputFormat = String::SetInputFormat("UTF-8");
	String	 outputFormat = String::SetOutputFormat("UTF-8");

	// Read saved queries from XML

	XML::Document	*document = new XML::Document();

	if (document->LoadFile(String(config->configDir).Append("cddb\\queries.xml")) == Success())
	{
		XML::Node	*root = document->GetRootNode();

		if (root != NIL)
		{
			for (Int i = 0; i < root->GetNOfNodes(); i++)
			{
				XML::Node	*node = root->GetNthNode(i);

				if (node->GetName() == "query") queries.Add(node->GetContent());
			}
		}
	}

	delete document;

	// Read saved submits from XML and database cache

	document = new XML::Document();

	if (document->LoadFile(String(config->configDir).Append("cddb\\submits.xml")) == Success())
	{
		XML::Node	*root = document->GetRootNode();

		if (root != NIL)
		{
			for (Int i = 0; i < root->GetNOfNodes(); i++)
			{
				XML::Node	*node = root->GetNthNode(i);

				if (node->GetName() == "submit")
				{
					InStream	*in = new InStream(STREAM_FILE, String(config->configDir).Append("cddb\\").Append(node->GetAttributeByName("category")->GetContent()).Append("\\").Append(node->GetContent()), IS_READONLY);

					if (in->Size() > 0)
					{
						String	 result = in->InputString(in->Size());
						CDDBInfo cddbInfo;

						ParseCDDBRecord(result, cddbInfo);

						cddbInfo.category = node->GetAttributeByName("category")->GetContent();

						for (Int i = 0; i < submits.Length(); i++)
						{
							if (submits.GetNth(i) == cddbInfo)
							{
								submits.Remove(submits.GetNthIndex(i));

								break;
							}
						}

						submits.Add(cddbInfo);
					}

					delete in;
				}
			}
		}
	}

	delete document;

	String::SetInputFormat(inputFormat);
	String::SetOutputFormat(outputFormat);

	return True;
}