NicTheQuick wrote: Wed May 29, 2024 11:52 am
All solutions are wrong. This should be right:...
Sorry, my error; this is a more complete code:
Code: Select all
unsigned long h = 0, high; // Directory Hash
OSD::elements = 0;
OSD::ndirs = 0;
while ((de = readdir(dir)) != nullptr) {
string fname = de->d_name;
// if (fname[0] == 'A') printf("Fname: %s\n",fname.c_str());
if (de->d_type == DT_REG || de->d_type == DT_DIR) {
if (fname.compare(0,1,".") != 0) {
// if (fname[0] == 'A') printf("Fname2: %s\n",fname.c_str());
// if ((de->d_type == DT_DIR) || (std::find(filexts.begin(),filexts.end(),fname.substr(fname.size()-4)) != filexts.end())) {
// if ((de->d_type == DT_DIR) || ((fname.size() > 3) && (std::find(filexts.begin(),filexts.end(),fname.substr(fname.size()-4)) != filexts.end()))) {
size_t fpos = fname.find_last_of(".");
if ((de->d_type == DT_DIR) || ((fpos != string::npos) && (std::find(filexts.begin(),filexts.end(),fname.substr(fpos)) != filexts.end()))) {
// if (fname[0] == 'A') printf("Fname3: %s\n",fname.c_str());
if (de->d_type == DT_DIR) {
filenames.push_back((char(32) + fname).c_str());
OSD::ndirs++;
} else {
filenames.push_back(fname.c_str());
OSD::elements++;
}
// Calc hash
for (int i = 0; i < fname.length(); i++) {
h = (h << 4) + fname[i];
if (high = h & 0xF0000000)
h ^= high >> 24;
h &= ~high;
}
cnt++;
if (cnt == MAX_FNAMES_PER_CHUNK) {
// Dump current chunk
sort(filenames.begin(),filenames.end()); // Sort vector
sprintf(fileName, "%d", chunk_cnt);
FILE *f = fopen((fpath + fileTypes[ftype].indexFilename + fileName).c_str(), "w");
if (f==NULL) {
printf("Error opening filelist chunk\n");
// Close progress dialog
OSD::progressDialog("","",0,2);
return;
}
for (int n=0; n < MAX_FNAMES_PER_CHUNK; n++) fputs((filenames[n] + std::string(63 - filenames[n].size(), ' ') + "\n").c_str(),f);
fclose(f);
filenames.clear();
cnt = 0;
chunk_cnt++;
items_processed--;
}
}
}
items_processed++;
OSD::progressDialog("","",(float) 100 / ((float) item_count / (float) items_processed),1);
}
}
Sorry to all, until at night I can't test any of your code.
Thank you again!