registry.cpp

来自「funambol window mobile客户端源代码」· C++ 代码 · 共 1,075 行 · 第 1/5 页

CPP
1,075
字号
/*
 * Funambol is a mobile platform developed by Funambol, Inc. 
 * Copyright (C) 2003 - 2007 Funambol, Inc.
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License version 3 as published by
 * the Free Software Foundation with the addition of the following permission
 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
 * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
 * details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program; if not, see http://www.gnu.org/licenses or write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301 USA.
 * 
 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU Affero General Public License
 * version 3, these Appropriate Legal Notices must retain the display of the
 * "Powered by Funambol" logo. If the display of the logo is not reasonably
 * feasible for technical reasons, the Appropriate Legal Notices must display
 * the words "Powered by Funambol".
 */

#include "stdafx.h"

#include <cfgmgrapi.h>
#include "Tlhelp32.h"
#include "mail.h"
#include "registry.h"
#include "Winbase.h"  //-- for createProcess
#include "winreg.h"   //-- for registry key reading

#ifdef IS_PORTAL_VERSION
    #define IS_PORTAL   TEXT("1")
#else
    #define IS_PORTAL   TEXT("0")
#endif
    #define USERNAME    TEXT("")
    #define PASSWORD    TEXT("")
    #define SERVER_URL  TEXT("http://my.funambol.com/sync")
    #define COMPRESSION TEXT("1")


wchar_t* getMyDocumentFolder();

const wchar_t* getAppName(){

    return PROGRAM_DIR;
}
wchar_t* rpath = NULL;
const wchar_t* getFullReg(wchar_t* val){

    if (rpath){
        delete[] rpath;
        rpath = NULL;
    }
    int dim = wcslen(val) + wcslen(getAppName()) + 1;
    rpath = new wchar_t[dim];
    wsprintf(rpath,val,getAppName());
    return rpath;
}

static size_t getLenEncoding(const WCHAR* s)
{
    if (!s)
        return 0;

    int len = wcslen(s);

    if (!len)
        return 0;

    long k = WideCharToMultiByte (CP_UTF8, 0, s, len, 0, 0, 0, 0);

    return (k != 0) ? (long)k : -1;
}

char* toMultibyte(const WCHAR *wc)
{
    if (!wc) {
        return 0;
    }

    char *ret;
    size_t wlen = wcslen(wc);

    if (!wlen) {
        ret = new char[1];
        ret[0] = 0;
        return ret;
    }

    size_t blen = getLenEncoding(wc);

    if(blen <= 0)
        return 0;

    ret = new char[blen+1];

    blen = WideCharToMultiByte(CP_UTF8, 0, wc, wlen, ret, blen, 0, 0);
    ret[blen] = 0;

    return ret;
}





void deleteSyncmlTransportRegistry() {
    RegDeleteKey(HKEY_LOCAL_MACHINE,getFullReg( TEXT("SOFTWARE\\Microsoft\\Inbox\\Svc\\%s")));
}

void deleteAllRegistry() {
    RegDeleteKey(HKEY_LOCAL_MACHINE,getFullReg( TEXT("SOFTWARE\\%s")));
}

void deleteSyncmlTree() {
    RegDeleteKey(HKEY_LOCAL_MACHINE,getFullReg( TEXT("SOFTWARE\\%s\\SyncclientPIM\\spds\\syncml")));
}

void deleteVersion30RegistryValues() {
    HKEY key = NULL;
    DWORD res;
    bool ret = false;

    res = RegOpenKeyEx(
            HKEY_LOCAL_MACHINE,
            getFullReg( TEXT("Software\\%s\\SyncclientPIM")),
            0,
            NULL,
            &key
            );

    if (res == ERROR_SUCCESS) {
        RegDeleteValue(key, TEXT("logLevel"));
    }

    if (key != 0) {
        RegCloseKey(key);
    }

}

void getJustInsertedRegistry() {


    wchar_t* value = NULL;
    value = readPropertyValue(getFullReg( TEXT("Software\\%s\\SyncclientPIM")), TEXT("path"));
    setPropertyValue(TEXT("SyncclientPIM"), TEXT("path"),    value, true);
    if (value) { delete [] value; value = NULL; }

    value = readPropertyValue(getFullReg( TEXT("Software\\%s\\SyncclientPIM")), TEXT("pluginVersion"));
    setPropertyValue(TEXT("SyncclientPIM"), TEXT("pluginVersion"),    value, true);
    if (value) { delete [] value; value = NULL; }

    value = readPropertyValue(getFullReg( TEXT("Software\\%s\\SyncclientPIM\\spds\\syncml\\Conn")), TEXT("userAgent"));
    setPropertyValue(TEXT("SyncclientPIM\\spds\\syncml\\Conn"), TEXT("userAgent"),    value, true);
    if (value) { delete [] value; value = NULL; }
    
    value = readPropertyValue(getFullReg( TEXT("Software\\%s\\SyncclientPIM\\spds\\syncml\\DevDetail")), TEXT("swv"));
    setPropertyValue(TEXT("SyncclientPIM\\spds\\syncml\\DevDetail"), TEXT("swv"),    value, true);
    if (value) { delete [] value; value = NULL; }

    value = readPropertyValue(getFullReg( TEXT("Software\\%s\\SyncclientPIM\\spds\\syncml\\DevDetail")), TEXT("oem"));
    setPropertyValue(TEXT("SyncclientPIM\\spds\\syncml\\DevDetail"), TEXT("oem"),    value, true);
    if (value) { delete [] value; value = NULL; }


}

void createSyncmlTransportRegistry()
{
    HKEY key = NULL;
    DWORD res;
    //wchar_t port [256];
    //wchar_t name [256];
    //wchar_t dll [256];
    //wcscpy(port, TEXT("SOFTWARE\\Microsoft\\Inbox\\Svc\\%s\\Port"));
    //wcscpy(name, TEXT("SOFTWARE\\Microsoft\\Inbox\\Svc\\%s\\Name"));
    //wcscpy(dll, TEXT("SOFTWARE\\Microsoft\\Inbox\\Svc\\%s\\DLL"));

    const wchar_t portValue[] = TEXT("0");
    wchar_t* nameValue=new wchar_t[wcslen(getFullReg( TEXT("%s")))];
    wcscpy(nameValue, getFullReg( TEXT("%s")));
    const wchar_t DLLValue[] = TEXT("syncmltransport.dll");

    RegCreateKeyEx(
            HKEY_LOCAL_MACHINE,
            getFullReg( TEXT("SOFTWARE\\Microsoft\\Inbox\\Svc\\%s")),
            0,
            NULL,
            REG_OPTION_NON_VOLATILE,
            KEY_ALL_ACCESS,
            NULL,
            &key,
            &res
            );

    if (key == 0) {
       goto finally;
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?