Skip to content

Commit

Permalink
fixed xml whitespace replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurHeitmann committed Dec 22, 2023
1 parent a6d2a7e commit c9bde97
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/fileTypeUtils/audio/wavToWemConverter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'package:archive/archive_io.dart';
import 'package:path/path.dart';
import 'package:xml/xml.dart';

import '../xml/xmlExtension.dart';

const _defaultTemplateFile = "wavToWemTemplate_default.zip";
const _bgmTemplateFile = "wavToWemTemplate_BGM.zip";

Expand Down Expand Up @@ -50,7 +52,7 @@ Future<void> wavToWem(String wavPath, String wemSavePath, bool isBgm, bool enabl
String wavSrcDir = join(projectPath, "wavSrc");
XmlDocument wSourcesXml = _getWwiseSourcesXml(wavPath, enableVolumeNormalization);
String wSourcesXmlPath = join(wavSrcDir, "ExtSourceList.wsources");
var xmlStr = wSourcesXml.toXmlString(pretty: true, indent: "\t");
var xmlStr = wSourcesXml.toPrettyString();
await File(wSourcesXmlPath).writeAsString(xmlStr);

print("Converting WAV to WEM");
Expand Down
3 changes: 2 additions & 1 deletion lib/fileTypeUtils/bxm/bxmReader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:typed_data';
import 'package:xml/xml.dart';

import '../utils/ByteDataWrapper.dart';
import '../xml/xmlExtension.dart';
import 'bxmIO.dart';

XmlElement parseBxm(ByteDataWrapper bytes) {
Expand Down Expand Up @@ -95,6 +96,6 @@ Future<void> convertBxmFileToXml(String bxmPath, String xmlPath) async {
var doc = XmlDocument();
doc.children.add(XmlDeclaration([XmlAttribute(XmlName("version"), "1.0"), XmlAttribute(XmlName("encoding"), "utf-8")]));
doc.children.add(root);
var xmlStr = "${doc.toXmlString(pretty: true, indent: "\t")}\n";
var xmlStr = doc.toPrettyString();
await File(xmlPath).writeAsString(xmlStr);
}
13 changes: 13 additions & 0 deletions lib/fileTypeUtils/xml/xmlExtension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

import 'package:xml/xml.dart';

extension XmlExtension on XmlNode {
String toPrettyString({ int? level }) {
return "${toXmlString(
pretty: true,
indent: "\t",
level: level,
preserveWhitespace: (node) => node.children.whereType<XmlText>().isNotEmpty
)}\n";
}
}
3 changes: 2 additions & 1 deletion lib/fileTypeUtils/yax/yaxToXml.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';
import 'package:xml/xml.dart';

import '../../utils.dart';
import '../xml/xmlExtension.dart';
import 'hashToStringMap.dart';
import 'japToEng.dart';
import '../utils/ByteDataWrapper.dart';
Expand Down Expand Up @@ -84,7 +85,7 @@ XmlElement yaxToXml(ByteDataWrapper bytes, { includeAnnotations = true }) {
Future<void> yaxFileToXmlFile(String yaxFilePath, String xmlFilePath) async {
var bytes = await ByteDataWrapper.fromFile(yaxFilePath);
var xml = yaxToXml(bytes);
var xmlString = xml.toXmlString(pretty: true, indent: "\t");
var xmlString = xml.toPrettyString();
var xmlFile = File(xmlFilePath);
await xmlFile.writeAsString('<?xml version="1.0" encoding="utf-8"?>\n');
await xmlFile.writeAsString(xmlString, mode: FileMode.append);
Expand Down
4 changes: 3 additions & 1 deletion lib/fileTypeUtils/z/zlibDecompress.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import 'dart:io';
import 'package:euc/jis.dart';
import 'package:xml/xml.dart';

import '../xml/xmlExtension.dart';

Future<void> decompressZlibXml(String input, String output) async {
var bytes = await File(input).readAsBytes();
var decompressed = ZLibDecoder().convert(bytes);
var str = ShiftJIS().decode(decompressed);
var xml = XmlDocument.parse(str);
var xmlStr = xml.toXmlString(pretty: true, indent: "\t");
var xmlStr = xml.toPrettyString();
await File(output).writeAsString(xmlStr);
}

0 comments on commit c9bde97

Please sign in to comment.