/* Opens file under the cursor in the viewer. */ static void view_current_file(const FileView *view) { char full_path[PATH_MAX]; get_current_full_path(view, sizeof(full_path), full_path); (void)vim_view_file(full_path, -1, -1, 1); }
static void cmd_return(key_info_t key_info, keys_info_t *keys_info) { char path[PATH_MAX]; if(!changed) { return; } get_current_full_path(view, sizeof(path), path); set_perm_string(view, perms, origin_perms); leave_attr_mode(); }
/* Loads full list of files into unfiltered list of the view. Returns position * of file under cursor in the unfiltered list. */ static int load_unfiltered_list(view_t *view) { int current_file_pos = view->list_pos; view->local_filter.in_progress = 1; view->local_filter.saved = strdup(view->local_filter.filter.raw); if(list_is_incomplete(view)) { char full_path[PATH_MAX + 1]; dir_entry_t *entry; get_current_full_path(view, sizeof(full_path), full_path); filter_clear(&view->local_filter.filter); (void)populate_dir_list(view, 1); /* Resolve current file position in updated list. */ entry = entry_from_path(view, view->dir_entry, view->list_rows, full_path); if(entry != NULL) { current_file_pos = entry_to_pos(view, entry); } if(current_file_pos >= view->list_rows) { current_file_pos = view->list_rows - 1; } } else { /* Save unfiltered (by local filter) list for further use. */ replace_dir_entries(view, &view->local_filter.entries, &view->local_filter.entry_count, view->dir_entry, view->list_rows); } view->local_filter.unfiltered = view->dir_entry; view->local_filter.unfiltered_count = view->list_rows; view->local_filter.prefiltered_count = view->filtered; view->dir_entry = NULL; return current_file_pos; }
/* Returns increment for curr_y. */ static int show_mime_type(FileView *view, int curr_y) { char full_path[PATH_MAX]; const char* mimetype = NULL; get_current_full_path(view, sizeof(full_path), full_path); mimetype = get_mimetype(full_path); mvwaddstr(menu_win, curr_y, 2, "Mime Type: "); if(mimetype == NULL) mimetype = "Unknown"; mvwaddstr(menu_win, curr_y, 13, mimetype); return 2; }
void open_dir(FileView *view) { char full_path[PATH_MAX]; const char *filename; filename = get_current_file_name(view); if(is_parent_dir(filename)) { cd_updir(view, 1); return; } get_current_full_path(view, sizeof(full_path), full_path); if(cd_is_possible(full_path)) { navigate_to(view, full_path); } }
/* Returns increment for curr_y. */ static int show_file_type(FileView *view, int curr_y) { const dir_entry_t *entry; int x; int old_curr_y = curr_y; x = getmaxx(menu_win); entry = &view->dir_entry[view->list_pos]; mvwaddstr(menu_win, curr_y, 2, "Type: "); if(entry->type == FT_LINK) { char full_path[PATH_MAX]; char linkto[PATH_MAX + NAME_MAX]; get_current_full_path(view, sizeof(full_path), full_path); mvwaddstr(menu_win, curr_y, 8, "Link"); curr_y += 2; mvwaddstr(menu_win, curr_y, 2, "Link To: "); if(get_link_target(full_path, linkto, sizeof(linkto)) == 0) { mvwaddnstr(menu_win, curr_y, 11, linkto, x - 11); if(!path_exists(linkto, DEREF)) { mvwaddstr(menu_win, curr_y - 2, 12, " (BROKEN)"); } } else { mvwaddstr(menu_win, curr_y, 11, "Couldn't Resolve Link"); } } else if(entry->type == FT_EXEC || entry->type == FT_REG) { #ifdef HAVE_FILE_PROG char full_path[PATH_MAX]; FILE *pipe; char command[1024]; char buf[NAME_MAX]; get_current_full_path(view, sizeof(full_path), full_path); /* Use the file command to get file information. */ snprintf(command, sizeof(command), "file \"%s\" -b", full_path); if((pipe = popen(command, "r")) == NULL) { mvwaddstr(menu_win, curr_y, 8, "Unable to open pipe to read file"); return 2; } if(fgets(buf, sizeof(buf), pipe) != buf) strcpy(buf, "Pipe read error"); pclose(pipe); mvwaddnstr(menu_win, curr_y, 8, buf, x - 9); if(x > 9 && strlen(buf) > (size_t)(x - 9)) { mvwaddnstr(menu_win, curr_y + 1, 8, buf + x - 9, x - 9); } #else /* #ifdef HAVE_FILE_PROG */ if(entry->type == FT_EXEC) mvwaddstr(menu_win, curr_y, 8, "Executable"); else mvwaddstr(menu_win, curr_y, 8, "Regular File"); #endif /* #ifdef HAVE_FILE_PROG */ } else if(entry->type == FT_DIR) { mvwaddstr(menu_win, curr_y, 8, "Directory"); } #ifndef _WIN32 else if(entry->type == FT_CHAR_DEV || entry->type == FT_BLOCK_DEV) { const char *const type = (entry->type == FT_CHAR_DEV) ? "Character Device" : "Block Device"; char full_path[PATH_MAX]; struct stat st; mvwaddstr(menu_win, curr_y, 8, type); get_current_full_path(view, sizeof(full_path), full_path); if(os_stat(full_path, &st) == 0) { char info[64]; snprintf(info, sizeof(info), "Device Id: 0x%x:0x%x", major(st.st_rdev), minor(st.st_rdev)); curr_y += 2; mvwaddstr(menu_win, curr_y, 2, info); } } else if(entry->type == FT_SOCK) { mvwaddstr(menu_win, curr_y, 8, "Socket"); } #endif else if(entry->type == FT_FIFO) { mvwaddstr(menu_win, curr_y, 8, "Fifo Pipe"); } else { mvwaddstr(menu_win, curr_y, 8, "Unknown"); } curr_y += 2; return curr_y - old_curr_y; }
void redraw_file_info_dialog(void) { const dir_entry_t *entry; char perm_buf[26]; char size_buf[56]; char buf[256]; #ifndef _WIN32 char id_buf[26]; #endif int curr_y; uint64_t size; int size_not_precise; assert(view != NULL); if(resize_for_menu_like() != 0) { return; } werase(menu_win); entry = &view->dir_entry[view->list_pos]; size = 0; if(entry->type == FT_DIR) { char full_path[PATH_MAX]; get_current_full_path(view, sizeof(full_path), full_path); tree_get_data(curr_stats.dirsize_cache, full_path, &size); } if(size == 0) { size = entry->size; } size_not_precise = friendly_size_notation(size, sizeof(size_buf), size_buf); curr_y = 2; curr_y += print_item("Path: ", entry->origin, curr_y); curr_y += print_item("Name: ", entry->name, curr_y); mvwaddstr(menu_win, curr_y, 2, "Size: "); mvwaddstr(menu_win, curr_y, 8, size_buf); if(size_not_precise) { snprintf(size_buf, sizeof(size_buf), " (%" PRId64 " bytes)", size); waddstr(menu_win, size_buf); } curr_y += 2; curr_y += show_file_type(view, curr_y); curr_y += show_mime_type(view, curr_y); #ifndef _WIN32 get_perm_string(perm_buf, sizeof(perm_buf), entry->mode); curr_y += print_item("Permissions: ", perm_buf, curr_y); #else copy_str(perm_buf, sizeof(perm_buf), attr_str_long(entry->attrs)); curr_y += print_item("Attributes: ", perm_buf, curr_y); #endif format_time(entry->mtime, buf, sizeof(buf)); curr_y += print_item("Modified: ", buf, curr_y); format_time(entry->atime, buf, sizeof(buf)); curr_y += print_item("Accessed: ", buf, curr_y); format_time(entry->ctime, buf, sizeof(buf)); #ifndef _WIN32 curr_y += print_item("Changed: ", buf, curr_y); #else curr_y += print_item("Created: ", buf, curr_y); #endif #ifndef _WIN32 get_uid_string(entry, 0, sizeof(id_buf), id_buf); curr_y += print_item("Owner: ", id_buf, curr_y); get_gid_string(entry, 0, sizeof(id_buf), id_buf); curr_y += print_item("Group: ", id_buf, curr_y); #endif /* Fake use after last assignment. */ (void)curr_y; box(menu_win, 0, 0); checked_wmove(menu_win, 0, 3); wprint(menu_win, " File Information "); wrefresh(menu_win); was_redraw = 1; }
void fuse_try_mount(FileView *view, const char program[]) { /* TODO: refactor this function fuse_try_mount() */ fuse_mount_t *runner; char file_full_path[PATH_MAX]; char mount_point[PATH_MAX]; if(!path_exists(cfg.fuse_home, DEREF)) { if(make_path(cfg.fuse_home, S_IRWXU) != 0) { show_error_msg("Unable to create FUSE mount home directory", cfg.fuse_home); return; } } get_current_full_path(view, sizeof(file_full_path), file_full_path); /* Check if already mounted. */ runner = get_mount_by_source(file_full_path); if(runner != NULL) { strcpy(mount_point, runner->mount_point); } else { char param[PATH_MAX]; param[0] = '\0'; /* New file to be mounted. */ if(starts_with(program, "FUSE_MOUNT2")) { FILE *f; if((f = os_fopen(file_full_path, "r")) == NULL) { show_error_msg("SSH mount failed", "Can't open file for reading"); curr_stats.save_msg = 1; return; } if(fgets(param, sizeof(param), f) == NULL) { show_error_msg("SSH mount failed", "Can't read file content"); curr_stats.save_msg = 1; fclose(f); return; } fclose(f); chomp(param); if(param[0] == '\0') { show_error_msg("SSH mount failed", "File is empty"); curr_stats.save_msg = 1; return; } } if(fuse_mount(view, file_full_path, param, program, mount_point) != 0) { return; } } navigate_to(view, mount_point); }