From 31e3a74c32444e6d123d7b475390ed8cbb9fbfc6 Mon Sep 17 00:00:00 2001 From: Nishi Date: Tue, 8 Oct 2024 08:55:36 +0000 Subject: [PATCH] add some stuff git-svn-id: file:///raid/svn-personal/reisen/trunk@13 c77b849d-6a5c-934c-a956-7b968ca1e197 --- SFX/main.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++--- Tool/main.c | 79 +++++++++++++++++++++++++++++++++++++++++++++---- example.conf | 4 +++ 3 files changed, 157 insertions(+), 9 deletions(-) create mode 100644 example.conf diff --git a/SFX/main.c b/SFX/main.c index 0d45dbd..f718caa 100644 --- a/SFX/main.c +++ b/SFX/main.c @@ -20,6 +20,7 @@ HWND edit; HWND progress; HINSTANCE hInst; FILE* finst; +char* config; HFONT titlefont; HFONT normalfont; HFONT versionfont; @@ -33,6 +34,7 @@ char setupname[512]; char welcome[512]; BOOL change = FALSE; +BOOL dirchange = TRUE; BOOL err; HWND windows[512]; int window_count = 0; @@ -43,6 +45,7 @@ struct entry { char* name; uint32_t size; BOOL dir; + BOOL skip; }; struct entry entries[2048]; @@ -116,7 +119,11 @@ void ExtractProc(void* arg){ sprintf(destpath, "%s%s", instpath, entries[i].name); retry: fseek(finst, strlen(entries[i].name), SEEK_CUR); - if(entries[i].dir){ + if(entries[i].skip){ + fseek(finst, entries[i].size, SEEK_CUR); + fseek(finst, 4, SEEK_CUR); + fseek(finst, 1, SEEK_CUR); + }else if(entries[i].dir){ fseek(finst, 4, SEEK_CUR); fseek(finst, 1, SEEK_CUR); CreateDirectory(destpath, NULL); @@ -243,7 +250,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { if(gphase == PHASE_DIR){ SendMessage(edit, WM_GETTEXT, MAX_PATH, (LPARAM)instpath); } - gphase++; + if(gphase == PHASE_WELCOME){ + if(dirchange){ + gphase++; + }else{ + gphase += 2; + } + }else{ + gphase++; + } RenderPhase(gphase, hWnd); RedrawWindow(hWnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE); } @@ -409,6 +424,7 @@ int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst, LPSTR lpsCmdLine, in uint32_t entbytes; uint32_t incr; BOOL first = TRUE; + config = NULL; instpath[0] = 'C'; instpath[1] = ':'; instpath[2] = '\\'; @@ -450,7 +466,7 @@ loop: entbytes |= n; } fflush(stdout); - if(attr & 1){ + if(attr == 1){ fseek(finst, -4-entbytes-1, SEEK_CUR); fread(&fnlen, 1, 1, finst); fseek(finst, -1-fnlen, SEEK_CUR); @@ -466,6 +482,7 @@ loop: }else{ int i; entries[counts - incr - 1].dir = FALSE; + entries[counts - incr - 1].skip = FALSE; entries[counts - incr - 1].name = fnnam; entries[counts - incr - 1].size = entbytes; for(i = 0; fnnam[i] != 0; i++){ @@ -473,7 +490,7 @@ loop: } incr++; } - }else{ + }else if(attr == 0){ fnnam = malloc(entbytes + 1); fnnam[entbytes] = 0; fseek(finst, -4-entbytes, SEEK_CUR); @@ -485,12 +502,29 @@ loop: free(fnnam); }else{ entries[counts - incr - 1].dir = TRUE; + entries[counts - incr - 1].skip = FALSE; entries[counts - incr - 1].name = fnnam; for(i = 0; fnnam[i] != 0; i++){ if(fnnam[i] == '/') fnnam[i] = '\\'; } incr++; } + }else if(attr == 2){ + config = malloc(entbytes + 1); + config[entbytes] = 0; + fseek(finst, -4-entbytes, SEEK_CUR); + fread(config, 1, entbytes, finst); + fseek(finst, -entbytes, SEEK_CUR); + bytes -= entbytes + 4 + 1; + + if(first){ + free(config); + }else{ + entries[counts - incr - 1].skip = TRUE; + entries[counts - incr - 1].size = entbytes; + entries[counts - incr - 1].name = ""; + incr++; + } } if(first){ counts++; @@ -503,6 +537,47 @@ loop: goto loop; } + if(config != NULL){ + int i; + int incr = 0; + for(i = 0;; i++){ + if(config[i] == '\n' || config[i] == 0){ + char oldc = config[i]; + char* line = config + incr; + config[i] = 0; + + if(strlen(line) > 0 && line[0] != '#'){ + int j; + for(j = 0;; j++){ + if(line[j] == ' ' || line[j] == '\t' || line[j] == 0){ + BOOL hasarg = line[j] != 0; + char* arg = NULL; + char oldc2 = line[j]; + line[j] = 0; + if(hasarg){ + j++; + for(; line[j] != 0 && (line[j] == '\t' || line[j] == ' '); j++); + arg = line + j; + } + if(strcmp(line, "DefaultDirectory") == 0 && hasarg){ + strcpy(instpath, arg); + instpath[strlen(arg)] = 0; + }else if(strcmp(line, "DirectoryUnchangable") == 0){ + dirchange = FALSE; + } + line[j] = oldc2; + break; + } + } + } + + config[i] = oldc; + incr = i + 1; + if(oldc == 0) break; + } + } + } + strcpy(setupname, name); strcpy(setupname + strlen(name), " Setup"); setupname[strlen(name) + 6] = 0; diff --git a/Tool/main.c b/Tool/main.c index 9cd4c4d..5fd2ed9 100644 --- a/Tool/main.c +++ b/Tool/main.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -17,6 +18,8 @@ const char* projname; #define COMPRESS 65535 +int scan(FILE* f, const char* base, const char* pref); + FILE* prepare_file(const char* path){ FILE* f = fopen(path, "wb"); if(f != NULL){ @@ -25,6 +28,42 @@ FILE* prepare_file(const char* path){ return f; } +void read_config(FILE* f, char* config){ + int i; + int incr = 0; + for(i = 0;; i++){ + if(config[i] == '\n' || config[i] == 0){ + char oldc = config[i]; + char* line = config + incr; + config[i] = 0; + + if(strlen(line) > 0 && line[0] != '#'){ + int j; + for(j = 0;; j++){ + if(line[j] == ' ' || line[j] == '\t' || line[j] == 0){ + bool hasarg = line[j] != 0; + char* arg = NULL; + line[j] = 0; + if(hasarg){ + j++; + for(; line[j] != 0 && (line[j] == '\t' || line[j] == ' '); j++); + arg = line + j; + } + if(strcmp(line, "Include") == 0 && hasarg){ + scan(f, arg, ""); + } + break; + } + } + } + + config[i] = oldc; + incr = i + 1; + if(oldc == 0) break; + } + } +} + int scan(FILE* f, const char* base, const char* pref){ DIR* dir = opendir(base); if(dir != NULL){ @@ -189,11 +228,41 @@ int main(int argc, char** argv){ fprintf(stderr, "Failed to create one\n"); return 1; } - if(scan(f, input, "") != 0){ - fprintf(stderr, "Failed to process\n"); - fclose(f); - remove(output); - return 1; + if(input[0] == '@'){ + struct stat s; + if(stat(input + 1, &s) == 0){ + uint8_t byt; + uint32_t written = s.st_size; + char* buf; + FILE* fin = fopen(input + 1, "r"); + buf = malloc(s.st_size + 1); + buf[s.st_size] = 0; + fread(buf, 1, s.st_size, fin); + fwrite(buf, 1, s.st_size, f); + + fclose(fin); + for(i = 0; i < 4; i++){ + byt = (written & 0xff000000) >> 24; + written = written << 8; + fwrite(&byt, 1, 1, f); + } + byt = 2; + fwrite(&byt, 1, 1, f); + total += s.st_size + 4 + 1; + + read_config(f, buf); + }else{ + fprintf(stderr, "Failed to process\n"); + remove(output); + return 1; + } + }else{ + if(scan(f, input, "") != 0){ + fprintf(stderr, "Failed to process\n"); + fclose(f); + remove(output); + return 1; + } } printf("Total: %lu bytes\n", (unsigned long)total); strcpy(name, projname); diff --git a/example.conf b/example.conf new file mode 100644 index 0000000..664289a --- /dev/null +++ b/example.conf @@ -0,0 +1,4 @@ +# $Id$ +Include /home/nishi/Downloads/zlib-1.3.1 +DefaultDirectory C:\ZLib +DirectoryUnchangable -- 2.43.0