lafe @ ウィキ
SaveAllTab
最終更新:
lafe
-
view
// すべてのタブの情報をTabList.xmlに保存する
void CDonutTabBar::SaveAllTab()
{
if (m_bSaveAllTab == false) {
return;
}
// トラベルログを保存する
_SaveTravelLog(GetCurSel());
CString TabList = Misc::GetExeDirectory() + _T("TabList.xml");
try {
CXmlFileWrite xmlWrite(TabList);
// <TabList>
xmlWrite.WriteStartElement(L"TabList");
for (int i = 0; i < GetItemCount(); ++i) {
const CTabItem &Item = GetItem(i);
xmlWrite.WriteStartElement(L"Tab");
xmlWrite.WriteAttributeString(L"name" , Item.m_strItem);
xmlWrite.WriteAttributeString(L"FullPath", Item.m_strFullPath);
CString strIndex;
strIndex.Format(_T("%d"), Item.m_nSelectedIndex);
xmlWrite.WriteAttributeString(L"index" , strIndex);
CString strNavigate;
if (Item.m_fsState & TCISTATE_NAVIGATELOCK) {
strNavigate = L"true";
} else {
strNavigate = L"false";
}
xmlWrite.WriteAttributeString(L"NavigateLock", strNavigate);
xmlWrite.WriteStartElement(L"ITEMIDLIST");
LPITEMIDLIST pidl = GetItemIDList(i);
do {
xmlWrite.WriteStartElement(L"ITEM");
int ByteSize = pidl->mkid.cb - sizeof(USHORT);
CString strabID;
for (int i = 0; i < ByteSize; ++i) {
strabID.AppendFormat(_T("%d,"), *(pidl->mkid.abID + i));
}
CString strcb;
strcb.AppendFormat(_T("%d"), pidl->mkid.cb);
xmlWrite.WriteAttributeString(L"cb", strcb);
xmlWrite.WriteAttributeString(L"abID", strabID);
xmlWrite.WriteFullEndElement();
} while (pidl = ::ILGetNext(pidl));
xmlWrite.WriteFullEndElement();
xmlWrite.WriteStartElement(L"TravelLog");
xmlWrite.WriteStartElement(L"Back");
for (int i = 0; i < Item.m_pTravelLogBack->size();++i) {
xmlWrite.WriteStartElement(L"item");
xmlWrite.WriteAttributeString(L"title", Item.m_pTravelLogBack->at(i).first);
xmlWrite.WriteAttributeString(L"url" , Item.m_pTravelLogBack->at(i).second);
xmlWrite.WriteFullEndElement(); // </item>
}
xmlWrite.WriteFullEndElement(); // </Back>
xmlWrite.WriteStartElement(L"Fore");
for (int i = 0; i < Item.m_pTravelLogFore->size();++i) {
xmlWrite.WriteStartElement(L"item");
xmlWrite.WriteAttributeString(L"title", Item.m_pTravelLogFore->at(i).first);
xmlWrite.WriteAttributeString(L"url" , Item.m_pTravelLogFore->at(i).second);
xmlWrite.WriteFullEndElement(); // </item>
}
xmlWrite.WriteFullEndElement(); // </Fore>
xmlWrite.WriteFullEndElement(); // </TravelLog>
xmlWrite.WriteFullEndElement(); // </Tab>
}
}
catch (LPCTSTR strError) {
MessageBox(strError);
}
catch (...) {
MessageBox(_T("SaveAllTabListに失敗"));
}
}
void CDonutTabBar::RestoreAllTab()
{
CString TabList = Misc::GetExeDirectory() + _T("TabList.xml");
vector<CTabItem> vecItem;
CTabItem item;
vector<std::pair<int, BYTE*> > vecIDList;
TRAVELLOG* pBackLog = NULL;
TRAVELLOG* pForeLog = NULL;
try {
CXmlFileRead xmlRead(TabList);
CString Element;
XmlNodeType nodeType;
while (xmlRead.Read(&nodeType) == S_OK) {
switch (nodeType) {
case XmlNodeType_Element:
{
Element = xmlRead.GetLocalName(); // 要素を取得
if (Element == _T("Tab")) {
if (xmlRead.MoveToFirstAttribute()) {
do {
CString strName = xmlRead.GetLocalName();
if (strName == _T("name")) {
item.m_strItem = xmlRead.GetValue();
} else if (strName == _T("FullPath")) {
item.m_strFullPath = xmlRead.GetValue();
} else if (strName == _T("index")) {
item.m_nSelectedIndex = _wtoi(xmlRead.GetValue());
} else if (strName == _T("NavigateLock")) {
if (xmlRead.GetValue() == _T("true")) {
item.m_fsState |= TCISTATE_NAVIGATELOCK;
} else {
item.m_fsState &= ~TCISTATE_NAVIGATELOCK;
}
}
} while (xmlRead.MoveToNextAttribute());
}
} else if (Element == _T("ITEMIDLIST")) {
CString strItem;
while (xmlRead.GetInternalElement(_T("ITEMIDLIST"), strItem)) {
if (strItem == _T("ITEM")) {
int nSize;
if (xmlRead.MoveToFirstAttribute()) {
nSize = _wtoi(xmlRead.GetValue());
if (nSize == 0) {
continue;
}
if (xmlRead.MoveToNextAttribute()) {
std::wstring strBinary = xmlRead.GetValue();
LPBYTE pabID = GetByteArrayFromBinary(nSize, strBinary);
vecIDList.push_back(std::make_pair(nSize, pabID));
}
}
}
}
} else if (Element == _T("Back")) {
pBackLog = new TRAVELLOG;
CString strItem;
/* 順次追加する */
while (xmlRead.GetInternalElement(_T("Back"), strItem)) {
if (strItem == _T("item")) {
CString title;
CString url;
if (xmlRead.MoveToFirstAttribute()) {
title = xmlRead.GetValue();
if (xmlRead.MoveToNextAttribute()) {
url = xmlRead.GetValue();
pBackLog->push_back( std::make_pair(title, url) );
}
}
}
}
item.m_pTravelLogBack = pBackLog;
pBackLog = NULL;
} else if (Element == _T("Fore")) {
pForeLog = new TRAVELLOG;
CString strItem;
/* 順次追加する */
while (xmlRead.GetInternalElement(_T("Fore"), strItem)) {
if (strItem == _T("item")) {
CString title;
CString url;
if (xmlRead.MoveToFirstAttribute()) {
title = xmlRead.GetValue();
if (xmlRead.MoveToNextAttribute()) {
url = xmlRead.GetValue();
pForeLog->push_back( std::make_pair(title, url) );
}
}
}
}
item.m_pTravelLogFore = pForeLog;
pForeLog = NULL;
}
break;
}
case XmlNodeType_EndElement:
{
if (xmlRead.GetLocalName() == _T("Tab")) {
// </Tab>にきたので
/* ITEMIDLISTを作成 */
int nSize = 0;
for (int i = 0; i < vecIDList.size(); ++i) {
nSize += vecIDList[i].first;
}
LPITEMIDLIST pRetIDList;
LPITEMIDLIST pNewIDList;
CComPtr<IMalloc> spMalloc;
::SHGetMalloc(&spMalloc);
pNewIDList = pRetIDList = (LPITEMIDLIST)spMalloc->Alloc(nSize + sizeof(USHORT));
::SecureZeroMemory(pRetIDList, nSize + sizeof(USHORT));
for (int i = 0; i < vecIDList.size() ; ++i) {
pRetIDList->mkid.cb = vecIDList[i].first;
memcpy(pRetIDList->mkid.abID, vecIDList[i].second, pRetIDList->mkid.cb - sizeof(USHORT));
delete vecIDList[i].second;
pRetIDList = LPITEMIDLIST((LPBYTE)pRetIDList + vecIDList[i].first);
}
item.m_pidl = pNewIDList;
vecIDList.clear(); // 使い終わったので削除しておく
vecItem.push_back(item);
}
break;
}
}
}
/* タブに追加していく */
for (int i = 0; i < vecItem.size(); ++i) {
AddTabItem(vecItem[i]);
}
}
catch (LPCTSTR strError) {
MessageBox(strError);
}
catch (...) {
MessageBox(_T("RestoreAllTabに失敗"));
}
}
// 履歴を保存する
void CDonutTabBar::SaveHistory()
{
CString History = Misc::GetExeDirectory() + _T("History.xml");
try {
CXmlFileWrite xmlWrite(History);
// <History>
xmlWrite.WriteStartElement(L"History");
for (int i = 0; i < m_vecHistoryItem.size(); ++i) {
const HistoryItem &Item = m_vecHistoryItem[i];
// <item>
xmlWrite.WriteStartElement(L"item");
xmlWrite.WriteAttributeString(L"Title" , Item.strTitle);
xmlWrite.WriteAttributeString(L"FullPath", Item.strFullPath);
// <ITEMIDLIST>
xmlWrite.WriteStartElement(L"ITEMIDLIST");
LPITEMIDLIST pidl = Item.pidl;
do {
xmlWrite.WriteStartElement(L"ITEM");
int ByteSize = pidl->mkid.cb - sizeof(USHORT);
CString strabID;
for (int i = 0; i < ByteSize; ++i) {
strabID.AppendFormat(_T("%d,"), *(pidl->mkid.abID + i));
}
CString strcb;
strcb.AppendFormat(_T("%d"), pidl->mkid.cb);
xmlWrite.WriteAttributeString(L"cb", strcb);
xmlWrite.WriteAttributeString(L"abID", strabID);
xmlWrite.WriteFullEndElement();
} while (pidl = ::ILGetNext(pidl));
xmlWrite.WriteFullEndElement(); // </ITEMIDLIST>
xmlWrite.WriteStartElement(L"TravelLog");
xmlWrite.WriteStartElement(L"Back");
for (int i = 0; i < Item.pLogBack->size();++i) {
xmlWrite.WriteStartElement(L"item");
xmlWrite.WriteAttributeString(L"title", Item.pLogBack->at(i).first);
xmlWrite.WriteAttributeString(L"url" , Item.pLogBack->at(i).second);
xmlWrite.WriteFullEndElement(); // </item>
}
xmlWrite.WriteFullEndElement(); // </Back>
xmlWrite.WriteStartElement(L"Fore");
for (int i = 0; i < Item.pLogFore->size();++i) {
xmlWrite.WriteStartElement(L"item");
xmlWrite.WriteAttributeString(L"title", Item.pLogFore->at(i).first);
xmlWrite.WriteAttributeString(L"url" , Item.pLogFore->at(i).second);
xmlWrite.WriteFullEndElement(); // </item>
}
xmlWrite.WriteFullEndElement(); // </Fore>
xmlWrite.WriteFullEndElement(); // </TravelLog>
xmlWrite.WriteFullEndElement(); // </item>
}
}
catch (LPCTSTR strError) {
MessageBox(strError);
}
catch (...) {
MessageBox(_T("SaveHistoryに失敗"));
}
}
// 履歴を復元する
void CDonutTabBar::RestoreHistory()
{
CString History = Misc::GetExeDirectory() + _T("History.xml");
vector<HistoryItem> vecItem;
HistoryItem item;
vector<std::pair<int, BYTE*> > vecIDList;
TRAVELLOG* pBackLog = NULL;
TRAVELLOG* pForeLog = NULL;
try {
CXmlFileRead xmlRead(History);
CString Element;
XmlNodeType nodeType;
while (xmlRead.Read(&nodeType) == S_OK) {
switch (nodeType) {
case XmlNodeType_Element:
{
Element = xmlRead.GetLocalName(); // 要素を取得
if (Element == _T("item")) {
if (xmlRead.MoveToFirstAttribute()) {
do {
CString strName = xmlRead.GetLocalName();
if (strName == _T("Title")) {
item.strTitle = xmlRead.GetValue();
} else if (strName == _T("FullPath")) {
item.strFullPath = xmlRead.GetValue();
}
} while (xmlRead.MoveToNextAttribute());
}
} else if (Element == _T("ITEMIDLIST")) {
CString strItem;
while (xmlRead.GetInternalElement(_T("ITEMIDLIST"), strItem)) {
if (strItem == _T("ITEM")) {
int nSize;
if (xmlRead.MoveToFirstAttribute()) {
nSize = _wtoi(xmlRead.GetValue());
if (nSize == 0) {
continue;
}
if (xmlRead.MoveToNextAttribute()) {
std::wstring strBinary = xmlRead.GetValue();
LPBYTE pabID = GetByteArrayFromBinary(nSize, strBinary);
vecIDList.push_back(std::make_pair(nSize, pabID));
}
}
}
}
} else if (Element == _T("Back")) {
pBackLog = new TRAVELLOG;
CString strItem;
/* 順次追加する */
while (xmlRead.GetInternalElement(_T("Back"), strItem)) {
if (strItem == _T("item")) {
CString title;
CString url;
if (xmlRead.MoveToFirstAttribute()) {
title = xmlRead.GetValue();
if (xmlRead.MoveToNextAttribute()) {
url = xmlRead.GetValue();
pBackLog->push_back( std::make_pair(title, url) );
}
}
}
}
item.pLogBack = pBackLog;
pBackLog = NULL;
} else if (Element == _T("Fore")) {
pForeLog = new TRAVELLOG;
CString strItem;
/* 順次追加する */
while (xmlRead.GetInternalElement(_T("Fore"), strItem)) {
if (strItem == _T("item")) {
CString title;
CString url;
if (xmlRead.MoveToFirstAttribute()) {
title = xmlRead.GetValue();
if (xmlRead.MoveToNextAttribute()) {
url = xmlRead.GetValue();
pForeLog->push_back( std::make_pair(title, url) );
}
}
}
}
item.pLogFore = pForeLog;
pForeLog = NULL;
}
break;
}
case XmlNodeType_EndElement:
{
if (xmlRead.GetLocalName() == _T("item")) {
// </item>にきたので
/* ITEMIDLISTを作成 */
int nSize = 0;
for (int i = 0; i < vecIDList.size(); ++i) {
nSize += vecIDList[i].first;
}
LPITEMIDLIST pRetIDList;
LPITEMIDLIST pNewIDList;
CComPtr<IMalloc> spMalloc;
::SHGetMalloc(&spMalloc);
pNewIDList = pRetIDList = (LPITEMIDLIST)spMalloc->Alloc(nSize + sizeof(USHORT));
::SecureZeroMemory(pRetIDList, nSize + sizeof(USHORT));
for (int i = 0; i < vecIDList.size() ; ++i) {
pRetIDList->mkid.cb = vecIDList[i].first;
memcpy(pRetIDList->mkid.abID, vecIDList[i].second, pRetIDList->mkid.cb - sizeof(USHORT));
delete vecIDList[i].second;
pRetIDList = LPITEMIDLIST((LPBYTE)pRetIDList + vecIDList[i].first);
}
item.pidl = pNewIDList;
vecIDList.clear(); // 使い終わったので削除しておく
vecItem.push_back(item);
}
break;
}
}
}
/* 履歴に追加していく */
for (int i = 0; i < vecItem.size(); ++i) {
HICON hIcon = CreateIconFromIDList(vecItem[i].pidl);
vecItem[i].hbmp = Misc::CreateBitmapFromHICON(hIcon);
::DestroyIcon(hIcon);
m_vecHistoryItem.push_back(vecItem[i]);
}
}
catch (LPCTSTR strError) {
MessageBox(strError);
}
catch (...) {
MessageBox(_T("RestoreHistoryに失敗"));
}
}