mirror of
https://github.com/syncthing/syncthing-android.git
synced 2025-01-10 20:15:54 +00:00
Create camera repository on first start (closes #4).
This commit is contained in:
parent
97e46c3f64
commit
5d078fc0c0
2 changed files with 80 additions and 52 deletions
|
@ -330,8 +330,12 @@ public class SyncthingService extends Service {
|
|||
"Copying default config, keys will be generated automatically");
|
||||
copyDefaultConfig();
|
||||
}
|
||||
|
||||
moveConfigFiles();
|
||||
ConfigXml config = new ConfigXml(getConfigFile());
|
||||
if (isFirstStart()) {
|
||||
config.createCameraRepo();
|
||||
}
|
||||
config.update();
|
||||
return new Pair<String, String>(config.getWebGuiUrl(), config.getApiKey());
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.nutomic.syncthingandroid.util;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
@ -64,7 +65,6 @@ public class ConfigXml {
|
|||
* Coming from 0.3.0 and earlier, the ignorePerms flag is set to true on every repository.
|
||||
*/
|
||||
public void update() {
|
||||
try {
|
||||
Log.i(TAG, "Checking for needed config updates");
|
||||
boolean changed = false;
|
||||
Element options = (Element) mConfig.getDocumentElement()
|
||||
|
@ -108,18 +108,8 @@ public class ConfigXml {
|
|||
}
|
||||
}
|
||||
|
||||
// Write the changes back to file.
|
||||
if (changed) {
|
||||
Log.i(TAG, "Writing updated config back to file");
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
Transformer transformer = transformerFactory.newTransformer();
|
||||
DOMSource domSource = new DOMSource(mConfig);
|
||||
StreamResult streamResult = new StreamResult(mConfigFile);
|
||||
transformer.transform(domSource, streamResult);
|
||||
}
|
||||
}
|
||||
catch (TransformerException e) {
|
||||
Log.w(TAG, "Failed to save updated config", e);
|
||||
saveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,4 +118,38 @@ public class ConfigXml {
|
|||
.getElementsByTagName("gui").item(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a repository for the default camera folder.
|
||||
*/
|
||||
public void createCameraRepo() {
|
||||
File cameraFolder =
|
||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
|
||||
|
||||
Element cameraRepo = mConfig.createElement("repository");
|
||||
cameraRepo.setAttribute("id", "camera");
|
||||
cameraRepo.setAttribute("directory", cameraFolder.getAbsolutePath());
|
||||
cameraRepo.setAttribute("ro", "true");
|
||||
cameraRepo.setAttribute("ignorePerms", "true");
|
||||
mConfig.getDocumentElement().appendChild(cameraRepo);
|
||||
|
||||
saveChanges();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes updated mConfig back to file.
|
||||
*/
|
||||
private void saveChanges() {
|
||||
try {
|
||||
Log.i(TAG, "Writing updated config back to file");
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
Transformer transformer = transformerFactory.newTransformer();
|
||||
DOMSource domSource = new DOMSource(mConfig);
|
||||
StreamResult streamResult = new StreamResult(mConfigFile);
|
||||
transformer.transform(domSource, streamResult);
|
||||
}
|
||||
catch (TransformerException e) {
|
||||
Log.w(TAG, "Failed to save updated config", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue