Ejemplo n.º 1
0
        bool search::index_files(const std::string &filter) {
            std::ifstream pbo_stream;
            std::regex txt_regex(filter);

            if (_active_pbo_list.size() < 1)
                return false;

            for (auto & pbo_file_path : _active_pbo_list) {
                pbo_stream.open(pbo_file_path, std::ios::binary | std::ios::in);
                if (!pbo_stream.good()) {
                    LOG(ERROR) << "Cannot open file - " << pbo_file_path;
                    continue;
                }

                ace::pbo::archive _archive(pbo_stream);
                for (ace::pbo::entry_p & entry : _archive.entries) {
                    if (entry->filename != "") {
                        if (std::regex_match(entry->filename, txt_regex)) {
                            std::string full_virtual_path = _archive.info->data + "\\" + entry->filename;
                            std::transform(full_virtual_path.begin(), full_virtual_path.end(), full_virtual_path.begin(), ::tolower);
                            _file_pbo_index[full_virtual_path] = pbo_file_path;
                            //LOG(DEBUG) << full_virtual_path << " = " << pbo_file_path;
                        }
                    }
                }
                pbo_stream.close();
            }

            LOG(INFO) << "PBO Index complete";

            return true;
        }
Ejemplo n.º 2
0
static void _archive_dir(char *in, char *out, int ilen, int olen)
{
    int i, t;
    DIR *d;
    struct dirent *de;

    if(verbose) {
        fprintf(stderr,"_archive_dir('%s','%s',%d,%d)\n",
                in, out, ilen, olen);
    }

    d = opendir(in);
    if(d == 0) die("cannot open directory '%s'", in);

    int size = 32;
    int entries = 0;
    char** names = malloc(size * sizeof(char*));
    if (names == NULL) {
      fprintf(stderr, "failed to allocate dir names array (size %d)\n", size);
      exit(1);
    }

    while((de = readdir(d)) != 0){
            /* xxx: feature? maybe some dotfiles are okay */
        if(de->d_name[0] == '.') continue;

            /* xxx: hack. use a real exclude list */
        if(!strcmp(de->d_name, "root")) continue;

        if (entries >= size) {
          size *= 2;
          names = realloc(names, size * sizeof(char*));
          if (names == NULL) {
            fprintf(stderr, "failed to reallocate dir names array (size %d)\n",
                    size);
            exit(1);
          }
        }
        names[entries] = strdup(de->d_name);
        if (names[entries] == NULL) {
          fprintf(stderr, "failed to strdup name \"%s\"\n",
                  de->d_name);
          exit(1);
        }
        ++entries;
    }

    qsort(names, entries, sizeof(char*), compare);

    for (i = 0; i < entries; ++i) {
        t = strlen(names[i]);
        in[ilen] = '/';
        memcpy(in + ilen + 1, names[i], t + 1);

        if(olen > 0) {
            out[olen] = '/';
            memcpy(out + olen + 1, names[i], t + 1);
            _archive(in, out, ilen + t + 1, olen + t + 1);
        } else {
            memcpy(out, names[i], t + 1);
            _archive(in, out, ilen + t + 1, t);
        }

        in[ilen] = 0;
        out[olen] = 0;

        free(names[i]);
    }
    free(names);

    closedir(d);
}