[physfs] Why not search program abs path when add archives?

fy fy0748 at gmail.com
Tue Nov 27 10:56:20 EST 2012


在 Tue, 27 Nov 2012 23:47:36 +0800,Thorbjørn Lindeijer  
<bjorn at lindeijer.nl> 写道:

> On Tue, Nov 27, 2012 at 3:14 PM, fy <fy0748 at gmail.com> wrote:
>> My code:
>>
>>       PHYSFS_init(argv[0]);
>>       PHYSFS_addToSearchPath("Content/Audio.zip", 1);
>>       if (PHYSFS_exists("bgm1.mp3")) {
>>           cout<<"test"<<endl;
>>       }
>>
>> If I start my program when current work directory is the program's path,
>> it's OK, and print "test".
>>
>> But if not, it didn't work.
>>
>>
>> So I changed my code like this:
>>
>>       char *path = getPath();
>>
>>       PHYSFS_init(path);
>>       PHYSFS_addToSearchPath("Content/Audio.zip", 1);
>>       if (PHYSFS_exists("bgm1.mp3")) {
>>           cout<<"test"<<endl;
>>       }
>>
>> It still didn't work, but i hope get a "true answer".
>>
>> thx for the lib.
>
> Who says the program's executable path is relevant for resolving
> relative file names? This depends on the functionality you're looking
> to implement. It is common for file operations to work relative to the
> "current working directory", and PhysFS follows that convention
> (possibly inheriting it from the standard system file access
> functions).
>
> C++ does not provide a standard way to obtain the path of the
> executable, but fortunately PhysFS provides a cross-platform
> abstraction for this. So your solution would look something like:
>
>     PHYSFS_init(argv[0]);
>
>     std::string audioFile = std::string(PHYSFS_getBaseDir()) +
> "/Content/Audio.zip";
>
>     PHYSFS_addToSearchPath(audioFile.c_str(), 1);
>     if (PHYSFS_exists("bgm1.mp3")) {
>         cout<<"test"<<endl;
>     }
>
> See  
> http://icculus.org/physfs/docs/html/physfs_8h.html#a0034c327dfb381a1c95deb80878bcede
>
> Best regards,
> Bjørn
> _______________________________________________
> physfs mailing list
> physfs at icculus.org
> http://icculus.org/mailman/listinfo/physfs

Thanks, I got it.

-- 
使用Opera的电子邮件客户端:http://www.opera.com/mail/


More information about the physfs mailing list