Subversion Repositories spk

Rev

Rev 277 | Rev 285 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 277 Rev 283
Line 26... Line 26...
26
// LZMA compression
26
// LZMA compression
27
#include "lzma/Lzma86Enc.h"
27
#include "lzma/Lzma86Enc.h"
28
#include "lzma/Lzma86Dec.h"
28
#include "lzma/Lzma86Dec.h"
29
 
29
 
30
// X2BOD
30
// X2BOD
-
 
31
#ifdef _XBODLIBRARY__
-
 
32
#include "../Windows/libx2bc.h"
31
/*
33
#else
32
#include "x2bc/x2bc_common/settings.h"
34
#include "x2bc/x2bc_common/settings.h"
33
#include "x2bc/x2bc_common/bob_dom.h"
35
#include "x2bc/x2bc_common/bob_dom.h"
34
#include "x2bc/x2bc_common/bod_parser.h"
36
#include "x2bc/x2bc_common/bod_parser.h"
35
#include "x2bc/x2bc_common/realfile_stream.h"
37
#include "x2bc/x2bc_common/realfile_stream.h"
36
*/
38
#endif
37
#include "../Windows/libx2bc.h"
-
 
38
 
39
 
39
//////////////////////////////////////////////////////////////////////
40
//////////////////////////////////////////////////////////////////////
40
// STATIC FUNCTIONS
41
// STATIC FUNCTIONS
41
//////////////////////////////////////////////////////////////////////
42
//////////////////////////////////////////////////////////////////////
42
 
43
 
Line 821... Line 822...
821
			break;
822
			break;
822
 
823
 
823
		case SPKCOMPRESS_LZMA:
824
		case SPKCOMPRESS_LZMA:
824
			{
825
			{
825
				unsigned char *compr = (unsigned char *)malloc(comprLen);
826
				unsigned char *compr = (unsigned char *)malloc(comprLen);
-
 
827
				if (!compr) {
-
 
828
					return NULL;
-
 
829
				}
826
				SRes res = Lzma86_Encode((Byte *)compr, (size_t *)&comprLen, (const Byte *)m_sData, (size_t)m_lDataSize, level, LZMA_DICT, SZ_FILTER_NO, (progress) ? progress->GetDonePointer() : NULL);
830
				SRes res = Lzma86_Encode((Byte *)compr, (size_t *)&comprLen, (const Byte *)m_sData, (size_t)m_lDataSize, level, LZMA_DICT, SZ_FILTER_NO, (progress) ? progress->GetDonePointer() : NULL);
827
 
831
 
828
				if ( res == SZ_OK )
832
				if ( res == SZ_OK )
829
				{
833
				{
830
					unsigned char *retData = new unsigned char[comprLen];
834
					unsigned char *retData = new unsigned char[comprLen];
Line 848... Line 852...
848
	// no data to try to compress
852
	// no data to try to compress
849
	if ( (!m_sData) || (!m_lDataSize) )
853
	if ( (!m_sData) || (!m_lDataSize) )
850
		return false;
854
		return false;
851
 
855
 
852
	// if comopression is set to noe, dont bother
856
	// if comopression is set to noe, dont bother
853
	if ( compressionType == SPKCOMPRESS_NONE )
857
	if (compressionType == SPKCOMPRESS_NONE)
854
		return true;
858
		return true;
855
 
859
 
856
	if ( compressionType == SPKCOMPRESS_7ZIP )
860
	if ( compressionType == SPKCOMPRESS_7ZIP )
857
		compressionType = SPKCOMPRESS_LZMA;
861
		compressionType = SPKCOMPRESS_LZMA;
858
 
862
 
859
	// if its zlib, and we are trying to compress pcked files (ie already zlib compression) then switch to lzma instead
863
	// if its zlib, and we are trying to compress pcked files (ie already zlib compression) then switch to lzma instead
860
	if ( compressionType == SPKCOMPRESS_ZLIB && (this->checkFileExt(L"pck") || this->checkFileExt(L"cat") || this->checkFileExt(L"dat") || this->checkFileExt(L"pbb") || this->checkFileExt(L"pbd")) )
864
	if ( compressionType == SPKCOMPRESS_ZLIB && (this->checkFileExt(L"pck") || this->checkFileExt(L"cat") || this->checkFileExt(L"dat") || this->checkFileExt(L"pbb") || this->checkFileExt(L"pbd")) )
861
		compressionType = SPKCOMPRESS_LZMA;
865
		compressionType = SPKCOMPRESS_LZMA;
862
 
866
 
-
 
867
	// dont compress cat/dat files
-
 
868
	if (this->checkFileExt(L"cat") || this->checkFileExt(L"dat"))
-
 
869
		compressionType = SPKCOMPRESS_NONE;
-
 
870
 
863
	// if its already compressed, no need to compress again
871
	// if its already compressed, no need to compress again
864
	if ( compressionType == m_iDataCompression )
872
	if ( compressionType == m_iDataCompression )
865
		return true;
873
		return true;
866
 
874
 
867
	// no need to change the compression
875
	// no need to change the compression
Line 932... Line 940...
932
			m_bUsedMalloc = false;
940
			m_bUsedMalloc = false;
933
			m_lDataSize = comprLen;
941
			m_lDataSize = comprLen;
934
			m_iDataCompression = compressionType;
942
			m_iDataCompression = compressionType;
935
		}
943
		}
936
		// we shall always return true, files can be added in non compressed mode
944
		// we shall always return true, files can be added in non compressed mode
-
 
945
		//TODO: file compression?
937
		return true;
946
		return true;
938
	}
947
	}
