Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

scandirs.cpp 4.35 KB
Newer Older
1 2 3 4 5 6
/* Synchronet file database scanning routines */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
7
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 *																			*
 * This program is free software; you can redistribute it and/or			*
 * modify it under the terms of the GNU General Public License				*
 * as published by the Free Software Foundation; either version 2			*
 * of the License, or (at your option) any later version.					*
 * See the GNU General Public License for more details: gpl.txt or			*
 * http://www.fsf.org/copyleft/gpl.html										*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

#include "sbbs.h"

/****************************************************************************/
/* Used to scan single or multiple directories. 'mode' is the scan type.    */
/****************************************************************************/
void sbbs_t::scandirs(long mode)
{
29
	char	ch,str[256]="";
30 31
	int		s;
	uint	i,k;
32 33 34 35 36 37

	if(!usrlibs) return;
	mnemonics(text[DirLibOrAll]);
	ch=(char)getkeys("DLA\r",0);
	if(sys_status&SS_ABORT || ch==CR) {
		lncntr=0;
38 39
		return; 
	}
40 41
	if(ch!='A') {
		if(mode&FL_ULTIME) {			/* New file scan */
42
			bprintf(text[NScanHdr],timestr(ns_time));
43
		}
44
		else if(mode==FL_NO_HDR) {		/* Search for a string */
45
			if(!getfilespec(str))
46
				return;
47
		}
48
		else if(mode==FL_FINDDESC) {	/* Find text in description */
49
			if(text[SearchExtendedQ][0] && !noyes(text[SearchExtendedQ]))
50 51 52
				mode=FL_EXFIND;
			if(sys_status&SS_ABORT) {
				lncntr=0;
53 54
				return; 
			}
55 56 57
			bputs(text[SearchStringPrompt]);
			if(!getstr(str,40,K_LINE|K_UPPER)) {
				lncntr=0;
58 59 60 61
				return; 
			} 
		}
	}
62 63 64
	if(ch=='D') {
		if((s=listfiles(usrdir[curlib][curdir[curlib]],str,0,mode))==-1)
			return;
rswindell's avatar
rswindell committed
65
		bputs(text[Scanned]);
66 67 68 69
		if(s>1)
			bprintf(text[NFilesListed],s);
		else if(!s && !(mode&FL_ULTIME))
			bputs(text[FileNotFound]);
70 71
		return; 
	}
72 73 74
	if(ch=='L') {
		k=0;
		for(i=0;i<usrdirs[curlib] && !msgabort();i++) {
rswindell's avatar
rswindell committed
75
			progress(text[Scanning], i, usrdirs[curlib], 10);
76 77 78 79 80 81
			if(mode&FL_ULTIME	/* New-scan */
				&& (cfg.lib[usrlib[curlib]]->offline_dir==usrdir[curlib][i]
				|| cfg.dir[usrdir[curlib][i]]->misc&DIR_NOSCAN))
				continue;
			else if((s=listfiles(usrdir[curlib][i],str,0,mode))==-1)
				return;
82 83
			else k+=s; 
		}
rswindell's avatar
rswindell committed
84 85
		progress(text[Done], i, usrdirs[curlib]);
		bputs(text[Scanned]);
86 87 88 89
		if(k>1)
			bprintf(text[NFilesListed],k);
		else if(!k && !(mode&FL_ULTIME))
			bputs(text[FileNotFound]);
90 91
		return; 
	}
92 93 94 95 96 97 98 99 100

	scanalldirs(mode);
}

/****************************************************************************/
/* Scan all directories in all libraries for files							*/
/****************************************************************************/
void sbbs_t::scanalldirs(long mode)
{
101
	char	str[256]="";
102 103
	int		s;
	uint	i,j,k,d;
104 105 106 107

	if(!usrlibs) return;
	k=0;
	if(mode&FL_ULTIME) {			/* New file scan */
108
		bprintf(text[NScanHdr],timestr(ns_time));
109
	}
110
	else if(mode==FL_NO_HDR) {		/* Search for a string */
111
		if(!getfilespec(str))
112
			return;
113
	}
114
	else if(mode==FL_FINDDESC) {	/* Find text in description */
115
		if(text[SearchExtendedQ][0] && !noyes(text[SearchExtendedQ]))
116 117 118
			mode=FL_EXFIND;
		if(sys_status&SS_ABORT) {
			lncntr=0;
119 120
			return; 
		}
121 122 123
		bputs(text[SearchStringPrompt]);
		if(!getstr(str,40,K_LINE|K_UPPER)) {
			lncntr=0;
124 125 126
			return; 
		}
	}
127 128 129
	unsigned total_dirs = 0;
	for(i=0; i < usrlibs ;i++)
		total_dirs += usrdirs[i];
130 131
	for(i=d=0;i<usrlibs;i++) {
		for(j=0;j<usrdirs[i] && !msgabort();j++,d++) {
rswindell's avatar
rswindell committed
132
			progress(text[Scanning], d, total_dirs, 10);
133 134 135 136
			if(mode&FL_ULTIME /* New-scan */
				&& (cfg.lib[usrlib[i]]->offline_dir==usrdir[i][j]
				|| cfg.dir[usrdir[i][j]]->misc&DIR_NOSCAN))
				continue;
137
			else if((s=listfiles(usrdir[i][j],str,0,mode))==-1) {
rswindell's avatar
rswindell committed
138
				bputs(text[Scanned]);
139
				return;
140
			}
141 142
			else k+=s; 
		}
143
		if(j<usrdirs[i])   /* aborted */
144 145
			break; 
	}
rswindell's avatar
rswindell committed
146 147
	progress(text[Done], d, total_dirs);
	bputs(text[Scanned]);
148 149 150 151 152 153
	if(k>1)
		bprintf(text[NFilesListed],k);
	else if(!k && !(mode&FL_ULTIME))
		bputs(text[FileNotFound]);
}