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

📄 msiactions.cpp

📁 JDesktop Integration Components (JDIC)
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2004 Sun Microsystems, Inc. All rights reserved. Use is * subject to license terms. *  * This program is free software; you can redistribute it and/or modify * it under the terms of the Lesser GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. *  * 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 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 <windows.h>#include <msi.h>#include <msiquery.h>#include <fcntl.h>#include <stdio.h>#include <stdlib.h>#include <direct.h>#include <shlwapi.h>#include <sys/stat.h>#define MAX_PATH_SIZE 2048char g_TEMP_BASE_PATH     [MAX_PATH_SIZE] = {0};  // C:\DOCUME~1\ADMINI~1\LOCALS~1\Tempchar g_TEMP_JAVAWS_PATH   [MAX_PATH_SIZE] = {0};  // C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\[javaws4c1.tmp]char g_TEMP_INSTALLER_JAR [MAX_PATH_SIZE] = {0};  // C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\[javaws4c1.tmp]\installer.jarchar g_TEMP_JAVAWS_URL    [MAX_PATH_SIZE] = {0};  // file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/[javaws4c1.tmp]char g_JAVAWS_HOME        [MAX_PATH_SIZE] = {0};  // C:\program files\java\j2re1.5.0\binchar g_SHORTCUT           [128] = {0};            // enough space to hold "-shortcut"char g_ASSOCIATION        [128] = {0};            // enough space to hold "-association"char g_CACHE_TYPE         [128] = {0};            // enough space to hold "-system"FILE *zipfp;char *dirname(char *path){    char *dstr = strdup(path);    char *p = dstr ;    while ( (p = strchr(p,'\\')) != NULL)    {         *p = '/';        p++;    }    char *lastslash = strrchr(dstr, '/');    if (lastslash != NULL)    {        *lastslash = '\0';    }    else    {        free(dstr) ;        dstr = NULL ;    }    return dstr ;}void mkdirs(char* path){    if (strlen(path) <= 0)        return;    char dir[MAX_PATH_SIZE];    strcpy(dir, path);    char* slash = strrchr(dir, '/');    if (slash == 0)        return;    *slash = 0;    mkdirs(dir);    mkdir(path);}/* For documentation purposes.struct zip_header {  unsigned short  magic0 ; 2 2  unsigned short  magic1 ; 2 4  unsigned short  vers; 2 6  unsigned short  flags; 2 8  unsigned short  compression; 2 10  unsigned short  modtime;2 12  unsigned short  moddate;2 14  int     crc; 4 18  int     clen;4  22  int     ulen; 4 26   unsigned short  filenamelen; 2 28  unsigned short  extrafieldlen; 2 30};*/int readAndWrite(){    char filename[MAX_PATH_SIZE];    char filepath[MAX_PATH_SIZE];    int rc;    //Note: We have already read the magic number of 4 bytes.    //Skip to compression if the file is compressed then abort.    fseek(zipfp,4,SEEK_CUR);    unsigned short compression;    rc = fread(&compression,1,sizeof(unsigned short),zipfp);    if (compression)     {        //l_abort("Error: Cannot unzip deflated file entries.\n");        return 0;      }    // Skip over to file length    fseek(zipfp,12,SEEK_CUR);     int file_len;    rc = fread(&file_len,1,sizeof(int),zipfp);    unsigned short filenamelen;    rc = fread(&filenamelen,1,sizeof(unsigned short),zipfp);    unsigned short extrafieldlen;    rc = fread(&extrafieldlen,1, sizeof(unsigned short), zipfp);    rc = fread(filename,filenamelen,sizeof(char),zipfp);    filename[filenamelen]='\0';    if (rc <=0) {        //sprintf(message,"Error: Could not read filename <%s>  from zip header\n", filename);        return 0;    }    bool isDir = (filename[filenamelen-1] == '/') ? true : false;    sprintf(filepath, "%s\\%s", g_TEMP_JAVAWS_PATH, filename);    char *pathname = dirname(filepath);    if (pathname != NULL) {        mkdirs(pathname);        free(pathname);    }    FILE *filefp=NULL;    if (!isDir) {        filefp = fopen(filepath,"wb+");        if (filefp == NULL) {            //sprintf(message,"Error:fopen: while opening file <%s>\n",filename);            return 0;        }    }    if (extrafieldlen > 0) {        fseek(zipfp,extrafieldlen,SEEK_CUR);    }    if (!isDir) {        //Read and write our file entry        rc = 1;        {            char *buffer = (char *) malloc(file_len+1);            if(!buffer)            {                fclose(filefp);                return 0;            }            rc = fread(buffer, 1, file_len, zipfp);            int rc2 = fwrite(buffer,1,rc,filefp);            if (buffer)                free(buffer);        }        fclose(filefp);    }    return 1;}bool isNext() {    unsigned short magic[2];    int rc;    rc = fread(&magic[0],1,2,zipfp);    rc = fread(&magic[1],1,2,zipfp);    return ( (magic[0] == 0x4B50) && (magic[1] == 0x0403) );}// Public API//Open a Zip file and initialize.int openZipFileReader(char *fname) {    if (!zipfp) {        zipfp = fopen(fname, "rb");        if (!zipfp) {            return 0;        }    }    return 1;}//Close a Zip File Readervoid closeZipFileReader() {    if (zipfp) {        fflush(zipfp);    fclose(zipfp);    zipfp=NULL;    }}//Read the file and extract its contents to //the directory of the zipfile.int do_extract(char *inputzip){    char *extract_dir = dirname(inputzip);    if ( (extract_dir != NULL) && (strlen(extract_dir) > 0) )     {        // ensure directory is created first        char *dir = (char *) malloc(strlen(extract_dir) + 2);        if(!dir)        {            return 0;        }        sprintf(dir, "%s/", extract_dir);        mkdirs(dir);        free(dir);        chdir(extract_dir);        free(extract_dir);    }    if (! openZipFileReader(inputzip))     {        return 0;    }    bool next = isNext();    // We must have at least one entry    if (!next) {          //sprintf(message,"Error: no entries in zip file.\n");        return 0;    }    while (next) {        readAndWrite();        next = isNext();    }    closeZipFileReader();    return 1;}/** * Recursively remove the specified directory and all its files and sub-dirs. * * @param dirName Specify the directory name * @return 1 if succeed */ int RemoveDir(char * dirName){    WIN32_FIND_DATA fileData;    HANDLE hSearch;    char filePattern[MAX_PATH_SIZE] = {0};    sprintf(filePattern, "%s\\%s", dirName, "*");    BOOL fFinished = false;    hSearch = FindFirstFile(filePattern, &fileData);        while (!fFinished)     {        if (fileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)         {            if ((strcmp(fileData.cFileName, ".") != 0) && (strcmp(fileData.cFileName, "..") != 0))            {                //For none "." & ".." directory, take resursive handling mechanism                char nextDirName[MAX_PATH_SIZE] = {0};                sprintf(nextDirName, "%s\\%s", dirName, fileData.cFileName);                RemoveDir(nextDirName);            }        }        else         {            //For general file, just delete            char fullFileName[MAX_PATH_SIZE] = {0};            sprintf(fullFileName, "%s\\%s", dirName, fileData.cFileName);            DeleteFile(fullFileName);                    }        if (!FindNextFile(hSearch, &fileData) && (GetLastError() == ERROR_NO_MORE_FILES))                fFinished = true;    }    //Close the search handle    FindClose(hSearch);    //Then delete the directory    RemoveDirectory(dirName);    return 1;}

⌨️ 快捷键说明

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