示例#1
0
bool
CAI302::DownloadNavpoint(Port &port, const GeoPoint &location,
                         int altitude, unsigned id,
                         bool turnpoint, bool airfield, bool markpoint,
                         bool landing_point, bool start_point,
                         bool finish_point, bool home_point,
                         bool thermal_point, bool waypoint, bool airspace,
                         const char *name, const char *remark,
                         OperationEnvironment &env)
{
  assert(name != nullptr);

  char location_string[32];
  FormatGeoPoint(location_string, location);

  unsigned attr = turnpoint | (airfield << 1) | (markpoint << 2) |
    (landing_point << 3) | (start_point << 4) | (finish_point << 5) |
    (home_point << 6) | (thermal_point << 7) | (waypoint << 8) |
    (airfield << 9);

  if (remark == nullptr)
    remark = "";

  char buffer[256];
  snprintf(buffer, sizeof(buffer), "C,0,%s,%d,%u,%u,%-12s,%-12s\r",
           location_string, altitude, id, attr, name, remark);
  return DownloadCommand(port, buffer, env);
}
示例#2
0
bool
CAI302::DownloadPilot(Port &port, const Pilot &pilot, unsigned ordinal,
                      OperationEnvironment &env)
{
  char buffer[256];
  snprintf(buffer, sizeof(buffer),
           "O,%-24s,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r",
           pilot.name,
           (ordinal << 8) | pilot.old_units,
           pilot.old_temperatur_units,
           pilot.sink_tone,
           pilot.total_energy_final_glide,
           pilot.show_final_glide_altitude_difference,
           pilot.map_datum,
           FromBE16(pilot.approach_radius),
           FromBE16(pilot.arrival_radius),
           FromBE16(pilot.enroute_logging_interval),
           FromBE16(pilot.close_logging_interval),
           FromBE16(pilot.time_between_flight_logs),
           FromBE16(pilot.minimum_speed_to_force_flight_logging),
           pilot.stf_dead_band,
           pilot.reserved_vario,
           FromBE16(pilot.unit_word),
           FromBE16(pilot.margin_height));

  return DownloadCommand(port, buffer, env);
}
示例#3
0
void CConEmuUpdate::wininet::SetCallback(CEDownloadCommand cbk, FDownloadCallback pfnCallback, LPARAM lParam)
{
	CEDownloadErrorArg args[2];
	args[0].argType = at_Uint;  args[0].uintArg = (DWORD_PTR)pfnCallback;
	args[1].argType = at_Uint;  args[1].uintArg = lParam;
	_ASSERTE(dc_ErrCallback<=cbk && cbk<=dc_LogCallback);
	DownloadCommand(cbk, 2, args);
}
示例#4
0
bool CConEmuUpdate::wininet::Deinit(bool bFull)
{
	// if bFull - release allocaled object too
	if (!DownloadCommand)
		return false;
	if (!DownloadCommand(bFull ? dc_Deinit : dc_Reset, 0, NULL))
		return false;
	return true;
}
示例#5
0
bool
CAI302::DeclareTP(Port &port, unsigned i, const GeoPoint &location,
                  int altitude, const char *name, OperationEnvironment &env)
{
  char location_string[32];
  FormatGeoPoint(location_string, location);

  char buffer[256];
  snprintf(buffer, sizeof(buffer),
           "D,%d,%s,%s,%d\r",
           128 + i, location_string,
           name,
           altitude);

  return DownloadCommand(port, buffer, env);
}
示例#6
0
bool
CAI302::DownloadPolar(Port &port, const Polar &polar,
                      OperationEnvironment &env)
{
  char buffer[256];
  snprintf(buffer, sizeof(buffer),
           "G,%-12s,%-12s,%d,%d,%d,%d,%d,%d,%d,%d\r",
           polar.glider_type,
           polar.glider_id,
           polar.best_ld,
           polar.best_glide_speed,
           polar.two_ms_sink_at_speed,
           FromBE16(polar.weight_in_litres),
           FromBE16(polar.ballast_capacity),
           0,
           FromBE16(polar.config_word),
           FromBE16(polar.wing_area));

  return DownloadCommand(port, buffer, env);
}
示例#7
0
/*
 * DownloadDone:  Unpack archive and move downloaded files into correct directory,
 *   if appropriate.
 *   zip_filename is the name of the file on the disk.
 *   file_info gives info about downloaded file.
 *   Return True iff successful.
 */
