Example #1
0
        /// convert wide char string to multibyte string
        bool WCSToMBS(behaviac::string& resultString, const behaviac::wstring& wstr, const char* locale)
        {
            BEHAVIAC_UNUSED_VAR(resultString);
            BEHAVIAC_UNUSED_VAR(wstr);
            BEHAVIAC_UNUSED_VAR(locale);

            bool ret = false;

#if BEHAVIAC_COMPILER_MSVC
            const int cp = (strcmp(locale, LOCALE_CN_UTF8) == 0) ? CP_UTF8 : CP_ACP;
            const int dwNum = WideCharToMultiByte(cp, 0, wstr.c_str(), -1, NULL, 0, NULL, NULL);
            char* buffer = (char*)BEHAVIAC_MALLOC_WITHTAG(dwNum * 2 + 2, "WCSToMBS");

            if (buffer)
            {
                WideCharToMultiByte(cp, 0, wstr.c_str(), -1, buffer, dwNum, NULL, NULL);

                resultString = buffer;
                BEHAVIAC_FREE(buffer);

                ret = true;
            }

#else
            uint32_t dwNum = (wstr.size() + 1) * 4;
            char* buffer = (char*)BEHAVIAC_MALLOC_WITHTAG(dwNum, "WCSToMBS");

            if (buffer)
            {
                //remember it to restore it later
                char* currrentLocale = setlocale(LC_ALL, 0);

                char* loc = setlocale(LC_ALL, locale);

                if (loc)
                {
                    wcstombs(buffer, wstr.c_str(), dwNum);
                    ret = true;
                }

                //restore
                setlocale(LC_ALL, currrentLocale);

                resultString = buffer;
                BEHAVIAC_FREE(buffer);
            }

#endif//#if BEHAVIAC_COMPILER_MSVC

            return ret;
        }
Example #2
0
    void Workspace::LoadWorkspaceAbsolutePath()
    {
#if !BEHAVIAC_RELEASE

        if (Config::IsLoggingOrSocketing())
        {
            //relative to exe's current path
            const char* workspaceExportPath = this->GetFilePath();

            //workspaceExportPath is the path to the export:
            //like: ..\example\spaceship\data\bt\exported
            behaviac::string fullPath = StringUtils::CombineDir(workspaceExportPath, "behaviors.dbg.xml");
            behaviac::string workspaceFilePathRelative;
            bool bOk = LoadWorkspaceSetting(fullPath.c_str(), workspaceFilePathRelative);

            if (bOk)
            {
                //workspaceFilePathRelative stored in behaviors.dbg.xml is the path relative to export
                //convert it to the full path
                wchar_t* workspaceRootPath = this->m_workspace_file;
                workspaceRootPath[0] = '\0';

                if (behaviac::CFileManager::GetInstance()->PathIsRelative(workspaceExportPath))
                {
                    const behaviac::wstring currentWD = behaviac::CFileManager::GetInstance()->GetCurrentWorkingDirectory();
                    int len = currentWD.size();
                    BEHAVIAC_ASSERT(len + 1 < kMaxPath, "path is too long !");
                    wcscpy(workspaceRootPath, currentWD.c_str());
                    wchar_t last = workspaceRootPath[len - 1];

                    if (last != L'/' && last != L'\\')
                    {
                        workspaceRootPath[len] = L'/';
                        workspaceRootPath[len + 1] = L'\0';
                    }

                    m_workspaceExportPathAbs = workspaceRootPath;

                    //{
                    //    uint32_t p = m_workspaceExportPathAbs.find_last_of(STRING2WSTRING("Assets"));

                    //    if (p != (uint32_t)-1) {
                    //        m_workspaceExportPathAbs = m_workspaceExportPathAbs.substr(0, p);
                    //    }
                    //}

                    m_workspaceExportPathAbs = StringUtils::CombineDir(m_workspaceExportPathAbs.c_str(), STRING2WSTRING(workspaceExportPath).c_str());
                }
                else
                {
                    m_workspaceExportPathAbs = STRING2WSTRING(workspaceExportPath);
                }

                m_workspaceExportPathAbs = StringUtils::CombineDir(m_workspaceExportPathAbs.c_str(), STRING2WSTRING(workspaceFilePathRelative).c_str());

                //ms_workspace_file = m_workspaceExportPathAbs+workspaceFilePathRelative;
                wcscpy(m_workspace_file, m_workspaceExportPathAbs.c_str());
            }
            else
            {
            }
        }

#endif
    }
Example #3
0
	bool Workspace::SetWorkspaceSettings(const char* workspaceExportPath, Workspace::EFileFormat format, float deltaTime, int deltaFrames)
	{
		ms_deltaTime = deltaTime;
		ms_deltaFrames = deltaFrames;
		ms_fileFormat = format;

		//debug to test bson
		//ms_fileFormat = EFF_bson;
		//a valid workspace file
		BEHAVIAC_ASSERT(workspaceExportPath && workspaceExportPath[0] != '\0');

		strcpy(ms_workspace_export_path, workspaceExportPath);

		{
			int len = strlen(ms_workspace_export_path);
			BEHAVIAC_ASSERT(len < kMaxPath - 1);
			if (ms_workspace_export_path[len - 1] != '/' && ms_workspace_export_path[len - 1] != '\\')
			{
				ms_workspace_export_path[len] = '/';
				ms_workspace_export_path[len + 1] = '\0';
			}
			else
			{
				//ended with '/'
				BEHAVIAC_ASSERT(ms_workspace_export_path[len - 1] == '\\' || ms_workspace_export_path[len - 1] == '/');
			}
		}

		//ms_workspace_root_path is the path to the export:
		//like: E:\WWWW\IEDDepot\ETC_Depot\tag\extension\behaviac\example\spaceship\data\bt\exported
		behaviac::string fullPath = ms_workspace_export_path;
		fullPath += "behaviors.dbg.xml";

		behaviac::string workspacePathRelative;
		bool bOk = LoadWorkspaceSetting(fullPath.c_str(), workspacePathRelative);
		if (bOk)
		{
			//workspacePath stored in behaviors.dbg.xml is the path relative to export
			//convert it to the full path
			wchar_t* workspaceRootPath = ms_workspace_file;
			workspaceRootPath[0] = '\0';

			if (CFileManager::GetInstance()->PathIsRelative(ms_workspace_export_path))
			{
				const behaviac::wstring currentWD = CFileManager::GetInstance()->GetCurrentWorkingDirectory().c_str();
				int len = currentWD.size();

				BEHAVIAC_ASSERT(len < kMaxPath);
				wcscpy(workspaceRootPath, currentWD.c_str());

				wchar_t last = workspaceRootPath[len - 1];
				if (last != L'/' && last != L'\\')
				{
					workspaceRootPath[len] = L'/';
					workspaceRootPath[len + 1] = L'\0';
				}
			}

			behaviac::wstring workspaceRootPathAbs = workspaceRootPath;

			//the first char is not the separator
			BEHAVIAC_ASSERT(ms_workspace_export_path[0] != '/' && ms_workspace_export_path[0] != '\\');

			workspaceRootPathAbs += STRING2WSTRING(ms_workspace_export_path);
			workspaceRootPathAbs += STRING2WSTRING(workspacePathRelative);

			wcscpy(ms_workspace_file, workspaceRootPathAbs.c_str());

			Socket::SendWorkspaceSettings();

			return true;
		}

		return false;
	}