From 8339101c9c4d45257182f1db8efd4c362153f430 Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Sat, 1 Jun 2024 09:30:58 -0600 Subject: [PATCH 1/2] Test write to file directly on o2rs --- lib/arc/arc.dart | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/arc/arc.dart b/lib/arc/arc.dart index 72dab16..2f320ec 100644 --- a/lib/arc/arc.dart +++ b/lib/arc/arc.dart @@ -4,7 +4,7 @@ import 'dart:async'; import 'dart:io'; import 'dart:typed_data'; -import 'package:archive/archive.dart'; +import 'package:archive/archive_io.dart'; import 'package:flutter_storm/flutter_storm.dart'; import 'package:flutter_storm/flutter_storm_defines.dart'; import 'package:retro/utils/log.dart'; @@ -14,8 +14,8 @@ enum ArcMode { } class Arc { + static ZipDecoder zdec = ZipDecoder(); - static ZipEncoder zenc = ZipEncoder(); dynamic handle; String path; @@ -36,7 +36,7 @@ class Arc { if(file.existsSync()) { handle = zdec.decodeBytes(file.readAsBytesSync()); } else { - handle = Archive(); + handle = ZipFileEncoder()..createWithBuffer(OutputFileStream(path)); } break; } @@ -100,6 +100,9 @@ class Arc { } Future?> _listZipFiles({ FutureOr Function(String, Uint8List)? onFile }) async { + if(handle is! Archive) { + return []; + } final files = []; final archive = handle as Archive; for (final file in archive) { @@ -120,11 +123,11 @@ class Arc { } void _addZipFile(String path, Uint8List data, bool compress) { - final archive = handle as Archive; + final archive = handle as ZipFileEncoder; if(compress) { - archive.addFile(ArchiveFile(path, data.length, data)); + archive.addArchiveFile(ArchiveFile(path, data.length, data)); } else { - archive.addFile(ArchiveFile.noCompress(path, data.length, data)); + archive.addArchiveFile(ArchiveFile.noCompress(path, data.length, data)); } } @@ -134,13 +137,12 @@ class Arc { } void _closeZip() { - final archive = handle as Archive; - final file = File(path); - final fileBytes = zenc.encode(archive); - if(fileBytes == null) { - throw Exception('Failed to encode archive'); + if(handle is! ZipFileEncoder) { + return; } - file.writeAsBytesSync(fileBytes); + + final archive = handle as ZipFileEncoder; + archive.close(); } Future?> listItems({ FutureOr Function(String, Uint8List)? onFile }) { From cee573828cdbc469669674306414dbaf8ad67859 Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Sat, 1 Jun 2024 10:14:19 -0600 Subject: [PATCH 2/2] Changed dumb validation --- .../create/create_finish/create_finish_viewmodel.dart | 6 ++---- lib/models/texture_manifest_entry.dart | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/features/create/create_finish/create_finish_viewmodel.dart b/lib/features/create/create_finish/create_finish_viewmodel.dart index 7d7ac5c..4530fbf 100644 --- a/lib/features/create/create_finish/create_finish_viewmodel.dart +++ b/lib/features/create/create_finish/create_finish_viewmodel.dart @@ -315,10 +315,8 @@ Future processPNG( return null; } - texture..textureType = pair.item2.textureType - ..isPalette = image.hasPalette && - (texture.textureType == TextureType.Palette4bpp || - texture.textureType == TextureType.Palette8bpp); + texture.textureType = pair.item2.textureType; + texture.isPalette = image.hasPalette && (texture.textureType == TextureType.Palette4bpp || texture.textureType == TextureType.Palette8bpp); final isNotOriginalSize = pair.item2.textureWidth != image.width || pair.item2.textureHeight != image.height; diff --git a/lib/models/texture_manifest_entry.dart b/lib/models/texture_manifest_entry.dart index 107d20d..d53251d 100644 --- a/lib/models/texture_manifest_entry.dart +++ b/lib/models/texture_manifest_entry.dart @@ -4,7 +4,7 @@ class TextureManifestEntry { TextureManifestEntry(this.hash, this.textureType, this.textureWidth, this.textureHeight); - factory TextureManifestEntry.fromJson(dynamic json) { + factory TextureManifestEntry.fromJson(Map json) { return TextureManifestEntry( json['hash'] as String, TextureType.values[json['textureType'] as int],