Skip to content

Commit

Permalink
Refactor file saving functions to check for existing files
Browse files Browse the repository at this point in the history
Updated _saveOptionsContentToFile and _saveFeedbackImage functions to check
if the target file already exists before creating a new one. If the file
exists, it is deleted first to ensure a fresh file is created each time.
This prevents potential issues with outdated or incorrect file data.

Changes:
- Added file existence check and deletion in _saveOptionsContentToFile.
- Added file existence check and deletion in _saveFeedbackImage.
  • Loading branch information
calcitem committed Jun 29, 2024
1 parent 38a50b8 commit b6ce175
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/ui/flutter_app/lib/home/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,11 @@ class HomeState extends State<Home> with TickerProviderStateMixin {
static Future<String> _saveOptionsContentToFile(String content) async {
final Directory output = await getTemporaryDirectory();
final File file = File('${output.path}/options.txt');

if (await file.exists()) {

Check warning on line 495 in src/ui/flutter_app/lib/home/home.dart

View workflow job for this annotation

GitHub Actions / Lint flutter code

Use of an async 'dart:io' method.. See https://dart.dev/tools/diagnostic-messages#avoid_slow_async_io
await file.delete();
}

await file.writeAsString(content);
return file.path;
}
Expand All @@ -499,6 +504,11 @@ class HomeState extends State<Home> with TickerProviderStateMixin {
final Directory output = await getTemporaryDirectory();
final String screenshotFilePath = "${output.path}/sanmill-feedback.png";
final File screenshotFile = File(screenshotFilePath);

if (await screenshotFile.exists()) {

Check warning on line 508 in src/ui/flutter_app/lib/home/home.dart

View workflow job for this annotation

GitHub Actions / Lint flutter code

Use of an async 'dart:io' method.. See https://dart.dev/tools/diagnostic-messages#avoid_slow_async_io
await screenshotFile.delete();
}

await screenshotFile.writeAsBytes(screenshot);
return screenshotFilePath;
}
Expand Down

0 comments on commit b6ce175

Please sign in to comment.