7 / 7 / 1
Регистрация: 09.03.2013
Сообщений: 54
1

Создание cab архива

27.08.2013, 06:28. Показов 1714. Ответов 0
Метки нет (Все метки)

Студворк — интернет-сервис помощи студентам
Здравствуйте! Помогите реализовать код создания cab архива с помощью CabinetAPI

Код из msdn не получается скомпилировать, не понимаю как работать с этими макросами.

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#include <windows.h>
#include <strsafe.h>
#include <FCI.h>
 
#pragma comment(lib,"cabinet.lib")
 
//Function prototypes
BOOL InitCab(PCCAB pccab);
LPCSTR FCIErrorToString(FCIERROR err);
 
int main(INT argc, CHAR *argv[])
{
    ERF   erf;            //FCI error structure
    HFCI  hfci = NULL;    //FCI handle
    CCAB  ccab;           //cabinet information structure
    INT   iArg;           //Argument counter
    INT   iExitCode = -1; //The exit code
    LPSTR pszFileName;    //The file name to store in the cabinet
 
    (VOID)HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
 
    ZeroMemory(&erf, sizeof(ERF));
 
    if ( argc < 2 )
    {
        printf("Usage: %s [file1] [file2] [+] [file3] ...\n"
               "\n"
               "file - The file to be added to the cabinet.\n"
               "+    - Creates a new folder for the succeeding files.\n"
               , argv[0]);
        goto CLEANUP;
    }
    
    if ( InitCab(&ccab) == FALSE )
    {
        printf("Failed to initialize the cabinet information structure.\n");
        goto CLEANUP;
    }
 
    //Creates the FCI context
 
    hfci = FCICreate(&erf,              //pointer the FCI error structure
                     fnFilePlaced,      //function to call when a file is placed
                     fnMemAlloc,        //function to allocate memory
                     fnMemFree,         //function to free memory
                     fnFileOpen,        //function to open a file
                     fnFileRead,        //function to read data from a file
                     fnFileWrite,       //function to write data to a file
                     fnFileClose,       //function to close a file
                     fnFileSeek,        //function to move the file pointer
                     fnFileDelete,      //function to delete a file
                     fnGetTempFileName, //function to obtain a temporary file name
                     &ccab,             //pointer to the FCI cabinet information structure
                     NULL);             //client context parameter, NULL for this sample.
 
    if ( hfci == NULL )
    {
        printf("FCICreate failed with error code %d: %s\n",
               erf.erfOper,
               FCIErrorToString((FCIERROR)erf.erfOper));
        goto CLEANUP;
    }
 
    //Add the files to the cabinet
 
    for ( iArg = 1; iArg < argc; iArg++ )
    {
        if ( strcmp(argv[iArg],"+") == 0 )
        {
            if ( FCIFlushFolder(hfci,                //FCI handle
                                fnGetNextCabinet,    //function to get the next cabinet specifications
                                fnStatus) == FALSE ) //function to update the cabinet status
 
            {
                printf("FCIFlushFolder failed with error code %d: %s\n",
                       erf.erfOper,
                       FCIErrorToString((FCIERROR)erf.erfOper));
                goto CLEANUP;
            }
        }
        else
        {
            //Remove the directory structure from the file name to store
 
            pszFileName = strrchr(argv[iArg], '\\');
 
            if ( pszFileName == NULL )
            {
                pszFileName = argv[iArg];
            }
 
            //Adds a file to the cabinet under construction
 
            if ( FCIAddFile(hfci,                       //FCI handle
                            argv[iArg],                 //file to add
                            pszFileName,                //file name to store
                            FALSE,                      //do not run when extracted
                            fnGetNextCabinet,           //function to get the next cabinet specifications
                            fnStatus,                   //function to update the cabinet status
                            fnGetOpenInfo,              //function to get the file date, time and attributes
                            tcompTYPE_MSZIP) == FALSE ) //use MSZIP compression
                            
            {
                printf("FCIAddFile failed with error code %d: %s\n",
                       erf.erfOper,
                       FCIErrorToString((FCIERROR)erf.erfOper));
                goto CLEANUP;
            }
        }
    } 
 
    //Complete the cabinet
 
    if ( FCIFlushCabinet(hfci,                //FCI handle
                         FALSE,               //do not call fnGetNextCabinet
                         fnGetNextCabinet,    //function to get the next cabinet specifications
                         fnStatus) == FALSE ) //function to update the cabinet status
    {
        printf("FCIFlushCabinet failed with error code %d: %s\n",
               erf.erfOper,
               FCIErrorToString((FCIERROR)erf.erfOper));
        goto CLEANUP;
    }
 
    iExitCode = 0;
 
CLEANUP:
 
    //Destory the FCI context
 
    if ( hfci != NULL )
    {
        if ( FCIDestroy(hfci) != TRUE )
        {
            printf("FCIDestroy failed with error code %d: %s\n",
                   erf.erfOper,
                   FCIErrorToString((FCIERROR)erf.erfOper));
        }
    }
 
    return iExitCode;
}
 