Bool DownloadDone(DownloadFileInfo *file_info)
{
   char zip_name[MAX_PATH + FILENAME_MAX];    // Name of uncompressed file
   char *destination_dir;

   // If we're a guest, skip non-guest files
   if (config.guest && !(file_info->flags & DF_GUEST))
      return True;
 
   sprintf(zip_name, "%s\\%s", download_dir, file_info->filename);

   switch (DownloadLocation(file_info->flags))
   {
   case DF_DIRRESOURCE:
      destination_dir = resource_dir;
      break;

   case DF_DIRCLIENT:
      destination_dir = client_dir;
      break;

   case DF_DIRHELP:
      destination_dir = help_dir;
      break;

   case DF_DIRMAIL:
      destination_dir = mail_dir;
      break;

   case DF_ADVERTISEMENT:
      destination_dir = ad_dir;
      break;

   case DF_DIRWIN:
   case DF_DIRWINSYS:
      // XXX Unimplemented
      debug(("Windows dir file flags unimplemented\n"));
      destination_dir = client_dir;
      break;

   default:
      debug(("Got bad file location flags %d\n", DownloadLocation(file_info->flags)));
      return False;
   }

   debug(("destination = %s\n", destination_dir));

   // Post-processing on file
   switch (DownloadCommand(file_info->flags))
   {
   case DF_DELETE:
      sprintf(zip_name, "%s\\%s", destination_dir, file_info->filename);
      if (!DownloadDeleteFile(zip_name))
	 return False;
      break;

   case DF_RETRIEVE:
      if (!DownloadUncrushFile(zip_name, destination_dir))
      {
	 unlink(zip_name);
	 return False;
      }
      unlink(zip_name);
      break;

   default:
      debug(("Got unknown download command %d\n", DownloadCommand(file_info->flags)));
      break;
   }

   debug(("Got file successfully\n"));

   return True;
}
示例#8
0
/*
 * TransferStart: Retrieve files; the information needed to set up the
 * transfer is in info.
 *
 * This function is run in its own thread.
 */
