fix on preview scrolling and error handling when no permission to stat
prevent preview if it is on directory
This commit is contained in:
parent
0c9ebad916
commit
74d5bda857
1 changed files with 12 additions and 6 deletions
18
ccc.c
18
ccc.c
|
@ -5,6 +5,7 @@
|
||||||
#include <linux/limits.h>
|
#include <linux/limits.h>
|
||||||
#include <dirent.h> /* directories etc. */
|
#include <dirent.h> /* directories etc. */
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
|
||||||
|
@ -306,7 +307,12 @@ long long get_directory_size(const char *path)
|
||||||
long add_file_stat(char *filepath)
|
long add_file_stat(char *filepath)
|
||||||
{
|
{
|
||||||
struct stat file_stat;
|
struct stat file_stat;
|
||||||
stat(filepath, &file_stat);
|
if (stat(filepath, &file_stat) == -1) {
|
||||||
|
/* can't be triggered ? */
|
||||||
|
if (errno == EACCES) {
|
||||||
|
return add_file(filepath, "", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* get last modified time */
|
/* get last modified time */
|
||||||
char *time = memalloc(20 * sizeof(char));
|
char *time = memalloc(20 * sizeof(char));
|
||||||
|
@ -409,6 +415,7 @@ void highlight_current_line()
|
||||||
wrefresh(panel);
|
wrefresh(panel);
|
||||||
/* show file content every time cursor changes */
|
/* show file content every time cursor changes */
|
||||||
show_file_content();
|
show_file_content();
|
||||||
|
wrefresh(preview_content);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -416,11 +423,12 @@ void highlight_current_line()
|
||||||
*/
|
*/
|
||||||
void show_file_content()
|
void show_file_content()
|
||||||
{
|
{
|
||||||
FILE *file = fopen(get_filepath((long) current_selection), "rb");
|
|
||||||
if (file) {
|
|
||||||
wclear(preview_content);
|
wclear(preview_content);
|
||||||
|
file *current_file = get_file((long) current_selection);
|
||||||
|
if (strncmp(current_file->type, "DIR", 3) == 0) return;
|
||||||
|
FILE *file = fopen(current_file->path, "rb");
|
||||||
|
if (file) {
|
||||||
draw_border_title(preview_border, true);
|
draw_border_title(preview_border, true);
|
||||||
|
|
||||||
fseek(file, 0, SEEK_END);
|
fseek(file, 0, SEEK_END);
|
||||||
long length = ftell(file);
|
long length = ftell(file);
|
||||||
/* check if file isn't empty */
|
/* check if file isn't empty */
|
||||||
|
@ -429,7 +437,6 @@ void show_file_content()
|
||||||
char *buffer = memalloc(length * sizeof(char));
|
char *buffer = memalloc(length * sizeof(char));
|
||||||
fread(buffer, 1, length, file);
|
fread(buffer, 1, length, file);
|
||||||
mvwprintw(preview_content, 0, 0, "%s", buffer);
|
mvwprintw(preview_content, 0, 0, "%s", buffer);
|
||||||
wrefresh(preview_content);
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
} else {
|
} else {
|
||||||
wclear(preview_content);
|
wclear(preview_content);
|
||||||
|
@ -486,7 +493,6 @@ void init_windows()
|
||||||
draw_border_title(preview_border, false);
|
draw_border_title(preview_border, false);
|
||||||
|
|
||||||
scrollok(directory_content, true);
|
scrollok(directory_content, true);
|
||||||
scrollok(preview_content, true);
|
|
||||||
/* window location y, x */
|
/* window location y, x */
|
||||||
windows[0] = (WIN_STRUCT) { directory_border, 0, 0, 0 };
|
windows[0] = (WIN_STRUCT) { directory_border, 0, 0, 0 };
|
||||||
windows[1] = (WIN_STRUCT) { directory_border, 0, 0, 0 };
|
windows[1] = (WIN_STRUCT) { directory_border, 0, 0, 0 };
|
||||||
|
|
Loading…
Reference in a new issue