| 
									
										
										
										
											2018-04-21 21:24:46 +08:00
										 |  |  | #include "..\e2dtool.h"
 | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 23:07:51 +08:00
										 |  |  | e2d::Data::Data(const String & key, const String & field) | 
					
						
							|  |  |  | 	: _key(key) | 
					
						
							|  |  |  | 	, _field(field) | 
					
						
							|  |  |  | 	, _dataPath(Path::getDataPath()) | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 23:07:51 +08:00
										 |  |  | void e2d::Data::saveInt(int value) | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-17 23:07:51 +08:00
										 |  |  | 	::WritePrivateProfileString( | 
					
						
							|  |  |  | 		(LPCWSTR)_field, | 
					
						
							|  |  |  | 		(LPCWSTR)_key, | 
					
						
							|  |  |  | 		(LPCWSTR)String::parse(value), | 
					
						
							|  |  |  | 		(LPCWSTR)_dataPath | 
					
						
							|  |  |  | 	); | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 23:07:51 +08:00
										 |  |  | void e2d::Data::saveDouble(double value) | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-17 23:07:51 +08:00
										 |  |  | 	::WritePrivateProfileString( | 
					
						
							|  |  |  | 		(LPCWSTR)_field, | 
					
						
							|  |  |  | 		(LPCWSTR)_key, | 
					
						
							|  |  |  | 		(LPCWSTR)String::parse(value), | 
					
						
							|  |  |  | 		(LPCWSTR)_dataPath | 
					
						
							|  |  |  | 	); | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 23:07:51 +08:00
										 |  |  | void e2d::Data::saveBool(bool value) | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-17 23:07:51 +08:00
										 |  |  | 	::WritePrivateProfileString( | 
					
						
							|  |  |  | 		(LPCWSTR)_field, | 
					
						
							|  |  |  | 		(LPCWSTR)_key, | 
					
						
							|  |  |  | 		(value ? L"1" : L"0"), | 
					
						
							|  |  |  | 		(LPCWSTR)_dataPath | 
					
						
							|  |  |  | 	); | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 23:07:51 +08:00
										 |  |  | void e2d::Data::saveString(const String& value) | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-17 23:07:51 +08:00
										 |  |  | 	::WritePrivateProfileString( | 
					
						
							|  |  |  | 		(LPCWSTR)_field, | 
					
						
							|  |  |  | 		(LPCWSTR)_key, | 
					
						
							|  |  |  | 		(LPCWSTR)value, | 
					
						
							|  |  |  | 		(LPCWSTR)_dataPath | 
					
						
							|  |  |  | 	); | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 23:07:51 +08:00
										 |  |  | int e2d::Data::getInt(int defaultValue) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return ::GetPrivateProfileInt( | 
					
						
							|  |  |  | 		(LPCWSTR)_field, | 
					
						
							|  |  |  | 		(LPCWSTR)_key, | 
					
						
							|  |  |  | 		defaultValue, | 
					
						
							|  |  |  | 		(LPCWSTR)_dataPath | 
					
						
							|  |  |  | 	); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | double e2d::Data::getDouble(double defaultValue) | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	wchar_t temp[32] = { 0 }; | 
					
						
							| 
									
										
										
										
											2018-07-17 23:07:51 +08:00
										 |  |  | 	::GetPrivateProfileString((LPCWSTR)_field, (LPCWSTR)_key, (LPCWSTR)String::parse(defaultValue), temp, 31, (LPCWSTR)_dataPath); | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | 	return std::stof(temp); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 23:07:51 +08:00
										 |  |  | bool e2d::Data::getBool(bool defaultValue) | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-17 23:07:51 +08:00
										 |  |  | 	int nValue = ::GetPrivateProfileInt( | 
					
						
							|  |  |  | 		(LPCWSTR)_field, | 
					
						
							|  |  |  | 		(LPCWSTR)_key, | 
					
						
							|  |  |  | 		defaultValue ? 1 : 0, | 
					
						
							|  |  |  | 		(LPCWSTR)_dataPath); | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | 	return nValue != 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 23:07:51 +08:00
										 |  |  | e2d::String e2d::Data::getString(const String& defaultValue) | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	wchar_t temp[256] = { 0 }; | 
					
						
							| 
									
										
										
										
											2018-07-17 23:07:51 +08:00
										 |  |  | 	::GetPrivateProfileString( | 
					
						
							|  |  |  | 		(LPCWSTR)_field, | 
					
						
							|  |  |  | 		(LPCWSTR)_key, | 
					
						
							|  |  |  | 		(LPCWSTR)defaultValue, | 
					
						
							|  |  |  | 		temp, | 
					
						
							|  |  |  | 		255, | 
					
						
							|  |  |  | 		(LPCWSTR)_dataPath | 
					
						
							|  |  |  | 	); | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | 	return temp; | 
					
						
							| 
									
										
										
										
											2018-05-24 14:33:16 +08:00
										 |  |  | } |