⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setup.cpp

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
 * 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 General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307  USA
 */


#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
//#include "Aygshell.h"


#define MSG_BEFORE_UNINSTALL TEXT("Do you want to keep the emails for the next Funambol Windows Mobile Plug-in installation?")
#define MSG_SYNC_IN_PROGRESS TEXT("Cannot uninstall. Sync is in progress.")
#define MSG_UI_PRESENT TEXT("Cannot uninstall. Funambol Windows Mobile Plug-in is opened.")
#define NO_SMARTPHONE TEXT("The version of the Funambol plug-in you are trying to install is not designed for this device. Please download the Pocket PC version.")
#define NO_POCKET_PC TEXT("The version of the Funambol plug-in you are trying to install is not designed for this device. Please download the Smartphone version.")

#define FILE1 TEXT("mails_I")
#define FILE2 TEXT("mails_O")
#define FILE3 TEXT("mails_D")
#define FILE4 TEXT("mails_S")
#define FILE5 TEXT("mails_T")
#define FILE6 TEXT("appointments.dat")
#define FILE7 TEXT("contacts.dat")
#define FILE8 TEXT("notes.dat")
#define FILE9 TEXT("tasks.dat")
#define FILE10 TEXT("briefcase.dat")
#define FILE11 TEXT("favorites.dat")
#define FILE18 TEXT("appOidToReset.dat")
#define FILE19 TEXT("wap_push.txt")


#define FILE12 TEXT("\\AccountLog.txt")
#define FILE13 TEXT("\\synclog.txt")
#define FILE14 TEXT("\\notlstnr.txt")
#define FILE15 TEXT("\\wap_push.txt")
#define FILE16 TEXT("\\wap.txt")
#define FILE17 TEXT("\\syncresults.txt")

int ret = 0;

int FileCopy ( const char *src, const char *dst );
int FileCopy ( const wchar_t *src, const wchar_t *dst );

const wchar_t *getProgramPath();
static BOOL IsSmartphoneDevice();

#if defined(WIN32_PLATFORM_WFSP)
    BOOL isPluginSmartphone = true;
#else 
    BOOL isPluginSmartphone = false;
#endif





wchar_t* getTempFileDir() {

    wchar_t* internalPath = new wchar_t[256];
    SHGetSpecialFolderPath(NULL, internalPath, CSIDL_WINDOWS, FALSE);
    wcscat(internalPath, TEXT("\\"));
    wcscat(internalPath, TEXT("tempFunFiles"));
    return internalPath;
}

void createFileForUpdate() {
    FILE* funinstall = fopen("\\__uninstall_Fun_plugin__", "a+");
    fputs ("uninstall", funinstall);
    fclose(funinstall);
}

void deleteFileForUpdate() {

    DeleteFile(TEXT("\\__uninstall_Fun_plugin__"));
}

bool existsFileForUpdate() {
    FILE* f = fopen("\\__uninstall_Fun_plugin__", "r");
    bool ret = false;
    if (f) {
        ret = true;
        fclose(f);
    }
    return ret;
}


BOOL removeFileInDir(const wchar_t* dir) {
    WIN32_FIND_DATA FileData;

    wchar_t internalPath[256];
    wcscpy(internalPath, dir);

    HANDLE hFind;
    wchar_t toFind    [512];
    wchar_t szNewPath [512];
    wchar_t filterPattern [256];

    szNewPath[0] =   0;

    DWORD dwAttrs;
    BOOL fFinished = FALSE;

    wsprintf(filterPattern, TEXT("*.*"));

    wsprintf(toFind, TEXT("%s/%s"), internalPath, filterPattern);

    hFind = FindFirstFile(toFind, &FileData);

    if (hFind != INVALID_HANDLE_VALUE) {

        while (!fFinished) {

            wsprintf(szNewPath, TEXT("%s/%s"), internalPath, FileData.cFileName);

            dwAttrs = GetFileAttributes(szNewPath);

            if (dwAttrs == FILE_ATTRIBUTE_DIRECTORY) { }

            else {
                  DeleteFile(szNewPath);
            }

            if (!FindNextFile(hFind, &FileData)) {
                if (GetLastError() == ERROR_NO_MORE_FILES) {
                    fFinished = TRUE;
                }
                else  {
                    return FALSE;
                }
            }
        }

        FindClose(hFind);
    }
    return true;
}

BOOL isWindowsMobile5() {

    OSVERSIONINFO OSVersionInfo;
    OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    GetVersionEx(&OSVersionInfo);

    if (OSVersionInfo.dwMajorVersion >= 5)
        return true;
    else
        return false;
}

