1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // client_config.cpp : Defines the class behaviors for the application.
21 #include "client_config.h"
22 #include "client_configDlg.h"
25 #include <nel/misc/system_utils.h>
27 using namespace NLMISC
;
30 // ***************************************************************************
34 BEGIN_MESSAGE_MAP(CClientConfigApp
, CWinApp
)
35 //{{AFX_MSG_MAP(CClientConfigApp)
36 // NOTE - the ClassWizard will add and remove mapping macros here.
37 // DO NOT EDIT what you see in these blocks of generated code!
39 ON_COMMAND(ID_HELP
, CWinApp::OnHelp
)
42 // ***************************************************************************
44 // CClientConfigApp construction
46 CClientConfigApp::CClientConfigApp()
48 // Place all significant initialization in InitInstance
52 // ***************************************************************************
54 // The one and only CClientConfigApp object
56 CClientConfigApp theApp
;
58 // ***************************************************************************
60 // CClientConfigApp initialization
62 class CMyCommandLineInfo
: public CCommandLineInfo
64 virtual void ParseParam( LPCTSTR lpszParam
, BOOL bFlag
, BOOL bLast
)
66 /* Yoyo: Disable AutoConfig cause don't work on every config
67 if ((strnicmp (lpszParam, "auto_config", 3) == 0) && bFlag)
71 if ((strnicmp (lpszParam, "gpu", 3) == 0) && bFlag)
72 GLRenderer = lpszParam+3;
73 if ((strnicmp (lpszParam, "cpu", 3) == 0) && bFlag)
74 CPUFrequency = atoi (lpszParam+3);
75 if ((strnicmp (lpszParam, "ram", 3) == 0) && bFlag)
76 SystemMemory = 1024*1024*atoi (lpszParam+3);
77 if ((strnicmp (lpszParam, "vram", 4) == 0) && bFlag)
78 VideoMemory = 1024*1024*atoi (lpszParam+4);
79 if ((strnicmp (lpszParam, "hwsb", 4) == 0) && bFlag)
80 HardwareSoundBuffer = atoi (lpszParam+4);
81 if ((strcmp (lpszParam, "?") == 0) && bFlag)
83 "\t/gpuGPUNAME\t\tSet GPU name to GPUNAME\n"
84 "\t/cpuCPUFREQUENCY\t\tSet CPU frequency to CPUFREQENCY\n"
85 "\t/ramAMOUNTRAM\t\tSet the amount of ram to AMOUNTRAM\n"
86 "\t/vramAMOUNTVRAM\t\tSet the amount of vram to AMOUNTVRAM\n"
87 "\t/hwsbHARDWARESOUNDBUFFER\t\tSet the number of hardware sound buffer\n"
88 "\t/auto_config\t\tAuto configuration mode\n"
90 "\nExemple : ryzom_configuration_r \"/gpu geforce4 ti 4600\" /cpu1500 /ram512 /vram64"
91 , CI18N::get ("uiConfigTitle"), MB_ICONEXCLAMATION|MB_OK);
100 while (PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
))
102 TranslateMessage(&msg
);
103 DispatchMessage(&msg
);
107 INT_PTR CALLBACK
MyDialogProc(
108 HWND hwndDlg
, // handle to dialog box
109 UINT uMsg
, // message
110 WPARAM wParam
, // first message parameter
111 LPARAM lParam
// second message parameter
117 BOOL
CClientConfigApp::InitInstance()
119 HANDLE mutex
= CreateMutex (NULL
, false, "RyzomConfig");
120 if (mutex
&& GetLastError() == ERROR_ALREADY_EXISTS
)
123 // Get the bitmap size
124 HRSRC hrsrc
= FindResource(m_hInstance
, MAKEINTRESOURCE(IDB_SLASH_SCREEN
), RT_BITMAP
);
126 HGLOBAL hBitmap
= LoadResource (m_hInstance
, hrsrc
);
128 BITMAP
*bitmap
= (BITMAP
*)LockResource(hBitmap
);
130 int width
= bitmap
->bmWidth
;
131 int height
= bitmap
->bmHeight
;
133 // Look the command line to see if we have a cookie and a addr
134 HWND SlashScreen
= CreateDialog (m_hInstance
, MAKEINTRESOURCE(IDD_SLASH_SCREEN
), NULL
, MyDialogProc
);
137 GetWindowRect (SlashScreen
, &rect
);
138 GetWindowRect (GetDesktopWindow (), &rectDesktop
);
139 SetWindowPos (SlashScreen
, HWND_TOP
, (rectDesktop
.right
-rectDesktop
.left
-width
)/2, (rectDesktop
.bottom
-rectDesktop
.top
-height
)/2, width
, height
, 0);
140 ShowWindow (SlashScreen
, SW_SHOW
);
146 AfxEnableControlContainer();
149 IDriver
*glDriver
= CDRU::createGlDriver();
150 IDriver
*d3dDriver
= CDRU::createD3DDriver();
152 // Get some information about the system
153 RegisterVideoModes (0, glDriver
);
154 RegisterVideoModes (1, d3dDriver
);
155 GetSystemInformation (d3dDriver
);
157 // Load the config file
158 if (!LoadConfigFile ())
161 // Add search pathes for *.uxt
162 // Local search path ?
163 if (::GetIntTestConfig())
164 CPath::addSearchPath ("translation/work", true, false);
165 CPath::addSearchPath ("patch", true, false);
166 CPath::addSearchPath ("data", true, false);
168 // Standard initialization
169 // If you are not using these features and wish to reduce the size
170 // of your final executable, you should remove from the following
171 // the specific initialization routines you do not need.
174 Enable3dControls(); // Call this when using MFC in a shared DLL
176 Enable3dControlsStatic(); // Call this when linking to MFC statically
180 LoadConfigFileDefault ();
185 // Parse command line for standard shell commands, DDE, file open
186 CMyCommandLineInfo cmdInfo
;
187 ParseCommandLine(cmdInfo
);
189 CClient_configDlg dlg
;
192 DestroyWindow (SlashScreen
);
194 sint nResponse
= (sint
)dlg
.DoModal();
195 if (nResponse
== IDOK
)
199 else if (nResponse
== IDCANCEL
)
201 // dismissed with Cancel
206 error ((ucstring
)e
.what());
209 // Since the dialog has been closed, return FALSE so that we exit the
210 // application, rather than start the application's message pump.
215 // ***************************************************************************
217 void CClientConfigApp::error (const ucstring
&message
)
223 MessageBoxW(*m_pMainWnd
, (WCHAR
*)message
.c_str(), (WCHAR
*)CI18N::get ("uiConfigTitle").c_str(), MB_OK
|MB_ICONEXCLAMATION
);
227 MessageBoxW(*m_pMainWnd
, (WCHAR
*)message
.c_str(), (WCHAR
*)ucstring("Ryzom Configuration").c_str(), MB_OK
|MB_ICONEXCLAMATION
);
231 MessageBoxW(NULL
, (WCHAR
*)message
.c_str(), (WCHAR
*)ucstring("Ryzom Configuration").c_str(), MB_OK
|MB_ICONEXCLAMATION
);
234 // ***************************************************************************
236 bool CClientConfigApp::yesNo (const ucstring
&question
)
239 return MessageBoxW(*m_pMainWnd
, (WCHAR
*)question
.c_str(), (WCHAR
*)CI18N::get ("uiConfigTitle").c_str(), MB_YESNO
|MB_ICONQUESTION
) == IDYES
;
241 return MessageBoxW(NULL
, (WCHAR
*)question
.c_str(), (WCHAR
*)CI18N::get ("uiConfigTitle").c_str(), MB_YESNO
|MB_ICONQUESTION
) == IDYES
;
244 // ***************************************************************************
246 std::string
GetNeLString (uint res
)
249 str
.LoadString (res
);
250 return (const char*)str
;
253 // ***************************************************************************
255 CString
GetString (uint res
)
258 str
.LoadString (res
);
262 // ***************************************************************************
263 void setWindowText(HWND hwnd
, LPCWSTR lpText
)
265 if (CSystemUtils::supportUnicode())
267 SetWindowTextW(hwnd
, lpText
);
271 ucstring
text((const ucchar
*) lpText
);
272 SetWindowTextA(hwnd
, (LPCTSTR
) text
.toString().c_str());