support UTF-8 in persona names

This commit is contained in:
Zlatin Balevsky
2019-11-02 14:43:24 +00:00
parent 568255140f
commit 86894f242b
8 changed files with 23 additions and 26 deletions

View File

@@ -191,8 +191,9 @@ public class Core {
def baos = new ByteArrayOutputStream() def baos = new ByteArrayOutputStream()
def daos = new DataOutputStream(baos) def daos = new DataOutputStream(baos)
daos.write(Constants.PERSONA_VERSION) daos.write(Constants.PERSONA_VERSION)
daos.writeShort((short)props.getNickname().length()) byte [] name = props.getNickname().getBytes(StandardCharsets.UTF_8)
daos.write(props.getNickname().getBytes(StandardCharsets.UTF_8)) daos.writeShort((short)name.length)
daos.write(name)
destination.writeBytes(daos) destination.writeBytes(daos)
daos.flush() daos.flush()
byte [] payload = baos.toByteArray() byte [] payload = baos.toByteArray()
@@ -335,8 +336,7 @@ public class Core {
return return
} }
log.info("saving settings") log.info("saving settings")
File f = new File(home, "MuWire.properties") saveMuSettings()
f.withOutputStream { muOptions.write(it) }
log.info("shutting down trust subscriber") log.info("shutting down trust subscriber")
trustSubscriber.stop() trustSubscriber.stop()
log.info("shutting down download manageer") log.info("shutting down download manageer")
@@ -358,6 +358,11 @@ public class Core {
log.info("shutdown complete") log.info("shutdown complete")
} }
public void saveMuSettings() {
File f = new File(home, "MuWire.properties")
f.withPrintWriter("UTF-8", { muOptions.write(it) })
}
static main(args) { static main(args) {
def home = System.getProperty("user.home") + File.separator + ".MuWire" def home = System.getProperty("user.home") + File.separator + ".MuWire"
home = new File(home) home = new File(home)

View File

@@ -93,7 +93,7 @@ class MuWireSettings {
} }
void write(OutputStream out) throws IOException { void write(Writer out) throws IOException {
Properties props = new Properties() Properties props = new Properties()
props.setProperty("leaf", isLeaf.toString()) props.setProperty("leaf", isLeaf.toString())
props.setProperty("allowUntrusted", allowUntrusted.toString()) props.setProperty("allowUntrusted", allowUntrusted.toString())
@@ -137,7 +137,7 @@ class MuWireSettings {
props.setProperty("trustSubscriptions", encoded) props.setProperty("trustSubscriptions", encoded)
} }
props.store(out, "") props.store(out, "This file is UTF-8")
} }
private static Set<String> readEncodedSet(Properties props, String property) { private static Set<String> readEncodedSet(Properties props, String property) {

View File

@@ -22,8 +22,9 @@ public class Name {
public void write(OutputStream out) throws IOException { public void write(OutputStream out) throws IOException {
DataOutputStream dos = new DataOutputStream(out) DataOutputStream dos = new DataOutputStream(out)
dos.writeShort(name.length()) byte [] bytes = name.getBytes(StandardCharsets.UTF_8)
dos.write(name.getBytes(StandardCharsets.UTF_8)) dos.writeShort(bytes.length)
dos.write(bytes)
} }
public getName() { public getName() {

View File

@@ -86,9 +86,9 @@ class DirectoryWatcher {
private void saveMuSettings() { private void saveMuSettings() {
File muSettingsFile = new File(home, "MuWire.properties") File muSettingsFile = new File(home, "MuWire.properties")
muSettingsFile.withOutputStream { muSettingsFile.withPrintWriter("UTF-8", {
muOptions.write(it) muOptions.write(it)
} })
} }
private void watch() { private void watch() {

View File

@@ -97,9 +97,6 @@ class ContentPanelController {
} }
void saveMuWireSettings() { void saveMuWireSettings() {
File f = new File(core.home, "MuWire.properties") core.saveMuSettings()
f.withOutputStream {
core.muOptions.write(it)
}
} }
} }

View File

@@ -299,10 +299,7 @@ class MainFrameController {
} }
void saveMuWireSettings() { void saveMuWireSettings() {
File f = new File(core.home, "MuWire.properties") core.saveMuSettings()
f.withOutputStream {
core.muOptions.write(it)
}
} }
void mvcGroupInit(Map<String, String> args) { void mvcGroupInit(Map<String, String> args) {

View File

@@ -137,10 +137,7 @@ class OptionsController {
model.trustListInterval = trustListInterval model.trustListInterval = trustListInterval
settings.trustListInterval = Integer.parseInt(trustListInterval) settings.trustListInterval = Integer.parseInt(trustListInterval)
File settingsFile = new File(core.home, "MuWire.properties") core.saveMuSettings()
settingsFile.withOutputStream {
settings.write(it)
}
// UI Setttings // UI Setttings

View File

@@ -41,9 +41,9 @@ class Ready extends AbstractLifecycleHandler {
def propsFile = new File(home, "MuWire.properties") def propsFile = new File(home, "MuWire.properties")
if (propsFile.exists()) { if (propsFile.exists()) {
log.info("loading existing props file") log.info("loading existing props file")
propsFile.withInputStream { propsFile.withReader("UTF-8", {
props.load(it) props.load(it)
} })
props = new MuWireSettings(props) props = new MuWireSettings(props)
if (props.incompleteLocation == null) if (props.incompleteLocation == null)
props.incompleteLocation = new File(home, "incompletes") props.incompleteLocation = new File(home, "incompletes")
@@ -90,9 +90,9 @@ class Ready extends AbstractLifecycleHandler {
props.downloadLocation = chooser.getSelectedFile() props.downloadLocation = chooser.getSelectedFile()
} }
propsFile.withOutputStream { propsFile.withPrintWriter("UTF-8", {
props.write(it) props.write(it)
} })
} }
Core core Core core