Beispiel #1
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);
  }

}
Beispiel #2
0
// loads a new task from scratch.
void Task::LoadNewTask(const TCHAR *szFileName,
                       const SETTINGS_COMPUTER &settings_computer)
{
  TASK_POINT Temp;
  START_POINT STemp;
  int i;
  bool TaskInvalid = false;
  bool WaypointInvalid = false;
  bool TaskLoaded = false;
  unsigned magic = 0;

  ActiveTaskPoint = 0;
  for(i=0;i<MAXTASKPOINTS;i++) {
    task_points[i].Index = -1;
  }

  FILE *file = _tfopen(szFileName, _T("rb"));
  if(file != NULL) {
    if (fread(&magic, sizeof(magic), 1, file) != 1) {
      TaskInvalid = true;
    } else if (magic != BINFILEMAGICNUMBER) {
      TaskInvalid = true;
    } else {

      SETTINGS_TASK new_settings = getSettings();
      TaskLoaded = true;

      for(i=0;i<MAXTASKPOINTS;i++) {
        if (fread(&Temp, sizeof(Temp), 1, file) != 1) {
          TaskInvalid = true;
          break;
        }
        memcpy(&task_points[i],&Temp, sizeof(TASK_POINT));

        if(!way_points.verify_index(Temp.Index) && (Temp.Index != -1)) {
          // 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 (fread(&new_settings, sizeof(SETTINGS_TASK), 1, file) != 1) {
          TaskInvalid = true;
        }

        for(i=0;i<MAXSTARTPOINTS;i++) {
          if (fread(&STemp, sizeof(STemp), 1, file) != 1) {
            TaskInvalid = true;
            break;
          }

          if(way_points.verify_index(STemp.Index) || (STemp.Index==-1)) {
            memcpy(&task_start_points[i],&STemp, sizeof(START_POINT));
          } else {
	    WaypointInvalid = true;
	  }
        }

        //// search for waypoints...
        if (!TaskInvalid) {
          if (!LoadTaskWaypoints(file) && WaypointInvalid) {
            // couldn't lookup the waypoints in the file and we know
            // there are invalid waypoints
            TaskInvalid = true;
          }
        }
      }
      fclose(file);
      if (!TaskInvalid) {
        setSettings(new_settings);
      }
    }
  } else {
    TaskInvalid = true;
  }

  if (TaskInvalid) {
    ClearTask();
  }

  RefreshTask(settings_computer);

  if (TaskInvalid && TaskLoaded) {
    MessageBoxX(
      gettext(TEXT("Error in task file!")),
      gettext(TEXT("Load task")),
      MB_OK|MB_ICONEXCLAMATION);
  } else {
    SetTaskModified(false);
    SetTargetModified(false);
    _tcscpy(LastTaskFileName, szFileName);
  }
}
Beispiel #3
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);
  }

}