unpack zips in src to better compression
This commit is contained in:
114
sources/z-tools/trunk/zview/file/count.c
Normal file
114
sources/z-tools/trunk/zview/file/count.c
Normal file
@@ -0,0 +1,114 @@
|
||||
#include "../general.h"
|
||||
#include "file.h"
|
||||
|
||||
/* Prototype */
|
||||
int16 count_files( WINDICON *wicones, fileinfo *file);
|
||||
int16 count_dir( const char *path, fileinfo *file);
|
||||
|
||||
/*==================================================================================*
|
||||
* int16 count_dir : *
|
||||
* Do a recursive file count in a directory. *
|
||||
*----------------------------------------------------------------------------------*
|
||||
* input: *
|
||||
* path -> the path where to search. *
|
||||
* item -> the adress where to return the number of files. *
|
||||
* size -> the adress where to return the total size of all the files. *
|
||||
*----------------------------------------------------------------------------------*
|
||||
* return: *
|
||||
* 1 is ok else 0 *
|
||||
*==================================================================================*/
|
||||
|
||||
int16 count_dir( const char *path, fileinfo *file)
|
||||
{
|
||||
char old_dir[MAX_PATH];
|
||||
DIR *dir;
|
||||
struct dirent *de;
|
||||
struct stat file_stat;
|
||||
|
||||
if ( dir_cd( path, old_dir, ( int16)( sizeof old_dir)))
|
||||
{
|
||||
if (( dir = opendir( ".")) != NULL)
|
||||
{
|
||||
while(( de = readdir( dir)) != NULL)
|
||||
{
|
||||
if (( strcmp( de->d_name, ".") == 0) || ( strcmp( de->d_name, "..") == 0))
|
||||
continue;
|
||||
|
||||
if ( lstat( de->d_name, &file_stat) != 0)
|
||||
{
|
||||
closedir( dir);
|
||||
dir_cd( old_dir, NULL, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( S_ISDIR( file_stat.st_mode))
|
||||
{
|
||||
if ( !count_dir( de->d_name, file))
|
||||
{
|
||||
closedir( dir);
|
||||
dir_cd( old_dir, NULL, 0);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
file->item ++;
|
||||
}
|
||||
else
|
||||
{
|
||||
file->item ++;
|
||||
file->size += file_stat.st_size;
|
||||
}
|
||||
}
|
||||
closedir( dir);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
|
||||
dir_cd( old_dir, NULL, 0);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*==================================================================================*
|
||||
* int16 count_files: *
|
||||
* Do a recursive file count. *
|
||||
*----------------------------------------------------------------------------------*
|
||||
* input: *
|
||||
* wicones -> the target wicones. *
|
||||
* item -> the adress where to return the number of files. *
|
||||
* size -> the adress where to return the total size of all the files. *
|
||||
*----------------------------------------------------------------------------------*
|
||||
* return: *
|
||||
* 1 is ok else 0 *
|
||||
*==================================================================================*/
|
||||
|
||||
int16 count_files( WINDICON *wicones, fileinfo *file)
|
||||
{
|
||||
Entry *entry = wicones->first_selected;
|
||||
|
||||
file->item = 0L;
|
||||
file->size = 0L;
|
||||
|
||||
while ( entry)
|
||||
{
|
||||
if ( S_ISDIR( entry->stat.st_mode))
|
||||
{
|
||||
if( !count_dir( entry->name, file))
|
||||
return 0;
|
||||
else
|
||||
file->item ++;
|
||||
}
|
||||
else
|
||||
{
|
||||
file->item ++;
|
||||
file->size += entry->stat.st_size;
|
||||
}
|
||||
|
||||
entry = entry->next_selected;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
2
sources/z-tools/trunk/zview/file/count.h
Normal file
2
sources/z-tools/trunk/zview/file/count.h
Normal file
@@ -0,0 +1,2 @@
|
||||
extern int16 count_files( WINDICON *wicones, fileinfo *file);
|
||||
|
||||
312
sources/z-tools/trunk/zview/file/delete.c
Normal file
312
sources/z-tools/trunk/zview/file/delete.c
Normal file
@@ -0,0 +1,312 @@
|
||||
#include "../general.h"
|
||||
#include "../prefs.h"
|
||||
#include "../ztext.h"
|
||||
#include "../close_modal.h"
|
||||
#include "../catalog/catalog.h"
|
||||
#include "../catalog/catalog_entry.h"
|
||||
#include "../catalog/catalog_mini_entry.h"
|
||||
#include "file.h"
|
||||
#include "count.h"
|
||||
|
||||
|
||||
/* local variable */
|
||||
static char size_to_delete[16];
|
||||
static uint32 size_deleted;
|
||||
static uint32 item_deleted;
|
||||
static uint32 item_to_delete;
|
||||
|
||||
static OBJECT *save_dialog;
|
||||
|
||||
/* prototype */
|
||||
boolean delete_file( const char *name, struct stat *file_stat);
|
||||
boolean delete_dir( WINDOW *win, const char *path);
|
||||
void delete_entry( WINDOW *win);
|
||||
void delete_progress( WINDOW *win);
|
||||
|
||||
|
||||
/*==================================================================================*
|
||||
* delete_file: *
|
||||
* Delete a plain file. This is capable of removing anything that is not a *
|
||||
* directory. *
|
||||
*----------------------------------------------------------------------------------*
|
||||
* returns: TRUE = success, FALSE = error *
|
||||
*==================================================================================*/
|
||||
|
||||
boolean delete_file( const char *name, struct stat *file_stat)
|
||||
{
|
||||
if ( unlink( name) != 0)
|
||||
{
|
||||
/* If possible, change the file permission for delete it */
|
||||
( void)chmod( name, S_IRWXU);
|
||||
return unlink( name) == 0 ? TRUE : FALSE;
|
||||
}
|
||||
else
|
||||
return ( TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*==================================================================================*
|
||||
* delete_dir: *
|
||||
* Delete a directory. *
|
||||
*----------------------------------------------------------------------------------*
|
||||
* returns: TRUE = success, FALSE = error *
|
||||
*==================================================================================*/
|
||||
|
||||
boolean delete_dir( WINDOW *win, const char *path)
|
||||
{
|
||||
char old_dir[MAX_PATH];
|
||||
DIR *dir;
|
||||
struct dirent *de;
|
||||
struct stat file_stat;
|
||||
|
||||
if ( rmdir( path) == 0)
|
||||
return TRUE;
|
||||
else
|
||||
{
|
||||
if ( dir_cd( path, old_dir, ( int16)( sizeof old_dir)))
|
||||
{
|
||||
if (( dir = opendir( ".")) != NULL)
|
||||
{
|
||||
while(( de = readdir( dir)) != NULL)
|
||||
{
|
||||
if (( strcmp( de->d_name, ".") == 0) || ( strcmp( de->d_name, "..") == 0))
|
||||
continue;
|
||||
|
||||
if ( lstat( de->d_name, &file_stat) != 0)
|
||||
break;
|
||||
|
||||
if ( S_ISDIR( file_stat.st_mode))
|
||||
{
|
||||
if ( delete_dir( win, de->d_name) == FALSE)
|
||||
break;
|
||||
else
|
||||
{
|
||||
item_deleted++;
|
||||
delete_progress( win);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( delete_file( de->d_name, &file_stat) == FALSE)
|
||||
break;
|
||||
else
|
||||
{
|
||||
item_deleted++;
|
||||
size_deleted += file_stat.st_size;
|
||||
delete_progress( win);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir( dir);
|
||||
}
|
||||
dir_cd( old_dir, NULL, 0);
|
||||
}
|
||||
|
||||
return rmdir( path) == 0 ? TRUE : FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void delete_progress( WINDOW *win)
|
||||
{
|
||||
static int32 bar_width = 0L;
|
||||
int32 new_bar_width = ( ( item_deleted * 100L) / item_to_delete) * 3;
|
||||
int16 pxy[4];
|
||||
char tmp[16];
|
||||
GRECT rwin, raes;
|
||||
W_FORM *form = ( W_FORM *)DataSearch( win, WD_WFRM);
|
||||
|
||||
size_to_text( tmp, ( float)size_deleted);
|
||||
|
||||
sprintf( save_dialog[OPERATION_DIAL_INFO].ob_spec.tedinfo->te_ptext, get_string( DELETE_INFO), item_to_delete - item_deleted);
|
||||
sprintf( save_dialog[OPERATION_DIAL_PROGRESS].ob_spec.tedinfo->te_ptext, get_string( PROGRESS_TXT), tmp, size_to_delete);
|
||||
|
||||
ObjcDraw( OC_FORM, win, OPERATION_DIAL_INFO, 0);
|
||||
ObjcDraw( OC_FORM, win, OPERATION_DIAL_PROGRESS, 0);
|
||||
|
||||
if (( bar_width == new_bar_width) || !new_bar_width)
|
||||
return;
|
||||
|
||||
WindGet( win, WF_WORKXYWH, &rwin.g_x, &rwin.g_y, &rwin.g_w, &rwin.g_h);
|
||||
|
||||
bar_width = new_bar_width;
|
||||
|
||||
pxy[0] = rwin.g_x + form->root[OPERATION_DIAL_BAR].ob_x;
|
||||
pxy[1] = rwin.g_y + form->root[OPERATION_DIAL_BAR].ob_y;
|
||||
pxy[2] = pxy[0] + bar_width;
|
||||
pxy[3] = pxy[1] + form->root[OPERATION_DIAL_BAR].ob_height;
|
||||
|
||||
while( !wind_update( BEG_UPDATE));
|
||||
graf_mouse( M_OFF, 0L);
|
||||
wind_get( win->handle, WF_FIRSTXYWH, &raes.g_x, &raes.g_y, &raes.g_w, &raes.g_h);
|
||||
|
||||
while ( raes.g_w && raes.g_h)
|
||||
{
|
||||
if( rc_intersect( &rwin, &raes))
|
||||
{
|
||||
rc_clip_on( win->graf.handle, &raes);
|
||||
|
||||
v_bar( win->graf.handle, pxy);
|
||||
|
||||
rc_clip_off( win->graf.handle);
|
||||
}
|
||||
|
||||
wind_get( win->handle, WF_NEXTXYWH, &raes.g_x, &raes.g_y, &raes.g_w, &raes.g_h);
|
||||
}
|
||||
|
||||
graf_mouse( M_ON, 0L);
|
||||
|
||||
wind_update( END_UPDATE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void delete_function( WINDOW *win)
|
||||
{
|
||||
WINDICON *wicones = ( WINDICON *)DataSearch( win_catalog, WD_ICON);
|
||||
Mini_Entry *mini_entry;
|
||||
fileinfo file;
|
||||
int16 x, y, w, h, deleted_entry = 0;
|
||||
|
||||
switch( evnt.buff[4])
|
||||
{
|
||||
case OPERATION_DIAL_CANCEL:
|
||||
ObjcChange( OC_FORM, win, OPERATION_DIAL_CANCEL, ~SELECTED, TRUE);
|
||||
ApplWrite( app.id, WM_CLOSED, win->handle, 0, 0, 0, 0);
|
||||
break;
|
||||
|
||||
case OPERATION_DIAL_OK:
|
||||
ObjcChange( OC_FORM, win, OPERATION_DIAL_OK, ~SELECTED, TRUE);
|
||||
strcpy( save_dialog[OPERATION_DIAL_INFO].ob_spec.tedinfo->te_ptext, get_string( CALCUL));
|
||||
|
||||
vsf_color( win->graf.handle, RED);
|
||||
|
||||
if( !count_files( wicones, &file))
|
||||
{
|
||||
ApplWrite( app.id, WM_CLOSED, win->handle, 0, 0, 0, 0);
|
||||
errshow( "", errno);
|
||||
return;
|
||||
}
|
||||
|
||||
item_to_delete = file.item;
|
||||
|
||||
size_deleted = 0L;
|
||||
item_deleted = 0L;
|
||||
|
||||
size_to_text( size_to_delete, ( float)file.size);
|
||||
|
||||
delete_progress( win);
|
||||
|
||||
while ( wicones->first_selected)
|
||||
{
|
||||
if ( S_ISDIR( wicones->first_selected->stat.st_mode))
|
||||
{
|
||||
if ( !delete_dir( win, wicones->first_selected->name))
|
||||
{
|
||||
errshow( wicones->first_selected->name, errno);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
deleted_entry++;
|
||||
item_deleted++;
|
||||
|
||||
delete_progress( win);
|
||||
|
||||
remove_selected_entry( wicones, wicones->first_selected);
|
||||
|
||||
/* the mini_entry returned is the mini_entry parent of the directory deleted
|
||||
because we give the current directory ( wicones->directory) as parameter */
|
||||
if ( ( mini_entry = find_mini_entry_by_path( wicones, wicones->directory)))
|
||||
{
|
||||
int16 old_state = mini_entry->state;
|
||||
|
||||
delete_mini_entry_child( mini_entry);
|
||||
scan_mini_dir( win_catalog, mini_entry);
|
||||
check_mini_dir( mini_entry->nbr_child, mini_entry->child);
|
||||
|
||||
mini_entry->state = old_state;
|
||||
|
||||
if( mini_entry->state == OFF)
|
||||
delete_mini_entry_child( mini_entry);
|
||||
|
||||
if ( browser_frame_width)
|
||||
{
|
||||
WindGet( win_catalog, WF_WORKXYWH, &x, &y, &w, &h);
|
||||
draw_page( win_catalog, x, y + mini_entry->arrow_position.y1 - 1, browser_frame_width, h - mini_entry->arrow_position.y1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !delete_file( wicones->first_selected->name, &wicones->first_selected->stat))
|
||||
{
|
||||
errshow( wicones->first_selected->name, errno);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
deleted_entry++;
|
||||
item_deleted++;
|
||||
size_deleted += wicones->first_selected->stat.st_size;
|
||||
|
||||
delete_progress( win);
|
||||
remove_selected_entry( wicones, wicones->first_selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
ObjcDraw( OC_FORM, win, OPERATION_DIAL_INFO, FALSE);
|
||||
|
||||
close_modal( win);
|
||||
|
||||
if ( deleted_entry)
|
||||
{
|
||||
( void)scan_dir( win_catalog, wicones->directory);
|
||||
WinCatalog_filelist_redraw();
|
||||
ObjcDraw( OC_TOOLBAR, win_catalog, TOOLBAR_DELETE, 1);
|
||||
ObjcDraw( OC_TOOLBAR, win_catalog, TOOLBAR_INFO, 1);
|
||||
ObjcDraw( OC_TOOLBAR, win_catalog, TOOLBAR_SAVE, 1);
|
||||
menu_ienable( get_tree( MENU_BAR), MENU_BAR_DELETE, 0);
|
||||
menu_ienable( get_tree( MENU_BAR), MENU_BAR_INFORMATION, 0);
|
||||
menu_ienable( get_tree( MENU_BAR), MENU_BAR_SAVE, 0);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*==================================================================================*
|
||||
* void delete_entry: *
|
||||
* Delete all the selected entries in the WINDOW win. *
|
||||
* A modal dialog box is shown for approve it. *
|
||||
*----------------------------------------------------------------------------------*
|
||||
* input: *
|
||||
* win -> the window's adress to handle. *
|
||||
*----------------------------------------------------------------------------------*
|
||||
* return: *
|
||||
* entries deleted *
|
||||
*==================================================================================*/
|
||||
|
||||
void delete_entry( WINDOW *win)
|
||||
{
|
||||
WINDOW *win_save_dialog;
|
||||
|
||||
save_dialog = get_tree( OPERATION_DIAL);
|
||||
|
||||
zstrncpy( save_dialog[OPERATION_DIAL_INFO].ob_spec.tedinfo->te_ptext, get_string( DELETE_ASK), 48);
|
||||
strcpy( save_dialog[OPERATION_DIAL_PROGRESS].ob_spec.tedinfo->te_ptext, "");
|
||||
|
||||
win_save_dialog = FormCreate( save_dialog, NAME|MOVER, delete_function, get_string( DELETE_TITLE), NULL, TRUE, FALSE);
|
||||
|
||||
WindSet( win_save_dialog, WF_BEVENT, BEVENT_MODAL, 0, 0, 0);
|
||||
|
||||
EvntAttach( win_save_dialog, WM_CLOSED, close_modal);
|
||||
|
||||
MenuDisable();
|
||||
}
|
||||
|
||||
2
sources/z-tools/trunk/zview/file/delete.h
Normal file
2
sources/z-tools/trunk/zview/file/delete.h
Normal file
@@ -0,0 +1,2 @@
|
||||
extern void delete_entry( WINDOW *win);
|
||||
|
||||
439
sources/z-tools/trunk/zview/file/file.c
Normal file
439
sources/z-tools/trunk/zview/file/file.c
Normal file
@@ -0,0 +1,439 @@
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* Files utilities */
|
||||
/*----------------------------------------------------------------------*/
|
||||
#include "../general.h"
|
||||
#include "../zedit/zedit.h"
|
||||
#include "../catalog/catalog_entry.h"
|
||||
#include "../ztext.h"
|
||||
#include "../catalog/catalog_icons.h"
|
||||
#include "../prefs.h"
|
||||
#include "../mfdb.h"
|
||||
#include "../txt_data.h"
|
||||
#include "../custom_font.h"
|
||||
#include "sort.h"
|
||||
|
||||
#define ALLOC_NDIRENTRIES (4) /* number of entries that should be allocated at once by readdir() */
|
||||
|
||||
/* Prototype */
|
||||
boolean dir_parent( char *dir, char *old_dir);
|
||||
boolean dir_cd( const char *new_dir, char *old_dir, int16 bufflen);
|
||||
boolean check_write_perm( const struct stat *file_stat);
|
||||
boolean scan_dir( WINDOW *win, const char *dirpath);
|
||||
boolean scan_mini_drv( WINDOW *win);
|
||||
void check_mini_dir( int16 nbr_child, Mini_Entry *entry);
|
||||
boolean scan_mini_dir( WINDOW *win, Mini_Entry *parent);
|
||||
|
||||
|
||||
/*==================================================================================*
|
||||
* dir_parent: *
|
||||
* go to the parent directory. *
|
||||
*----------------------------------------------------------------------------------*
|
||||
* returns: TRUE = success, FALSE = if root path ( so, no dir up). *
|
||||
*----------------------------------------------------------------------------------*
|
||||
* dir: Pointer to the current directory, the new directory will be *
|
||||
* returned on the same pointer. *
|
||||
* old_dir: Pointer on a null string where will be returned the name of the *
|
||||
* old directory. ( not the full path, only the name) *
|
||||
*==================================================================================*/
|
||||
|
||||
boolean dir_parent( char *dir, char *old_dir)
|
||||
{
|
||||
int16 len, i, ii;
|
||||
|
||||
len = ( int16) strlen( dir) - 1;
|
||||
|
||||
if ( len < 3)
|
||||
return FALSE;
|
||||
|
||||
if ( dir[len] == '\\')
|
||||
dir[len] = '\0';
|
||||
|
||||
len--;
|
||||
i = len;
|
||||
|
||||
while ( dir[i] != '\\')
|
||||
i--;
|
||||
|
||||
ii = len - i - 1;
|
||||
|
||||
old_dir[ii + 1] = '\0';
|
||||
|
||||
while ( dir[len] != '\\')
|
||||
{
|
||||
old_dir[ii] = dir[len];
|
||||
dir[len] = '\0';
|
||||
len--;
|
||||
ii--;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*==================================================================================*
|
||||
* dir_cd: *
|
||||
* enter to a directory. *
|
||||
*----------------------------------------------------------------------------------*
|
||||
* returns: TRUE = success, FALSE = error *
|
||||
*----------------------------------------------------------------------------------*
|
||||
* new_dir: The New directory. *
|
||||
* old_dir: Pointer where save the previous directory. *
|
||||
* ( If NULL, no storing is done). *
|
||||
*==================================================================================*/
|
||||
|
||||
boolean dir_cd( const char *new_dir, char *old_dir, int16 bufflen)
|
||||
{
|
||||
if ( old_dir != NULL)
|
||||
getcwd( old_dir, bufflen);
|
||||
|
||||
return chdir( new_dir) == 0 ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
|
||||
/*==================================================================================*
|
||||
* check_write_perm: *
|
||||
* Do complex WRITE permission check. *
|
||||
*----------------------------------------------------------------------------------*
|
||||
* returns: TRUE = ok, FALSE = no *
|
||||
*----------------------------------------------------------------------------------*
|
||||
* stat: Entry Stat. *
|
||||
*==================================================================================*/
|
||||
|
||||
boolean check_write_perm( const struct stat *file_stat)
|
||||
{
|
||||
uid_t uid = geteuid();
|
||||
gid_t gid = getegid();
|
||||
|
||||
|
||||
/* if ( uid == 0)
|
||||
return TRUE;
|
||||
*/
|
||||
if ( file_stat->st_uid == uid)
|
||||
return ( file_stat->st_mode & S_IWUSR) ? TRUE : FALSE;
|
||||
|
||||
if ( file_stat->st_gid == gid)
|
||||
return ( file_stat->st_mode & S_IWGRP) ? TRUE : FALSE;
|
||||
|
||||
return ( file_stat->st_mode & S_IWOTH) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
|
||||
/*==================================================================================*
|
||||
* scan_dir: *
|
||||
* scan the 'dirpath' directory and fit somes entries in 'dirfile'. *
|
||||
*----------------------------------------------------------------------------------*
|
||||
* return: TRUE if ok or FALSE if error *
|
||||
*==================================================================================*/
|
||||
|
||||
boolean scan_dir( WINDOW *win, const char *dirpath)
|
||||
{
|
||||
short dum, allocated_entries = 0;
|
||||
Entry *entry;
|
||||
DIR *dir;
|
||||
struct dirent *de;
|
||||
struct stat file_stat;
|
||||
struct tm *tmt;
|
||||
WINDICON *dirfile = ( WINDICON *)DataSearch( win, WD_ICON);
|
||||
|
||||
if ( dirfile->nbr_icons)
|
||||
{
|
||||
for ( dum = 0; dum < dirfile->nbr_icons; dum++)
|
||||
{
|
||||
delete_txt_data( &dirfile->entry[dum].preview);
|
||||
delete_mfdb( dirfile->entry[dum].preview.image, dirfile->entry[dum].preview.page);
|
||||
}
|
||||
|
||||
dirfile->nbr_icons = 0;
|
||||
|
||||
gfree( dirfile->entry);
|
||||
}
|
||||
|
||||
dirfile->first_selected = NULL;
|
||||
dirfile->entry = NULL;
|
||||
dirfile->edit = NULL;
|
||||
|
||||
if ( !dir_cd( dirpath, NULL, 0))
|
||||
dir_cd( ".", NULL, 0);
|
||||
|
||||
strcpy( dirfile->directory, dirpath);
|
||||
|
||||
dum = ( int16)strlen( dirfile->directory);
|
||||
|
||||
if ( dirfile->directory[dum-1] != '\\')
|
||||
strcat( dirfile->directory, "\\");
|
||||
|
||||
if (( dir = opendir( ".")) == NULL)
|
||||
{
|
||||
errshow( "dir", errno);
|
||||
goto abort;
|
||||
}
|
||||
|
||||
while(( de = readdir( dir)) != NULL)
|
||||
{
|
||||
if (( strcmp( de->d_name, ".") == 0) || ( strcmp( de->d_name, "..") == 0))
|
||||
continue;
|
||||
|
||||
if ( stat( de->d_name, &file_stat) != 0)
|
||||
continue;
|
||||
|
||||
if (((( file_stat.st_flags & FA_HIDDEN) != 0) || de->d_name[0] == '.') && !show_hidden)
|
||||
continue;
|
||||
|
||||
/* allocate new memory for entries if needed */
|
||||
if ( dirfile->nbr_icons >= allocated_entries)
|
||||
{ /* allocate new entries */
|
||||
if ( dirfile->nbr_icons == 0)
|
||||
{ /* alloc for the first time */
|
||||
if (( dirfile->entry = ( Entry *)gmalloc( ALLOC_NDIRENTRIES * sizeof( Entry))) == NULL)
|
||||
{
|
||||
errshow( "", ENOMEM);
|
||||
goto abort;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ /* expand allocated memory */
|
||||
if (( entry = ( Entry *)grealloc( dirfile->entry, ( allocated_entries + ALLOC_NDIRENTRIES) * sizeof( Entry))) == NULL)
|
||||
{
|
||||
errshow( "", ENOMEM);
|
||||
goto abort;
|
||||
}
|
||||
dirfile->entry = entry;
|
||||
}
|
||||
allocated_entries += ALLOC_NDIRENTRIES;
|
||||
}
|
||||
/* fill out and add new entry */
|
||||
entry = &dirfile->entry[dirfile->nbr_icons];
|
||||
entry->preview.image = NULL;
|
||||
entry->preview.page = 0;
|
||||
entry->preview.comments = NULL;
|
||||
entry->next_selected = NULL;
|
||||
entry->stat = file_stat;
|
||||
strcpy( entry->name, de->d_name);
|
||||
zstrncpy( entry->name_shown, de->d_name, 99);
|
||||
|
||||
/* Get Size */
|
||||
size_to_text( entry->size, ( float)file_stat.st_size);
|
||||
/* Get Time */
|
||||
tmt = localtime(&file_stat.st_mtime);
|
||||
strftime( entry->date, 28, "%A %d %B %Y", tmt);
|
||||
strftime( entry->time, 12, "%H:%M:%S", tmt);
|
||||
|
||||
set_entry_icon( entry);
|
||||
|
||||
/* find if the entry name is bigger than the case width */
|
||||
if (( entry->icon_txt_w = get_text_width( entry->name_shown)) >= dirfile->case_w - 4)
|
||||
entry->icon_txt_w = name_shorter( dirfile->case_w - 6, entry->name_shown);
|
||||
|
||||
dirfile->nbr_icons++;
|
||||
}
|
||||
|
||||
closedir( dir);
|
||||
|
||||
sort_entries( dirfile);
|
||||
|
||||
return TRUE;
|
||||
|
||||
|
||||
abort:
|
||||
closedir( dir);
|
||||
|
||||
if ( dirfile->nbr_icons > 0)
|
||||
gfree( dirfile->entry);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/*==================================================================================*
|
||||
* scan_mini_drv: *
|
||||
* Creates a list with the available drives. *
|
||||
*----------------------------------------------------------------------------------*
|
||||
* returns: TRUE if ok, FALSE if any error occured *
|
||||
*==================================================================================*/
|
||||
boolean scan_mini_drv( WINDOW *win)
|
||||
{
|
||||
int current_drv, drv, allocated_entries = 0;
|
||||
uint32 drives, tmp_d;
|
||||
Mini_Entry *entry;
|
||||
WINDICON *dirlist = ( WINDICON *)DataSearch( win, WD_ICON);
|
||||
|
||||
/* initialise directory descriptor */
|
||||
dirlist->nbr_child = 0;
|
||||
dirlist->entry = NULL;
|
||||
dirlist->mini_selected = NULL;
|
||||
|
||||
/* read contents of directory and build list */
|
||||
drives = Drvmap();
|
||||
|
||||
tmp_d = drives;
|
||||
|
||||
for ( current_drv = 0; current_drv < 32; current_drv++, tmp_d >>= 1)
|
||||
{
|
||||
if ( tmp_d & 0x1)
|
||||
{
|
||||
drv = 'A' + current_drv;
|
||||
|
||||
if ( strchr( skip_drive, drv))
|
||||
continue;
|
||||
|
||||
/* allocate new memory for entries if needed */
|
||||
if ( dirlist->nbr_child >= allocated_entries)
|
||||
{
|
||||
if ( dirlist->nbr_child == 0)
|
||||
{
|
||||
if (( dirlist->root = ( Mini_Entry *)gmalloc( ALLOC_NDIRENTRIES * sizeof( Mini_Entry))) == NULL)
|
||||
goto abort;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (( entry = ( Mini_Entry *)grealloc( dirlist->root, ( allocated_entries + ALLOC_NDIRENTRIES) * sizeof( Mini_Entry))) == NULL)
|
||||
goto abort;
|
||||
|
||||
dirlist->root = entry;
|
||||
}
|
||||
allocated_entries += ALLOC_NDIRENTRIES;
|
||||
}
|
||||
|
||||
/* fill out and add new entry */
|
||||
entry = &dirlist->root[dirlist->nbr_child];
|
||||
|
||||
sprintf( entry->foldername, "%c:\\", drv);
|
||||
sprintf( entry->name, "%c", drv);
|
||||
|
||||
entry->parent = NULL;
|
||||
entry->child = NULL;
|
||||
entry->nbr_child = 0;
|
||||
entry->icon_txt_w = get_text_width( entry->name);
|
||||
entry->state = UNKNOWN;
|
||||
|
||||
dirlist->nbr_child++;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
||||
abort:
|
||||
if ( dirlist->nbr_child > 0)
|
||||
gfree( dirlist->root);
|
||||
|
||||
errshow( "", ENOMEM);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
void check_mini_dir( int16 nbr_child, Mini_Entry *entry)
|
||||
{
|
||||
int16 i, next;
|
||||
char old_dir[MAX_PATH];
|
||||
DIR *dir;
|
||||
struct dirent *de;
|
||||
struct stat file_stat;
|
||||
|
||||
for ( i = 0 ; i < nbr_child; i++)
|
||||
{
|
||||
next = 0;
|
||||
|
||||
if ( dir_cd( entry[i].foldername, old_dir, ( int)( sizeof old_dir)))
|
||||
{
|
||||
if (( dir = opendir( entry[i].foldername)) != NULL)
|
||||
{
|
||||
while(( de = readdir( dir)) != NULL && next == 0)
|
||||
{
|
||||
if (( strcmp( de->d_name, ".") == 0) || ( strcmp( de->d_name, "..") == 0))
|
||||
continue;
|
||||
|
||||
if ( stat( de->d_name, &file_stat) != 0)
|
||||
continue;
|
||||
|
||||
if ( S_ISDIR( file_stat.st_mode))
|
||||
{
|
||||
next = 1;
|
||||
entry[i].state = OFF;
|
||||
}
|
||||
}
|
||||
closedir( dir);
|
||||
}
|
||||
dir_cd( old_dir, NULL, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boolean scan_mini_dir( WINDOW *win, Mini_Entry *parent)
|
||||
{
|
||||
short allocated_entries = 0;
|
||||
char old_dir[MAX_PATH];
|
||||
Mini_Entry *entry;
|
||||
DIR *dir;
|
||||
struct dirent *de;
|
||||
struct stat file_stat;
|
||||
|
||||
|
||||
if ( dir_cd( parent->foldername, old_dir, ( int)( sizeof old_dir)))
|
||||
{
|
||||
if (( dir = opendir( ".")) != NULL)
|
||||
{
|
||||
while(( de = readdir( dir)) != NULL)
|
||||
{
|
||||
if (( strcmp( de->d_name, ".") == 0) || ( strcmp( de->d_name, "..") == 0))
|
||||
continue;
|
||||
|
||||
if ( stat( de->d_name, &file_stat) != 0)
|
||||
continue;
|
||||
|
||||
if ( !S_ISDIR( file_stat.st_mode))
|
||||
continue;
|
||||
|
||||
if (( file_stat.st_flags & 2) == FA_HIDDEN && !show_hidden)
|
||||
continue;
|
||||
|
||||
if ( parent->nbr_child >= allocated_entries)
|
||||
{
|
||||
if ( parent->nbr_child == 0)
|
||||
{
|
||||
if (( parent->child = ( Mini_Entry *)gmalloc( ALLOC_NDIRENTRIES * sizeof( Mini_Entry))) == NULL)
|
||||
goto abort;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (( entry = ( Mini_Entry *)grealloc( parent->child, ( allocated_entries + ALLOC_NDIRENTRIES) * sizeof( Mini_Entry))) == NULL)
|
||||
goto abort;
|
||||
|
||||
parent->child = entry;
|
||||
}
|
||||
allocated_entries += ALLOC_NDIRENTRIES;
|
||||
}
|
||||
|
||||
entry = &parent->child[parent->nbr_child];
|
||||
|
||||
strcpy( entry->foldername, parent->foldername);
|
||||
strcat( entry->foldername, de->d_name);
|
||||
strcat( entry->foldername, "\\");
|
||||
strcpy( entry->name, de->d_name);
|
||||
|
||||
entry->parent = parent;
|
||||
entry->child = NULL;
|
||||
entry->nbr_child = 0;
|
||||
entry->icon_txt_w = get_text_width( entry->name);
|
||||
entry->state = UNKNOWN;
|
||||
|
||||
parent->nbr_child++;
|
||||
}
|
||||
closedir( dir);
|
||||
}
|
||||
dir_cd( old_dir, NULL, 0);
|
||||
}
|
||||
|
||||
qsort( parent->child, parent->nbr_child, sizeof( Mini_Entry), cmp_entries_name);
|
||||
|
||||
return TRUE;
|
||||
|
||||
|
||||
abort:
|
||||
closedir( dir);
|
||||
if ( parent->nbr_child > 0)
|
||||
gfree( parent->child);
|
||||
|
||||
parent->nbr_child = 0;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
7
sources/z-tools/trunk/zview/file/file.h
Normal file
7
sources/z-tools/trunk/zview/file/file.h
Normal file
@@ -0,0 +1,7 @@
|
||||
extern boolean dir_cd( const char *new_dir, char *old_dir, int16 bufflen);
|
||||
extern boolean dir_parent( char *dir, char *old_dir);
|
||||
extern boolean check_write_perm( const struct stat *file_stat);
|
||||
extern boolean scan_dir( WINDOW *win, const char *dirpath);
|
||||
extern boolean scan_mini_drv( WINDOW *win);
|
||||
extern void check_mini_dir( int16 nb_child, Mini_Entry *entry);
|
||||
extern boolean scan_mini_dir( WINDOW *win, Mini_Entry *parent);
|
||||
55
sources/z-tools/trunk/zview/file/rename.c
Normal file
55
sources/z-tools/trunk/zview/file/rename.c
Normal file
@@ -0,0 +1,55 @@
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* Rename functions */
|
||||
/*----------------------------------------------------------------------*/
|
||||
#include "../general.h"
|
||||
#include "../catalog/catalog_icons.h"
|
||||
#include "file.h"
|
||||
|
||||
/* prototype */
|
||||
boolean rename_entry( WINDOW *win, const char *new_name);
|
||||
|
||||
|
||||
/*==================================================================================*
|
||||
* rename_entry: *
|
||||
* rename a file or directory. *
|
||||
*----------------------------------------------------------------------------------*
|
||||
* returns: TRUE = success, FALSE = rename not complete. *
|
||||
*----------------------------------------------------------------------------------*
|
||||
* old_name: Pointer to the current file/directory name. *
|
||||
* new_name: Pointer to the new file/directory name. *
|
||||
*==================================================================================*/
|
||||
|
||||
boolean rename_entry( WINDOW *win, const char *new_name)
|
||||
{
|
||||
int16 i;
|
||||
WINDICON *wicones = (WINDICON *)DataSearch( win, WD_ICON);
|
||||
|
||||
if( strcmp( wicones->first_selected->name, new_name) == 0) /* if name is unchanged, do nothing */
|
||||
return FALSE;
|
||||
|
||||
if( strchr( new_name, '/') || strchr( new_name, '\\')) /* disallow attempts to use rename to move files */
|
||||
{
|
||||
errshow( wicones->first_selected->name, INVAL);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for ( i = 0 ; i < wicones->nbr_icons ; i++)
|
||||
if ( !strcmp( wicones->entry[i].name, new_name))
|
||||
{
|
||||
errshow( "", E_NAMEEXIST);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
if ( rename( wicones->first_selected->name, new_name) != 0)
|
||||
{
|
||||
errshow( wicones->first_selected->name, errno);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
strcpy( wicones->first_selected->name, new_name);
|
||||
|
||||
set_entry_icon( wicones->first_selected);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
2
sources/z-tools/trunk/zview/file/rename.h
Normal file
2
sources/z-tools/trunk/zview/file/rename.h
Normal file
@@ -0,0 +1,2 @@
|
||||
extern boolean rename_entry( WINDOW *win, const char *new_name);
|
||||
|
||||
159
sources/z-tools/trunk/zview/file/sort.c
Normal file
159
sources/z-tools/trunk/zview/file/sort.c
Normal file
@@ -0,0 +1,159 @@
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* Sortring Operations */
|
||||
/*------------------- ---------------------------------------------------*/
|
||||
#include "..//general.h"
|
||||
#include "..//ztext.h"
|
||||
#include "..//prefs.h"
|
||||
|
||||
/* prototype */
|
||||
int cmp_entries_name( const void *obj_a, const void *obj_b);
|
||||
static int cmp_entries_size( const void *obj_a, const void *obj_b);
|
||||
static int cmp_entries_date( const void *obj_a, const void *obj_b);
|
||||
static int cmp_entries_dirsbeforefiles(const void *obj_a, const void *obj_b);
|
||||
int16 sort_entries( WINDICON *dirfile);
|
||||
|
||||
|
||||
int cmp_entries_name(const void *obj_a, const void *obj_b)
|
||||
{
|
||||
Entry *entry_a;
|
||||
Entry *entry_b;
|
||||
int cmp_val;
|
||||
char name_a[256];
|
||||
char name_b[256];
|
||||
|
||||
entry_a = (Entry *)obj_a;
|
||||
entry_b = (Entry *)obj_b;
|
||||
|
||||
strcpy(name_a, entry_a->name);
|
||||
str2lower(name_a);
|
||||
strcpy(name_b, entry_b->name);
|
||||
str2lower(name_b);
|
||||
|
||||
cmp_val = strcmp(name_a, name_b);
|
||||
|
||||
return cmp_val;
|
||||
}
|
||||
|
||||
|
||||
static int cmp_entries_size(const void *obj_a, const void *obj_b)
|
||||
{
|
||||
Entry *entry_a;
|
||||
Entry *entry_b;
|
||||
int cmp_val;
|
||||
int32 size_a;
|
||||
int32 size_b;
|
||||
|
||||
entry_a = (Entry *)obj_a;
|
||||
entry_b = (Entry *)obj_b;
|
||||
|
||||
size_a = entry_a->stat.st_size;
|
||||
size_b = entry_b->stat.st_size;
|
||||
|
||||
if ( size_a < size_b)
|
||||
cmp_val = -1;
|
||||
else if ( size_a == size_b)
|
||||
cmp_val = 0;
|
||||
else
|
||||
cmp_val = 1;
|
||||
|
||||
return cmp_val;
|
||||
}
|
||||
|
||||
|
||||
static int cmp_entries_date(const void *obj_a, const void *obj_b)
|
||||
{
|
||||
Entry *entry_a;
|
||||
Entry *entry_b;
|
||||
int cmp_val;
|
||||
int32 date_a;
|
||||
int32 date_b;
|
||||
|
||||
entry_a = (Entry *)obj_a;
|
||||
entry_b = (Entry *)obj_b;
|
||||
|
||||
date_a = entry_a->stat.st_mtime;
|
||||
date_b = entry_b->stat.st_mtime;
|
||||
|
||||
if ( date_a < date_b)
|
||||
cmp_val = -1;
|
||||
else if ( date_a == date_b)
|
||||
cmp_val = 0;
|
||||
else
|
||||
cmp_val = 1;
|
||||
|
||||
return cmp_val;
|
||||
}
|
||||
|
||||
|
||||
static int cmp_entries_dirsbeforefiles(const void *obj_a, const void *obj_b)
|
||||
{
|
||||
Entry *entry_a;
|
||||
Entry *entry_b;
|
||||
int cmp_val;
|
||||
|
||||
entry_a = (Entry *)obj_a;
|
||||
entry_b = (Entry *)obj_b;
|
||||
|
||||
|
||||
if ( entry_a->type == ET_DIR)
|
||||
cmp_val = ( ( entry_b->type == ET_DIR) ? 0 : -1);
|
||||
else
|
||||
cmp_val = ( ( entry_b->type == ET_DIR) ? 1 : 0);
|
||||
|
||||
return cmp_val;
|
||||
}
|
||||
|
||||
|
||||
int16 sort_entries( WINDICON *dirfile)
|
||||
{
|
||||
int16 nb_of_dirs = 0;
|
||||
|
||||
if ( dirfile->nbr_icons < 2)
|
||||
return 1;
|
||||
|
||||
switch ( sortingmode)
|
||||
{
|
||||
case 0: /* directories before files */
|
||||
/* get number of directories */
|
||||
qsort(dirfile->entry, dirfile->nbr_icons, sizeof(Entry), cmp_entries_dirsbeforefiles);
|
||||
while ( (nb_of_dirs < dirfile->nbr_icons) && ( dirfile->entry[nb_of_dirs].type == ET_DIR))
|
||||
nb_of_dirs++;
|
||||
/* sort directories */
|
||||
if (nb_of_dirs > 1)
|
||||
qsort(dirfile->entry, nb_of_dirs, sizeof(Entry), cmp_entries_name);
|
||||
/* sort files */
|
||||
if (dirfile->nbr_icons - nb_of_dirs > 1)
|
||||
qsort(&dirfile->entry[nb_of_dirs], dirfile->nbr_icons - nb_of_dirs, sizeof(Entry), cmp_entries_name);
|
||||
break;
|
||||
|
||||
case 1 :
|
||||
/* get number of directories */
|
||||
qsort(dirfile->entry, dirfile->nbr_icons, sizeof(Entry), cmp_entries_dirsbeforefiles);
|
||||
while ( (nb_of_dirs < dirfile->nbr_icons) && ( dirfile->entry[nb_of_dirs].type == ET_DIR))
|
||||
nb_of_dirs++;
|
||||
/* sort directories */
|
||||
if (nb_of_dirs > 1)
|
||||
qsort(dirfile->entry, nb_of_dirs, sizeof(Entry), cmp_entries_name);
|
||||
/* sort files */
|
||||
if (dirfile->nbr_icons - nb_of_dirs > 1)
|
||||
qsort(&dirfile->entry[nb_of_dirs], dirfile->nbr_icons - nb_of_dirs, sizeof(Entry), cmp_entries_size);
|
||||
break;
|
||||
|
||||
case 2 : /* files before directories */
|
||||
/* get number of directories */
|
||||
qsort(dirfile->entry, dirfile->nbr_icons, sizeof(Entry), cmp_entries_dirsbeforefiles);
|
||||
while ( (nb_of_dirs < dirfile->nbr_icons) && ( dirfile->entry[nb_of_dirs].type == ET_DIR))
|
||||
nb_of_dirs++;
|
||||
/* sort directories */
|
||||
if (nb_of_dirs > 1)
|
||||
qsort(dirfile->entry, nb_of_dirs, sizeof(Entry), cmp_entries_name);
|
||||
/* sort files */
|
||||
if (dirfile->nbr_icons - nb_of_dirs > 1)
|
||||
qsort(&dirfile->entry[nb_of_dirs], dirfile->nbr_icons - nb_of_dirs, sizeof(Entry), cmp_entries_date);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
2
sources/z-tools/trunk/zview/file/sort.h
Normal file
2
sources/z-tools/trunk/zview/file/sort.h
Normal file
@@ -0,0 +1,2 @@
|
||||
extern int16 sort_entries( WINDICON *dirfile);
|
||||
extern int cmp_entries_name(const void *obj_a, const void *obj_b);
|
||||
Reference in New Issue
Block a user