setup.cpp
来自「funambol window mobile客户端源代码」· C++ 代码 · 共 980 行 · 第 1/2 页
CPP
980 行
/*
* 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
//#include "Aygshell.h"
#include "spds/DataTransformerFactory.h"
#include "spds/B64Encoder.h"
#include "spds/B64Decoder.h"
#include "spds/DESEncoder.h"
#include "spds/DESDecoder.h"
#include "base/stringUtils.h"
//#include "base/util/utils.h"
#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")
// Used to have a different key in the cared and comed edition
// With the value NULL, the default password is used.
// it is define in ClientSettings.h too (because the dll is not linked)
// important: the follow define must be in this way
// PASS_KEY<4 blanks>NULL
#define PASS_KEY NULL
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();
bool checkCredentials();
#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;
unsigned long ret_code=0;
wchar_t *cmd = new wchar_t[wcslen(path)+wcslen(app)+5];
wsprintf(cmd, TEXT("%s\\%s"), path, app);
if( CreateProcess( cmd, cmdline,
NULL, NULL, FALSE, 0,
NULL, NULL, NULL, &procinfo ) ) {
ret_code = procinfo.dwProcessId;
}
else
ret_code= 0;
if(path)
{path=NULL;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?