123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421 |
- #include "stdafx.h"
- #include "mediaManage.h"
- #include <set>
- #include <algorithm>
- mediaManage::mediaManage()
- {
- m_curParse.clear();
- if (checkDirExist(DEFAULT_RESOURSE_PATH))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Set defaultAdvertPath:%s, defaultDownloadPath:%s", DEFAULT_RESOURSE_PATH, DEFAULT_DOWNLOAD_PATH);
- setDefaultAddvertPath(string(DEFAULT_RESOURSE_PATH));
- setDefaultDownloadPath(string(DEFAULT_DOWNLOAD_PATH));
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Set defaultAdvertPath:%s, defaultDownloadPath:%s", DEFAULT_RESOURSE_PATH_C, DEFAULT_DOWNLOAD_PATH_C);
- setDefaultAddvertPath(string(DEFAULT_RESOURSE_PATH_C));
- setDefaultDownloadPath(string(DEFAULT_DOWNLOAD_PATH_C));
- }
- bloged = false;
- }
- void mediaManage::setDefaultAddvertPath(string addvertPath){ m_addvertPath = addvertPath; }
- void mediaManage::setDefaultDownloadPath(string downloadPath){ m_downloadPath = downloadPath; }
- void mediaManage::GetPlayList(vector<ResourceParse> &resourceList)
- {
- resourceList.clear();
- for (vector<ParseInfo>::iterator i = m_curParse.begin(); i != m_curParse.end(); i++)
- {
- for (vector<ResourceParse>::iterator j = i->m_mediaList.begin(); j != i->m_mediaList.end(); j++)
- {
- if (checkInVaildTime(j->vaildTime, true) && checkInPlayTime(j->playTime, true))
- resourceList.push_back(*j);
- }
- }
- }
- size_t mediaManage::GetPlayListByLocal(vector<ResourceParse>& resourceList)
- {
- size_t uNum = 0;
- resourceList.clear();
- #ifdef RVC_OS_WIN
- for each (auto i in m_localList)
- {
- if (checkInVaildTime(i.vaildTime, true) && checkInPlayTime(i.playTime, true)) {
- resourceList.push_back(i);
- uNum++;
- }
- }
- #else
- for (vector<ResourceParse>::iterator it = m_localList.begin(); it != m_localList.end(); it++)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("play extend %c:%s, %s, %s, %s", it->type, it->resourcePath.c_str(), it->videoNames.c_str(), it->vaildTime.c_str(), it->playTime.c_str());
- if (checkInVaildTime(it->vaildTime, true) && checkInPlayTime(it->playTime, true)) {
- resourceList.push_back(*it);
- uNum++;
- }
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("uNum is %d, m_localList size is %d, resourceList size is %d", uNum, m_localList.size(), resourceList.size());
- for (vector<ResourceParse>::iterator i = resourceList.begin(); i != resourceList.end(); i++)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("begin play extend %c:%s, %s", i->type, i->resourcePath.c_str(), i->videoNames.c_str());
- }
- #endif // _WIN32
- return uNum;
- }
- size_t mediaManage::GetPlayListByLocal(CResourceParse** ResourceArr, size_t uSize)
- {
- size_t uNum = 0;
- for (vector<ResourceParse>::iterator it = m_localList.begin(); it != m_localList.end() && uNum < uSize; it++)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("new deep copy play extend %c:%s, %s, %s, %s", it->type, it->resourcePath.c_str(), it->videoNames.c_str(), it->vaildTime.c_str(), it->playTime.c_str());
- if (checkInVaildTime(it->vaildTime, true) && checkInPlayTime(it->playTime, true)) {
- CResourceParse* pNode = new CResourceParse();
- pNode->type = it->type;
- pNode->fullScreen = it->fullScreen;
- pNode->primMonitor = it->primMonitor;
- pNode->simpleMode = it->simpleMode;
- pNode->playInterval = it->playInterval;
- pNode->priority = it->priority;
- if (it->videoNames.length() > 0) {
- pNode->pvideoNames = new char[it->videoNames.length() + 1];
- memset(pNode->pvideoNames, 0, it->videoNames.length() + 1);
- memcpy(pNode->pvideoNames, it->videoNames.c_str(), it->videoNames.length());
- }
- if (it->vaildTime.length() > 0) {
- pNode->pvaildTime = new char[it->vaildTime.length() + 1];
- memset(pNode->pvaildTime, 0, it->vaildTime.length() + 1);
- memcpy(pNode->pvaildTime, it->vaildTime.c_str(), it->vaildTime.length());
- }
- if (it->resourcePath.length() > 0) {
- pNode->presourcePath = new char[it->resourcePath.length() + 1];
- memset(pNode->presourcePath, 0, it->resourcePath.length() + 1);
- memcpy(pNode->presourcePath, it->resourcePath.c_str(), it->resourcePath.length());
- }
- if (it->playTime.length() > 0) {
- pNode->playTime = new char[it->playTime.length() + 1];
- memset(pNode->playTime, 0, it->playTime.length() + 1);
- memcpy(pNode->playTime, it->playTime.c_str(), it->playTime.length());
- }
- ResourceArr[uNum++] = pNode;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("aftercopy play extend pNode->type=0x%08x:pNode->presourcePath=0x%08x, pNode->pvideoNames=0x%08x, pNode->pvaildTime=0x%08x, pNode->playTime=0x%08x", pNode->type, pNode->presourcePath, pNode->pvideoNames, pNode->pvaildTime, pNode->playTime);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("aftercopy play extend %c:%s, %s, %s, %s", pNode->type, pNode->presourcePath, pNode->pvideoNames, pNode->pvaildTime, pNode->playTime);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d ResourceList[%d] address is 0x%08x, pNode address is 0x%08x.", __FUNCTION__, __LINE__, uNum-1, ResourceArr[uNum-1], pNode);
-
- }
- }
- return uNum;
- }
- size_t mediaManage::GetPlayListByLocal(rvcResourceParse_t* ResourceArr, size_t uSize)
- {
- size_t uNum = 0;
- for (vector<ResourceParse>::iterator it = m_localList.begin(); it != m_localList.end() && uNum < uSize; it++)
- {
- if (false == bloged){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("new deep copy play extend %c:%s, %s, %s, %s", it->type, it->resourcePath.c_str(), it->videoNames.c_str(), it->vaildTime.c_str(), it->playTime.c_str());
- }
- if (checkInVaildTime(it->vaildTime, true) && checkInPlayTime(it->playTime, true) && IsResourceExist(it->resourcePath, it->videoNames)) {
- rvcResourceParse_t* pNode = ResourceArr+uNum;
- pNode->type = it->type;
- pNode->fullScreen = it->fullScreen;
- pNode->primMonitor = it->primMonitor;
- pNode->simpleMode = it->simpleMode;
- pNode->playInterval = it->playInterval;
- pNode->priority = it->priority;
- if (it->videoNames.length() > 0) {
- memcpy(pNode->strvideoNames, it->videoNames.c_str(), it->videoNames.length());
- }
- if (it->vaildTime.length() > 0) {
- memcpy(pNode->strvaildTime, it->vaildTime.c_str(), it->vaildTime.length());
- }
- if (it->resourcePath.length() > 0) {
- memcpy(pNode->strResourcePath, it->resourcePath.c_str(), it->resourcePath.length());
- }
- if (it->playTime.length() > 0) {
- memcpy(pNode->strplayTime, it->playTime.c_str(), it->playTime.length());
- }
- uNum++;
- }
- }
- bloged = true;
- return uNum;
- }
- bool mediaManage::InitResourseList(vector<string> resourceList)
- {
- /*
- */
- vector<string> needDelete(10), needAdd(10);
- set<string> oldResourceList, newResourseList;
- //get the old resource List
- for (vector<ParseInfo>::iterator j = m_curParse.begin(); j != m_curParse.end(); j++)
- oldResourceList.insert(j->m_resourceName);
- for (vector<string>::iterator i = resourceList.begin(); i != resourceList.end(); i++)
- newResourseList.insert(*i);
- auto deletePos = set_difference(oldResourceList.begin(), oldResourceList.end(), newResourseList.begin(), newResourseList.end(), needDelete.begin());//need to delete
- needDelete.resize(deletePos - needDelete.begin());
- auto addPos = set_difference(newResourseList.begin(), newResourseList.end(), oldResourceList.begin(), oldResourceList.end(), needAdd.begin());//need to add
- needAdd.resize(addPos - needAdd.begin());
- DeleteResourceList(needDelete);
- AddResourceList(needAdd);
- return true;
- }
- bool mediaManage::AddResourceList(vector<string> resourceList)
- {
- if (0 == resourceList.size())
- return true;
- for (vector<string>::iterator i = resourceList.begin(); i != resourceList.end(); i++)
- {
- int pos = i->find(".zip");
- if (-1 == pos)
- continue;
- string dirName = i->substr(0, pos);
- string fileName = m_downloadPath + SPLIT_SLASH_STR + *i;
- string dirPath = m_addvertPath + SPLIT_SLASH_STR + dirName;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("dirName:%s, fileName:%s, dirPath:%s", dirName.c_str(), fileName.c_str(), dirPath.c_str());
- wstring wfileName, wdirPath;
- StringToWstring(wfileName, fileName);
- StringToWstring(wdirPath, dirPath);
- if (!checkFileExist(dirPath))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("dir %s not exist!", dirPath.c_str());
- continue;
- }
- /*
- if (!checkFileExist(dirPath) && createDir(dirPath) && !Unzip2Folder((BSTR)wfileName.c_str(), (BSTR)wdirPath.c_str()))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("unzip %s to %s fail!", fileName.c_str(), dirPath.c_str());
- continue;
- }
- */
- string configPath = "";
- if (!findVaildConfig(dirPath, configPath))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("can not find config file in %s//%s", dirPath.c_str(), configPath.c_str());
- continue;
- }
- vector<ResourceParse> mediaList;
- if (!parseResourceIni(configPath.c_str(), mediaList))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("parse config %s fail!", configPath.c_str());
- continue;
- }
- string resourcePath = dirPath + SPLIT_SLASH_STR;
- /* if (!getUniqueDir(dirPath, resourcePath))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("error:find multi resource dir!");
- continue;
- }
- resourcePath = dirPath + "\\" + resourcePath + "\\";
- */
- for (vector<ResourceParse>::iterator j = mediaList.begin(); j != mediaList.end(); j++)
- j->resourcePath = resourcePath;
- ParseInfo resourseInfo(*i, mediaList);
- m_curParse.push_back(resourseInfo);//modify resourse list
- }
- return true;
- }
- void mediaManage::InitResourceListByLocal()
- {
- string headFile = m_addvertPath + SPLIT_SLASH_STR + HEADINI_NAME;
- string branchFile = m_addvertPath + SPLIT_SLASH_STR + BRANCHINI_NAME;
- string networkFile = m_addvertPath + SPLIT_SLASH_STR + NETWORKINI_NAME;
- vector<ResourceParse> headList, branchList, networkList, allList;
- if (!checkFileExist(headFile)) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("head config %s not exist!", headFile.c_str());
- }
- else if (!parseResourceIni(headFile.c_str(), headList)) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("parse head config %s fail!", headFile.c_str());
- }
- if (!checkFileExist(branchFile)) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("branch config %s not exist!", branchFile.c_str());
- }
- else if (!parseResourceIni(branchFile.c_str(), branchList)) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("parse branch config %s fail!", branchFile.c_str());
- }
- if (!checkFileExist(networkFile)) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("network config %s not exist!", networkFile.c_str());
- }
- else if (!parseResourceIni(networkFile.c_str(), networkList)) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("parse network config %s fail!", networkFile.c_str());
- }
-
- m_localList.clear();
- #ifdef RVC_OS_WIN
- for each (auto i in headList)
- m_localList.push_back(i);
- for each (auto i in branchList)
- m_localList.push_back(i);
- for each (auto i in networkList)
- m_localList.push_back(i);
- #else
- size_t uheadList = 0;
- size_t ubranchList = 0;
- size_t unetworkList = 0;
- for (vector<ResourceParse>::iterator it = headList.begin(); it < headList.end(); ++it){
- m_localList.push_back(*it);
- uheadList++;
- }
- for (vector<ResourceParse>::iterator it = branchList.begin(); it < branchList.end(); ++it){
- m_localList.push_back(*it);
- ubranchList++;
- }
- for (vector<ResourceParse>::iterator it = networkList.begin(); it < networkList.end(); ++it){
- m_localList.push_back(*it);
- unetworkList++;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("headList size is %d, branchList size is %d, networkList size is %d, and m_localList size is %u.", uheadList, ubranchList, unetworkList, m_localList.size());
- #endif // RVC_OS_WIN
-
- std::stable_sort(m_localList.begin(), m_localList.end(), [](const ResourceParse& a, const ResourceParse& b) {
- return a.priority > b.priority;
- });
- for (auto i = m_localList.begin(); i != m_localList.end(); i++)
- {
- size_t pos = i->videoNames.find("\\");
- if (pos != string::npos){
- //Dbg("%s find result is not string::npos", i->videoNames.c_str());
- i->resourcePath = m_addvertPath + SPLIT_SLASH_STR + i->videoNames.substr(0, pos) + SPLIT_SLASH_STR;
- i->videoNames = i->videoNames.substr(pos + 1, i->videoNames.length() - pos - 1);
- }
- else {
- //Dbg("%s find result is string::npos", i->videoNames.c_str());
- i->resourcePath = m_addvertPath + SPLIT_SLASH_STR;
- }
- }
- }
- void mediaManage::DeleteResourceList(vector<string> resourceList)
- {
- if (0 == resourceList.size())
- return;
- for (vector<string>::iterator i = resourceList.begin(); i != resourceList.end(); i++)
- {
- for (vector<ParseInfo>::iterator j = m_curParse.begin(); j != m_curParse.end(); j++)
- {
- if (*i == j->m_resourceName)
- {
- m_curParse.erase(j);
- break;
- }
- }
- }
- }
- bool mediaManage::findVaildConfig(string dirPath, string &configPath)
- {
- string headFile = dirPath + SPLIT_SLASH_STR + HEADINI_NAME;
- string branchFile = dirPath + SPLIT_SLASH_STR + BRANCHINI_NAME;
- string networkFile = dirPath + SPLIT_SLASH_STR + NETWORKINI_NAME;
- if (checkFileExist(headFile))
- {
- configPath = headFile;
- return true;
- }
- else if (checkFileExist(branchFile))
- {
- configPath = branchFile;
- return true;
- }
- else if (checkFileExist(networkFile))
- {
- configPath = networkFile;
- return true;
- }
- else
- return false;
- }
- bool mediaManage::IsResourceExist(string strPath, string strName)
- {
- return checkFileExist(strPath + strName);
- }
- void mediaManage::clearOutdataResource()
- {
- vector<string> dirInfo, needDelete(10);
- set<string> oldResourceList, newResourseList;
- try
- {
- getDirs(m_addvertPath, dirInfo);
- for (vector<ParseInfo>::iterator i = m_curParse.begin(); i != m_curParse.end(); i++)
- {
- int pos = i->m_resourceName.find(".zip");
- if (-1 == pos)
- continue;
- newResourseList.insert(i->m_resourceName.substr(0, pos));
- }
- for (vector<string>::iterator i = dirInfo.begin(); i != dirInfo.end(); i++)
- {
- if(-1 != i->find(DEFAULT_HEAD_CONTAIN) || -1 != i->find(DEFAULT_FEN_CONTAIN) || -1 != i->find(DEFAULT_NETWORK_CONTAIN) || -1 != i->find(DEFAULT_NETWORK2_CONTAIN))
- oldResourceList.insert(*i);
- }
- auto deletePos = set_difference(oldResourceList.begin(), oldResourceList.end(), newResourseList.begin(), newResourseList.end(), needDelete.begin());//need to delete
- needDelete.resize(deletePos - needDelete.begin());
- for (vector<string>::iterator i = needDelete.begin(); i != needDelete.end(); i++)
- {
- string path = m_addvertPath + SPLIT_SLASH_STR + *i;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("remove Dir %s %s!", *i, removeDir(path) ? "success" : "fail");
- }
- }
- catch (exception* e)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("remove Dir exception:%s", e->what());
- }
- }
|