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

📄 utils.h

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 H
字号:
/*
 * 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
 */


#ifndef INCL_UTILS_PIM
    #define INCL_UTILS_PIM

    #include "spdm/spdmutils.h"
    #include "pimstore.h"
    #include "Tlhelp32.h"
    #include "base/Log.h"
    #include "customization.h"

    #include <string>
    using namespace std;
    // definitions

/*
* For the Windows Mobile 5 the IPOutlook Application is the newer
* IPOutlookApp2 interface. We continue to keep the old IPOutlookApp
* to support wm2003 devices. It is used to get the POOM application and
* move into the PIMPR_* properties to set values that are not exposed 
* by the common IContact, IAppoointment and ITask interfaces.
* See {Contact,Appointment,Task}Builder for details
*/

#if _WIN32_WCE > 0x500 
    #define IP_OUTLOOK_APP IPOutlookApp2
#else
    #define IP_OUTLOOK_APP IPOutlookApp
#endif

    #define ERR_INTERNET_CONNECTION_MISSING       2005

    #define DIM_LOCAL_TEMP 256
    #define POA_OBJECT             TEXT("PocketOutlook.Application")
    #define INITGUID
    #define APPLICATION_URI        ROOT_CONTEXT
    #define FILENAME_APPOINTMENTS  "appointments.dat"
    #define FILENAME_CONTACTS      "contacts.dat"
    #define FILENAME_TASKS         "tasks.dat"
    #define FILENAME_FILES         "briefcase.dat"
    #define FILENAME_NOTES         "notes.dat"
    #define FILENAME_FAVORITES     "favorites.dat"

    #define PWI_EXTENSION_PATTERN   TEXT("*.pwi")
    #define PWI_EXTENSION           TEXT(".pwi")
    #define URL_EXTENSION           TEXT(".url")

    #define GPRS_FILE_NAME          TEXT("gprs.exe")


    #define MSG_ERR_AUTH_REQUIRED  TEXT("Not authorized.")
    #define MSG_ERR_AUTH_EXPIRED   TEXT("Account expired.")
    #define MSG_ERR_SRV_FAULT      TEXT("Server error.")
    #define MSG_ERR_NOT_FOUND      TEXT("Server returned NOT FOUND for SyncSource %s.")
    #define MSG_ERR_PROTOCOL_ERROR TEXT("Protocol error.")
    #define MSG_ERR_INTERNET_CONNECTION_MISSING TEXT("Impossible to establish an internet connection.")
    #define MSG_ERR_ADDRESSCHANGE_FAILED_CRED      TEXT("Address notification failed. Please check your credentials.")
    #define MSG_ERR_ADDRESSCHANGE_FAILED_NOTIF     "Address notification failed. The client is not notifiable."

    #define PREPARING_CONTACTS_SYNC         TEXT("Preparing CONTACTS sync...")
    #define PREPARING_APPOINTMENTS_SYNC     TEXT("Preparing APPOINTMENTS sync...")
    #define PREPARING_TASKS_SYNC            TEXT("Preparing TASKS sync...")
    #define PREPARING_FILES_SYNC            TEXT("Preparing FILES sync...")
    #define PREPARING_NOTES_SYNC            TEXT("Preparing NOTES sync...")
    #define PREPARING_FAVORITES_SYNC        TEXT("Preparing FAVORITES sync...")
    #define PREPARING_ASSET_SYNC            TEXT("Preparing ASSET sync...")

    #define STARTING_STD_SYNC   TEXT("Starting standard sync")
    #define STARTING_SLOW_SYNC  TEXT("Starting slow sync")

    #define SET_ALL_ITEMS       TEXT("Current item number is %i")
    #define NO_SYNC             TEXT("No sync for this source.")
    #define MESSAGE_FROM_SERVER TEXT("Response from server:")
    #define SERVER_NEW_ITEMS    TEXT("   New items are:\t\t%i")
    #define SERVER_UPDATE_ITEMS TEXT("   Updated items are:\t\t%i")
    #define SERVER_DELETE_ITEMS TEXT("   Deleted items are:\t\t%i")

    #define MESSAGE_TO_SERVER   TEXT("Send sync info to the server:")
    #define CLIENT_NEW_ITEMS    TEXT("   New items are:\t\t%i")
    #define CLIENT_UPDATE_ITEMS TEXT("   Updated items are:\t\t%i")
    #define CLIENT_DELETE_ITEMS TEXT("   Deleted items are:\t\t%i")

    #define ENDING_SYNC         TEXT("Ending sync...")
    #define SYNC_ENDED          TEXT("Sync ended")
    #define SEPARATOR            TEXT("===========")
    #define SEPARATOR_BLANK     TEXT("   ")

    #define APPOINTMENT_END_TIME    0.999306

    #define MAX_DATE_DOUBLE         949998.000000;
    #define MAX_DATE_DOUBLE_4000    767011.083333;

    #define START_DAY               TEXT("0000")
    #define END_DAY                 TEXT("2359")

    #define CDATA_START             TEXT("<![CDATA[")
    #define CDATA_END               TEXT("]]>")

    // name of the sources. Used in Main.cpp and SettingFunction.cpp
    #define APPOINTMENTS_NAME   TEXT("calendar")
    #define CONTACTS_NAME       TEXT("contact")
    #define TASKS_NAME          TEXT("task")
    #define FILES_NAME          TEXT("briefcase")
    #define NOTES_NAME          TEXT("note")
    #define FAVORITES_NAME      TEXT("favorite")
    #define MAILS_NAME          TEXT("mail")

    #define APPOINTMENTS_NAME_A   "calendar"
    #define CONTACTS_NAME_A       "contact"
    #define TASKS_NAME_A          "task"
    #define FILES_NAME_A          "briefcase"
    #define NOTES_NAME_A          "note"
    #define FAVORITES_NAME_A      "favorite"
    #define MAILS_NAME_A          "mail"

    #define LOW_DEVICE_MEMORY       "Error: too low storage memory (less than 2.5 Mb)"

    #define QP_MAX_LINE_LEN 70

    #define DIM_PATH 256
    #define DIM_FILE 300

    // static int constFiles           = 600;
    // static int constNotes           = 601;
    // static int constFavorites       = 602;

    typedef enum {
        constFiles           = 600,
        constNotes           = 601,
        constFavorites       = 602,
        constAsset           = 603
    } CONST_FILE_OBJ;

    typedef enum {
        OL_CONTACTS     = 10,
        OL_CALENDAR     = 9,
        OL_TASK         = 13,
        OL_BRIEFCASE    = 600,
        OL_NOTES        = 601,
        OL_FAVORITES    = 602
    } SourceType;

    /*------------------ methods -----------------*/

    static int windowsMobileVersion = 0;
    static int pocketPCDevice = 0;

    /*
    * use to determine if the source is a filesystem sync source or a db sync source.
    * If fileSystem needs to convert / char into @ to be possible creare a file (/ is not permitted in filename)
    * Is false in sync4j
    */
    static  BOOL FILE_SYSTEM_SYNC_SOURCE = false;

    /*
    * use to determine if is necessary to encode the key in base64 and decode the return key.
    * Is false in sync4j
    */
    static  BOOL IS_KEY_BASE64 = true;

    static  BOOL dbg = false;

    void error();
    void error(wchar_t* errorMessage);

    wchar_t* getElementContent(const wchar_t* xml, wchar_t* tag, unsigned int* pos);
    void     normalizeBoolean(wchar_t* localTemp);
    void     replaceAmpLGt(std::wstring &s);
    void     convertSlashAt(wchar_t* filename);
    void     convertAtSlash(wchar_t* filename);

    void     getDirName(const wchar_t* path, wchar_t* dirname);

    void     removeStartCarriage(wchar_t** ptr);
    void     removeEndCarriage(wchar_t** ptr);

    DATE     getSystemTime();
    void     systemTimeToDouble(const wchar_t* dataString, DATE* date, const wchar_t* action);
    void     doubleToSystemTime(wchar_t* tempDate, DATE date);
    void     doubleToSystemTimeHourZero(wchar_t* tempDate, DATE date, BOOL isHourToSetToZero);
    void     doubleToSystemTimeBirthday(wchar_t* tempDate, DATE date);
    void     systemTimeToDoubleBirthday(const wchar_t* dataString, DATE* date);
    void     systemTimeToDoubleBirthFormat(const wchar_t* dataString, DATE* date, const wchar_t* type);
    BOOL     getDateAndTimeAsIs(const wchar_t* dataString, DATE* date);

    bool isDateForAllDayEventFormat(const wchar_t* stringDate);

    /**
     * Parse the given date, in the formats:
     * @param date: the date to parse, in one of the formats:
     *               "YYYYMMDDThhmmss" (local time, complete) or
     *               "YYYYMMDDThhmmssZ" (utc time, complete)
     *               "yyyy-MM-dd" (date only format)
     * @param hour: can be used to force a particular hour to the date.
     *              valid values, at the moment, are only "0000" or "2359"
     *
     * @return the date, as a double value (Windows DATE format)
     */
    DATE getDATEFromString(const wchar_t *date, const wchar_t *hour = NULL);

    time_t   FileTimeToUnixTime(FILETIME &ft);
    void     UnixTimeToFileTime(time_t t, FILETIME &ft);
    void     localTimeToUTC(SYSTEMTIME &t);
    void     localTimeToUTC2(SYSTEMTIME &t);
    void     UTCToLocalTime(SYSTEMTIME &t);
    void     UTCToLocalTime2(SYSTEMTIME &t);
    BOOL     IsDST(TIME_ZONE_INFORMATION *ptzi, time_t localTime);
    void     SafeGetTimeZoneInformation(TIME_ZONE_INFORMATION *ptzi);
    time_t   GetTransitionTimeT(TIME_ZONE_INFORMATION *ptzi, int year, BOOL fStartDST);
    time_t   GetLocalTimeT();

    void     getFileName(const wchar_t* path, wchar_t* filename);

    wchar_t* encodeBase64UTF8 (wchar_t* toEncode);
    wchar_t* decodeBase64WUTF8(wchar_t* toDecode);
    char*    decodeBase64WUTF8(wchar_t* toDecode, int* myLen);

    void encodeSpecialChar(std::wstring &s);
    void decodeSpecialChar(std::wstring &s);
    void convertNewlines(std::wstring &s);
    /*
    * This function gets a unique file name in the current directory based on the parameter filename.
    * It checks in the specified dir if fileName exists. If none it return the same file name.
    * If one already exists it return a file name like - file (1) - according to the
    * rules applied by windows 2003 for PPC
    */
    void    getUniqueFileName(wchar_t* fileName);

    /*
    * return the length for the base64 array starting from length of the original array
    */
    int lengthForB64(int len);

    /*
    * Format a FILETIIME date (already into utc time) in a utc string yyyymmddThhmmssZ
    */
    wchar_t* FileTime2UTCTimeFormatter(FILETIME &ft, wchar_t* out);

    IP_OUTLOOK_APP* getOutlookApp();
    void releaseOutlookApp(IP_OUTLOOK_APP* polApp);
    void disposeOutlookApp();
    
    bool isSIF(const string& dataType);
    bool isSIF(const wstring& dataType);

    bool checkSIF(int dataType);
    wchar_t* getDayBefore(int dayBefore);

    bool convertRrule(IRecurrencePattern * pRecPat, wchar_t* rrule, DATE startDate);
    wchar_t* extractRrule(IRecurrencePattern * pRecPat);
    wchar_t* extractDayOfWeek(long l);
    long calculateDayOfWeek(wchar_t* in);
    bool isDayOfWeek(wchar_t* string);
    long getWeekDay(DATE dt);

    wchar_t* decodeQpUTF8VProp(wchar_t* value);
    bool addQpUTFString(BSTR pwsz, char* fAppend, int start);

    DWORD getProcessPid(const wchar_t *name);
    DWORD stopProcess(DWORD pid);
    DWORD stopProcessByName(const wchar_t *name);

    DWORD getMemoryAvailable();
    BOOL isMemoryAvailable(DWORD min = 0);
    BOOL isWindowsMobile5();
    unsigned int getMaxObjectSizeToSend();
    BOOL existsDirectory(wchar_t* dir);
    BOOL isPocketPC();
    const wchar_t* getFriendlyName(wstring name);
    LogLevel getLOGLevel();

#endif

⌨️ 快捷键说明

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