Jump to content
  • Advertisement
Sign in to follow this  
vcGamer

Application path problem

This topic is 3514 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi I'm trying to run my game from different folders but I get errors, it seems that the media files cannot be read, I use this syntax: Logo_Model.CreateSkinMesh ( "Artwork\\models\\logo.x" , Caps2 , Renderer.GetDevice () ); In debug mode there is no problem, but in release mode (I have to make my game in release mode finally!), when the path name is long I get error, for example: C:\dfsdf sdfdsfsdf\mygame\mygame.exe or C:\program files\mygame\mygame.exe I insert my media in Artwork\ folder what is the solution? how can work like microsoft in findmediapath? how can I use getmodulefilename?, how can I use these codes? char module_name[MAX_PATH]; GetModuleFileName(0, module_name, MAX_PATH); std::string path(module_name); path.erase(path.find_last_of('\\'), std::string::npos); thanks

Share this post


Link to post
Share on other sites
Advertisement
I may be wrong, but as long as your path looks like this...

ReleaseFolder\Executable.exe
ReleaseFolder\Artwork\MediaFiles

Then in your code you can just use
"..\\Artwork\\MediaFiles\\FileName" etc (It could be just one . but I think it's two, I always forget.)

Does this work for you?

Share this post


Link to post
Share on other sites
The code snippet with GetModuleFileName gives you the path your exe resides in.

With this you build full paths every time you want to access an external file that's relative to your exe:

std::string FullPath = path + "\\Artwork\\models\\logo.x";

Logo_Model.CreateSkinMesh( FullPath.c_str(), Caps2, Renderer.GetDevice() );


You might want to create a helper function that gets the module path once and puts it in front of the passed in parameter:


std::string AppPath( const std::string& RelativePath )
{
static std::string ModulePath;

if ( ModulePath.empty() )
{
char module_name[MAX_PATH];

GetModuleFileName( 0, module_name, MAX_PATH );

ModulePath = module_name;
ModulePath.erase( ModulePath.find_last_of('\\'), std::string::npos );
}
return ModulePath + RelativePath;
}

Logo_Model.CreateSkinMesh( AppPath( "\\Artwork\\models\\logo.x" ).c_str(), Caps2, Renderer.GetDevice() );

Share this post


Link to post
Share on other sites
Try something like this. It will set the current directory. Then you can use relative paths.


char szFileName[ MAX_PATH ];
std::string szFilePath;
GetModuleFileName( NULL, szFileName, MAX_PATH );

std::string::size_type last = szFilePath.find_last_of( "\\/" );
if ( last == std::string::npos )
szFilePath = ".\\";
else
szFilePath = szFileName.substr( 0, last + 1 );

SetCurrentDirectory( szFilePath.c_str() );

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!