void EDirectory::RescanList() { char Dir[256]; char Name[256]; int DirCount = 0; unsigned long SizeCount = 0; FileFind *ff; FileInfo *fi; int rc; if (Files) FreeList(); Count = 0; FCount = 0; if (JustDirectory(Path, Dir, sizeof(Dir)) != 0) return; JustFileName(Path, Name, sizeof(Name)); // we don't want any special information about symbolic links, just to browse files ff = new FileFind(Dir, "*", ffDIRECTORY | ffHIDDEN | ffLINK); if (ff == 0) return ; rc = ff->FindFirst(&fi); while (rc == 0) { assert(fi != 0); if (strcmp(fi->Name(), ".") != 0) { Files = (FileInfo **)realloc((void *)Files, ((FCount | 255) + 1) * sizeof(FileInfo *)); if (Files == 0) { delete fi; delete ff; return; } Files[FCount] = fi; SizeCount += Files[FCount]->Size(); if (fi->Type() == fiDIRECTORY && (strcmp(fi->Name(), "..") != 0)) DirCount++; Count++; FCount++; } else delete fi; rc = ff->FindNext(&fi); } delete ff; { char CTitle[256]; sprintf(CTitle, "%d files%c%d dirs%c%lu bytes%c%-200.200s", FCount, ConGetDrawChar(DCH_V), DirCount, ConGetDrawChar(DCH_V), SizeCount, ConGetDrawChar(DCH_V), Dir); SetTitle(CTitle); } qsort(Files, FCount, sizeof(FileInfo *), FileNameCmp); NeedsRedraw = 1; }
/** * @brief 读取奖品INI信息 * * @param char*** ppStringBufferIni 传入字符串数组返回奖品信息 * @param int* pStringCount 返回数组的个数 */ DLLEXPORT void _stdcall LoadLotteryIniInfo(char*** ppStringBufferIni, int* pStringsCount) { //读取ini文件进行奖品信息的录入 std::vector<std::string> listLottery; //CFileFind filefind; FileFind filefind; if (filefind.IsFileExist(L"set.ini")) { TCHAR strKeyNameTemp[2048]; TCHAR strValueTemp[256]; //filefind.FindNextFileW(); std::wstring IniPath = filefind.getFilePath(); DWORD dwKeyNameSize = GetPrivateProfileString(L"LotteryName", NULL, NULL, strKeyNameTemp, 2048, IniPath.c_str()); //DWORD dw = GetLastError(); if (dwKeyNameSize > 0) { TCHAR* pKeyName = new TCHAR[dwKeyNameSize]; int nKeyNameLen = 0; for (int j = 0; j < dwKeyNameSize; j++) { pKeyName[nKeyNameLen++] = strKeyNameTemp[j]; if (strKeyNameTemp[j] == L'') { if (GetPrivateProfileString(L"LotteryName", pKeyName, NULL, strValueTemp, 256, IniPath.c_str()) > 0) { listLottery.push_back(exString::WideCharToMultiChar(strValueTemp)); } nKeyNameLen = 0; } } delete[] pKeyName; } } *pStringsCount = listLottery.size(); size_t stSizeOfArray = sizeof(char*) * listLottery.size(); *ppStringBufferIni = (char**)::CoTaskMemAlloc(stSizeOfArray); memset(*ppStringBufferIni, 0, stSizeOfArray); for (int i = 0, count = listLottery.size(); i < count; i++) { (*ppStringBufferIni)[i] = (char*)::CoTaskMemAlloc(listLottery[i].length() + 1); strcpy((*ppStringBufferIni)[i], listLottery[i].c_str()); } }
/*! * \brief */ void SequenceLogFileManager::enumFileInfoList(const CoreString* dirName) { if (mFileInfoArray.size() > 0) return; FixedString<MAX_PATH> path; FileFind find; find.setListener(this); path.format("%s%c%08d%c*.slog", dirName->getBuffer(), PATH_DELIMITER, mUserId, PATH_DELIMITER); find.exec(&path); path.format("%s%c%08d%c*.log", dirName->getBuffer(), PATH_DELIMITER, mUserId, PATH_DELIMITER); find.exec(&path); mFileInfoArray.sort(CompareFileInfo()); }
int MultiFileLoad(int createFlags, const char *FileName, const char *Mode, EView *View) { char fX[MAXPATH]; int count = 0; char FPath[MAXPATH]; char FName[MAXPATH]; FileFind *ff; FileInfo *fi; int rc; assert(View != 0); JustDirectory(FileName, fX, sizeof (fX)); if (fX[0] == 0) strcpy(fX, "."); JustFileName(FileName, FName, sizeof(FName)); if (ExpandPath(fX, FPath, sizeof(FPath)) == -1) return 0; Slash(FPath, 1); ff = new FileFind(FPath, FName, ffHIDDEN | ffFULLPATH); if (ff == 0) return 0; rc = ff->FindFirst(&fi); while (rc == 0) { count++; if (FileLoad(createFlags, fi->Name(), Mode, View) == 0) { delete fi; delete ff; return 0; } delete fi; rc = ff->FindNext(&fi); } delete ff; if (count == 0) return FileLoad(createFlags, FileName, Mode, View); return 1; }
int CompletePath(const char *Base, char *Match, int Count) { char Name[MAXPATH]; const char *dirp; char *namep; int len, count = 0; char cname[MAXPATH]; int hascname = 0; RxMatchRes RM; FileFind *ff; FileInfo *fi; int rc; if (strcmp(Base, "") == 0) { if (ExpandPath(".", Name, sizeof(Name)) != 0) return -1; } else { if (ExpandPath(Base, Name, sizeof(Name)) != 0) return -1; } // SlashDir(Name); dirp = Name; namep = SepRChr(Name); if (namep == Name) { dirp = SSLASH; namep = Name + 1; } else if (namep == NULL) { namep = Name; dirp = SDOT; } else { *namep = 0; namep++; } len = strlen(namep); strcpy(Match, dirp); SlashDir(Match); cname[0] = 0; ff = new FileFind(dirp, "*", ffDIRECTORY | ffHIDDEN #if defined(USE_DIRENT) | ffFAST // for SPEED #endif ); if (ff == 0) return 0; rc = ff->FindFirst(&fi); while (rc == 0) { const char *dname = fi->Name(); // filter out unwanted files if ((strcmp(dname, ".") != 0) && (strcmp(dname, "..") != 0) && (!CompletionFilter || RxExec(CompletionFilter, dname, strlen(dname), dname, &RM) != 1)) { if (( #if defined(UNIX) strncmp #else // os2, nt, ... strnicmp #endif (namep, dname, len) == 0) && (dname[0] != '.' || namep[0] == '.')) { count++; if (Count == count) { Slash(Match, 1); strcat(Match, dname); if ( #if defined(USE_DIRENT) // for SPEED IsDirectory(Match) #else fi->Type() == fiDIRECTORY #endif ) Slash(Match, 1); } else if (Count == -1) { if (!hascname) { strcpy(cname, dname); hascname = 1; } else { int o = 0; #ifdef UNIX while (cname[o] && dname[o] && (cname[o] == dname[o])) o++; #endif #if defined(OS2) || defined(NT) while (cname[o] && dname[o] && (toupper(cname[o]) == toupper(dname[o]))) o++; #endif cname[o] = 0; } } } } delete fi; rc = ff->FindNext(&fi); } delete ff; if (Count == -1) { Slash(Match, 1); strcat(Match, cname); if (count == 1) SlashDir(Match); } return count; }
int _tmain(int argc, _TCHAR* argv[]) { ASSERT(argc>=3); if (argc<3) { _tcout<<_T("打包参数太少!")<<endl; return -1; } string src_path=argv[AM_SRC_PATHNAME]; string dst_path=argv[AM_DST_PATHNAME]; string src_key=DPK_DEFAULT_KEY; //源目录 if(argc==4) { src_key=argv[AM_LUCK_KEY]; } CDpk dpk; dpk.create(dst_path.c_str(),src_key.c_str()); //查找文件 FileFind find; if(!find.FindFile(src_path.c_str(),true)) { _tcout<<_T("查找文件失败!")<<std::endl; } else { const StringArray & arr=find.GetFileName(); if (arr.size()<=0) { _tcout<<_T("文件个数为 0 !")<<std::endl; goto Flag; } for (size_t i=0;i<arr.size();++i) { //打开文件 hFile=CreateFile(arr[i].c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if(INVALID_HANDLE_VALUE==hFile) { _tcout<<_T("打开: ")<<arr[i].c_str()<<_T(" 文件失败!")<<std::endl; system("pause"); break; } //清除路径前缀 string path=arr[i].c_str(); //path.erase(0,src_path.length()+1); int nPos=src_path.find_last_of('\\'); path=path.substr(nPos+1,path.length()-nPos-1); StringReplace(path,"\\","/"); //拷贝文件的路径名 SDpkNodeData data; //获取文件长度并分配内存 data.nSize=GetFileSize(hFile,NULL); data.pData=new char[data.nSize](); //读取文件 ReadFile(hFile, data.pData, data.nSize, &nRealSize, NULL); ASSERT(data.nSize==nRealSize); //关闭文件 CloseHandle(hFile); _tcout<<_T("成功: ")<<path.c_str()<<std::endl; //保存 dpk.addFileData(path.c_str(),data); } dpk.save(); } _tcout<<_T("打包成功!")<<endl; //system("pause"); return 0; Flag: _tcout<<_T("打包失败!")<<endl; //system("pause"); return -1; }
/** * @brief 打开制定索引的设备 * * @param int selIndex 传入需要打开设备的索引,索引号码从0开始 * @param int selFilter 传入包过滤器,默认值为-1,表示截取所有类型的包 * * @return bool 返回true表示打开成功,返回false表示打开失败 */ bool Wincap::OpenDevice(int selIndex, int selFilter/* = -1*/) { bool bRet = false; u_int netmask; struct bpf_program fcode; do{ //判断所有索引是否符合,如果不符合则跳出 if ((selIndex < 0 || selIndex >= mDevCount) || (selFilter != -1 && (selFilter < 0 || selFilter >= mFilter.size()))) { const char* errormsg = "打开索引错误,请确认后再尝试"; strcpy(mErrbuf, errormsg); break; } pcap_if_t* seldev = nullptr; pcap_if_t* dev = mAlldev; //根据索引找到需要打开的设备 for (int i = 0; i < selIndex; i++) { dev = dev->next; } seldev = dev; //打开需要打开的设备 if ((mAdhandle = pcap_open_live(seldev->name, 65536, 1, 1000, mErrbuf)) == nullptr) { const char* errormsg = "打开指定的设备出错,请确认后再尝试"; strcpy(mErrbuf, errormsg); break; } //打开数据包连接 if (pcap_datalink(mAdhandle) != DLT_EN10MB) { const char* errormsg = "这不适合于非以太网的网络"; strcpy(mErrbuf, errormsg); break; } //如果打开设备的地址存在,那么掩码否则传入默认值 if (dev->addresses != NULL) netmask = ((struct sockaddr_in *)(dev->addresses->netmask))->sin_addr.S_un.S_addr; else netmask = 0xffffff; //如果传入的过滤器是-1,那么表示所有类型的包都需要抓取 if (selFilter == -1) { char filter[] = ""; //将过滤器加载到已经打开设备,如果打开失败则跳出 if (pcap_compile(mAdhandle, &fcode, filter, 1, netmask) < 0) { const char* errormsg = "语法错误,无法编译过滤器"; strcpy(mErrbuf, errormsg); break; } } else { //保存选择的设备索引 std::string selfilter = mFilter[selFilter]; char* filter = new char[selfilter.length() + 1]; strcpy(filter, selfilter.c_str()); //将过滤器加载到已经打开的设备上面,如果打开失败则跳出 if (pcap_compile(mAdhandle, &fcode, filter, 1, netmask) < 0) { const char* errormsg = "语法错误,无法编译过滤器"; strcpy(mErrbuf, errormsg); break; } } //设置过滤器 if (pcap_setfilter(mAdhandle, &fcode) < 0) { const char* errormsg = "设置过滤器错误"; strcpy(mErrbuf, errormsg); break; } //设置自动保存文件 if (mbSaveFile) { FileFind file; char thistime[30]; struct tm* ltime; memset(mFilepath, 0, 512); memset(mFilename, 0, 64); if (!file.IsDirectoryExist(_T("SavedData"))) { CreateDirectory(_T("SavedData"), NULL); } time_t nowtime; time(&nowtime); ltime = localtime(&nowtime); strftime(thistime, sizeof(thistime), "%Y%m%d %H%M%S", ltime); strcpy(mFilepath, "SavedData\\"); strcat(mFilename, thistime); strcat(mFilename, ".lix"); strcat(mFilepath, mFilename); mDumpfile = pcap_dump_open(mAdhandle, mFilepath); if (mDumpfile == NULL) { const char* errormsg = "文件创建错误"; strcpy(mErrbuf, errormsg); break; } } bRet = true; } while (false); return bRet; }