コード例 #1
0
ファイル: Test7Zip2.cpp プロジェクト: HeavyFlagship/lib7zip
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;
}
コード例 #2
0
ファイル: test7zipprops.cpp プロジェクト: qopencc/lib7zip
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;
}