Subversion Repositories spk

Rev

Rev 317 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 317 Rev 323
Line 1875... Line 1875...
1875
	else
1875
	else
1876
		_iGame = i; 
1876
		_iGame = i; 
1877
}
1877
}
1878
 
1878
 
1879
 
1879
 
1880
unsigned char *C_File::BobDecompile(size_t *size)
1880
unsigned char* C_File::BobDecompile(size_t* size)
1881
{
1881
{
1882
 
-
 
1883
	(*size) = 0;
1882
	(*size) = 0;
1884
 
1883
 
1885
	Utils::WString fromFile = this->filePointer();
1884
	Utils::WString fromFile = this->filePointer();
1886
	if (!CFileIO::Exists(fromFile))
1885
	if (!CFileIO::Exists(fromFile))
1887
	{
1886
	{
1888
		if (this->writeToFile(CPackages::tempDirectory() + L"bob.tmp"))
1887
		if (this->writeToFile(CPackages::tempDirectory() + L"bob.tmp"))
1889
			fromFile = CPackages::tempDirectory() + L"bob.tmp";
1888
			fromFile = CPackages::tempDirectory() + L"bob.tmp";
1890
	}
1889
	}
1891
 
1890
 
1892
	fromFile = fromFile.findReplace(L"/", L"\\");
1891
	fromFile = fromFile.findReplace(L"/", L"\\");
1893
	Utils::WString toFile = CPackages::tempDirectory() + L"bod.tmp";
1892
	Utils::WString toFile = CPackages::tempDirectory() + L"bod.tmp";
1894
	toFile = toFile.findReplace(L"/", L"\\");
1893
	toFile = toFile.findReplace(L"/", L"\\");
1895
 
1894
 
1896
	if (CFileIO::Exists(fromFile))
1895
	if (CFileIO::Exists(fromFile))
1897
	{
1896
	{
1898
#ifdef _XBODLIBRARY__
1897
#ifdef _XBODLIBRARY__
1899
		if (X2BC_BOB2BOD(fromFile.toString().c_str(), toFile.toString().c_str())) {
1898
		if (X2BC_BOB2BOD(fromFile.toString().c_str(), toFile.toString().c_str())) {
1900
			CFileIO F(toFile);
1899
			CFileIO F(toFile);
1901
			if (F.exists() && F.startRead()) {
1900
			if (F.exists() && F.startRead()) {
1902
				unsigned char* data = F.readAll(size);
1901
				unsigned char* data = F.readAll(size);
1903
				F.close();
1902
				F.close();
1904
				F.remove();
1903
				F.remove();
1905
 
1904
 
1906
				return data;
1905
				return data;
1907
			}
1906
			}
1908
		}
1907
		}
1909
#else
1908
#else
1910
		// Use x2bc library to convert the file
1909
		// Use x2bc library to convert the file
1911
		Settings settings;
1910
		Settings settings;
1912
		bob_dom_document doc(&settings);
1911
		bob_dom_document doc(&settings);
1913
 
1912
 
1914
		ibinaryrealfile is;
1913
		ibinaryrealfile is;
1915
		otextrealfile os;
1914
		otextrealfile os;
1916
 
1915
 
1917
		is.open(fromFile.toString().c_str(), filestream::rdonly);
1916
		is.open(fromFile.toString().c_str(), filestream::rdonly);
1918
		os.open(toFile.toString().c_str(), filestream::create);
1917
		os.open(toFile.toString().c_str(), filestream::create);
1919
 
1918
 
1920
		if (!is.fail() && !os.fail())
1919
		if (!is.fail() && !os.fail())
1921
		{
1920
		{
1922
			if (doc.convert(is, os))
1921
			if (doc.convert(is, os))
1923
			{
1922
			{
1924
				CFileIO F(toFile);
1923
				CFileIO F(toFile);
1925
				if (F.exists() && F.startRead())
1924
				if (F.exists() && F.startRead())
1926
				{
1925
				{
1927
					unsigned char* data = F.readAll(size);
1926
					unsigned char* data = F.readAll(size);
1928
					F.close();
1927
					F.close();
1929
					F.remove();
1928
					F.remove();
1930
 
1929
 
1931
					return data;
1930
					return data;
1932
				}
1931
				}
1933
			}
1932
			}
1934
		}
1933
		}
1935
#endif
1934
#endif
1936
	}
1935
	}
1937
 
1936
 
1938
	if (CFileIO::Exists(CPackages::tempDirectory() + L"bob.tmp"))
1937
	if (CFileIO::Exists(CPackages::tempDirectory() + L"bob.tmp"))
1939
		CFileIO::Remove(CPackages::tempDirectory() + L"bob.tmp");
1938
		CFileIO::Remove(CPackages::tempDirectory() + L"bob.tmp");
-
 
1939
 
-
 
1940
	return NULL;
-
 
1941
}
-
 
1942
 
-
 
1943
unsigned char* C_File::BobCompile(size_t* size, bool isCut)
-
 
1944
{
-
 
1945
	(*size) = 0;
1940
 
1946
 
1941
	return NULL;
-
 
1942
	/*
-
 
1943
	(*size) = 0;
-
 
1944
 
-
 
1945
	Utils::WString fromFile = this->filePointer();
-
 
1946
	if ( !CFileIO::Exists(fromFile) ) {
1947
	if (!m_sData || !m_lDataSize)
1947
		if ( this->writeToFile(CPackages::tempDirectory() + L"bob.tmp")) {
-
 
1948
			fromFile = CPackages::tempDirectory() + L"bob.tmp";
-
 
1949
		}
-
 
1950
	}
1948
	{
1951
 
-
 
1952
	fromFile = fromFile.findReplace(L"/", L"\\");
-
 
1953
	Utils::WString toFile = CPackages::tempDirectory() + L"bod.tmp";
-
 
1954
	toFile = toFile.findReplace(L"/", L"\\");
-
 
1955
 
-
 
1956
	if ( CFileIO::Exists(fromFile) ) {
1949
		if (!this->ReadFromFile())
1957
		if ( X2BC_BOB2BOD(fromFile.toString().c_str(), toFile.toString().c_str())) {
-
 
1958
			CFileIO F(toFile);
-
 
1959
			if ( F.exists() && F.startRead() ) {
-
 
1960
				unsigned char *data = F.readAll(size);
-
 
1961
				F.close();
-
 
1962
				F.remove();
-
 
1963
 
-
 
1964
				return data;
1950
			return NULL;
1965
			}
-
 
1966
		}
-
 
1967
	}
1951
	}
1968
 
1952
 
1969
	if ( CFileIO::Exists(CPackages::tempDirectory() + L"bob.tmp") )
1953
	Utils::WString toFile = CPackages::tempDirectory() + L"bob.tmp";
1970
		CFileIO::Remove(CPackages::tempDirectory() + L"bob.tmp");
1954
	toFile = toFile.findReplace(L"/", L"\\");
1971
		*/
1955
	CFileIO ToFile(toFile);
1972
 
-
 
1973
 
1956
 
1974
	/*
-
 
1975
	Settings settings;
1957
	Settings settings;
1976
	bob_dom_document doc(&settings);
1958
	bod_parser p(&settings);
1977
	
-
 
1978
	ibinaryrealfile is;
-
 
1979
	otextrealfile os;
-
 
1980
	os.open(CPackages::tempDirectory() + "tmp.tmp", filestream::create);
-
 
1981
	is.open(this->filePointer().c_str(), filestream::rdonly);
-
 
1982
	
-
 
1983
	if(is.fail() || os.fail()) return NULL;
-
 
1984
	
-
 
1985
	bool bRes=doc.convert(is, os);
-
 
1986
 
-
 
1987
	for(bob_dom_document::ErrorIterator &it=doc.errors.begin(); it!=doc.errors.end(); ++it){
-
 
1988
		//BOBError(*it);
-
 
1989
	}
-
 
1990
 
-
 
1991
	if ( bRed ) {
-
 
1992
		CFileIO F(CPackages::tempDirectory() + "tmp.tmp");
-
 
1993
		if ( F.exists() && F.startRead() ) {
-
 
1994
			unsigned char *data = F.readAll(size);
-
 
1995
			F.close();
-
 
1996
			F.remove();
-
 
1997
 
-
 
1998
			return data;
-
 
1999
		}
-
 
2000
	}
-
 
2001
*/
-
 
2002
	return NULL;
-
 
2003
}
-
 
2004
 
-
 
2005
bool C_File::BobDecompile()
-
 
2006
{
-
 
2007
	bool bRes=false;
1959
	bool bRes;
2008
 
-
 
2009
 
-
 
2010
	Utils::WStringList outData;
-
 
2011
	outData.pushBack(L"// Converted by SPK Libraries\n");
1960
	bod_parser::fileType type = isCut ? bod_parser::cutFile : bod_parser::bobFile;
2012
	/*
-
 
2013
	bob_with_errors *e=0;
-
 
2014
	char *pszTime;
-
 
2015
	char *name="";
-
 
2016
 
1961
 
2017
	time_t tm=time(0);
1962
	obinaryrealfile os;
2018
	pszTime=ctime(&tm);
-
 
2019
	pszTime[strlen(pszTime)-1]=0;
-
 
2020
 
-
 
2021
	clearErrors();
-
 
2022
 
-
 
2023
	os << "// Converted with x2bc from \"" << is.name() << "\" at " << pszTime << endl;
1963
	os.open(ToFile.fullFilename().toFileUTF8().c_str(), filestream::create);
2024
	if(settings->convert()==false)
-
 
2025
		os << "// Raw mode - values are not converted" << endl;
-
 
2026
	os << endl;
-
 
2027
	*/
-
 
2028
	/*
-
 
2029
	switch(m_sData[0]){
1964
	if (!os.bad())
2030
		case bob_dom_bob::hdr_begin:
-
 
2031
			{
-
 
2032
				bob_dom_bob *bob = new bob_dom_bob(NULL);
-
 
2033
				//bRes=bob->load(is);
-
 
2034
				//if(bRes) bRes=bob->toFile(os);
-
 
2035
				delete bob;
-
 
2036
				break;
-
 
2037
			}
-
 
2038
		case bob_dom_cut::hdr_begin:
-
 
2039
			{
1965
	{
2040
				bob_dom_cut *cut = new bob_dom_cut(NULL);
1966
		bRes = p.compile((char *)m_sData, (size_t)m_lDataSize, type, os);
2041
				//bRes=cut->convert(is, os);
-
 
2042
				delete cut;
-
 
2043
				break;
-
 
2044
			}
-
 
2045
		default:
-
 
2046
			return false;
-
 
2047
	}
-
 
2048
 
-
 
2049
	if(e){
-
 
2050
		for(bob_with_errors::ErrorIterator &amp;it=e->errors.begin(); it!=e->;errors.end(); ++it){
1967
		for (bod_parser::iterator&amp; it = p.errors.begin(); it != p.errors.end(); ++it) {
2051
			bob_error(it->;severity, it->code, "%s->%s", name, it->text);
1968
			;  // check errors?
2052
		}
1969
		}
2053
	}
1970
	}
2054
	return bRes;
1971
	os.close();
2055
 
1972
 
2056
	bob_dom_ibufferstream<unsigned char> is((const unsigned char *)m_sData, m_lDataSize);
1973
	CFileIO tmpFile(CPackages::tempDirectory() + L"bob.tmp");
2057
	bob_dom_otextrealfile os;
1974
	if (tmpFile.exists() &&; tmpFile.startRead())
2058
 
1975
	{
2059
	if(is.fail() || os.fail()) return false;
1976
		unsigned char* data = tmpFile.readAll(size);
-
 
1977
		tmpFile.close();
-
 
1978
		tmpFile.remove();
-
 
1979
		if (data)
-
 
1980
			return data;
2060
 
1981
	}
2061
	bool bRes=doc.convert(is, os);*/
-
 
2062
 
1982
 
2063
	return bRes;
1983
	return NULL;
2064
}
1984
}
2065
 
1985
 
2066
bool C_File::BodCompile()
-
 
2067
{
-
 
2068
	return true;
-
 
2069
}
-
 
2070
 
1986
 
2071
bool C_File::renameScript(const Utils::WString &baseName)
1987
bool C_File::renameScript(const Utils::WString &baseName)
2072
{
1988
{
2073
	if ( !m_sData || !m_lDataSize )
1989
	if ( !m_sData || !m_lDataSize )
2074
	{
1990
	{