Subversion Repositories eduke32

Rev

Rev 5061 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5061 Rev 5064
Line 33... Line 33...
33
# include <shellapi.h>
33
# include <shellapi.h>
34
#endif
34
#endif
35
#include "cache1d.h"
35
#include "cache1d.h"
36
#include "pragmas.h"
36
#include "pragmas.h"
37
#include "baselayer.h"
37
#include "baselayer.h"
-
 
38
#include "crc32.h"
38
39
39
#ifdef WITHKPLIB
40
#ifdef WITHKPLIB
40
#include "kplib.h"
41
#include "kplib.h"
41
42
42
char *kpzbuf = NULL;
43
char *kpzbuf = NULL;
Line 663... Line 664...
663
static intptr_t groupfil[MAXGROUPFILES] = {-1,-1,-1,-1,-1,-1,-1,-1};
664
static intptr_t groupfil[MAXGROUPFILES] = {-1,-1,-1,-1,-1,-1,-1,-1};
664
static int32_t groupfilpos[MAXGROUPFILES];
665
static int32_t groupfilpos[MAXGROUPFILES];
665
static uint8_t groupfilgrp[MAXGROUPFILES];
666
static uint8_t groupfilgrp[MAXGROUPFILES];
666
static char *gfilelist[MAXGROUPFILES];
667
static char *gfilelist[MAXGROUPFILES];
667
static int32_t *gfileoffs[MAXGROUPFILES];
668
static int32_t *gfileoffs[MAXGROUPFILES];
-
 
669
static int32_t groupcrc[MAXGROUPFILES];
668
670
669
static uint8_t filegrp[MAXOPENFILES];
671
static uint8_t filegrp[MAXOPENFILES];
670
static int32_t filepos[MAXOPENFILES];
672
static int32_t filepos[MAXOPENFILES];
671
static intptr_t filehan[MAXOPENFILES] =
673
static intptr_t filehan[MAXOPENFILES] =
672
{
674
{
Line 689... Line 691...
689
static int32_t kopen_internal(const char *filename, char **lastpfn, char searchfirst, char checkcase, char tryzip, int32_t newhandle, uint8_t *arraygrp, intptr_t *arrayhan, int32_t *arraypos);
691
static int32_t kopen_internal(const char *filename, char **lastpfn, char searchfirst, char checkcase, char tryzip, int32_t newhandle, uint8_t *arraygrp, intptr_t *arrayhan, int32_t *arraypos);
690
static int32_t kread_grp(int32_t handle, void *buffer, int32_t leng);
692
static int32_t kread_grp(int32_t handle, void *buffer, int32_t leng);
691
static int32_t klseek_grp(int32_t handle, int32_t offset, int32_t whence);
693
static int32_t klseek_grp(int32_t handle, int32_t offset, int32_t whence);
692
static void kclose_grp(int32_t handle);
694
static void kclose_grp(int32_t handle);
693
695
-
 
696
static void initgroupfile_crc32(int32_t handle)
-
 
697
{
-
 
698
    int32_t b, crcval = 0;
-
 
699
#define BUFFER_SIZE (1024 * 1024 * 8)
-
 
700
    uint8_t *buf = (uint8_t *)Xmalloc(BUFFER_SIZE);
-
 
701
    klseek_grp(handle, 0, BSEEK_SET);
-
 
702
-
 
703
    do
-
 
704
    {
-
 
705
        b = kread_grp(handle, buf, BUFFER_SIZE);
-
 
706
        if (b > 0) crcval = Bcrc32((uint8_t *)buf, b, crcval);
-
 
707
    }
-
 
708
    while (b == BUFFER_SIZE);
-
 
709
-
 
710
    groupcrc[handle] = crcval;
-
 
711
    klseek_grp(handle, 0, BSEEK_SET);
-
 
712
    Bfree(buf);
-
 
713
}
-
 
714
694
int32_t initgroupfile(const char *filename)
715
int32_t initgroupfile(const char *filename)
695
{
716
{
696
    char buf[70];
717
    char buf[70];
697
718
698
    // translate all backslashes (0x5c) to forward slashes (0x2f)
719
    // translate all backslashes (0x5c) to forward slashes (0x2f)
Line 751... Line 772...
751
            gfilelist[numgroupfiles][(i<<4)+12] = 0;
772
            gfilelist[numgroupfiles][(i<<4)+12] = 0;
752
            gfileoffs[numgroupfiles][i] = j;
773
            gfileoffs[numgroupfiles][i] = j;
753
            j += k;
774
            j += k;
754
        }
775
        }
755
        gfileoffs[numgroupfiles][gnumfiles[numgroupfiles]] = j;
776
        gfileoffs[numgroupfiles][gnumfiles[numgroupfiles]] = j;
-
 
777
        initgroupfile_crc32(numgroupfiles);
756
        numgroupfiles++;
778
        numgroupfiles++;
757
        return 0;
779
        return 0;
758
    }
780
    }
