some fixes (removed all chdir)

git-svn-id: https://clonekeenplus.svn.sourceforge.net/svnroot/clonekeenplus/cgenius/trunk@153 4df4b0f3-56ce-47cb-b001-ed939b7d65a6
This commit is contained in:
albertzeyer
2009-07-24 16:42:43 +00:00
parent 37625747ee
commit fd1d4e1b32
6 changed files with 37 additions and 133 deletions

View File

@@ -11,6 +11,8 @@
#include "CLogFile.h" #include "CLogFile.h"
#include <fstream> #include <fstream>
#include "FindFile.h" #include "FindFile.h"
#include "Debug.h"
CLogFile::CLogFile() {} CLogFile::CLogFile() {}
@@ -109,6 +111,7 @@ void CLogFile::textOut(int Color, bool List, const char *Text)
void CLogFile::textOut(const char *Text) void CLogFile::textOut(const char *Text)
{ {
notes << Text << endl;
fprintf(m_Logfile,"%s",Text); fprintf(m_Logfile,"%s",Text);
fflush(m_Logfile); fflush(m_Logfile);
} }

View File

@@ -38,55 +38,6 @@ void addmaptile(unsigned int t)
} }
} }
bool renameFilenamesLowerCase(const std::string& dir_name)
{
#ifdef TARGET_WIN32
return true;
#else
DIR *p_Dir;
char newname[256];
char buf[256];
struct dirent *dp;
memset(newname,0,256);
strcpy(buf,dir_name.c_str());
if(buf[0] == '\0')
strcpy(buf,"./");
chdir("data");
if((p_Dir = opendir(buf))==NULL)
return false;
bool retval = true;
// This function checks if all the files in the directory are lower case.
// If they aren't rename them
while((dp = readdir(p_Dir)) != NULL)
{
if(dp->d_type == DT_REG)
{
strcpy(newname,dp->d_name);
int len = strlen(newname);
for(int pos=0 ; pos < len ; pos++ )
if(newname[pos] >= 'A' && newname[pos] <= 'Z')
newname[pos] += ('a'-'A');
if(strncmp(newname,dp->d_name,strlen(dp->d_name)) != 0)
if(rename(dp->d_name,newname) != -1)
retval &= true;
}
}
closedir(p_Dir);
chdir("../");
return retval;
#endif
}
short checkConsistencyofGameData(stGameData *p_GameData) short checkConsistencyofGameData(stGameData *p_GameData)
{ {
@@ -129,12 +80,6 @@ short checkConsistencyofGameData(stGameData *p_GameData)
p_GameData->FileList[24] = "sounds.ck" + itoa(p_GameData->Episode); p_GameData->FileList[24] = "sounds.ck" + itoa(p_GameData->Episode);
} }
// Rename all the the files in the directory to lower case
if(!renameFilenamesLowerCase(p_GameData->DataDirectory))
{
g_pLogFile->ftextOut(PURPLE,"WARNING: There was an error while trying to format correctly the game data.");
g_pLogFile->ftextOut(PURPLE,"Please check, if you have write permissions on the game data directory and it is accessible<br>");
}
// Finally check if they really exist! // Finally check if they really exist!
int c=0; int c=0;

View File

