نحوه استفاده به زبان C++‎

CopyCreate a Zip archive - destructor



using namespace System;
using namespace Ionic::Zip;

int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");

ZipFile ^ zip;
try
{
zip = gcnew ZipFile();
zip->AddEntry("Readme.txt", "This is the content for the Readme.txt entry.");
zip-&gtAddFile("CreateZipFile.cpp");
zip->Save("test.zip");
}
finally
{
zip->~ZipFile();
}

Console::WriteLine(L"Press <ENTER> to quit.");
Console::ReadLine();
return 0;
}


Create a Zip archive - delete


using namespace System;
using namespace Ionic::Zip;

int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");

ZipFile ^ zip;
try
{
zip = gcnew ZipFile();
zip->AddEntry("Readme.txt", "This is the content for the Readme.txt entry.");
zip-&gtAddFile("CreateZipFile.cpp");
zip->Save("test.zip");
}
finally
{
delete zip;
}

Console::WriteLine(L"Press <ENTER> to quit.");
Console::ReadLine();
return 0;
}


Create a zip file using AES encryption


#include "stdafx.h"

using namespace System;
using namespace Ionic::Zip;

int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");

ZipFile ^ zip;
try
{
zip = gcnew ZipFile();
zip->Password = verySecret;
zip->Encryption = EncryptionAlgorithm::WinZipAes128;
zip->AddEntry("Readme.txt", "This is the content for the Readme.txt entry.");
zip->AddFile("Data.csv");
zip->Save("test.zip");
}
finally
{
zip->~ZipFile();
}

Console::WriteLine(L"Press <ENTER> to quit.");
Console::ReadLine();
return 0;
}


Use a SaveProgress event from C++‎


#include "stdafx.h"

using namespace System;
using namespace System::IO;
using namespace Ionic::Zip;


public ref class DnzHelloCppCli
{

private:
bool justHadByteUpdate;

public:
DnzHelloCppCli()
{
}

public:
void Run()
{
Console::WriteLine(L"Hello World");
Console::WriteLine("Using DotNetZip version {0}", ZipFile::LibraryVersion);
array<String^>^ filesToAdd = System::IO::Directory::GetFiles(".", "*.cpp");

ZipFile ^ zip;
try
{
zip = gcnew ZipFile();
zip->Password = "Harbinger";
zip->Encryption = EncryptionAlgorithm::WinZipAes128;
zip->SaveProgress += gcnew EventHandler<SaveProgressEventArgs^>(this, &DnzHelloCppCli::SaveProgress);
zip->AddEntry("Readme.txt", "This is the content for the Readme.txt entry.");
zip->AddFiles(filesToAdd, "files");
zip->Save("MyArchive.zip");
}
finally
{
zip->~ZipFile();
}

Console::WriteLine(L"Press <ENTER> to quit.");
Console::ReadLine();
return;
}

public:
void SaveProgress(Object^ sender, SaveProgressEventArgs^ e)
{
switch (e->EventType)
{
case ZipProgressEventType::Saving_Started:
{
Console::WriteLine("Saving: {0}", e->ArchiveName);
break;
}
case ZipProgressEventType::Saving_BeforeWriteEntry:
{
if (this->justHadByteUpdate)
{
Console::WriteLine();
}
Console::WriteLine(" Writing: {0} ({1}/{2})",
e->CurrentEntry->FileName,
(e->EntriesSaved + 1),
e->EntriesTotal);
this->justHadByteUpdate = false;
break;
}
case ZipProgressEventType::Saving_AfterWriteEntry:
{
if (e->CurrentEntry->InputStreamWasJitProvided)
{
e->CurrentEntry->InputStream->Close();
e->CurrentEntry->InputStream = nullptr;
}
break;
}
case ZipProgressEventType::Saving_Completed:
{
this->justHadByteUpdate = false;
Console::WriteLine();
Console::WriteLine("Done: {0}", e->ArchiveName);
break;
}
case ZipProgressEventType::Saving_EntryBytesRead:
{
if (this->justHadByteUpdate)
{
Console::SetCursorPosition(0, Console::CursorTop);
}
Console::Write(" {0}/{1} ({2:N0}%)",
e->BytesTransferred,
e->TotalBytesToTransfer,
(((double) e->BytesTransferred) / (0.01 * e->TotalBytesToTransfer)));
this->justHadByteUpdate = true;
break;
}
}
}

};


int main(array<System::String ^> ^args)
{
try
{
DnzHelloCppCli^ me = gcnew DnzHelloCppCli();
me->Run();
}
catch (Exception^ ex1)
{
Console::Error->WriteLine(String::Concat("exception: ", ex1));
}
return 0;
}


موفق باشید