void ProcessFolder(xr_vector<char*>& list, LPCSTR path) { xr_vector<char*>* i_list = FS.file_list_open ("$target_folder$",path,FS_ListFiles|FS_RootOnly); if (!i_list){ Log ("ERROR: Unable to open file list:", path); return; } xr_vector<char*>::iterator it = i_list->begin(); xr_vector<char*>::iterator itE = i_list->end(); for (;it!=itE;++it){ xr_string tmp_path = xr_string(path)+xr_string(*it); if (!testSKIP(tmp_path.c_str())){ list.push_back (xr_strdup(tmp_path.c_str())); //. Msg ("+f: %s",tmp_path.c_str()); }else{ Msg ("-f: %s",tmp_path.c_str()); } } FS.file_list_close (i_list); }
void xrCompressor::GatherFiles(LPCSTR path) { xr_vector<char*>* i_list = FS.file_list_open ("$target_folder$",path,FS_ListFiles|FS_RootOnly); if (!i_list){ Msg ("! ERROR: Unable to open file list:%s", path); return; } xr_vector<char*>::iterator it = i_list->begin(); xr_vector<char*>::iterator itE = i_list->end(); for (;it!=itE;++it) { xr_string tmp_path = xr_string(path)+xr_string(*it); if (!testSKIP(tmp_path.c_str())) { files_list->push_back (xr_strdup(tmp_path.c_str())); }else{ Msg ("* -f: %s",tmp_path.c_str()); } } FS.file_list_close (i_list); }
void xrCompressor::CompressOne(LPCSTR path) { filesTOTAL ++; if (testSKIP(path)) { filesSKIP ++; printf (" - a SKIP"); Msg ("%-80s - SKIP",path); return; } string_path fn; strconcat (sizeof(fn), fn, target_name.c_str(), "\\", path); if (::GetFileAttributes(fn)==u32(-1)) { filesSKIP ++; printf (" - CAN'T OPEN"); Msg ("%-80s - CAN'T OPEN",path); return; } IReader* src = FS.r_open (fn); if (0==src) { filesSKIP ++; printf (" - CAN'T OPEN"); Msg ("%-80s - CAN'T OPEN",path); return; } bytesSRC += src->length (); u32 c_crc32 = crc32 (src->pointer(),src->length()); u32 c_ptr = 0; u32 c_size_real = 0; u32 c_size_compressed = 0; u32 a_tests = 0; ALIAS* A = testALIAS (src,c_crc32,a_tests); printf ("%3da ",a_tests); if(A) { filesALIAS ++; printf ("ALIAS"); Msg ("%-80s - ALIAS (%s)",path,A->path); // Alias found c_ptr = A->c_ptr; c_size_real = A->c_size_real; c_size_compressed = A->c_size_compressed; } else { if (testVFS(path)) { filesVFS ++; // Write into BaseFS c_ptr = fs_pack_writer->tell (); c_size_real = src->length(); c_size_compressed = src->length(); fs_pack_writer->w (src->pointer(),c_size_real); printf ("VFS"); Msg ("%-80s - VFS",path); } else { //if(testVFS(path)) // Compress into BaseFS c_ptr = fs_pack_writer->tell(); c_size_real = src->length(); if (0!=c_size_real) { u32 c_size_max = rtc_csize (src->length()); u8* c_data = xr_alloc<u8> (c_size_max); t_compress.Begin (); c_size_compressed = c_size_max; if (bFast) { R_ASSERT(LZO_E_OK == lzo1x_1_compress ((u8*)src->pointer(),c_size_real,c_data,&c_size_compressed,c_heap)); }else { R_ASSERT(LZO_E_OK == lzo1x_999_compress ((u8*)src->pointer(),c_size_real,c_data,&c_size_compressed,c_heap)); } t_compress.End (); if ((c_size_compressed+16) >= c_size_real) { // Failed to compress - revert to VFS filesVFS ++; c_size_compressed = c_size_real; fs_pack_writer->w (src->pointer(),c_size_real); printf ("VFS (R)"); Msg ("%-80s - VFS (R)",path); } else { // Compressed OK - optimize if (!bFast) { u8* c_out = xr_alloc<u8> (c_size_real); u32 c_orig = c_size_real; R_ASSERT (LZO_E_OK == lzo1x_optimize (c_data,c_size_compressed,c_out,&c_orig, NULL)); R_ASSERT (c_orig == c_size_real ); xr_free (c_out); }//bFast fs_pack_writer->w (c_data,c_size_compressed); printf ("%3.1f%%", 100.f*float(c_size_compressed)/float(src->length())); Msg ("%-80s - OK (%3.1f%%)",path,100.f*float(c_size_compressed)/float(src->length())); } // cleanup xr_free (c_data); }else { //0!=c_size_real filesVFS ++; c_size_compressed = c_size_real; printf ("VFS (R)"); Msg ("%-80s - EMPTY FILE",path); } }//test VFS } //(A) // Write description write_file_header (path,c_crc32,c_ptr,c_size_real,c_size_compressed); if (0==A) { // Register for future aliasing ALIAS R; R.path = xr_strdup (fn); R.crc = c_crc32; R.c_ptr = c_ptr; R.c_size_real = c_size_real; R.c_size_compressed = c_size_compressed; aliases.insert (mk_pair(R.c_size_real,R)); } FS.r_close (src); }