Exemplo n.º 1
0
// Fetch the map file full path name.
HANDLE LocationDialog::openMapFile(char* mapName)
{
	HANDLE hMap;
	TCHAR fileName[MAX_PATH];
	int len;

	// Get subdir containing this plugin.
	GetModuleFileName(hInstance, fileName, MAX_PATH);

	// Append subdir string containing maps.
	TCHAR *slash = _tcsrchr(fileName, '\\');
	if (slash) {
		_tcscpy(slash, SGEOLOC);
	} else {
		// If the plugin filename contains no path information, look in plugcfg.
		_tcscpy(fileName,theInterface->GetDir(APP_PLUGCFG_DIR));
		len = _tcslen(fileName);
		if (len) {
			if (_tcscmp(&fileName[len-1],_T("\\")))
				_tcscat(fileName,_T("\\"));
		}
	}

	_tcscat(fileName,mapName);
	hMap = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ, NULL,
						OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
	if (hMap == INVALID_HANDLE_VALUE) {
		// If that fails, look in the MaxStart dir.
		_tcscpy(fileName,theInterface->GetDir(APP_MAXSTART_DIR));
		len = _tcslen(fileName);
		if (len) {
			if (_tcscmp(&fileName[len-1],_T("\\")))
				_tcscat(fileName,_T("\\"));
			_tcscat(fileName, GEOLOC);
		}   
		_tcscat(fileName,mapName);
		hMap = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ, NULL,
							OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
		if (hMap == INVALID_HANDLE_VALUE) {
			// If THAT fails, look beneath the main exe dir.
			_tcscpy(fileName,theInterface->GetDir(APP_MAXROOT_DIR));
			len = _tcslen(fileName);
			if (len) {
				if (_tcscmp(&fileName[len-1],_T("\\")))
					_tcscat(fileName,_T("\\"));
			}
			_tcscat(fileName, GEOLOC);
			_tcscat(fileName,mapName);
			hMap = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ, NULL,
							OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
			if (hMap == INVALID_HANDLE_VALUE) {
				// Last try: If THAT fails, look IN the main exe dir.
				_tcscpy(fileName,theInterface->GetDir(APP_MAXROOT_DIR));
				len = _tcslen(fileName);
				if (len) {
					if (_tcscmp(&fileName[len-1],_T("\\")))
						_tcscat(fileName,_T("\\"));
				}
				_tcscat(fileName,mapName);
				hMap = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ, NULL,
								OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
			}
		}
	}

	return hMap;
}