COCOS2DX 3.x fullpathforfilename and isfileexist behave differently under IOS/MAC and Win32

Source: Internet
Author: User

One, Fullpathforfilename

Project first developed the IOS/MAC version, these two days want to Win32 project also well, but encountered some resources can not correctly find the problem.

Further observation found that for those resource paths that could not be found, Fullpathforfilename returned the incoming short path directly as it was, rather than returning the full path.

Look at the implementation code for Fullpathforfilename, which has this section:

Fixme:should it return nullptr? Or an empty string?
The file wasn ' t found, return the file name passed in.
return filename;

That is, the current processing is to return the parameter as it is if the path is not found.

So the initial determination is because the path is not found, then why not find it?

Break the point in the implementation of the Fullpathforfilename, look at the value of the _searchpatharray, and find that the path is the right one:

But one of the FullPath = This->getpathforfilename (NewFileName, Resolutionit, Searchit) returns the FullPath is empty.

It then followed the Getpathforfilename breakpoint and found that the path that was constructed before path = getfullpathfordirectoryandfilename (path, file) was consistent with the expected The path returned by this sentence is an empty string.

Then followed to the Getfullpathfordirectoryandfilename, found that the following code:

If the file doesn ' t exist, return an empty string
if (!isfileexistinternal (ret)) {
ret = "";
}

So understand, the original is Ios/mac on the isfileexistinternal and Win32 on the isfileexistinternal behavior is inconsistent, on the Ios/mac, Isfileexistinternal returns true regardless of the file path or folder path, as long as the path exists, and on the Win32 platform, ISFILEEXISTINTERNAL returns true only if the file path is passed in and the file exists. If the folder path is passed in, it will always return false. I used fullpathforfilename in my project to get the full path of the folder, so I can work under Ios/mac, but it doesn't work on Win32.

An easy way to do this is to change the code in Getfullpathfordirectoryandfilename directly to:

If the file doesn ' t exist, return an empty string
if (!isfileexistinternal (ret)
&&!isdirectoryexistinternal (ret)//added [Yang Chao]
) {
ret = "";
}

So the Fullpathforfilename Act on the Win32 is the same as the Ios/mac.

Two, isfileexist

The Isfileexistinternal function is used in isfileexist, so the behavior of isfileexist is not consistent with Ios/mac on Win32. In Ios/mac, to determine whether a file or folder exists can be used isfileexist function, and on the Win32 platform Isfileexist can only judge the existence of the file, if you want to determine whether the folder exists, you need to use the Isdirectoryexist function.

COCOS2DX 3.x fullpathforfilename and isfileexist behave differently under IOS/MAC and Win32

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.