abraunegg-onedrive/src/main.d

47 lines
1.2 KiB
D
Raw Normal View History

2015-09-01 20:45:34 +02:00
import std.file;
2015-09-11 18:33:22 +02:00
import config, monitor, onedrive, sync;
2015-09-01 20:45:34 +02:00
private string configFile = "./onedrive.conf";
private string refreshTokenFile = "refresh_token";
void main()
{
auto cfg = new Config(configFile);
auto onedrive = new OneDriveApi(cfg.get("client_id"), cfg.get("client_secret"));
2015-09-02 11:21:19 +02:00
onedrive.onRefreshToken = (string refreshToken) { std.file.write(refreshTokenFile, refreshToken); };
2015-09-01 20:45:34 +02:00
try {
string refreshToken = readText(refreshTokenFile);
onedrive.setRefreshToken(refreshToken);
} catch (FileException e) {
onedrive.authorize();
}
auto sync = new SyncEngine(cfg, onedrive);
sync.applyDifferences();
2015-09-11 18:33:22 +02:00
sync.uploadDifferences();
2015-09-01 20:45:34 +02:00
2015-09-11 18:33:22 +02:00
Monitor m;
import std.stdio;
m.onDirCreated = delegate(string path) {
writeln("Directory created: ", path);
sync.createFolderItem(path);
sync.uploadDifferences(path);
};
m.onFileChanged = delegate(string path) {
writeln("File changed: ", path);
sync.uploadDifference2(path);
};
m.onDelete = delegate(string path) {
sync.deleteByPath(path);
};
m.onMove = delegate(string from, string to) {
sync.moveItem(from, to);
};
m.init();
string syncDir = cfg.get("sync_dir");
chdir(syncDir);
m.addRecursive("test");
while (true) m.update();
2015-09-01 20:45:34 +02:00
}