void __cdecl TransferStart(void *download_info)
{
    Bool done;
    char filename[MAX_PATH + FILENAME_MAX];
    char local_filename[MAX_PATH + 1];  // Local filename of current downloaded file
    int i;
    int outfile;                   // Handle to output file
    DWORD size;                      // Size of block we're reading
    int bytes_read;                // Total # of bytes we've read

#if defined VANILLA_UPDATER
    const char *mime_types[2] = { "application/x-zip-compressed" };
#else
    const char *mime_types[4] = { "application/octet-stream", "text/plain", "application/x-msdownload", NULL };
    //const char *mime_types[2] = { "application/octet-stream", NULL };
#endif

    DWORD file_size;
    DWORD file_size_buf_len;
    DWORD index = 0;
    DownloadInfo *info = (DownloadInfo *)download_info;

    aborted = False;
    hConnection = NULL;
    hSession = NULL;
    hFile = NULL;

    hConnection = InternetOpen(szAppName, INTERNET_OPEN_TYPE_PRECONFIG,
                               NULL, NULL, INTERNET_FLAG_RELOAD);

    if (hConnection == NULL)
    {
        DownloadError(info->hPostWnd, GetString(hInst, IDS_CANTINIT));
        return;
    }

    if (aborted)
    {
        TransferCloseHandles();
        return;
    }

    hSession = InternetConnect(hConnection, info->machine, INTERNET_INVALID_PORT_NUMBER,
                               NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
    if (hSession == NULL)
    {
        DownloadError(info->hPostWnd, GetString(hInst, IDS_NOCONNECTION), info->machine);
        return;
    }

    for (i = info->current_file; i < info->num_files; i++)
    {
        if (aborted)
        {
            TransferCloseHandles();
            return;
        }

        // Skip non-guest files if we're a guest
        if (config.guest && !(info->files[i].flags & DF_GUEST))
        {
            PostMessage(info->hPostWnd, BK_FILEDONE, 0, i);
            continue;
        }

        // If not supposed to transfer file, inform main thread
        if (DownloadCommand(info->files[i].flags) != DF_RETRIEVE)
        {
            // Wait for main thread to finish processing previous file
            WaitForSingleObject(hSemaphore, INFINITE);

            if (aborted)
            {
                TransferCloseHandles();
                return;
            }

            PostMessage(info->hPostWnd, BK_FILEDONE, 0, i);
            continue;
        }
#if VANILLA_UPDATER
        sprintf(filename, "%s%s", info->path, info->files[i].filename);
#else
        sprintf(filename, "%s//%s", info->path, info->files[i].filename);
#endif
        hFile = HttpOpenRequest(hSession, NULL, filename, NULL, NULL,
                                mime_types, INTERNET_FLAG_NO_UI, 0);
        if (hFile == NULL)
        {
            debug(("HTTPOpenRequest failed, error = %d, %s\n",
                   GetLastError(), GetLastErrorStr()));
            DownloadError(info->hPostWnd, GetString(hInst, IDS_CANTFINDFILE),
                          filename, info->machine);
            return;
        }

        if (!HttpSendRequest(hFile, NULL, 0, NULL, 0)) {
            debug(("HTTPSendRequest failed, error = %d, %s\n",
                   GetLastError(), GetLastErrorStr()));
            DownloadError(info->hPostWnd, GetString(hInst, IDS_CANTSENDREQUEST),
                          filename, info->machine);
            return;
        }

        // Get file size
        file_size_buf_len = sizeof(file_size);
        index = 0;
        if (!HttpQueryInfo(hFile, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
                           &file_size, &file_size_buf_len, &index)) {
            debug(("HTTPQueryInfo failed, error = %d, %s\n",
                   GetLastError(), GetLastErrorStr()));
            DownloadError(info->hPostWnd, GetString(hInst, IDS_CANTGETFILESIZE),
                          filename, info->machine);
            return;
        }

        PostMessage(info->hPostWnd, BK_FILESIZE, i, file_size);
#if VANILLA_UPDATER
        sprintf(local_filename, "%s\\%s", download_dir, info->files[i].filename);
#else
        sprintf(local_filename, "%s\\%s", info->files[i].path, info->files[i].filename);
#endif
        outfile = open(local_filename, O_BINARY | O_RDWR | O_CREAT | O_TRUNC, S_IWRITE | S_IREAD);
        if (outfile <= 0)
        {
            debug(("Couldn't open local file %s for writing\n", local_filename));
            DownloadError(info->hPostWnd, GetString(hInst, IDS_CANTWRITELOCALFILE),
                          local_filename);
            return;
        }

        // Read first block
        done = False;
        bytes_read = 0;
        while (!done)
        {
            if (!InternetReadFile(hFile, buf, BUFSIZE, &size))
            {
                DownloadError(info->hPostWnd, GetString(hInst, IDS_CANTREADFTPFILE), filename);
            }

            if (size > 0)
            {
                if (write(outfile, buf, size) != size)
                {
                    DownloadError(info->hPostWnd, GetString(hInst, IDS_CANTWRITELOCALFILE),
                                  local_filename);
                    close(outfile);
                    return;
                }
            }

            // Update graph position
            bytes_read += size;
            PostMessage(info->hPostWnd, BK_PROGRESS, 0, bytes_read);

            // See if done with file
            if (size == 0)
            {
                close(outfile);
                InternetCloseHandle(hFile);
                done = True;

                // Wait for main thread to finish processing previous file
                WaitForSingleObject(hSemaphore, INFINITE);

                if (aborted)
                {
                    TransferCloseHandles();
                    return;
                }

                PostMessage(info->hPostWnd, BK_FILEDONE, 0, i);
            }
        }
    }

    InternetCloseHandle(hSession);
    InternetCloseHandle(hConnection);

    PostMessage(info->hPostWnd, BK_TRANSFERDONE, 0, 0);
}
示例#9
0
bool CConEmuUpdate::wininet::Init(CConEmuUpdate* apUpd)
{
	//  Already initialized?
	if (hDll)
	{
		_ASSERTE(DownloadCommand!=NULL);
		// But check if local objects are created...
		if (!DownloadCommand(dc_Init, 0, NULL))
		{
			DWORD nErr = GetLastError(); // No use?
			pUpd->ReportError(L"Failed to re-inialize gpInet, code=%u", nErr);
			return false;
		}
		return true;
	}

	pUpd = apUpd;

	bool bRc = false;
	wchar_t* pszLib = lstrmerge(gpConEmu->ms_ConEmuBaseDir, WIN3264TEST(L"\\ConEmuCD.dll",L"\\ConEmuCD64.dll"));
	HMODULE lhDll = pszLib ? LoadLibrary(pszLib) : NULL;
	DownloadCommand_t lDownloadCommand = NULL;
	if (!lhDll)
	{
		_ASSERTE(lhDll!=NULL);
		lhDll = LoadLibrary(WIN3264TEST(L"ConEmuCD.dll",L"ConEmuCD64.dll"));
	}
	if (!lhDll)
	{
		DWORD nErr = GetLastError();
		pUpd->ReportError(L"Required library '%s' was not loaded, code=%u", WIN3264TEST(L"ConEmuCD.dll",L"ConEmuCD64.dll"), nErr);
		goto wrap;
	}

	lDownloadCommand = (DownloadCommand_t)GetProcAddress(lhDll, "DownloadCommand");
	if (!lDownloadCommand)
	{
		pUpd->ReportError(L"Exported function DownloadCommand in '%s' not found! Check your installation!",
			WIN3264TEST(L"ConEmuCD.dll",L"ConEmuCD64.dll"), GetLastError());
		goto wrap;
	}

	if (!lDownloadCommand(dc_Init, 0, NULL))
	{
		DWORD nErr = GetLastError(); // No use?
		pUpd->ReportError(L"Failed to inialize gpInet, code=%u", nErr);
		goto wrap;
	}

	hDll = lhDll;
	DownloadCommand = lDownloadCommand;

	SetCallback(dc_ErrCallback, ErrorCallback, (LPARAM)apUpd);
	SetCallback(dc_LogCallback, (gpSetCls && gpSetCls->isAdvLogging)?LogCallback:NULL, (LPARAM)apUpd);

	bRc = true;
wrap:
	SafeFree(pszLib);
	if (lhDll && !bRc)
	{
		FreeLibrary(lhDll);
	}
	return bRc;
}
示例#10
0
bool
CAI302::DeclareSave(Port &port, OperationEnvironment &env)
{
  return DownloadCommand(port, "D,255\r", env, 5000);
}
示例#11
0
bool
CAI302::DeclareSave(Port &port, OperationEnvironment &env)
{
  return DownloadCommand(port, "D,255\r", env, std::chrono::seconds(5));
}
示例#12
0
bool
CAI302::CloseNavpoints(Port &port, OperationEnvironment &env)
{
  return DownloadCommand(port, "C,-1\r", env, std::chrono::seconds(5));
}