Use configured resolution for login/outgame/ingame
[ryzomcore.git] / nelns / login_system / nel_launcher_windows_ext / Configuration.cpp
blob88b0d854a642c75cd7f43a52ca4804695e697eb1
1 // Configuration.cpp: implementation of the CConfiguration class.
2 //
3 //////////////////////////////////////////////////////////////////////
5 #include "stdafx.h"
6 #include "nel_launcher.h"
7 #include "Configuration.h"
8 #include <nel/misc/debug.h>
10 #ifdef _DEBUG
11 #undef THIS_FILE
12 static char THIS_FILE[]=__FILE__;
13 #define new DEBUG_NEW
14 #endif
16 #define CONFIG_FILE "nel_launcher.cfg"
18 #define KEY_HOST "StartupHost"
19 #define KEY_VERSION "Version"
20 #define KEY_URL_MAIN "StartupPage"
21 #define KEY_URL_RN "RNPage"
22 #define KEY_URL_NEWS "NewsPage"
23 #define KEY_APPLICATION "Application"
25 //////////////////////////////////////////////////////////////////////
26 // Construction/Destruction
27 //////////////////////////////////////////////////////////////////////
29 CConfiguration::CConfiguration()
33 CConfiguration::~CConfiguration()
37 BOOL CConfiguration::Load()
39 CFile f;
40 DWORD dwSize;
41 CString csBuffer;
42 CString csValue;
44 if(f.Open(CONFIG_FILE, CFile::modeRead))
46 nlinfo("Opening configuration file...");
48 dwSize = f.GetLength();
49 f.Read(csBuffer.GetBuffer(dwSize), dwSize);
50 csBuffer.ReleaseBuffer();
51 f.Close();
53 // Reading the configuration file version
54 GetValue(csBuffer, KEY_VERSION, csValue);
55 NLMISC::fromString(csValue, m_dVersion);
56 nlinfo("Config' version %s", csValue);
58 if(m_dVersion < APP.m_dVersion)
60 nlinfo("Launcher version > config version, loading config from resources...");
61 LoadFromResource();
63 else
65 nlinfo("Launcher version <= config version, loading config from configuration file...");
67 HINSTANCE hInst = (HINSTANCE)GetModuleHandle(NULL);
69 if(!GetValue(csBuffer, KEY_HOST, m_csHost))
70 m_csHost.LoadString(hInst, IDS_HOST);
72 if(!GetValue(csBuffer, KEY_URL_MAIN, m_csUrlMain))
73 m_csUrlMain.LoadString(hInst, IDS_URLMAIN);
75 if(!GetValue(csBuffer, KEY_URL_RN, m_csUrlRN))
76 m_csUrlRN.LoadString(hInst, IDS_URLRN);
78 if(!GetValue(csBuffer, KEY_URL_NEWS, m_csUrlNews))
79 m_csUrlNews.LoadString(hInst, IDS_URLNEWS);
81 if(!GetValue(csBuffer, KEY_APPLICATION, m_csApp, 0))
82 m_csApp.LoadString(hInst, IDS_APPLICATION_APP);
84 if(!GetValue(csBuffer, KEY_APPLICATION, m_csExe, 1))
85 m_csExe.LoadString(hInst, IDS_APPLICATION_EXE);
87 if(!GetValue(csBuffer, KEY_APPLICATION, m_csBasePath, 2))
88 m_csBasePath.LoadString(hInst, IDS_APPLICATION_BASEPATH);
90 if(!GetValue(csBuffer, KEY_APPLICATION, m_csAppBasePath, 3))
91 m_csAppBasePath.LoadString(hInst, IDS_APPLICATION_APPBASEPATH);
94 else
96 // No configuration file is available
97 // Take configuration from exe resource
98 nlinfo("No configuration file found, loading config from resources...");
99 LoadFromResource();
101 nlinfo("Host %s", m_csHost);
102 nlinfo("URL main page %s", m_csUrlMain);
103 nlinfo("URL 'release notes' %s", m_csUrlRN);
104 nlinfo("URL 'news' %s", m_csUrlNews);
105 nlinfo("App %s", m_csApp);
106 nlinfo("Exe %s", m_csExe);
107 nlinfo("BasePath %s", m_csBasePath);
108 nlinfo("AppBasePath %s", m_csAppBasePath);
110 return TRUE;
113 void CConfiguration::LoadFromResource()
115 HINSTANCE hInst = (HINSTANCE)GetModuleHandle(NULL);
117 m_csHost.LoadString(hInst, IDS_HOST);
118 m_csUrlMain.LoadString(hInst, IDS_URLMAIN);
119 m_csUrlRN.LoadString(hInst, IDS_URLRN);
120 m_csUrlNews.LoadString(hInst, IDS_URLNEWS);
121 m_csApp.LoadString(hInst, IDS_APPLICATION_APP);
122 m_csExe.LoadString(hInst, IDS_APPLICATION_EXE);
123 m_csBasePath.LoadString(hInst, IDS_APPLICATION_BASEPATH);
124 m_csAppBasePath.LoadString(hInst, IDS_APPLICATION_APPBASEPATH);
125 m_csAppBasePath.TrimRight();
128 BOOL CConfiguration::GetValue(CString& csBuffer, CString csKey, CString& csValue, int iIndex)
130 int iOffset1 = 0;
131 int iOffset2;
132 CString csRow;
133 CString csKeyTmp;
135 while((iOffset2 = csBuffer.Find('\n', iOffset1)) != -1)
137 csRow = csBuffer.Mid(iOffset1, iOffset2 - iOffset1);
138 if(csRow.Right(1) == "\r")
139 csRow = csRow.Left(csRow.GetLength()-1);
140 csRow.TrimLeft();
141 csRow.TrimRight();
143 if(csRow.Left(2) != "//" && csRow.GetLength() > 0 && csRow.Find('=') != -1)
145 csKeyTmp = csRow.Mid(0, csRow.Find('='));
146 csKeyTmp.TrimLeft();
147 csKeyTmp.TrimRight();
148 if(!csKeyTmp.CompareNoCase(csKey))
150 // This is the key we're looking for
151 csValue = csRow.Mid(csRow.Find('=')+1);
152 csValue.TrimLeft();
153 csValue.TrimRight();
154 if(csValue.Left(1) == "\"")
155 csValue.Delete(0);
156 if(csValue.Right(1) == ";")
157 csValue = csValue.Left(csValue.GetLength()-1);
158 if(csValue.Right(1) == "\"")
159 csValue = csValue.Left(csValue.GetLength()-1);
161 if(csValue.Left(1) == "{")
163 // This is a key is multiple values, delete '{' and '}'
164 csValue.Delete(0);
165 csValue.TrimRight();
166 if(csValue.Right(1) == "}")
167 csValue = csValue.Left(csValue.GetLength()-1);
168 csValue.TrimLeft();
169 csValue.TrimRight();
171 for(int i = 0; i <= iIndex; i++)
173 if(csValue.IsEmpty())
174 return FALSE;
176 if(csValue.Left(1) == "\"")
177 csValue.Delete(0);
178 if(csValue.Find('"') != -1)
180 if(i == iIndex)
182 csValue = csValue.Left(csValue.Find('\"'));
183 return TRUE;
185 csValue = csValue.Mid(csValue.Find('\"')+1);
186 csValue.TrimLeft();
187 if(csValue.Left(1) == ",")
188 csValue.Delete(0);
189 csValue.TrimLeft();
192 return FALSE;
194 return TRUE;
197 iOffset1 = iOffset2 + 1;
199 return FALSE;