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

制作网站首先要知道什么wordpress 主题更新

制作网站首先要知道什么,wordpress 主题更新,网站营销型,淄博信息港在使用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/670363/

相关文章:

  • 微网站建设价格公司建设网站算入什么会计科目
  • 去百度建网站保定便宜的网站制作
  • 织梦网站程序5.7首页模板东莞58同城招聘网
  • 免费软件不收费网站青海h5页面制作
  • 自己做的商业网站在那里发布郑州注册公司流程及费用
  • 怎么用ftp修改网站图片wordpress 内网搭建
  • 公司建网站软件系统流小说
  • 淘宝有做网站吗营销型网站建站教程
  • 响应式网站建设必推全网天下网站前期建设
  • 做网站建设销售途径奇人网站
  • 阜宁网站制作服务免费做图软件电脑版
  • 做网站哪家公司比较好网站如何做问卷调查
  • 建立网站需要多少钱?西部数据网站建设
  • 哈尔滨网站设计公司地址如何搜索网站
  • 电子商务网站规划 分析 设计八八网
  • 网站建设及解析流程免费百度下载
  • 关键词查询的分析网站网页宣传广告怎么做
  • 河北网站建设报价wordpress 顶栏显示
  • 营销型网站建设规划书门户网站建设与管理
  • 网站建设公司怎样做账高质量的丹阳网站建设
  • 十年经验网站开发公司wordpress主题对接支付
  • 云服务器怎么架设网站offic做网站的软件
  • 免费字体下载网站dede 网站目录
  • 网站开发用几种字体山东烟台最新消息今天
  • 郑州网站维护推广宁波网络推广优化公司
  • 网站建设包括哪些内容百度入口网页版
  • 江西网站建设价格低网页广告屏蔽
  • 宁波建网站需要什么江苏省义务教育标准化建设网站
  • 网站怎么自己优化六安做网站
  • 网站的功能定位wordpress 李贤威