many C-string -> std::string replacements and some additional code taken from OpenLieroX
git-svn-id: https://clonekeenplus.svn.sourceforge.net/svnroot/clonekeenplus/cgenius/trunk@87 4df4b0f3-56ce-47cb-b001-ed939b7d65a6
This commit is contained in:
@@ -6,12 +6,15 @@
|
||||
*/
|
||||
|
||||
#include "CExeFile.h"
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "../StringUtils.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
CExeFile::CExeFile(int episode, char *datadirectory) {
|
||||
CExeFile::CExeFile(int episode, const std::string& datadirectory) {
|
||||
m_episode = episode;
|
||||
m_datadirectory = datadirectory;
|
||||
m_data = NULL;
|
||||
@@ -23,12 +26,11 @@ CExeFile::~CExeFile() {
|
||||
|
||||
bool CExeFile::readData()
|
||||
{
|
||||
char filename[256];
|
||||
unsigned char *m_data_temp;
|
||||
|
||||
sprintf(filename, "data/%skeen%d.exe", m_datadirectory, m_episode);
|
||||
std::string filename = "data/" + m_datadirectory + "keen" + itoa(m_episode) + ".exe";
|
||||
|
||||
ifstream File(filename,ios::binary);
|
||||
std::ifstream File(filename.c_str(),ios::binary);
|
||||
|
||||
if(!File) return false;
|
||||
|
||||
|
||||
@@ -12,11 +12,11 @@
|
||||
#define CEXEFILE_H_
|
||||
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
#include <string>
|
||||
|
||||
class CExeFile {
|
||||
public:
|
||||
CExeFile(int episode, char *datadirectory);
|
||||
CExeFile(int episode, const std::string& datadirectory);
|
||||
virtual ~CExeFile();
|
||||
|
||||
bool readData();
|
||||
@@ -27,10 +27,10 @@ private:
|
||||
int m_datasize;
|
||||
int m_episode;
|
||||
unsigned char *m_data;
|
||||
char *m_datadirectory;
|
||||
std::string m_datadirectory;
|
||||
|
||||
int get_bit(int *p_bit_count, unsigned char *fin, int *posin);
|
||||
int unlzexe(unsigned char *fin, vector<unsigned char> *outbuffer);
|
||||
int unlzexe(unsigned char *fin, std::vector<unsigned char> *outbuffer);
|
||||
};
|
||||
|
||||
#endif /* CEXEFILE_H_ */
|
||||
|
||||
@@ -83,7 +83,7 @@ bool CParser::saveParseFile(void) // open, write on the file and close
|
||||
|
||||
if((fp=fopen(CONFIGFILENAME,"wt")))
|
||||
{
|
||||
list<char*>::iterator i;
|
||||
std::list<char*>::iterator i;
|
||||
|
||||
for(i=m_filebuffer.begin() ; i != m_filebuffer.end() ; ++i )
|
||||
fprintf(fp,"%s",*i);
|
||||
@@ -104,7 +104,7 @@ bool CParser::saveParseFile(void) // open, write on the file and close
|
||||
int CParser::getIntValue(const char *keyword, const char *category)
|
||||
{
|
||||
// The getter will search for category and than for keyword. After that, read the value and return it!
|
||||
list<char*>::iterator i;
|
||||
std::list<char*>::iterator i;
|
||||
|
||||
char *line;
|
||||
|
||||
@@ -152,7 +152,7 @@ void CParser::saveIntValue(const char *keyword, const char *category,int value)
|
||||
// 2.- category exists, but keyword not
|
||||
// 3.- category and keyword exist, only the value must be changed
|
||||
|
||||
list<char*>::iterator i;
|
||||
std::list<char*>::iterator i;
|
||||
|
||||
|
||||
char *line;
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
using namespace std;
|
||||
|
||||
|
||||
class CParser {
|
||||
@@ -43,7 +42,7 @@ public:
|
||||
private:
|
||||
bool m_isOpen;
|
||||
|
||||
list<char*> m_filebuffer;
|
||||
std::list<char*> m_filebuffer;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@
|
||||
#include <string.h>
|
||||
#include <fstream>
|
||||
|
||||
CPatcher::CPatcher(int episode, int version,unsigned char *data, char *datadir) {
|
||||
CPatcher::CPatcher(int episode, int version,unsigned char *data, const std::string& datadir) {
|
||||
m_episode = episode;
|
||||
m_version = version;
|
||||
m_data = data;
|
||||
strcpy(m_datadirectory, datadir);
|
||||
m_datadirectory = datadir;
|
||||
}
|
||||
|
||||
CPatcher::~CPatcher() {
|
||||
@@ -35,7 +35,7 @@ void CPatcher::patchMemory()
|
||||
|
||||
// change to the proper directory
|
||||
chdir("data");
|
||||
chdir(m_datadirectory);
|
||||
chdir(m_datadirectory.c_str());
|
||||
|
||||
// TODO: Extend this part further with more commands
|
||||
while(!m_TextList.empty())
|
||||
@@ -108,7 +108,7 @@ bool CPatcher::loadPatchfile()
|
||||
{
|
||||
bool ret = false;
|
||||
chdir("data");
|
||||
chdir(m_datadirectory);
|
||||
chdir(m_datadirectory.c_str());
|
||||
// Detect the patchfile
|
||||
DIR *dir = opendir(".");
|
||||
struct dirent *dp;
|
||||
@@ -122,7 +122,7 @@ bool CPatcher::loadPatchfile()
|
||||
// The file was found! now read it into the memory!
|
||||
|
||||
char* buf;
|
||||
ifstream Patchfile(dp->d_name);
|
||||
std::ifstream Patchfile(dp->d_name);
|
||||
|
||||
while(!Patchfile.eof())
|
||||
{
|
||||
@@ -157,12 +157,12 @@ bool CPatcher::loadPatchfile()
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CPatcher::patchMemfromFile(const char *patch_file_name, int offset)
|
||||
void CPatcher::patchMemfromFile(const std::string& patch_file_name, int offset)
|
||||
{
|
||||
unsigned char *buf_to_patch;
|
||||
unsigned char byte;
|
||||
|
||||
ifstream Patchfile(patch_file_name, ios::binary);
|
||||
std::ifstream Patchfile(patch_file_name.c_str(), std::ios::binary);
|
||||
|
||||
if(!Patchfile) return;
|
||||
|
||||
|
||||
@@ -9,15 +9,15 @@
|
||||
#define CPATCHER_H_
|
||||
|
||||
#include <list>
|
||||
using namespace std;
|
||||
#include <string>
|
||||
|
||||
class CPatcher {
|
||||
public:
|
||||
CPatcher(int episode, int version,unsigned char *data, char *datadir);
|
||||
CPatcher(int episode, int version,unsigned char *data, const std::string& datadir);
|
||||
virtual ~CPatcher();
|
||||
|
||||
void patchMemory();
|
||||
void patchMemfromFile(const char *patch_file_name, int offset);
|
||||
void patchMemfromFile(const std::string& patch_file_name, int offset);
|
||||
|
||||
private:
|
||||
|
||||
@@ -26,9 +26,9 @@ private:
|
||||
int m_episode;
|
||||
int m_version;
|
||||
unsigned char *m_data;
|
||||
char m_datadirectory[256];
|
||||
|
||||
list<char*> m_TextList;
|
||||
std::string m_datadirectory;
|
||||
|
||||
std::list<char*> m_TextList;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -12,24 +12,19 @@
|
||||
#include "../include/fileio.h"
|
||||
#include "../fileio/CExeFile.h"
|
||||
#include "../CLogFile.h"
|
||||
#include "../StringUtils.h"
|
||||
|
||||
int readStoryText(char **ptext, int episode, char *path)
|
||||
int readStoryText(char **ptext, int episode, const std::string& path)
|
||||
{
|
||||
std::string buf2 = formatPathString(path);
|
||||
std::string buf = buf2 + "storytxt.ck" + itoa(episode);
|
||||
|
||||
FILE *fp;
|
||||
char buf[256];
|
||||
char buf2[256];
|
||||
|
||||
memset(buf,0,256*sizeof(char));
|
||||
|
||||
formatPathString(buf2,path);
|
||||
|
||||
sprintf(buf,"%sstorytxt.ck%d",buf2,episode);
|
||||
|
||||
if((fp=fopen(buf,"rt"))==NULL)
|
||||
if((fp=fopen(buf.c_str(),"rt"))==NULL)
|
||||
{
|
||||
sprintf(buf,"%skeen%d.exe",buf2,episode);
|
||||
buf = buf2 + "keen" + itoa(episode) + ".exe";
|
||||
|
||||
if((fp=fopen(buf,"rb"))!=NULL)
|
||||
if((fp=fopen(buf.c_str(),"rb"))!=NULL)
|
||||
{
|
||||
unsigned char *filebuf;
|
||||
int startflag=0, endflag=0; // where story begins and ends!
|
||||
|
||||
Reference in New Issue
Block a user