示例#1
0
文件: wdll_ver.cpp 项目: Marlinc/0ad
void wdll_ver_Append(const OsPath& pathname, VersionList& list)
{
	if(pathname.empty())
		return;	// avoid error in ReadVersionString

	// pathname may not have an extension (e.g. driver names from the
	// registry). note that always appending ".dll" would be incorrect
	// since some have ".sys" extension.
	OsPath modulePathname(pathname);
	if(modulePathname.Extension() == "")
		modulePathname = modulePathname.ChangeExtension(L".dll");
	const OsPath moduleName(modulePathname.Filename());

	// read file version. try this with and without FS redirection since
	// pathname might assume both.
	wchar_t versionString[500];	// enclosed in () below
	if(ReadVersionString(modulePathname, versionString, ARRAY_SIZE(versionString)) != INFO::OK)
	{
		WinScopedDisableWow64Redirection s;
		// still failed; avoid polluting list with DLLs that don't exist
		// (requiring callers to check for their existence beforehand would be
		// onerous and unreliable)
		if(ReadVersionString(modulePathname, versionString, ARRAY_SIZE(versionString)) != INFO::OK)
			return;
	}

	if(!list.empty())
		list += L", ";
	
	list += moduleName.Filename().string();
	list += L" (";
	list += versionString;
	list += L")";
}
/* install packages defined in packageList from local path to sensor*/
bool SensorUpdater::installPackagesFromPath(const VersionList& packageList,
                                            const std::string& localPath)
{
  if (!is_ssh_initialized_) {
    std::cout << "sensor updater is not connected to any sensor\n";
    return false;
  }
  for (size_t i = 0; i < packageList.size(); i++) {
    std::cout << "Installing " << packageList[i].package_name << " ...  ";

    // download
    std::string pkg_filename = localPath + packageList[i].package_name + std::string(".deb");
    std::string pkg_remote_filename = remotePath() + packageList[i].package_name + std::string(".deb");

    // transfer file to sensor
    bool ret = pSsh_->sendFile(pkg_filename, pkg_remote_filename);
    if (!ret) {
      std::cout << "failed.\n";
      std::cout << "[ERROR]: Could not upload file to sensor!\n";
      exit(1);
    }

    // install
    ret = sensorInstallDebFile(pkg_remote_filename);

    if (!ret) {
      std::cout << "failed.\n";
      std::cout << "[ERROR]: Could not install debfile on sensor " << pkg_filename << "\n";
      exit(1);
    }
    std::cout << "done.\n";
  }
  std::cout << std::endl;
  return true;
}
bool SensorUpdater::printVersionsRepo(const REPOS& repo)
{
  VersionList listFtp;
  bool success = getVersionsOnServer(&listFtp, repo);

  if (!success) {
    std::cout << "Error: could not get installed versions from repository!\n";
    return false;
  }

  std::cout << "Name\t\tVersion\t\tftppath\n";
  for (size_t i = 0; i < listFtp.size(); i++) {
    std::cout << listFtp[i].package_name << "\t\t" << listFtp[i].version_major << "."
              << listFtp[i].version_minor << "." << listFtp[i].version_patch << "\t\t"
              << listFtp[i].path << "\n";
  }
  return true;
}
bool SensorUpdater::checkCalibrationConvertion(const VersionList& old_list,
                                               const VersionList& new_list)
{
  VersionEntry linux_embedded_entry;
  VersionEntry version_of_cali_change(2,0,0);
  //check if the calibration need to be converted
  if (old_list.size() == 0) {
    std::cout << "Try to copy possible available calibration ... ";
    if (loadXmlCameraCalibrationFile("/tmp/calibration.xml")) {
      std::cout << "done." << std::endl;
      if (!convertCalibration()) {
        std::cerr << "Could not convert calibration to new format" << std::endl;
        return false;
      }
    } else {
      std::cout << "No calibration file found, nothing to convert" << std::endl;
    }
  } else {
    size_t i;
    for (i = 0; i < old_list.size(); i++) {
      if (old_list[i].package_name == "visensor-linux-embedded") {
        break;
      }
    }
    if ((i >= old_list.size()) && (old_list.size() != new_list.size())) {
      std::cerr << "could not found linux embedded version" << std::endl;
      return false;
    }
    if ((old_list[i] < version_of_cali_change)
        && ((new_list[i] > version_of_cali_change) || (new_list[i] == version_of_cali_change))) {
      if (!convertCalibration()) {
        std::cerr << "could not convert calibration to new format" << std::endl;
        return false;
      }
    }
  }
  return true;
}
/* clean all installed packages on the sensor with the given prefix */
bool SensorUpdater::sensorClean(void)
{
  VersionList listSensor;

  // get all the installed packages with the given prefix
  bool success = getVersionInstalled(&listSensor);

  if (!success) {
    std::cout << "Error: could not get installed versions from sensor!\n";
    return false;
  }

  // remove package after package
  for (size_t i = 0; i < listSensor.size(); i++) {
    std::cout << "Removing " << listSensor[i].package_name << " from Sensor ... ";
    success = sensorRemoveDeb(listSensor[i].package_name);
    if (success)
      std::cout << "done.\n";
    else
      std::cout << "failed!\n";
  }
  std::cout << std::endl;
  return success;
}
bool SensorUpdater::printVersionsInstalled(void)
{
  VersionList listSensor;
  bool success = getVersionInstalled(&listSensor);

  if (!success) {
    std::cout << "Error: could not get installed versions from sensor!\n";
    return false;
  }

  std::cout << "Name\t\t\t\tVersion\n";
  std::cout << "-----------------------------------------\n";
  if (!listSensor.size()) {
    std::cout << "No packages installed!\n";
    return true;
  }

  for (size_t i = 0; i < listSensor.size(); i++) {
    std::cout << listSensor[i].package_name << "\t\t" << listSensor[i].version_major << "."
              << listSensor[i].version_minor << "." << listSensor[i].version_patch << "\n";
  }
  std::cout << std::endl;
  return true;
}
/* download packages defined in packageList from repo to local path */
bool SensorUpdater::downloadPackagesToPath(const VersionList& packageList,
                                           const std::string& localPath)
{
  // download and install the needed packages
   WebClient web_client(servername());

  for (size_t i = 0; i < packageList.size(); i++) {
    std::cout << "Downloading " << packageList[i].package_name << " ...  ";

     // download
    std::string pkg_filename = localPath + packageList[i].package_name + std::string(".deb");

    bool ret = web_client.getFileToFile(packageList[i].path, pkg_filename);
    if (!ret) {
      std::cout << "failed.\n";
      std::cout << "[ERROR]: Could not fetch update package from online repository! \n";
      exit(1);
    }

    std::cout << "done.\n";
  }
  std::cout << std::endl;
  return true;
}
/* get a list of the newest/defined versions from the repo */
bool SensorUpdater::getUpdateList(VersionList* outList, const VersionList &packageVersionList, const REPOS &repo)
{
  // get the newest version from the repos
  VersionList allPackages;
  bool success = getVersionsOnServer(&allPackages, repo);

  //extract the newst version of all mandatory packages
  VersionList updatePackages;
  int i;
  parse_function_map::const_iterator iter;
  for (iter =  possible_pkgs_.begin(), i = 0; iter != possible_pkgs_.end(); ++iter, ++i) {
    // extract all packages which are mandatory to install
    VersionList temp;

    for(size_t j=0; j<allPackages.size(); j++) {
      if( allPackages[j].package_name == iter->first) {
        if (!packageVersionList.empty()) {
          // check if the version is the requested version
          if (allPackages[j] == packageVersionList[i]) {
            if (allPackages[j].package_name != packageVersionList[i].package_name) {
              std::cerr << "requested version package name and found package name does not match" << std::endl;
              exit(-1);
            }

            temp.push_back( allPackages[j] );
            break;
          }
        }
        else {
          temp.push_back( allPackages[j] );
        }
      }
    }

    // check we found the mandatory package
    if (temp.size() < 1) {
      std::cout << "[ERROR]: Could not find the required package \""
                << iter->first << "\" in the online repository!\n";
      exit(1);
    }

    // sort for version
    std::sort(temp.begin(), temp.end());

    // add the newest version of the mandatory package to the update list
    updatePackages.push_back(temp.back());
  }
  *outList = updatePackages;
  return success;
}