Fixing user interface problems
This commit is contained in:
12
Makefile
12
Makefile
@@ -1,13 +1,13 @@
|
|||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -Wall -Wextra -std=c99 -Isrc -Isrc/miniz -Isrc/microtar
|
CFLAGS = -Wall -Wextra -std=c99 -Isrc -Iminiz -Imicrotar/src
|
||||||
CFLAGS_MINIZ = -Wall -Wextra -std=c99 -D_POSIX_C_SOURCE=200112L -Isrc -Isrc/miniz -Isrc/microtar -Wno-unused-function -Wno-implicit-function-declaration
|
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 = -lm
|
||||||
LIBS_STATIC = -static -lm
|
LIBS_STATIC = -static -lm
|
||||||
ARCH = $(shell uname -m)
|
ARCH = $(shell uname -m)
|
||||||
TARGET = build/otp-$(ARCH)
|
TARGET = build/otp-$(ARCH)
|
||||||
SOURCES = $(wildcard src/*.c)
|
SOURCES = $(wildcard src/*.c)
|
||||||
MINIZ_SOURCES = $(wildcard src/miniz/*.c)
|
MINIZ_SOURCES = $(wildcard miniz/*.c)
|
||||||
MICROTAR_SOURCES = $(wildcard src/microtar/*.c)
|
MICROTAR_SOURCES = $(wildcard microtar/src/*.c)
|
||||||
OBJS = $(SOURCES:.c=.o)
|
OBJS = $(SOURCES:.c=.o)
|
||||||
MINIZ_OBJS = $(MINIZ_SOURCES:.c=.o)
|
MINIZ_OBJS = $(MINIZ_SOURCES:.c=.o)
|
||||||
MICROTAR_OBJS = $(MICROTAR_SOURCES:.c=.o)
|
MICROTAR_OBJS = $(MICROTAR_SOURCES:.c=.o)
|
||||||
@@ -30,11 +30,11 @@ src/%.o: src/%.c
|
|||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
# Compile miniz library files with reduced warnings
|
# Compile miniz library files with reduced warnings
|
||||||
src/miniz/%.o: src/miniz/%.c
|
miniz/%.o: miniz/%.c
|
||||||
$(CC) $(CFLAGS_MINIZ) -c $< -o $@
|
$(CC) $(CFLAGS_MINIZ) -c $< -o $@
|
||||||
|
|
||||||
# Compile microtar library files normally
|
# Compile microtar library files normally
|
||||||
src/microtar/%.o: src/microtar/%.c
|
microtar/src/%.o: microtar/src/%.c
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|||||||
23
build.sh
23
build.sh
@@ -346,10 +346,29 @@ clean_project() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
install_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
|
make install
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
print_success "Installation completed"
|
print_success "Installation completed - binary installed to /usr/local/bin/otp"
|
||||||
else
|
else
|
||||||
print_error "Installation failed"
|
print_error "Installation failed"
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
@@ -10,12 +10,12 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "microtar/microtar.h"
|
#include "microtar.h"
|
||||||
|
|
||||||
// Suppress warnings from miniz header
|
// Suppress warnings from miniz header
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||||
#include "miniz/miniz.h"
|
#include "miniz.h"
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
17
src/state.c
17
src/state.c
@@ -1,10 +1,12 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
// Global state variables
|
// 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 is_interactive_mode = 0;
|
||||||
|
static int pads_dir_initialized = 0;
|
||||||
|
|
||||||
// Terminal dimensions (moved from ui.c to state.c for global access)
|
// Terminal dimensions (moved from ui.c to state.c for global access)
|
||||||
static int terminal_width = 80; // Default fallback width
|
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
|
// Getters and setters for global state
|
||||||
|
|
||||||
const char* get_current_pads_dir(void) {
|
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;
|
return current_pads_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,6 +34,7 @@ void set_current_pads_dir(const char* dir) {
|
|||||||
if (dir) {
|
if (dir) {
|
||||||
strncpy(current_pads_dir, dir, sizeof(current_pads_dir) - 1);
|
strncpy(current_pads_dir, dir, sizeof(current_pads_dir) - 1);
|
||||||
current_pads_dir[sizeof(current_pads_dir) - 1] = '\0';
|
current_pads_dir[sizeof(current_pads_dir) - 1] = '\0';
|
||||||
|
pads_dir_initialized = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
56
src/ui.c
56
src/ui.c
@@ -319,7 +319,33 @@ int handle_decrypt_menu(void) {
|
|||||||
// Remove newline
|
// Remove newline
|
||||||
input_line[strcspn(input_line, "\n")] = 0;
|
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
|
// Empty input - launch file manager to browse for files
|
||||||
char selected_file[512];
|
char selected_file[512];
|
||||||
if (launch_file_manager(get_files_directory(), selected_file, sizeof(selected_file)) != 0) {
|
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);
|
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 {
|
else {
|
||||||
// Check if it looks like a file path
|
// 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
|
// It's a valid file - decrypt it with enhanced input for output filename
|
||||||
char temp_default[512];
|
char temp_default[512];
|
||||||
char default_output[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';
|
temp_default[sizeof(temp_default) - 1] = '\0';
|
||||||
|
|
||||||
// Remove common encrypted extensions to get a better default
|
// 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
|
// 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
|
// It's a directory archive - extract to directory
|
||||||
char extract_dir[512];
|
char extract_dir[512];
|
||||||
strncpy(extract_dir, output_file, sizeof(extract_dir) - 1);
|
strncpy(extract_dir, output_file, sizeof(extract_dir) - 1);
|
||||||
@@ -453,9 +461,9 @@ int handle_decrypt_menu(void) {
|
|||||||
if (ext) *ext = '\0';
|
if (ext) *ext = '\0';
|
||||||
|
|
||||||
printf("Extracting directory archive to: %s/\n", extract_dir);
|
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 {
|
} else {
|
||||||
return decrypt_file(input_line, output_file);
|
return decrypt_file(trimmed_input, output_file);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("Input not recognized as ASCII armor or valid file path.\n");
|
printf("Input not recognized as ASCII armor or valid file path.\n");
|
||||||
|
|||||||
12
src/util.c
12
src/util.c
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
// Global variables for preferences
|
// Global variables for preferences
|
||||||
static char default_pad_path[1024] = "";
|
static char default_pad_path[1024] = "";
|
||||||
|
static char pads_directory[1024] = "";
|
||||||
|
|
||||||
void show_progress(uint64_t current, uint64_t total, time_t start_time) {
|
void show_progress(uint64_t current, uint64_t total, time_t start_time) {
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
@@ -506,6 +507,11 @@ int load_preferences(void) {
|
|||||||
if (strcmp(key, "default_pad") == 0) {
|
if (strcmp(key, "default_pad") == 0) {
|
||||||
strncpy(default_pad_path, value, sizeof(default_pad_path) - 1);
|
strncpy(default_pad_path, value, sizeof(default_pad_path) - 1);
|
||||||
default_pad_path[sizeof(default_pad_path) - 1] = '\0';
|
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, "# OTP Preferences File\n");
|
||||||
fprintf(file, "# This file is automatically generated and updated by the OTP program\n\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) {
|
if (strlen(default_pad_path) > 0) {
|
||||||
fprintf(file, "default_pad=%s\n", default_pad_path);
|
fprintf(file, "default_pad=%s\n", default_pad_path);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user