Skip to content

Instantly share code, notes, and snippets.

@hasherezade
Created February 23, 2022 22:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hasherezade/2c7837874f7adf0f73192f4d861d83c6 to your computer and use it in GitHub Desktop.
Save hasherezade/2c7837874f7adf0f73192f4d861d83c6 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <Windows.h>
#pragma comment(lib,"LZ32.lib")
bool decompress(LPSTR infile, LPSTR outfile)
{
INT hin, hout = 0;
OFSTRUCT ofin = { 0 };
OFSTRUCT ofout = { 0 };
LONG error = 0;
if ((hin = LZOpenFileA(infile, &ofin, OF_READ)) < 0)
{
std::cerr << "can't open input file: " << infile << "\n";
return false;
}
if ((hout = LZOpenFileA(outfile, &ofout, OF_CREATE | OF_WRITE)) < 0)
{
LZClose(hin);
std::cerr << "can't open output file: "<< outfile << "\n";
return false;
}
error = LZCopy(hin, hout);
LZClose(hin);
LZClose(hout);
if (error < 0)
{
std::cerr << "LZCopy failed, error is: " << error << "\n";
return false;
}
return true;
}
int main(int argc, char *argv[])
{
if (argc < 3) {
return 0;
}
if (decompress(argv[1], argv[2])) {
std::cout << "Success!\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment