Sequence* PatchTree::FindAllFiles(Sequence *files, const char *startPath, const char *extensionMask) { char *path = strcat(strcpy(new char[MAX_LINE], startPath), "\\"); int length = strlen(path); if(extensionMask) strcat(path, extensionMask); WIN32_FIND_DATA *fd = new WIN32_FIND_DATA; for(int i=0; i<2; i++) { if(i) strcat(path, "*.*"); HANDLE fff = FindFirstFile(path, fd); if(fff!=INVALID_HANDLE_VALUE) { do { if(!(strcmp(fd->cFileName, ".") && strcmp(fd->cFileName, ".."))) continue; if(!i||fd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { path[length] = '\0'; strcat(path, fd->cFileName); files = i?FindAllFiles(files, path, extensionMask):new Sequence(NULL, path, files); } }while(FindNextFile(fff, fd)); FindClose(fff); } path[length] = '\0'; } delete fd; delete[] path; return files; }
int main(int argc,char*argv[]) { std::set<std::string> stFiles; FindAllFiles(stFiles,"C:\\Program Files (x86)\\Electronic Arts\\Battlefield 2142"); std::ofstream ofs("checksums.txt"); for (std::set<std::string>::iterator it=stFiles.begin();it!=stFiles.end();++it) { ofs << MD5File(it->c_str()) << '\t' << *it << std::endl; } ofs.close(); return 0; }
PatchTree* PatchTree::BuildPatchTree() { Sequence *files = FindAllFiles(new Sequence(NULL, PATCH_SETTINGS, NULL), PATCH_PATH, PATCH_MASK); if(!files) return NULL; char *sections = new char[MAX_LINE]; PatchTree *tree = NULL; Sequence *current = files; do { GetPrivateProfileSectionNames(sections, MAX_LINE, current->String); char *name = sections; while(*name != '\0') { PatchTree *patch; if((patch = new PatchTree(name))->ReadSection(current->String, name) ? patch->UpdateTree(&tree) : true) delete patch; name += strlen(name) + 1; } current = current->Next; }while(current); delete files; delete[] sections; return tree; }
bool FileHandler::FindAllFiles(std::string path, std::list<std::string>& fileList, std::list<std::string>& folders) { DIR *dir; struct dirent *entry; if (!(dir = opendir(path.data()))) return false; if (!(entry = readdir(dir))) return false; do { std::string filename = path + "/" + entry->d_name; if (entry->d_type == DT_DIR) { if (filename[filename.size()-1] == '.') { continue; } folders.push_back(filename); FindAllFiles(filename, fileList, folders); } else { std::string filename = path + "/" + entry->d_name; fileList.push_back(filename); } } while ((entry = readdir(dir))); closedir(dir); return true; }