代码拉取完成,页面将自动刷新
同步操作将从 ccc1/ZHLT_UPack 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#ifndef __IO_STATIC_H__
#define __IO_STATIC_H__
/*!
Author : dfhu
data: 2002-7
des: the baic io function wrap
*/
#include <string>
#include <vector>
#include <sys/stat.h>
#include <sys/types.h>
#include "iostatic_func.h"
#ifdef WIN32
#include <windows.h>
#include <direct.h>
#include "winver.h"
#include <tchar.h>
#include <io.h>
#define mkdir(a,b) mkdir(a)
#define S_IRUSR 0
#define S_IWUSR 1
#define S_IXUSR 2
#define S_IRGRP 4
#define S_IWGRP 8
#define S_IXGRP 16
#define S_IROTH 32
#define S_IWOTH 64
#define S_IXOTH 128
#endif
#pragma warning (disable : 4267 4018)
namespace IO_OP
{
inline bool Exist(const char *name)
{
struct stat buf;
if(stat(name,&buf)==0)
return true;
else
return false;
}
inline bool Exist(const std::string &name)
{
return Exist(name.c_str());
}
inline bool Rename( const char *oldName, const char *newName )
{
return rename(oldName, newName ) == 0;
}
namespace File
{
static inline bool IsFile( const char *name )
{
struct stat buf;
if(stat(name,&buf)==0)
if(S_IFREG&buf.st_mode)
return true;
return false;
}
static inline bool Delete(const char *name)
{
#ifdef WIN32
return DeleteFile(name)!=0;
#else
unlink(name);
#endif
}
static inline int GetFileLength( const char *name )
{
struct stat buf;
if(stat(name,&buf)==0)
return buf.st_size;
else
return 0;
}
static inline bool Delete(const std::string &name)
{
return Delete(name.c_str());
}
static inline bool DeleteAlways( const char *name )
{
_chmod( name, _S_IREAD | _S_IWRITE );
return Delete(name);
}
static inline
bool CopyF( const char *src, const char *dst, bool bFailIfExist )
{
#ifdef _WIN32
return (CopyFile( src, dst, bFailIfExist)!=0);
#else
return false;
#endif
}
};
namespace Path
{
static inline bool IsDir(const char *name)
{
struct stat buf;
if(stat(name,&buf)==0)
if(S_IFDIR&buf.st_mode)
return true;
return false;
}
static inline bool IsDir(const std::string &name)
{
return IsDir(name.c_str());
}
static inline void Remove(const char *name)
{
#ifdef WIN32
RemoveDirectory(name);
#else
unlink(name);
#endif
}
static inline void Remove(const std::string &sDir)
{
Remove(sDir.c_str());
}
static inline bool MakeDir(const char *sDir,int priv = S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH)
{
return mkdir(sDir,S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH)==0;
}
static inline bool MakeDir(const std::string &sDir,int priv = S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH)
{
return mkdir(sDir.c_str(),S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH)==0;
}
/* static bool MakeTree(string &sDir)
{
if(Exist(sDir.c_str()))
return true;
else
{
string sParentDir = sDir;
for(;;)
{
Parent(sParentDir);
if(!Valid(sParentDir))
break;
if(MakeTree(sParentDir))
break;
}
if(Valid(sParentDir))
return MakeDir(sDir);
else
return false;
}
}*/
static inline bool MakeTree(const std::string &sDir)
{
if(Exist(sDir.c_str()))
return true;
else
{
std::string sParentDir = sDir;
// for(;;)
{
if(!Valid( sDir ))
return false;
if( MakeDir( sDir ) )
return true;
Parent(sParentDir);
if(MakeTree(sParentDir))
return MakeDir(sDir);
else
return false;
}
}
}
static inline void AllSub(const std::string &sDir,std::vector<std::string> &sFileNameArray, bool bFullPathNameReturn=true)
{
#ifdef WIN32
std::string sFileName=sDir+"/*.*";
WIN32_FIND_DATA FindFileData;
HANDLE hFind=FindFirstFile(sFileName.c_str(),&FindFileData);
if(hFind==INVALID_HANDLE_VALUE)
return;
BOOL bFind=TRUE;//FindNextFile(hFind,&FindFileData);
while(bFind)
{
char *t=FindFileData.cFileName;
if( bFullPathNameReturn )
sFileName=sDir+'/'+t;
else
sFileName=t;
sFileNameArray.push_back(sFileName);
bFind=FindNextFile(hFind,&FindFileData);
}
FindClose(hFind);
#else
std::string sFileName;
struct dirent * *namelist;
int n=scandir(sDir.c_str(),&namelist,NULL,alphasort);
if(n>0)
{
while(n--)
{
struct dirent *name=namelist[n];
if( bFullPathNameReturn )
sFileName=sDir+'/'+name->d_name;
else
sFileName = name->d_name;
sFileNameArray.push_back(sFileName);
free(name);
}
free(namelist);
}
#endif
}
static inline void AllSubNoExtJudge(const std::string &sDir,std::vector<std::string> &sFileNameArray, bool bFullPathNameReturn)
{
AllSub( sDir, sFileNameArray, bFullPathNameReturn );
}
static inline void AllSubWithSearchSubDir( const char *sSearchDir, const char *sExt, std::vector<std::string> &sFileNameArray )
{
#ifdef WIN32
std::string sDir = sSearchDir;
NoEndDir( sDir );
std::string sFileName=sDir+"/*";//+sExt;
WIN32_FIND_DATA FindFileData;
HANDLE hFind=FindFirstFile(sFileName.c_str(),&FindFileData);
if(hFind==INVALID_HANDLE_VALUE)
return;
std::vector< std::string > sDirArray;
BOOL bFind=TRUE;//FindNextFile(hFind,&FindFileData);
while(bFind)
{
char *t=FindFileData.cFileName;
if( (FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) )
{
if( (t[0] == '.' && t[1] == 0)
|| (t[0] == '.' && t[1] == '.' && t[2] == 0) )
{
}
else
{
sFileName=sDir+'/'+t;
sDirArray.push_back( sFileName );
}
}
else
{
bool bExt = false;
if( !sExt )
bExt = true;
else
{
const char *ext = IO_OP::File::GetExt( t );
if( ext && (ext+1) )
{
if( stricmp(ext+1,sExt) == 0)
bExt = true;
}
}
if(bExt )
{
sFileName=sDir+'/'+t;
sFileNameArray.push_back(sFileName);
}
}
bFind=FindNextFile(hFind,&FindFileData);
}
FindClose(hFind);
for( int i=0; i<sDirArray.size(); ++i )
AllSubWithSearchSubDir( sDirArray[i].c_str(), sExt, sFileNameArray );
#endif
}
static inline void AllSub(const std::string &sDir, const std::string &sExt, std::vector<std::string> &sFileNameArray, bool bFullPathNameReturn=true)
{
#ifdef WIN32
std::string sFileName=sDir+"/*."+sExt;
WIN32_FIND_DATA FindFileData;
HANDLE hFind=FindFirstFile(sFileName.c_str(),&FindFileData);
if(hFind==INVALID_HANDLE_VALUE)
return;
BOOL bFind=TRUE;//FindNextFile(hFind,&FindFileData);
while(bFind)
{
char *t=FindFileData.cFileName;
if( bFullPathNameReturn )
sFileName=sDir+'/'+t;
else
sFileName = t;
sFileNameArray.push_back(sFileName);
bFind=FindNextFile(hFind,&FindFileData);
}
FindClose(hFind);
#else
std::string sFileName;
struct dirent * *namelist;
int n=scandir(sDir.c_str(),&namelist,NULL,alphasort);
if(n>0)
{
while(n--)
{
struct dirent *name=namelist[n];
if( strstr(name->d_name, sExt.c_str()) == NULL )
{
if( bFullPathNameReturn )
sFileName=sDir+'/'+name->d_name;
else
sFileName = name->d_name;
sFileNameArray.push_back(sFileName);
}
free(name);
}
free(namelist);
}
#endif
}
static inline void AllSubWithExtJudge(const std::string &sDir,const std::string &sExt,std::vector<std::string> &sFileNameArray, bool bFullPathNameReturn)
{
AllSub(sDir, sExt, sFileNameArray, bFullPathNameReturn );
}
static inline int GetDirFileNumber( const std::string &sDir )
{
#ifdef WIN32
std::string sFileName=sDir+"/*.*";
WIN32_FIND_DATA FindFileData;
HANDLE hFind=FindFirstFile(sFileName.c_str(),&FindFileData);
if(hFind==INVALID_HANDLE_VALUE)
return 0;
int n = 0;
BOOL bFind=TRUE;//FindNextFile(hFind,&FindFileData);
while(bFind)
{
if( !(FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) )
++n;
bFind=FindNextFile(hFind,&FindFileData);
}
FindClose(hFind);
return n;
#else
std::string sFileName;
struct dirent * *namelist;
int n=scandir(sDir.c_str(),&namelist,NULL,alphasort);
return n;
#endif
}
static inline int GetDirFileNumber( const std::string &sDir, const std::string &sExt )
{
#ifdef WIN32
std::string sFileName=sDir+"/*."+sExt;
WIN32_FIND_DATA FindFileData;
HANDLE hFind=FindFirstFile(sFileName.c_str(),&FindFileData);
if(hFind==INVALID_HANDLE_VALUE)
return 0;
int nNum = 0;
BOOL bFind=TRUE;//FindNextFile(hFind,&FindFileData);
while(bFind)
{
if( !(FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) )
++nNum;
bFind=FindNextFile(hFind,&FindFileData);
}
FindClose(hFind);
return nNum;
#else
int nNum = 0;
std::string sFileName;
struct dirent * *namelist;
int n=scandir(sDir.c_str(),&namelist,NULL,alphasort);
if(n>0)
{
while(n--)
{
struct dirent *name=namelist[n];
if( strstr(name->d_name, sExt.c_str()) == NULL )
{
nNum++;
}
free(name);
}
free(namelist);
}
return nNum;
#endif
}
static inline void AllSubDir(const std::string &sDir,std::vector<std::string> &sDirNameArray, bool bFullPathNameReturn=true)
{
#ifdef WIN32
std::string sFileName=sDir;
EndDir(sFileName);
sFileName += "*";
WIN32_FIND_DATA FindFileData;
HANDLE hFind=FindFirstFile(sFileName.c_str(),&FindFileData);
if(hFind==INVALID_HANDLE_VALUE)
return;
BOOL bFind=TRUE;//FindNextFile(hFind,&FindFileData);
while(bFind)
{
if( (FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) )
{
char *t=FindFileData.cFileName;
if( bFullPathNameReturn )
sFileName=sDir+'/'+t;
else
sFileName = t;
sDirNameArray.push_back(sFileName);
}
bFind=FindNextFile(hFind,&FindFileData);
}
FindClose(hFind);
#else
std::string sFileName;
struct dirent * *namelist;
int n=scandir(sDir.c_str(),&namelist,NULL,alphasort);
if(n>0)
{
while(n--)
{
struct dirent *name=namelist[n];
// if( strstr(name->d_name, sExt.c_str()) == NULL )
{
if( bFullPathNameReturn )
sFileName=sDir+'/'+name->d_name;
else
sFileName = name->d_name;
sDirNameArray.push_back(sFileName);
}
free(name);
}
free(namelist);
}
#endif
}
static inline void AllSubFile(const std::string &sDir,std::vector<std::string> &sFileNameArray, bool bFullPathNameReturn=true)
{
#ifdef WIN32
std::string sFileName=sDir;
EndDir(sFileName);
sFileName += "*.*";
WIN32_FIND_DATA FindFileData;
HANDLE hFind=FindFirstFile(sFileName.c_str(),&FindFileData);
if(hFind==INVALID_HANDLE_VALUE)
return;
BOOL bFind=TRUE;//FindNextFile(hFind,&FindFileData);
while(bFind)
{
if( !(FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
&& (!(FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DEVICE)) )
{
char *t=FindFileData.cFileName;
if( bFullPathNameReturn )
sFileName=sDir+'/'+t;
else
sFileName = t;
sFileNameArray.push_back(sFileName);
}
bFind=FindNextFile(hFind,&FindFileData);
}
FindClose(hFind);
#else
std::string sFileName;
struct dirent * *namelist;
int n=scandir(sDir.c_str(),&namelist,NULL,alphasort);
if(n>0)
{
while(n--)
{
struct dirent *name=namelist[n];
// if( strstr(name->d_name, sExt.c_str()) == NULL )
{
if( bFullPathNameReturn )
sFileName=sDir+'/'+name->d_name;
else
sFileName = name->d_name;
sFileNameArray.push_back(sFileName);
}
free(name);
}
free(namelist);
}
#endif
}
static inline void AllSubDirFile(const std::string &sDir,std::vector<std::string> &sDirNameArray, std::vector<std::string> &sFilenameArray, bool bFullPathNameReturn = true )
{
#ifdef WIN32
std::string sFileName=sDir;
EndDir(sFileName);
sFileName += "*";
WIN32_FIND_DATA FindFileData;
HANDLE hFind=FindFirstFile(sFileName.c_str(),&FindFileData);
if(hFind==INVALID_HANDLE_VALUE)
return;
BOOL bFind=TRUE;//FindNextFile(hFind,&FindFileData);
while(bFind)
{
if( (FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) )
{
char *t=FindFileData.cFileName;
if( bFullPathNameReturn )
sFileName=sDir+'/'+t;
else
sFileName = t;
sDirNameArray.push_back(sFileName);
}
else
{
char *t=FindFileData.cFileName;
if( bFullPathNameReturn )
sFileName=sDir+'/'+t;
else
sFileName = t;
sFilenameArray.push_back(sFileName);
}
bFind=FindNextFile(hFind,&FindFileData);
}
FindClose(hFind);
#else
std::string sFileName;
struct dirent * *namelist;
int n=scandir(sDir.c_str(),&namelist,NULL,alphasort);
if(n>0)
{
while(n--)
{
struct dirent *name=namelist[n];
// if( strstr(name->d_name, sExt.c_str()) == NULL )
{
if( bFullPathNameReturn )
sFileName=sDir+'/'+name->d_name;
else
sFileName = name->d_name;
sDirNameArray.push_back(sFileName);
}
free(name);
}
free(namelist);
}
#endif
}
static inline void DelTree(const std::string &sDir)
{
std::vector<std::string> tmpArray;
AllSub(sDir,tmpArray);
std::string name;
_chmod( sDir.c_str(), _S_IREAD | _S_IWRITE );
for(int i = 0 ;i < tmpArray.size();i++)
{
name = tmpArray[i];
const char *pName = IO_OP::Path::GetName(name.c_str());
if( pName[0] == '.' && pName[1] == 0 )
continue;
if( pName[0] == '.' && pName[2] == 0 && pName[1] == '.' )
continue;
if(IsDir(name))
{
DelTree(name);
}
else
{
///
_chmod( name.c_str(), _S_IREAD | _S_IWRITE );
File::Delete(name);
}
}
Remove(sDir);
}
static inline std::string GetCurrentDir()
{
char dirBufL[266];
#if defined(_WIN32)
GetCurrentDirectory(256, dirBufL);
#else
getcwd(dirBufL, 256);
#endif
return std::string(dirBufL);
}
static inline void MakeAbsoluteDir( std::string &sDir )
{
if( sDir.size() > 1 )
{
std::string sSub = sDir.substr(0,2);
if( sSub == "./" || sSub == ".\\" )
{
std::string currentDir = IO_OP::Path::GetCurrentDir();
IO_OP::Path::EndDir( currentDir );
sDir.insert( 0, currentDir );
}
}
if( sDir.size() > 2 )
{
std::string sSub = sDir.substr(0,3);
if( sSub == "../" || sSub == "..\\" )
{
std::string currentDir = IO_OP::Path::GetCurrentDir();
IO_OP::Path::EndDir( currentDir );
sDir.insert( 0, currentDir );
}
}
}
static inline void MakeAbsoluteDir( std::string &sDir, const char *currentDir )
{
if( sDir.size() > 1 )
{
std::string sSub = sDir.substr(0,2);
if( sSub == "./" || sSub == ".\\" )
{
sDir.insert( 0, currentDir );
}
}
if( sDir.size() > 2 )
{
std::string sSub = sDir.substr(0,3);
if( sSub == "../" || sSub == "..\\" )
{
sDir.insert( 0, currentDir );
}
}
}
template< typename TFunctor, typename TParam1, typename TParam2 >
inline
void do_walkdir( const std::string &sDir, TParam1 &p1, TParam2 &p2, TFunctor func)
{
func( sDir, p1, p2 );
std::vector< std::string > dirArray;
std::string sCheckDir = sDir;
IO_OP::Path::NoEndDir( sCheckDir );
IO_OP::Path::AllSubDir( sCheckDir,dirArray, false );
std::string sDirWithEnd = sDir;
IO_OP::Path::EndDir( sDirWithEnd );
for( size_t i=0; i<dirArray.size(); ++i )
{
if( (dirArray[i] == ".")
|| (dirArray[i] == "..") )
{
}
else
{
do_walkdir( sDirWithEnd + dirArray[i], p1, p2,func );
}
}
}
};
};
#pragma warning (default : 4267 4018)
#endif
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。