/* ======================================================================================= Name: IniData.cpp : implementation file(functions for getting ini data, check this data, write them ...) Author: Mihaela Tancu Date: 2 June 1998 ======================================================================================= */ #include "stdafx.h" #include "winbase.h" #include "io.h" #include "IniData.h" #include #include #include #include #include "Scr.h" #include "Print.h" BOOL bDebug; BOOL bConvAnim = FALSE; BOOL bConvTextures = FALSE; BOOL bConvLevels = TRUE; BOOL bFix1; BOOL bStartPrg = TRUE; //BOOL b3DCard; //BOOL bUsed = TRUE; BOOL bDsc = FALSE; /* ======================================================================================= * Macro to bound size of a rect ======================================================================================= */ #define M_vVerifyRect( _p_stRect, _iMinWidth, _iMinHeight )\ {\ if (_p_stRect->right - _p_stRect->left + 1 < _iMinWidth )\ _p_stRect->right = _p_stRect->left + _iMinWidth ;\ if (_p_stRect->bottom - _p_stRect->top + 1 < _iMinHeight )\ _p_stRect->bottom = _p_stRect->top + _iMinHeight;\ } /* ======================================================================================= Globals ======================================================================================= */ tdstInitialValue g_stInitialData; // data in ini file tdstInitialValue g_stDefaultData = // default value for data { "d:\\cpa\\appli\\BinaryTool\\GameDataBinDD3D", // default temp path for game data debug(computed) "none", // default game data path (computed if none) "d:\\cpa\\appli\\BinaryTool\\GameData", // default temp path for source directory (computed) "none", // default source directory path (computed if none) "d:\\cpa\\appli\\BinaryTool\\GameDataBinRD3D", // default temp path for game data release(computed) "none", // default game data release path (computed if none) "d:\\cpa\\appli\\BinaryTool\\GameDataBinDDFX", // default temp path for game data release(computed) "none", // default game data release path (computed if none) "d:\\cpa\\appli\\BinaryTool\\GameDataBinRDFX", // default temp path for game data release(computed) "none", // default game data release path (computed if none) "Debug", // default temp for debug "none", // default "D3D", // default temp for debug "none", // default "MainWinR.exe", // default temp for exe file "none", // default }; char g_szIniFile[MAX_PATH]; tdstWindowsPosSize g_stWinPosSize; char g_szStartPrgIniFile[MAX_PATH]; /* ======================================================================================= Name: fn_IniData_vSetDestBinDD3D Description: Change the rights of the file to write Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vSetDestBinDD3D( char *_szPath ) { if (_access( g_szIniFile, 2) == -1) _chmod ( g_szIniFile, _S_IWRITE ); WritePrivateProfileString( "General directories", "DirNameDestBinDD3D", _szPath, g_szIniFile ); } /* ======================================================================================= Name: MLT_vOutput Description: Write a string in the rich edit Author: Mihaela Tancu ======================================================================================= */ void MLT_vOutput( char cLineType, char *szFormat, ... ) { va_list argptr; char szLine[256]; va_start( argptr, szFormat ); vsprintf( szLine, szFormat, argptr ); va_end( argptr ); #ifndef _WINDOWS cLineType = cLineType; // to avoid warning fprintf( stderr, szLine ); #else fn_vAfxOutputStringRes( szLine, cLineType); #endif } /* ======================================================================================= Name: fn_IniData_vSetSPDebug Description: Change the rights of the file to write Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vSetSPDebug( char *_szPath ) { if (_access( g_szStartPrgIniFile, 2) == -1) _chmod ( g_szStartPrgIniFile, _S_IWRITE ); WritePrivateProfileString( "Glide", "Debug", _szPath, g_szStartPrgIniFile ); } /* ======================================================================================= Name: fn_IniData_vSetSPRelease Description: Change the rights of the file to write Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vSetSPRelease( char *_szPath ) { if (_access( g_szStartPrgIniFile, 2) == -1) _chmod ( g_szStartPrgIniFile, _S_IWRITE ); WritePrivateProfileString( "Glide", "Release", _szPath, g_szStartPrgIniFile ); } /* ======================================================================================= Name: fn_IniData_vSetAskAtEachTime Description: Change the rights of the file to write Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vSetAskAtEachTime( char *_szPath ) { if (_access( g_szStartPrgIniFile, 2) == -1) _chmod ( g_szStartPrgIniFile, _S_IWRITE ); WritePrivateProfileString( "Start", "AskAtEachTime", _szPath, g_szStartPrgIniFile ); } /* ======================================================================================= Name: fn_IniData_vSetAskAtEachTime Description: Change the rights of the file to write Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vSetAskAtEachTime( int iValue ) { char szValue[2]; if (_access( g_szStartPrgIniFile, 2) == -1) _chmod ( g_szStartPrgIniFile, _S_IWRITE ); if (iValue) strcpy( szValue, "1"); else strcpy( szValue, "0"); WritePrivateProfileString( "Start", "AskAtEachTime", szValue, g_szStartPrgIniFile ); } /* ======================================================================================= Name: fn_IniData_vSetBinDebugIsOk Description: Change the rights of the file to write Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vSetBinDebugIsOk( int iValue ) { char szValue[2]; if (_access( g_szStartPrgIniFile, 2) == -1) _chmod ( g_szStartPrgIniFile, _S_IWRITE ); if (iValue) strcpy( szValue, "1"); else strcpy( szValue, "0"); WritePrivateProfileString( "Start", "BinDebugIsOk", szValue, g_szStartPrgIniFile ); } /* ======================================================================================= Name: fn_IniData_vSetBinReleaseIsOk Description: Change the rights of the file to write Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vSetBinReleaseIsOk( int iValue ) { char szValue[2]; if (_access( g_szStartPrgIniFile, 2) == -1) _chmod ( g_szStartPrgIniFile, _S_IWRITE ); if (iValue) strcpy( szValue, "1"); else strcpy( szValue, "0"); WritePrivateProfileString( "Start", "BinReleaseIsOk", szValue, g_szStartPrgIniFile ); } /* ======================================================================================= Name: fn_IniData_vSetUseBinaryData Description: Change the rights of the file to write Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vSetBinUseBinaryData( int iValue ) { char szValue[2]; if (_access( g_szStartPrgIniFile, 2) == -1) _chmod ( g_szStartPrgIniFile, _S_IWRITE ); if (iValue) strcpy( szValue, "1"); else strcpy( szValue, "0"); WritePrivateProfileString( "Start", "UseBinaryData", szValue, g_szStartPrgIniFile ); } /* ======================================================================================= Name: fn_IniData_vSetGDDebugBin Description: Change the rights of the file to write Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vSetGDDebugBin( char *_szPath ) { if (_access( g_szStartPrgIniFile, 2) == -1) _chmod ( g_szStartPrgIniFile, _S_IWRITE ); WritePrivateProfileString( "Start", "GDDebugBin", _szPath, g_szStartPrgIniFile ); } /* ======================================================================================= Name: fn_IniData_vSetGDReleaseBin Description: Change the rights of the file to write Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vSetGDReleaseBin( char *_szPath ) { if (_access( g_szStartPrgIniFile, 2) == -1) _chmod ( g_szStartPrgIniFile, _S_IWRITE ); WritePrivateProfileString( "Start", "GDReleaseBin", _szPath, g_szStartPrgIniFile ); } /* ======================================================================================= Name: fn_IniData_vSetSource Description: Change the rights of the file to write (write the path for RawData Directory in the .ini file) Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vSetSource( char *_szPath ) { if (_access( g_szIniFile, 2) == -1) _chmod ( g_szIniFile, _S_IWRITE ); WritePrivateProfileString( "General directories", "DirNameSource", _szPath, g_szIniFile ); } /* ======================================================================================= Name: fn_IniData_vSetDestBinR Description: Change the rights of the file to write (write the path for Textures Sub-directory in the .ini file) Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vSetDestBinRD3D( char *_szPath ) { if (_access( g_szIniFile, 2) == -1) _chmod ( g_szIniFile, _S_IWRITE ); WritePrivateProfileString( "General directories", "DirNameDestBinRD3D", _szPath, g_szIniFile ); } /* ======================================================================================= Name: fn_IniData_vSetGameData Description: Change the rights of the file to write (write the path for Game Data Directory in the .ini file) Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vSetDestBinDDFX( char *_szPath ) { if (_access( g_szIniFile, 2) == -1) _chmod ( g_szIniFile, _S_IWRITE ); WritePrivateProfileString( "General directories", "DirNameDestBinDDFX", _szPath, g_szIniFile ); } /* ======================================================================================= Name: fn_IniData_vSetDestBinR Description: Change the rights of the file to write (write the path for Textures Sub-directory in the .ini file) Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vSetDestBinRDFX( char *_szPath ) { if (_access( g_szIniFile, 2) == -1) _chmod ( g_szIniFile, _S_IWRITE ); WritePrivateProfileString( "General directories", "DirNameDestBinRDFX", _szPath, g_szIniFile ); } /* ======================================================================================= Name: fn_IniData_vGetDatasFromStartFile Description: Get all datas saved in the .ini file Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vGetDatasFromStartFile( BOOL _bFirst ) { if (_bFirst) { // GetCurrentDirectory( MAX_PATH, g_szStartPrgIniFile ); strcpy(g_szStartPrgIniFile, sInitialDir); if (g_szStartPrgIniFile[strlen(g_szStartPrgIniFile) - 1] != '\\') strcat( g_szStartPrgIniFile, "\\"); strcat( g_szStartPrgIniFile, C_szStartPrgIniFile ); } if (bDebug) GetPrivateProfileString( "Glide", "Debug", g_stDefaultData.szExeFile, g_stInitialData.szExeFile, MAX_PATH, g_szStartPrgIniFile ); else GetPrivateProfileString( "Glide", "Release", g_stDefaultData.szExeFile, g_stInitialData.szExeFile, MAX_PATH, g_szStartPrgIniFile ); HANDLE hHandle; WIN32_FIND_DATA stFindFileData; memset(&stFindFileData,0,sizeof(stFindFileData)); hHandle = FindFirstFile(g_szStartPrgIniFile, &stFindFileData); //return a boolean for telling if some files *.* exists in the directory or not if( hHandle == INVALID_HANDLE_VALUE) { char _szMessage[50]; sprintf(_szMessage, "The %s file does not exist, so the datas will be taken from the Default structure!", g_szStartPrgIniFile); bStartPrg=FALSE; AfxMessageBox( _szMessage, MB_OK | MB_ICONSTOP ); } FindClose(hHandle); if (strcmp( g_stInitialData.szExeFile, g_stDefaultData.szExeFile) == 0) strcpy( g_stInitialData.szExeFile, g_stInitialData.szTempPath8); } /* ======================================================================================= Name: fn_IniData_vGetDatasFromFile Description: Get all datas saved in the .ini file Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vGetDatasFromFile( BOOL _bFirst ) { char szCompleteBinarization[10]; if (_bFirst) { GetCurrentDirectory( MAX_PATH, g_szIniFile ); if (g_szIniFile[strlen(g_szIniFile) - 1] != '\\') strcat( g_szIniFile, "\\"); strcat( g_szIniFile, C_szIniFile ); /* * set all ini data with default data */ memcpy( &g_stInitialData, &g_stDefaultData, sizeof( tdstInitialValue ) ); } /* * get the informations for name of the executable, local path, game data, rawdata, textures and default directories */ GetPrivateProfileString( "General directories", "DirNameDestBinDD3D", g_stDefaultData.szDestBinDD3D, g_stInitialData.szDestBinDD3D, MAX_PATH, g_szIniFile ); GetPrivateProfileString( "General directories", "DirNameSource", g_stDefaultData.szSource, g_stInitialData.szSource, MAX_PATH, g_szIniFile ); GetPrivateProfileString( "General directories", "DirNameDestBinRD3D", g_stDefaultData.szDestBinRD3D, g_stInitialData.szDestBinRD3D, MAX_PATH, g_szIniFile ); GetPrivateProfileString( "General directories", "DirNameDestBinDDFX", g_stDefaultData.szDestBinDDFX, g_stInitialData.szDestBinDDFX, MAX_PATH, g_szIniFile ); GetPrivateProfileString( "General directories", "DirNameDestBinRDFX", g_stDefaultData.szDestBinRDFX, g_stInitialData.szDestBinRDFX, MAX_PATH, g_szIniFile ); GetPrivateProfileString( "Mode", "Mode", g_stDefaultData.szMode, g_stInitialData.szMode, MAX_PATH, g_szIniFile ); GetPrivateProfileString( "Fix", "Fix", g_stDefaultData.szFix, g_stInitialData.szFix, MAX_PATH, g_szIniFile ); GetPrivateProfileString( "Mode", "CompleteBinarization", "1", szCompleteBinarization, 10, g_szIniFile ); // GetPrivateProfileString( "Executable File", "Executable File", g_stDefaultData.szExeFile, g_stInitialData.szExeFile, MAX_PATH, g_szIniFile ); /* * set executable name, local path... */ HANDLE hHandle; WIN32_FIND_DATA stFindFileData; memset(&stFindFileData,0,sizeof(stFindFileData)); hHandle = FindFirstFile(g_szIniFile, &stFindFileData); //return a boolean for telling if some files *.* exists in the directory or not if( hHandle == INVALID_HANDLE_VALUE) { char _szMessage[50]; sprintf(_szMessage, "The %s file does not exist, so the datas will be taken from the Default structure!", g_szIniFile); AfxMessageBox( _szMessage, MB_OK | MB_ICONSTOP ); } FindClose(hHandle); if (strcmp( g_stInitialData.szDestBinDD3D, g_stDefaultData.szDestBinDD3D) == 0) strcpy( g_stInitialData.szDestBinDD3D, g_stInitialData.szTempPath1); if (strcmp( g_stInitialData.szSource, g_stDefaultData.szSource) == 0) strcpy( g_stInitialData.szSource, g_stInitialData.szTempPath2); if (strcmp( g_stInitialData.szDestBinRD3D, g_stDefaultData.szDestBinRD3D) == 0) strcpy( g_stInitialData.szDestBinRD3D, g_stInitialData.szTempPath3); if (strcmp( g_stInitialData.szMode, g_stDefaultData.szMode) == 0) strcpy( g_stInitialData.szMode, g_stInitialData.szTempPath4); if (strcmp( g_stInitialData.szDestBinDDFX, g_stDefaultData.szDestBinDDFX) == 0) strcpy( g_stInitialData.szDestBinDDFX, g_stInitialData.szTempPath5); if (strcmp( g_stInitialData.szDestBinRDFX, g_stDefaultData.szDestBinRDFX) == 0) strcpy( g_stInitialData.szDestBinRDFX, g_stInitialData.szTempPath6); if (strcmp( g_stInitialData.szFix, g_stDefaultData.szFix) == 0) strcpy( g_stInitialData.szFix, g_stInitialData.szTempPath7); // if (strcmp( g_stInitialData.szExeFile, g_stDefaultData.szExeFile) == 0) // strcpy( g_stInitialData.szExeFile, g_stInitialData.szTempPath8); strcpy(szSource, g_stInitialData.szSource); strcpy(sSource, g_stInitialData.szSource); if (!stricmp(g_stInitialData.szMode, "Debug")) bDebug = TRUE; else bDebug = FALSE; if (!stricmp(g_stInitialData.szFix, "0")) bFix1 = FALSE; else bFix1 = TRUE; if (!stricmp(szCompleteBinarization, "0")) bDsc = FALSE; else bDsc = TRUE; /* * Get the position and the size of the main window */ fn_IniData_vGetWindowPosSize(); if (!bAuto) fn_IniData_vGetDatasFromStartFile(TRUE); } /* ======================================================================================= Name: fn_IniData_vSetMode Description: Set the entry in the .ini file for Version Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vSetMode( BOOL bSetIgnore ) { char szValue[9]; if (_access( g_szIniFile, 2) == -1) _chmod ( g_szIniFile, _S_IWRITE ); if (bSetIgnore) strcpy( szValue, "Debug"); else strcpy( szValue, "Release"); WritePrivateProfileString( "Mode", "Mode", szValue, g_szIniFile ); } /* ======================================================================================= Name: fn_IniData_vSetFix Description: Set the entry in the .ini file for Fix Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vSetFix( BOOL bFix ) { char szValue[9]; if (_access( g_szIniFile, 2) == -1) _chmod ( g_szIniFile, _S_IWRITE ); if (bFix) strcpy( szValue, "1"); else strcpy( szValue, "0"); WritePrivateProfileString( "Fix", "Fix", szValue, g_szIniFile ); } /* ======================================================================================= Name: fn_IniData_vSetCompleteBinarization Description: Change the rights of the file to write Set the entry in the .ini file for Complete binarization (=generation of dsb files) Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vSetCompleteBinarization( BOOL bDsc ) { if (_access( g_szIniFile, 2) == -1) _chmod ( g_szIniFile, _S_IWRITE ); if( bDsc ) WritePrivateProfileString( "Mode", "CompleteBinarization", "1", g_szIniFile ); else WritePrivateProfileString( "Mode", "CompleteBinarization", "0", g_szIniFile ); } /* ======================================================================================= Name: fn_IniData_vSet3DCard Description: Set the entry in the .ini file for Version Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vSet3DCard( BOOL bSetIgnore ) { char szValue[9]; if (_access( g_szIniFile, 2) == -1) _chmod ( g_szIniFile, _S_IWRITE ); if (bSetIgnore) strcpy( szValue, "D3D"); else strcpy( szValue, "DFX"); WritePrivateProfileString( "3DCard", "3DCard", szValue, g_szIniFile ); } /* ======================================================================================= Name: fn_IniData_vSetDscCreated Description: Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vSetDscCreated(BOOL bDsc) { char szValue[2]; if (_access( g_szStartPrgIniFile, 2) == -1) _chmod ( g_szStartPrgIniFile, _S_IWRITE ); if (bDsc) strcpy( szValue, "1"); else strcpy( szValue, "0"); WritePrivateProfileString( "Start", "DscCreated", szValue, g_szStartPrgIniFile ); } /* ======================================================================================= Name: fn_IniData_vGetWindowPosSize Description: Get the position andd the size of the main window from the .ini file Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vGetWindowPosSize( void ) { char szString[100]; GetPrivateProfileString( "WinPref", "Main", "", szString, 100, g_szIniFile ); fn_IniData_vStudyRect( szString, &g_stWinPosSize.stMainPos ); M_vVerifyRect( (&g_stWinPosSize.stMainPos), C_iMainWindowWidth, C_iMainWindowHeight ); } /* ======================================================================================= Name: fn_IniData_vWriteWindowPosSize Description: Save the new position and size of the main window Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vWriteWindowPosSize( void ) { char szValue[50]; RECT *p_stRect; if (_access( g_szIniFile, 2) == -1) _chmod ( g_szIniFile, _S_IWRITE ); //writing the new values for the position and size of the main window p_stRect = &g_stWinPosSize.stMainPos; sprintf( szValue, "(%4d,%4d,%4d,%4d)", p_stRect->left, p_stRect->top, p_stRect->right, p_stRect->bottom ); WritePrivateProfileString( "WinPref", "Main ", szValue, g_szIniFile ); } /* ======================================================================================= Name: fn_IniData_vStudyRect Description: Verify that the values are correct (can be integers) Author: Mihaela Tancu ======================================================================================= */ void fn_IniData_vStudyRect( char *_szString, RECT *_p_stRect ) { char *p_szValue[5], *p_szEnd; char cVal; //study if the values can be integers memset( _p_stRect, 0, sizeof( RECT ) ); if ( (p_szValue[0] = strchr(_szString, '(' )) == NULL) return; if ( (p_szValue[1] = strchr (++p_szValue[0], ',')) == NULL) return; if ( (p_szValue[2] = strchr (++p_szValue[1], ',')) == NULL) return; if ( (p_szValue[3] = strchr (++p_szValue[2], ',')) == NULL) return; p_szValue[3] ++; p_szValue[4] = _szString + strlen( _szString ); for (cVal = 0; cVal < 4; cVal ++) { while ( !isdigit(*p_szValue[cVal]) ) { if (p_szValue[cVal] == p_szValue[cVal+1]) return; p_szValue[cVal]++; } p_szEnd = p_szValue[cVal] + 1; while ( isdigit(*p_szEnd)) { if (p_szEnd == p_szValue[cVal+1]) return; p_szEnd++; } *p_szEnd = 0; } //convert to integer the ascii values _p_stRect->left = atoi( p_szValue[0] ); _p_stRect->top = atoi( p_szValue[1] ); _p_stRect->right = atoi( p_szValue[2] ); _p_stRect->bottom = atoi( p_szValue[3] ); } /* ======================================================================================= Name: fn_ComRes_vDeleteLines Description: Delete all the text in the rich edir box control Author: Mihaela Tancu ======================================================================================= */ void fn_ComRes_vDeleteLines( CRichEditCtrl *_oRichEdit) { //delete the content of the rich edit control (result and command) _oRichEdit->SetWindowText( "" ); } /* ======================================================================================= Name: fn_ComRes_vWriteLine Description: Write a line in a rich edit Author: Mihaela Tancu ======================================================================================= */ void fn_ComRes_vWriteLine( char *szLine, char cLineType ,CRichEditCtrl* _oRichEdit, CHARFORMAT* _stCharFormat) { long lOldLength; long lNewLength; long lSize; _stCharFormat->crTextColor = gs_a_xLineColor[ cLineType ]; _stCharFormat->dwEffects = 0; // write a line in the rich edit control // with different color (red or black) for Ok or for Error lOldLength = _oRichEdit->GetTextLength(); lNewLength = lOldLength + strlen( szLine ); lSize = _oRichEdit->GetLimitText(); if (lNewLength > lSize) { lSize += 10000; _oRichEdit->LimitText( lSize ); } _oRichEdit->ReplaceSel( szLine ); _oRichEdit->SetSel( lOldLength, -1 ); _oRichEdit->SetSelectionCharFormat( *_stCharFormat ); _oRichEdit->SetSel( lNewLength, lNewLength ); _oRichEdit->RedrawWindow(NULL,NULL, RDW_INVALIDATE |RDW_FRAME| RDW_UPDATENOW ); }