Beispiel #1
0
/**
 * 実行している自身のディレクトリパス取得
 * @return 実行ディレクトリフルパス
 */
std::string getBinaryDir()
{
    const int MAXPATHLEN = 4096;
    char exepath[MAXPATHLEN] = {};
#if _WIN32
	wchar_t app_full_path[1024];
	DWORD length = GetModuleFileNameW(NULL, app_full_path, sizeof(app_full_path) / sizeof(wchar_t));
	std::wstring str(app_full_path, length);
	const char16_t* p = reinterpret_cast<const char16_t*>(str.c_str());
	std::u16string u16str(p);
	// utf16 to utf8
	std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
	std::string stdstr = convert.to_bytes(u16str);

	std::string::size_type pos = stdstr.find_last_of("\\");
	if (pos != std::string::npos) {
		std::string basepath = stdstr.substr(0, pos + 1);
		return basepath;
	}
	return stdstr;
    
#elif __APPLE__
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1012
    uint32_t size = sizeof(exepath);
    int ret = _NSGetExecutablePath(exepath, &size);
    if (0 != ret) {
        return ""; // FIXME(IDS): 
    } 
#else
    CFBundleRef bundle         = CFBundleGetMainBundle();
    CFURLRef    executableURL  = CFBundleCopyExecutableURL(bundle);
    CFStringRef executablePath = CFURLCopyFileSystemPath(executableURL, kCFURLPOSIXPathStyle);
    CFStringGetMaximumSizeOfFileSystemRepresentation(executablePath);
    CFStringGetFileSystemRepresentation(executablePath, exepath, MAXPATHLEN);
    CFRelease(executablePath);
    CFRelease(executableURL);
#endif
#else // Linux
    readlink("/proc/self/exe", exepath, sizeof(exepath));
#endif
    // for Mac & Linux
    std::string fullpath(exepath);
    size_t t = fullpath.rfind("/");
    if (t != std::string::npos) {
        fullpath = fullpath.substr(0, t + 1);
    }
    return fullpath;
}
Beispiel #2
0
// Get a tag's string value from a given name
GMexport const char* FMODGMS_Snd_Get_TagStringFromName(double soundIndex, char* tagName)
{
	int si = (int)round(soundIndex);
	int sndListSize = soundList.size();

	if (sndListSize > si && si >= 0)
	{
		int numTags;
		FMOD_TAG tag;
		bool tagFound = false;

		soundList[si]->getNumTags(&numTags, 0);

		// iterate through tags and find the one that matches tagName
		for (int i = 0; i < numTags; i++)
		{
			soundList[si]->getTag(0, i, &tag);

			if (strcmp(tag.name, tagName) == 0)
			{
				tagFound = true;
				break;
			}
		}

		if (tagFound)
		{
			if (tag.datatype >= FMOD_TAGDATATYPE_STRING && tag.datatype < FMOD_TAGDATATYPE_CDTOC)
			{
				if (tag.datatype >= FMOD_TAGDATATYPE_STRING && tag.datatype < FMOD_TAGDATATYPE_CDTOC)
				{
					// 8-bit string
					if (tag.datatype == FMOD_TAGDATATYPE_STRING || tag.datatype == FMOD_TAGDATATYPE_STRING_UTF8)
					{
						return (const char*)tag.data;
					}

					// 16-bit string
					else if (tag.datatype == FMOD_TAGDATATYPE_STRING_UTF16)
					{
						std::u16string u16str((char16_t*)tag.data + 1, tag.datalen / 2);
						u16ToASCII(u16str);
						return tagString.c_str();

						/*const char16_t* chr16str = u16str.c_str();
						tagString = u16Converter.to_bytes(chr16str);
						return tagString.c_str();*/


					}

					else if (tag.datatype == FMOD_TAGDATATYPE_STRING_UTF16BE)
					{
						std::u16string u16str((char16_t*)tag.data, tag.datalen / 2);
						u16ToASCII(u16str);
						return tagString.c_str();

						/*const char16_t* chr16str = u16str.c_str();
						tagString = u16Converter.to_bytes(chr16str);
						return tagString.c_str();*/
					}
				}
			}

			else
			{
				errorMessage = "Tag is not a string.";
				return errorMessage;
			}
		}

		else
		{
			errorMessage = "Tag not found.";
			return errorMessage;
		}
	}

	// index out of bounds
	else
	{
		errorMessage = "Sound index out of bounds.";
		return errorMessage;
	}

	return "What?";
}
Beispiel #3
0
// Get a tag's string value from a given index
GMexport const char* FMODGMS_Snd_Get_TagStringFromIndex(double soundIndex, double tagIndex)
{
	int si = (int)round(soundIndex);
	int sndListSize = soundList.size();

	if (sndListSize > si && si >= 0)
	{
		int numTags;
		int ti = (int)round(tagIndex);

		soundList[si]->getNumTags(&numTags, 0);

		if (numTags > ti)
		{
			FMOD_TAG tag;
			soundList[si]->getTag(0, ti, &tag);

			if (tag.datatype >= FMOD_TAGDATATYPE_STRING && tag.datatype < FMOD_TAGDATATYPE_CDTOC)
			{
				// 8-bit string
				if (tag.datatype == FMOD_TAGDATATYPE_STRING || tag.datatype == FMOD_TAGDATATYPE_STRING_UTF8)
				{
					return (const char*)tag.data;
				}

				// 16-bit string
				else if (tag.datatype == FMOD_TAGDATATYPE_STRING_UTF16)
				{
					std::u16string u16str((char16_t*)tag.data + 1, tag.datalen / 2);
					u16ToASCII(u16str);
					return tagString.c_str();

					/*const char16_t* chr16str = u16str.c_str();
					tagString = u16Converter.to_bytes(chr16str);
					return tagString.c_str();*/
				}

				else if (tag.datatype == FMOD_TAGDATATYPE_STRING_UTF16BE)
				{
					std::u16string u16str((char16_t*)tag.data, tag.datalen / 2);
					u16ToASCII(u16str);
					return tagString.c_str();

					/*const char16_t* chr16str = u16str.c_str();
					tagString = u16Converter.to_bytes(chr16str);
					return tagString.c_str();*/
				}
			}


			else
			{
				errorMessage = "Tag is not a string.";
				return errorMessage;
			}
		}

		else
		{
			errorMessage = "Tag index out of bounds.";
			return errorMessage;
		}
	}

	// index out of bounds
	else
	{
		errorMessage = "Sound index out of bounds.";
		return errorMessage;
	}

	return "What?";
}