]> git.ayabusa.dev Git - thoryum.git/commitdiff
Added a unzip using libzip
authorAyabusa <lebgpub@gmail.com>
Tue, 9 Jun 2026 17:23:09 +0000 (19:23 +0200)
committerAyabusa <lebgpub@gmail.com>
Tue, 9 Jun 2026 17:23:09 +0000 (19:23 +0200)
.gitignore
Makefile
README.txt
src/cli.c
src/cli.h
src/main.c
src/unzip.c [new file with mode: 0644]
src/unzip.h [new file with mode: 0644]

index e76cd0c3d0bbab70586b1cec148a6d7f159bbb47..a3e02865c06a5ac33c1d20d3529497c0e700489d 100644 (file)
@@ -5,3 +5,5 @@
 *.desktop
 *.DESKTOP
 *.Desktop
+/test*
+*.zip
index 9faa0d09ca9792a2303e0760d5f187f58ca95a37..9336d74c16e52c338074fcc23026e688e1258938 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
-CFLAGS = -Wall -Wextra -g
-LIBS = -lcurl
-SRC = src/main.c src/cpu.c src/downloader.c src/cli.c
-OBJ = build/main.o build/cpu.o build/downloader.o build/cli.o
+CFLAGS = -Wall -Wextra -g -fsanitize=address
+LIBS = -lcurl -lzip
+SRC = src/main.c src/cpu.c src/downloader.c src/cli.c src/unzip.c
+OBJ = build/main.o build/cpu.o build/downloader.o build/cli.o build/unzip.o
 RES = build/Thoryum
 
 all: setup $(OBJ) build
@@ -19,6 +19,9 @@ build/downloader.o: src/downloader.c
 build/cli.o: src/cli.c
        $(CC) $(CFLAGS) -c $^ -o $@ $(LIBS)
 
+build/unzip.o: src/unzip.c
+       $(CC) $(CFLAGS) -c $^ -o $@ $(LIBS)
+
 setup:
        mkdir -p build
 
index c5ec1baba78171d1e422692381eb911cf3f5750d..1565b8a0b0a3150aeb528941701a8b577288ccfe 100644 (file)
@@ -3,13 +3,13 @@
 ▄▄▄█████▓ ██░ ██  ▒█████   ██▀███ ▓██   ██▓ █    ██  ███▄ ▄███▓
 ▓  ██▒ ▓▒▓██░ ██▒▒██▒  ██▒▓██ ▒ ██▒▒██  ██▒ ██  ▓██▒▓██▒▀█▀ ██▒
 ▒ ▓██░ ▒░▒██▀▀██░▒██░  ██▒▓██ ░▄█ ▒ ▒██ ██░▓██  ▒██░▓██    ▓██░
-░ ▓██▓ ░ ░▓█ ░██ ▒██   ██░▒██▀▀█▄   ░ ▐██▓░▓▓█  ░██░▒██    ▒██ 
+░ ▓██▓ ░ ░▓█ ░██ ▒██   ██░▒██▀▀█▄   ░ ▐██▓░▓▓█  ░██░▒██    ▒██
   ▒██▒ ░ ░▓█▒░██▓░ ████▓▒░░██▓ ▒██▒ ░ ██▒▓░▒▒█████▓ ▒██▒   ░██▒
   ▒ ░░    ▒ ░░▒░▒░ ▒░▒░▒░ ░ ▒▓ ░▒▓░  ██▒▒▒ ░▒▓▒ ▒ ▒ ░ ▒░   ░  ░
     ░     ▒ ░▒░ ░  ░ ▒ ▒░   ░▒ ░ ▒░▓██ ░▒░ ░░▒░ ░ ░ ░  ░      ░
-  ░       ░  ░░ ░░ ░ ░ ▒    ░░   ░ ▒ ▒ ░░   ░░░ ░ ░ ░      ░   
-          ░  ░  ░    ░ ░     ░     ░ ░        ░            ░   
-                                   ░ ░                         
+  ░       ░  ░░ ░░ ░ ░ ▒    ░░   ░ ▒ ▒ ░░   ░░░ ░ ░ ░      ░
+          ░  ░  ░    ░ ░     ░     ░ ░        ░            ░
+                                   ░ ░
                                              - By Ayabusa, 2026
 
 ===== Making Thorium more at home on Linux =====
@@ -38,6 +38,7 @@ out of the box experience and an update wrapper.
 First you'll need to install the following libs:
 - Standart lib, should work with glibc or musl
 - Libcurl, to download from da web
+- Libzip, to extract some shit
 
 TODO : write some shit about using it
 
