예제 #1
0
void RasterTerrain::OpenTerrain(void)
{
  TCHAR  szFile[MAX_PATH] = TEXT("\0");

  GetRegistryString(szRegistryTerrainFile, szFile, MAX_PATH);

  char zfilename[MAX_PATH];

  ExpandLocalPath(szFile);

  unicode2ascii(szFile, zfilename, MAX_PATH);

  if (strlen(zfilename)==0) {
    static TCHAR  szMapFile[MAX_PATH] = TEXT("\0");
    GetRegistryString(szRegistryMapFile, szMapFile, MAX_PATH);
    ExpandLocalPath(szMapFile);
    _tcscpy(szFile,szMapFile);
    _tcscat(szFile,TEXT("/terrain.jp2"));
    unicode2ascii(szFile, zfilename, MAX_PATH);
  }

  // TODO code: Check locking, especially when reloading a file.
  // TODO bug: Fix cache method

  CreateTerrainMap(zfilename);
}
예제 #2
0
void
ReadWayPoints(WayPointList &way_points, RasterTerrain &terrain)
{
  StartupStore(TEXT("ReadWayPoints\n"));

  TCHAR szFile1[MAX_PATH] = TEXT("\0");
  TCHAR szFile2[MAX_PATH] = TEXT("\0");
  bool file_embedded = false;

  // JMW TODO protect with mutex (whole waypoint list class)

  CloseWayPoints(way_points);

  GetRegistryString(szRegistryWayPointFile, szFile1, MAX_PATH);
  SetRegistryString(szRegistryWayPointFile, TEXT("\0"));

  if (_tcslen(szFile1)>0) {
    ExpandLocalPath(szFile1);
  } else {
    file_embedded = true;
    GetRegistryString(szRegistryMapFile, szFile1, MAX_PATH);
    ExpandLocalPath(szFile1);
    _tcscat(szFile1, TEXT("/"));
    _tcscat(szFile1, TEXT("waypoints.xcw"));
  }

  globalFileNum = 0;
  if (ReadWayPointFile(szFile1, way_points, terrain)) {
    // read OK, so set the registry to the actual file name
    if (!file_embedded) {
      printf("save\n");
      ContractLocalPath(szFile1);
      SetRegistryString(szRegistryWayPointFile, szFile1);
    }
  } else {
    StartupStore(TEXT("No waypoint file 1\n"));
  }

  // read additional waypoint file

  GetRegistryString(szRegistryAdditionalWayPointFile, szFile2, MAX_PATH);

  SetRegistryString(szRegistryAdditionalWayPointFile, TEXT("\0"));

  if (_tcslen(szFile2)>0){
    ExpandLocalPath(szFile2);

    globalFileNum = 1;
    if (ReadWayPointFile(szFile2, way_points, terrain)) {
      // read OK, so set the registry to the actual file name
      ContractLocalPath(szFile2);
      SetRegistryString(szRegistryAdditionalWayPointFile, szFile2);
    } else {
      StartupStore(TEXT("No waypoint file 2\n"));
    }
  }
}
예제 #3
0
void
ReadAirspace(AirspaceDatabase &airspace_database, RasterTerrain *terrain)
{
  TCHAR tpath[MAX_PATH];

  // TODO bug: add exception handler to protect parser code against chrashes
  // TODO bug: second file should be opened even if first was not okay

  // Read the airspace filenames from the registry
  GetRegistryString(szRegistryAirspaceFile, tpath, MAX_PATH);
  if (tpath[0] != 0) {
    ExpandLocalPath(tpath);

    char path[MAX_PATH];
    unicode2ascii(tpath, path, sizeof(path));

    if (!ReadAirspace(airspace_database, path))
      StartupStore(TEXT("No airspace file 1\n"));
  } else {
    // TODO feature: airspace in xcm files should be a feature
    /*
    static TCHAR  szMapFile[MAX_PATH] = TEXT("\0");
    GetRegistryString(szRegistryMapFile, szMapFile, MAX_PATH);
    ExpandLocalPath(szMapFile);
    wcscat(szMapFile,TEXT("/"));
    wcscat(szMapFile,TEXT("airspace.txt"));
    unicode2ascii(szMapFile, zfilename, MAX_PATH);
    fp  = zzip_fopen(zfilename, "rt");
    */
  }

  GetRegistryString(szRegistryAdditionalAirspaceFile, tpath, MAX_PATH);
  if (tpath[0] != 0) {
    ExpandLocalPath(tpath);

    char path[MAX_PATH];
    unicode2ascii(tpath, path, sizeof(path));

    if (!ReadAirspace(airspace_database, path))
      StartupStore(TEXT("No airspace file 2\n"));
  }

  // Calculate the airspace boundaries
  FindAirspaceAreaBounds(airspace_database);
  FindAirspaceCircleBounds(airspace_database);

  if (terrain != NULL) {
    terrain->Lock();
    airspace_database.UpdateAGL(*terrain);
    terrain->Unlock();
  }
}
예제 #4
0
void
WaypointWriteFiles(WayPointList &way_points,
                   const SETTINGS_COMPUTER &settings_computer)
{
  // JMW TODO protect with mutex (whole waypoint list class)

  TCHAR szFile1[MAX_PATH] = TEXT("\0");
  TCHAR szFile2[MAX_PATH] = TEXT("\0");

  FILE *fp=NULL;

  GetRegistryString(szRegistryWayPointFile, szFile1, MAX_PATH);
  ExpandLocalPath(szFile1);

  if (_tcslen(szFile1)>0) {
    fp = _tfopen(szFile1, TEXT("wb"));
  } else {
    LocalPath(szFile1);
    _tcscat(szFile1,TEXT("\\waypoints1.dat"));
    fp = _tfopen(szFile1, TEXT("wb"));
  }

  if(fp != NULL) {
    globalFileNum = 0;
    WriteWayPointFile(way_points, fp, settings_computer);
    fprintf(fp,"\r\n");
    fclose(fp);
    fp = NULL;
  }

  GetRegistryString(szRegistryAdditionalWayPointFile, szFile2, MAX_PATH);
  ExpandLocalPath(szFile2);

  if (_tcslen(szFile2)>0) {
    fp = _tfopen(szFile2, TEXT("wb"));
  } else {
    LocalPath(szFile2);
    _tcscat(szFile2,TEXT("\\waypoints2.dat"));
    fp = _tfopen(szFile2, TEXT("wb"));
  }

  if(fp != NULL) {
    globalFileNum = 1;
    WriteWayPointFile(way_points, fp, settings_computer);
    fprintf(fp,"\r\n");
    fclose(fp);
    fp = NULL;
  }

}
예제 #5
0
void OpenAirfieldDetails() {
  TCHAR zfilename[MAX_PATH];

  zAirfieldDetails = NULL;

  _tcscpy(szAirfieldDetailsFile,szAirfieldFile);

  if (_tcslen(szAirfieldDetailsFile)>0) {
    ExpandLocalPath(szAirfieldDetailsFile);
    _tcscpy(zfilename, szAirfieldDetailsFile);
    _tcscpy(szAirfieldFile,_T(""));
  } else {
	#if 0
	LocalPath(zfilename, _T(KD_WAYPOINTS));
	_tcscat(zfilename, _T(DIRSEP));
	_tcscat(zfilename, _T(LKF_AIRFIELDS));
	#else
	_tcscpy(zfilename, _T(""));
	#endif
  }
  if (_tcslen(zfilename)>0) {
    StartupStore(_T(". open AirfieldFile <%s> %s"), zfilename, NEWLINE);
    zAirfieldDetails = openzip(zfilename, "rb");
  }
};
예제 #6
0
/**
 * Writes all missing translations found during runtime to a language file
 * in the data dir
 */
