mirror of
https://github.com/FoggedLens/deflock-app.git
synced 2026-07-06 04:37:56 +02:00
broke download dialog, cleaned up debug stuff
This commit is contained in:
@@ -11,42 +11,22 @@ Future<List<int>> fetchLocalTile({required int z, required int x, required int y
|
|||||||
final areas = offlineService.offlineAreas;
|
final areas = offlineService.offlineAreas;
|
||||||
final List<_AreaTileMatch> candidates = [];
|
final List<_AreaTileMatch> candidates = [];
|
||||||
|
|
||||||
print('[fetchLocalTile] Looking for tile $z/$x/$y in ${areas.length} offline areas');
|
|
||||||
|
|
||||||
for (final area in areas) {
|
for (final area in areas) {
|
||||||
print('[fetchLocalTile] Checking area: ${area.id}, status: ${area.status}, zoom: ${area.minZoom}-${area.maxZoom}');
|
if (area.status != OfflineAreaStatus.complete) continue;
|
||||||
|
if (z < area.minZoom || z > area.maxZoom) continue;
|
||||||
if (area.status != OfflineAreaStatus.complete) {
|
|
||||||
print('[fetchLocalTile] Skipping area ${area.id} - status not complete: ${area.status}');
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (z < area.minZoom || z > area.maxZoom) {
|
|
||||||
print('[fetchLocalTile] Skipping area ${area.id} - zoom $z outside range ${area.minZoom}-${area.maxZoom}');
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get tile coverage for area at this zoom only
|
// Get tile coverage for area at this zoom only
|
||||||
final coveredTiles = computeTileList(area.bounds, z, z);
|
final coveredTiles = computeTileList(area.bounds, z, z);
|
||||||
final hasTile = coveredTiles.any((tile) => tile[0] == z && tile[1] == x && tile[2] == y);
|
final hasTile = coveredTiles.any((tile) => tile[0] == z && tile[1] == x && tile[2] == y);
|
||||||
print('[fetchLocalTile] Area ${area.id} covers ${coveredTiles.length} tiles at zoom $z, contains target tile: $hasTile');
|
|
||||||
|
|
||||||
if (hasTile) {
|
if (hasTile) {
|
||||||
final tilePath = _tilePath(area.directory, z, x, y);
|
final tilePath = _tilePath(area.directory, z, x, y);
|
||||||
final file = File(tilePath);
|
final file = File(tilePath);
|
||||||
final exists = await file.exists();
|
if (await file.exists()) {
|
||||||
print('[fetchLocalTile] Tile file path: $tilePath, exists: $exists');
|
|
||||||
|
|
||||||
if (exists) {
|
|
||||||
final stat = await file.stat();
|
final stat = await file.stat();
|
||||||
candidates.add(_AreaTileMatch(area: area, file: file, modified: stat.modified));
|
candidates.add(_AreaTileMatch(area: area, file: file, modified: stat.modified));
|
||||||
print('[fetchLocalTile] Added candidate from area ${area.id}');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print('[fetchLocalTile] Found ${candidates.length} candidates for tile $z/$x/$y');
|
|
||||||
|
|
||||||
if (candidates.isEmpty) {
|
if (candidates.isEmpty) {
|
||||||
throw Exception('Tile $z/$x/$y not found in any offline area');
|
throw Exception('Tile $z/$x/$y not found in any offline area');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ class OfflineAreaService {
|
|||||||
await _loadAreasFromDisk();
|
await _loadAreasFromDisk();
|
||||||
await _ensureAndAutoDownloadWorldArea();
|
await _ensureAndAutoDownloadWorldArea();
|
||||||
_initialized = true;
|
_initialized = true;
|
||||||
print('OfflineAreaService: Initialization complete. Found ${_areas.length} offline areas.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Directory> getOfflineAreaDir() async {
|
Future<Directory> getOfflineAreaDir() async {
|
||||||
@@ -58,7 +57,6 @@ class OfflineAreaService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<int> getAreaSizeBytes(OfflineArea area) async {
|
Future<int> getAreaSizeBytes(OfflineArea area) async {
|
||||||
print('[getAreaSizeBytes] Starting for area ${area.id}, status: ${area.status}');
|
|
||||||
int total = 0;
|
int total = 0;
|
||||||
final dir = Directory(area.directory);
|
final dir = Directory(area.directory);
|
||||||
if (await dir.exists()) {
|
if (await dir.exists()) {
|
||||||
@@ -69,9 +67,7 @@ class OfflineAreaService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
area.sizeBytes = total;
|
area.sizeBytes = total;
|
||||||
print('[getAreaSizeBytes] Before saveAreasToDisk, area ${area.id} status: ${area.status}');
|
|
||||||
await saveAreasToDisk();
|
await saveAreasToDisk();
|
||||||
print('[getAreaSizeBytes] After saveAreasToDisk, area ${area.id} status: ${area.status}');
|
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +83,6 @@ class OfflineAreaService {
|
|||||||
if (json['directory'].toString().startsWith(offlineDir.path)) {
|
if (json['directory'].toString().startsWith(offlineDir.path)) {
|
||||||
final relativePath = json['directory'].toString().replaceFirst('${offlineDir.path}/', '');
|
final relativePath = json['directory'].toString().replaceFirst('${offlineDir.path}/', '');
|
||||||
json['directory'] = relativePath;
|
json['directory'] = relativePath;
|
||||||
print('[OfflineAreaService] Saving area ${area.id} with relative path: $relativePath');
|
|
||||||
}
|
}
|
||||||
return json;
|
return json;
|
||||||
}).toList();
|
}).toList();
|
||||||
@@ -133,29 +128,20 @@ class OfflineAreaService {
|
|||||||
final offlineDir = await getOfflineAreaDir();
|
final offlineDir = await getOfflineAreaDir();
|
||||||
final fullPath = '${offlineDir.path}/$relativePath';
|
final fullPath = '${offlineDir.path}/$relativePath';
|
||||||
|
|
||||||
print('[OfflineAreaService] Area ${areaJson['id']}: stored="$storedDir", relative="$relativePath", full="$fullPath"');
|
|
||||||
|
|
||||||
// Update the JSON to use the full path for this session
|
// Update the JSON to use the full path for this session
|
||||||
areaJson['directory'] = fullPath;
|
areaJson['directory'] = fullPath;
|
||||||
|
|
||||||
final area = OfflineArea.fromJson(areaJson);
|
final area = OfflineArea.fromJson(areaJson);
|
||||||
|
|
||||||
if (!Directory(area.directory).existsSync()) {
|
if (!Directory(area.directory).existsSync()) {
|
||||||
print('[OfflineAreaService] Directory does not exist: ${area.directory}');
|
|
||||||
area.status = OfflineAreaStatus.error;
|
area.status = OfflineAreaStatus.error;
|
||||||
} else {
|
} else {
|
||||||
print('[OfflineAreaService] Directory exists, getting size...');
|
|
||||||
|
|
||||||
// Reset error status if directory now exists (fixes areas that were previously broken due to path issues)
|
// Reset error status if directory now exists (fixes areas that were previously broken due to path issues)
|
||||||
if (area.status == OfflineAreaStatus.error) {
|
if (area.status == OfflineAreaStatus.error) {
|
||||||
print('[OfflineAreaService] Resetting error status to complete for area ${area.id} since directory now exists');
|
|
||||||
area.status = OfflineAreaStatus.complete;
|
area.status = OfflineAreaStatus.complete;
|
||||||
}
|
}
|
||||||
|
|
||||||
print('[OfflineAreaService] Status before getAreaSizeBytes: ${area.status}');
|
|
||||||
getAreaSizeBytes(area);
|
getAreaSizeBytes(area);
|
||||||
print('[OfflineAreaService] Status after getAreaSizeBytes: ${area.status}');
|
|
||||||
print('[OfflineAreaService] Area ${area.id} loaded successfully');
|
|
||||||
}
|
}
|
||||||
_areas.add(area);
|
_areas.add(area);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user