| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | #include "..\etools.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static e2d::String s_sDefaultFileName = L"DefaultData.ini"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-30 01:41:29 +08:00
										 |  |  | void e2d::Data::saveInt(String key, int value, String field) | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	::WritePrivateProfileString(field, key, String::toString(value), Data::getDataFilePath()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-30 01:41:29 +08:00
										 |  |  | void e2d::Data::saveDouble(String key, double value, String field) | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	::WritePrivateProfileString(field, key, String::toString(value), Data::getDataFilePath()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-30 01:41:29 +08:00
										 |  |  | void e2d::Data::saveBool(String key, bool value, String field) | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	const wchar_t* sValue = value ? L"1" : L"0"; | 
					
						
							|  |  |  | 	::WritePrivateProfileString(field, key, sValue, Data::getDataFilePath()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-30 01:41:29 +08:00
										 |  |  | void e2d::Data::saveString(String key, String value, String field) | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	::WritePrivateProfileString(field, key, value, Data::getDataFilePath()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-30 01:41:29 +08:00
										 |  |  | int e2d::Data::getInt(String key, int defaultValue, String field) | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	return ::GetPrivateProfileInt(field, key, defaultValue, Data::getDataFilePath()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-30 01:41:29 +08:00
										 |  |  | double e2d::Data::getDouble(String key, double defaultValue, String field) | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	wchar_t temp[32] = { 0 }; | 
					
						
							|  |  |  | 	::GetPrivateProfileString(field, key, String::toString(defaultValue), temp, 31, Data::getDataFilePath()); | 
					
						
							|  |  |  | 	return std::stof(temp); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-30 01:41:29 +08:00
										 |  |  | bool e2d::Data::getBool(String key, bool defaultValue, String field) | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	int nDefaultValue = defaultValue ? 1 : 0; | 
					
						
							|  |  |  | 	int nValue = ::GetPrivateProfileInt(field, key, nDefaultValue, Data::getDataFilePath()); | 
					
						
							|  |  |  | 	return nValue != 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-30 01:41:29 +08:00
										 |  |  | e2d::String e2d::Data::getString(String key, String defaultValue, String field) | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	wchar_t temp[256] = { 0 }; | 
					
						
							|  |  |  | 	::GetPrivateProfileString(field, key, defaultValue, temp, 255, Data::getDataFilePath()); | 
					
						
							|  |  |  | 	return temp; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-30 01:41:29 +08:00
										 |  |  | void e2d::Data::setDataFileName(String fileName) | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:04 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (!fileName.isEmpty()) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		s_sDefaultFileName.clear(); | 
					
						
							|  |  |  | 		s_sDefaultFileName << fileName << L".ini"; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::String e2d::Data::getDataFilePath() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return Path::getDefaultSavePath() + s_sDefaultFileName; | 
					
						
							|  |  |  | } |