mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
#144 opt.: only show decompress option when valid
This commit is contained in:
@@ -136,16 +136,15 @@ class PsResult {
|
|||||||
);
|
);
|
||||||
|
|
||||||
final procs = <Proc>[];
|
final procs = <Proc>[];
|
||||||
var err = '';
|
final errs = <String>[];
|
||||||
for (var i = 1; i < lines.length; i++) {
|
for (var i = 1; i < lines.length; i++) {
|
||||||
final line = lines[i];
|
final line = lines[i];
|
||||||
if (line.isEmpty) continue;
|
if (line.isEmpty) continue;
|
||||||
try {
|
try {
|
||||||
procs.add(Proc.parse(line, map));
|
procs.add(Proc.parse(line, map));
|
||||||
} catch (e, trace) {
|
} catch (e, trace) {
|
||||||
err += '$line: $e\n';
|
errs.add('$line: $e');
|
||||||
_logger.warning(trace);
|
_logger.warning(trace);
|
||||||
rethrow;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +165,7 @@ class PsResult {
|
|||||||
procs.sort((a, b) => a.binary.compareTo(b.binary));
|
procs.sort((a, b) => a.binary.compareTo(b.binary));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return PsResult(procs: procs, error: err.isEmpty ? null : err);
|
return PsResult(procs: procs, error: errs.isEmpty ? null : errs.join('\n'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -344,7 +344,8 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
|
|||||||
title: Text(_s.download),
|
title: Text(_s.download),
|
||||||
onTap: () => _download(context, file),
|
onTap: () => _download(context, file),
|
||||||
),
|
),
|
||||||
ListTile(
|
// Only show decompress option when the file is a compressed file
|
||||||
|
if (_canDecompress(file.filename)) ListTile(
|
||||||
leading: const Icon(Icons.folder_zip),
|
leading: const Icon(Icons.folder_zip),
|
||||||
title: Text(_s.decompress),
|
title: Text(_s.decompress),
|
||||||
onTap: () => _decompress(context, file),
|
onTap: () => _decompress(context, file),
|
||||||
@@ -717,6 +718,15 @@ String? _getDecompressCmd(String filename) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _canDecompress(String filename) {
|
||||||
|
for (final ext in _extCmdMap.keys) {
|
||||||
|
if (filename.endsWith('.$ext')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// Translate from
|
/// Translate from
|
||||||
/// https://github.com/ohmyzsh/ohmyzsh/blob/03a0d5bbaedc732436b5c67b166cde954817cc2f/plugins/extract/extract.plugin.zsh
|
/// https://github.com/ohmyzsh/ohmyzsh/blob/03a0d5bbaedc732436b5c67b166cde954817cc2f/plugins/extract/extract.plugin.zsh
|
||||||
const _extCmdMap = {
|
const _extCmdMap = {
|
||||||
@@ -752,11 +762,11 @@ const _extCmdMap = {
|
|||||||
'rar': 'unrar x -ad FILE',
|
'rar': 'unrar x -ad FILE',
|
||||||
'rpm': 'rpm2cpio FILE | cpio --quiet -id',
|
'rpm': 'rpm2cpio FILE | cpio --quiet -id',
|
||||||
'7z': '7za x FILE',
|
'7z': '7za x FILE',
|
||||||
'deb': 'mkdir -p "control" "data"'
|
// 'deb': 'mkdir -p "control" "data"'
|
||||||
'ar vx FILE > /dev/null'
|
// 'ar vx FILE > /dev/null'
|
||||||
'cd control; extract ../control.tar.*'
|
// 'cd control; extract ../control.tar.*'
|
||||||
'cd ../data; extract ../data.tar.*'
|
// 'cd ../data; extract ../data.tar.*'
|
||||||
'cd ..; rm *.tar.* debian-binary',
|
// 'cd ..; rm *.tar.* debian-binary',
|
||||||
'zst': 'unzstd FILE',
|
'zst': 'unzstd FILE',
|
||||||
'cab': 'cabextract FILE',
|
'cab': 'cabextract FILE',
|
||||||
'exe': 'cabextract FILE',
|
'exe': 'cabextract FILE',
|
||||||
|
|||||||
Reference in New Issue
Block a user