Ejemplo n.º 1
0
void
Project::UpdateBuildInfo(void)
{
	fBuildInfo.projectFolder = fPath.GetFolder();
	fBuildInfo.objectFolder = fObjectPath;
	
	fBuildInfo.includeList.MakeEmpty();
	
	fBuildInfo.includeString = "";
	ProjectPath *projItem = new ProjectPath(fPath.GetFolder());
	fBuildInfo.includeList.AddItem(projItem);
	fBuildInfo.includeString << "-I '" << projItem->Absolute() << "'";
	
	for (int32 i = 0; i < fLocalIncludeList.CountItems(); i++)
	{
		ProjectPath *newitem = new ProjectPath(*fLocalIncludeList.ItemAt(i));
		fBuildInfo.includeList.AddItem(newitem);
		fBuildInfo.includeString << " -I '" << newitem->Absolute() << "'";
	}
	
	for (int32 i = 0; i < fSystemIncludeList.CountItems(); i++)
	{
		BString *item = fSystemIncludeList.ItemAt(i);
		ProjectPath *newitem = new ProjectPath("/", MakeAbsolutePath(item->String()).String());
		fBuildInfo.includeList.AddItem(newitem);
		fBuildInfo.includeString << " -I '" << newitem->Absolute() << "'";
	}
	
	fBuildInfo.errorList.msglist.MakeEmpty();
}
Ejemplo n.º 2
0
int ComparePaths(const String &path1, const String &path2)
{
    // Make minimal absolute paths
    String fixed_path1 = MakeAbsolutePath(path1);
    String fixed_path2 = MakeAbsolutePath(path2);

    fixed_path1.TrimRight('/');
    fixed_path2.TrimRight('/');

    int cmp_result =
#if defined AGS_CASE_SENSITIVE_FILESYSTEM
        fixed_path1.Compare(fixed_path2);
#else
        fixed_path1.CompareNoCase(fixed_path2);
#endif // AGS_CASE_SENSITIVE_FILESYSTEM
    return cmp_result;
}
Ejemplo n.º 3
0
std::shared_ptr<Resource> BillboardAnimationLoader::Load(
	const ResourceKey& key,
	const FileManager& fileManager) const
{
	File file;
	fileManager.Open(key.GetFilePath(), file);
	auto animationJson = file.ReadAll();

	auto deleter = [](json_value* p){ json_value_free(p); };
	auto animationVal = std::unique_ptr<json_value, decltype(deleter)>(
		json_parse(animationJson.c_str(),
			animationJson.length() * sizeof(std::string::value_type)),
		deleter);

	assert(animationVal->type == json_object);
	auto textureVal = (*animationVal)["texture"];
	auto framesXVal = (*animationVal)["framesX"];
	auto framesYVal = (*animationVal)["framesY"];
	auto framesVal = (*animationVal)["frames"];

	assert(textureVal.type == json_string);
	std::string textureFilePath = MakeAbsolutePath(
		key.GetFilePath(), std::string(textureVal));

	auto texture = g_resourceManager->Acquire<TextureResource>(
		ResourceKey(textureFilePath));

	assert(framesXVal.type == json_integer);
	assert(framesYVal.type == json_integer);
	int numFramesX = json_int_t(framesXVal);
	int numFramesY = json_int_t(framesYVal);

	std::vector<Vec2f> texcoordsScales;
	std::vector<Vec2f> texcoordsOffsets;
	std::vector<int> times;

	assert(framesVal.type == json_array);
	const unsigned int numFrames = framesVal.u.array.length;
	for (size_t i = 0; i < numFrames; ++i)
	{
		assert(framesVal[i].type == json_object);
		auto frameXVal = framesVal[i]["x"];
		auto frameYVal = framesVal[i]["y"];
		auto timeVal = framesVal[i]["ms"];

		assert(frameXVal.type == json_integer);
		assert(frameYVal.type == json_integer);
		assert(timeVal.type == json_integer);
		int frameX = json_int_t(frameXVal);
		int frameY = json_int_t(frameYVal);
		int time = json_int_t(timeVal);

		float frameWidth = 1.0f / numFramesX;
		float frameHeight = 1.0f / numFramesY;

		Vec2f texcoordsScale(frameWidth, frameHeight);
		Vec2f texcoordsOffset(frameX * frameWidth, (1 - frameY) * frameHeight);

		texcoordsScales.push_back(texcoordsScale);
		texcoordsOffsets.push_back(texcoordsOffset);
		times.push_back(time);
	}

	return std::make_shared<BillboardAnimationResource>(
		texcoordsScales, texcoordsOffsets, times, texture);
}
Ejemplo n.º 4
0
BOOL Shell::Execute_Cd( const TStringVector& cmdparts, tstring& reply )
{
	if (cmdparts.size() == 1)
	{
		reply = m_currentPath;
		return TRUE;
	}
	else if (cmdparts.size() > 1)
	{
		tstring target = cmdparts[1];
		if (target.size() == 2 && target[1] == ':')
		{
			//切换当前分区
			int index = 0;
			TCHAR partition = target[0];
			if (partition >= 'a' && partition <= 'z') index = partition - 'a';
			else if (partition >= 'A' && partition <= 'Z') index = partition - 'A';
			else
			{
				reply = _T("invalid partition");
				return FALSE;
			}

			if (! m_partitions[index].bValid)
			{
				reply = _T("invalid partition");
				return FALSE;
			}

			m_currentPath = m_partitions[index].curPath;
			reply = m_currentPath;

			return TRUE;
		}
		else 
		{
			tstring testPath;
			if (target.size() > 2 && target[1] == ':')
			{
				//绝对路径
				testPath = target;
			}
			else
			{
				//相对路径
				testPath = m_currentPath;
				testPath += '\\';
				testPath += target;
				MakeAbsolutePath(testPath.c_str(), testPath);
			}
			
			BOOL bExists = FALSE;
			BOOL bDir = FALSE;
			if (FileExistsInClient(testPath.c_str(), bExists, bDir))
			{
				if (bExists && bDir)
				{
					SetCurrentPath(testPath.c_str());
					reply = m_currentPath;
					return TRUE;
				}
				else
				{
					reply = _T("invalid filepath");
					return FALSE;
				}
			}
			else
			{
				reply = _T("等待客户端回应超时");
				return FALSE;
			}
		}
	}

	return FALSE;
}
Ejemplo n.º 5
0
BOOL Shell::Execute_Dir( const TStringVector& cmdparts, tstring& reply )
{
	tstring findstr = _T("*");
	if (cmdparts.size() > 1)
	{
		findstr = cmdparts[1];
	}

	findstr = m_currentPath + _T("\\") + findstr;
	MakeAbsolutePath(findstr.c_str(), findstr);
	if (findstr.find('*') == tstring::npos 
		&& findstr.find('?') == tstring::npos)
	{
		trim(findstr, '\\');
		findstr += _T("\\*");
	}

	CommData request;
	request.SetMsgID(MSGID_LIST_FILES);
	request.SetData(_T("findstr"), findstr.c_str());

	CommData commData;
	if (! AskAndWaitForReply(request, commData))
	{
		reply = _T("客户端响应超时");
		return FALSE;
	}

	DECLARE_STR_PARAM(result);
	//	result		str	目录内容	filename(str)|attr(dword)|filesize(uint64)|lastWriteTime(uint64 filetime):
	tostringstream toss;
	TStringVector fileParts;
	splitByChar(result.c_str(), fileParts, ':');
	TStringVector::iterator fileIter = fileParts.begin();
	for (; fileIter != fileParts.end(); fileIter++)
	{
		tstring& fileInfo = *fileIter;
		TStringVector attrParts;
		splitByChar(fileInfo.c_str(), attrParts, '|');
		if (attrParts.size() != 4) continue;

		tstring& filename = attrParts[0];
		DWORD dwAttrs = 0;
		ULARGE_INTEGER filesize = {0};
		ULARGE_INTEGER lastWriteTime = {0};
		if (1 != _stscanf_s(attrParts[1].c_str(), _T("%u"), &dwAttrs)) continue;
		if (1 != _stscanf_s(attrParts[2].c_str(), _T("%I64u"), &filesize.QuadPart)) continue;
		if (1 != _stscanf_s(attrParts[3].c_str(), _T("%I64u"), &lastWriteTime.QuadPart)) continue;

		SYSTEMTIME systime;
		FILETIME ftLastWriteTime;
		ftLastWriteTime.dwLowDateTime = lastWriteTime.LowPart;
		ftLastWriteTime.dwHighDateTime = lastWriteTime.HighPart;
		FILETIME ftLocalLastWriteTime;
		FileTimeToLocalFileTime(&ftLastWriteTime, &ftLocalLastWriteTime);
		FileTimeToSystemTime(&ftLocalLastWriteTime, &systime);

		BOOL bDir = (dwAttrs & FILE_ATTRIBUTE_DIRECTORY);

		TCHAR line[MAX_PATH * 2] = {0};
		_stprintf_s(line, _T("%04d/%02d/%02d %02d:%02d:%02d %20s %s\r\n"), 
			systime.wYear, systime.wMonth, systime.wDay,
			systime.wHour, systime.wMinute, systime.wSecond,
			(bDir ? _T("<DIR>   ") : FormatSizeWithUnit(filesize.QuadPart).c_str()), filename.c_str());

		toss << line;
	}

	reply = toss.str();

	return TRUE;
}
Ejemplo n.º 6
0
std::shared_ptr<Resource> FontLoader::Load(
	const ResourceKey& key,
	const FileManager& fileManager) const
{
	File file;
	fileManager.Open(key.GetFilePath(), file);
	auto fontJson = file.ReadAll();

	auto deleter = [](json_value* p){ json_value_free(p); };
	auto fontVal = std::unique_ptr<json_value, decltype(deleter)>(
		json_parse(fontJson.c_str(),
			fontJson.length() * sizeof(std::string::value_type)),
		deleter);

	assert(fontVal->type == json_object);
	auto textureVal = (*fontVal)["texture"];
	auto dimXVal = (*fontVal)["dimX"];
	auto dimYVal = (*fontVal)["dimY"];
	auto charHVal = (*fontVal)["charH"];
	auto charactersVal = (*fontVal)["characters"];

	assert(textureVal.type == json_string);
	std::string textureFilePath = MakeAbsolutePath(
		key.GetFilePath(), std::string(textureVal));

	auto texture = g_resourceManager->Acquire<TextureResource>(
		ResourceKey(textureFilePath));

	assert(dimXVal.type == json_integer);
	assert(dimYVal.type == json_integer);
	assert(charHVal.type == json_integer);
	int dimX = json_int_t(dimXVal);
	int dimY = json_int_t(dimYVal);
	int charH = json_int_t(charHVal);

	float charTexW = 1.0f / dimX;
	float charTexH = 1.0f / dimY;
	float charScaleAspectRatio = 1.0f / (dimX * charH);
	float charScaleY = 1.0f / dimY;

	std::vector<Vec2f> texcoordsScales;
	std::vector<Vec2f> texcoordsOffsets;
	std::vector<float> aspectRatios;
	std::unordered_map<char, size_t> charToIdxLookup;

	assert(charactersVal.type == json_array);
	const unsigned int numCharacters = charactersVal.u.array.length;
	for (size_t i = 0; i < numCharacters; ++i)
	{
		assert(charactersVal[i].type == json_object);
		auto charVal = charactersVal[i]["c"];
		auto xVal = charactersVal[i]["x"];
		auto yVal = charactersVal[i]["y"];
		auto charWVal = charactersVal[i]["w"];

		assert(charVal.type == json_string);
		assert(xVal.type == json_integer);
		assert(yVal.type == json_integer);
		assert(charWVal.type == json_integer);
		char character = std::string(charVal).at(0);
		int charTexX = json_int_t(xVal);
		int charTexY = json_int_t(yVal);
		int charW = json_int_t(charWVal);

		Vec2f texcoordsScale(charW * charScaleAspectRatio, charScaleY);
		Vec2f texcoordsOffset(
			charTexX * charTexW, 1 - charTexY * charTexH - charTexH);

		texcoordsScales.push_back(texcoordsScale);
		texcoordsOffsets.push_back(texcoordsOffset);
		aspectRatios.push_back(charW / static_cast<float>(charH));
		charToIdxLookup.insert(std::make_pair(character, i));
	}

	return std::make_shared<FontResource>(
		texcoordsScales, texcoordsOffsets, aspectRatios, charToIdxLookup,
		texture);
}
Ejemplo n.º 7
0
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ALUTAPI ALvoid ALUTAPIENTRY alutLoadWAVFile(ALbyte *file,ALenum *format,ALvoid **data,ALsizei *size,ALsizei *freq)
{
	OSStatus		err = noErr;
	AudioFileID		audioFile = 0;
	FSRef			fsRef;

	*data = NULL; // in case of failure, do not return some unitialized value as a bogus address

	if (IsRelativePath(file))
	{
		char			absolutePath[256];
		// we need to make a full path here so FSPathMakeRef() works properly
		MakeAbsolutePath(file, absolutePath, 256);
		// create an fsref from the file parameter
		err = FSPathMakeRef ((const UInt8 *) absolutePath, &fsRef, NULL);
	}
	else
		err = FSPathMakeRef ((const UInt8 *) file, &fsRef, NULL);
	
	if (err == noErr)
	{
		err = AudioFileOpen(&fsRef, fsRdPerm, 0, &audioFile);
		if (err == noErr)
		{
			UInt32							dataSize;
			CAStreamBasicDescription		asbd;
			
			dataSize = sizeof(CAStreamBasicDescription);
			AudioFileGetProperty(audioFile, kAudioFilePropertyDataFormat, &dataSize, &asbd);
			
			*format = GetOALFormatFromASBD(asbd);
			if (IsFormatSupported(*format))
			{
				*freq = (UInt32) asbd.mSampleRate;
				
				SInt64	audioDataSize = 0;
				dataSize = sizeof(audioDataSize);
				err = AudioFileGetProperty(audioFile, kAudioFilePropertyAudioDataByteCount, &dataSize, &audioDataSize);
				if (err == noErr)
				{
					*size = audioDataSize;
					*data = NULL;
					*data = calloc(1, audioDataSize);
					if (*data)
					{
						dataSize = audioDataSize;
						err = AudioFileReadBytes(audioFile, false, 0, &dataSize, *data);
						
						if ((asbd.mFormatID == kAudioFormatLinearPCM) && (asbd.mBitsPerChannel > 8))
						{
							// we just got 16 bit pcm data out of a WAVE file on a big endian platform, so endian swap the data
							AudioConverterRef				converter;
							CAStreamBasicDescription		outFormat = asbd;
							void *							tempData = NULL;
							
							// ste format to big endian
							outFormat.mFormatFlags = kAudioFormatFlagIsBigEndian | kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
							// make some place for converted data
							tempData = calloc(1 , audioDataSize);
							
							err = AudioConverterNew(&asbd, &outFormat, &converter);
							if ((err == noErr) && (tempData != NULL))
							{
								UInt32		bufferSize = audioDataSize;
								err = AudioConverterConvertBuffer(converter, audioDataSize, *data, &bufferSize, tempData);
								if (err == noErr)
									memcpy(*data, tempData, audioDataSize);
								AudioConverterDispose(converter);
							}
							if (tempData) free (tempData);
						}
					}
				}
			}
			err = AudioFileClose(audioFile);
		}
	}
}