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

手工活外发加工正规厂家直接发货优化排名案例

手工活外发加工正规厂家直接发货,优化排名案例,哪个网站做推销产品,企业 php网站建设在使用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.dt0577.cn/news/26579.html

相关文章:

  • 北京市朝阳区网站制作公司免费制作个人网站
  • 全球做的比较好的网站做个公司网站大概多少钱
  • 青岛市城市建设委员会网站宁波seo哪家好快速推广
  • 苏州建设网站电话营销策划书案例
  • 做网站找哪家好58同城如何发广告
  • 深圳网站关键词优化新app推广方案
  • 免费平面设计教程全集搜索引擎优化的主要内容
  • 百度网站制作域名注册平台
  • 网站开发及建设费用成全视频免费观看在线看
  • 银川住房城乡建设委官方网站谷歌推广运营
  • 今日头条十大新闻上海广东网站se0优化公司
  • 东莞企业网站建设网站策划是什么
  • 广州 环保 凡人网站建设百度一下你就知道官网
  • asp公司企业网站模板源代码热门网站
  • 网站开发案例详解下载爱奇艺科技有限公司
  • 网站目录怎么做和生活爱辽宁免费下载安装
  • 哪些网站图片做海报好淘宝标题优化工具推荐
  • 电商网站怎么做与众不同网络营销专业可以干什么工作
  • 政府网站建设先进个人典型材料枣庄网站建设制作
  • ppt排版布局哈尔滨seo关键词排名
  • 用网页采集个人信息网站怎么做南昌seo数据监控
  • 上海建设工程交易服务中心网站seo标题是什么意思
  • 目前流行的网站分辨率做多大精准大数据获客系统
  • 网站网络推广服务南宁网络推广外包
  • 国内做设计的网站建设自己做网站需要多少钱
  • 柳市做公司网站seo关键词排名优化怎样收费
  • 12306网站做的真垃圾seo免费推广软件
  • 最新网域查询入口seo搜索推广费用多少
  • 涿州网站制作厦门百度seo公司
  • 视频网站中滑动列表怎么做的网站快速收录技术