⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 install.c

📁 SEAL是DOS 下的32位保护模式的GUI程序
💻 C
字号:
/* SEAL installer 2.0 (c) 2000,2001 Kostas Michalopoulos aka Bad Sector */
#include <conio.h>
#include <process.h>
#include <unistd.h>
#include <dir.h>
#include <dos.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>

#include "scrpages.h"
#include "cmdparse.h"

#define CMD_NEXT 10
#define CMD_QUIT 20

char    *title_bar;
char    *line[5];
char    *binaries, *sources;
char    *binfiles, *srcfiles;
char    *success;

/* BAR commands (for UnBARring) */
#define CMD_INFO        0
#define CMD_COMMENT     1
#define CMD_STATUS      2
#define CMD_CREATEFILE  100
#define CMD_CREATEDIR   101
#define CMD_CLOSEDIR    102
#define CMD_FINISH      255

typedef struct t_barhead
{
  unsigned char ID[3];
  unsigned char version;
} t_barhead;

char *path;
char *spath;
p_page first, pitems, ppath, punbar;
int topic, fin;

void unbar_file(FILE *f)
{
  t_barhead hd;
  if (!f) return;
  fread(&hd, 1, sizeof(hd), f);
  #define READ_PARAMETER {                                      \
    unsigned short len;                                         \
    fread(&len, 1, 2, f);                                       \
    parameter = (char *) malloc(len+1);                         \
    fread(parameter, 1, len, f);                                \
    parameter[len] = 0;                                         \
  };
  punbar->item[1].y2 = filelength(fileno(f));
  while (!feof(f)) {
    unsigned char cmd;
    char *parameter;
    fread(&cmd, 1, 1, f);

    if (cmd == CMD_FINISH) {
      printf("Finished.\n");
      break;
    };
    switch (cmd) {
      case CMD_INFO: {    // parameter contains a line of information.
        READ_PARAMETER;   // Current BARs says only information about the
        free(parameter);  // program that was used to make them.
      }; break;
      case CMD_COMMENT: { // parameter contains a line of comments. Each line
        READ_PARAMETER;   // can have sub-lines, separated with the character
        free(parameter);  // 0xD (13 - '\r'). Current BARs doesn't use this.
      }; break;
      case CMD_STATUS: {  // parameter contains the text that should be
        READ_PARAMETER;   // displayed in the status line (if any)
        free(punbar->item[3].data);
        punbar->item[3].data = (void *) strdup(parameter);
        draw_page_item(punbar, 3);
        free(parameter);
      }; break;
      case CMD_CREATEFILE: {
        unsigned char attrib;
        unsigned short time, date;
        unsigned long size, toread, read = 0;
        struct ftime stime;
        FILE *ouf;

        READ_PARAMETER;
        fread(&attrib, 1, 1, f);
        fread(&time, 1, 2, f);
        fread(&date, 1, 2, f);
        fread(&size, 1, 4, f);

        stime.ft_tsec  = (time & 0x1F);
        stime.ft_min   = (time >> 5) & 0x3F;
        stime.ft_hour  = (time >> 11) & 0x1F;
        stime.ft_day   = (date & 0x1F);
        stime.ft_month = (date >> 5) & 0x0F;
        stime.ft_year  = ((date >> 9) & 0x7F);

        free(punbar->item[2].data);
        punbar->item[2].data = malloc(strlen(parameter)+28);
        strcpy(punbar->item[2].data, "Extracting ");
        strcat(punbar->item[2].data, parameter);
        strcat(punbar->item[2].data, "...            ");
        draw_page_item(punbar, 2);
        ouf = fopen(parameter, "wb+");
        while (1) {
          char buff[16384];
          toread = 16384;
          if (read+toread > size) toread = size-read;
          fread(&buff, 1, toread, f);
          fwrite(&buff, 1, toread, ouf);
          read += toread;
          punbar->item[1].index = ftell(f);
          draw_page_item(punbar, 1);
          if (read == size) break;
        };
        fclose(ouf);
        ouf = fopen(parameter, "rb");
        setftime(fileno(ouf), &stime);
        fclose(ouf);

        free(parameter);
      }; break;
      case CMD_CREATEDIR: {
        READ_PARAMETER;
        mkdir(parameter, S_IWUSR);
        chdir(parameter);
        free(parameter);
      }; break;
      case CMD_CLOSEDIR: {
        chdir("..");
      }; break;
      default: {
      }; break;
    };
    punbar->item[1].index = ftell(f);
    draw_page_item(punbar, 1);
  };
}

void install_seal()
{
  FILE *f1, *f2;

  mkdir(path, S_IWUSR);
  mkdir(spath, S_IWUSR);
  f1 = fopen(get_list_item(pitems->item[3].index, binfiles), "rb+");
  f2 = fopen(get_list_item(pitems->item[4].index, srcfiles), "rb+");
  chdir(path);
  unbar_file(f1);
  chdir(spath);
  unbar_file(f2);
  if (f1) fclose(f1);
  if (f2) fclose(f2);

  fin = 1;
  punbar->terminate = 1;

  chdir(path);
}

void help(p_page p)
{
  window(22, 9, 80, 25);
  textcolor(0);
  textbackground(7);
  cprintf("赏屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -