]> Nishi Git Mirror - dataworks.git/commitdiff
installer works
authornishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Fri, 14 Jun 2024 13:19:44 +0000 (13:19 +0000)
committernishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Fri, 14 Jun 2024 13:19:44 +0000 (13:19 +0000)
git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@303 d4a5a174-5a4a-5b4b-b672-37683c10d7d5

Installer/indep-base.h
Installer/indep-jp.h
Installer/install.c

index 080ab1d0bc09e5bb45191bf058c70b3a6a706e00..d3642eb0107258308a5946a494c3d90b5a62bcdc 100644 (file)
 /* -------------------------------------------------------------------------- */
 /* --- 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 <nishi@nishi.boats>\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."
index 132712c6e925ccdf4e32de34d5ad451c246a16ab..bc8aa5bd5aa2182baba4e9e96010be096bac4179 100644 (file)
 /* -------------------------------------------------------------------------- */
 /* --- 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 <nishi@nishi.boats>\n"
+#define INSTALLER_WHERE "どこにインストールしますか? "
+#define INSTALLER_ERROR "エラー"
+#define INSTALLER_ABORT "インストールを中断します。"
+#define INSTALLER_COPYING "コピー中"
+#define INSTALLER_SUCCESS "インストールに成功しました。"
index 70c7d9a23ef393a3bb9cf0401c28605f2394bd42..c45f9379f8a3da5b693f6ed9024b4785a6dee868 100644 (file)
 /* -------------------------------------------------------------------------- */
 /* --- END LICENSE --- */
 
+#include <direct.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
+#include <sys/stat.h>
 
 #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;
 }