From 1e017d81b7b5e99f1abf411821ed0403d80a8851 Mon Sep 17 00:00:00 2001 From: Laan Tungir Date: Sat, 17 Jan 2026 07:39:23 -0400 Subject: [PATCH] Fixing user interface problems --- Makefile | 12 +++++------ build.sh | 23 +++++++++++++++++++-- src/archive.c | 4 ++-- src/state.c | 17 +++++++++++++++- src/ui.c | 56 +++++++++++++++++++++++++++++---------------------- src/util.c | 12 +++++++++++ 6 files changed, 89 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index c206e65..3e8a14e 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,13 @@ CC = gcc -CFLAGS = -Wall -Wextra -std=c99 -Isrc -Isrc/miniz -Isrc/microtar -CFLAGS_MINIZ = -Wall -Wextra -std=c99 -D_POSIX_C_SOURCE=200112L -Isrc -Isrc/miniz -Isrc/microtar -Wno-unused-function -Wno-implicit-function-declaration +CFLAGS = -Wall -Wextra -std=c99 -Isrc -Iminiz -Imicrotar/src +CFLAGS_MINIZ = -Wall -Wextra -std=c99 -D_POSIX_C_SOURCE=200112L -Isrc -Iminiz -Imicrotar/src -Wno-unused-function -Wno-implicit-function-declaration LIBS = -lm LIBS_STATIC = -static -lm ARCH = $(shell uname -m) TARGET = build/otp-$(ARCH) SOURCES = $(wildcard src/*.c) -MINIZ_SOURCES = $(wildcard src/miniz/*.c) -MICROTAR_SOURCES = $(wildcard src/microtar/*.c) +MINIZ_SOURCES = $(wildcard miniz/*.c) +MICROTAR_SOURCES = $(wildcard microtar/src/*.c) OBJS = $(SOURCES:.c=.o) MINIZ_OBJS = $(MINIZ_SOURCES:.c=.o) MICROTAR_OBJS = $(MICROTAR_SOURCES:.c=.o) @@ -30,11 +30,11 @@ src/%.o: src/%.c $(CC) $(CFLAGS) -c $< -o $@ # Compile miniz library files with reduced warnings -src/miniz/%.o: src/miniz/%.c +miniz/%.o: miniz/%.c $(CC) $(CFLAGS_MINIZ) -c $< -o $@ # Compile microtar library files normally -src/microtar/%.o: src/microtar/%.c +microtar/src/%.o: microtar/src/%.c $(CC) $(CFLAGS) -c $< -o $@ clean: diff --git a/build.sh b/build.sh index 190def4..95e3fdd 100755 --- a/build.sh +++ b/build.sh @@ -346,10 +346,29 @@ clean_project() { } install_project() { - print_status "Installing OTP project..." + print_status "Building project before installation..." + + # Build the project first (without version increment for install) + print_status "Cleaning previous build..." + make clean + + print_status "Building OTP project for x86_64..." + make CC=gcc ARCH=x86_64 + if [ $? -ne 0 ]; then + print_error "Build failed" + return 1 + fi + print_success "Build completed successfully" + + # Clean up object files after successful build + print_status "Cleaning up object files..." + rm -f src/*.o miniz/*.o microtar/src/*.o + + # Now install + print_status "Installing OTP project to system..." make install if [ $? -eq 0 ]; then - print_success "Installation completed" + print_success "Installation completed - binary installed to /usr/local/bin/otp" else print_error "Installation failed" return 1 diff --git a/src/archive.c b/src/archive.c index 3afa19c..0c74d8b 100644 --- a/src/archive.c +++ b/src/archive.c @@ -10,12 +10,12 @@ #include #include #include "main.h" -#include "microtar/microtar.h" +#include "microtar.h" // Suppress warnings from miniz header #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" -#include "miniz/miniz.h" +#include "miniz.h" #pragma GCC diagnostic pop //////////////////////////////////////////////////////////////////////////////// diff --git a/src/state.c b/src/state.c index 3adb54d..fb36fcc 100644 --- a/src/state.c +++ b/src/state.c @@ -1,10 +1,12 @@ #include #include +#include #include "main.h" // Global state variables -static char current_pads_dir[512] = DEFAULT_PADS_DIR; +static char current_pads_dir[512] = ""; static int is_interactive_mode = 0; +static int pads_dir_initialized = 0; // Terminal dimensions (moved from ui.c to state.c for global access) static int terminal_width = 80; // Default fallback width @@ -13,6 +15,18 @@ static int terminal_height = 24; // Default fallback height // Getters and setters for global state const char* get_current_pads_dir(void) { + // Initialize pads directory on first access if not already set + if (!pads_dir_initialized && strlen(current_pads_dir) == 0) { + char* home_dir = getenv("HOME"); + if (home_dir) { + snprintf(current_pads_dir, sizeof(current_pads_dir), "%s/.otp/pads", home_dir); + } else { + // Fallback to relative path if HOME is not set + strncpy(current_pads_dir, DEFAULT_PADS_DIR, sizeof(current_pads_dir) - 1); + } + current_pads_dir[sizeof(current_pads_dir) - 1] = '\0'; + pads_dir_initialized = 1; + } return current_pads_dir; } @@ -20,6 +34,7 @@ void set_current_pads_dir(const char* dir) { if (dir) { strncpy(current_pads_dir, dir, sizeof(current_pads_dir) - 1); current_pads_dir[sizeof(current_pads_dir) - 1] = '\0'; + pads_dir_initialized = 1; } } diff --git a/src/ui.c b/src/ui.c index 647c8b7..6052366 100644 --- a/src/ui.c +++ b/src/ui.c @@ -319,7 +319,33 @@ int handle_decrypt_menu(void) { // Remove newline input_line[strcspn(input_line, "\n")] = 0; - if (strlen(input_line) == 0) { + // Trim leading whitespace to handle pasted content better + char* trimmed_input = input_line; + while (*trimmed_input == ' ' || *trimmed_input == '\t') { + trimmed_input++; + } + + // Check for ASCII armor FIRST, before checking for empty input + // This handles cases where pasted text starts with the header + if (strncmp(trimmed_input, "-----BEGIN OTP MESSAGE-----", 27) == 0) { + // Looks like ASCII armor - collect the full message + char full_message[MAX_INPUT_SIZE * 4] = {0}; + strcat(full_message, input_line); + strcat(full_message, "\n"); + + printf("Continue pasting the message (end with -----END OTP MESSAGE-----):\n"); + + char line[MAX_LINE_LENGTH]; + while (fgets(line, sizeof(line), stdin)) { + strncat(full_message, line, sizeof(full_message) - strlen(full_message) - 1); + if (strstr(line, "-----END OTP MESSAGE-----")) { + break; + } + } + + return decrypt_text(NULL, full_message); + } + else if (strlen(trimmed_input) == 0) { // Empty input - launch file manager to browse for files char selected_file[512]; if (launch_file_manager(get_files_directory(), selected_file, sizeof(selected_file)) != 0) { @@ -382,31 +408,13 @@ int handle_decrypt_menu(void) { return decrypt_file(selected_file, output_file); } } - else if (strncmp(input_line, "-----BEGIN OTP MESSAGE-----", 27) == 0) { - // Looks like ASCII armor - collect the full message - char full_message[MAX_INPUT_SIZE * 4] = {0}; - strcat(full_message, input_line); - strcat(full_message, "\n"); - - printf("Continue pasting the message (end with -----END OTP MESSAGE-----):\n"); - - char line[MAX_LINE_LENGTH]; - while (fgets(line, sizeof(line), stdin)) { - strncat(full_message, line, sizeof(full_message) - strlen(full_message) - 1); - if (strstr(line, "-----END OTP MESSAGE-----")) { - break; - } - } - - return decrypt_text(NULL, full_message); - } else { // Check if it looks like a file path - if (access(input_line, R_OK) == 0) { + if (access(trimmed_input, R_OK) == 0) { // It's a valid file - decrypt it with enhanced input for output filename char temp_default[512]; char default_output[512]; - strncpy(temp_default, input_line, sizeof(temp_default) - 1); + strncpy(temp_default, trimmed_input, sizeof(temp_default) - 1); temp_default[sizeof(temp_default) - 1] = '\0'; // Remove common encrypted extensions to get a better default @@ -441,7 +449,7 @@ int handle_decrypt_menu(void) { } // Check if it's a directory archive - if (strstr(input_line, ".tar.gz.otp") || strstr(input_line, ".tar.otp")) { + if (strstr(trimmed_input, ".tar.gz.otp") || strstr(trimmed_input, ".tar.otp")) { // It's a directory archive - extract to directory char extract_dir[512]; strncpy(extract_dir, output_file, sizeof(extract_dir) - 1); @@ -453,9 +461,9 @@ int handle_decrypt_menu(void) { if (ext) *ext = '\0'; printf("Extracting directory archive to: %s/\n", extract_dir); - return decrypt_and_extract_directory(input_line, extract_dir); + return decrypt_and_extract_directory(trimmed_input, extract_dir); } else { - return decrypt_file(input_line, output_file); + return decrypt_file(trimmed_input, output_file); } } else { printf("Input not recognized as ASCII armor or valid file path.\n"); diff --git a/src/util.c b/src/util.c index cf444e2..4da0756 100644 --- a/src/util.c +++ b/src/util.c @@ -19,6 +19,7 @@ // Global variables for preferences static char default_pad_path[1024] = ""; +static char pads_directory[1024] = ""; void show_progress(uint64_t current, uint64_t total, time_t start_time) { time_t now = time(NULL); @@ -506,6 +507,11 @@ int load_preferences(void) { if (strcmp(key, "default_pad") == 0) { strncpy(default_pad_path, value, sizeof(default_pad_path) - 1); default_pad_path[sizeof(default_pad_path) - 1] = '\0'; + } else if (strcmp(key, "pads_directory") == 0) { + strncpy(pads_directory, value, sizeof(pads_directory) - 1); + pads_directory[sizeof(pads_directory) - 1] = '\0'; + // Apply the pads directory from config + set_current_pads_dir(pads_directory); } } } @@ -1109,6 +1115,12 @@ int save_preferences(void) { fprintf(file, "# OTP Preferences File\n"); fprintf(file, "# This file is automatically generated and updated by the OTP program\n\n"); + // Save pads directory + const char* current_pads = get_current_pads_dir(); + if (current_pads && strlen(current_pads) > 0) { + fprintf(file, "pads_directory=%s\n", current_pads); + } + if (strlen(default_pad_path) > 0) { fprintf(file, "default_pad=%s\n", default_pad_path); }