From 4fddcb3310ba9d3dac43931e65748a2570823198 Mon Sep 17 00:00:00 2001 From: nishi Date: Fri, 14 Jun 2024 13:19:44 +0000 Subject: [PATCH] installer works git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@303 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- Installer/indep-base.h | 16 +++++- Installer/indep-jp.h | 16 +++++- Installer/install.c | 114 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+), 2 deletions(-) diff --git a/Installer/indep-base.h b/Installer/indep-base.h index 080ab1d..d3642eb 100644 --- a/Installer/indep-base.h +++ b/Installer/indep-base.h @@ -29,4 +29,18 @@ /* -------------------------------------------------------------------------- */ /* --- END LICENSE --- */ -#define INSTALLER_TITLE "Installer for DataWorks\n" +#define INSTALLER_TITLE " DataWorks Installer\n" +#define INSTALLER_LINE "\xc4" +#define INSTALLER_WELCOME \ + "Welcome to the DataWorks Installer!\n" \ + "DataWorks is a simple cross-platform DBMS written in C.\n" \ + "Code is being written to be easy to port as much as possible, and works on DOS,\n" \ + "NetBSD, Linux, Windows, and etc.\n" \ + "\n" \ + "Installation is easy - Just specify where to install.\n" \ + "Enjoy! - Nishi \n" +#define INSTALLER_WHERE "Where do you want to install to? " +#define INSTALLER_ERROR "Error" +#define INSTALLER_ABORT "Aborting the installation." +#define INSTALLER_COPYING "Copying" +#define INSTALLER_SUCCESS "Installed successfully." diff --git a/Installer/indep-jp.h b/Installer/indep-jp.h index 132712c..bc8aa5b 100644 --- a/Installer/indep-jp.h +++ b/Installer/indep-jp.h @@ -29,4 +29,18 @@ /* -------------------------------------------------------------------------- */ /* --- END LICENSE --- */ -#define INSTALLER_TITLE "DataWorksインストーラー\n" +#define INSTALLER_TITLE " DataWorksインストーラー\n" +#define INSTALLER_LINE "─" +#define INSTALLER_WELCOME \ + "DataWorksインストーラーへようこそ!\n" \ + "DataWorksはシンプルな、Cで書かれたクロスプラットフォームなDBMSです。\n" \ + "非常に移植性を重視したコードを書いており、DOS、NetBSD、Linux、Windowsなどで動作\n" \ + "します。\n" \ + "\n" \ + "インストールは単純です - インストール先を指定するだけです。\n" \ + "ぜひ楽しんで! - Nishi \n" +#define INSTALLER_WHERE "どこにインストールしますか? " +#define INSTALLER_ERROR "エラー" +#define INSTALLER_ABORT "インストールを中断します。" +#define INSTALLER_COPYING "コピー中" +#define INSTALLER_SUCCESS "インストールに成功しました。" diff --git a/Installer/install.c b/Installer/install.c index 70c7d9a..c45f937 100644 --- a/Installer/install.c +++ b/Installer/install.c @@ -29,18 +29,132 @@ /* -------------------------------------------------------------------------- */ /* --- END LICENSE --- */ +#include #include +#include #include +#include #include "indep.h" const char copyr1[] = "Copyright (C) Crabware, pnsk-lab 2024"; +char* __util_strdup(const char* a) { + char* str = malloc(strlen(a) + 1); + memcpy(str, a, strlen(a)); + str[strlen(a)] = 0; + return str; +} + +char* __util_strcat(const char* a, const char* b) { + char* str = malloc(strlen(a) + strlen(b) + 1); + memcpy(str, a, strlen(a)); + memcpy(str + strlen(a), b, strlen(b)); + str[strlen(a) + strlen(b)] = 0; + return str; +} + int main() { printf("\x1b[2J\x1b[1;1H"); fflush(stdout); printf(INSTALLER_TITLE); int i; for(i = 0; i < 80; i++) printf("-"); + fflush(stdout); printf("\x1b[2;%dH %s -\n", 80 - strlen(copyr1) - 2, copyr1); + printf("%s\n", INSTALLER_WELCOME); + printf("%s", INSTALLER_WHERE); + char cbuf[2]; + cbuf[1] = 0; + char* str = malloc(1); + str[0] = 0; +do_so: + while(1) { + if(fread(cbuf, 1, 1, stdin) <= 0) { + free(str); + return 1; + } + if(cbuf[0] == '\n') { + if(strlen(str) == 0) { + goto do_so; + } + break; + } else if(cbuf[0] != '\r') { + char* tmp = str; + str = __util_strcat(tmp, cbuf); + free(tmp); + } + } + FILE* in = fopen("extract.exe", "rb"); + struct stat s; + stat("extract.exe", &s); + if(in == NULL) { + printf("%s: ", INSTALLER_ERROR); + printf("%s\n", strerror(errno)); + printf("%s\n", INSTALLER_ABORT); + free(str); + return 1; + } + if(chdir(str) != 0) { + fclose(in); + printf("%s: ", INSTALLER_ERROR); + printf("%s\n", strerror(errno)); + printf("%s\n", INSTALLER_ABORT); + free(str); + return 1; + } else { + char* to = __util_strcat(str, "\\_extract.exe"); + FILE* out = fopen(to, "wb"); + if(out == NULL) { + fclose(in); + printf("%s: ", INSTALLER_ERROR); + printf("%s\n", strerror(errno)); + printf("%s\n", INSTALLER_ABORT); + free(str); + return 1; + } + char buf[512]; + uint64_t readalr = 0; + while(1) { + int len = fread(buf, 1, 512, in); + fwrite(buf, 1, len, out); + readalr += len; + printf("\r%s [", INSTALLER_COPYING); + int i; + for(i = 0; i < 20; i++) { + if(20 * ((double)readalr / (uint64_t)s.st_size) > i) { + printf("#"); + } else { + printf(" "); + } + } + printf("] %3.2f%%", 100 * ((double)readalr / (uint64_t)s.st_size)); + fflush(stdout); + if(feof(in)) break; + } + fclose(in); + fclose(out); + printf("\n"); + int i; + for(i = 0; to[i] != 0; i++) { + if(to[i] == ':') { + unsigned total; + if(to[0] >= 'A' && to[0] <= 'Z') { + _dos_setdrive(to[0] - 'A' + 1, &total); + } else if(to[0] >= 'a' && to[0] <= 'z') { + _dos_setdrive(to[0] - 'a' + 1, &total); + } + break; + } + } + remove("dw.exe"); + remove("dwserv.exe"); + remove("dwrcli.exe"); + system(to); + remove(to); + free(to); + printf("%s\n", INSTALLER_SUCCESS); + } + free(str); + return 0; } -- 2.43.0