This more than likely boils down to a C++ question. I am using the MSVC 2008,
trying to check to see if a file exsist before trying to load it.
come across a bunch of different ways, doing something wrong. what kind of string prepration needs to be done.
bool asgFILE_fileExists(std::string filename)
{
bool bReturn = false;
ofstream myfile (filename.c_str());
if (myfile.is_open())
{
bReturn = true;
myfile.close();
}
else
{
bReturn = false;
}
return bReturn;
}
basicly trying to check to see if a "png" file exsists before I use the dbLoadImage() command.
to get the directories I am looking for I use this
std::string asgFILE_GetExeFileName()
{
char buffer[MAX_PATH];
GetModuleFileName( NULL, buffer, MAX_PATH );
return std::string(buffer);
}
std::string asgFILE_GetExePath()
{
std::string f = asgFILE_GetExeFileName();
return f.substr(0, f.find_last_of( "\\/" ));
}
Do these function look solid? or is there something else I should worry about?
When I run the program, the file name and directories look fine, but I can never seem to beable to detect if the png file is there or not.
popped up a screen shot, I have one which is a false the (first) red, which is not valid file. and a the 2nd red line is the true file (which is still indicating that it is false).
int BS_IMAGES_LoadImage(std::string sFileName, int nOptionalID)
{
int nImageID = 0;
int iTest = 0;
std::string sFullFile = oGlobal.FILE_PATH_CUR + sFileName;
if (nOptionalID < 1)
{
nOptionalID = BS_IMAGES_GetNextImage();
}
nImageID = nOptionalID;
dbLoadImage ( sFullFile,0, nImageID );
// Check if File Exsits
if (asgFILE_fileExists(sFullFile)==true)
{
BS_NewMessage("> [LOAD-IMAGE] "+sFileName+", ID#: "+IntToString(nImageID)+", competed.",2);
}
else
{
BS_NewMessage("!!! Image Load Error, Image: "+sFileName+", fp: "+sFullFile+", failed to Load!",1);
}
return nImageID;
}
Also I don't think the path is working write, I found the SetCurrentDirectory() command, intering the string into that does not change the directory.
If anybody gots a good peice of code or a link to point me to be happy to share.
There are many answers but just one question" ~ Jerilith the Mad