// -*- C++ -*- generated by wxGlade 0.6.3 on Thu Feb 19 10:54:56 2009

#include <memory>

#include "wx/artprov.h"

#include "Consts.h"
#include "Toolkit.h"

#include "Adapter.h"

#include "MainFrame.h"

// begin wxGlade: ::extracode
// end wxGlade



CMainFrame::CMainFrame(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
    wxFrame(parent, id, title, pos, size, wxDEFAULT_FRAME_STYLE)
, _uiLastSelectedItemID(0)
{
	InitFrame();
	InitImageList();

	InitMenuBar();
	InitToolBar();
	InitStatusBar();

	InitTreeCtrl(window_1_pane_1);
	InitNotebook(window_1_pane_2);

	set_properties();
    do_layout();
    // end wxGlade
	InitObjects();
}

CMainFrame::~CMainFrame()
{
	DestroyImageList();
}

BEGIN_EVENT_TABLE(CMainFrame, wxFrame)
    // begin wxGlade: CMainFrame::event_table
    EVT_MENU(IDM_FILE_EXIT, CMainFrame::OnMenuFileExit)
	EVT_MENU(IDM_HELP_ABOUT, CMainFrame::OnMenuHelpAbout)
    EVT_TOOL(IDT_BUTTON_OPEN, CMainFrame::OnToolBarOpen)
	EVT_TOOL(IDT_BUTTON_RELOAD, CMainFrame::OnToolBarReload)

	EVT_TREE_SEL_CHANGED(IDC_TREE, CMainFrame::OnTreeSelectChanged)
	EVT_TREE_ITEM_RIGHT_CLICK(IDC_TREE, CMainFrame::OnTreeRightClick)
	EVT_TREE_ITEM_MENU(IDC_TREE, CMainFrame::OnTreeItemMenu)
	EVT_TREE_ITEM_ACTIVATED(IDC_TREE, CMainFrame::OnTreeItemActivated)

    EVT_BUTTON(IDB_DATA_EXPORT, CMainFrame::OnButtonInfoExport)

    EVT_TOOLBOOK_PAGE_CHANGED(IDC_NOTEBOOK, CMainFrame::OnNotebookPageChanged)
	EVT_TOOLBOOK_PAGE_CHANGING(IDC_NOTEBOOK, CMainFrame::OnNotebookPageChanging)
    // end wxGlade
	EVT_MENU(IDM_HELP_TEST, CMainFrame::OnMenuHelpTest)
	EVT_MENU(IDM_VIEW_TREESTYLE_CATEGORY, CMainFrame::OnMenuViewTreeStyle)
	EVT_MENU(IDM_VIEW_TREESTYLE_DIRECTORY, CMainFrame::OnMenuViewTreeStyle)

	EVT_MENU(IDM_PARSER_DBC, CMainFrame::OnMenuParserDBC)
	EVT_MENU(IDM_PARSER_BLP, CMainFrame::OnMenuParserBLP)

	EVT_MENU(IDM_SETTING_LOADDBCCONFIG, CMainFrame::OnMenuSettingLoadDBCConfig)
END_EVENT_TABLE();

void CMainFrame::set_properties()
{
    // begin wxGlade: CMainFrame::set_properties
    // end wxGlade
}


void CMainFrame::do_layout()
{
    // begin wxGlade: CMainFrame::do_layout
	wxBoxSizer* sizer_1 = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_3 = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_2 = new wxBoxSizer(wxVERTICAL);
    sizer_1->Add(static_line_1, 0, wxEXPAND, 0);
    sizer_2->Add(m_ctrlTree, 1, wxEXPAND, 0);
    window_1_pane_1->SetSizer(sizer_2);

    sizer_3->Add(m_ctrlNotebook, 1, wxEXPAND, 0);
    window_1_pane_2->SetSizer(sizer_3);
    window_1->SplitVertically(window_1_pane_1, window_1_pane_2, 195);
	window_1->SetMinimumPaneSize(100);

    sizer_1->Add(window_1, 1, wxEXPAND, 0);
    SetSizer(sizer_1);
//    sizer_1->Fit(this);
    Layout();
    // end wxGlade
	Center();
}
////
void CMainFrame::InitFrame()
{
    window_1 = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER);
    window_1_pane_2 = new wxPanel(window_1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER);
    static_line_1 = new wxStaticLine(this, wxID_ANY);
    window_1_pane_1 = new wxPanel(window_1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER);

    SetTitle(wxT("wxDeMPQ"));
    SetSize(wxSize(653, 477));
}

