renaming to Thermion
This commit is contained in:
28
thermion_dart/lib/thermion_dart/utils/dart_resources.dart
Normal file
28
thermion_dart/lib/thermion_dart/utils/dart_resources.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import '../compatibility/compatibility.dart';
|
||||
import 'package:ffi/ffi.dart' hide Utf8Pointer;
|
||||
|
||||
class DartResourceLoader {
|
||||
static final _assets = <int, Pointer>{};
|
||||
static void loadResource(Pointer<Char> uri, Pointer<ResourceBuffer> out) {
|
||||
try {
|
||||
var data = File(uri.cast<Utf8>().toDartString().replaceAll("file://", ""))
|
||||
.readAsBytesSync();
|
||||
var ptr = calloc<Uint8>(data.lengthInBytes);
|
||||
ptr.asTypedList(data.lengthInBytes).setRange(0, data.lengthInBytes, data);
|
||||
|
||||
out.ref.data = ptr.cast<Void>();
|
||||
out.ref.size = data.lengthInBytes;
|
||||
out.ref.id = _assets.length;
|
||||
_assets[out.ref.id] = ptr;
|
||||
} catch (err) {
|
||||
print(err);
|
||||
out.ref.size = -1;
|
||||
}
|
||||
}
|
||||
|
||||
static void freeResource(ResourceBuffer rb) {
|
||||
calloc.free(_assets[rb.id]!);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user