Beispiel #1
0
string Path::GetFileName( string path )
{
	int l = path.find_last_of(DirectorySeparatorChar());
	
	if(l == -1)
		l = path.find_last_of(AltDirectorySeparatorChar());
	
	return path.substr(l + 1);
}
Beispiel #2
0
string Path::GetDirectoryName( string path )
{
	int l = path.find_last_of(DirectorySeparatorChar());
	
	if(l == -1)
		l = path.find_last_of(AltDirectorySeparatorChar());
	
	if(l == -1)
		return "";
	
	return path.substr(0, l);
}
Beispiel #3
0
string Path::GetFileNameWithoutExtension( string path )
{
	int l = path.find_last_of(DirectorySeparatorChar());			
	
	if(l == -1)
		l = path.find_last_of(AltDirectorySeparatorChar());
	
	int extension = path.find_last_of('.');
	if(extension == -1)
		extension = path.length();
	
	return path.substr(l + 1, extension);
}
Beispiel #4
0
char *HostMachine::ResolveFileName(const char *istr)
{
	if(!istr) return NULL;

	char *RetBuf = new char[MaxPathLength()], *RBPtr;
	RBPtr = RetBuf;

	const char *start, *end;
	char * TempStr = new char[MaxPathLength()];
	int CopyOffset;
	start = istr;
	do
	{
		end = start;
		while(*end != '/' && *end) end++;

		memcpy(TempStr, start, end-start);
		TempStr[end-start] = '\0';
		bool Handled = false;
		CopyOffset = 0;

		if(!strcmp(TempStr, "%ROMPATH%") && ROMPath)
		{
			Handled = true;
			memcpy(RBPtr, ROMPath, strlen(ROMPath)+1);
			RBPtr += strlen(ROMPath);
		}

		if(!strcmp(TempStr, "%GFXPATH%") && GFXPath)
		{
			Handled = true;
			memcpy(RBPtr, GFXPath, strlen(GFXPath)+1);
			RBPtr += strlen(GFXPath);
		}

		if(	!strcmp(TempStr, "%EXECPATH%")	|| 
			(!strcmp(TempStr, "%ROMPATH%") && !ROMPath) ||
			(!strcmp(TempStr, "%GFXPATH%") && !GFXPath)
			)
		{
			Handled = true;
			char *T = GetExecutablePath();
			memcpy(RBPtr, T, strlen(T)+1);
			RBPtr += strlen(T);
			delete[] T;
		}

		if(	!strcmp(TempStr, "%HOMEPATH%")	)
		{
#ifndef WIN32
			Handled = true;
			char *T = getenv("HOME");
			memcpy(RBPtr, T, strlen(T)+1);
			RBPtr += strlen(RBPtr);
#else
			Handled = true;
			char *T = getenv("APPDATA");
			if(T)
			{
				memcpy(RBPtr, T, strlen(T)+1);
				RBPtr += strlen(RBPtr);
			}
			else
			{
				T = GetExecutablePath();
				memcpy(RBPtr, T, strlen(T)+1);
				RBPtr += strlen(T);
				delete[] T;
			}
#endif
		}


		if( !strncmp(TempStr, "%DOT%", 5) )
		{
#ifndef WIN32
			RBPtr[0] = '.';
			RBPtr[1] = '\0';
			RBPtr ++;
#endif
			CopyOffset = 5;
		}

		if(!Handled && CopyOffset < (end-start))
		{
			memcpy(RBPtr, &start[CopyOffset], (end-start)-CopyOffset);
			RBPtr += (end-start)-CopyOffset;
		}

		RBPtr[0] = DirectorySeparatorChar();
		RBPtr[1] = '\0';
		RBPtr++;
		start = end+1;
	}
	while(*end);

	delete [] TempStr;

	RBPtr--;
	*RBPtr = '\0';
	return RetBuf;
}