checkFile static method

Future<bool> checkFile(
  1. String folder,
  2. String oldFile,
  3. String newFile
)

Проверка существования файла

Implementation

static Future<bool> checkFile(
  String folder,
  String oldFile,
  String newFile,
) async {
  final tempDir = await tempFolder;
  final name = newFile.split('/').last.split('.').first;
  final ext = getFileExt(newFile);
  final singleName = '$name$ext';
  final tileName = '${name}_{0}_{1}_{2}$ext';

  final singlePath = '$tempDir/$folder/$singleName';
  final singleExists = await File(singlePath).exists();

  if (oldFile == singleName || oldFile == tileName || !singleExists) {
    return true;
  }

  // Проверяем тайлы
  final tilePattern = tileName
      .replaceAll('{0}', '*')
      .replaceAll('{1}', '*')
      .replaceAll('{2}', '*');
  final tileDir = Directory('$tempDir/$folder');
  if (await tileDir.exists()) {
    final files = await tileDir.list().toList();
    return !files.any((file) => file.path.contains(tilePattern));
  }

  return true;
}