939
 
948
 
940
	return false;
949
	return false;
941
}
950
}
Line 1841... Line 1850...
1841
}
1850
}
1842
 
1851
 
1843
 
1852
 
1844
unsigned char *C_File::BobDecompile(size_t *size)
1853
unsigned char *C_File::BobDecompile(size_t *size)
1845
{
1854
{
-
 
1855
 
-
 
1856
	(*size) = 0;
-
 
1857
 
-
 
1858
	Utils::WString fromFile = this->filePointer();
-
 
1859
	if (!CFileIO::Exists(fromFile))
-
 
1860
	{
-
 
1861
		if (this->writeToFile(CPackages::tempDirectory() + L"bob.tmp"))
-
 
1862
			fromFile = CPackages::tempDirectory() + L"bob.tmp";
-
 
1863
	}
-
 
1864
 
-
 
1865
	fromFile = fromFile.findReplace(L"/", L"\\");
-
 
1866
	Utils::WString toFile = CPackages::tempDirectory() + L"bod.tmp";
-
 
1867
	toFile = toFile.findReplace(L"/", L"\\");
-
 
1868
 
-
 
1869
	if (CFileIO::Exists(fromFile))
-
 
1870
	{
-
 
1871
#ifdef _XBODLIBRARY__
-
 
1872
		if (X2BC_BOB2BOD(fromFile.toString().c_str(), toFile.toString().c_str())) {
-
 
1873
			CFileIO F(toFile);
-
 
1874
			if (F.exists() && F.startRead()) {
-
 
1875
				unsigned char* data = F.readAll(size);
-
 
1876
				F.close();
-
 
1877
				F.remove();
-
 
1878
 
-
 
1879
				return data;
-
 
1880
			}
-
 
1881
		}
-
 
1882
#else
-
 
1883
		// Use x2bc library to convert the file
-
 
1884
		Settings settings;
-
 
1885
		bob_dom_document doc(&settings);
-
 
1886
 
-
 
1887
		ibinaryrealfile is;
-
 
1888
		otextrealfile os;
-
 
1889
 
-
 
1890
		is.open(fromFile.toString().c_str(), filestream::rdonly);
-
 
1891
		os.open(toFile.toString().c_str(), filestream::create);
-
 
1892
 
-
 
1893
		if (!is.fail() && !os.fail())
-
 
1894
		{
-
 
1895
			if (doc.convert(is, os))
-
 
1896
			{
-
 
1897
				CFileIO F(toFile);
-
 
1898
				if (F.exists() && F.startRead())
-
 
1899
				{
-
 
1900
					unsigned char* data = F.readAll(size);
-
 
1901
					F.close();
-
 
1902
					F.remove();
-
 
1903
 
-
 
1904
					return data;
-
 
1905
				}
-
 
1906
			}
-
 
1907
		}
-
 
1908
#endif
-
 
1909
	}
-
 
1910
 
-
 
1911
	if (CFileIO::Exists(CPackages::tempDirectory() + L"bob.tmp"))
-
 
1912
		CFileIO::Remove(CPackages::tempDirectory() + L"bob.tmp");
-
 
1913
 
-
 
1914
	return NULL;
-
 
1915
	/*
1846
	(*size) = 0;
1916
	(*size) = 0;
1847
 
1917
 
1848
	Utils::WString fromFile = this->filePointer();
1918
	Utils::WString fromFile = this->filePointer();
1849
	if ( !CFileIO::Exists(fromFile) ) {
1919
	if ( !CFileIO::Exists(fromFile) ) {
1850
		if ( this->writeToFile(CPackages::tempDirectory() + L"bob.tmp")) {
1920
		if ( this->writeToFile(CPackages::tempDirectory() + L"bob.tmp")) {
Line 1869... Line 1939...
1869
		}
1939
		}
1870
	}
1940
	}
1871
 
1941
 
1872
	if ( CFileIO::Exists(CPackages::tempDirectory() + L"bob.tmp") )
1942
	if ( CFileIO::Exists(CPackages::tempDirectory() + L"bob.tmp") )
1873
		CFileIO::Remove(CPackages::tempDirectory() + L"bob.tmp");
1943
		CFileIO::Remove(CPackages::tempDirectory() + L"bob.tmp");
-
 
1944
		*/
-
 
1945
 
-
 
1946
 
1874
	/*
1947
	/*
1875
	Settings settings;
1948
	Settings settings;
1876
	bob_dom_document doc(&settings);
1949
	bob_dom_document doc(&settings);
1877
	
1950
	
1878
	ibinaryrealfile is;
1951
	ibinaryrealfile is;