bool backupFiles() {

    wchar_t* internalPath = getTempFileDir();
    if (internalPath == NULL)
        return false;

    const wchar_t* path = getProgramPath();

    CreateDirectory(internalPath, NULL);
    // clean if there are some dirty files
    removeFileInDir(internalPath);

    wchar_t src[255]; wchar_t dst[255];

    wsprintf(src, TEXT("%s\\%s"), path, FILE1);
    wsprintf(dst, TEXT("%s\\%s"), internalPath, FILE1);
    FileCopy(src, dst);

    wsprintf(src, TEXT("%s\\%s"), path, FILE2);
    wsprintf(dst, TEXT("%s\\%s"), internalPath, FILE2);
    FileCopy(src, dst);

    wsprintf(src, TEXT("%s\\%s"), path, FILE3);
    wsprintf(dst, TEXT("%s\\%s"), internalPath, FILE3);
    FileCopy(src, dst);

    wsprintf(src, TEXT("%s\\%s"), path, FILE4);
    wsprintf(dst, TEXT("%s\\%s"), internalPath, FILE4);
    FileCopy(src, dst);

    wsprintf(src, TEXT("%s\\%s"), path, FILE5);
    wsprintf(dst, TEXT("%s\\%s"), internalPath, FILE5);
    FileCopy(src, dst);

    wsprintf(src, TEXT("%s\\%s"), path, FILE6);
    wsprintf(dst, TEXT("%s\\%s"), internalPath, FILE6);
    FileCopy(src, dst);

    wsprintf(src, TEXT("%s\\%s"), path, FILE7);
    wsprintf(dst, TEXT("%s\\%s"), internalPath, FILE7);
    FileCopy(src, dst);

    wsprintf(src, TEXT("%s\\%s"), path, FILE8);
    wsprintf(dst, TEXT("%s\\%s"), internalPath, FILE8);
    FileCopy(src, dst);

    wsprintf(src, TEXT("%s\\%s"), path, FILE9);
    wsprintf(dst, TEXT("%s\\%s"), internalPath, FILE9);
    FileCopy(src, dst);

    wsprintf(src, TEXT("%s\\%s"), path, FILE10);
    wsprintf(dst, TEXT("%s\\%s"), internalPath, FILE10);
    FileCopy(src, dst);

    wsprintf(src, TEXT("%s\\%s"), path, FILE11);
    wsprintf(dst, TEXT("%s\\%s"), internalPath, FILE11);
    FileCopy(src, dst);

    wsprintf(src, TEXT("%s\\%s"), path, FILE18);
    wsprintf(dst, TEXT("%s\\%s"), internalPath, FILE18);

    wsprintf(src, TEXT("%s\\%s"), path, FILE19);
    wsprintf(dst, TEXT("%s\\%s"), internalPath, FILE19);

    FileCopy(src, dst);

    if (internalPath)
        delete [] internalPath;
    return true;
}


// return true for ok
bool backupFrom30() {
    backupFiles();
    // copy registry settings
    backupRegistry30();
    return true;
}


// return true for ok
bool backupClientVersion() {

    backupFiles();
    backupRegistryVersion();

    return true;
}

bool existsBackup() {

    // to check for the registry backup
    HKEY key = NULL;
    DWORD res;
    bool ret = false;

 //   wchar_t rpath[MAX_PATH] = TEXT("");
 //   wsprintf(rpath ,TEXT("\\Software\\%s\\SyncclientPIM"),getAppName());
    res = RegOpenKeyEx(
            HKEY_LOCAL_MACHINE,
            getFullReg(TEXT("\\Software\\%sBkp\\SyncclientPIM")),
            0,
            NULL,
            &key
            );

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

    if (res == ERROR_SUCCESS) {
        ret = true;
    } else {
        //MessageBox (NULL, TEXT("no backup"), TEXT ("Alert"), MB_SETFOREGROUND | MB_ICONHAND | MB_OK);
    }

    return ret;
}

