*.desktop
*.DESKTOP
*.Desktop
+/test*
+*.zip
-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
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
▄▄▄█████▓ ██░ ██ ▒█████ ██▀███ ▓██ ██▓ █ ██ ███▄ ▄███▓
▓ ██▒ ▓▒▓██░ ██▒▒██▒ ██▒▓██ ▒ ██▒▒██ ██▒ ██ ▓██▒▓██▒▀█▀ ██▒
▒ ▓██░ ▒░▒██▀▀██░▒██░ ██▒▓██ ░▄█ ▒ ▒██ ██░▓██ ▒██░▓██ ▓██░
-░ ▓██▓ ░ ░▓█ ░██ ▒██ ██░▒██▀▀█▄ ░ ▐██▓░▓▓█ ░██░▒██ ▒██
+░ ▓██▓ ░ ░▓█ ░██ ▒██ ██░▒██▀▀█▄ ░ ▐██▓░▓▓█ ░██░▒██ ▒██
▒██▒ ░ ░▓█▒░██▓░ ████▓▒░░██▓ ▒██▒ ░ ██▒▓░▒▒█████▓ ▒██▒ ░██▒
▒ ░░ ▒ ░░▒░▒░ ▒░▒░▒░ ░ ▒▓ ░▒▓░ ██▒▒▒ ░▒▓▒ ▒ ▒ ░ ▒░ ░ ░
░ ▒ ░▒░ ░ ░ ▒ ▒░ ░▒ ░ ▒░▓██ ░▒░ ░░▒░ ░ ░ ░ ░ ░
- ░ ░ ░░ ░░ ░ ░ ▒ ░░ ░ ▒ ▒ ░░ ░░░ ░ ░ ░ ░
- ░ ░ ░ ░ ░ ░ ░ ░ ░ ░
- ░ ░
+ ░ ░ ░░ ░░ ░ ░ ▒ ░░ ░ ▒ ▒ ░░ ░░░ ░ ░ ░ ░
+ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░
+ ░ ░
- By Ayabusa, 2026
===== Making Thorium more at home on Linux =====
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
void *free_ctx(struct ctx *ctx) {
free(ctx->install_loc);
+ if (ctx->opti_name)
+ free(ctx->opti_name);
free(ctx);
return NULL;
}
struct ctx {
enum mode mode;
- char *install_loc;
int silent;
+ char *install_loc;
+ char *opti_name;
};
struct ctx *init_ctx(int argc, char **argv);
+#include <ctype.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#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"
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;
}
--- /dev/null
+#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;
+}
--- /dev/null
+#ifndef UNZIP_H
+#define UNZIP_H
+
+int zip_extract_to(char *zip_path, char *extract_loc);
+
+#endif