Version v0.3.40 - -m Add directory encryption (TAR+GZIP+OTP), integrate ranger for directory selection, add microtar/miniz libraries, remove binary state file backward compatibility - enforce text format only
This commit is contained in:
77
src/util.c
77
src/util.c
@@ -240,6 +240,83 @@ int launch_file_manager(const char* start_directory, char* selected_file, size_t
|
||||
return 1; // Fall back to manual entry
|
||||
}
|
||||
|
||||
int launch_directory_manager(const char* start_directory, char* selected_dir, size_t buffer_size) {
|
||||
char* fm = get_preferred_file_manager();
|
||||
if (!fm) {
|
||||
printf("No file manager found. Please install ranger, fzf, nnn, or lf.\n");
|
||||
printf("Falling back to manual directory path entry.\n");
|
||||
return 1; // Fall back to manual entry
|
||||
}
|
||||
|
||||
char temp_filename[64];
|
||||
snprintf(temp_filename, sizeof(temp_filename), "/tmp/otp_dir_%ld.tmp", time(NULL));
|
||||
|
||||
char command[512];
|
||||
int result = 1;
|
||||
|
||||
printf("Opening %s for directory selection...\n", fm);
|
||||
printf("Navigate INTO the directory you want to encrypt, then press 'q' to quit and select it.\n");
|
||||
|
||||
if (strcmp(fm, "ranger") == 0) {
|
||||
snprintf(command, sizeof(command), "cd '%s' && ranger --choosedir=%s",
|
||||
start_directory ? start_directory : ".", temp_filename);
|
||||
} else if (strcmp(fm, "fzf") == 0) {
|
||||
// fzf doesn't have directory-only mode easily, use find
|
||||
snprintf(command, sizeof(command), "cd '%s' && find . -type d | fzf > %s",
|
||||
start_directory ? start_directory : ".", temp_filename);
|
||||
} else if (strcmp(fm, "nnn") == 0) {
|
||||
snprintf(command, sizeof(command), "cd '%s' && nnn -p %s",
|
||||
start_directory ? start_directory : ".", temp_filename);
|
||||
} else if (strcmp(fm, "lf") == 0) {
|
||||
snprintf(command, sizeof(command), "cd '%s' && lf -selection-path=%s",
|
||||
start_directory ? start_directory : ".", temp_filename);
|
||||
}
|
||||
|
||||
result = system(command);
|
||||
|
||||
if (result == 0 || result == 256) { // Some file managers return 256 on success
|
||||
// Read selected directory from temp file
|
||||
FILE* temp_file = fopen(temp_filename, "r");
|
||||
if (temp_file) {
|
||||
if (fgets(selected_dir, buffer_size, temp_file)) {
|
||||
// Remove trailing newline
|
||||
selected_dir[strcspn(selected_dir, "\n\r")] = 0;
|
||||
|
||||
// For relative paths, make absolute if needed
|
||||
if (selected_dir[0] == '.' && selected_dir[1] == '/') {
|
||||
char current_dir[512];
|
||||
if (getcwd(current_dir, sizeof(current_dir))) {
|
||||
char abs_path[1024];
|
||||
snprintf(abs_path, sizeof(abs_path), "%s/%s", current_dir, selected_dir + 2);
|
||||
strncpy(selected_dir, abs_path, buffer_size - 1);
|
||||
selected_dir[buffer_size - 1] = '\0';
|
||||
}
|
||||
} else if (selected_dir[0] != '/') {
|
||||
// Relative path without ./
|
||||
char current_dir[512];
|
||||
if (getcwd(current_dir, sizeof(current_dir))) {
|
||||
char abs_path[1024];
|
||||
snprintf(abs_path, sizeof(abs_path), "%s/%s", current_dir, selected_dir);
|
||||
strncpy(selected_dir, abs_path, buffer_size - 1);
|
||||
selected_dir[buffer_size - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
fclose(temp_file);
|
||||
unlink(temp_filename);
|
||||
free(fm);
|
||||
return 0; // Success
|
||||
}
|
||||
fclose(temp_file);
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up and indicate failure
|
||||
unlink(temp_filename);
|
||||
free(fm);
|
||||
return 1; // Fall back to manual entry
|
||||
}
|
||||
|
||||
// Stdin detection functions implementation
|
||||
int has_stdin_data(void) {
|
||||
// Check if stdin is a pipe/redirect (not a terminal)
|
||||
|
||||
Reference in New Issue
Block a user