Files
itgmania212121/stepmania/src/RageUtil.h
T

128 lines
4.3 KiB
C
Raw Normal View History

/*
-----------------------------------------------------------------------------
File: RageUtil.h
Desc: Helper and error-controlling function used throughout the program.
Copyright (c) 2001 Chris Danford. All rights reserved.
-----------------------------------------------------------------------------
*/
2001-11-03 10:52:42 +00:00
#ifndef _RAGEUTIL_H_
#define _RAGEUTIL_H_
2002-01-20 07:51:09 +00:00
#include "dxerr8.h"
#pragma comment(lib, "DxErr8.lib")
2001-11-03 10:52:42 +00:00
//-----------------------------------------------------------------------------
// SAFE_ Macros
//-----------------------------------------------------------------------------
#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
#define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p); (p)=NULL; } }
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
//-----------------------------------------------------------------------------
// Other Macros
//-----------------------------------------------------------------------------
#define RECTWIDTH(rect) ((rect).right - (rect).left)
#define RECTHEIGHT(rect) ((rect).bottom - (rect).top)
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
2002-01-16 10:01:32 +00:00
#define clamp(val,low,high) ( max( (low), min((val),(high)) ) )
2001-11-03 10:52:42 +00:00
//-----------------------------------------------------------------------------
// Misc helper functions
//-----------------------------------------------------------------------------
// Simple function for generating random numbers
2001-12-28 10:15:59 +00:00
float randomf( float low=-1.0f, float high=1.0f );
2001-11-03 10:52:42 +00:00
int roundf( FLOAT f );
int roundf( double f );
2001-12-28 10:15:59 +00:00
bool IsAnInt( CString s );
2001-11-03 10:52:42 +00:00
CString ssprintf( LPCTSTR fmt, ...);
CString vssprintf( LPCTSTR fmt, va_list argList );
/*
@FUNCTION: Splits a Path into 4 parts (Directory, Drive, Filename, Extention).
NOTE: Supports UNC path names.
@PARAM1: Whether the Supplied Path (PARAM2) contains a directory name only
or a file name (Reason: some directories will end with "xxx.xxx"
which is like a file name).
@PARAM2: Path to Split.
@PARAM3: (Referenced) Directory.
@PARAM4: (Referenced) Drive.
@PARAM5: (Referenced) Filename.
@PARAM6: (Referenced) Extention.
*/
void splitpath(BOOL UsingDirsOnly, CString Path, CString& Drive, CString& Dir, CString& FName, CString& Ext);
2001-12-28 10:15:59 +00:00
void splitrelpath( CString Path, CString& Dir, CString& FName, CString& Ext );
2001-11-03 10:52:42 +00:00
/*
@FUNCTION: Splits a CString into an CStringArray according the Deliminator.
NOTE: Supports UNC path names.
@PARAM1: Source string to be Split.
@PARAM2: Deliminator.
@PARAM3: (Referenced) CStringArray to Add to.
*/
2001-12-28 10:15:59 +00:00
void split(CString Source, CString Deliminator, CStringArray& AddIt, bool bIgnoreEmpty = true );
2001-11-03 10:52:42 +00:00
/*
@FUNCTION: Joins a CStringArray to create a CString according the Deliminator.
@PARAM1: Deliminator.
@PARAM2: (Referenced) CStringArray to Add to.
*/
CString join(CString Deliminator, CStringArray& Source);
void GetDirListing( CString sPath, CStringArray &AddTo, BOOL bOnlyDirs=FALSE );
2001-11-25 04:31:44 +00:00
bool DoesFileExist( CString sPath );
2001-12-20 12:37:38 +00:00
DWORD GetFileSizeInBytes( CString sFilePath );
2001-11-03 10:52:42 +00:00
int CompareCStrings(const void *arg1, const void *arg2);
void SortCStringArray( CStringArray &AddTo, BOOL bSortAcsending = TRUE );
//-----------------------------------------------------------------------------
// Log helpers
//-----------------------------------------------------------------------------
void RageLogStart();
void RageLog( LPCTSTR fmt, ...);
2002-01-20 07:51:09 +00:00
void RageLogHr( HRESULT hr, LPCTSTR fmt, ...);
2001-11-03 10:52:42 +00:00
//-----------------------------------------------------------------------------
// Error helpers
//-----------------------------------------------------------------------------
VOID DisplayErrorAndDie( CString sError );
2002-01-16 10:01:32 +00:00
#if defined(DEBUG) | defined(_DEBUG)
#define RageError(str) DisplayErrorAndDie( ssprintf( "%s\n\n%s(%d)", str, __FILE__, (DWORD)__LINE__) )
#define RageErrorHr(str,hr) DisplayErrorAndDie( ssprintf("%s (%s)\n\n%s(%d)", str, DXGetErrorString8(hr), __FILE__, (DWORD)__LINE__) )
#else
#define RageError(str) DisplayErrorAndDie( ssprintf( "%s\n\n%", str ) )
#define RageErrorHr(str,hr) DisplayErrorAndDie( ssprintf("%s (%s)\n\n%", str, DXGetErrorString8(hr) ) )
#endif
2001-11-03 10:52:42 +00:00
LONG GetRegKey(HKEY key, LPCTSTR subkey, LPTSTR retdata);
HINSTANCE GotoURL(LPCTSTR url);
2001-11-03 10:52:42 +00:00
#endif