void CMainFrame::InitImageList()
{
	wxSize size(16, 16);
	m_imageList = new wxImageList(size.GetWidth(), size.GetHeight());
	m_imageList->Add(wxArtProvider::GetIcon(wxART_NEW, wxART_OTHER, size));
}

void CMainFrame::DestroyImageList()
{
	delete m_imageList;
}

void CMainFrame::InitMenuBar()
{
    MainMenBar = new wxMenuBar();
    wxMenu* wxglade_tmp_menu_1 = new wxMenu();
    wxglade_tmp_menu_1->Append(IDM_FILE_EXIT, wxT("E&xit"), wxT("Exit DeMPQ program..."), wxITEM_NORMAL);
    MainMenBar->Append(wxglade_tmp_menu_1, wxT("&File"));

	wxMenu* temp_view = new wxMenu();
	temp_view->Append(IDM_VIEW_TREESTYLE_CATEGORY, wxT("Tree Style:&Category"), wxT("Use category style to display the tree.."), wxITEM_RADIO);
	temp_view->Append(IDM_VIEW_TREESTYLE_DIRECTORY, wxT("Tree Style:&Directory"), wxT("Use directory style to display the tree.."), wxITEM_RADIO);
    MainMenBar->Append(temp_view, wxT("&View"));

    wxMenu* wxglade_tmp_menu_2 = new wxMenu();
	wxglade_tmp_menu_2->Append(IDM_PARSER_DBC, wxT("Parse &DBC.."), wxT("Parse DBC file..."), wxITEM_NORMAL);
//	wxglade_tmp_menu_2->AppendSeparator();
	wxglade_tmp_menu_2->Append(IDM_PARSER_BLP, wxT("Parse &BLP.."), wxT("Parse BLP file..."), wxITEM_NORMAL);
    MainMenBar->Append(wxglade_tmp_menu_2, wxT("&Parser"));

    wxMenu* menu_setting = new wxMenu();
	menu_setting->Append(IDM_SETTING_LOADDBCCONFIG, wxT("&Load DBC Configuration.."), wxT("Load DBC configuration file..."), wxITEM_NORMAL);
    MainMenBar->Append(menu_setting, wxT("&Setting"));

    wxMenu* wxglade_tmp_menu_11 = new wxMenu();
	wxglade_tmp_menu_11->Append(IDM_HELP_ABOUT, wxT("&About"), wxT("About this program.."), wxITEM_NORMAL);
	wxglade_tmp_menu_11->AppendSeparator();
	wxglade_tmp_menu_11->Append(IDM_HELP_TEST, wxT("&Test"), wxT("Just for test."), wxITEM_CHECK);
    MainMenBar->Append(wxglade_tmp_menu_11, wxT("&Help"));
    SetMenuBar(MainMenBar);
}

