コード例 #1
0
ファイル: path.hpp プロジェクト: kpublic/zpublic
 static CString GetRootPath(LPCTSTR szFullPath)
 {
     CString strRoot(szFullPath);
     CString strTempPath(szFullPath);
     int nPos = strTempPath.Find(_T('\\'));
     if (nPos != -1)
         strRoot = strTempPath.Left(nPos);
     return strRoot;
 }
コード例 #2
0
ファイル: FileHelper.cpp プロジェクト: LeeWangyeol/Scut
std::string CFileHelper::getPath(const char* szPath, bool bOnly2X)
{
    if (szPath == NULL)
    {
        ScutLog("getPath Input parameter == Null");
        return std::string();
    }
    if (szPath[0] == '/') {
        return std::string(szPath);
    }

#ifdef SCUT_ANDROID
    if (strstr(szPath, "resource/")) {
        return std::string(szPath);
    }
#endif
    std::string strDirPath = "";
    strDirPath += getResourceDir(szPath);

    // prevent getPath(getPath(imageName));  "icon/head.png" will become "resource/resource/head.png"
    std::string strTempPath(szPath);

    if (strDirPath.length() > 0 && strTempPath.find(strDirPath) == 0)
    {
        strDirPath = "";
    }

    if (strDirPath.size())
    {
        strDirPath += FILE_SEP;

        float fScale = cocos2d::Director::getInstance()->getContentScaleFactor();
        if (fScale > 1 || !(s_width == 480 && s_height == 320 || s_height == 320&& s_width == 480 || s_width
                            < 480 && s_height <480))
        {
            bool bTmx = false;
            const char* pPos = strstr(szPath, ".jpg");
            if (pPos == NULL)	//yubo image
            {
                pPos = strstr(szPath, ".ndj");
            }
            if (pPos == NULL)
            {
                pPos = strstr(szPath, ".png");
            }
            /*
            if (pPos == NULL)
            {
            	pPos = strstr(szPath, ".pnx");
            }
            */
            if (pPos == NULL)	//yubo image
            {
                pPos = strstr(szPath, ".ndp");
            }
            if (pPos == NULL)
            {
                pPos = strstr(szPath, ".tmx");
                bTmx = true;
            }
            if (pPos == NULL)
            {
                pPos = strstr(szPath, ".pvr");
                bTmx = true;
            }
            if (pPos == NULL)
            {
                pPos = strstr(szPath, ".ccz");
                bTmx = true;
            }
            if (pPos == NULL)
            {
                pPos = strstr(szPath, ".plist");
                bTmx = true;
            }
            if(pPos == NULL)
            {
                pPos = strstr(szPath, ".dat");
            }
            if (pPos != NULL)
            {
                char szTmp[256] = {0};
                char szFileName[256] = {0};
                memcpy(szFileName, szPath, pPos - szPath);
                if (bTmx && ((s_width == 1024 && s_height == 768) || (s_height == 1024&& s_width == 768)))
                {
                    if (bOnly2X)
                    {
                        sprintf(szTmp, "%s@2x%s", szFileName, pPos);
                    }
                    else
                        sprintf(szTmp, "%s@2x-ipad%s", szFileName, pPos);
                }
#if (defined SCUT_MAC || defined SCUT_WIN32)
                else if (bTmx && ((s_width == 960 && s_height == 640) || (s_height == 960 && s_width == 640)))
                {
                    if (bOnly2X)
                    {
                        sprintf(szTmp, "%s@2x%s", szFileName, pPos);
                    }
                    else
                        sprintf(szTmp, "%s@2x-ipad%s", szFileName, pPos);
                }
#endif
                else
                {
                    sprintf(szTmp, "%s@2x%s", szFileName, pPos);
                }

                strDirPath += szTmp;
            }
            else
            {
                strDirPath += szPath;
            }
        }
        else
        {
            strDirPath += szPath;
        }

    }
    else
    {
        strDirPath = szPath;
    }
#if defined(SCUT_IPHONE) || defined(SCUT_MAC)
    if (s_strIPhoneBundleID.size() == 0)
    {
        s_strIPhoneBundleID = ScutDataLogic::getBundleID();
    }

    std::string strRelativePath = s_strIPhoneBundleID;
    strRelativePath += FILE_SEP;
    strRelativePath += strDirPath;
    std::string strFilePath = ScutDataLogic::getDocumentFilePathByFileName(strRelativePath.c_str());
    struct stat st;
    if (true && stat(strFilePath.c_str(), &st) != 0)//cocos2d::CCImage::getIsScaleEnabled()
    {
        if (strFilePath.rfind("@2x") == std::string::npos)
        {
            strTempPath = strFilePath;
            int t = strTempPath.rfind(".");
            if (t != std::string::npos)
            {
                strTempPath.insert(t, "@2x");
                if (stat(strTempPath.c_str(), &st) == 0)
                {
                    return strFilePath;
                }
            }
        }

//			if (strDirPath.rfind("@2x") == std::string::npos)
//			{
//				int t = strDirPath.rfind(".");
//				if (t != std::string::npos)
//				{
//					strDirPath.insert(t, "@2x");
//				}
//			}
    }

    if (stat(strFilePath.c_str(), &st) == 0)
    {
        return strFilePath;
    }
    else
    {
        if (strFilePath.rfind(".png") != std::string::npos)
        {
            strTempPath = strFilePath;
            string_replace(strTempPath, ".png", ".pnx");
            if (stat(strTempPath.c_str(), &st) == 0)
            {
                return strTempPath;
            }
        }

        std::string retPath = std::string(appFullPathFromRelativePath(strDirPath.c_str()));
        if (retPath == strDirPath)
        {
            strTempPath = strDirPath;
            string_replace(strTempPath, ".png", ".pnx");
            retPath = std::string(appFullPathFromRelativePath(strTempPath.c_str()));
            if (retPath == strTempPath)
            {
                return strDirPath;
            }
            else
                return retPath;
        }

        return retPath;
    }
#endif

#ifdef SCUT_ANDROID
    if (s_strAndroidSDPath.size())
    {
        std::string strFilePath = s_strAndroidSDPath + strDirPath;
        struct stat st;

        if (true && stat(strFilePath.c_str(), &st) != 0)
        {
            if (strFilePath.rfind("@2x") == std::string::npos)
            {
                strTempPath = strFilePath;
                int t = strTempPath.rfind(".");
                if (t != std::string::npos)
                {
                    strTempPath.insert(t, "@2x");
                    if (stat(strTempPath.c_str(), &st) == 0)
                    {
                        return strFilePath;
                    }
                }
            }
        }

        if (stat(strFilePath.c_str(), &st) == 0)
        {
            return strFilePath;
        }
        else
        {
            if (strFilePath.rfind(".png") != std::string::npos)
            {
                strTempPath = strFilePath;
                string_replace(strTempPath, ".png", ".pnx");
                if (stat(strTempPath.c_str(), &st) == 0)
                {
                    return strTempPath;
                }
            }
        }
    }

    return std::string(strDirPath);
#endif

#ifdef SCUT_WIN32
    std::string ret= ScutExt::getResRootDir();
    ret += strDirPath;

    struct stat st;
    if (ret.rfind(".png") != std::string::npos && stat(ret.c_str(), &st) != 0)
    {
        strTempPath = ret;
        string_replace(strTempPath, ".png", ".pnx");
        if (stat(strTempPath.c_str(), &st) == 0)
        {
            return strTempPath;
        }
    }
    return ret;
#endif
}