home *** CD-ROM | disk | FTP | other *** search
/ Quake++ for Quake / Quake++.iso / quake / edquake / code / pak.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-12  |  3.0 KB  |  143 lines

  1. /*EdQuake v0.50 source code
  2.   (c) Copyright 1996 Scott Mitting
  3.   email:smitting@netusa1.net
  4.   ----------------------------------
  5.   PAK.C  -  .PAK file control
  6.  
  7.   __variables:
  8.   char *quakepath;          -- path to current editing .PAK file
  9.   pak_t      pak;        -- pointer to pak file
  10.   pakentry_t pakentry;        -- pointer to current entry
  11.  
  12.   __functions:
  13.   void getname()             -- low level function
  14.   void getentry(int e)             -- selects new current entry
  15.   void export(int e, char*filename)  -- saves an entry to disk
  16.   void openpak()             -- opens a pak file
  17.   void showmenu(int showE, int curE) -- low level function for selectpak
  18.   int findfile(char *filename)       -- text search for file
  19.   ----------------------------------
  20. */
  21. #include <stdio.h>
  22. #include <malloc.h>
  23. #include <string.h>
  24. #include "pak.h"
  25. #include "svgacc.h"
  26. #include "grfx.h"
  27. #include "disk.h"
  28.  
  29. char *quakepath;
  30. pak_t      pak;
  31. pakentry_t pakentry;
  32. config_t config;
  33. char *mapfile;
  34. char *wadname;
  35. char *pakname;
  36.  
  37.  
  38. int loadconfig()
  39. {
  40.    FILE *p;
  41.    p = fopen("edquake.cfg","rb");
  42.    if (!p) return 0;
  43.    fread(mapfile,64,1,p);
  44.    fread(wadname,64,1,p);
  45.    fread(pakname,64,1,p);
  46.    fread(&config,64,1,p);
  47.    fclose(p);
  48.    return 1;
  49. }
  50.  
  51. void saveconfig()
  52. {
  53.    FILE *p;
  54.    p = fopen("edquake.cfg","wb");
  55.    if (!p) return;
  56.    fwrite(mapfile,64,1,p);
  57.    fwrite(wadname,64,1,p);
  58.    fwrite(pakname,64,1,p);
  59.    fwrite(&config,64,1,p);
  60.    fclose(p);
  61. }
  62.  
  63. void openpak()
  64. {
  65.    pak.p = fopen(pakname,"rb");
  66.    if (!pak.p) return;
  67.    fseek(pak.p,4,0);
  68.    pak.tableloc = fgetl(pak.p);
  69.    fseek(pak.p,0,2);
  70.    pak.tablelen = (ftell(pak.p) - pak.tableloc) / 64;
  71.    fseek(pak.p,0,0);
  72. }
  73.  
  74. void getname()
  75. {
  76.    int t;
  77.    for (t = 0; t < 56; t++)
  78.        pakentry.name[t] = fgetc(pak.p);
  79. }
  80.  
  81. void getentry(int e)
  82. {
  83.    fseek(pak.p, pak.tableloc + ((e-1) * 64),0);
  84.    getname();
  85.    pakentry.loc = fgetl(pak.p);
  86.    pakentry.len = fgetl(pak.p);
  87. }
  88.  
  89. void export(int e, char*filename)
  90. {
  91.    FILE *out;
  92.    long byte;
  93.    int  t;
  94.  
  95.    getentry(e);
  96.    out = fopen(filename, "wb");
  97.    if (!out) return;
  98.    fseek(pak.p, pakentry.loc, 0);
  99.    for (byte = 1; byte <= pakentry.len; byte++)
  100.        fputc(fgetc(pak.p),out);
  101.    fclose(out);
  102. }
  103.  
  104. void showmenu(int showE, int curE)
  105. {
  106.    int t,qt;
  107.    char buf[80];
  108.    qt = 40;
  109.    mousehide();
  110.    for (t = 1; t < 20; t++)
  111.    {
  112.      getentry(t + showE);
  113.      if (t != curE)
  114.      {
  115.     drwfillbox(SET, BLACK,6,qt,300,qt+14);
  116.     sprintf(buf, "%s",       pakentry.name);
  117.     drwstring(SET, WHITE,BLACK,buf,11,qt);
  118.      }
  119.      else
  120.      {
  121.     drwfillbox(SET,RED,6,qt,300,qt+14);
  122.     sprintf(buf, "%s",       pakentry.name);
  123.     drwstring(SET, YELLOW,RED,buf,11,qt);
  124.      }
  125.      qt+=14;
  126.    }
  127.    mouseshow();
  128. }
  129.  
  130. int findfile(char *filename)
  131. {
  132.    int t;
  133.    if (!pak.p) return -1;
  134.    for (t = 0; t < pak.tablelen; t++)
  135.    {
  136.       getentry(t);
  137.       if (strcmpi(filename, pakentry.name) == 0) t += 1000;
  138.    }
  139.    if (t < 1000) return -1;
  140.    t-=1001;
  141.    return t;
  142. }
  143.