Beispiel #1
0
CString	CPathFinder::GetDriveLabel(BOOL bPCNameIfNetwork)
{
	if (_sDriveLabel.IsEmpty() && !IsRelativePath())
	{
		if ((bPCNameIfNetwork) && (!IsLocalPath()))
			_sDriveLabel = GetDir(0);
		else
		{
			CString sRoot;
			TCHAR	szVolumeName[256];

			szVolumeName[0] = '\0';
			if (IsLocalPath())
			{
				sRoot = _sDrive + CString(_T("\\"));
			}
			else if (GetDirCount() > 1)
			{
				sRoot.Format(_T("\\\\%s\\%s\\"), GetDir(0), GetDir(1));
			}

			GetVolumeInformation(sRoot, szVolumeName, 255, NULL, NULL, NULL, NULL, 0);

			_sDriveLabel = szVolumeName;
		}
	}

	return _sDriveLabel;
}
Beispiel #2
0
// This function must be called whenever _arrDir array is needed, since this
// method is the one which parses _strDir and fill _arrDir
void CPath::FillDirArray()
{
	if (_strDir.IsEmpty() || (_arrDir.GetSize() > 0)) return;

	int nFrom, nTo;

	// nFrom: 0 - relative / 1 - local / 2 - network
	nFrom = IsLocalPath() ? 1 : (IsRelativePath() ? 0 : 2);

	while ((nTo = _strDir.Find('\\', nFrom)) != -1)
	{
		_arrDir.Add(_strDir.Mid(nFrom, nTo - nFrom));
		nFrom = nTo + 1;
	}
}
Beispiel #3
0
CString CPathFinder::GetAbsolutePath(LPCTSTR szBaseFolder)
{
	if (!IsRelativePath()) return (LPCTSTR)sCEmptyString;

	TCHAR	szAbsolutePath[_MAX_PATH];
	CString sFullPath(szBaseFolder);

	if (sFullPath.IsEmpty()) return (LPCTSTR)sCEmptyString;

	sFullPath = CPathFinder::AddBackSlash(sFullPath);
	sFullPath += GetPath();

	if (!PathCanonicalize(szAbsolutePath, sFullPath)) return (LPCTSTR)sCEmptyString;

	return szAbsolutePath;
}
Beispiel #4
0
CString CPathFinder::GetRelativePath(LPCTSTR szBaseFolder)
{
	if (IsRelativePath()) return (LPCTSTR)sCEmptyString;

	TCHAR	szRelativePath[_MAX_PATH];
	CString	sRelPath;

	PathRelativePathTo(szRelativePath, szBaseFolder, FILE_ATTRIBUTE_DIRECTORY, 
					GetPath(), IsFilePath() ? 0 : FILE_ATTRIBUTE_DIRECTORY);

	sRelPath = szRelativePath;
	if (sRelPath.GetLength() > 1)
	{
		// Remove ".\" from the beginning
		if ((sRelPath[0] == '.') && (sRelPath[1] == '\\'))
			sRelPath.Right(sRelPath.GetLength() - 2);
	}

	return sRelPath;
}
Beispiel #5
0
int CdFilenameStr::ChangeToRelativeDir( const CdFilenameStr& ev ) 
{
	int	merrRv = 0 ;

	CdFilenameStr	aFilenameStrBase( ev ) ;
	// --------------------------------
	//	ドライブ
	// --------------------------------
	if ( merrRv >= 0 ){
		if ( Drive().length() > 0 && ev.Drive().length() > 0 
				&& Drive() != ev.Drive() ){
			//	双方別々のドライブが指定されている場合は、
			//	相対パスへの変換はできません。
			merrRv = -1 ;	//	 ドライブが異なるため、相対パスにはできません。
		}	else	{
			setDrive( L"" ) ;
			aFilenameStrBase.setDrive( L"" ) ;
		}
	}

	// --------------------------------
	//	ディレクトリ
	// --------------------------------
	if ( merrRv >= 0 ){
		if ( IsRelativePath() ){
			merrRv = -2 ;	//	 thisが相対パスです
		}	else if ( aFilenameStrBase.IsRelativePath() ){
			merrRv = -3 ;	//	 evが相対パスです
		} 
	}
	if ( merrRv >= 0 ){
		//thisを相対パスに変更します。
		setIsRelativePath( true ) ;
		aFilenameStrBase.setIsRelativePath( true ) ;
		
		while ( DirCount() > 0 
				&& aFilenameStrBase.DirCount() > 0 
				&& DirAt( 0 ) == aFilenameStrBase.DirAt( 0 ) 
				&& DirAt( 0 ) != L"." 
				&& DirAt( 0 ) != L".." ){
			delDirAt( 0 ) ;
			aFilenameStrBase.delDirAt( 0 ) ;
		} 
		//	先頭よりの共通のディレクトリを削除します。

		//	
		int iLi ;
		for ( iLi = 0 ; iLi < aFilenameStrBase.DirCount() ; iLi ++ ){
			addDirAt( 0 , L".." ) ;
		}
	}
	// --------------------------------
	//	ファイル名
	// --------------------------------
	if ( merrRv >= 0 ){
		if ( Filename().length() > 0 ){
			if ( aFilenameStrBase.Filename().length() > 0 ){
				setFilename( ev.Filename() ) ;
			}
		}
	}
	return ( merrRv ) ;
};
Beispiel #6
0
bool PathUtil::IsAbsolutePath(const String &path)
{
	return !IsRelativePath(path);
}
Beispiel #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);
		}
	}
}
ERcExitCode CResourceCompilerHelper::InvokeResourceCompiler(const char* szSrcFilePath, const char* szDstFilePath, const bool bUserDialog, const bool bRefresh) 
{
	ERcExitCode eRet = eRcExitCode_Pending;

	// make command for execution
	wchar_t szProjectDir[512];
	GetCurrentDirectoryW(sizeof(szProjectDir) / sizeof(szProjectDir[0]), szProjectDir);

	SettingsManagerHelpers::CFixedString<wchar_t, 512> wRemoteCmdLine;
	SettingsManagerHelpers::CFixedString<wchar_t, 512> wDir;
	CSettingsManagerTools smTools = CSettingsManagerTools();

	wchar_t szToolsDir[512];
	CryFindEngineToolsFolder(sizeof(szToolsDir) / sizeof(szToolsDir[0]), szToolsDir);
	if (!szToolsDir[0])
	{
		return eRcExitCode_FatalError;
	}

	wchar_t szRegSettingsBuffer[1024];
	smTools.GetEngineSettingsManager()->GetValueByRef("RC_Parameters", SettingsManagerHelpers::CWCharBuffer(szRegSettingsBuffer, sizeof(szRegSettingsBuffer)));

	wRemoteCmdLine.append(szToolsDir);
	wRemoteCmdLine.appendAscii("/rc/");
	wRemoteCmdLine.appendAscii(RC_EXECUTABLE);
	wRemoteCmdLine.appendAscii(" \"");
	if (IsRelativePath(szSrcFilePath))
	{
		wRemoteCmdLine.append(szProjectDir);
		wRemoteCmdLine.appendAscii("\\");
	}
	wRemoteCmdLine.appendAscii(szSrcFilePath);
	wRemoteCmdLine.appendAscii("\" ");
	wRemoteCmdLine.appendAscii(bUserDialog ? "/userdialog=1 " : "/userdialog=0 ");
	wRemoteCmdLine.appendAscii(bRefresh    ? "/refresh=1 "    : "/refresh=0 "   );
	wRemoteCmdLine.append(szRegSettingsBuffer);

	// make it write to a filename of our choice
	char szDstFilename[512];
	char szDstPath[512];

	RemovePath(szDstFilePath, szDstFilename, sizeof(szDstFilename) / sizeof(szDstFilename[0]));
	RemoveFilename(szDstFilePath, szDstPath, sizeof(szDstPath) / sizeof(szDstPath[0]));

	wRemoteCmdLine.appendAscii(" /overwritefilename=\"");
	wRemoteCmdLine.appendAscii(szDstFilename);
	wRemoteCmdLine.appendAscii("\"");
	wRemoteCmdLine.appendAscii(" /targetroot=\"");
	if (IsRelativePath(szDstPath))
	{
		wRemoteCmdLine.append(szProjectDir);
		wRemoteCmdLine.appendAscii("\\");
	}
	wRemoteCmdLine.appendAscii(szDstPath);
	wRemoteCmdLine.appendAscii("\"");

	wDir.append(szToolsDir);
	wDir.appendAscii("\\rc");

	STARTUPINFOW si;
	ZeroMemory(&si, sizeof(si));
	si.cb = sizeof(si);
	si.dwX = 100;
	si.dwY = 100;
	si.dwFlags = STARTF_USEPOSITION;

	PROCESS_INFORMATION pi;
	ZeroMemory(&pi, sizeof(pi));

#if defined(DEBUG) && !defined(NDEBUG) && defined(_RENDERER)
	extern ILog *iLog;

	char tmp1[512];
	char tmp2[512];
	SettingsManagerHelpers::CCharBuffer dst1(tmp1, 512); SettingsManagerHelpers::ConvertUtf16ToUtf8(wDir.c_str(), dst1);
	SettingsManagerHelpers::CCharBuffer dst2(tmp2, 512); SettingsManagerHelpers::ConvertUtf16ToUtf8(wRemoteCmdLine.c_str(), dst2);

	iLog->Log("Debug: RC: dir \"%s\", cmd \"%s\"\n", tmp1, tmp2);
#endif

	if (!CreateProcessW( 
		NULL,     // No module name (use command line). 
		const_cast<wchar_t*>(wRemoteCmdLine.c_str()), // Command line. 
		NULL,     // Process handle not inheritable. 
		NULL,     // Thread handle not inheritable. 
		FALSE,    // Set handle inheritance to FALSE. 
		BELOW_NORMAL_PRIORITY_CLASS + (bUserDialog ? 0 : CREATE_NO_WINDOW),	// creation flags. 
		NULL,     // Use parent's environment block. 
		wDir.c_str(),  // Set starting directory. 
		&si,      // Pointer to STARTUPINFO structure.
		&pi))     // Pointer to PROCESS_INFORMATION structure.
	{
		eRet = eRcExitCode_FatalError;
	}
	else
	{
		// Wait until child process exits.
		WaitForSingleObject(pi.hProcess, INFINITE);

		DWORD exitCode;
		if (GetExitCodeProcess(pi.hProcess, &exitCode) == 0)
		{
			eRet = eRcExitCode_Error;
		}
		else
		{
			eRet = (ERcExitCode)exitCode;
		}
	}

	// Close process and thread handles. 
	CloseHandle(pi.hProcess);
	CloseHandle(pi.hThread);

	return eRet;
}