bool restoreFiles() {

    wchar_t* internalPath = getTempFileDir();
    if (internalPath == NULL)
        return false;
    const wchar_t* path = getProgramPath();

    wchar_t src[255]; wchar_t dst[255];

    wsprintf(dst, TEXT("%s\\%s"), path, FILE1);
    wsprintf(src, TEXT("%s\\%s"), internalPath, FILE1);
    FileCopy(src, dst);

    wsprintf(dst, TEXT("%s\\%s"), path, FILE2);
    wsprintf(src, TEXT("%s\\%s"), internalPath, FILE2);
    FileCopy(src, dst);

    wsprintf(dst, TEXT("%s\\%s"), path, FILE3);
    wsprintf(src, TEXT("%s\\%s"), internalPath, FILE3);
    FileCopy(src, dst);

    wsprintf(dst, TEXT("%s\\%s"), path, FILE4);
    wsprintf(src, TEXT("%s\\%s"), internalPath, FILE4);
    FileCopy(src, dst);

    wsprintf(dst, TEXT("%s\\%s"), path, FILE5);
    wsprintf(src, TEXT("%s\\%s"), internalPath, FILE5);
    FileCopy(src, dst);

    wsprintf(dst, TEXT("%s\\%s"), path, FILE6);
    wsprintf(src, TEXT("%s\\%s"), internalPath, FILE6);
    FileCopy(src, dst);

    wsprintf(dst, TEXT("%s\\%s"), path, FILE7);
    wsprintf(src, TEXT("%s\\%s"), internalPath, FILE7);
    FileCopy(src, dst);

    wsprintf(dst, TEXT("%s\\%s"), path, FILE8);
    wsprintf(src, TEXT("%s\\%s"), internalPath, FILE8);
    FileCopy(src, dst);

    wsprintf(dst, TEXT("%s\\%s"), path, FILE9);
    wsprintf(src, TEXT("%s\\%s"), internalPath, FILE9);
    FileCopy(src, dst);

    wsprintf(dst, TEXT("%s\\%s"), path, FILE10);
    wsprintf(src, TEXT("%s\\%s"), internalPath, FILE10);
    FileCopy(src, dst);

    wsprintf(dst, TEXT("%s\\%s"), path, FILE11);
    wsprintf(src, TEXT("%s\\%s"), internalPath, FILE11);
    FileCopy(src, dst);

    wsprintf(dst, TEXT("%s\\%s"), path, FILE18);
    wsprintf(src, TEXT("%s\\%s"), internalPath, FILE18);
    FileCopy(src, dst);

    wsprintf(dst, TEXT("%s\\%s"), path, FILE19);
    wsprintf(src, TEXT("%s\\%s"), internalPath, FILE19);
    FileCopy(src, dst);

    if (internalPath)
        delete [] internalPath;
    return true;
}

// return true for ok
bool restoreClientVersion() {

    restoreFiles();
    restoreRegistryVersion();

    return true;
}

bool removeBackupVersion() {

    removeBackupRegistryVersion();

    wchar_t* internalPath = getTempFileDir();
    if (internalPath == NULL)
        return false;
    removeFileInDir(internalPath);
    RemoveDirectory(internalPath); // remove tmp empty dir

    return true;
}

//use to delete the funambol 3.0 installation files
bool removeAllFileFrom30() {

    const wchar_t* path = getProgramPath();

    removeFileInDir(path);
    wchar_t internalPath[256];
    wsprintf(internalPath, TEXT("%sdocs"), path);

    removeFileInDir(internalPath);
    RemoveDirectory(internalPath);
    return true;

}

/****************************************************************/
// retrieve the Funambol program path and set it in a static
// buffer. Return the buffer
const wchar_t *getProgramPath()
{
    static wchar_t path[MAX_PATH] = TEXT("");
    //wchar_t* ret_path = NULL;
    HKEY key = NULL;
    long err = 0;
    ULONG dim = 0;
    DWORD type =0;

    wchar_t rpath[MAX_PATH] = TEXT("");
    wsprintf(rpath ,TEXT("\\Software\\%s\\SyncclientPIM"),getAppName());

    RegOpenKeyEx(HKEY_LOCAL_MACHINE,rpath,0,0, &key );

    err = RegQueryValueEx(key, _T("path"),  NULL, NULL, NULL, &dim  );
    if (err == ERROR_SUCCESS)
    {
        if (dim > 0)
        {
            wchar_t *buf = new wchar_t[dim + 1];
            memset(buf, 0, (dim+1)*sizeof(wchar_t));
            err = RegQueryValueEx( key, _T("path"),  NULL, NULL, (UCHAR*)buf, &dim);
            RegCloseKey(key);
            wcscpy(path, buf);
            //ret_path = _wcsdup(buf);
            if(buf)
                {delete[]buf; buf=NULL;}
        }
        else
            RegCloseKey(key);
    }
    else
    {
        //-- reg value not found
        if (!path[0])
        {
            SHGetSpecialFolderPath(NULL, path, CSIDL_PROGRAM_FILES , FALSE);
            wcscat(path, TEXT("\\"));
            wcscat(path, PROGRAM_DIR);
            //ret_path = _wcsdup(path);
        }
    }
    return path;
}


/**
 * Start a command in a new process and return the pid
 * or 0 in case of error.
 */
unsigned long startprogram(const wchar_t *app, const wchar_t *cmdline)
{
    const wchar_t *path = getProgramPath();
    PROCESS_INFORMATION procinfo;

⌨️ 快捷键说明

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