1024) {$size/=1024; $suffix=$suxAry[$cnt];} return $suffix?sprintf("%.1f",$size).$suffix:$size.'B'; } function countchar($str,$chr) { return (strlen($str) - strlen(str_replace($chr,'',$str))) / strlen($chr); } function mysort($a, $b) { // row(md5,size,path) $a,$b global $excludes_order,$includes_order,$normal_depth; // basic sort first if($a['size'] != $b['size']) return $a['size'] > $b['size'] ? -1 : 1; if($a['md5'] != $b['md5']) return strnatcmp($a['md5'], $b['md5']); // $a_pathdepth = countchar($a['path'],'/'); // $b_pathdepth = countchar($b['path'],'/'); // deeper path first if(($a['depth'] + $b['depth']) > $normal_depth*2) { if($a['depth'] == $b['depth']) return strnatcmp($a['path'], $b['path']); return $a['depth'] > $b['depth'] ? -1 : 1; } // exclude foreach($excludes_order as $excl) { $a_exclude = !!strstr($a['path'],$excl); $b_exclude = !!strstr($b['path'],$excl); if($a_exclude + $b_exclude) { if($a_exclude == $b_exclude) return strnatcmp(basename($a['path']), basename($b['path'])); else return $a_exclude ? 1 : -1; } } // include foreach($includes_order as $incl) { $a_include = preg_match('|'.$incl.'|i',$a['path']); $b_include = preg_match('|'.$incl.'|i',$b['path']); if($a_include + $b_include) { if($a_include == $b_include) return strnatcmp(basename($a['path']), basename($b['path'])); else return $a_include ? -1 : 1; } } // last: strnatcmp return strnatcmp($a['path'], $b['path']); } function read_and_sort($file, &$ary,$names_only=false) { $ary = array('files'=>array(),'names'=>array()); $f = file(basename($file)); foreach($f as $line) { $file = array(); list($file['md5'],$file['size'],$file['path']) = explode("\t",rtrim($line)); if(!$names_only) { $file['depth'] = countchar($file['path'],'/'); $ary['files'][] = $file; } $ary['names'][$file['path']] = array('md5'=>$file['md5'],'size'=>$file['size']); } if(!$names_only) usort($ary['files'],'mysort'); } function hdr() { // header('Content-Type: text/html; charset=big5'); echo ' Dup Selector '; } function select_file() { $fs = glob('*.txt'); hdr(); foreach ($fs as $f) echo $f.' DupSelect CalcTotal
'; echo ''; } function generate_new_list() { $my_ary = array(); $fp = fopen(substr(basename($_GET['file']),0,-4).'-delete.lst','wb+'); fwrite($fp,implode("\n",$_POST['files'])); fclose($fp); read_and_sort($_GET['file'],$my_ary,true); $fp = fopen(substr(basename($_GET['file']),0,-4).'-delete.txt','wb+'); foreach($_POST['files'] as $f) fwrite($fp,$my_ary['names'][$f]['md5']."\t".$my_ary['names'][$f]['size']."\t$f\n"); fclose($fp); hdr(); echo '
';
	print_r($_POST['files']);
	echo '
'; } function calc_total() { $my_ary = array(); read_and_sort($_GET['file'],$my_ary,true); $fsize = 0; hdr(); echo '
';
	echo "           Size  MD5       Filename\n";
	echo "--------------------------------------------------------------\n";
	foreach($my_ary['names'] as $f=>$g) {
		$fsize += $g['size'];
		echo str_pad(number_format($g['size'],0,'.',','),15,' ',STR_PAD_LEFT).'  '.$g['md5']."  $f\n";
	}
	echo 'Total: '.proper_size($fsize).' ('.number_format($fsize,0,'.',',').')
'; echo '
'; } function dupselect_ui() { global $deselects,$normal_depth; $my_ary = array(); read_and_sort($_GET['file'],$my_ary); $perv_md5='';$perv_depth=0; $twostar=false; $deselect=false; hdr(); echo '
'."\n"; echo ''."\n"; foreach($my_ary['files'] as $f) { if($perv_md5 != $f['md5']) { $twostar=false; $deselect=true; $perv_depth=0; echo "
\n"; } else { $deselect=false; } foreach($deselects as $d) { if(strstr($f['path'],$d)) { $deselect=true; break; } } echo '
\n"; if($perv_depth>$normal_depth && $f['depth']>$normal_depth) $twostar=true; $perv_md5 = $f['md5']; $perv_depth = $f['depth']; } echo '
'; }