-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c277354
commit c33024c
Showing
8 changed files
with
222 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
import 'dart:io'; | ||
|
||
import '../utils/ByteDataWrapper.dart'; | ||
|
||
class SmdEntry { | ||
final String id; | ||
final int indexX10; | ||
final String text; | ||
|
||
const SmdEntry(this.id, this.indexX10, this.text); | ||
} | ||
|
||
Future<List<SmdEntry>> readSmdFile(String path) async { | ||
var file = File(path); | ||
var bytes = await file.readAsBytes(); | ||
var reader = ByteDataWrapper(bytes.buffer); | ||
var entries = <SmdEntry>[]; | ||
int count = reader.readUint32(); | ||
for (int i = 0; i < count; i++) { | ||
String id = reader.readString(0x80, encoding: StringEncoding.utf16); | ||
int indexX10 = reader.readUint64(); | ||
String text = reader.readString(0x800, encoding: StringEncoding.utf16); | ||
var zerosRemover = RegExp("\x00+\$"); | ||
id = id.replaceAll(zerosRemover, ""); | ||
text = text.replaceAll(zerosRemover, ""); | ||
entries.add(SmdEntry(id, indexX10, text)); | ||
} | ||
return entries; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
import 'dart:io'; | ||
import 'dart:typed_data'; | ||
|
||
import '../utils/ByteDataWrapper.dart'; | ||
import 'smdReader.dart'; | ||
|
||
Future<void> saveSmd(List<SmdEntry> entries, String path) async { | ||
var totalSize = 4 + entries.length * 0x888; | ||
var bytes = ByteDataWrapper(ByteData(totalSize).buffer); | ||
bytes.writeUint32(entries.length); | ||
for (var entry in entries) { | ||
var id = entry.id.padRight(0x40, '\x00'); | ||
var text = entry.text.padRight(0x400, '\x00'); | ||
bytes.writeString(id, StringEncoding.utf16); | ||
bytes.writeUint64(entry.indexX10); | ||
bytes.writeString(text, StringEncoding.utf16); | ||
} | ||
|
||
var file = File(path); | ||
await file.writeAsBytes(bytes.buffer.asUint8List()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// ignore_for_file: invalid_use_of_protected_member, invalid_use_of_visible_for_testing_member | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
import '../../fileTypeUtils/smd/smdReader.dart'; | ||
import '../../widgets/propEditors/customXmlProps/tableEditor.dart'; | ||
import '../Property.dart'; | ||
import '../hasUuid.dart'; | ||
import '../nestedNotifier.dart'; | ||
import '../undoable.dart'; | ||
|
||
class SmdEntryData with HasUuid { | ||
final StringProp id; | ||
final StringProp text; | ||
final ChangeNotifier _anyChangeNotifier; | ||
|
||
SmdEntryData({ required this.id, required this.text, required ChangeNotifier anyChangeNotifier }) | ||
: _anyChangeNotifier = anyChangeNotifier { | ||
id.addListener(_anyChangeNotifier.notifyListeners); | ||
text.addListener(_anyChangeNotifier.notifyListeners); | ||
} | ||
} | ||
|
||
class SmdData extends NestedNotifier<SmdEntryData> with CustomTableConfig, Undoable { | ||
final ChangeNotifier fileChangeNotifier; | ||
|
||
SmdData(List<SmdEntryData> entries, String fileName, this.fileChangeNotifier) | ||
: super(entries) { | ||
name = fileName; | ||
columnNames = ["ID", "Text"]; | ||
rowCount = NumberProp(entries.length, true); | ||
} | ||
|
||
SmdData.from(List<SmdEntry> rawEntries, String fileName) | ||
: fileChangeNotifier = ChangeNotifier(), | ||
super([]) { | ||
addAll(rawEntries.map((e) { | ||
var idProp = StringProp(e.id); | ||
var textProp = StringProp(e.text); | ||
textProp.transform = (str) => str; | ||
return SmdEntryData( | ||
id: idProp, | ||
text: textProp, | ||
anyChangeNotifier: fileChangeNotifier, | ||
); | ||
})); | ||
name = fileName; | ||
columnNames = ["ID", "Text"]; | ||
rowCount = NumberProp(rawEntries.length, true); | ||
} | ||
|
||
List<SmdEntry> toEntries() | ||
=> List.generate(length, (i) => SmdEntry(this[i].id.value, i * 10, this[i].text.value)); | ||
|
||
@override | ||
void onRowAdd() { | ||
var idProp = StringProp("ID"); | ||
var textProp = StringProp("Text"); | ||
textProp.transform = (str) => str; | ||
add(SmdEntryData( | ||
id: idProp, | ||
text: textProp, | ||
anyChangeNotifier: fileChangeNotifier, | ||
)); | ||
rowCount.value++; | ||
fileChangeNotifier.notifyListeners(); | ||
} | ||
|
||
@override | ||
void onRowRemove(int index) { | ||
removeAt(index); | ||
rowCount.value--; | ||
fileChangeNotifier.notifyListeners(); | ||
} | ||
|
||
@override | ||
RowConfig rowPropsGenerator(int index) { | ||
var entry = this[index]; | ||
return RowConfig( | ||
key: Key(entry.uuid), | ||
cells: [ | ||
CellConfig(prop: entry.id), | ||
CellConfig(prop: entry.text, allowMultiline: true), | ||
], | ||
); | ||
} | ||
|
||
@override | ||
void restoreWith(Undoable snapshot) { | ||
// TODO: implement restoreWith | ||
} | ||
|
||
@override | ||
Undoable takeSnapshot() { | ||
// TODO: implement takeSnapshot | ||
throw UnimplementedError(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters