Example #1
0
bool CProject::_loadPropItem(const string& filename)
{
	CTextFile file;
	if (!file.Load(filename))
		return false;

	ItemProp prop;
	int ID;
	int i;

	do
	{
		file.GetInt();
		ID = file.GetInt();
		prop.name = file.GetString();

		for (i = 0; i < 15; i++)
			file.NextToken();

		prop.part = file.GetInt();

		file.GetLine();
		m_itemProps[ID] = prop;
	} while (file.TokenType() != ETokenType::End);

	file.Close();
	return true;
}
Example #2
0
void TestFileSystemInit(void)
{
	CFileSystem		cSystem;
	char*			szFullName;
	CFileUtil		cFileUtil;
	CChars			szWorkingDirectory;
	CChars			szTemp;
	CTextFile		cTextFile;

	szWorkingDirectory.Init("Finder");
	cFileUtil.FullPath(&szWorkingDirectory);

	cSystem.Init("Finder");

	szFullName = cSystem.GetFileName("Lord/1.rar");
	szTemp.Init(szFullName);
	szTemp.RemoveFromStart(szWorkingDirectory.Length()+1);
	szTemp.Replace(FILE_SEPARATOR[0], '/');

	AssertString("Lord/1.rar", szTemp.Text());
	szTemp.Kill();

	szFullName = cSystem.GetFileName("File.txt");
	cTextFile.Init();
	cTextFile.Read(szFullName);

	AssertString("Hello World.", cTextFile.Text());

	cTextFile.Kill();

	cSystem.Kill();
}
Example #3
0
bool CResources::LoadString(CTextFile& file)
{
	while(!file.Eof())
	{
		CString line;
		file.ReadLine(line);
		line.Trim();
		if (line == _T("BEGIN"))
			break;
	}
	if (file.Eof())
		return false;

	int sepcount = 0;

	while(!file.Eof())
	{
		CString line;
		file.ReadLine(line);
		CAtlArray<CString> Words;
		CutString(line, Words);
		CString word = Words[0];

		if(word == _T("END"))
			return true;
		
		ResString item;
		item.m_ID = word;
		if (Words.GetCount() > 1)
		{
			item.m_String = Words[1];
		}
	}
	return false;
}
bool CFileKeyedValues::LoadFromConfFile(CHTString sConfFile, CHTString& rsError)
{
   CTextFile vFile;
   if (!vFile.Open(sConfFile, false, false, rsError))
   {
      rsError = "Unable to open configuration file: "+rsError;
      return false;
   }

   CHTStringArray asLines;
   if (!vFile.SlurpFile(asLines, rsError) || !vFile.Close(rsError))
   {
      rsError = "Unable to read configuration file: "+rsError;
      return false;
   }
   for (int iLine = 0; iLine < asLines.size(); iLine++)
   {
      CHTString sLine = asLines[iLine];
      if (sLine == "" || sLine.StartsWith("#")) continue;

      int iEquals;
      if (!sLine.Find("=", iEquals))
      {
         rsError = "The configuration file is in an invalid format.  The correct format is 'key=setting'.";
         return false;
      }

      m_asKeys.Add(sLine.Left(iEquals));
      m_asValues.Add(sLine.Mid(iEquals+1));
   }

   return true;
}
void AssertPakFile(char* szFileName, char* szContents, CFiles* pcFiles)
{
	CAbstractFile*	pcFile;
	CTextFile		cTextFile;

	pcFile = pcFiles->GetFile(szFileName);
	AssertNotNull(pcFile);

	cTextFile.Init();
	cTextFile.Read(pcFile);
	AssertString(szContents, cTextFile.Text());
	cTextFile.Kill();
}
void CInputDeviceDesc::Dump(void)
{
	CTextFile	cFile;
	CChars		szName;

	cFile.Init();
	ToString(&cFile.mcText);

	szName.Init("../");
	szName.Append(mszFriendlyName.Text());
	szName.Append(".txt");
	cFile.Write(szName.Text());
	szName.Kill();
	cFile.Kill();
}
bool CFileKeyedValues::SaveToConfFile(CHTString sFile, CHTString& rsError)
{
   CTextFile vFile;
   if (!vFile.Open(sFile, true, false, rsError))
      return false;

   for (int iSetting = 0; iSetting < m_asKeys.size(); iSetting++)
   {
      if (!vFile.AppendLine(m_asKeys[iSetting]+"="+m_asValues[iSetting], rsError))
         return false;
   }

   if (!vFile.Close(rsError))
      return false;

   return true;
}
Example #8
0
//////////////////////////////////////////////////////////////////////////
//																		//
//																		//
//////////////////////////////////////////////////////////////////////////
void CCFile::Load(void)
{
	CTextFile	cFile;

	if (!mbLoaded)
	{
		mbLoaded = TRUE;

		cFile.Init();
		cFile.Read(mszFullName.Text());

		mszContents.Kill();
		mszContents.Init(cFile.Text());

		cFile.Kill();
	}
}
Example #9
0
bool CResToolbar::Load(CTextFile& file)
{
	CString line;
	while(!file.Eof())
	{
		file.ReadLine(line);
		if (line == _T("BEGIN"))
			break;
	}
	if (file.Eof())
		return false;
	
	int sepcount = 0;

	while(!file.Eof())
	{
		CString line;
		file.ReadLine(line);
		CAtlArray<CString> Words;
		CutString(line, Words);
		CString word = Words[0];

		if(word == _T("BUTTON") || word == _T("SEPARATOR"))
		{
			ResToolbarItem item;

			item.m_Type = word;

			if(word == _T("BUTTON"))
			{
				if (Words.GetCount() > 1)
				{
					item.m_ID = Words[1];
				}
				m_vItems.Add(item);
			}
						
		}
		else if(word == _T("END"))
			return true;
	}
	return false;
}
BOOL SaveOBJ(CMesh *pcMesh, char* szFileName)
{
	CTextFile cTextFile;
	BOOL bTextureCoords;
	BOOL bVertexNormals;

	cTextFile.Init();

	AddOBJHeading(&cTextFile.mcText);
	AddOBJName(pcMesh, &cTextFile.mcText);
	AddOBJVertices(pcMesh, &cTextFile.mcText);
	bVertexNormals = AddOBJNormals(&pcMesh->mcNormals, &cTextFile.mcText);
	bTextureCoords = AddOBJTextureCoords(&pcMesh->mcUVs, &cTextFile.mcText);
	AddOBJFaces(pcMesh, &cTextFile.mcText, bTextureCoords, bVertexNormals);
	
	cTextFile.Write(szFileName);
	cTextFile.Kill();
	return FALSE;
}
Example #11
0
void CServerList::SaveStaticServers()
{
	CTextFile file;
	if (!file.Open(m_staticServersConfig, CTextFile::write)) {
		AddLogLineN(CFormat( _("Failed to open '%s'") ) % m_staticServersConfig );
		return;
	}

	for (CInternalList::const_iterator it = m_servers.begin(); it != m_servers.end(); ++it) {
		const CServer* server = *it;

		if (server->IsStaticMember()) {
			file.WriteLine(CFormat(wxT("%s:%u,%u,%s"))
				% server->GetAddress() % server->GetPort()
				% server->GetPreferences() % server->GetListName());
		}
	}

	file.Close();
}
void TestBufferedFileReadWrite(void)
{
	CFileUtil	cFileUtil;
	CFileBasic	cFile;
	CTextFile	cText;
	char		sz[20];

	cFileUtil.Delete("Test.txt");

	cFile.Init(BufferedFile(DiskFile("Test.txt"), 3));
	cFile.Open(EFM_ReadWrite_Create);
	cFile.Write("abcdefghijklmn", 1, 14);
	cFile.Write("op", 1, 2);
	cFile.Seek(3);
	memset(sz, 0, 20);
	cFile.Read(sz, 2, 1);
	AssertString("de", sz);
	cFile.Read(sz, 2, 1);
	AssertString("fg", sz);
	cFile.Write("12", 2, 1);
	cFile.Read(sz, 2, 1);
	AssertString("jk", sz);
	cFile.Write("34", 2, 1);
	cFile.Read(sz, 2, 1);
	AssertString("no", sz);
	cFile.Seek(2);
	cFile.Write("XY", 2, 1);
	cFile.Read(sz, 1, 3);
	AssertString("efg", sz);
	cFile.Close();
	cFile.Kill();

	cText.Init();
	cText.Read("Test.txt");
	AssertString("abXYefg12jk34nop", cText.mcText.Text());
	cText.Kill();

	cFileUtil.Delete("Test.txt");
}
Example #13
0
void CompareReadLines(size_t count, const wxChar* expected[], EReadTextFile criteria)
{
	CTextFile file;
	ASSERT_FALSE(file.IsOpened());
	ASSERT_TRUE(file.Eof());
	for (size_t j = 0; j < ArraySize(g_filesDefault); ++j) {
		CONTEXT(wxString(wxT("Checking file: ")) + g_filesDefault[j]);

		ASSERT_TRUE(file.Open(CPath(wxSTRINGIZE_T(SRCDIR)).JoinPaths(CPath(g_filesDefault[j])).GetRaw(), CTextFile::read));

		wxArrayString lines = file.ReadLines(criteria);

		ASSERT_EQUALS(ArrToStr(count, expected), ArrToStr(lines));
		ASSERT_EQUALS(count, lines.GetCount());
	}
	ASSERT_TRUE(file.IsOpened());
	ASSERT_TRUE(file.Eof());
};
Example #14
0
bool CProject::_loadTerrain(const string& filename)
{
	CTextFile file;
	if (!file.Load(filename))
		return false;

	string tok, tok2;
	int brace = 1, j, k;
	file.SetMark();
	int i = file.GetInt();
	tok = file.Token();
	int frameCount = file.GetInt();
	int imageCount = 0, idCount = 0;
	if (brace == 1 && frameCount)
	{
		if (m_waterListCount)
		{
			for (k = 0; k < m_waterListCount; k++)
			{
				DeleteArray(m_waterLists[k].textures);
				DeleteArray(m_waterLists[k].textureIDs);
			}
			DeleteArray(m_waterLists);
		}
		m_waterListCount = frameCount;
		m_waterLists = new WaterList[frameCount];
		for (j = 0; j < frameCount; j++)
		{
			m_waterLists[j].frame = 0.0f;
			m_waterLists[j].textureCount = 0;
			m_waterLists[j].textureIDs = 0;
			m_waterLists[j].textures = 0;
		}
		imageCount = 0;
	}

	CFolderElement* folders[32];
	CTerrainElement* terrain;
	folders[1] = m_terrainFolder;

	while (brace)
	{
		if (file.TokenType() == ETokenType::EndBlock || file.TokenType() == ETokenType::End)
		{
			brace--;
			if (brace > 0)
			{
				file.SetMark();
				i = file.GetInt();
				tok = file.Token();
				frameCount = file.GetInt();
				idCount = 0;
				if (frameCount)
				{
					if (brace == 1)
					{
						if (m_waterListCount)
						{
							for (k = 0; k < m_waterListCount; k++)
							{
								DeleteArray(m_waterLists[k].textures);
								DeleteArray(m_waterLists[k].textureIDs);
							}
							DeleteArray(m_waterLists);
						}
						m_waterListCount = frameCount;
						m_waterLists = new WaterList[frameCount];
						for (j = 0; j < frameCount; j++)
						{
							m_waterLists[j].frame = 0.0f;
							m_waterLists[j].textureCount = 0;
							m_waterLists[j].textureIDs = 0;
							m_waterLists[j].textures = 0;
						}
						imageCount = 0;
					}
					else if (brace == 2)
					{
						m_waterLists[imageCount].name = tok;
						DeleteArray(m_waterLists[imageCount].textures);
						DeleteArray(m_waterLists[imageCount].textureIDs);
						m_waterLists[imageCount].textureCount = frameCount;
						m_waterLists[imageCount].textures = new CTexture*[frameCount];
						m_waterLists[imageCount].textureIDs = new int[frameCount];
						memset(m_waterLists[imageCount].textures, 0, sizeof(CTexture*) * frameCount);
						memset(m_waterLists[imageCount].textureIDs, 0, sizeof(int) * frameCount);
						imageCount++;
					}
				}
			}
			continue;
		}

		file.NextToken();
		if (file.TokenType() == ETokenType::StartBlock)
		{
			brace++;
			file.SetMark();
			i = file.GetInt();
			tok2 = file.Token();
			frameCount = file.GetInt();

			if (i == 0 && brace == 2 && frameCount)
			{
				m_waterLists[imageCount].name = tok2;
				DeleteArray(m_waterLists[imageCount].textures);
				DeleteArray(m_waterLists[imageCount].textureIDs);
				m_waterLists[imageCount].textureCount = frameCount;
				m_waterLists[imageCount].textures = new CTexture*[frameCount];
				m_waterLists[imageCount].textureIDs = new int[frameCount];
				memset(m_waterLists[imageCount].textures, 0, sizeof(CTexture*) * frameCount);
				memset(m_waterLists[imageCount].textureIDs, 0, sizeof(int) * frameCount);
				imageCount++;
			}

			folders[brace] = new CFolderElement();
			folders[brace]->setSelectable(false);
			folders[brace]->setIcon(m_icons[2]);
			if (brace == 3)
				folders[brace]->setText(m_waterLists[imageCount - 1].name);
			else
				folders[brace]->setText(tok);
			folders[brace - 1]->appendRow(folders[brace]);
			continue;
		}
		else
		{
			file.GoMark();
			i = file.GetInt();
			frameCount = file.GetInt();
			if (brace == 3)
			{
				m_waterLists[imageCount - 1].textureIDs[idCount] = i;
				idCount++;
			}
		}

		m_terrains[i] = file.GetString();
		file.NextToken();
		file.NextToken();

		terrain = new CTerrainElement();
		terrain->setIcon(m_icons[4]);
		terrain->setText(m_terrains[i]);
		terrain->SetTerrain(i);
		folders[brace]->appendRow(terrain);

		file.SetMark();
		i = file.GetInt();
	}

	file.Close();
	return true;
}
Example #15
0
bool CProject::_loadPropMover(const string& filename)
{
	CTextFile file;
	if (!file.Load(filename))
		return false;

	MoverProp prop;
	int ID;
	int i;
	do
	{
		ID = file.GetInt();
		prop.name = file.GetString();
		prop.AI = (uint)file.GetInt();

		for (i = 0; i < 7; i++)
			file.GetInt();

		prop.belligerence = (uint)file.GetInt();

		for (i = 0; i < 35; i++)
			file.NextToken();

		prop.fly = file.GetBool();

		file.GetLine();
		m_moverProps[ID] = prop;
	} while (file.TokenType() != ETokenType::End);

	file.Close();
	return true;
}
Example #16
0
	virtual void run()
	{
		const wxChar* lines[] = {
			wxT(" # comment"),
			wxT("abc"),
			wxT("# foo bar"),
			wxT(" "),
			wxT("def ghi "),
			wxT(""),
			wxT("# xyz"),
			wxT(" xyz"),
			wxT(" "),
			wxT("")
		};

		{
			CONTEXT(wxT("Writing lines manually"));

			CTextFile file;
			ASSERT_TRUE(file.Open(wxT("testfile.txt"), CTextFile::write));

			for (size_t i = 0; i < ArraySize(lines); ++i) {
				CONTEXT(wxString::Format(wxT("Writing the %i'th line."), static_cast<int>(i)));

				ASSERT_TRUE(file.WriteLine(lines[i]));
			}
		}

		{
			CONTEXT(wxT("Reading manually written lines"));

			CTextFile file;
			ASSERT_TRUE(file.Open(wxT("testfile.txt"), CTextFile::read));
			ASSERT_FALSE(file.Eof());

			for (size_t i = 0; i < ArraySize(lines); ++i) {
				CONTEXT(wxString::Format(wxT("Reading the %i'th line."), static_cast<int>(i)));

				ASSERT_EQUALS(lines[i], file.GetNextLine());
			}
			ASSERT_TRUE(file.Eof());
		}

		{
			CONTEXT(wxT("Writing lines automatically"));

			CTextFile file;
			ASSERT_FALSE(file.IsOpened());
			ASSERT_TRUE(file.Open(wxT("testfile.txt"), CTextFile::write));
			ASSERT_TRUE(file.WriteLines(wxArrayString(ArraySize(lines), lines)));
			ASSERT_TRUE(file.IsOpened());
		}

		{
			CONTEXT(wxT("Reading automatically written lines"));

			CTextFile file;
			ASSERT_FALSE(file.IsOpened());
			ASSERT_TRUE(file.Open(wxT("testfile.txt"), CTextFile::read));
			ASSERT_TRUE(file.IsOpened());
			ASSERT_FALSE(file.Eof());

			for (size_t i = 0; i < ArraySize(lines); ++i) {
				CONTEXT(wxString::Format(wxT("Reading the %i'th line."), static_cast<int>(i)));

				ASSERT_EQUALS(lines[i], file.GetNextLine());
			}

			ASSERT_TRUE(file.Eof());
		}
	}
