Skip to content

Commit

Permalink
Write to file directly on o2rs (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
KiritoDv authored Jun 1, 2024
1 parent c1be413 commit 4acb537
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
26 changes: 14 additions & 12 deletions lib/arc/arc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -14,8 +14,8 @@ enum ArcMode {
}

class Arc {

static ZipDecoder zdec = ZipDecoder();
static ZipEncoder zenc = ZipEncoder();

dynamic handle;
String path;
Expand All @@ -36,7 +36,7 @@ class Arc {
if(file.existsSync()) {
handle = zdec.decodeBytes(file.readAsBytesSync());
} else {
handle = Archive();
handle = ZipFileEncoder()..createWithBuffer(OutputFileStream(path));
}
break;
}
Expand Down Expand Up @@ -100,6 +100,9 @@ class Arc {
}

Future<List<String>?> _listZipFiles({ FutureOr<void> Function(String, Uint8List)? onFile }) async {
if(handle is! Archive) {
return [];
}
final files = <String>[];
final archive = handle as Archive;
for (final file in archive) {
Expand All @@ -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));
}
}

Expand All @@ -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<List<String>?> listItems({ FutureOr<void> Function(String, Uint8List)? onFile }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,8 @@ Future<Uint8List?> 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;
Expand Down
2 changes: 1 addition & 1 deletion lib/models/texture_manifest_entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class TextureManifestEntry {

TextureManifestEntry(this.hash, this.textureType, this.textureWidth, this.textureHeight);

factory TextureManifestEntry.fromJson(dynamic json) {
factory TextureManifestEntry.fromJson(Map<String, dynamic> json) {
return TextureManifestEntry(
json['hash'] as String,
TextureType.values[json['textureType'] as int],
Expand Down

0 comments on commit 4acb537

Please sign in to comment.