?? ttsdlg.cpp
字號:
//this is the index data file
ifstream file("D:/TTS-Data/index.dat");
string line;
//初始化文件索引、閱讀標記以及存儲標記
::getline(file, line);
//get the readTeg
istringstream temp(line);
temp >> m_lastReadBook >> m_lastSaveBook;
int bookNum = 0;
while(::getline(file, line))
{
istringstream input(line);
int readTag;
int saveTag;
string content;
input >> readTag >> saveTag >> content;
m_bookIndex[bookNum] = content;
m_readTag[bookNum] = readTag;
m_saveTag[bookNum] = saveTag;
bookNum++;
}
//初始化中間變量, Book從0開始計數
m_currentBook = m_lastReadBook;
m_currentPage = m_readTag[m_lastReadBook];
m_curSaveBook = m_lastSaveBook;
m_curSavePage = m_saveTag[m_lastSaveBook];
}
void CTTSDlg::NextBook()
{
ostringstream readStr;
if(m_isSave) //當前為錄制狀態
{
if(m_curSaveBook != 999)
{
m_curSaveBook++;
m_curSavePage = m_saveTag[m_curSaveBook];
readStr << "錄制當前閱讀的內容到第" << m_curSaveBook+1 << "本書。"
<< m_bookIndex[m_curSaveBook] << "第" << m_saveTag[m_curSaveBook]+1
<< "頁。按錄制鍵確認錄制或選擇其他書頁";
}
else
readStr << "已經到達最后一本書.";
}
else if(m_isDelete) //當前為刪除狀態
{
if(m_currentBook != 999)
{
m_currentBook++;
m_currentPage = 0;
m_isDelBook = true;
readStr << "清除當前整書, 第" << m_currentBook+1 << "本書"
<< m_bookIndex[m_currentBook] << "是否確認"
<< "或通過前后頁選擇要清除的頁碼";
}
else
readStr << "已經到達最后一本書.";
}
else //當前為閱讀狀態
{
m_isLoad = true;
if(m_currentBook != 999) //如果不是最后一本書
{
m_currentBook++;
m_currentPage = m_readTag[m_currentBook];
if(m_bookIndex[m_currentBook].length() == 0)
readStr << "第" << m_currentBook+1 << "本書,該書為空白。";
else
{
readStr << "第" << m_currentBook+1 << "本書。" << m_bookIndex[m_currentBook]
<< "當前讀到第" << m_readTag[m_currentBook]+1 << "頁";
}
}
else
readStr << "已經到達最后一本書.";
}
STTSPlayString(m_hTTSInstance, (char*)readStr.str().c_str(), 1);
}
void CTTSDlg::PreBook()
{
ostringstream readStr;
if(m_isSave) //當前狀態為錄制
{
if(m_curSaveBook != 0)
{
m_curSaveBook--;
m_curSavePage = m_saveTag[m_curSaveBook];
readStr << "錄制當前閱讀的內容到第" << m_curSaveBook+1 << "本書。"
<< m_bookIndex[m_curSaveBook] << "第" << m_saveTag[m_curSaveBook]+1
<< "頁。按錄制鍵確認錄制或選擇其他書頁";
}
else
readStr << "已經到達第一本書";
}
else if(m_isDelete)
{
if(m_currentBook != 0)
{
m_currentBook--;
m_currentPage = 0;
m_isDelBook = true;
readStr << "清除當前整書, 第" << m_currentBook+1 << "本書"
<< m_bookIndex[m_currentBook] << "是否確認"
<< "或通過前后頁選擇要清除的頁碼";
}
else
readStr << "已經到達第一本書";
}
else //當前狀態為閱讀
{
m_isLoad = true;
if(m_currentBook != 0) //如果不是第一本書
{
m_currentBook--;
m_currentPage = m_readTag[m_currentBook];
if(m_bookIndex[m_currentBook].length() == 0)
readStr << "第" << m_currentBook+1 << "本書,該書為空白。";
else
{
readStr << "第" << m_currentBook+1 << "本書。"
<< m_bookIndex[m_currentBook] << "當前讀到第"
<< m_readTag[m_currentBook]+1 << "頁";
}
}
else
readStr << "已經到達第一本書";
}
STTSPlayString(m_hTTSInstance, (char*)readStr.str().c_str(), 1);
}
void CTTSDlg::NextPage()
{
ostringstream readStr;
if(m_isSave) //當前狀態為錄制狀態
{
//該書為空白
//if(m_bookIndex[m_curSaveBook].length() == 0)
//{
// readStr << "該書為空白,錄制當前閱讀的內容到第" << m_curSavePage+1 << "頁"
// << "請按錄制鍵開始錄制";
// STTSPlayString(m_hTTSInstance, (char*)readStr.str().c_str(), 1);
// return;
//}
//if(m_curSavePage != 0)
// m_curSavePage++;
m_curSavePage++;
readStr << "錄制當前閱讀的內容到第" << m_curSavePage+1 << "頁"
<< "按錄制鍵確認錄制或選擇其他書頁";
}
else if(m_isDelete) //當前狀態為刪除狀態
{
m_isDelBook = false;
m_currentPage++;
ostringstream pageName;
pageName << "D:/TTS-Data/" << m_currentBook << "/" << m_currentPage;
string line;
ifstream file(pageName.str().c_str());
if(!file.is_open()) //該頁為空白頁
{
readStr << "該頁為空白頁";
}
else
{
::getline(file, line);
::getline(file, line);
file.close();
readStr << "清除當前的內容, 第" << m_currentPage+1 << "頁" << line
<< "請按清除鍵確認清除";
}
}
else //當前狀態為閱讀狀態
{
//判斷該書是否有內容
m_isLoad = true;
if(m_bookIndex[m_currentBook].length() == 0)
{
STTSPlayString(m_hTTSInstance, (char*)"該書為空白", 1);
return;
}
m_currentPage++;
//當前頁的名字
ostringstream pageName;
pageName << "D:/TTS-Data/" << m_currentBook << "/" << m_currentPage;
ifstream file(pageName.str().c_str());
if(!file.is_open()) //如果該頁為空
readStr << "第" << m_currentPage+1 << "頁。本頁為空白頁。";
else //如果該頁不為空
{
string line;
//得到該頁的第一行
::getline(file, line);
::getline(file, line);
readStr << "第" << m_currentPage+1 << "頁。" << line << "請按朗讀暫停鍵開始閱讀";
file.close();
}
}
STTSPlayString(m_hTTSInstance, (char*)readStr.str().c_str(), 1);
}
void CTTSDlg::PrePage()
{
ostringstream readStr;
if(m_isSave) //當前狀態為錄制狀態
{
if(m_curSavePage == 0)
readStr << "已到達首頁";
else
{
m_curSavePage--;
readStr << "錄制當前閱讀的內容到第" << m_curSavePage+1 << "頁"
<< "按錄制鍵確認錄制或選擇其他書頁";
}
}
else if(m_isDelete) //當前狀態為刪除
{
m_isDelBook = false;
if(m_currentPage == 0)
readStr << "已到達首頁";
else
{
m_currentPage--;
ostringstream pageName;
pageName << "D:/TTS-Data/" << m_currentBook << "/" << m_currentPage;
string line;
ifstream file(pageName.str().c_str());
if(!file.is_open()) //該頁為空白頁
readStr << "該頁為空白頁";
else
{
::getline(file, line);
::getline(file, line);
file.close();
readStr << "清除當前的內容, 第" << m_currentPage+1 << "頁" << line
<< "請按清除鍵確認清除";
}
}
}
else //當前狀態為閱讀狀態
{
//判斷該書是否有內容
m_isLoad = true;
if(m_bookIndex[m_currentBook].length() == 0)
{
STTSPlayString(m_hTTSInstance, (char*)"該書為空白", 1);
return;
}
if(m_currentPage == 0)
readStr << "已到達首頁";
else
{
m_currentPage--;
ostringstream pageName;
pageName << "D:/TTS-Data/" << m_currentBook << "/" << m_currentPage;
ifstream file(pageName.str().c_str());
if(!file.is_open()) //this page is empty
readStr << "第" << m_currentPage+1 << "頁。本頁為空白頁。";
else //this page is not empty
{
string line;
//得到該頁的第一行
::getline(file, line);
::getline(file, line);
readStr << "第" << m_currentPage+1 << "頁。" << line << "請按朗讀暫停鍵開始閱讀";
file.close();
}
}
}
STTSPlayString(m_hTTSInstance, (char*)readStr.str().c_str(), 1);
}
void CTTSDlg::LoadSavedPage()
{
ostringstream pageName;
pageName << "D:/TTS-Data/" << m_currentBook << "/"
<< m_currentPage;
ifstream file(pageName.str().c_str());
if(!file.is_open())
{
STTSPlayString(m_hTTSInstance, "該頁為空白頁", 1);
return;
}
if(!m_page.empty())
m_page.clear();
//裝載存儲的文件
string line;
while(::getline(file, line))
m_page.push_back(line);
file.close();
m_senPos = m_page.begin();
//更新閱讀標記
m_lastReadBook = m_currentBook;
m_readTag[m_currentBook] = m_currentPage;
}
void CTTSDlg::CheckSavePage()
{
//當第二次進行確認時,保存該頁內容
if(m_isSave)
{
SavePage();
return;
}
m_isSave = true;
ostringstream readStr;
readStr << "錄制當前閱讀的內容到第"<< m_lastSaveBook+1 << "本書。"
<< m_bookIndex[m_lastSaveBook].c_str() << "第"
<< m_saveTag[m_lastSaveBook]+1 << "頁。" << "按錄制鍵確認錄制或選擇其他書頁";
m_curSavePage = m_saveTag[m_curSaveBook];
STTSPlayString(m_hTTSInstance, (char*)readStr.str().c_str(), 1);
}
void CTTSDlg::SavePage()
{
ostringstream dirName;
dirName << "D:/TTS-Data/" << m_curSaveBook;
_finddata_t fileInfo;
intptr_t handle;
//如果該書還不存在,創建該書
handle = _findfirst(dirName.str().c_str(), &fileInfo);
if(handle == -1)
_mkdir(dirName.str().c_str());
_findclose(handle);
ostringstream pageName;
pageName << "D:/TTS-Data/" << m_curSaveBook << "/"
<< m_curSavePage;
if(m_isCover) //用戶要求覆蓋該頁內容
{
ofstream file(pageName.str().c_str());
for(list<string>::iterator pos = m_page.begin();
pos != m_page.end(); pos++)
file << *pos << endl;
file.close();
//更新錄制標記
m_lastSaveBook = m_curSaveBook;
m_saveTag[m_curSaveBook] = m_curSavePage + 1;
//表示錄制成功
m_isCover = false;
m_isSave = false;
STTSPlayString(m_hTTSInstance, "該頁內容已經錄制", 1);
}
else
{
//檢查該頁內是否已經有內容
ifstream checkFile(pageName.str().c_str());
if(!checkFile.is_open()) //該頁為空白頁
{
//寫入文件
ofstream file(pageName.str().c_str());
for(list<string>::iterator pos = m_page.begin();
pos != m_page.end(); pos++)
file << *pos << endl;
file.close();
//更新錄制標記
m_lastSaveBook = m_curSaveBook;
m_saveTag[m_curSaveBook] = m_curSavePage + 1;
m_isSave = false; //錄制成功
STTSPlayString(m_hTTSInstance, "該頁內容已經錄制", 1);
}
else //該頁已有內容
{
STTSPlayString(m_hTTSInstance, "本頁已有內容,按錄制鍵覆蓋或選擇其他頁", 1);
m_isCover = true;
}
}
//更新書目索引
dirName << "/*.*";
handle = _findfirst(dirName.str().c_str(), &fileInfo);
if(handle != -1)
{
do
{
if(string(fileInfo.name) == "."
|| string(fileInfo.name) == "..")
continue;
else
break;
}while(_findnext(handle, &fileInfo) == 0);
}
ostringstream firstPage;
firstPage << "D:/TTS-Data/" << m_curSaveBook << "/"
<< fileInfo.name;
ifstream first(firstPage.str().c_str());
string line;
::getline(first, line);
::getline(first, line);
if(m_bookIndex[m_curSaveBook] != line)
m_bookIndex[m_curSaveBook] = line;
//if(m_curSavePage == 0)
//{
// //這本書原本為空
// list<string>::iterator pos = m_page.begin();
// pos++;
// if(m_bookIndex[m_curSaveBook].length() == 0)
// {
// m_bookIndex[m_curSaveBook] = *pos;
// m_readTag[m_curSaveBook] = 0;
// }
// else
// m_bookIndex[m_curSaveBook] = *pos;
//}
}
void CTTSDlg::CheckDelete()
{
if(m_isDelete)
{
Delete();
return;
}
m_isDelete = true;
m_currentPage = 0;
ostringstream readStr;
readStr << "清除當前整書, 第" << m_currentBook+1 << "本書"
<< m_bookIndex[m_currentBook] << "是否確認"
<< "或通過前后頁選擇要清除的頁碼";
STTSPlayString(m_hTTSInstance, (char*)readStr.str().c_str(), 1);
}
void CTTSDlg::Delete()
{
ostringstream name;
ostringstream readStr;
if(m_isDelBook) //清除整書
{
name << "D:/TTS-Data/" << m_currentBook << "/*.*";
list<string> deleteFiles;
_finddata_t fileInfo;
intptr_t handle;
handle = _findfirst(name.str().c_str(), &fileInfo);
//刪除該目錄下所有文件
if(handle != -1)
{
do
{
if(string(fileInfo.name) == "."
|| string(fileInfo.name) == "..")
continue;
ostringstream filename;
filename << "D:/TTS-Data/" << m_currentBook
<< "/" << fileInfo.name;
//int res = remove(fileInfo.name);
deleteFiles.push_back(filename.str());
}while(_findnext(handle, &fileInfo) == 0);
}
_findclose(handle);
for(list<string>::iterator pos = deleteFiles.begin();
pos != deleteFiles.end(); pos++)
int res = remove(pos->c_str());
ostringstream dirName;
dirName << "D:/TTS-Data/" << m_currentBook;
int res = _rmdir(dirName.str().c_str());
//更新書目索引
m_bookIndex[m_currentBook] = "";
m_readTag[m_currentBook] = 0;
m_saveTag[m_currentBook] = 0;
m_isDelete = false;
readStr << "第" << m_currentBook+1 << "本書已經清除";
}
else //清除一頁
{
name << "D:/TTS-Data/" << m_currentBook << "/"
<< m_currentPage;
ifstream checkFile(name.str().c_str());
if(!checkFile.is_open()) //該頁為空白頁
return;
else
checkFile.close();
int res = remove(name.str().c_str());
m_isDelete = false;
readStr << "第" << m_currentBook + 1 << "本書第" << m_currentPage+1 << "頁已經清除";
//更新書目
_finddata_t fileInfo;
intptr_t handle;
ostringstream dirName;
dirName << "D:/TTS-Data/" << m_currentBook << "/*.*";
handle = _findfirst(dirName.str().c_str(), &fileInfo);
if(handle != -1)
{
do
{
if(string(fileInfo.name) == "."
|| string(fileInfo.name) == "..")
continue;
else
break;
}while(_findnext(handle, &fileInfo) == 0);
}
_findclose(handle);
ostringstream firstPage;
firstPage << "D:/TTS-Data/" << m_curSaveBook << "/"
<< fileInfo.name;
ifstream first(firstPage.str().c_str());
string line;
::getline(first, line);
::getline(first, line);
if(m_bookIndex[m_curSaveBook] != line)
m_bookIndex[m_curSaveBook] = line;
first.close();
if(line == "")
{
m_readTag[m_currentBook] = 0;
m_saveTag[m_currentBook] = 0;
ostringstream delDir;
delDir << "D:/TTS-Data/" << m_currentBook;
remove(delDir.str().c_str());
}
}
STTSPlayString(m_hTTSInstance, (char*)readStr.str().c_str(), 1);
}
void CTTSDlg::SaveIndex()
{
ofstream file("D:/TTS-Data/index.dat");
file << m_lastReadBook << " " << m_lastSaveBook << endl;
for(unsigned i = 0; i < m_bookIndex.size(); i++)
{
file << m_readTag[i] << " "
<< m_saveTag[i] << " "
<< m_bookIndex[i] << endl;
}
file.close();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -