#include "stdafx.h" #include "mediaManage.h" #include #include 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 &resourceList) { resourceList.clear(); for (vector::iterator i = m_curParse.begin(); i != m_curParse.end(); i++) { for (vector::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& 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::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::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::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::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 resourceList) { /* */ vector needDelete(10), needAdd(10); set oldResourceList, newResourseList; //get the old resource List for (vector::iterator j = m_curParse.begin(); j != m_curParse.end(); j++) oldResourceList.insert(j->m_resourceName); for (vector::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 resourceList) { if (0 == resourceList.size()) return true; for (vector::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 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::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 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::iterator it = headList.begin(); it < headList.end(); ++it){ m_localList.push_back(*it); uheadList++; } for (vector::iterator it = branchList.begin(); it < branchList.end(); ++it){ m_localList.push_back(*it); ubranchList++; } for (vector::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 resourceList) { if (0 == resourceList.size()) return; for (vector::iterator i = resourceList.begin(); i != resourceList.end(); i++) { for (vector::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 dirInfo, needDelete(10); set oldResourceList, newResourseList; try { getDirs(m_addvertPath, dirInfo); for (vector::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::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::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()); } }