index 5643c76ca000dc7a5f47218d4be32b778eb30db3..0e4803b31a13800d9b5469d1394acc45e07d5267 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -46,6 +46,8 @@ struct ctx *init_ctx(int argc, char **argv) {
 
 void *free_ctx(struct ctx *ctx) {
     free(ctx->install_loc);
+    if (ctx->opti_name)
+        free(ctx->opti_name);
     free(ctx);
     return NULL;
 }
index 8a36ff2c748076627c019ee8ed6bb9dee7ec12b6..858b0902289e918951afdd513bb01b8a27cb11d4 100644 (file)
--- a/src/cli.h
+++ b/src/cli.h
@@ -8,8 +8,9 @@ enum mode {
 
 struct ctx {
     enum mode mode;
-    char *install_loc;
     int silent;
+    char *install_loc;
+    char *opti_name;
 };
 
 struct ctx *init_ctx(int argc, char **argv);
index 42bf73c6fb6ee86f9fe50ef73144de7f7c99bd9e..dcaf5fd17dcb4d8c50a1a9cfd3498f499262110f 100644 (file)
@@ -1,3 +1,4 @@
+#include <ctype.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <string.h>
@@ -7,6 +8,7 @@
 #include "cpu.h"
 #include "downloader.h"
 #include "cli.h"
+#include "unzip.h"
 
 #define SED_PATCH "s/WMClass=thorium/WMClass=thorium-browser/g"
 #define DESKTOP_FILE "thorium-portable.desktop"
@@ -34,20 +36,57 @@ void patch_desktop_file(char *install_loc) {
     wait(NULL);
 }
 
+void install(struct ctx *ctx) {
+    char *suffix = calloc(10, 1);
+    strcpy(suffix, ctx->opti_name);
+    strcat(suffix, ".zip");
+    char *url = DL_get_latest_version_url(suffix);
+    printf("Downloading the latest Thorium release from :\n%s\n", url);
+    free(suffix);
+}
+
+void update(struct ctx *ctx) {
+    //TODO
+}
+
 int main(int argc, char **argv) {
-       printf("Hello this is Thoryum ;)\n");
-       enum CPU_opti opti = CPU_fetch_opti();
-       char opti_name[5] = {0};
-       CPU_opti_name(opti_name, opti);
-       printf("You are using the CPU : '%s'\n", opti_name);
-       /*
-       FILE *file = fopen("page.out", "w");
-       DL_get_file("https://ayabusa.dev", file);
-       fclose(file);
-       */
-       //printf("Latest version url : '%s,'\n",DL_get_latest_version_url("AVX.zip"));
-       //patch_desktop_file(".");
-       struct ctx *ctx = init_ctx(argc, argv);
-       print_ctx(ctx);
-       ctx = free_ctx(ctx);
+
+    zip_extract_to("thorium.zip", "test");
+    return 0;
+
+    /*
+        FILE *file = fopen("page.out", "w");
+        DL_get_file("https://ayabusa.dev", file);
+        fclose(file);
+        */
+    //printf("Latest version url : '%s,'\n",DL_get_latest_version_url("AVX.zip"));
+    //patch_desktop_file(".");
+    struct ctx *ctx = init_ctx(argc, argv);
+    print_ctx(ctx);
+    ctx = free_ctx(ctx);
+
+    // We get da CPU shit
+    enum CPU_opti opti = CPU_fetch_opti();
+    char opti_name[5] = {0};
+    CPU_opti_name(opti_name, opti);
+    printf("Detected CPU opti : '%s'\n", opti_name);
+    ctx->opti_name = strdup(opti_name);
+
+    if (!ctx->silent) {
+        printf("Are you sure you want to procede with the installation of Thorium ? [y/n] ");
+        char response;
+        scanf("%c", &response);
+        if (toupper(response) != 'Y') {
+            printf("Aborting.\n");
+            exit(EXIT_FAILURE);
+        }
+        printf("Okkkkk lets go.\n");
+    }
+
+    if (ctx->mode == NORMAL)
+        install(ctx);
+    else
+        update(ctx);
+
+    return 0;
 }
diff --git a/src/unzip.c b/src/unzip.c
new file mode 100644 (file)
index 0000000..c0a30f7
--- /dev/null
@@ -0,0 +1,77 @@
+#include <stddef.h>
+#include <stdio.h>
+#include <zip.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include "unzip.h"
+
+// Thank gosh I found this ref : https://gist.github.com/mobius/1759816
+
+static void safe_create_dir(const char *dir)
+{
+    if (mkdir(dir, 0755) < 0) {
+        if (errno != EEXIST) {
+            perror(dir);
+            exit(1);
+        }
+    }
+}
+
+int zip_extract_to(char *zip_path, char *extract_loc) {
+    struct zip *za;
+    int err;
+    char buf[100];
+
+    extract_loc = strdup(extract_loc);
+    int extract_loc_len =  strlen(extract_loc);
+    if (extract_loc[extract_loc_len - 1] != '/') {
+        extract_loc = realloc(extract_loc, extract_loc_len + 2);
+        extract_loc[extract_loc_len] = '/';
+        extract_loc[extract_loc_len + 1] = '\0';
+    }
+
+    if ((za = zip_open(zip_path, 0, &err)) == NULL) {
+        zip_error_to_str(buf, sizeof(buf), err, errno);
+        fprintf(stderr, "Failed to open zip archive `%s': %s\n", zip_path, buf);
+        return 1;
+    }
+
+    for (int i = 0; i < zip_get_num_entries(za, 0); i++) {
+        zip_stat_t sb;
+        if (!zip_stat_index(za, i, 0, &sb)) {
+            int len = strlen(sb.name);
+
+            char *name = calloc(1, extract_loc_len + len + 2);
+            strcpy(name, extract_loc);
+            strcat(name, sb.name);
+
+            len = strlen(name);
+
+            if (name[len - 1] == '/')
+                safe_create_dir(name);
+            else {
+                struct zip_file *zf = zip_fopen_index(za, i, 0);
+
+                int fd = open(name, O_RDWR | O_TRUNC | O_CREAT, 0644);
+
+                long long sum = 0;
+                while (sum != sb.size) {
+                    len = zip_fread(zf, buf, 100);
+                    write(fd, buf, len);
+                    sum += len;
+                }
+                close(fd);
+                zip_fclose(zf);
+            }
+            free(name);
+        } else {
+            printf("Oopsie, Iv got some error while extracting the file %s\n", __FILE__);
+        }
+    }
+    free(extract_loc);
+    return zip_close(za) != 0;
+}
diff --git a/src/unzip.h b/src/unzip.h
new file mode 100644 (file)
index 0000000..b040df5
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef UNZIP_H
+#define UNZIP_H
+
+int zip_extract_to(char *zip_path, char *extract_loc);
+
+#endif