Example #17
0
bool CProject::_loadCharacter(const string& filename)
{
	CTextFile file;
	if (!file.Load(filename))
		return false;

	const string keys[] =
	{
		"randomItem",
		";",
		"SetEquip",
		")",
		"m_szName",
		"SetFigure",
		"SetName",
		"SetMusic",
		"m_nStructure",
		"m_szChar",
		"m_szDialog",
		"m_szDlgQuest",
		"SetImage",
		"AddMenuLang",
		"AddMenu",
		"AddVenderSlot",
		"AddVendorSlot",
		"AddVendorSlotLang",
		"AddVendorItemLang",
		"AddVenderItem",
		"AddVendorItem",
		"AddVenderItem2",
		"AddVendorItem2",
		"SetVenderType",
		"SetBuffSkill",
		"SetLang",
		"SetOutput",
		"AddTeleport",
		";"
	};

	int block;
	string key;
	do
	{
		Character character;

		character.ID = file.GetString();
		key = character.ID.toLower();
		file.NextToken();

		character.moverID = 0;
		character.head = 0;
		character.hairColor = 0;
		character.hair = 0;
		memset(&character.parts, 0, sizeof(character.parts));
		character.partCount = 0;

		block = 1;
		while (block && file.TokenType() != ETokenType::End)
		{
			file.NextToken();
			if (file.TokenType() == ETokenType::StartBlock)
				block++;
			else if (file.TokenType() == ETokenType::EndBlock)
				block--;
			else
			{
				const string tok = file.Token();
				if (tok == keys[0])
				{
					file.NextToken(); // {
					file.NextToken();
					while (file.TokenType() != ETokenType::EndBlock)
					{
						if (file.Token() == keys[1])
						{
							file.NextToken();
							continue;
						}
						file.NextToken();
					}
				}
				else if (tok == keys[2])
				{
					file.NextToken();
					while (file.Token() != keys[3])
					{
						const uint part = (uint)file.GetInt();
						if (character.partCount < MAX_HUMAN_PARTS)
						{
							character.parts[character.partCount] = part;
							character.partCount++;
						}
						file.NextToken();
					}
				}
				else if (tok == keys[4])
				{
					file.NextToken();
					character.name = file.GetString();
				}
				else if (tok == keys[5])
				{
					file.NextToken();
					character.moverID = file.GetInt();
					file.NextToken();
					character.hair = file.GetInt();
					file.NextToken();
					character.hairColor = file.GetUInt();
					file.NextToken();
					character.head = file.GetInt();
				}
				else if (tok == keys[6])
				{
					file.NextToken();
					character.name = file.GetString();
					file.NextToken();
					file.NextToken();
				}
				else if (tok == keys[7])
				{
					file.NextToken();
					file.NextToken();
				}
				else if (tok == keys[8])
				{
					file.NextToken();
					file.NextToken();
				}
				else if (tok == keys[9])
				{
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
				}
				else if (tok == keys[10])
				{
					file.NextToken();
					file.NextToken();
				}
				else if (tok == keys[11])
				{
					file.NextToken();
					file.NextToken();
				}
				else if (tok == keys[12])
				{
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
				}
				else if (tok == keys[13])
				{
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					if (file.TokenType() != ETokenType::Delimiter || file.Token() != keys[28])
					{
						file.NextToken();
						file.NextToken();
					}
				}
				else if (tok == keys[14])
				{
					file.NextToken();
					file.NextToken();
					file.NextToken();
				}
				else if (tok == keys[15])
				{
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
				}
				else if (tok == keys[16])
				{
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
				}
				else if (tok == keys[17])
				{
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					if (file.TokenType() != ETokenType::Delimiter || file.Token() != keys[28])
					{
						file.NextToken();
						file.NextToken();
					}
				}
				else if (tok == keys[18])
				{
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					if (file.TokenType() != ETokenType::Delimiter || file.Token() != keys[28])
					{
						file.NextToken();
						file.NextToken();
					}
				}
				else if (tok == keys[19] || tok == keys[20])
				{
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
				}
				else if (tok == keys[21] || tok == keys[22])
				{
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
				}
				else if (tok == keys[23])
				{
					file.NextToken();
					file.NextToken();
					file.NextToken();
				}
				else if (tok == keys[24])
				{
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
				}
				else if (tok == keys[25])
				{
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
				}
				else if (tok == keys[26])
				{
					file.NextToken();
					file.NextToken();
					file.NextToken();
				}
				else if (tok == keys[27])
				{
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
					file.NextToken();
				}
			}
		}

		if (!key.isEmpty())
			m_characters[key] = character;

	} while (file.TokenType() != ETokenType::End);

	file.Close();
	return true;
}
Example #18
0
bool CProject::_loadModel(const string& filename)
{
	CTextFile file;
	if (!file.Load(filename))
		return false;

	CFolderElement* folders[32];
	CModelElement* model;

	ModelProp prop;
	byte type;
	int max, motion;
	string motionStr;
	file.NextToken();
	while (file.TokenType() != ETokenType::End)
	{
		folders[1] = new CFolderElement();
		folders[1]->setIcon(m_icons[1]);
		folders[1]->setText(file.Token());
		m_objFolder->appendRow(folders[1]);

		type = (byte)file.GetInt();

		file.NextToken(); // {
		file.NextToken(); // nom d'un objet ou }

		int brace = 1;
		while (brace)
		{
			if (file.TokenType() == ETokenType::EndBlock)
			{
				brace--;
				if (brace > 0)
				{
					file.NextToken(); // nom d'un objet ou }
					continue;
				}
				if (brace == 0)
					continue;
			}

			prop.filename = file.Token();
			file.SetMark();

			file.NextToken();
			if (file.TokenType() == ETokenType::StartBlock)
			{
				brace++;
				folders[brace] = new CFolderElement();
				folders[brace]->setIcon(m_icons[1]);
				folders[brace]->setText(prop.filename);
				folders[brace - 1]->appendRow(folders[brace]);
				file.NextToken(); // nom d'un objet ou }
				prop.filename = file.Token();
				continue;
			}
			else
				file.GoMark();

			prop.ID = file.GetInt();
			prop.type = type;
			prop.modelType = (byte)file.GetInt();
			prop.part = file.GetString();
			prop.fly = file.GetBool();
			prop.distant = (byte)file.GetInt();
			prop.pick = file.GetBool();
			prop.scale = file.GetFloat();
			prop.trans = file.GetBool();
			prop.shadow = file.GetBool();
			prop.textureEx = (byte)file.GetInt();
			prop.renderFlag = file.GetBool();

			file.NextToken();
			if (file.TokenType() == ETokenType::StartBlock)
			{
				file.SetMark();
				file.NextToken();

				max = 0;
				while (file.TokenType() != ETokenType::EndBlock)
				{
					motion = file.GetInt();
					if (motion > max)
						max = motion;
					file.NextToken();  // nom d'une animation ou }
				}
				max++;

				prop.motionCount = max;
				file.GoMark();
				file.NextToken(); // nom d'une animation ou }
				prop.motions = new char[max * 32];
				memset(prop.motions, 0, max * 32);
				while (file.TokenType() != ETokenType::EndBlock)
				{
					motionStr = file.Token();
					motion = file.GetInt();
					file.NextToken(); // nom d'une animation ou }

					strcpy(prop.GetMotion(motion), motionStr.toLocal8Bit().constData());
				}
				file.NextToken(); // nom d'un objet ou }
			}
			else
			{
				prop.motionCount = 0;
				prop.motions = null;
			}

			m_models[type][prop.ID] = prop;

			model = new CModelElement();
			model->setIcon(m_icons[3]);

			if (type == OT_MOVER)
			{
				auto it = m_moverProps.constFind(prop.ID);
				if (it != m_moverProps.constEnd() && !(*it).name.isEmpty())
					model->setText((*it).name);
				else
					model->setText(prop.filename);
			}
			else if (type == OT_ITEM)
			{
				auto it = m_itemProps.constFind(prop.ID);
				if (it != m_itemProps.constEnd() && !(*it).name.isEmpty())
					model->setText((*it).name);
				else
					model->setText(prop.filename);
			}
			else
				model->setText(prop.filename);

			model->SetModel(&m_models[type][prop.ID]);
			folders[brace]->appendRow(model);
		}

		file.NextToken(); // type d'objet ou }
	}

	file.Close();
	return true;
}
Example #19
0
void CPlayerPlaylistBar::OnContextMenu(CWnd* /*pWnd*/, CPoint p)
{
    LVHITTESTINFO lvhti;
    lvhti.pt = p;
    m_list.ScreenToClient(&lvhti.pt);
    m_list.SubItemHitTest(&lvhti);

    POSITION pos = FindPos(lvhti.iItem);
    //bool fSelected = (pos == m_pl.GetPos());
    bool fOnItem = !!(lvhti.flags & LVHT_ONITEM);

    CMenu m;
    m.CreatePopupMenu();

    enum {
        M_OPEN = 1, M_ADD, M_REMOVE, M_CLEAR, M_CLIPBOARD, M_SAVEAS,
        M_SORTBYNAME, M_SORTBYPATH, M_RANDOMIZE, M_SORTBYID,
        M_SHUFFLE, M_HIDEFULLSCREEN
    };

    CAppSettings& s = AfxGetAppSettings();

    m.AppendMenu(MF_STRING | (!fOnItem ? (MF_DISABLED | MF_GRAYED) : MF_ENABLED), M_OPEN, ResStr(IDS_PLAYLIST_OPEN));
    if (((CMainFrame*)AfxGetMainWnd())->GetPlaybackMode() == PM_CAPTURE) {
        m.AppendMenu(MF_STRING | MF_ENABLED, M_ADD, ResStr(IDS_PLAYLIST_ADD));
    }
    m.AppendMenu(MF_STRING | (/*fSelected||*/!fOnItem ? (MF_DISABLED | MF_GRAYED) : MF_ENABLED), M_REMOVE, ResStr(IDS_PLAYLIST_REMOVE));
    m.AppendMenu(MF_SEPARATOR);
    m.AppendMenu(MF_STRING | (!m_pl.GetCount() ? (MF_DISABLED | MF_GRAYED) : MF_ENABLED), M_CLEAR, ResStr(IDS_PLAYLIST_CLEAR));
    m.AppendMenu(MF_SEPARATOR);
    m.AppendMenu(MF_STRING | (!fOnItem ? (MF_DISABLED | MF_GRAYED) : MF_ENABLED), M_CLIPBOARD, ResStr(IDS_PLAYLIST_COPYTOCLIPBOARD));
    m.AppendMenu(MF_STRING | (!m_pl.GetCount() ? (MF_DISABLED | MF_GRAYED) : MF_ENABLED), M_SAVEAS, ResStr(IDS_PLAYLIST_SAVEAS));
    m.AppendMenu(MF_SEPARATOR);
    m.AppendMenu(MF_STRING | (!m_pl.GetCount() ? (MF_DISABLED | MF_GRAYED) : MF_ENABLED), M_SORTBYNAME, ResStr(IDS_PLAYLIST_SORTBYLABEL));
    m.AppendMenu(MF_STRING | (!m_pl.GetCount() ? (MF_DISABLED | MF_GRAYED) : MF_ENABLED), M_SORTBYPATH, ResStr(IDS_PLAYLIST_SORTBYPATH));
    m.AppendMenu(MF_STRING | (!m_pl.GetCount() ? (MF_DISABLED | MF_GRAYED) : MF_ENABLED), M_RANDOMIZE, ResStr(IDS_PLAYLIST_RANDOMIZE));
    m.AppendMenu(MF_STRING | (!m_pl.GetCount() ? (MF_DISABLED | MF_GRAYED) : MF_ENABLED), M_SORTBYID, ResStr(IDS_PLAYLIST_RESTORE));
    m.AppendMenu(MF_SEPARATOR);
    m.AppendMenu(MF_STRING | MF_ENABLED | (s.bShufflePlaylistItems ? MF_CHECKED : MF_UNCHECKED), M_SHUFFLE, ResStr(IDS_PLAYLIST_SHUFFLE));
    m.AppendMenu(MF_SEPARATOR);
    m.AppendMenu(MF_STRING | MF_ENABLED | (s.bHidePlaylistFullScreen ? MF_CHECKED : MF_UNCHECKED), M_HIDEFULLSCREEN, ResStr(IDS_PLAYLIST_HIDEFS));

    CMainFrame* pMainFrm = (CMainFrame*)AfxGetMainWnd();

    int nID = (int)m.TrackPopupMenu(TPM_LEFTBUTTON | TPM_RETURNCMD, p.x, p.y, this);
    switch (nID) {
        case M_OPEN:
            m_pl.SetPos(pos);
            m_list.Invalidate();
            pMainFrm->OpenCurPlaylistItem();
            break;
        case M_ADD:
            pMainFrm->AddCurDevToPlaylist();
            m_pl.SetPos(m_pl.GetTailPosition());
            break;
        case M_REMOVE:
            if (m_pl.RemoveAt(pos)) {
                pMainFrm->CloseMedia();
            }
            m_list.DeleteItem(lvhti.iItem);
            SavePlaylist();
            break;
        case M_CLEAR:
            if (Empty()) {
                pMainFrm->CloseMedia();
            }
            break;
        case M_SORTBYID:
            m_pl.SortById();
            SetupList();
            SavePlaylist();
            break;
        case M_SORTBYNAME:
            m_pl.SortByName();
            SetupList();
            SavePlaylist();
            break;
        case M_SORTBYPATH:
            m_pl.SortByPath();
            SetupList();
            SavePlaylist();
            break;
        case M_RANDOMIZE:
            m_pl.Randomize();
            SetupList();
            SavePlaylist();
            break;
        case M_CLIPBOARD:
            if (OpenClipboard() && EmptyClipboard()) {
                CString str;

                CPlaylistItem& pli = m_pl.GetAt(pos);
                POSITION pos2 = pli.m_fns.GetHeadPosition();
                while (pos2) {
                    str += _T("\r\n") + pli.m_fns.GetNext(pos2);
                }
                str.Trim();

                if (HGLOBAL h = GlobalAlloc(GMEM_MOVEABLE, (str.GetLength() + 1) * sizeof(TCHAR))) {
                    if (TCHAR* cp = (TCHAR*)GlobalLock(h)) {
                        _tcscpy_s(cp, str.GetLength() + 1, str);
                        GlobalUnlock(h);
                        SetClipboardData(CF_UNICODETEXT, h);
                    }
                }
                CloseClipboard();
            }
            break;
        case M_SAVEAS: {
            CSaveTextFileDialog fd(
                CTextFile::ASCII, NULL, NULL,
                _T("Media Player Classic playlist (*.mpcpl)|*.mpcpl|Playlist (*.pls)|*.pls|Winamp playlist (*.m3u)|*.m3u|Windows Media playlist (*.asx)|*.asx||"),
                this);

            if (fd.DoModal() != IDOK) {
                break;
            }

            CTextFile::enc encoding = (CTextFile::enc)fd.GetEncoding();
            if (encoding == CTextFile::ASCII) {
                encoding = CTextFile::ANSI;
            }

            int idx = fd.m_pOFN->nFilterIndex;

            CPath path(fd.GetPathName());

            switch (idx) {
                case 1:
                    path.AddExtension(_T(".mpcpl"));
                    break;
                case 2:
                    path.AddExtension(_T(".pls"));
                    break;
                case 3:
                    path.AddExtension(_T(".m3u"));
                    break;
                case 4:
                    path.AddExtension(_T(".asx"));
                    break;
                default:
                    break;
            }

            bool fRemovePath = true;

            CPath p(path);
            p.RemoveFileSpec();
            CString base = (LPCTSTR)p;

            pos = m_pl.GetHeadPosition();
            while (pos && fRemovePath) {
                CPlaylistItem& pli = m_pl.GetNext(pos);

                if (pli.m_type != CPlaylistItem::file) {
                    fRemovePath = false;
                } else {
                    POSITION pos;

                    pos = pli.m_fns.GetHeadPosition();
                    while (pos && fRemovePath) {
                        CString fn = pli.m_fns.GetNext(pos);

                        CPath p(fn);
                        p.RemoveFileSpec();
                        if (base != (LPCTSTR)p) {
                            fRemovePath = false;
                        }
                    }

                    pos = pli.m_subs.GetHeadPosition();
                    while (pos && fRemovePath) {
                        CString fn = pli.m_subs.GetNext(pos);

                        CPath p(fn);
                        p.RemoveFileSpec();
                        if (base != (LPCTSTR)p) {
                            fRemovePath = false;
                        }
                    }
                }
            }

            if (idx == 1) {
                SaveMPCPlayList(path, encoding, fRemovePath);
                break;
            }

            CTextFile f;
            if (!f.Save(path, encoding)) {
                break;
            }

            if (idx == 2) {
                f.WriteString(_T("[playlist]\n"));
            } else if (idx == 4) {
                f.WriteString(_T("<ASX version = \"3.0\">\n"));
            }

            pos = m_pl.GetHeadPosition();
            CString str;
            int i;
            for (i = 0; pos; i++) {
                CPlaylistItem& pli = m_pl.GetNext(pos);

                if (pli.m_type != CPlaylistItem::file) {
                    continue;
                }

                CString fn = pli.m_fns.GetHead();

                /*
                            if (fRemovePath)
                            {
                                CPath p(path);
                                p.StripPath();
                                fn = (LPCTSTR)p;
                            }
                */

                switch (idx) {
                    case 2:
                        str.Format(_T("File%d=%s\n"), i + 1, fn);
                        break;
                    case 3:
                        str.Format(_T("%s\n"), fn);
                        break;
                    case 4:
                        str.Format(_T("<Entry><Ref href = \"%s\"/></Entry>\n"), fn);
                        break;
                    default:
                        break;
                }
                f.WriteString(str);
            }

            if (idx == 2) {
                str.Format(_T("NumberOfEntries=%d\n"), i);
                f.WriteString(str);
                f.WriteString(_T("Version=2\n"));
            } else if (idx == 4) {
                f.WriteString(_T("</ASX>\n"));
            }
        }
        break;
        case M_SHUFFLE:
            s.bShufflePlaylistItems = !s.bShufflePlaylistItems;
            break;
        case M_HIDEFULLSCREEN:
            s.bHidePlaylistFullScreen = !s.bHidePlaylistFullScreen;
            break;
        default:
            break;
    }
}
Example #20
0
bool CProject::Load(const string& filename)
{
	CTextFile file;
	if (!file.Load(filename))
		return false;

	QVector<string> models;
	QVector<string> terrains;
	QVector<string> propMovers;
	QVector<string> propItems;
	QVector<string> characters;

	const string keys[] =
	{
		"project",
		"define",
		"localdef",
		"string",
		"model",
		"terrain",
		"propmover",
		"propitem",
		"character"
	};

	string tok;
	file.NextToken();
	while (file.TokenType() != ETokenType::End)
	{
		tok = file.Token().toLower();

		if (tok == keys[0])
			m_name = file.GetString();
		else if (tok == keys[1] || tok == keys[2])
			CTextFile::LoadDefine(file.GetString(), false);
		else if (tok == keys[3])
			CTextFile::LoadText(file.GetString());
		else if (tok == keys[4])
			models.push_back(file.GetString());
		else if (tok == keys[5])
			terrains.push_back(file.GetString());
		else if (tok == keys[6])
			propMovers.push_back(file.GetString());
		else if (tok == keys[7])
			propItems.push_back(file.GetString());
		else if (tok == keys[8])
			characters.push_back(file.GetString());
		else
			file.NextToken();

		file.NextToken();
	}
	file.Close();

	QVector<string>::iterator it;
	for (it = propMovers.begin(); it != propMovers.end(); it++)
	{
		if (!_loadPropMover(*it))
			return false;
	}

	for (it = propItems.begin(); it != propItems.end(); it++)
	{
		if (!_loadPropItem(*it))
			return false;
	}

	for (it = characters.begin(); it != characters.end(); it++)
	{
		if (!_loadCharacter(*it))
			return false;
	}

	for (it = terrains.begin(); it != terrains.end(); it++)
	{
		if (!_loadTerrain(*it))
			return false;
	}

	for (it = models.begin(); it != models.end(); it++)
	{
		if (!_loadModel(*it))
			return false;
	}

	g_waterCount = m_waterListCount;
	return true;
}
BOOL CConvexHullGenerator::Generate(void)
{
	int							iMaxXIndex;
	int							iMinXIndex;
	CHalfSpaceHelper			cHalfSpace;
	int							iFarIndex;
	SFloat3*					psPosition;
	CArrayExtremeTrianglePtr	apcTriangles;
	CExtremeTriangle*			pcTriangle;
	CExtremeTriangle*			pcDeleted;
	SFreeListIterator			sIter;
	CArrayExtremeTrianglePtr	cDeleted;
	CArrayExtremeTrianglePtr	cFixedDeleted;
	int							j;
	SConvexHullHoleEdge			sEdges;
	int							k;
	int							aiIndex[3];
	int							iIndex;
	CExtremeTriangle*			pcSelected;
	CTextFile					cTextFile;
	int							iTriangle;
	float						fMinX;
	float						fMaxX;

	iMaxXIndex = FindMaxX(&fMinX);
	iMinXIndex = FindMinX(&fMaxX);
	iFarIndex = FindFurthestPoint(iMaxXIndex, iMinXIndex);

	if (iFarIndex == -1)
	{
		gcUserError.Set("Could not find a third point generating Convex Hull.");
		return FALSE;
	}

	apcTriangles.Init(2048);

	if (!FindFirstPairTriangles(&apcTriangles, iMaxXIndex, iMinXIndex, iFarIndex))
	{
		gcUserError.Set("Could not find the first triangle pair generating Convex Hull.");
		return FALSE;
	}

	cDeleted.Init(512);
	cFixedDeleted.Init(512);

	for (iTriangle = 0; iTriangle < apcTriangles.NumElements(); iTriangle++)
	{
		pcSelected = *apcTriangles.Get(iTriangle);

		if ((pcSelected == NULL) || (pcSelected->maiVisible.NumElements() == 0))
		{
			continue;
		}

		aiIndex[0] = GetIndex(mpsPoints, iStride, pcSelected->mpsPosition);
		aiIndex[1] = GetIndex(mpsPoints, iStride, pcSelected->mpsPosition1);
		aiIndex[2] = GetIndex(mpsPoints, iStride, pcSelected->mpsPosition2);

		iFarIndex = pcSelected->FindFurthestPoint(mpsPoints, iStride);
		if (iFarIndex == -1)
		{
			gcUserError.Set("Could not find furthest point!");
			return FALSE;
		}

		cDeleted.FakeSetUsedElements(0);  //It's sort of safe to do this.

		psPosition = GetPosition(mpsPoints, iStride, iFarIndex);
		pcTriangle = (CExtremeTriangle*)mcTriangles.StartIteration(&sIter);
		while (pcTriangle)
		{
			if (pcTriangle->maiVisible.NumElements() > 0)
			{
				if (pcTriangle->NotContains(psPosition))
				{
					cDeleted.Add(&pcTriangle);
				}
			}
			pcTriangle = (CExtremeTriangle*)mcTriangles.Iterate(&sIter);
		}
		
		RemoveDiscontiguousTriangles(pcSelected, &cDeleted, &cFixedDeleted);

		for (j = 0; j < cDeleted.NumElements(); j++)
		{
			pcDeleted = *cDeleted.Get(j);
			FindEdges(&sEdges, pcDeleted, &cDeleted);

			for (k = 0; k < sEdges.iNumEdges; k++)
			{
				pcTriangle = AddTriangle(GetPosition(mpsPoints, iStride, sEdges.aaiEdgeIndices[k][0]),
					GetPosition(mpsPoints, iStride, sEdges.aaiEdgeIndices[k][1]),
					GetPosition(mpsPoints, iStride, iFarIndex));

				apcTriangles.Add(&pcTriangle);
				AddPointsFromTriangles(pcTriangle, &cDeleted, iFarIndex);
			}
		}

		for (j = 0; j < cDeleted.NumElements(); j++)
		{
			pcDeleted = *cDeleted.Get(j);
			pcDeleted->Kill();
			mcTriangles.Remove(pcDeleted);

			iIndex = apcTriangles.FindWithIntKey((int)(size_t)pcDeleted, 0);
			*(apcTriangles.Get(iIndex)) = NULL;
		}
	}
	cDeleted.Kill();
	cFixedDeleted.Kill();

	apcTriangles.Kill();

	RemoveSlivers();

	if (mszHullName)
	{
		CChars szTemp;
		szTemp.Init("Writing Hull file [");
		szTemp.Append(mszHullName);
		szTemp.Append("]\n");
		szTemp.Kill();
		cTextFile.Init();
		DumpTriangleObj(&cTextFile.mcText, iTriangle);
		cTextFile.Write(mszHullName);
		cTextFile.Kill();
	}

	return TRUE;
}
void TestBufferedFileWrite(void)
{
	CFileUtil	cFileUtil;
	CFileBasic	cFile;
	CTextFile	cText;

	cFileUtil.Delete("Test.txt");

	cFile.Init(BufferedFile(DiskFile("Test.txt"), 3));
	cFile.Open(EFM_Write_Create);
	cFile.Write("ab", 1, 2);
	cFile.Write("cd", 1, 2);
	cFile.Close();
	cFile.Kill();

	cText.Init();
	cText.Read("Test.txt");
	AssertString("abcd", cText.mcText.Text());
	cText.Kill();

	cFile.Init(BufferedFile(DiskFile("Test.txt"), 5));
	cFile.Open(EFM_Write_Create);
	cFile.Write("abcdefghi", 1, 9);
	cFile.Write("jklmn", 1, 5);
	cFile.Close();
	cFile.Kill();

	cText.Init();
	cText.Read("Test.txt");
	AssertString("abcdefghijklmn", cText.mcText.Text());
	cText.Kill();

	cFile.Init(BufferedFile(DiskFile("Test.txt"), 5));
	cFile.Open(EFM_ReadWrite);
	cFile.Seek(4);
	cFile.Write("xyz", 3, 1);
	cFile.Close();
	cFile.Kill();

	cText.Init();
	cText.Read("Test.txt");
	AssertString("abcdxyzhijklmn", cText.mcText.Text());
	cText.Kill();

	cFile.Init(BufferedFile(DiskFile("Test.txt"), 8));
	cFile.Open(EFM_ReadWrite);
	cFile.Seek(0, EFSO_END);
	cFile.Write("opqrst", 6, 1);
	cFile.Seek(0);
	cFile.Write("123456", 6, 1);
	cFile.Write("78", 2, 1);
	cFile.Close();
	cFile.Kill();

	cText.Init();
	cText.Read("Test.txt");
	AssertString("12345678ijklmnopqrst", cText.mcText.Text());
	cText.Kill();

	cFile.Init(BufferedFile(DiskFile("Test.txt"), 3));
	cFile.Open(EFM_Write_Create);
	cFile.Write("ab", 1, 2);
	cFile.Write("cdef", 1, 4);
	cFile.Write("gh", 1, 2);
	cFile.Close();
	cFile.Kill();

	cText.Init();
	cText.Read("Test.txt");
	AssertString("abcdefgh", cText.mcText.Text());
	cText.Kill();

	cFileUtil.Delete("Test.txt");
}
Example #23
0
bool CResources::Load(LPCTSTR filename, bool bAppend /* = false */)
{
	CTextFile file;
	if (!bAppend)
	{
		m_Dialogs.RemoveAll();
		m_Menus.RemoveAll();
		m_Toolbars.RemoveAll();
		m_Accels.RemoveAll();
		m_Icons.RemoveAll();
		m_Bitmaps.RemoveAll();
		m_Cursors.RemoveAll();
	}
	if(!file.Open(filename))
	{
		return false;
	}

	while(!file.Eof())
	{
		CString line;
		file.ReadLine(line);
		if (line.IsEmpty())
			continue;
		line.TrimLeft();
		if (line.GetLength() >= 2 && line[0] == _T('/') && line[1] == _T('/'))
			continue;
		if (line[0] == _T('#'))
			continue;

		CAtlArray<CString> Words;
		CutString(line, Words);
		{
			CString word;
			if (Words.GetCount() > 1)
			{
				word = Words[1];
			}
			else
			{
				word.Empty();
			}
			if (word == _T("DESIGNINFO"))
			{
				//skip disign info
				while(!file.Eof())
				{
					file.ReadLine(line);
					line.Trim();
					if (line == _T("BEGIN"))
						break;
				}
				if (file.Eof())
					return false;
				int Level = 1;
				while(!file.Eof() && Level)
				{
					file.ReadLine(line);
					line.Trim();
					if (line == _T("BEGIN"))
						Level++;
					if (line == _T("END"))
						Level--;
				}
				if (Level)
					return false;
				else
					continue;
			}

			if(word == _T("MENU"))
			{
				CResMenu newmenu;
				newmenu.m_ID = Words[0];
				newmenu.Load(file);

				m_Menus.Add(newmenu);
			}
			else if( word == _T("TOOLBAR") )
			{
				CResToolbar newtoolbar;
				newtoolbar.m_ID = Words[0];
				newtoolbar.Load(file);

				m_Toolbars.Add(newtoolbar);
			}
			else if( (word == _T("DIALOG"))
				|| word == _T("DIALOGEX")
				)
			{
				CResDialog newdialog;
				newdialog.m_ID = Words[0];
				newdialog.m_Type = word;
				newdialog.Load(file);

				m_Dialogs.Add(newdialog);
			}
			else if( word == _T("BITMAP") || 
				word == _T("ICON") ||
				word == _T("CURSOR")
				)
			{
				ResBinary m_simple;
				m_simple.m_ID = Words[0];

				if(word == _T("BITMAP"))
					m_Bitmaps.Add(m_simple);
				else if(word == _T("ICON"))
					m_Icons.Add(m_simple);
				else
					m_Cursors.Add(m_simple);
			}
			else if(word == _T("ACCELERATORS"))
			{
				CResAccelerators accels;
				accels.m_ID = Words[0];
				accels.Load(file);
				m_Accels.Add(accels);
			}
			else 
			{
				if(Words.GetCount() > 0 && (Words[0] == _T("STRINGTABLE")))
				{
					LoadString(file);
				}
			}
		}
	}
	return true;
}
Example #24
0
bool CResMenu::Load(CTextFile &file)
{
	int level = 0;

	CString buffer;//next line
	CString line;
	CAtlArray<CString> Words;

	while(!file.Eof())
	{
		CString word;
		if (buffer.IsEmpty())
		{
			file.ReadLine(line);
		}
		else
		{
			line = buffer;
			buffer.Empty();
		}
		
		CutString(line, Words);
		if (Words[0] == _T("BEGIN"))
		{
			continue;
		}
		if (Words[0] == _T("END"))
		{
			return true;
		}
		if (Words[0] == _T("POPUP"))
		{
			CResMenu SubMenu;
			SubMenu.m_String = Words[1];
			if (!SubMenu.Load(file))
				return false;
			m_SubMenus.Add(SubMenu);
		}
		if (Words[0] == _T("MENUITEM"))
		{
			file.ReadLine(buffer);
			buffer.TrimLeft();
			buffer.TrimRight();
			while (_tcsncmp(buffer, _T("MENUITEM"), 8) &&
				_tcsncmp(buffer, _T("POPUP"), 5) &&
				_tcsncmp(buffer, _T("BEGIN"), 5) &&
				_tcsncmp(buffer, _T("END"), 3))
			{
				//
				line += _T(" ") + buffer;
				CutString(line, Words);
				file.ReadLine(buffer);
				buffer.TrimLeft();
				buffer.TrimRight();
			}
			ResMenuItem newitem;
			if (Words.GetCount() > 1)
			{
				newitem.m_String = Words[1];
				if (newitem.m_String == _T("SEPARATOR") && Words.GetCount() == 2)
				{
				}
				else
				{
					newitem.m_String.Replace(_T("\"\""), _T("\""));
					newitem.m_ID = Words[2];
					if (Words.GetCount() > 3)
					{
						newitem.m_Style = Words[3];
					}
				}
			}
			m_vItems.Add(newitem);
		}
	}
	return false;
}
void TestBufferedFileRead(void)
{
	CFileUtil	cFileUtil;
	CFileBasic	cFile;
	CTextFile	cText;
	char		sz[20];
	char		c;
	int			iCount;
	int			i;
	char		szExpected[20];

	cFileUtil.Delete("Test.txt");

	cText.Init();
	cText.mcText.Append("abcdefghijk");
	cText.Write("Test.txt");
	cText.Kill();

	cFile.Init(BufferedFile(DiskFile("Test.txt"), 3));

	cFile.Open(EFM_Read);

	for (c = 'a'; c <= 'k'; c++)
	{
		AssertFalse(cFile.IsEndOfFile());
		memset(sz, 0, 20);
		iCount = (int)cFile.Read(sz, 1, 1);
		AssertChar(c, sz[0]);
		AssertChar(0, sz[1]);
		AssertInt(1, iCount);
	}
	AssertTrue(cFile.IsEndOfFile());

	cFile.Seek(0);

	szExpected[2] = 0;
	for (i = 0; i < 5; i++)
	{
		AssertFalse(cFile.IsEndOfFile());
		memset(sz, 0, 20);
		iCount = (int)cFile.Read(sz, 1, 2);
		szExpected[0] = 'a' + (char)i * 2;
		szExpected[1] = 'b' + (char)i * 2;
		AssertString(szExpected, sz);
		AssertInt(2, iCount);
	}
	AssertFalse(cFile.IsEndOfFile());
	memset(sz, 0, 20);
	iCount = (int)cFile.Read(sz, 1, 2);
	AssertString("k", sz);
	AssertInt(1, iCount);
	AssertTrue(cFile.IsEndOfFile());

	cFile.Seek(0);

	szExpected[3] = 0;
	for (i = 0; i < 3; i++)
	{
		AssertFalse(cFile.IsEndOfFile());
		memset(sz, 0, 20);
		iCount = (int)cFile.Read(sz, 1, 3);
		szExpected[0] = 'a' + (char)i * 3;
		szExpected[1] = 'b' + (char)i * 3;
		szExpected[2] = 'c' + (char)i * 3;
		AssertString(szExpected, sz);
		AssertInt(3, iCount);
	}
	AssertFalse(cFile.IsEndOfFile());
	memset(sz, 0, 20);
	iCount = (int)cFile.Read(sz, 1, 3);
	AssertString("jk", sz);
	AssertInt(2, iCount);
	AssertTrue(cFile.IsEndOfFile());

	cFile.Kill();

	cFileUtil.Delete("Test.txt");
}
Example #26
0
bool CPlayerPlaylistBar::SaveMPCPlayList(CString fn, CTextFile::enc e, bool fRemovePath)
{
    CTextFile f;
    if (!f.Save(fn, e)) {
        return false;
    }

    f.WriteString(_T("MPCPLAYLIST\n"));

    POSITION pos = m_pl.GetHeadPosition(), pos2;
    for (int i = 1; pos; i++) {
        CPlaylistItem& pli = m_pl.GetNext(pos);

        CString idx;
        idx.Format(_T("%d"), i);

        CString str;
        str.Format(_T("%d,type,%d"), i, pli.m_type);
        f.WriteString(str + _T("\n"));

        if (!pli.m_label.IsEmpty()) {
            f.WriteString(idx + _T(",label,") + pli.m_label + _T("\n"));
        }

        if (pli.m_type == CPlaylistItem::file) {
            pos2 = pli.m_fns.GetHeadPosition();
            while (pos2) {
                CString fn2 = pli.m_fns.GetNext(pos2);
                if (fRemovePath) {
                    CPath p(fn2);
                    p.StripPath();
                    fn2 = (LPCTSTR)p;
                }
                f.WriteString(idx + _T(",filename,") + fn2 + _T("\n"));
            }

            pos2 = pli.m_subs.GetHeadPosition();
            while (pos2) {
                CString fn2 = pli.m_subs.GetNext(pos2);
                if (fRemovePath) {
                    CPath p(fn2);
                    p.StripPath();
                    fn2 = (LPCTSTR)p;
                }
                f.WriteString(idx + _T(",subtitle,") + fn2 + _T("\n"));
            }
        } else if (pli.m_type == CPlaylistItem::device && pli.m_fns.GetCount() == 2) {
            f.WriteString(idx + _T(",video,") + pli.m_fns.GetHead() + _T("\n"));
            f.WriteString(idx + _T(",audio,") + pli.m_fns.GetTail() + _T("\n"));
            str.Format(_T("%d,vinput,%d"), i, pli.m_vinput);
            f.WriteString(str + _T("\n"));
            str.Format(_T("%d,vchannel,%d"), i, pli.m_vchannel);
            f.WriteString(str + _T("\n"));
            str.Format(_T("%d,ainput,%d"), i, pli.m_ainput);
            f.WriteString(str + _T("\n"));
            str.Format(_T("%d,country,%d"), i, pli.m_country);
            f.WriteString(str + _T("\n"));
        }
    }

    return true;
}
void TestFilesSimple(void)
{
	CFiles			cFiles;
	CAbstractFile*	pcFile;
	CTextFile		cTextFile;

	//If this test fails you probably need to re-generate the source PAK files.
	//Use TestPackFilesPackerSimple to do this.

	cFiles.Init("Game", "PAK");
	AssertInt(6, cFiles.GetNumPackFiles());

	pcFile = cFiles.GetFile("Sounds/Santa/Seattle.txt");
	AssertNotNull(pcFile);

	cTextFile.Init();
	cTextFile.Read(pcFile);
	AssertString("All night long\r\n", cTextFile.Text());
	cTextFile.Kill();

	pcFile = cFiles.GetFile("Sounds/General.txt");
	AssertNotNull(pcFile);

	cTextFile.Init();
	cTextFile.Read(pcFile);
	AssertString("General", cTextFile.Text());
	cTextFile.Kill();

	pcFile = cFiles.GetFile("Sounds/Santa/Slay/Spelling.txt");
	AssertNotNull(pcFile);

	cTextFile.Init();
	cTextFile.Read(pcFile);
	AssertString("Spelling", cTextFile.Text());
	cTextFile.Kill();

	cFiles.Kill();
}