DragonNest/Client/DnLauncher3/DnOptionData.cpp
2024-12-19 09:48:26 +08:00

247 lines
6.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "stdafx.h"
#include "DnOptionData.h"
//////////////////////////////////////////////////////////////////////////
// CDnOptionData Class
//////////////////////////////////////////////////////////////////////////
CDnOptionData::CDnOptionData()
: m_nWidth( 1280 )
, m_nHeight( 800 )
, m_nGraphicQuality( 0 )
, m_nTextureQuality( 0 )
, m_bWindow( FALSE )
, m_bVSync( FALSE )
, m_bAutoGameStart(FALSE)
, m_nLanguage(0)
#ifdef _USE_PARTITION_SELECT
, m_nSelectChannelNum( 0 )
, m_nSelectPartitionId( 0 )
#endif // _USE_PARTITION_SELECT
#ifdef _USE_MULTILANGUAGE
, m_nLanguageID( 0 )
#endif // _USE_MULTILANGUAGE
{
}
CDnOptionData::~CDnOptionData()
{
m_vecOptionData.clear();
}
CDnOptionData& CDnOptionData::GetInstance()
{
static CDnOptionData global;
return global;
}
BOOL CDnOptionData::SaveConfigOption( HWND hWnd )
{
FILE *stream = NULL;
TCHAR szFilename[MAX_PATH] = {0,};
TCHAR szPath[_MAX_PATH]={0,};
SHGetSpecialFolderPath( hWnd, szPath, CSIDL_PERSONAL, 0 );
swprintf_s( szFilename, L"%s\\DragonNest", szPath );
_wmkdir( szFilename );
swprintf_s( szFilename, L"%s\\DragonNest\\Config", szPath );
_wmkdir( szFilename );
swprintf_s( szFilename, L"%s\\DragonNest\\Config\\%s", szPath, L"Config.ini" );
CString szInstallPath = szFilename;
if( _wfopen_s( &stream, szInstallPath.GetString() , L"w+" ) != 0 )
return FALSE;
fseek( stream, 0L, SEEK_SET );
fprintf( stream, " Width %d\n ", m_nWidth );
fprintf( stream, "Height %d\n ", m_nHeight );
fprintf( stream, "GraphicQuality %d\n ", m_nGraphicQuality );
fprintf( stream, "TextureQuality %d\n ", m_nTextureQuality );
fprintf( stream, "WindowMode %d\n ", m_bWindow ? 1 : 0 );
fprintf(stream, "VSync %d\n ", m_bVSync ? 1 : 0);
fprintf(stream, "Language %d\n ", m_nLanguage);
#ifdef _USE_MULTILANGUAGE
fprintf( stream, "LanguageID %d\n ", m_nLanguageID );
#endif // _USE_MULTILANGUAGE
std::vector<stOptionData>::iterator iter = m_vecOptionData.begin();
for( ; iter != m_vecOptionData.end(); iter++ )
fprintf( stream, "%s %s\n ", (*iter).m_strOptionField.c_str(), (*iter).m_strOptionValue.c_str() );
fclose( stream );
return TRUE;
}
BOOL CDnOptionData::LoadConfigOption( HWND hWnd )
{
FILE *stream = NULL;
char szString[256]={0,};
TCHAR szFilename[MAX_PATH]={0,};
TCHAR szPath[_MAX_PATH]={0,};
SHGetSpecialFolderPath( hWnd, szPath, CSIDL_PERSONAL, 0 );
swprintf_s( szFilename, L"%s\\DragonNest", szPath );
_wmkdir( szFilename );
swprintf_s( szFilename, L"%s\\DragonNest\\Config", szPath );
_wmkdir( szFilename );
swprintf_s( szFilename, L"%s\\DragonNest\\Config\\%s", szPath, L"Config.ini" );
CString szInstallPath = szFilename;
if( _wfopen_s( &stream, szInstallPath.GetString(), L"r+" ) != 0 )
return FALSE;
m_vecOptionData.clear();
fseek( stream, 0L, SEEK_SET );
for( int i = 0; ;i++ )
{
int numRead = fscanf_s( stream, "%s", szString, 256 );
if( numRead != 1 ) break;
if( !SetOptionValue( stream , szString ) ) // <20>ػ<EFBFBD><D8BB><EFBFBD>, ǰ<><C7B0>, â<><C3A2><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ɼ<EFBFBD><C9BC><EFBFBD> <20>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
{
stOptionData OptionData;
OptionData.m_strOptionField = szString;
fscanf_s( stream, "%s", szString, 256 );
OptionData.m_strOptionValue = szString;
m_vecOptionData.push_back( OptionData );
}
}
fclose( stream );
if( m_nWidth < 1024 )
{
m_nWidth = 1024;
m_nHeight = 768;
}
return TRUE;
}
#ifdef _USE_PARTITION_SELECT
BOOL CDnOptionData::SavePartitionOption( HWND hWnd )
{
FILE *stream = NULL;
TCHAR szFilename[MAX_PATH] = {0,};
CString szInstallPath = DNPATCHINFO.GetClientPath();
TCHAR szPath[_MAX_PATH]={0,};
SHGetSpecialFolderPath( hWnd, szPath, CSIDL_PERSONAL, 0 );
swprintf_s( szFilename, L"%s\\DragonNest", szPath );
_wmkdir( szFilename );
swprintf_s( szFilename, L"%s\\DragonNest\\Config", szPath );
_wmkdir( szFilename );
swprintf_s( szFilename, L"%s\\DragonNest\\Config\\%s", szPath, L"Partition.ini" );
szInstallPath = szFilename;
if( _wfopen_s( &stream, szInstallPath.GetString(), L"w+" ) != 0 )
return FALSE;
fseek( stream, 0L, SEEK_SET );
fprintf( stream, " SelectChannelNum %d\n ", m_nSelectChannelNum );
fprintf( stream, "SelectPartitionId %d\n ", m_nSelectPartitionId );
fclose( stream );
return TRUE;
}
BOOL CDnOptionData::LoadPartitionOption( HWND hWnd )
{
FILE *stream = NULL;
char szString[256]={0,};
TCHAR szFilename[MAX_PATH]={0,};
CString szInstallPath = DNPATCHINFO.GetClientPath();
TCHAR szPath[_MAX_PATH]={0,};
SHGetSpecialFolderPath( hWnd, szPath, CSIDL_PERSONAL, 0 );
swprintf_s( szFilename, L"%s\\DragonNest", szPath );
_wmkdir( szFilename );
swprintf_s( szFilename, L"%s\\DragonNest\\Config", szPath );
_wmkdir( szFilename );
swprintf_s( szFilename, L"%s\\DragonNest\\Config\\%s", szPath, L"Partition.ini" );
szInstallPath = szFilename;
if( _wfopen_s( &stream, szInstallPath.GetString(), L"r+" ) != 0 )
return FALSE;
fseek( stream, 0L, SEEK_SET );
fscanf_s( stream, "%s", szString, 256 );
if( strcmp("SelectChannelNum",szString ) == 0 )
fscanf_s( stream, "%d", &(m_nSelectChannelNum) );
fscanf_s( stream, "%s", szString, 256 );
if( strcmp("SelectPartitionId",szString ) == 0 )
fscanf_s( stream, "%d", &(m_nSelectPartitionId) );
fclose( stream );
return TRUE;
}
#endif // _USE_PARTITION_SELECT
BOOL CDnOptionData::SetOptionValue( FILE *stream, char * szString )
{
if( !szString)
return false;
if( strcmp( "Width", szString ) == 0 )
{
fscanf_s( stream, "%d", &(m_nWidth) );
return TRUE;
}
else if( strcmp( "Height", szString ) == 0 )
{
fscanf_s( stream, "%d", &(m_nHeight) );
return TRUE;
}
else if( strcmp( "GraphicQuality", szString ) == 0 )
{
fscanf_s( stream, "%d", &(m_nGraphicQuality) );
return TRUE;
}
else if( strcmp( "TextureQuality", szString ) == 0 )
{
fscanf_s( stream, "%d", &(m_nTextureQuality) );
return TRUE;
}
else if( strcmp( "WindowMode", szString ) == 0 )
{
int iWindowMode = 0;
fscanf_s( stream, "%d", &(iWindowMode) );
m_bWindow = iWindowMode?true:false;
return TRUE;
}
else if( strcmp( "VSync", szString ) == 0 )
{
int iVSync = 0;
fscanf_s( stream, "%d", &(iVSync) );
m_bVSync = iVSync?true:false;
return TRUE;
}
else if (strcmp("Language", szString) == 0)
{
fscanf_s(stream, "%d", &(m_nLanguage));
}
#ifdef _USE_MULTILANGUAGE
else if( strcmp( "LanguageID", szString ) == 0 )
{
fscanf_s( stream, "%d", &(m_nLanguageID) );
DNPATCHINFO.SetLanguageParamByLanguageID( m_nLanguageID );
DNPATCHINFO.SetLocaleGuidePage();
return TRUE;
}
#endif // _USE_MULTILANGUAGE
return FALSE;
}