Use configured resolution for login/outgame/ingame
[ryzomcore.git] / ryzom / tools / client / client_config / client_config.cpp
blobda434171a421de44d66d4682b39e6c370991eb49
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
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.
8 //
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.
20 #include "stdafx.h"
21 #include "client_config.h"
22 #include "client_configDlg.h"
23 #include "cfg_file.h"
25 #include <nel/misc/system_utils.h>
27 using namespace NLMISC;
28 using namespace NL3D;
30 // ***************************************************************************
32 // CClientConfigApp
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!
38 //}}AFX_MSG
39 ON_COMMAND(ID_HELP, CWinApp::OnHelp)
40 END_MESSAGE_MAP()
42 // ***************************************************************************
44 // CClientConfigApp construction
46 CClientConfigApp::CClientConfigApp()
48 // Place all significant initialization in InitInstance
49 Localized = false;
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)
69 AutoConfig = true;
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)
82 MessageBoxW(NULL,
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"
89 "\t/?\t\tHelp\n"
90 "\nExemple : ryzom_configuration_r \"/gpu geforce4 ti 4600\" /cpu1500 /ram512 /vram64"
91 , CI18N::get ("uiConfigTitle"), MB_ICONEXCLAMATION|MB_OK);
96 void pump ()
98 // Display the window
99 MSG msg;
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
114 return FALSE;
117 BOOL CClientConfigApp::InitInstance()
119 HANDLE mutex = CreateMutex (NULL, false, "RyzomConfig");
120 if (mutex && GetLastError() == ERROR_ALREADY_EXISTS)
121 exit (0);
123 // Get the bitmap size
124 HRSRC hrsrc = FindResource(m_hInstance, MAKEINTRESOURCE(IDB_SLASH_SCREEN), RT_BITMAP);
125 nlassert (hrsrc);
126 HGLOBAL hBitmap = LoadResource (m_hInstance, hrsrc);
127 nlassert (hBitmap);
128 BITMAP *bitmap = (BITMAP*)LockResource(hBitmap);
129 nlassert (bitmap);
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);
135 RECT rect;
136 RECT rectDesktop;
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);
142 pump ();
146 AfxEnableControlContainer();
148 // Create drivers
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 ())
159 return FALSE;
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.
173 #ifdef _AFXDLL
174 Enable3dControls(); // Call this when using MFC in a shared DLL
175 #else
176 Enable3dControlsStatic(); // Call this when linking to MFC statically
177 #endif
179 // Init the data
180 LoadConfigFileDefault ();
182 // Init the database
183 CreateDataBase ();
185 // Parse command line for standard shell commands, DDE, file open
186 CMyCommandLineInfo cmdInfo;
187 ParseCommandLine(cmdInfo);
189 CClient_configDlg dlg;
190 m_pMainWnd = &dlg;
192 DestroyWindow (SlashScreen);
194 sint nResponse = (sint)dlg.DoModal();
195 if (nResponse == IDOK)
197 // dismissed with OK
199 else if (nResponse == IDCANCEL)
201 // dismissed with Cancel
204 catch (Exception &e)
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.
211 return FALSE;
215 // ***************************************************************************
217 void CClientConfigApp::error (const ucstring &message)
219 if (m_pMainWnd)
221 if (Localized)
223 MessageBoxW(*m_pMainWnd, (WCHAR*)message.c_str(), (WCHAR*)CI18N::get ("uiConfigTitle").c_str(), MB_OK|MB_ICONEXCLAMATION);
225 else
227 MessageBoxW(*m_pMainWnd, (WCHAR*)message.c_str(), (WCHAR*)ucstring("Ryzom Configuration").c_str(), MB_OK|MB_ICONEXCLAMATION);
230 else
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)
238 if (m_pMainWnd)
239 return MessageBoxW(*m_pMainWnd, (WCHAR*)question.c_str(), (WCHAR*)CI18N::get ("uiConfigTitle").c_str(), MB_YESNO|MB_ICONQUESTION) == IDYES;
240 else
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)
248 CString str;
249 str.LoadString (res);
250 return (const char*)str;
253 // ***************************************************************************
255 CString GetString (uint res)
257 CString str;
258 str.LoadString (res);
259 return str;
262 // ***************************************************************************
263 void setWindowText(HWND hwnd, LPCWSTR lpText)
265 if (CSystemUtils::supportUnicode())
267 SetWindowTextW(hwnd, lpText);
269 else
271 ucstring text((const ucchar *) lpText);
272 SetWindowTextA(hwnd, (LPCTSTR) text.toString().c_str());