void WriteMissingTranslations() {
  std::map<TCHAR*, TCHAR*, lessTCHAR<TCHAR*> >::iterator
    s=unusedTranslations.begin(),e=unusedTranslations.end();

  TCHAR szFile1[MAX_PATH] = TEXT("%LOCAL_PATH%\\\\localization_todo.xcl\0");
  FILE *fp=NULL;

  ExpandLocalPath(szFile1);
  fp  = _tfopen(szFile1, TEXT("w+"));

  if (fp != NULL) {
    while (s != e) {
      TCHAR* p = (s->second);
      if (p) {
        while (*p) {
          if (*p != _T('\n')) {
            fwprintf(fp, TEXT("%c"), *p);
          } else {
            fwprintf(fp, TEXT("\\n"));
          }
          p++;
        }
        fwprintf(fp, TEXT("=\n"));
      }
      s++;
    }
    fclose(fp);
  }
}
예제 #7
0
bool
Profile::GetPath(const char *key, TCHAR *value)
{
  TCHAR buffer[MAX_PATH];
  if (!Get(key, buffer, ARRAY_SIZE(buffer)))
      return false;

  ExpandLocalPath(value, buffer);
  return true;
}
예제 #8
0
/**
 * Reads the selected LanguageFile into the cache
 */
void ReadLanguageFile() {
  StartupStore(TEXT("Loading language file\n"));

  TCHAR szFile1[MAX_PATH] = TEXT("\0");
  FILE *fp=NULL;

  // Read the language filename from the registry
  GetRegistryString(szRegistryLanguageFile, szFile1, MAX_PATH);
  ExpandLocalPath(szFile1);

  // Reset filename in registry in case language
  // loading crashes the application
  SetRegistryString(szRegistryLanguageFile, TEXT("\0"));

  // If the language file is not set use the default one
  if (_tcslen(szFile1)==0) {
    _tcscpy(szFile1,TEXT("default.xcl"));
  }

  // Open the language file
  fp  = _tfopen(szFile1, TEXT("rt"));

  // Return if file error
  if (fp == NULL)
    return;

  // TODO code: Safer sizes, strings etc - use C++ (can scanf restrict length?)
  TCHAR buffer[2049]; // key from scanf
  TCHAR key[2049];    // key from scanf
  TCHAR value[2049];  // value from scanf
  int found;          // Entries found from scanf

  // Read from the file
  while ((GetTextData_Size < MAXSTATUSMESSAGECACHE)
      && _fgetts(buffer, 2048, fp)
      && ((found = _stscanf(buffer, TEXT("%[^#=]=%[^\r\n][\r\n]"), key, value)) != EOF)) {

    // Check valid line?
    if ((found != 2) || key[0] == 0 || value[0] == 0) continue;

    // Save parsed translation to the cache
    GetTextData[GetTextData_Size].key = StringMallocParse(key);
    GetTextData[GetTextData_Size].text = StringMallocParse(value);

    // Global counter
    GetTextData_Size++;
  }

  // file was OK, so save filename to registry again
  ContractLocalPath(szFile1);
  SetRegistryString(szRegistryLanguageFile, szFile1);

  fclose(fp);
}
예제 #9
0
void RasterTerrain::OpenTerrain(void)
{
  #if TESTBENCH
  StartupStore(TEXT(". Loading Terrain... %s"),NEWLINE);
  #endif
  CreateProgressDialog(MsgToken(900)); // Loading Terrain File...

  TCHAR szFile[MAX_PATH] = _T("\0");
  _tcscpy(szFile,szTerrainFile);
  ExpandLocalPath(szFile);

  if ( (_tcslen(szFile)>0) && ( _tcsstr(szFile, _T(".DEM")) || _tcsstr(szFile, _T(".dem")) ) ) {
	if (!CreateTerrainMap(szFile)) {
      // If no terrain will be found, the registry will be invalid on next run
      _tcscpy(szTerrainFile,_T(""));
      StartupStore(_T("... INVALID TERRAIN file <%s>%s"),szFile,NEWLINE);
	}
  } else {
    StartupStore(_T(". NO TERRAIN file available.%s"),NEWLINE);
  }
}
예제 #10
0
파일: LKLanguage.cpp 프로젝트: braun/LK8000
void LKReadLanguageFile() {
  static bool doinit=true;
  static TCHAR oldLang[4];

  if (doinit) {
	_tcscpy(LKLangSuffix,_T(""));
	_tcscpy(oldLang,_T("XXX"));
	doinit=false;
  }

  bool english=false;
  TCHAR szFile1[MAX_PATH] = TEXT("\0");
  _tcscpy(LKLangSuffix,_T(""));
  GetRegistryString(szRegistryLanguageFile, szFile1, MAX_PATH);
  tryeng:
  if (_tcslen(szFile1)==0) {
	_tcscpy(szFile1,_T("%LOCAL_PATH%\\\\_Language\\ENGLISH.LNG"));
	english=true;
  }
  ExpandLocalPath(szFile1);
  // SetRegistryString(szRegistryLanguageFile, TEXT("\0")); // ?

  ZZIP_FILE *langFile = zzip_fopen(szFile1, "rb");
	if (langFile == NULL) {
	if (english) {
		StartupStore(_T("--- CRITIC, NO ENGLISH LANGUAGE FILES!%s"),NEWLINE);
		// critic point, no default language! BIG PROBLEM here!
		for (unsigned short i=0; i<MAX_MESSAGES; i++) {
			LKMessages[i]=NULL;
			LKMessagesIndex[i]=-1;
		}
		return;
		
	} else {
		StartupStore(_T("--- NO LANGUAGE FILE FOUND <%s>, retrying with ENGlish!%s"),szFile1,NEWLINE);
		_tcscpy(szFile1,_T(""));
		goto tryeng;
	}
	return;
  }

  bool found=false;
  TCHAR sTmp[200];
  TCHAR mylang[30];
  while (ReadULine(langFile, sTmp, countof(sTmp))) {
	if (_tcslen(sTmp)<3) continue;
	if ((sTmp[0]=='L')&&(sTmp[1]=='=')) {
		_tcscpy(mylang,&sTmp[2]);

		for (unsigned short i=0; i<_tcslen(mylang); i++) {
			if (mylang[i]=='\r' || mylang[i]=='\n') {
				mylang[i]='\0';
				break;
			}
		}
		found=true;
		break;
	}
  }

  if (found) {
	if (_tcslen(mylang)>3) mylang[3]='\0';
	_tcscpy(LKLangSuffix,mylang);
  }

  if (_tcscmp(oldLang,LKLangSuffix)!=0) { 

	if ( !LKLoadMessages(false) ) { 
		// force reload of english
		if (_tcscmp(_T("ENG"),LKLangSuffix) == 0 ) {
			StartupStore(_T("... CRITICAL, no english langauge available!%s"),NEWLINE);
		} else {
			StartupStore(_T("... LoadText failed, fallback to english language\n"));
			_tcscpy(szFile1,_T("%LOCAL_PATH%\\\\_Language\\ENGLISH.LNG"));
			SetRegistryString(szRegistryLanguageFile, szFile1); 
			_tcscpy(LKLangSuffix,_T("ENG"));
			LKLoadMessages(false);
		}
	} else  {
	  	_tcscpy(oldLang,mylang);
		// Now overload english messages filling gaps in translations
		// only if current lang is not english of course: no reason to load it twice
		if (_tcscmp(_T("ENG"),LKLangSuffix) != 0 ) {
			_tcscpy(LKLangSuffix,_T("ENG"));
			LKLoadMessages(true);
			_tcscpy(LKLangSuffix,oldLang);
		}
	}
  }
  zzip_fclose(langFile);
  return;
}
예제 #11
0
void
StatusMessageList::LoadFile()
{
  StartupStore(TEXT("Loading status file\n"));

  TCHAR szFile1[MAX_PATH] = TEXT("\0");
  FILE *fp=NULL;

  // Open file from registry
  GetRegistryString(szRegistryStatusFile, szFile1, MAX_PATH);
  ExpandLocalPath(szFile1);

  SetRegistryString(szRegistryStatusFile, TEXT("\0"));

  if (_tcslen(szFile1)>0)
    fp  = _tfopen(szFile1, TEXT("rt"));

  // Unable to open file
  if (fp == NULL)
    return;

  // TODO code: Safer sizes, strings etc - use C++ (can scanf restrict length?)
  TCHAR buffer[2049];	// Buffer for all
  TCHAR key[2049];	// key from scanf
  TCHAR value[2049];	// value from scanf
  int ms;				// Found ms for delay
  const TCHAR **location;	// Where to put the data
  int found;			// Entries found from scanf
  bool some_data;		// Did we find some in the last loop...

  // Init first entry
  _init_Status(StatusMessageData_Size);
  some_data = false;

  /* Read from the file */
  while (
	 (StatusMessageData_Size < MAXSTATUSMESSAGECACHE)
	 && _fgetts(buffer, 2048, fp)
	 && ((found = _stscanf(buffer, TEXT("%[^#=]=%[^\n]\n"), key, value)) != EOF)
	 ) {
    // Check valid line? If not valid, assume next record (primative, but works ok!)
    if ((found != 2) || key[0] == 0 || value[0] == 0) {

      // Global counter (only if the last entry had some data)
      if (some_data) {
	StatusMessageData_Size++;
	some_data = false;
	_init_Status(StatusMessageData_Size);
      }

    } else {

      location = NULL;

      if (_tcscmp(key, TEXT("key")) == 0) {
	some_data = true;	// Success, we have a real entry
	location = &StatusMessageData[StatusMessageData_Size].key;
      } else if (_tcscmp(key, TEXT("sound")) == 0) {
	StatusMessageData[StatusMessageData_Size].doSound = true;
	location = &StatusMessageData[StatusMessageData_Size].sound;
      } else if (_tcscmp(key, TEXT("delay")) == 0) {
	if (_stscanf(value, TEXT("%d"), &ms) == 1)
	  StatusMessageData[StatusMessageData_Size].delay_ms = ms;
      } else if (_tcscmp(key, TEXT("hide")) == 0) {
	if (_tcscmp(value, TEXT("yes")) == 0)
	  StatusMessageData[StatusMessageData_Size].doStatus = false;
      }

      // Do we have somewhere to put this && is it currently empty ? (prevent lost at startup)
      if (location && (_tcscmp(*location, TEXT("")) == 0)) {
	// TODO code: this picks up memory lost from no entry, but not duplicates - fix.
	if (*location) {
	  // JMW fix memory leak
          free((void*)*location);
	}
	*location = StringMallocParse(value);
      }
    }

  }

  // How many we really got (blank next just in case)
  StatusMessageData_Size++;
  _init_Status(StatusMessageData_Size);

  // file was ok, so save it to registry
  ContractLocalPath(szFile1);
  SetRegistryString(szRegistryStatusFile, szFile1);

  fclose(fp);
}
예제 #12
0
void TopologyStore::Open() {
  StartupStore(TEXT("OpenTopology\n"));
  XCSoarInterface::CreateProgressDialog(gettext(TEXT("Loading Topology File...")));
  Poco::ScopedRWLock protect(lock, true);

  // Start off by getting the names and paths
  static TCHAR  szOrigFile[MAX_PATH] = TEXT("\0");
  static TCHAR  szFile[MAX_PATH] = TEXT("\0");
  static  TCHAR Directory[MAX_PATH] = TEXT("\0");

  for (int z=0; z<MAXTOPOLOGY; z++) {
    topology_store[z] = 0;
  }

  GetRegistryString(szRegistryTopologyFile, szFile, MAX_PATH);
  ExpandLocalPath(szFile);
  _tcscpy(szOrigFile,szFile); // make copy of original
  ContractLocalPath(szOrigFile);

  // remove it in case it causes a crash (will restore later)
  SetRegistryString(szRegistryTopologyFile, TEXT("\0"));

  if (_tcslen(szFile)==0) {

    // file is blank, so look for it in a map file
    static TCHAR  szMapFile[MAX_PATH] = TEXT("\0");
    GetRegistryString(szRegistryMapFile, szMapFile, MAX_PATH);
    if (_tcslen(szMapFile)==0) {
      return;
    }
    ExpandLocalPath(szMapFile);

    // Look for the file within the map zip file...
    _tcscpy(Directory,szMapFile);
    _tcscat(Directory,TEXT("/"));
    szFile[0]=0;
    _tcscat(szFile,Directory);
    _tcscat(szFile,TEXT("topology.tpl"));

  } else {
    ExtractDirectory(Directory,szFile);
  }

  // Ready to open the file now..

  static ZZIP_FILE* zFile;
  char zfilename[MAX_PATH];
  unicode2ascii(szFile, zfilename, MAX_PATH);
  zFile = zzip_fopen(zfilename, "rt");
  if (!zFile) {
    StartupStore(TEXT("No topology file\n%s\n"), szFile);
    return;
  }

  TCHAR ctemp[80];
  TCHAR TempString[READLINE_LENGTH+1];
  TCHAR ShapeName[50];
  double ShapeRange;
  long ShapeIcon;
  long ShapeField;
  TCHAR wShapeFilename[MAX_PATH];
  TCHAR *Stop;
  int numtopo = 0;
  char ShapeFilename[MAX_PATH];

  while(ReadString(zFile,READLINE_LENGTH,TempString)) {

    if((_tcslen(TempString) > 0)
       && (_tcsstr(TempString,TEXT("*")) != TempString)) // Look For Comment
      {

        BYTE red, green, blue;
        // filename,range,icon,field

        // File name
        PExtractParameter(TempString, ctemp, 0);
        _tcscpy(ShapeName, ctemp);

        _tcscpy(wShapeFilename, Directory);

        _tcscat(wShapeFilename,ShapeName);
        _tcscat(wShapeFilename,TEXT(".shp"));

#ifdef _UNICODE
        WideCharToMultiByte( CP_ACP, 0, wShapeFilename,
                             _tcslen(wShapeFilename)+1,
                             ShapeFilename,
                             200, NULL, NULL);
#else
        strcpy(ShapeFilename, wShapeFilename);
#endif

        // Shape range
        PExtractParameter(TempString, ctemp, 1);
        ShapeRange = StrToDouble(ctemp,NULL);

        // Shape icon
        PExtractParameter(TempString, ctemp, 2);
        ShapeIcon = _tcstol(ctemp, &Stop, 10);

        // Shape field for text display

        // sjt 02NOV05 - field parameter enabled
        PExtractParameter(TempString, ctemp, 3);
        if (_istalnum(ctemp[0])) {
          ShapeField = _tcstol(ctemp, &Stop, 10);
          ShapeField--;
        } else {
          ShapeField = -1;
	}

        // Red component of line / shading colour
        PExtractParameter(TempString, ctemp, 4);
        red = (BYTE)_tcstol(ctemp, &Stop, 10);

        // Green component of line / shading colour
        PExtractParameter(TempString, ctemp, 5);
        green = (BYTE)_tcstol(ctemp, &Stop, 10);

        // Blue component of line / shading colour
        PExtractParameter(TempString, ctemp, 6);
        blue = (BYTE)_tcstol(ctemp, &Stop, 10);

        if ((red==64)
            && (green==96)
            && (blue==240)) {
          // JMW update colours to ICAO standard
          red =    85; // water colours
          green = 160;
          blue =  255;
        }

        if (ShapeField<0) {
          Topology* newtopo;
          newtopo = new Topology(ShapeFilename, Color(red,green,blue));
          topology_store[numtopo] = newtopo;
        } else {
          TopologyLabel *newtopol;
          newtopol = new TopologyLabel(ShapeFilename,
                                       Color(red,green,blue),
                                       ShapeField);
          topology_store[numtopo] = newtopol;
        }
        if (ShapeIcon!=0)
          topology_store[numtopo]->loadBitmap(ShapeIcon);

        topology_store[numtopo]->scaleThreshold = ShapeRange;

        numtopo++;
      }
  }

  zzip_fclose(zFile);

  // file was OK, so save it
  SetRegistryString(szRegistryTopologyFile, szOrigFile);
}
예제 #13
0
void RasterTerrain::OpenTerrain(void)
{
  terrain_initialised = false;
  #if TESTBENCH
  StartupStore(TEXT(". Loading Terrain... %s"),NEWLINE);
  #endif
  CreateProgressDialog(gettext(TEXT("_@M900_"))); // Loading Terrain File...

  TCHAR szFile[MAX_PATH] = _T("\0");

  _tcscpy(szFile,szTerrainFile);

  TCHAR szOrigFile[MAX_PATH] = _T("\0");
  ExpandLocalPath(szFile);
  _tcscpy(szOrigFile, szFile);
  ContractLocalPath(szOrigFile);

  // If no terrain will be found, the registry will be invalid on next run
  _tcscpy(szTerrainFile,_T(""));


#ifdef LKMTERRAIN
  static TCHAR  szMFile[MAX_PATH] = TEXT("\0");
  if (_tcslen(szFile)==0) {
    StartupStore(_T(". NO TERRAIN file configured%s"),NEWLINE);
    _tcscpy(szMFile,szMapFile);
    ExpandLocalPath(szMFile);
    _tcscpy(szFile,szMFile);

     _tcscpy(szFile,szMFile);
     _tcscat(szFile, _T("/terrain.dem")); 
     StartupStore(_T(". Attempting to use DEM <%s> inside mapfile%s"),szFile,NEWLINE);
  }

  if (CreateTerrainMap(szFile)) {
	_tcscpy(szTerrainFile,szOrigFile);
	terrain_initialised = true;
	return;
  } else {
	_tcscpy(szFile,szMFile);
	_tcscat(szFile, _T("/terrain.dat")); 
	StartupStore(_T(". Attempting to use DAT <%s> inside mapfile%s"),szFile,NEWLINE);

	if (CreateTerrainMap(szFile)) {
		_tcscpy(szTerrainFile,szOrigFile);
		terrain_initialised = true;
		return;
	}
   }
#else

  if ( (_tcslen(szFile)>0) && ( _tcsstr(szFile, _T(".DEM")) || _tcsstr(szFile, _T(".dem")) ) ) {
	if (CreateTerrainMap(szFile)) {
		_tcscpy(szterrainFile,szOrigFile);
		terrain_initialised = true;
		return;
	} else {
		StartupStore(_T("... INVALID TERRAIN file <%s>%s"),szFile,NEWLINE);
	}
  }

#endif

  if (TerrainMap) {
	TerrainMap->Close();
	delete TerrainMap;
	TerrainMap = NULL;
  }
  terrain_initialised = false;
  StartupStore(_T(". NO TERRAIN file available.%s"),NEWLINE);
}
예제 #14
0
// Loads a new task from scratch.
// This is called on startup by the even manager because in DEFAULT MENU we have a GCE event
// configured to load Default.tsk for STARTUP_SIMULATOR and STARTUP_REAL.
// Until we change this, which would be a good thing because these configuration are unnecessary ,
// we must use the FullResetAsked trick.
void LoadNewTask(LPCTSTR szFileName)
{
  TASK_POINT Temp;
  START_POINT STemp;
  int i;
  bool TaskInvalid = false;
  bool WaypointInvalid = false;
  bool TaskLoaded = false;
  char taskinfo[LKPREAMBOLSIZE+1]; // 100207
  bool oldversion=false; // 100207
  TCHAR taskFileName[MAX_PATH];

  LockTaskData();

  ClearTask();
  if (FullResetAsked) {
	#if TESTBENCH
	StartupStore(_T("... LoadNewTask detected FullResetAsked, attempt to load DEMO.TSK\n"));
	#endif
	// Clear the flag, forever.
  	FullResetAsked=false;
	_tcscpy(taskFileName,_T("%LOCAL_PATH%\\\\_Tasks\\DEMO.TSK"));
	ExpandLocalPath(taskFileName);

  } else {
	_tcscpy(taskFileName,szFileName);
  }
  
  StartupStore(_T(". LoadNewTask <%s>%s"),taskFileName,NEWLINE);

  FILE* stream = _tfopen(taskFileName, _T("rb"));
  if(stream) {
      // Defaults
      int   old_StartLine    = StartLine;
      int   old_SectorType   = SectorType;
      DWORD old_SectorRadius = SectorRadius;
      DWORD old_StartRadius  = StartRadius;
      int   old_AutoAdvance  = AutoAdvance;
      double old_AATTaskLength = AATTaskLength;
      BOOL   old_AATEnabled  = AATEnabled;
      DWORD  old_FinishRadius = FinishRadius;
      int    old_FinishLine = FinishLine;
      bool   old_EnableMultipleStartPoints = EnableMultipleStartPoints;

      TaskLoaded = true;

      if(fread(taskinfo, sizeof(char), LKPREAMBOLSIZE, stream) != LKPREAMBOLSIZE) {
          TaskInvalid = true;
          goto goEnd;
      }

	// task version check
	if ( (taskinfo[0]!= 'L') || (taskinfo[1]!= 'K') || (taskinfo[2]!=LKTASKVERSION) ) { 
		TaskInvalid = true;
		oldversion = true;
		goto goEnd;
	}

      for(i=0;i<OLD_MAXTASKPOINTS;i++) {
          if(fread(&Temp, 1, sizeof(OLD_TASK_POINT), stream) != sizeof(OLD_TASK_POINT)) {
              TaskInvalid = true;
              break;
          }
          if(i < MAXTASKPOINTS) {
            memcpy(&Task[i],&Temp, sizeof(OLD_TASK_POINT));

            if( !ValidNotResWayPoint(Temp.Index) && (Temp.Index != -1) ) { // 091213
                // Task is only invalid here if the index is out of range
                // of the waypoints and not equal to -1.
                // (Because -1 indicates a null task item)
                WaypointInvalid = true; 
       	    }
          }
        }

      if (!TaskInvalid) {
        TaskInvalid = fread(&AATEnabled, 1, sizeof(BOOL), stream) != sizeof(BOOL);
      }
      if (!TaskInvalid) {
        TaskInvalid = fread(&AATTaskLength, 1, sizeof(double), stream) != sizeof(double);
      }
	// ToDo review by JW
	
	// 20060521:sgi added additional task parameters
      if (!TaskInvalid) {
        TaskInvalid = fread(&FinishRadius, 1, sizeof(FinishRadius), stream) != sizeof(FinishRadius);
      }
      if (!TaskInvalid) {
        TaskInvalid = fread(&FinishLine, 1, sizeof(FinishLine), stream) != sizeof(FinishLine);
      }
      if (!TaskInvalid) {
        TaskInvalid = fread(&StartRadius, 1, sizeof(StartRadius), stream) != sizeof(StartRadius);
      }
      if (!TaskInvalid) {
        TaskInvalid = fread(&StartLine, 1, sizeof(StartLine), stream) != sizeof(StartLine);
      }
      if (!TaskInvalid) {
        TaskInvalid = fread(&SectorType, 1, sizeof(SectorType), stream) != sizeof(SectorType);
      }
      if (!TaskInvalid) {
        TaskInvalid = fread(&SectorRadius, 1, sizeof(SectorRadius), stream) != sizeof(SectorRadius);
      }
      if (!TaskInvalid) {
        TaskInvalid = fread(&AutoAdvance, 1, sizeof(AutoAdvance), stream) != sizeof(AutoAdvance);
      }
      if (!TaskInvalid) {
        TaskInvalid = fread(&EnableMultipleStartPoints, 1, sizeof(EnableMultipleStartPoints), stream) != sizeof(EnableMultipleStartPoints);
      }
      for(i=0;i<MAXSTARTPOINTS;i++) {
        if(fread(&STemp, 1, sizeof(START_POINT), stream) != sizeof(START_POINT)) {
            TaskInvalid = true;
            break;
        }
	  
          if( ValidNotResWayPoint(STemp.Index) || (STemp.Index==-1) ) { // 091213
            memcpy(&StartPoints[i],&STemp, sizeof(START_POINT));
          } else {
	    WaypointInvalid = true;
		StartupStore(_T("--- LoadNewTask: invalid waypoint=%d found%s"),STemp.Index,NEWLINE); // 091213
	  }
        }

        // search for waypoints...
        if (!TaskInvalid) {
          if (!LoadTaskWaypoints(stream) && WaypointInvalid) {
            // couldn't lookup the waypoints in the file and we know there are invalid waypoints
            TaskInvalid = true;
            StartupStore(_T(". LoadTaskNew: cant locate waypoint in file, and invalid wp in task file%s"),NEWLINE);
          }
        }

        // TimeGate config
        if (!TaskInvalid) {
            TaskInvalid = fread(&PGOpenTimeH, 1, sizeof(PGOpenTimeH), stream) != sizeof(PGOpenTimeH);
        }  
        if (!TaskInvalid) {
            TaskInvalid = fread(&PGOpenTimeM, 1, sizeof(PGOpenTimeM), stream) != sizeof(PGOpenTimeM);
        }  
        if (!TaskInvalid) {
            InitActiveGate();

            // PGOpenTime is Calculated !
            int tmp;
            TaskInvalid = fread(&tmp, 1, sizeof(tmp), stream) != sizeof(tmp);
        }
        if (!TaskInvalid) {
            PGCloseTime=86399;
            // PGCloseTime is Calculated !
            int tmp;
            TaskInvalid = fread(&tmp, 1, sizeof(tmp), stream) != sizeof(tmp);
        }
        if (!TaskInvalid) {
            TaskInvalid = fread(&PGGateIntervalTime, 1, sizeof(PGGateIntervalTime), stream) != sizeof(PGGateIntervalTime);
        }
        if (!TaskInvalid) {
            TaskInvalid = fread(&PGNumberOfGates, 1, sizeof(PGNumberOfGates), stream) != sizeof(PGNumberOfGates);
        }
        if (!TaskInvalid) {
            TaskInvalid = fread(&PGStartOut, 1, sizeof(PGStartOut), stream) != sizeof(PGStartOut);
        }    

goEnd:

      fclose(stream);

      if (TaskInvalid) {
	if (oldversion)
		StartupStore(_T("------ Task is invalid: old task format%s"),NEWLINE);
	else
		StartupStore(_T("------ Task is invalid%s"),NEWLINE);

        StartLine = old_StartLine;
        SectorType = old_SectorType;
        SectorRadius = old_SectorRadius;
        StartRadius = old_StartRadius;
        AutoAdvance = old_AutoAdvance;
        AATTaskLength = old_AATTaskLength;
        AATEnabled = old_AATEnabled;
        FinishRadius = old_FinishRadius;
        FinishLine = old_FinishLine;
        EnableMultipleStartPoints = old_EnableMultipleStartPoints;
      }

  } else {
    StartupStore(_T("... LoadNewTask: file <%s> not found%s"),taskFileName,NEWLINE); // 091213
    TaskInvalid = true;
  }
  
  if (TaskInvalid) {
    ClearTask();
  } 

  RefreshTask();
  
  if (!ValidTaskPoint(0)) {
    ActiveWayPoint = 0;
  }

  UnlockTaskData();

  if (TaskInvalid && TaskLoaded) {
	if (oldversion) {
	// LKTOKEN  _@M360_ = "Invalid old task format!" 
		MessageBoxX(gettext(TEXT("_@M360_")), 
	// LKTOKEN  _@M396_ = "Load task" 
			gettext(TEXT("_@M396_")), mbOk);
	} else {
	// LKTOKEN  _@M264_ = "Error in task file!" 
		MessageBoxX(gettext(TEXT("_@M264_")), 
	// LKTOKEN  _@M396_ = "Load task" 
			gettext(TEXT("_@M396_")), mbOk);
	}
  } else {
	#if TESTBENCH
	StartupStore(_T("------ Task is Loaded%s"),NEWLINE);
	#endif
	TaskModified = false; 
	TargetModified = false;
	_tcscpy(LastTaskFileName, taskFileName);
  }

}
예제 #15
0
파일: Read.cpp 프로젝트: PhilColbert/LK8000
void ReadWayPoints(void)
{
  #if TESTBENCH
  StartupStore(TEXT(". ReadWayPoints%s"),NEWLINE);
  #endif

  TCHAR szFile1[MAX_PATH] = TEXT("\0");
  TCHAR szFile2[MAX_PATH] = TEXT("\0");
        
  ZZIP_FILE *fp=NULL;

    LockTaskData();
    CloseWayPoints(); // BUGFIX 091104 duplicate waypoints entries
    InitVirtualWaypoints();	// 091103

    _tcscpy(szFile1,szWaypointFile);

    _tcscpy(szWaypointFile,_T(""));
      
    if (_tcslen(szFile1)>0) {
      ExpandLocalPath(szFile1);
      fp = openzip(szFile1, "rt");
    } else {
    }

    if(fp != NULL)
      {
        globalFileNum = 0;
        WpFileType[1]=ReadWayPointFile(fp, szFile1);
        zzip_fclose(fp);
        fp = 0;
        // read OK, so set the registry to the actual file name
        ContractLocalPath(szFile1);
	_tcscpy(szWaypointFile,szFile1);
      } else {
      StartupStore(TEXT("--- No waypoint file 1%s"),NEWLINE);
    }

  // read additional waypoint file

    // reset to empty until we verified it is existing
    _tcscpy(szFile2,szAdditionalWaypointFile);
    _tcscpy(szAdditionalWaypointFile,_T(""));

    if (_tcslen(szFile2)>0){
      ExpandLocalPath(szFile2);
      fp = openzip(szFile2, "rt");
      if(fp != NULL){
        globalFileNum = 1;
        WpFileType[2]=ReadWayPointFile(fp, szFile2);
        zzip_fclose(fp);
        fp = NULL;
        // read OK, so set the registry to the actual file name
        ContractLocalPath(szFile2);
	_tcscpy(szAdditionalWaypointFile,szFile2);
      } else {
        StartupStore(TEXT("--- No waypoint file 2%s"),NEWLINE);
      }
    }
	
    // each time we load WayPoint, we need to init WaypointCalc !!
    InitWayPointCalc();

  UnlockTaskData();

}
예제 #16
0
// Loads a new task from scratch.
// This is called on startup by the even manager because in DEFAULT MENU we have a GCE event
// configured to load Default.tsk for STARTUP_SIMULATOR and STARTUP_REAL.
// Until we change this, which would be a good thing because these configuration are unnecessary ,
// we must use the FullResetAsked trick.
void LoadNewTask(LPCTSTR szFileName)
{
  HANDLE hFile;
  TASK_POINT Temp;
  START_POINT STemp;
  DWORD dwBytesRead;
  int i;
  bool TaskInvalid = false;
  bool WaypointInvalid = false;
  bool TaskLoaded = false;
  char taskinfo[LKPREAMBOLSIZE+1]; // 100207
  bool oldversion=false; // 100207
  TCHAR taskFileName[MAX_PATH];

  LockTaskData();

  ClearTask();
  if (FullResetAsked) {
	#if TESTBENCH
	StartupStore(_T("... LoadNewTask detected FullResetAsked, attempt to load DEMO.TSK\n"));
	#endif
	// Clear the flag, forever.
  	FullResetAsked=false;
	_tcscpy(taskFileName,_T("%LOCAL_PATH%\\\\_Tasks\\DEMO.TSK"));
	ExpandLocalPath(taskFileName);

  } else {
	_tcscpy(taskFileName,szFileName);
  }
  
  StartupStore(_T(". LoadNewTask <%s>%s"),taskFileName,NEWLINE);

  hFile = CreateFile(taskFileName,GENERIC_READ,0, (LPSECURITY_ATTRIBUTES)NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,NULL);

  if(hFile!= INVALID_HANDLE_VALUE )
    {

      // Defaults
      int   old_StartLine    = StartLine;
      int   old_SectorType   = SectorType;
      DWORD old_SectorRadius = SectorRadius;
      DWORD old_StartRadius  = StartRadius;
      int   old_AutoAdvance  = AutoAdvance;
      double old_AATTaskLength = AATTaskLength;
      BOOL   old_AATEnabled  = AATEnabled;
      DWORD  old_FinishRadius = FinishRadius;
      int    old_FinishLine = FinishLine;
      bool   old_EnableMultipleStartPoints = EnableMultipleStartPoints;

      TaskLoaded = true;

	if(!ReadFile(hFile,&taskinfo,LKPREAMBOLSIZE,&dwBytesRead, (OVERLAPPED *)NULL)) {
		TaskInvalid = true;
		goto goEnd;
	}

	// task version check
	if ( (taskinfo[0]!= 'L') || (taskinfo[1]!= 'K') || (taskinfo[2]!=LKTASKVERSION) ) { 
		TaskInvalid = true;
		oldversion = true;
		goto goEnd;
	}

      for(i=0;i<MAXTASKPOINTS;i++)
        {
          if(!ReadFile(hFile,&Temp,sizeof(TASK_POINT),&dwBytesRead, (OVERLAPPED *)NULL))
            {
              TaskInvalid = true;
              break;
            }
	  memcpy(&Task[i],&Temp, sizeof(TASK_POINT));

          if( !ValidNotResWayPoint(Temp.Index) && (Temp.Index != -1) ) { // 091213
            // Task is only invalid here if the index is out of range
            // of the waypoints and not equal to -1.
            // (Because -1 indicates a null task item)
	        WaypointInvalid = true; 
	  }
        }

      if (!TaskInvalid) {

	if (!ReadFile(hFile,&AATEnabled,sizeof(BOOL),&dwBytesRead,(OVERLAPPED*)NULL)) {
          TaskInvalid = true;
        }
	if (!ReadFile(hFile,&AATTaskLength,sizeof(double),&dwBytesRead,(OVERLAPPED*)NULL)) {
          TaskInvalid = true;
        }
	
	// ToDo review by JW
	
	// 20060521:sgi added additional task parameters
	if (!ReadFile(hFile,&FinishRadius,sizeof(FinishRadius),&dwBytesRead,(OVERLAPPED*)NULL)) {
          TaskInvalid = true;
        }
	if (!ReadFile(hFile,&FinishLine,sizeof(FinishLine),&dwBytesRead,(OVERLAPPED*)NULL)) {
          TaskInvalid = true;
        }
	if (!ReadFile(hFile,&StartRadius,sizeof(StartRadius),&dwBytesRead,(OVERLAPPED*)NULL)) {
          TaskInvalid = true;
        }
	if (!ReadFile(hFile,&StartLine,sizeof(StartLine),&dwBytesRead,(OVERLAPPED*)NULL)) {
          TaskInvalid = true;
        }
	if (!ReadFile(hFile,&SectorType,sizeof(SectorType),&dwBytesRead,(OVERLAPPED*)NULL)) {
          TaskInvalid = true;
        }
	if (!ReadFile(hFile,&SectorRadius,sizeof(SectorRadius),&dwBytesRead,(OVERLAPPED*)NULL)) {
          TaskInvalid = true;
        }
	if (!ReadFile(hFile,&AutoAdvance,sizeof(AutoAdvance),&dwBytesRead,(OVERLAPPED*)NULL)) {
          TaskInvalid = true;
        }

        if (!ReadFile(hFile,&EnableMultipleStartPoints,sizeof(bool),&dwBytesRead,(OVERLAPPED*)NULL)) {
          TaskInvalid = true;
        }

        for(i=0;i<MAXSTARTPOINTS;i++)
        {
          if(!ReadFile(hFile,&STemp,sizeof(START_POINT),&dwBytesRead, (OVERLAPPED *)NULL)) {
            TaskInvalid = true;
            break;
          }
	  
          if( ValidNotResWayPoint(STemp.Index) || (STemp.Index==-1) ) { // 091213
            memcpy(&StartPoints[i],&STemp, sizeof(START_POINT));
          } else {
	    WaypointInvalid = true;
		StartupStore(_T("--- LoadNewTask: invalid waypoint=%d found%s"),STemp.Index,NEWLINE); // 091213
	  }
        }

        // search for waypoints...
        if (!TaskInvalid) {
          if (!LoadTaskWaypoints(hFile) && WaypointInvalid) {
            // couldn't lookup the waypoints in the file and we know there are invalid waypoints
            TaskInvalid = true;
            StartupStore(_T(". LoadTaskNew: cant locate waypoint in file, and invalid wp in task file%s"),NEWLINE);
          }
        }

      }
      
        // TimeGate config
        if (!TaskInvalid) {
            TaskInvalid = !ReadFile(hFile, &PGOpenTimeH, sizeof (PGOpenTimeH), &dwBytesRead, (OVERLAPPED*) NULL);
        }
        if (!TaskInvalid) {
            TaskInvalid = !ReadFile(hFile, &PGOpenTimeM, sizeof (PGOpenTimeM), &dwBytesRead, (OVERLAPPED*) NULL);
        }
        if (!TaskInvalid) {
			PGOpenTime=((PGOpenTimeH*60)+PGOpenTimeM)*60;

			// PGOpenTime is Calculated !
			int tmp;
            TaskInvalid = !ReadFile(hFile, &tmp, sizeof (tmp), &dwBytesRead, (OVERLAPPED*) NULL);
        }
        if (!TaskInvalid) {
			PGCloseTime=86399;
			
			// PGCloseTime is Calculated !
			int tmp;
            TaskInvalid = !ReadFile(hFile, &tmp, sizeof (tmp), &dwBytesRead, (OVERLAPPED*) NULL);
        }
        if (!TaskInvalid) {
            TaskInvalid = !ReadFile(hFile, &PGGateIntervalTime, sizeof (PGGateIntervalTime), &dwBytesRead, (OVERLAPPED*) NULL);
        }
        if (!TaskInvalid) {
            TaskInvalid = !ReadFile(hFile, &PGNumberOfGates, sizeof (PGNumberOfGates), &dwBytesRead, (OVERLAPPED*) NULL);
        }
        if (!TaskInvalid) {
            TaskInvalid = !ReadFile(hFile, &PGStartOut, sizeof (PGStartOut), &dwBytesRead, (OVERLAPPED*) NULL);
        }    

goEnd:

      CloseHandle(hFile);

      if (TaskInvalid) {
	if (oldversion)
		StartupStore(_T("------ Task is invalid: old task format%s"),NEWLINE);
	else
		StartupStore(_T("------ Task is invalid%s"),NEWLINE);

        StartLine = old_StartLine;
        SectorType = old_SectorType;
        SectorRadius = old_SectorRadius;
        StartRadius = old_StartRadius;
        AutoAdvance = old_AutoAdvance;
        AATTaskLength = old_AATTaskLength;
        AATEnabled = old_AATEnabled;
        FinishRadius = old_FinishRadius;
        FinishLine = old_FinishLine;
        EnableMultipleStartPoints = old_EnableMultipleStartPoints;
      }

  } else {
    StartupStore(_T("... LoadNewTask: file <%s> not found%s"),taskFileName,NEWLINE); // 091213
    TaskInvalid = true;
  }
  
  if (TaskInvalid) {
    ClearTask();
  } 

  RefreshTask();
  
  if (!ValidTaskPoint(0)) {
    ActiveWayPoint = 0;
  }

  UnlockTaskData();

  if (TaskInvalid && TaskLoaded) {
	if (oldversion) {
	// LKTOKEN  _@M360_ = "Invalid old task format!" 
		MessageBoxX(hWndMapWindow, gettext(TEXT("_@M360_")), 
	// LKTOKEN  _@M396_ = "Load task" 
			gettext(TEXT("_@M396_")), MB_OK|MB_ICONEXCLAMATION);
	} else {
	// LKTOKEN  _@M264_ = "Error in task file!" 
		MessageBoxX(hWndMapWindow, gettext(TEXT("_@M264_")), 
	// LKTOKEN  _@M396_ = "Load task" 
			gettext(TEXT("_@M396_")), MB_OK|MB_ICONEXCLAMATION);
	}
  } else {
	#if TESTBENCH
	StartupStore(_T("------ Task is Loaded%s"),NEWLINE);
	#endif
	TaskModified = false; 
	TargetModified = false;
	_tcscpy(LastTaskFileName, taskFileName);
  }

}