Пример #1
0
int32_t ScanGroups(void)
{
    CACHE1D_FIND_REC *srch;
    struct grpcache *fg, *fgg;

    initprintf("Searching for game data...\n");

    LoadGameList();
    LoadGroupsCache();

    srch = klistpath("/", "*.grp", CACHE1D_FIND_FILE);
    ProcessGroups(srch);
    klistfree(srch);

    srch = klistpath("/", "*.ssi", CACHE1D_FIND_FILE);
    ProcessGroups(srch);
    klistfree(srch);

    FreeGroupsCache();

    for (grpfile_t *grp = foundgrps; grp; grp=grp->next)
    {
        if (grp->type->dependency)
        {
            if (FindGroup(grp->type->dependency) == NULL) // couldn't find dependency
            {
                //initprintf("removing %s\n", grp->name);
                RemoveGroup(grp);
                grp = foundgrps;
                // start from the beginning so we can remove anything that depended on this grp
                continue;
            }
        }
    }

    if (usedgrpcache)
    {
        int32_t i = 0;
        FILE *fp;
        fp = fopen(GRPCACHEFILE, "wt");
        if (fp)
        {
            for (fg = usedgrpcache; fg; fg=fgg)
            {
                fgg = fg->next;
                fprintf(fp, "\"%s\" %d %d %d\n", fg->name, fg->size, fg->mtime, fg->crcval);
                Bfree(fg);
                i++;
            }
            fclose(fp);
        }
//        initprintf("Found %d recognized GRP %s.\n",i,i>1?"files":"file");

        return 0;
    }

    initprintf("Found no recognized game data!\n");

    return 0;
}
Пример #2
0
//// FILE NAME / DIRECTORY LISTS ////
void fnlist_clearnames(fnlist_t *fnl)
{
    klistfree(fnl->finddirs);
    klistfree(fnl->findfiles);

    fnl->finddirs = fnl->findfiles = NULL;
    fnl->numfiles = fnl->numdirs = 0;
}
Пример #3
0
static void LoadGameList(void)
{
    for (size_t i = 0; i < ARRAY_SIZE(internalgrpfiles); i++)
    {
        grpinfo_t * const fg = (grpinfo_t *)Xcalloc(1, sizeof(grpinfo_t));

        fg->name = Xstrdup(internalgrpfiles[i].name);
        fg->crcval = internalgrpfiles[i].crcval;
        fg->size = internalgrpfiles[i].size;
        fg->game = internalgrpfiles[i].game;
        fg->dependency = internalgrpfiles[i].dependency;

        if (internalgrpfiles[i].scriptname)
            fg->scriptname = dup_filename(internalgrpfiles[i].scriptname);

        if (internalgrpfiles[i].defname)
            fg->defname = dup_filename(internalgrpfiles[i].defname);

        fg->postprocessing = internalgrpfiles[i].postprocessing;

        fg->next = listgrps;
        listgrps = fg;
    }

    CACHE1D_FIND_REC * const srch = klistpath("/", "*.grpinfo", CACHE1D_FIND_FILE);

    for (CACHE1D_FIND_REC *sidx = srch; sidx; sidx = sidx->next)
        LoadList(sidx->name);

    klistfree(srch);
}
Пример #4
0
static unsigned char GetModsDirNames(GtkListStore *list)
{
    char *homedir;
    char pdir[BMAX_PATH];
    unsigned char iternumb = 0;
    CACHE1D_FIND_REC *dirs = NULL;
    GtkTreeIter iter;

    pathsearchmode = 1;

    if ((homedir = Bgethomedir()))
    {
        Bsnprintf(pdir, sizeof(pdir), "%s/" ".eduke32", homedir);
        dirs = klistpath(pdir, "*", CACHE1D_FIND_DIR);
        for (dirs=dirs; dirs != NULL; dirs=dirs->next)
        {
            if ((Bstrcmp(dirs->name, "autoload") == 0) ||
                    (Bstrcmp(dirs->name, "..") == 0) ||
                    (Bstrcmp(dirs->name, ".") == 0))
                continue;
            else
            {
                gtk_list_store_append(list, &iter);
                gtk_list_store_set(list, &iter, 0,dirs->name, -1);
                iternumb++;
            }
        }
    }

    klistfree(dirs);
    dirs = NULL;

    return iternumb;
}
Пример #5
0
static void LoadGameList(void)
{
    struct grpfile *fg;
    CACHE1D_FIND_REC *srch, *sidx;

    int32_t i;

    for (i = 0; i<NUMGRPFILES; i++)
    {
        fg = (struct grpfile *)Bcalloc(1, sizeof(struct grpfile));

        fg->name = Bstrdup(internalgrpfiles[i].name);
        fg->crcval = internalgrpfiles[i].crcval;
        fg->size = internalgrpfiles[i].size;
        fg->game = internalgrpfiles[i].game;
        fg->dependency = internalgrpfiles[i].dependency;

        if (internalgrpfiles[i].scriptname)
            fg->scriptname = dup_filename(internalgrpfiles[i].scriptname);

        if (internalgrpfiles[i].defname)
            fg->defname = dup_filename(internalgrpfiles[i].defname);

        fg->next = listgrps;
        listgrps = fg;
    }

    srch = klistpath("/", "*.grpinfo", CACHE1D_FIND_FILE);

    for (sidx = srch; sidx; sidx = sidx->next)
        LoadList(srch->name);

    klistfree(srch);
}
Пример #6
0
static inline void clearfilenames(void)
{
    klistfree(finddirs);
    finddirs = NULL;
    numdirs = 0;
}
Пример #7
0
int32_t ScanGroups(void)
{
    CACHE1D_FIND_REC *srch, *sidx;
    struct grpcache *fg, *fgg;
    struct grpfile *grp;
    char *fn;
    struct Bstat st;
#define BUFFER_SIZE (1024 * 1024 * 8)
    uint8_t *buf = (uint8_t *)Bmalloc(BUFFER_SIZE);

    if (!buf)
    {
        initprintf("Error allocating %d byte buffer to scan GRPs!\n", BUFFER_SIZE);
        return 0;
    }

    initprintf("Searching for game data...\n");

    LoadGameList();
    //LoadGroupsCache(); SB: disabled to match local

    srch = klistpath("/", "*.grp", CACHE1D_FIND_FILE);

    for (sidx = srch; sidx; sidx = sidx->next)
    {
        for (fg = grpcache; fg; fg = fg->next)
        {
            if (!Bstrcmp(fg->name, sidx->name)) break;
        }

        if (fg)
        {
            if (findfrompath(sidx->name, &fn)) continue; // failed to resolve the filename
            if (Bstat(fn, &st))
            {
                Bfree(fn);
                continue;
            } // failed to stat the file
            Bfree(fn);
            if (fg->size == st.st_size && fg->mtime == st.st_mtime)
            {
                grp = (struct grpfile *)Bcalloc(1, sizeof(struct grpfile));
                grp->name = Bstrdup(sidx->name);
                grp->crcval = fg->crcval;
                grp->size = fg->size;
                grp->next = foundgrps;
                foundgrps = grp;

                fgg = (struct grpcache *)Bcalloc(1, sizeof(struct grpcache));
                strcpy(fgg->name, fg->name);
                fgg->size = fg->size;
                fgg->mtime = fg->mtime;
                fgg->crcval = fg->crcval;
                fgg->next = usedgrpcache;
                usedgrpcache = fgg;
                continue;
            }
        }

        {
            int32_t b, fh;
            int32_t crcval;

            fh = openfrompath(sidx->name, BO_RDONLY|BO_BINARY, BS_IREAD);
            if (fh < 0) continue;
            if (Bfstat(fh, &st)) continue;

            initprintf(" Checksumming %s...", sidx->name);
            crc32init((uint32_t *)&crcval);
            do
            {
                b = read(fh, buf, BUFFER_SIZE);
                if (b > 0) crc32block((uint32_t *)&crcval, (uint8_t *)buf, b);
            }
            while (b == BUFFER_SIZE);
            crc32finish((uint32_t *)&crcval);
            close(fh);
            initprintf(" Done\n");

            grp = (struct grpfile *)Bcalloc(1, sizeof(struct grpfile));
            grp->name = Bstrdup(sidx->name);
            grp->crcval = crcval;
            grp->size = st.st_size;
            grp->next = foundgrps;
            foundgrps = grp;

            fgg = (struct grpcache *)Bcalloc(1, sizeof(struct grpcache));
            Bstrncpy(fgg->name, sidx->name, BMAX_PATH);
            fgg->size = st.st_size;
            fgg->mtime = st.st_mtime;
            fgg->crcval = crcval;
            fgg->next = usedgrpcache;
            usedgrpcache = fgg;
        }
    }

    klistfree(srch);
    FreeGroupsCache();

    for (grp = foundgrps; grp; /*grp=grp->next*/)
    {
        struct grpfile *igrp;
        for (igrp = listgrps; igrp; igrp=igrp->next)
            if (grp->crcval == igrp->crcval) break;

        if (igrp == NULL)
        {
            grp = grp->next;
            continue;
        }

        if (igrp->dependency)
        {
            struct grpfile *depgrp;

            //initprintf("found grp with dep\n");
            for (depgrp = foundgrps; depgrp; depgrp=depgrp->next)
                if (depgrp->crcval == igrp->dependency) break;

            if (depgrp == NULL || depgrp->crcval != igrp->dependency) // couldn't find dependency
            {
                //initprintf("removing %s\n", grp->name);
                RemoveGroup(igrp->crcval);
                grp = foundgrps;
                continue;
            }
        }

        if (igrp->game && !grp->game)
            grp->game = igrp->game;

        grp=grp->next;
    }

    if (usedgrpcache)
    {
        int32_t i = 0;
        FILE *fp;
        fp = fopen(GRPCACHEFILE, "wt");
        if (fp)
        {
            for (fg = usedgrpcache; fg; fg=fgg)
            {
                fgg = fg->next;
                fprintf(fp, "\"%s\" %d %d %d\n", fg->name, fg->size, fg->mtime, fg->crcval);
                Bfree(fg);
                i++;
            }
            fclose(fp);
        }
//        initprintf("Found %d recognized GRP %s.\n",i,i>1?"files":"file");

        Bfree(buf);
        return 0;
    }

    initprintf("Found no recognized game data!\n");

    Bfree(buf);
    return 0;
}