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

View File

@ -93,7 +93,7 @@ class MuWireSettings {
}
void write(OutputStream out) throws IOException {
void write(Writer out) throws IOException {
Properties props = new Properties()
props.setProperty("leaf", isLeaf.toString())
props.setProperty("allowUntrusted", allowUntrusted.toString())
@ -137,7 +137,7 @@ class MuWireSettings {
props.setProperty("trustSubscriptions", encoded)
}
props.store(out, "")
props.store(out, "This file is UTF-8")
}
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 {
DataOutputStream dos = new DataOutputStream(out)
dos.writeShort(name.length())
dos.write(name.getBytes(StandardCharsets.UTF_8))
byte [] bytes = name.getBytes(StandardCharsets.UTF_8)
dos.writeShort(bytes.length)
dos.write(bytes)
}
public getName() {

View File

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

View File

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

View File

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

View File

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

View File

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