1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-23 11:21:29 +00:00

Create camera repository on first start (closes #4).

This commit is contained in:
Felix Ableitner 2014-06-24 22:06:01 +02:00
parent 97e46c3f64
commit 5d078fc0c0
2 changed files with 80 additions and 52 deletions

View file

@ -330,8 +330,12 @@ public class SyncthingService extends Service {
"Copying default config, keys will be generated automatically"); "Copying default config, keys will be generated automatically");
copyDefaultConfig(); copyDefaultConfig();
} }
moveConfigFiles(); moveConfigFiles();
ConfigXml config = new ConfigXml(getConfigFile()); ConfigXml config = new ConfigXml(getConfigFile());
if (isFirstStart()) {
config.createCameraRepo();
}
config.update(); config.update();
return new Pair<String, String>(config.getWebGuiUrl(), config.getApiKey()); return new Pair<String, String>(config.getWebGuiUrl(), config.getApiKey());
} }

View file

@ -1,5 +1,6 @@
package com.nutomic.syncthingandroid.util; package com.nutomic.syncthingandroid.util;
import android.os.Environment;
import android.util.Log; import android.util.Log;
import org.w3c.dom.Document; 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. * Coming from 0.3.0 and earlier, the ignorePerms flag is set to true on every repository.
*/ */
public void update() { public void update() {
try {
Log.i(TAG, "Checking for needed config updates"); Log.i(TAG, "Checking for needed config updates");
boolean changed = false; boolean changed = false;
Element options = (Element) mConfig.getDocumentElement() Element options = (Element) mConfig.getDocumentElement()
@ -108,18 +108,8 @@ public class ConfigXml {
} }
} }
// Write the changes back to file.
if (changed) { if (changed) {
Log.i(TAG, "Writing updated config back to file"); saveChanges();
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);
} }
} }
@ -128,4 +118,38 @@ public class ConfigXml {
.getElementsByTagName("gui").item(0); .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);
}
}
} }