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; }
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()); };
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 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; }
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; }
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()); } }