-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSettings.cpp
More file actions
89 lines (78 loc) · 2.33 KB
/
Settings.cpp
File metadata and controls
89 lines (78 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "Settings.h"
#include <Directory.h>
#include <File.h>
#include <FindDirectory.h>
#include <Message.h>
#include <Path.h>
#include "config.h"
Settings gSettings;
Settings::Settings(void)
{
maxThreads = 10;
LoadSettings();
}
void
Settings::LoadSettings(void)
{
BPath configPath;
BDirectory configDirectory;
BFile settingsFile;
BString readString;
BMessage settings = BMessage();
if(find_directory(B_USER_SETTINGS_DIRECTORY, &configPath) == B_OK)
{
configDirectory.SetTo(configPath.Path());
if(settingsFile.SetTo(&configDirectory, SETTINGS_FILE, B_READ_ONLY) == B_OK)
{
if (settingsFile.Lock() == B_OK) {
if (settings.Unflatten(&settingsFile) == B_OK) {
authKey = settings.GetString("DropBox:AuthKey");
authVerifier = settings.GetString("DropBox:AuthVerifier");
refreshToken = settings.GetString("DropBox:RefreshToken");
cursor = settings.GetString("DropBox:Cursor");
bulkUploadCursor = settings.GetString("DropBox:BulkUploadCursor");
bulkUploadPath = settings.GetString("DropBox:BulkUploadPath");
bulkUploadIndex = settings.GetInt64("DropBox:BulkUploadIndex", 0);
lastLocalSync = settings.GetInt32("DropBox:LastLocalSync", 0);
}
settingsFile.Unlock();
}
}
else
{
authKey.SetTo("");
authVerifier.SetTo("");
refreshToken.SetTo("");
cursor.SetTo("");
}
}
}
void
Settings::SaveSettings(void)
{
BPath configPath;
BDirectory configDirectory;
BFile settingsFile;
BString readString;
BMessage settings = BMessage();
if(find_directory(B_USER_SETTINGS_DIRECTORY, &configPath) == B_OK)
{
configDirectory.SetTo(configPath.Path());
if(settingsFile.SetTo(&configDirectory, SETTINGS_FILE, B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE) == B_OK)
{
settings.AddString("DropBox:AuthKey", authKey);
settings.AddString("DropBox:AuthVerifier", authVerifier);
settings.AddString("DropBox:RefreshToken", refreshToken);
settings.AddString("DropBox:Cursor", cursor);
settings.AddString("DropBox:BulkUploadCursor", bulkUploadCursor);
settings.AddString("DropBox:BulkUploadPath", bulkUploadPath);
settings.AddInt64("DropBox:BulkUploadIndex", bulkUploadIndex);
settings.AddInt32("DropBox:LastLocalSync", lastLocalSync);
if (settingsFile.Lock() == B_OK) {
if (settings.Flatten(&settingsFile) == B_OK) {
}
settingsFile.Unlock();
}
}
}
}