static void writeProjectItem(const ProjectItem* item, const StringMap& params, const StringSet& urlSchemes)
{
  if (!item)
    return;

  // Open input file
  auto inMode = item->replaceParams ? ios::in : ios::binary;
  ifstream ifs(item->inFile.c_str(), inMode);
  if (!ifs.is_open()) {
    SBLog::warning() << "Failed to open " << item->inFile << " for reading." << std::endl;
    return;
  }

  // Open output file
  ofstream ofs;
  auto outMode = item->replaceParams ? ios::out : ios::binary;
  openOutputFileStream(ofs, item->outFile, outMode);

  if (item->replaceParams) {
    // Expand input line by line and write it out
    std::string line;
    while (std::getline(ifs, line)) {
      expandString(line, params);
      ofs << line << std::endl;
    }
  } else {
    // Copy the file contents
    ofs << ifs.rdbuf();
  }

  if (!urlSchemes.empty() && isAppxManifestFileName(item->inFile)) {
      ofs.close();
      insertUrlSchemes(item->outFile, urlSchemes);
  }
}
VCProject* SBNativeTarget::constructVCProject(VSTemplateProject* projTemplate)
{
  VCProject* proj = SBTarget::constructVCProject(projTemplate);
  String vsProjDir = sb_dirname(proj->getPath());

  // Write variables file for App targets
  for (auto bs : m_buildSettings) {
    if (getProductType() == TargetApplication || getProductType() == TargetBundle) {
      String configName = bs.first;
      BuildSettings* configBS = bs.second;

      // Figure out where the file should go
      String varsFilePath = joinPaths(vsProjDir, getName() + "-" + configName + "-xcvars.txt");

      // Open a file stream to write to
      OFStream varsOut;
      openOutputFileStream(varsOut, varsFilePath);

      // Write the build settings out
      XCConfigPrinter varsPrinter(varsOut);
      configBS->print(varsPrinter);

      // Add the variables file to the project
      VCProjectItem* xcvarsFile = addRelativeFilePathToVS("Text", varsFilePath, "Xcode Variable Files", *proj, *configBS);

      // Mark the file as non-deployable
      xcvarsFile->setDefinition("DeploymentContent", "false");
    }
  }

  return proj;
}
Exemple #3
0
bool VSSolution::write() const {
    // Open solution file for writing
    std::ofstream ofs;
    openOutputFileStream(ofs, m_absFilePath);
    write(ofs);

    return ofs.is_open();
}