BOOL InitCab(PCCAB pccab)
{
    BOOL bInit = FALSE;
    DWORD dCurrentDir;
    HRESULT hr;
 
    ZeroMemory(pccab, sizeof(CCAB));
 
    pccab->cb = 0x100000;            //Maximum cabinet size in bytes
    pccab->cbFolderThresh = 0x10000; //Maximum folder size in bytes
 
    pccab->setID = 555; //Cabinet set ID
    pccab->iCab = 1;    //Number of this cabinet in a set
    pccab->iDisk = 0;   //Disk number
 
 
    if( fnGetNextCabinet(pccab, 0, NULL) == TRUE ) //Get the next cabinet name
    {
        //Set the disk name to empty
 
        pccab->szDisk[0] =  '\0';
           
        //Set the cabinet path to the current directory
 
        dCurrentDir = GetCurrentDirectoryA(ARRAYSIZE(pccab->szCabPath), 
                                           pccab->szCabPath);
 
        if( dCurrentDir != 0 )
        {
            hr = StringCchCatA(pccab->szCabPath, 
                               ARRAYSIZE(pccab->szCabPath), 
                               "\\");
                
            bInit = SUCCEEDED(hr);
        }
    }
    
    return bInit;
}
 
LPCSTR FCIErrorToString(FCIERROR err)
{
    switch (err)
    {
        case FCIERR_NONE:
            return "No error";
 
        case FCIERR_OPEN_SRC:
            return "Failure opening file to be stored in cabinet";
        
        case FCIERR_READ_SRC:
            return "Failure reading file to be stored in cabinet";
        
        case FCIERR_ALLOC_FAIL:
            return "Insufficient memory in FCI";
 
        case FCIERR_TEMP_FILE:
            return "Could not create a temporary file";
 
        case FCIERR_BAD_COMPR_TYPE:
            return "Unknown compression type";
 
        case FCIERR_CAB_FILE:
            return "Could not create cabinet file";
 
        case FCIERR_USER_ABORT:
            return "Client requested abort";
 
        case FCIERR_MCI_FAIL:
            return "Failure compressing data";
 
        default:
            return "Unknown error";
    }
}
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
27.08.2013, 06:28
Ответы с готовыми решениями:

Создание ZIP архива
Есть несколько xml файлов. Надо их засунуть в 1 архив. Есть-ли подходящая либа на плюсах? Про zlib...

Создание архива rar/zip на C++
Народ, такая ситуация, мне необходимо создать архив rar или zip (желательно rar, запароленный) при...

Создание своего архива и работа с ним
Здравствуйте форумчане! Вопрос таков: можно ли создать свой архив, наподобе какого-нибудь *.pak,...

Распаковать файлы из архива CAB
Здравствуйте , мне тут по заданию необходимо скопировать файлы Вот отрывок из задания . &quot; мы...

0
27.08.2013, 06:28
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
27.08.2013, 06:28
Помогаю со студенческими работами здесь

Установка CAB-архива в Windows Vista
Скачал с сайта обновление в виде cab архива, подскажите как его установить:confused:

Сделать инстайлер моей программы + cab архива
Здравствуйте. Я никогда не делал инстайлеры, хочу попросить вашего совета. Какой программой лучше...

C#. CAB файл. Сборка CAB файла Cabwiz-ом Глюки в процессе
В общем понадобилось из программы собрать CAB-файл. inf собирал буквально по кусочкам, добавляя к...

Битый cab архив в MSDN для Visual Studio 2008 cab27.cab
у кого есть файлик для английской msdn для MVS2008 cab27.cab? При установке msdn говорит, что он...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
1
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2023, CyberForum.ru