@@ -10,22 +10,16 @@
#include <string.h> #include <string.h>
#include <fstream> #include <fstream>
#include "../FindFile.h" #include "../FindFile.h"
#include "../StringUtils.h"
CPatcher::CPatcher(int episode, int version,unsigned char *data, const std::string& datadir) { CPatcher::CPatcher(int episode, int version,unsigned char *data, const std::string& datadir) {
m_episode = episode; m_episode = episode;
m_version = version; m_version = version;
m_data = data; m_data = data;
m_datadirectory = datadir; m_datadirectory = datadir;
if(m_datadirectory != "") m_datadirectory += "/";
} }
CPatcher::~CPatcher() { CPatcher::~CPatcher() {}
while(!m_TextList.empty())
{
delete *(m_TextList.begin());
m_TextList.pop_front();
}
}
void CPatcher::patchMemory() void CPatcher::patchMemory()
{ {
@@ -35,49 +29,40 @@ void CPatcher::patchMemory()
// then read out of the list the patch commands and apply them to the // then read out of the list the patch commands and apply them to the
// Exe-file data m_data // Exe-file data m_data
// change to the proper directory
chdir("data");
chdir(m_datadirectory.c_str());
// TODO: Extend this part further with more commands // TODO: Extend this part further with more commands
while(!m_TextList.empty()) while(!m_TextList.empty())
{ {
char line[256]; std::string line = *m_TextList.begin();
strcpy(line,*(m_TextList.begin())); if(strCaseStartsWith(line,"\%version"))
if(strncmp(line,"\%version",strlen("\%version")) == 0)
{ {
char *verstring; std::string verstring = line.substr(strlen("\%version"));
char detected_version[5];
verstring = line + strlen("\%version"); if((stringcaseequal(verstring,"1.31") && m_version == 131 )
|| (stringcaseequal(verstring,"1.1") && m_version == 110 )
sscanf(verstring,"%s",detected_version); || stringcaseequal(verstring,"ALL"))
if((!strcmp(detected_version,"1.31") && m_version == 131 )
|| (!strcmp(detected_version,"1.1") && m_version == 110 )
|| !strcmp(detected_version,"ALL"))
{ {
while(!m_TextList.empty()) while(!m_TextList.empty())
{ {
// Get the next line // Get the next line
strcpy(line,*(m_TextList.begin())); line = *m_TextList.begin();
// Now we really start to process the commands // Now we really start to process the commands
if( strncmp(line,"\%patchfile",strlen("\%patchfile")) == 0 ) if( strCaseStartsWith(line,"\%patchfile") )
{ {
unsigned long offset; size_t offset = 0;
char *newbuf; std::string patch_file_name;
char patch_file_name[256]; std::string newbuf = line.substr(strlen("\%patchfile"));
newbuf = line + strlen("\%patchfile"); size_t p = newbuf.find(' ');
sscanf(newbuf,"%lx %s",&offset,patch_file_name); // Only hexadecimal numbers supported if(p != std::string::npos) {
patchMemfromFile((const char*)patch_file_name,offset); sscanf(newbuf.substr(0,p).c_str(), "%lx", &offset); // Only hexadecimal numbers supported
patch_file_name = newbuf.substr(p+1);
patchMemfromFile("data/" + m_datadirectory + "/" + patch_file_name,offset);
}
} }
if(!m_TextList.empty()) if(!m_TextList.empty())
{ {
delete *(m_TextList.begin());
m_TextList.pop_front(); m_TextList.pop_front();
} }
} }
@@ -86,50 +71,38 @@ void CPatcher::patchMemory()
if(!m_TextList.empty()) if(!m_TextList.empty())
{ {
delete *(m_TextList.begin());
m_TextList.pop_front(); m_TextList.pop_front();
} }
} }
// change back to "data" dir
char curdir[256];
while(1)
{
char *reldir;
getcwd(curdir,256);
reldir = curdir+strlen(curdir)-strlen("data");
if(strcmp(reldir,"data"))
chdir("..");
else
break;
}
chdir("..");
} }
bool CPatcher::loadPatchfile() bool CPatcher::loadPatchfile()
{ {
bool ret = false; std::string fullfname = GetFullFileName("data/" + m_datadirectory);
chdir("data"); if(fullfname.size() == 0)
chdir(m_datadirectory.c_str()); return false;
// Detect the patchfile
DIR *dir = opendir(".");
struct dirent *dp;
// Detect the patchfile
DIR *dir = opendir(Utf8ToSystemNative(fullfname).c_str());
bool ret = false;
if(dir) if(dir)
{ {
struct dirent *dp;
while( ( dp = readdir(dir) ) ) while( ( dp = readdir(dir) ) )
{ {
if(strstr(dp->d_name,".pat")) if(strstr(dp->d_name,".pat"))
{ {
// The file was found! now read it into the memory! // The file was found! now read it into the memory!
char* buf;
std::ifstream Patchfile; OpenGameFileR(Patchfile, dp->d_name); std::ifstream Patchfile; OpenGameFileR(Patchfile, dp->d_name);
while(!Patchfile.eof()) while(!Patchfile.eof())
{ {
buf = new char[256]; char buf[256];
Patchfile.getline(buf,256); Patchfile.getline(buf,sizeof(buf));
fix_markend(buf);
m_TextList.push_back(buf); m_TextList.push_back(buf);
} }
@@ -141,19 +114,6 @@ bool CPatcher::loadPatchfile()
} }
} }
char curdir[256];
while(1)
{
char *reldir;
getcwd(curdir,256);
reldir = curdir+strlen(curdir)-strlen("data");
if(strcmp(reldir,"data"))
chdir("..");
else
break;
}
chdir("..");
closedir(dir); closedir(dir);
return ret; return ret;

View File

@@ -28,7 +28,7 @@ private:
unsigned char *m_data; unsigned char *m_data;
std::string m_datadirectory; std::string m_datadirectory;
std::list<char*> m_TextList; std::list<std::string> m_TextList;
}; };

View File

@@ -15,7 +15,6 @@ void addmaptile(unsigned int t);
void addenemytile(unsigned int t, stCloneKeenPlus *pCKP); void addenemytile(unsigned int t, stCloneKeenPlus *pCKP);
short checkConsistencyofGameData(stGameData *p_GameData); short checkConsistencyofGameData(stGameData *p_GameData);
std::string formatPathString(const std::string& path); std::string formatPathString(const std::string& path);
bool renameFilenamesLowerCase(const char *dir_name);
void assignChangeTileAttribute(stTile *tile, int episode); void assignChangeTileAttribute(stTile *tile, int episode);
#endif #endif

View File

@@ -57,12 +57,11 @@ bool CEGAGraphics::loadData()
std::string buf; std::string buf;
vector<char> databuf; vector<char> databuf;
chdir("data"); // TODO: You must be able to use another directory
if(m_path == "") if(m_path == "")
buf = "egahead.ck" + itoa(m_episode); buf = "egahead.ck" + itoa(m_episode);
else else
buf = m_path + "/egahead.ck" + itoa(m_episode); buf = m_path + "/egahead.ck" + itoa(m_episode);
std::ifstream HeadFile; OpenGameFileR(HeadFile, buf, ios::binary); std::ifstream HeadFile; OpenGameFileR(HeadFile, "data/" + buf, ios::binary);
if(!HeadFile) if(!HeadFile)
return false; return false;
@@ -113,7 +112,7 @@ bool CEGAGraphics::loadData()
buf = "egalatch.ck" + itoa(m_episode); buf = "egalatch.ck" + itoa(m_episode);
else else
buf = m_path + "/egalatch.ck" + itoa(m_episode); buf = m_path + "/egalatch.ck" + itoa(m_episode);
m_Latch->loadData(buf,(compressed>>1)); // The second bit tells, if latch is compressed. m_Latch->loadData("data/" + buf,(compressed>>1)); // The second bit tells, if latch is compressed.
m_Sprit = new CEGASprit(SpritePlaneSize, m_Sprit = new CEGASprit(SpritePlaneSize,
@@ -126,9 +125,7 @@ bool CEGAGraphics::loadData()
buf = "egasprit.ck" + itoa(m_episode); buf = "egasprit.ck" + itoa(m_episode);
else else
buf = m_path + "/egasprit.ck" + itoa(m_episode); buf = m_path + "/egasprit.ck" + itoa(m_episode);
m_Sprit->loadData(buf,(compressed>>1)); m_Sprit->loadData("data/" + buf,(compressed>>1));
chdir("../");
return true; return true;
} }