//============================================================================= CIFin::CifFile::CifFile(std::string filename) { _first = _current = _default = NULL; _curLay = NULL; _hierTree = NULL; _fileName = filename; std::ostringstream info; // Open the input file std::string fname(convertString(_fileName)); if (!(_cifFh = fopen(fname.c_str(),"rt"))) // open the input file { _status = cfs_FNF; return; } // feed the flex with the buffer of the input file void* b = new_cif_lex_buffer( _cifFh ); info << "Parsing \"" << _fileName << "\" using CIF grammar"; tell_log(console::MT_INFO,info.str()); CIFInFile = this; _default = DEBUG_NEW CifStructure(0,NULL); _default->cellNameIs(std::string(getFileNameOnly(filename) + "_cif")); // run the bison generated parser ciflloc.first_column = ciflloc.first_line = 1; ciflloc.last_column = ciflloc.last_line = 1; /* cifdebug = 1;*/ cifparse(); delete_cif_lex_buffer( b ); if (cifnerrs > 0) _status = cfs_ERR; else _status = cfs_POK; closeFile(); }
/* instead of using just "test.exe" as the file name (LPSTR)getFileNameOnly(s).c_str() I use the whole path. Looks much better in Winrar and with the MS Cab viewer as one ca see the entier file paths Except that it doesn't always work....*sigh*. So you'll have to use the filename to determine what the full path was. */ bool MakeCab(const std::wstring& in_Where, const std::string& in_Why, DWORD& o_NumFilesInCab, const std::wstring& in_StrThisFileOnly, const bool in_bDontRecurse = false) { g_CurrentDescription = in_Why; ERF erf = { 0 }; CCAB cab_parameters = { 0 }; client_state cs = { 0 }; set_cab_parameters(&cab_parameters); HFCI hfci = FCICreate( &erf, file_placed, mem_alloc, mem_free, fci_open, fci_read, fci_write, fci_close, fci_seek, fci_delete, get_temp_file, &cab_parameters, &cs ); if (hfci == NULL) { printf("FCICreate() failed: code %d [%s]\n", erf.erfOper, return_fci_error_string( (FCIERROR)erf.erfOper)); return false; } o_NumFilesInCab = 0; std::vector<std::wstring> VecFiles; std::list<std::wstring> SkippedExtensions; if(in_StrThisFileOnly.empty()) { if( GetFileCount(in_Where.c_str(), o_NumFilesInCab, VecFiles, SkippedExtensions, in_bDontRecurse) && o_NumFilesInCab) { wprintf(L"Ready to create a CAB using [%s] with [%d] files in it...\r\n", in_Where.c_str(), o_NumFilesInCab); printf("Destination CAB: [%s]\r\n", GetExeDir().c_str()); } else { wprintf(L"Cannot perform under [%s]...Specify a valid, non-empty folder\r\n", in_Where.c_str()); printf("Destination CAB: [%s]\r\n", GetExeDir().c_str()); return false; } } else { ++o_NumFilesInCab; VecFiles.push_back(in_StrThisFileOnly); } // For each file in 'in_Where' folder and subfolder, unless 'in_StrThisFileOnly' param was specified for each(std::wstring s in VecFiles) { if (FALSE == FCIAddFile( hfci, (LPSTR)wide2Ansi(s).c_str(), // file to add, can't be a folder, needs full path (LPSTR)getFileNameOnly(s).c_str(), // file name in cabinet file, and should not include any path information (e.g. “TEST.EXE”). FALSE, // specifies whether the file should be executed automatically when the cabinet is extracted get_next_cabinet, progress, // should point to a function which is called periodically by FCI so that the application may send a progress report to the user get_open_info, // point to a function which opens a file and returns its datestamp, timestamp, and attributes COMPRESSION_TYPE)) { printf("FCIAddFile(%s) failed: code %d [%s]\n", wide2Ansi(s).c_str(), erf.erfOper, return_fci_error_string( (FCIERROR)erf.erfOper)); TRACE3("FCIAddFile(%s) failed: code %d [%s]\n", wide2Ansi(s).c_str(), erf.erfOper, return_fci_error_string( (FCIERROR)erf.erfOper)); //FCIDestroy(hfci); //return false; // Try to keep a possible good file created so far... o_NumFilesInCab--; } } /* The FCIFlushCabinet API forces the current cabinet under construction to be completed immediately and written to disk. Further calls to FCIAddFile will cause files to be added to another cabinet. It is also possible that there exists pending data in FCI’s internal buffers that will may require spillover into another cabinet, if the current cabinet has reached the application-specified media size limit. */ if(o_NumFilesInCab > 0) { if (FALSE == FCIFlushCabinet( hfci, FALSE, // The fGetNextCab flag determines whether the function pointed to by the supplied GetNextCab parameter, will be called. get_next_cabinet, // If fGetNextCab is TRUE, then GetNextCab will be called to obtain continuation information progress)) { printf("FCIFlushCabinet() failed: code %d [%s]\n", erf.erfOper, return_fci_error_string( (FCIERROR)erf.erfOper)); FCIDestroy(hfci); return false; } } if (FCIDestroy(hfci) != TRUE) { printf("FCIDestroy() failed: code %d [%s]\n", erf.erfOper, return_fci_error_string( (FCIERROR)erf.erfOper)); return false; } return o_NumFilesInCab > 0; }