Fixing user interface problems

This commit is contained in:
2026-01-17 07:39:23 -04:00
parent 2e2f78720e
commit 1e017d81b7
6 changed files with 89 additions and 35 deletions

View File

@@ -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");