Skip to content

Commit

Permalink
生成filelist时扫描子目录
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanyuanxiang committed Jan 17, 2019
1 parent 2f4a238 commit db8620b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
2 changes: 2 additions & 0 deletions ReadMe.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ V1.0.1.2
1、新增注释。
2、更新YAMA到更稳定的版本。
3、仅当截图时才创建ScreenShot目录。
2019.1.16
生成filelist时,扫描子目录中的文件,以便升级程序能下载子目录中的更新文件。
32 changes: 22 additions & 10 deletions socket/SocketServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,24 @@ void CSocketServer::GetAllSoftwareVersion()
Lock();
m_mapVersion.insert(make_pair(app.tolower(), GetExeVersion(path)));
Unlock();
CheckFilelist(ff.GetFilePath());
CString filelist = ff.GetFilePath() + _T("\\filelist.txt");
DeleteFile(filelist);
CheckFilelist(ff.GetFilePath(), filelist);
}
}
}
ff.Close();
}


void CSocketServer::CheckFilelist(const CString &folder)
/************************************************************************
* @brief 扫描指定目录,将该目录下的文件写入指定文件
* @param[in] folder 指定目录
* @param[in] file_list 指定文件
* @param[in] file file_list根目录
************************************************************************/
void CSocketServer::CheckFilelist(const CString &folder,
const CString &file_list,
const CString &root)
{
CFileFind ff;
CString filter = folder + _T("\\*.*");
Expand All @@ -151,29 +160,30 @@ void CSocketServer::CheckFilelist(const CString &folder)
while (bFind)
{
bFind = ff.FindNextFile();
if (ff.IsDots() || ff.IsDirectory())continue;
if (ff.IsDots())continue;
else if(ff.IsDirectory())
CheckFilelist(folder + _T("\\") + ff.GetFileName(), file_list, ff.GetFileName());
else
{
CString name = ff.GetFileName();
CString name = root.IsEmpty() ? ff.GetFileName() : root + _T("\\") + ff.GetFileName();
int n = name.Find(L".conf", 0); // 排除配置文件
if (name != L"filelist.txt" && n == -1)
if (ff.GetFileName() != L"filelist.txt" && n == -1)
{
v_AllFiles.push_back(name);
}
}
}
ff.Close();

CString file(folder + _T("\\filelist.txt"));
FILE *filelist = NULL;
if (filelist = fopen(W2A(file), "wb"))
if (filelist = fopen(W2A(file_list), "a+"))
{
for (std::vector<CString>::const_iterator itor = v_AllFiles.begin();
itor != v_AllFiles.end(); ++itor)
{
String cur = W2A(*itor);
fwrite(cur, 1, strlen(cur), filelist);
fwrite("\r\n", 1, 2, filelist);
fwrite("\n", 1, 1, filelist);
}
fclose(filelist);
}
Expand Down Expand Up @@ -296,7 +306,9 @@ std::string CSocketServer::getVersion(const std::string &name)
while(*p) ++p;
while('\\' != *p) --p;
sprintf(p+1, "%s", name.c_str());
CheckFilelist(CString(path));
CString filelist = CString(path)+_T("\\filelist.txt");
DeleteFile(filelist);
CheckFilelist(CString(path), filelist);
sprintf(p+1, "%s\\%s.exe", name.c_str(), name.c_str());
std::string ver = GetExeVersion(CString(path));
Lock();
Expand Down
2 changes: 1 addition & 1 deletion socket/SocketServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CSocketServer : public CSocketBase
std::map<std::string, std::string> m_mapVersion;
void GetAllSoftwareVersion();
// 自动生成升级文件列表"filelist.txt"
void CheckFilelist(const CString &folder);
void CheckFilelist(const CString &folder, const CString &file_list, const CString &root=NULL);

public:
// 检测是否需要更新版本,若需要则返回新版本号
Expand Down

0 comments on commit db8620b

Please sign in to comment.