📄 clientsettings.cpp
字号:
// Copy array in a tmp buffer
if (winSourceConfigsCount>0) {
s = new WindowsSyncSourceConfig[winSourceConfigsCount];
for (i=0; i<winSourceConfigsCount; i++) {
s[i] = winSourceConfigs[i];
}
}
// Delete old one, create new (+1 element)
if (winSourceConfigs) {
delete [] winSourceConfigs;
}
winSourceConfigs = new WindowsSyncSourceConfig[winSourceConfigsCount+1];
// Copy back.
for (i=0; i<winSourceConfigsCount; i++)
winSourceConfigs[i] = s[i];
// Copy the new one.
winSourceConfigs[winSourceConfigsCount] = wsc;
if (s) {
delete [] s;
s = NULL;
}
winSourceConfigsCount ++;
return TRUE;
}
// ------------------------------ Other methods ----------------------------------
/*
* Returns the value of the given property, from rootKey tree (read only).
* The value is returned as a new char array and must be freed by the user.
*
* @param context : full context of key, under rootKey
* @param propertyName : name of property to retrieve
* @param rootKey : one of HKEY_LOCAL_MACHINE
* HKEY_CLASSES_ROOT
* HKEY_CURRENT_USER
* HKEY_USERS
* ...
* @return : the property value (new allocated buffer)
* if key not found, returns an empty string.
*/
char* ClientSettings::readPropertyValue(const char* context, const char* propertyName, HKEY rootKey) {
DWORD res = 0;
long err = 0;
ULONG dim = 0;
HKEY key = NULL;
char* ret = NULL;
char* fullContext = new char[strlen(context) + 10];
sprintf(fullContext, "%s/%s", "Software", context);
//RegCreateKeyExA(
WCHAR* wideFullContext = toWideChar(fullContext);
RegCreateKeyEx(
rootKey,
wideFullContext,
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_READ, // Read only: could be from a limited rights user.
NULL,
&key,
&res
);
if (key == 0) {
lastErrorCode = ERR_INVALID_CONTEXT;
//sprintf(lastErrorMsg, ERR_INVALID_REG_PATH, fullContext);
goto finally;
}
// Get value length
//err = RegQueryValueExA(
WCHAR* widePropertyName = toWideChar(propertyName);
err = RegQueryValueEx(
key,
widePropertyName,
NULL,
NULL, // we currently support only strings
NULL,
&dim
);
if (err == ERROR_SUCCESS) {
if (dim > 0) {
char* buf = new char[dim + 1];
//err = RegQueryValueExA(
err = RegQueryValueEx(
key,
widePropertyName,
NULL,
NULL, // we currently support only strings
(UCHAR*)buf,
&dim
);
if (err == ERROR_SUCCESS) {
ret = stringdup(buf);
}
delete [] buf;
}
}
finally:
if(widePropertyName){
delete [] widePropertyName;
widePropertyName = NULL;
}
if(wideFullContext){
delete [] wideFullContext;
wideFullContext = NULL;
}
if (!ret) {
// Always return an empty string if key not found!
ret = stringdup(EMPTY_STRING);
}
if (fullContext) {
delete [] fullContext;
}
if (key != 0) {
RegCloseKey(key);
}
return ret;
}
void ClientSettings::readWinSourceConfig(unsigned int i) {
char* tmp;
if (!sourcesNode) {
open();
}
ManagementNode* node = NULL;
node = sourcesNode->getChild(i);
if (node) {
if (strcmp(node->getName(), "mails") == 0) {
const char* context = NULL;
char t[255];
char* fn = node->createFullName();
strcpy(t, fn);
delete [] fn;
context = strstr(t, node->getName());
t[context - t - 1] = 0;
MailSourceManagementNode* mmn = new MailSourceManagementNode(t, node->getName());
if (mmn) {
if (mailssconfig) {
delete mailssconfig;
}
mailssconfig = new MailSyncSourceConfig(mmn->getMailSourceConfig(true));
delete mmn;
}
}
tmp = node->readPropertyValue(PROPERTY_SOURCE_USE_SIF);
winSourceConfigs[i].setUseSif(tmp);
delete [] tmp;
tmp = node->readPropertyValue(PROPERTY_SOURCE_DIR);
winSourceConfigs[i].setSyncDir(tmp);
delete [] tmp;
tmp = node->readPropertyValue(PROPERTY_SCHEDULE);
winSourceConfigs[i].setSchedule(tmp);
delete [] tmp;
}
}
void ClientSettings::refreshIP(){
// get IP
checkNetwork();
setIp(getLocalAddress());
}
void ClientSettings::setDirty(int flag){
dirty |= flag;
}
/*
BOOL ClientSettings::readConfigSources(const char* sourceType, BOOL toClose) {
int n = 0, i = 0; // number of sync sources
BOOL ret = FALSE;
ManagementNode* nn = NULL;
if (!open()) {
return FALSE;
}
n = sourcesNode->getChildrenMaxCount();
//
// Let's remove previously created config objects and reinitialize
// sourceConfigs
//
if (sourceConfigs) {
delete [] sourceConfigs;
}
sourceConfigs = new SyncSourceConfig[n];
sourceConfigsCount = n;
for (i=0; i<n; ++i) {
// node owns children, we must not delete them
readSourceConfig(i, *(sourcesNode) );
}
if (sourceType && strcmp(sourceType, "all") == 0) {
if (toClose)
close();
return true;
}
for (unsigned int i=0; i<sourceConfigsCount; ++i) {
if (strcmp(sourceConfigs[i].getName(), sourceType) == 0) {
ssconfig.assign(sourceConfigs[i]);
nn = sourcesNode->getChild(i);
break;
}
}
char* tmp;
// TODO: this method is used in ClientSettings for "mail" to init mailssconfig, but seems not used anywhere else,
// so the code for the other sources below should be removed
if (strcmp(sourceType, "contact") == 0) {
tmp = nn->readPropertyValue(PROPERTY_SOURCE_USE_SIF);
//~setUseSif(string(tmp));
delete [] tmp;
tmp = nn->readPropertyValue(PROPERTY_SCHEDULE);
//~setSchedule(string(tmp));
delete [] tmp;
} else if (strcmp(sourceType, "calendar") == 0) {
tmp = nn->readPropertyValue(PROPERTY_SOURCE_USE_SIF);
//~setUseSif(string(tmp));
delete [] tmp;
tmp = nn->readPropertyValue(PROPERTY_SCHEDULE);
//~setSchedule(string(tmp));
delete [] tmp;
} else if (strcmp(sourceType, "task") == 0) {
tmp = nn->readPropertyValue(PROPERTY_SOURCE_USE_SIF);
//~setUseSif(string(tmp));
delete [] tmp;
tmp = nn->readPropertyValue(PROPERTY_SCHEDULE);
//~setSchedule(string(tmp));
delete [] tmp;
} else if (strcmp(sourceType, "briefcase") == 0) {
tmp = nn->readPropertyValue(PROPERTY_SOURCE_DIR);
setDir(string(tmp));
delete [] tmp;
tmp = nn->readPropertyValue(PROPERTY_SCHEDULE);
//~setSchedule(string(tmp));
delete [] tmp;
} else if (strcmp(sourceType, "note") == 0) {
tmp = nn->readPropertyValue(PROPERTY_SOURCE_DIR);
setDir(string(tmp));
delete [] tmp;
tmp = nn->readPropertyValue(PROPERTY_SCHEDULE);
//~setSchedule(string(tmp));
delete [] tmp;
} else if (strcmp(sourceType, "mail") == 0) {
const char* context = NULL;
char t[255];
char* fn = nn->createFullName();
strcpy(t, fn);
delete [] fn;
context = strstr(t, nn->getName());
t[context - t - 1] = 0;
MailSourceManagementNode* mmn = new MailSourceManagementNode(t, nn->getName());
mailssconfig = mmn->getMailSourceConfig(true);
if (mmn) {
delete mmn;
}
}
ret = TRUE;
if (toClose)
close();
return ret;
}
*/
/*
// TODO: called only for "mail", the other sources could be removed if not needed anymore
BOOL ClientSettings::saveConfigSources(const char* saveAll) {
ManagementNode* nn;
// to save all the sources config. It is used by the form
// in which there are all the sources whith the list of the sync property
// and to reset the last timestamp in the recover form. it is set to 1
//
if (saveAll && strcmp(saveAll, "all") == 0) {
for (unsigned int i=0; i<sourceConfigsCount; ++i) {
nn = sourcesNode->getChild(i);
saveSourceConfig(i, *sourcesNode, *nn);
}
close();
return true;
}
for (unsigned int i=0; i<sourceConfigsCount; ++i) {
if (strcmp(sourceConfigs[i].getName(), ssconfig.getName()) == 0) {
nn = sourcesNode->getChild(i);
break;
}
}
if (strcmp(ssconfig.getName(), "contact") == 0 ||
strcmp(ssconfig.getName(), "calendar") == 0 ||
strcmp(ssconfig.getName(), "task") == 0) {
if(strcmp(ssconfig.getEncryption(), "0") != 0 || strcmp(ssconfig.getName(), "note") == 0) {
nn->setPropertyValue(PROPERTY_SOURCE_ENCODING, "b64");
} else {
nn->setPropertyValue(PROPERTY_SOURCE_ENCODING, "bin");
}
//nn->setPropertyValue(PROPERTY_SOURCE_ENCODING, ssconfig.getEncoding());
} else if (strcmp(ssconfig.getName(), "mail") == 0) {
//setMailSourceConfig(mailssconfig, nn);
const char* context = NULL;
char* tt = nn->createFullName();
char t[255];
strcpy(t, tt);
context = strstr(t, nn->getName());
t[context - t - 1] = 0;
MailSourceManagementNode* mmn = new MailSourceManagementNode(t, nn->getName());
if(strcmp(mailssconfig.getEncryption(), "0") != 0) {
mailssconfig.setEncoding("b64");
} else {
mailssconfig.setEncoding("bin");
}
//mmn->setMailSourceConfig(mailssconfig);
if (tt) { delete [] tt; }
if (mmn){ delete [] mmn;}
}
close();
return TRUE;
}
*/
/**
* Reads all sources timestamps from win registry and set
* all values into configuration.
void ClientSettings::readSourcesTimestamps() {
if (!open()) {
return;
}
for (unsigned int i=0; i<sourceConfigsCount; i++) {
ManagementNode* node = sourcesNode->getChild(i);
if (node) {
// This sets only variables that the library uses internally, like anchors
readSourceVars(i, *sourcesNode, *node);
}
}
close();
}
*/
/**
* Reads only "sync" properties of each source, to win registry.
void ClientSettings::readSyncModes() {
if (!open()) {
return;
}
for (unsigned int i=0; i<sourceConfigsCount; i++) {
ManagementNode* node = sourcesNode->getChild(i);
if (node) {
winSourceConfigs[i].setSync(node->readPropertyValue(PROPERTY_SOURCE_SYNC));
}
}
close();
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -