Example #1
0
	Fuse7z_lib7zip(std::string const & filename, std::string const & cwd) : Fuse7z(filename, cwd), stream(filename) {
		logger << "Initialization of fuse-7z with archive " << filename << Logger::endl;

		if (!lib.Initialize()) {
			stringstream ss;
			ss << "7z library initialization failed";
			throw runtime_error(ss.str());
		}

		WStringArray exts;

		if (!lib.GetSupportedExts(exts)) {
			stringstream ss;
			ss << "Could not get list of 7z-supported file extensions";
			throw runtime_error(ss.str());
		}

		
		logger << "Supported extensions : ";
		size_t size = exts.size();
		for(size_t i = 0; i < size; i++) {
			std::wstring ext = exts[i];
			

			for(size_t j = 0; j < ext.size(); j++) {
				logger << (char)(ext[j] &0xFF);
			}
			logger << " ";

		}
		logger << Logger::endl;


		if (lib.OpenArchive(&stream, &archive)) {
			unsigned int numItems = 0;

			archive->GetItemCount(&numItems);

			logger << "Archive contains " << numItems << " entries" << Logger::endl;
			Node * node;
			for(unsigned int i = 0;i < numItems;i++) {
				C7ZipArchiveItem * pArchiveItem = NULL;
				if (archive->GetItemInfo(i, &pArchiveItem)) {
					std::wstring wpath(pArchiveItem->GetFullPath());
					std::string path;
					path.resize(wpath.length());
					std::copy(wpath.begin(), wpath.end(), path.begin());

					node = root_node->insert(const_cast<char*>(path.c_str()));
					node->id = i;

					node->is_dir = pArchiveItem->IsDir();

					{
						unsigned long long size;
						pArchiveItem->GetUInt64Property(lib7zip::kpidSize, size);
						node->stat.st_size = size;
					}

					{
						unsigned long long secpy, time, bias, gain;
						secpy = 31536000;
						gain = 10000000ULL;
						bias = secpy * gain * 369 + secpy * 2438356ULL + 5184000ULL;
						pArchiveItem->GetFileTimeProperty(lib7zip::kpidATime, time);
						node->stat.st_atim.tv_sec = (time - bias)/gain;
						node->stat.st_atim.tv_nsec = ((time - bias) % gain) * 100;
						pArchiveItem->GetFileTimeProperty(lib7zip::kpidCTime, time);
						node->stat.st_ctim.tv_sec = (time - bias)/gain;
						node->stat.st_ctim.tv_nsec = ((time - bias) % gain) * 100;
						pArchiveItem->GetFileTimeProperty(lib7zip::kpidMTime, time);
						node->stat.st_mtim.tv_sec = (time - bias)/gain;
						node->stat.st_mtim.tv_nsec = ((time - bias) % gain) * 100;
					}
				}
				if ((i+1) % 10000 == 0) {
					logger << "Indexed " << (i+1) << "th file : " << node->fullname() << Logger::endl;
				}
			}
		}
		else {
			stringstream ss;
			ss << "open archive " << archive_fn  << " failed" << endl;
			throw runtime_error(ss.str());
		}

	}
Example #2
0
int main(int argc, char * argv[])
#endif
{
	C7ZipLibrary lib;

	if (!lib.Initialize()) {
		wprintf(L"initialize fail!\n");
		return 1;
	}

	WStringArray exts;

	if (!lib.GetSupportedExts(exts)) {
		wprintf(L"get supported exts fail\n");
		return 1;
	}

	size_t size = exts.size();

	for(size_t i = 0; i < size; i++) {
		wstring ext = exts[i];

		for(size_t j = 0; j < ext.size(); j++) {
			wprintf(L"%c", (char)(ext[j] &0xFF));
		}

		wprintf(L"\n");
	}

	C7ZipArchive * pArchive = NULL;

	TestInStream stream("Test7Zip.zip");
	TestOutStream oStream("TestResult.txt");
        if (lib.OpenArchive(&stream, &pArchive, true)) {
		unsigned int numItems = 0;

		pArchive->GetItemCount(&numItems);

		wprintf(L"%d\n", numItems);

		for(unsigned int i = 0;i < numItems;i++) {
			C7ZipArchiveItem * pArchiveItem = NULL;

			if (pArchive->GetItemInfo(i, &pArchiveItem)) {
				wprintf(L"%d,%ls,%d\n", pArchiveItem->GetArchiveIndex(),
						pArchiveItem->GetFullPath().c_str(),
						pArchiveItem->IsDir());

				wprintf(L"get all properties\n");
				for(lib7zip::PropertyIndexEnum index = lib7zip::kpidPackSize;
					index <= lib7zip::kpidIsDir;
					index = (lib7zip::PropertyIndexEnum)(index + 1)) {
					wstring strVal = L"";
					unsigned __int64 val = 0;
					bool bVal = false;

					bool result = pArchiveItem->GetUInt64Property(index, val);

					wprintf(L"\n\nGetProperty:%d %ls\n", (int)index, 
							index_names[(int)index]);

					wprintf(L"UInt64 result:%ls val=%ld\n", 
							result ? L"true" : L"false",
							val);

					result = pArchiveItem->GetBoolProperty(index, bVal);

					wprintf(L"Bool result:%ls val=%ls\n", 
							result ? L"true" : L"false",
							bVal ? L"true" : L"false");

					result = pArchiveItem->GetStringProperty(index, strVal);

					wprintf(L"String result:%ls val=%ls\n", 
							result ? L"true" : L"false",
							strVal.c_str());				

					result = pArchiveItem->GetFileTimeProperty(index, val);

					wprintf(L"FileTime result:%ls val=%ld\n", 
							result ? L"true" : L"false",
							val);				
				}

				//set archive password or item password
				pArchive->SetArchivePassword(L"test");
				if (i==0) {
					//Or set password for each archive item
					//pArchiveItem->SetArchiveItemPassword(L"test");
					pArchive->Extract(pArchiveItem, &oStream);
				}
			} //if
		}//for
	}
	else {
		wprintf(L"open archive Test7Zip.zip fail\n");
	}

	if (pArchive != NULL)
		delete pArchive;

	return 0;
}
Example #3
0
int main(int argc, char * argv[])
#endif
{
    C7ZipLibrary lib;

    if (!lib.Initialize()) {
        wprintf(L"initialize fail!\n");
        return 1;
    }

    const char * files[] = {
        "Test7ZipProp.tar",
        "testzip.zip",
        "Test7Zip.7z",
        "lib7zip-1.4.0.tar.gz",
        "testbzip.bz2",
    };

    const wchar_t * files_ext[] = {
        L"tar",
        L"zip",
        L"7z",
        L"gz",
        L"bz2",
    };

    C7ZipArchive * pArchive = NULL;

    for (int i=0; i < sizeof(files) / sizeof(const char *); i++) {
        TestInStream stream(files[i], files_ext[i]);

        if (lib.OpenArchive(&stream, &pArchive)) {
            unsigned int numItems = 0;

            //print archive properties
            for(lib7zip::PropertyIndexEnum index = lib7zip::PROP_INDEX_BEGIN;
                    index < lib7zip::PROP_INDEX_END;
                    index = (lib7zip::PropertyIndexEnum)(index + 1)) {
                wstring strVal = L"";
                unsigned __int64 val = 0;
                bool bVal = false;

                bool result = pArchive->GetUInt64Property(index, val);

                wprintf(L"\n\nGetArciveProperty:%d %ls\n", (int)index,
                        index_names[(int)index]);

                wprintf(L"Archive UInt64 result:%ls val=%ld\n",
                        result ? L"true" : L"false",
                        val);

                result = pArchive->GetBoolProperty(index, bVal);

                wprintf(L"Archive Bool result:%ls val=%ls\n",
                        result ? L"true" : L"false",
                        bVal ? L"true" : L"false");

                result = pArchive->GetStringProperty(index, strVal);

                wprintf(L"Archive String result:%ls val=%ls\n",
                        result ? L"true" : L"false",
                        strVal.c_str());

                result = pArchive->GetFileTimeProperty(index, val);

                wprintf(L"Archive FileTime result:%ls val=%ld\n",
                        result ? L"true" : L"false",
                        val);
            }

            pArchive->GetItemCount(&numItems);

            wprintf(L"Contains Items:%d\n", numItems);

            for(unsigned int i = 0; i < numItems; i++) {
                C7ZipArchiveItem * pArchiveItem = NULL;

                if (pArchive->GetItemInfo(i, &pArchiveItem)) {
                    wprintf(L"%d,%ls,%d\n", pArchiveItem->GetArchiveIndex(),
                            pArchiveItem->GetFullPath().c_str(),
                            pArchiveItem->IsDir());

                    wprintf(L"get all properties\n");
                    for(lib7zip::PropertyIndexEnum index = lib7zip::PROP_INDEX_BEGIN;
                            index <= lib7zip::PROP_INDEX_END;
                            index = (lib7zip::PropertyIndexEnum)(index + 1)) {
                        wstring strVal = L"";
                        unsigned __int64 val = 0;
                        bool bVal = false;

                        bool result = pArchiveItem->GetUInt64Property(index, val);

                        wprintf(L"\n\nGetProperty:%d %ls\n", (int)index,
                                index_names[(int)index]);

                        wprintf(L"UInt64 result:%ls val=%ld\n",
                                result ? L"true" : L"false",
                                val);

                        result = pArchiveItem->GetBoolProperty(index, bVal);

                        wprintf(L"Bool result:%ls val=%ls\n",
                                result ? L"true" : L"false",
                                bVal ? L"true" : L"false");

                        result = pArchiveItem->GetStringProperty(index, strVal);

                        wprintf(L"String result:%ls val=%ls\n",
                                result ? L"true" : L"false",
                                strVal.c_str());

                        result = pArchiveItem->GetFileTimeProperty(index, val);

                        wprintf(L"FileTime result:%ls val=%ld\n",
                                result ? L"true" : L"false",
                                val);
                    }
                }
            }
        }
        else {
            wprintf(L"open archive %s fail\n", files[i]);
        }
    }

    if (pArchive != NULL)
        delete pArchive;

    return 0;
}