当前位置: 首页 > news >正文

甘肃省城乡城乡建设厅网站自建房设计图

甘肃省城乡城乡建设厅网站,自建房设计图,无锡网站营销公司简介,tiktok国际版网页入口在使用cocos2dx c开发项目时,通常使用cocos自带的UserDefault来存储一些项目所用到的一些配置信息:如游戏的音量,游戏的闯关数等... 但是windows平台下,测试发现如果用户的帐户名使用是中文,在启动程序时会报错&#…

在使用cocos2dx c++开发项目时,通常使用cocos自带的UserDefault来存储一些项目所用到的一些配置信息:如游戏的音量,游戏的闯关数等...

但是windows平台下,测试发现如果用户的帐户名使用是中文,在启动程序时会报错,导致程序无法运行。经过排查,把问题定位到CCFileUtils-win32.cpp的FileUtilsWin32::getWritablePath函数中:string FileUtilsWin32::getWritablePath() const
{
    // Get full path of executable, e.g. c:\Program Files (x86)\My Game Folder\MyGame.exe
    char full_path[CC_MAX_PATH + 1];
    ::GetModuleFileNameA(nullptr, full_path, CC_MAX_PATH + 1);
 
    // Debug app uses executable directory; Non-debug app uses local app data directory
//#ifndef _DEBUG
        // Get filename of executable only, e.g. MyGame.exe
        char *base_name = strrchr(full_path, '\\');
 
        if(base_name)
        {
            char app_data_path[CC_MAX_PATH + 1];
 
            // Get local app data directory, e.g. C:\Documents and Settings\username\Local Settings\Application Data
            if (SUCCEEDED(SHGetFolderPathA(nullptr, CSIDL_LOCAL_APPDATA, nullptr, SHGFP_TYPE_CURRENT, app_data_path)))
            {
                string ret((char*)app_data_path);
 
                // Adding executable filename, e.g. C:\Documents and Settings\username\Local Settings\Application Data\MyGame.exe
                ret += base_name;
 
                // Remove ".exe" extension, e.g. C:\Documents and Settings\username\Local Settings\Application Data\MyGame
                ret = ret.substr(0, ret.rfind("."));
 
                ret += "\\";
 
                // Create directory
                if (SUCCEEDED(SHCreateDirectoryExA(nullptr, ret.c_str(), nullptr)))
                {
                    return convertPathFormatToUnixStyle(ret);
                }
            }
        }
//#endif // not defined _DEBUG
 
    // If fetching of local app data directory fails, use the executable one
    string ret((char*)full_path);
 
    // remove xxx.exe
    ret =  ret.substr(0, ret.rfind("\\") + 1);
 
    ret = convertPathFormatToUnixStyle(ret);
 
    return ret;
}

这里可以看到作者在使用
SUCCEEDED(SHGetFolderPathA(nullptr, CSIDL_LOCAL_APPDATA, nullptr, SHGFP_TYPE_CURRENT, app_data_path))
这个函数时,目的是想通过
CSIDL_LOCAL_APPDATA
来把路径定位到帐户下的APPData目录,而CSIDL_LOCAL_APPDATA这个宏的解释是:

#define CSIDL_LOCAL_APPDATA             0x001c        // <user name>\Local Settings\Applicaiton Data (non roaming)

微软在解释SHGetFolderPath时,说明了用法:

SHGetFolderPathW (Unicode) and SHGetFolderPathA (ANSI)
由于ANSI的兼容性不好,很多情况会导致中文乱码,所以这里需要修改SHGetFolderPathW来将字符集转成unicode,这样比较好用。

修改过后:


string FileUtilsWin32::getWritablePath() const
{
    // Get full path of executable, e.g. c:\Program Files (x86)\My Game Folder\MyGame.exe
    char full_path[CC_MAX_PATH + 1];
    ::GetModuleFileNameA(nullptr, full_path, CC_MAX_PATH + 1);
 
    // Debug app uses executable directory; Non-debug app uses local app data directory
//#ifndef _DEBUG
    // Get filename of executable only, e.g. MyGame.exe
    char *base_name = strrchr(full_path, '\\');
 
    if(base_name)
    {
     // Get local app data directory, e.g. C:\Documents and Settings\username\Local Settings\Application Data
    WCHAR utf16Path[CC_MAX_PATH + 1] = { 0 };
    if(SUCCEEDED(SHGetFolderPathW(nullptr, CSIDL_LOCAL_APPDATA, nullptr, SHGFP_TYPE_CURRENT, utf16Path)))
    {
            char utf8_path[1024 + 2] = { 0 };
        WideCharToMultiByte(CP_UTF8, 0, utf16Path, CC_MAX_PATH + 1, utf8_path, 1024 + 2, NULL, NULL);
        string ret((char*)utf8_path);
        // Adding executable filename, e.g. C:\Documents and Settings\username\Local Settings\Application Data\MyGame.exe
        ret += base_name;
 
        // Remove ".exe" extension, e.g. C:\Documents and Settings\username\Local Settings\Application Data\MyGame
        ret = ret.substr(0, ret.rfind("."));
 
        ret += "\\";
 
        // Create directory
        if (SUCCEEDED(SHCreateDirectoryExA(nullptr, ret.c_str(), nullptr)))
        {
            return convertPathFormatToUnixStyle(ret);
        }
    }
     }
//#endif // not defined _DEBUG
 
    // If fetching of local app data directory fails, use the executable one
    string ret((char*)full_path);
 
    // remove xxx.exe
    ret =  ret.substr(0, ret.rfind("\\") + 1);
 
    ret = convertPathFormatToUnixStyle(ret);
 
    return ret;
}

这样就解决了中文目录下使用userDefault造成的程序崩溃问题。
 

http://www.yayakq.cn/news/359154/

相关文章:

  • 快速迁移网站杭州旅游 网站建设
  • 企业建设营销网站有哪些步骤永久免费网站建设方案
  • 网站建设费入如保入账开封到濮阳
  • 燕郊网站制作网站开发定价
  • 河北省正定县城乡建设网站急招二级建造师
  • 网站建设开题报告数据库建立wordpress注册会员才能看
  • 海口快速建站公司推荐购物网站开发的必要性
  • 百度新闻搜索威海优化联系电话
  • 如何做购物券网站wordpress调用评论
  • 网址我的上网主页win10优化工具
  • 怎么做视频解析网站在线教育网站html模板
  • seo网站策划苏州好的做网站的公司有哪些
  • 安陆网站的建设wordpress升级崩了
  • 服务器 空间 虚拟主机 网站需要wordpress新建页面源码
  • 长沙微网站大型门户网站建设特点
  • 可做易企秀的网站做电影网站如何赚钱
  • 网站建设费用设计安康市移动公司电话
  • 眼科医院网站设计怎么做跨站攻击 wordpress
  • 数据需求 网站建设网站建设与维护新的体会
  • 外贸网站电子建设南京外贸网站建设
  • 向国旗敬礼做时代新人网站自然堂网站建设情况
  • 双轨网站开发网站设置为主页怎么设置
  • 介绍几个免费的网站网站seo快速排名优化
  • 做网站银川南阳教育论坛网站建设
  • 男女做羞羞的视频网站网址ip地址查询
  • wordpress 导购站模板游戏app软件定制开发
  • 网站建设的软件有哪些成都网站建设cdajcx
  • 张家口网站建设工作室传奇手游996盒子下载
  • 去年做哪个网站致富用vs做购物网站代码
  • 外贸累网站建站宝盒创业经历