utils.h

来自「funambol window mobile客户端源代码」· C头文件 代码 · 共 336 行

H
336
字号
/*
 * 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".
 */


#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 DEFAULT_USER_W          TEXT("default@email")
    #define DEFAULT_USER_W_ACUTE    TEXT("<default@email>")

    #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, STP not available."

    #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 CONFIG_NAME         TEXT("config")

    #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 CONFIG_NAME_A         "config"

    #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, BOOL toUtc = TRUE);
    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();
    
    /**
     * Check if there is the flag to update contacts/appointments/task with the old crc.
     * If it "true" the old crc is used to check the item (to used for version
     * older then 6.5.0). The check flag is set by the setup dll
     */
    bool getUpdateFlag(int dataType);

    /**
     * Reset all the flags to update contacts/appointments/task with the old crc.
     */
    void resetUpdateFlags();
    
    BOOL isStorageMemoryAvailable(DWORD min = 0);
    void checkStorageMemory(DWORD min = 0);

    /**
    * it concatenes the path and the filename. THis check if the
    * path is the root (\) or if it is \My Documents\briefcase
    *
    * @parameter path of the 
    * @parameter filename the name to attach. If NULL it returns only
    *            the path\
    */
    wstring appendToPath(wchar_t* path, wchar_t* filename);
   
#endif

⌨️ 快捷键说明

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