759
    klseek_grp(numgroupfiles, 0, BSEEK_SET);
781
    klseek_grp(numgroupfiles, 0, BSEEK_SET);
760
782
Line 854... Line 876...
854
876
855
            // skip unknown data
877
            // skip unknown data
856
            klseek_grp(numgroupfiles, 104, BSEEK_CUR);
878
            klseek_grp(numgroupfiles, 104, BSEEK_CUR);
857
        }
879
        }
858
        gfileoffs[numgroupfiles][gnumfiles[numgroupfiles]] = j;
880
        gfileoffs[numgroupfiles][gnumfiles[numgroupfiles]] = j;
-
 
881
        initgroupfile_crc32(numgroupfiles);
859
        numgroupfiles++;
882
        numgroupfiles++;
860
        return 0;
883
        return 0;
861
    }
884
    }
862
885
863
    kclose_grp(numgroupfiles);
886
    kclose_grp(numgroupfiles);
Line 1037... Line 1060...
1037
    }
1060
    }
1038
1061
1039
    return -1;
1062
    return -1;
1040
}
1063
}
1041
1064
1042
void krename(const char *filename, const char *newname)
1065
void krename(int32_t crcval, int32_t filenum, const char *newname)
1043
{
-
 
1044
    int32_t i, j, k;
-
 
1045
    char bad, *gfileptr;
-
 
1046
-
 
1047
    for (k=numgroupfiles-1; k>=0; k--)
-
 
1048
    {
-
 
1049
        if (groupfil[k] >= 0)
-
 
1050
        {
-
 
1051
            for (i=gnumfiles[k]-1; i>=0; i--)
-
 
1052
            {
1066
{
1053
                gfileptr = (char *)&gfilelist[k][i<<4];
-
 
1054
-
 
1055
                bad = 0;
-
 
1056
                for (j=0; j<13; j++)
1067
    for (int32_t k=numgroupfiles-1; k>=0; k--)
1057
                {
1068
    {
1058
                    if (!filename[j]) break;
1069
        if (groupfil[k] >= 0 && groupcrc[k] == crcval)
1059
                    if (toupperlookup[filename[j]] != toupperlookup[gfileptr[j]])
-
 
1060
                    {
1070
        {
1061
                        bad = 1;
-
 
1062
                        break;
-
 
1063
                    }
-
 
1064
                }
-
 
1065
                if (bad) continue;
-
 
1066
                if (j<13 && gfileptr[j]) continue;   // JBF: because e1l1.map might exist before e1l1
-
 
1067
                if (j==13 && filename[j]) continue;   // JBF: long file name
-
 
1068
-
 
1069
                Bstrncpy(gfileptr, newname, 12);
1071
            Bstrncpy((char *)&gfilelist[k][filenum<<4], newname, 12);
1070
                return;
1072
            return;
1071
            }
1073
        }
1072
        }
1074
    }
1073
    }
1075
}
1074
}
-
 
1075
1076
1076
int32_t kopen4load(const char *filename, char searchfirst)
1077
int32_t kopen4load(const char *filename, char searchfirst)
1077
{
1078
{
1078
    int32_t newhandle = MAXOPENFILES-1;
1079
    int32_t newhandle = MAXOPENFILES-1;
1079
1080