void CMainFrame::InitToolBar()
{
	long style = wxTB_HORIZONTAL | wxTB_DOCKABLE | wxTB_TEXT | wxTB_FLAT;
	wxToolBarBase *toolBar = CreateToolBar(style, wxID_ANY);

	wxBitmap bmpToolBar[2];
	bmpToolBar[0] = wxBITMAP(RC_BMP_TOOLBAR_OPEN);
	bmpToolBar[1] = wxBITMAP(RC_BMP_TOOLBAR_RELOAD);

	toolBar->SetToolBitmapSize(wxSize(bmpToolBar[0].GetWidth(), bmpToolBar[0].GetHeight()));
	toolBar->AddTool(IDT_BUTTON_OPEN, _T("Open"), bmpToolBar[0], wxNullBitmap, wxITEM_NORMAL, _T("Open file.."), _T("Open a MPQ file.."));

	toolBar->AddSeparator();
	toolBar->AddTool(IDT_BUTTON_RELOAD, _T("Reload"), bmpToolBar[1], wxNullBitmap, wxITEM_NORMAL, _T("Reload the file.."), _T("Reload the MPQ file.."));

	toolBar->AddSeparator();

	wxStaticText* label = new wxStaticText(toolBar, wxID_ANY, wxT("Filter : "), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
	toolBar->AddControl(label);

    m_ctrlToolComboBox = new wxComboBox(toolBar, IDC_COMBO, wxEmptyString, wxDefaultPosition);
	m_ctrlToolComboBox->Append(_T("*.*"));
    m_ctrlToolComboBox->Append(_T("*.jpg"));
    m_ctrlToolComboBox->Append(_T("*.gif"));
    m_ctrlToolComboBox->Append(_T("*.m2"));
    m_ctrlToolComboBox->Append(_T("*.blp"));
    m_ctrlToolComboBox->Append(_T("*.dbc"));
    m_ctrlToolComboBox->Append(_T("*.wav"));
    m_ctrlToolComboBox->Append(_T("*.mp3"));
    toolBar->AddControl(m_ctrlToolComboBox);

	toolBar->Realize();
}

void CMainFrame::InitStatusBar()
{
    MainStatusBar = CreateStatusBar(2, wxST_SIZEGRIP);

	int MainStatusBar_widths[] = { -1, 100 };
    MainStatusBar->SetStatusWidths(2, MainStatusBar_widths);
    const wxString MainStatusBar_fields[] = {
        wxT("Hint"),
        wxT("FileNum")
    };
    for(int i = 0; i < MainStatusBar->GetFieldsCount(); ++i) {
        MainStatusBar->SetStatusText(MainStatusBar_fields[i], i);
    }
}

void CMainFrame::InitTreeCtrl(wxPanel* parent)
{
	m_ctrlTree = new wxTreeCtrl(window_1_pane_1, IDC_TREE, wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS|wxTR_LINES_AT_ROOT|wxTR_FULL_ROW_HIGHLIGHT|wxTR_DEFAULT_STYLE|wxRAISED_BORDER);
//	_objMPQTree.AttachTreeCtrl(m_ctrlTree);
}

void CMainFrame::InitNotebook(wxPanel* parent)
{
    m_ctrlNotebook = new wxToolbook(parent, IDC_NOTEBOOK, wxDefaultPosition, wxDefaultSize, wxNB_TOP);
	
	m_ctrlNotebook->SetImageList(m_imageList);
}

int CMainFrame::InitObjects()
{
	_objMPQTree.AttachTreeCtrl(m_ctrlTree);

	_objNotebookPanelManager.InitPanels(m_ctrlNotebook);
	_objNotebookPanelManager.ShowPanel(PT_INFO, true);
	_objNotebookPanelManager.ShowPanel(PT_DATA, true, false);
	_objMPQData.AttachDataPanel((CNotebookDataPanel*)_objNotebookPanelManager.GetPanel(PT_DATA));

	_objMPQDBCFieldManager.Load(CSTR_DBC_CONFIGUREFILE);

	return 0;
}

///


void CMainFrame::OnMenuFileExit(wxCommandEvent &event)
{
	Close();
    event.Skip();
}

void CMainFrame::OnMenuHelpAbout(wxCommandEvent& event)
{
	wxMessageBox(wxT("--- CREATE BY JIE. ---"), wxT("DeMPQ(Develop version)"));
	event.Skip();
}

void CMainFrame::OnToolBarOpen(wxCommandEvent &event)
{
	wxFileDialog dlg(this,
						wxT("Open MPQ File.."),
						wxEmptyString,
						_T("*.mpq"),
						_T("Configration Files (*.mpq)|*.mpq|All Files (*.*)|*.*"),
						wxFD_OPEN|wxFD_FILE_MUST_EXIST);
	if (dlg.ShowModal() == wxID_OK)
	{
		wxString str = m_ctrlToolComboBox->GetValue();
		if(str.empty())
			str = wxT("*.*");

		ScanMPQArchData(dlg.GetPath(), str);
	}

    event.Skip();

}

void CMainFrame::OnToolBarReload(wxCommandEvent &event)
{
	if(_objDeMPQ.ArchFileName().empty())
	{
		OnToolBarOpen(event);
	}
	else
	{
		wxString str = m_ctrlToolComboBox->GetValue();
		if(str.empty())
			str = wxT("*.*");

		ScanMPQArchData(Toolkit::String2wxString(_objDeMPQ.ArchFileName()), str);

		event.Skip();
	}
}

void CMainFrame::OnTreeSelectChanged(wxTreeEvent &event)
{
	_uiLastSelectedItemID = (unsigned int)event.GetItem().m_pItem;

	DisplayItemInfo(_uiLastSelectedItemID);

    event.Skip();

}

void CMainFrame::OnTreeRightClick(wxTreeEvent &event)
{
    event.Skip();

}

void CMainFrame::OnTreeItemMenu(wxTreeEvent &event)
{
	//_uiLastSelectedItemID = (unsigned int)event.GetItem().m_pItem;
	//
 //   wxPoint pt = event.GetPoint();

	//DisplayItemMenu(_uiLastSelectedItemID, pt);

	//m_ctrlTree->SelectItem(event.GetItem(), true);

    event.Skip();
}

void CMainFrame::OnTreeItemActivated(wxTreeEvent& event)
{
	_uiLastSelectedItemID = (unsigned int)event.GetItem().m_pItem;

	ParseItemData(_uiLastSelectedItemID);

    event.Skip();
}

void CMainFrame::OnNotebookPageChanged(wxToolbookEvent &event)
{
	if(_uiLastSelectedItemID != 0)
		DisplayItemData(_uiLastSelectedItemID);
    event.Skip();
}

void CMainFrame::OnNotebookPageChanging(wxToolbookEvent &event)
{
	event.Skip();
}

void CMainFrame::OnButtonInfoExport(wxCommandEvent &event)
{
	if(_uiLastSelectedItemID != 0)
	{
		ExportItemData(_uiLastSelectedItemID);
	}
    event.Skip();
}

void CMainFrame::OnMenuHelpTest(wxCommandEvent& event)
{
//	_objMPQDBCFieldManager.Load(".\\DBC.xml");
	if(!event.IsChecked())
		_objNotebookPanelManager.ShowPanel(PT_WAVE, false);
	else
	{
		_objNotebookPanelManager.ShowPanel(PT_WAVE, true);
		//CNotebookBLPPanel* panel = (CNotebookBLPPanel*)_objNotebookPanelManager.GetPanel(PT_BLP);
		//panel->ShowImage(wxT(".\\horse.blp.png"));
	}
	event.Skip();
}

void CMainFrame::OnMenuViewTreeStyle(wxCommandEvent& event)
{
	bool change = false;
	if(event.GetId() == IDM_VIEW_TREESTYLE_CATEGORY)
	{
		change = _objMPQTree.SetTreeStyle(CMPQTreeObject::TS_CATEGORY);
	}
	else
	{
		change = _objMPQTree.SetTreeStyle(CMPQTreeObject::TS_DIRECTORY);
	}
	
	if(change)
	{
		if(!_objDeMPQ.ArchFileName().empty())
		{
			wxString str = m_ctrlToolComboBox->GetValue();
			if(str.empty())
				str = wxT("*.*");

			ScanMPQArchData(Toolkit::String2wxString(_objDeMPQ.ArchFileName()), str);
		}
	}

	event.Skip();
}

void CMainFrame::OnMenuParserDBC(wxCommandEvent &event)
{
	wxFileDialog dlg(this,
						wxT("Open DBC file..."),
						wxEmptyString,
						wxT("*.dbc"),
						wxT("DBC Files (*.dbc)|*.dbc|All Files (*.*)|*.*"),
						wxFD_OPEN|wxFD_FILE_MUST_EXIST);
	if (dlg.ShowModal() == wxID_OK)
	{
		std::string file = Toolkit::wxString2String(dlg.GetPath());
		if(ParseMPQDBCFile(file, file, false) != 0)
		{
			wxMessageBox(wxT("Parse DBC file failed."));
		}
	}
	event.Skip();
}

void CMainFrame::OnMenuParserBLP(wxCommandEvent &event)
{
	wxFileDialog dlg(this,
						wxT("Open BLP file..."),
						wxEmptyString,
						wxT("*.blp"),
						wxT("BLP Files (*.blp)|*.blp|All Files (*.*)|*.*"),
						wxFD_OPEN|wxFD_FILE_MUST_EXIST);
	if (dlg.ShowModal() == wxID_OK)
	{
		std::string file = Toolkit::wxString2String(dlg.GetPath());
		if(ParseMPQBLPFile(file, file, false) != 0)
		{
			wxMessageBox(wxT("Parse BLP file failed."));
		}
	}
	event.Skip();
}


void CMainFrame::OnMenuSettingLoadDBCConfig(wxCommandEvent &event)
{
	wxFileDialog dlg(this,
						wxT("Open DBC configuration file..."),
						wxEmptyString,
						wxT("*.xml"),
						wxT("DBC Configuration Files (*.xml)|*.xml|All Files (*.*)|*.*"),
						wxFD_OPEN|wxFD_FILE_MUST_EXIST);
	if (dlg.ShowModal() == wxID_OK)
	{
		if(LoadMPQDBCConfigFile(Toolkit::wxString2String(dlg.GetPath()), false) != 0)
		{
			wxMessageBox(wxT("Load DBC configuration file failed."));
		}
	}
	event.Skip();
}


////
void CMainFrame::TreeRefresh(const wxString& rootfile)
{
	SetStatusText(wxT("0"), 1);
	_objMPQTree.Refresh(rootfile);
}

void CMainFrame::TreeUpdateOver(unsigned int count)
{
	SetStatusText(wxT("Scan over."), 0);
	wxString str;
	str.sprintf(wxT("%d"), count);
	SetStatusText(str, 1);
	_objMPQTree.AppendOver(count);
}

void CMainFrame::TreeAppend(const MPQData::TFileData &data, unsigned int count)
{
	SetStatusText(Toolkit::String2wxString(data.m_strName), 0);
	_objMPQTree.Append(data, false);
	wxString str;
	str.sprintf(wxT("%d"), count);
	SetStatusText(str, 1);
}

void CMainFrame::NoteDataReadBegin(const wxString& file)
{
	_objMPQData.ReadBegin(file);
}

void CMainFrame::NoteDataReadEnd()
{
	_objMPQData.ReadEnd();
}

void CMainFrame::NoteDataRead(const char* data, size_t size)
{
	_objMPQData.Read(data, size);
}

///
int CMainFrame::ScanMPQArchData(const wxString &arch, const wxString &filter)
{
	std::auto_ptr<CArchScanAdapter> scan(new CArchScanAdapter(*this));
	_objDeMPQ.OpenArch(Toolkit::wxString2String(arch));
	return _objDeMPQ.ScanArch(scan.get(), Toolkit::wxString2String(filter));
}

void CMainFrame::DisplayItemInfo(unsigned int id)
{
	const MPQData::TFileData* data = _objMPQTree.GetData(id);
	
	CNotebookInfoPanel* panel = (CNotebookInfoPanel*)_objNotebookPanelManager.GetPanel(PT_INFO);
	if(panel == NULL)
		return;
	panel->DisplayInfo(data);

	if(m_ctrlNotebook->GetSelection() == PT_DATA)
	{
		DisplayItemData(data);
	}
	
//	ParseItemData(data);
}

void CMainFrame::DisplayItemData(unsigned int id)
{
	if(m_ctrlNotebook->GetSelection() != PT_DATA)
		return;
	const MPQData::TFileData* data = _objMPQTree.GetData(id);
	DisplayItemData(data);
}

void CMainFrame::DisplayItemData(const MPQData::TFileData *data)
{
	if(data == NULL)
		return;

	CNotebookDataPanel * panel = (CNotebookDataPanel *)_objNotebookPanelManager.GetPanel(PT_DATA);
	if(panel == NULL)
		return;
	if(panel->CheckDataFileName(Toolkit::String2wxString(data->m_strName)))
		return;

	if(data->m_uiSize > 0xFFFF)
	{
		wxMessageDialog dlg(this,wxT("Data size MORE than 64kb, sure to view ?"), wxT("Comfirm"), (wxCENTRE | wxYES_NO | wxICON_QUESTION));
		if(dlg.ShowModal() != wxID_YES)
		{
			m_ctrlNotebook->SetSelection(PT_INFO);
			return;
		}
	}

	std::auto_ptr<CFileReadAdapter> adapter(new CFileReadAdapter(*this));
	_objDeMPQ.ReadFile(adapter.get(), data->m_strName);
}

void CMainFrame::DisplayItemMenu(unsigned int id, const wxPoint& pos)
{
	const MPQData::TFileData* data = _objMPQTree.GetData(id);
	if(data == NULL)
		return;

	    //wxPoint screenpt = ClientToScreen(pos);
//	ClientToScreen(pos);
	wxMenu menu(wxT("DDD"));
	menu.Append(IDM_HELP_TEST, wxT("&Test"), wxT("Just for test."), wxITEM_CHECK);
	PopupMenu(&menu, pos);
}

void CMainFrame::ExportItemData(unsigned int id)
{
	const MPQData::TFileData* data = _objMPQTree.GetData(id);
	if(data == NULL)
		return;
	wxString ofile = wxT("*.*");
	wxString suffix = wxT("All Files (*.*)|*.*");
	wxString file = Toolkit::String2wxString(data->m_strName);

	size_t pos = file.find_last_of(wxT("\\"));
	if(pos != 0)
	{
		file = file.substr(pos + 1);
	}

	wxFileDialog dlg(this,
						wxT("Export file from MPQ..."),
						wxEmptyString,
						file,
						suffix,
						wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
	if (dlg.ShowModal() == wxID_OK)
	{
		if(_objDeMPQ.ExtractFile(data->m_strName, Toolkit::wxString2String(dlg.GetPath())) != 0)
		{
			wxMessageBox(wxT("Export data failed."));
		}
	}
}

int CMainFrame::ExtractFileToCache(const std::string& file, std::string& cache)
{
	cache = file;

	size_t pos = cache.find_last_of("\\");
	if(pos != 0)
	{
		cache = cache.substr(pos + 1);
	}
	cache = CSTR_MPQFILE_CACHE + cache;

	if(_objDeMPQ.ExtractFile(file, cache) != 0)
	{
		wxMessageBox(wxT("Extract data failed."));
		return -1;
	}
	return 0;
}

int CMainFrame::ParseItemData(unsigned int id)
{
	const MPQData::TFileData* data = _objMPQTree.GetData(id);
	if(data == NULL)
		return -1;

	wxString file = Toolkit::String2wxString(data->m_strName);

	size_t pos = file.find_last_of(wxT("."));
	wxString suffix = file.substr(pos + 1);
	if(pos == 0)
	{
		suffix = wxT("");
	}

	CMPQTreeObject::SuffixType type = _objMPQTree.GetSuffixType(suffix);

	if(type == CMPQTreeObject::ST_DBC)
	{
		std::string str;
		if(ExtractFileToCache(data->m_strName, str) != 0)
			return -1;
		return ParseMPQDBCFile(data->m_strName, str, true);
	}
	else if(type == CMPQTreeObject::ST_BLP)
	{
		std::string str;
		if(ExtractFileToCache(data->m_strName, str) != 0)
			return -1;
		return ParseMPQBLPFile(data->m_strName, str, true);
	}
	else if(type == CMPQTreeObject::ST_WAV || type == CMPQTreeObject::ST_MP3)
	{
		std::string str;
		if(ExtractFileToCache(data->m_strName, str) != 0)
			return -1;
		return ParseMPQWaveFile(data->m_strName, str, true);
	}
	return 0;
}

int CMainFrame::ParseMPQDBCFile(const std::string& mpqfile, const std::string &cachefile, bool remove)
{
	CMPQDBCObject obj;
	if(obj.LoadFile(cachefile, remove) != 0)
		return -1;
		
	CNotebookPanel* panel = _objNotebookPanelManager.ShowPanel(PT_DBC, true);
	if(panel == NULL)
		return -1;

	panel->SetFileName(Toolkit::String2wxString(mpqfile));

	obj.AttachPanel(panel);
	if(obj.ParseInfo() != 0)
		return -1;
	if(obj.ParseData(_objMPQDBCFieldManager) != 0)
		return -1;

	return 0;
}

int CMainFrame::LoadMPQDBCConfigFile(const std::string& file, bool reload)
{
	return _objMPQDBCFieldManager.Load(file, reload);
}

int CMainFrame::ParseMPQBLPFile(const std::string& mpqfile, const std::string &cachefile, bool remove)
{
	CMPQBLPObject obj;
	if(obj.LoadFile(cachefile, remove) != 0)
		return -1;
		
	CNotebookPanel* panel = _objNotebookPanelManager.ShowPanel(PT_BLP, true);
	if(panel == NULL)
		return -1;

	panel->SetFileName(Toolkit::String2wxString(mpqfile));

	obj.AttachPanel(panel);
	if(obj.ShowImage() != 0)
		return -1;

	return 0;
}

int CMainFrame::ParseMPQWaveFile(const std::string& mpqfile, const std::string &cachefile, bool remove)
{
	CMPQWaveObject obj;
	if(obj.LoadFile(cachefile, remove) != 0)
		return -1;
	CNotebookPanel* panel = _objNotebookPanelManager.ShowPanel(PT_WAVE, true);
	if(panel == NULL)
		return -1;
	panel->SetFileName(Toolkit::String2wxString(mpqfile));

	obj.AttachPanel(panel);
	if(obj.PlayFile() != 0)
		return -1;
	return 0;
}

