Exemple #1
0
bool uncompress(const ustring & archive, const ustring & directory)
// Uncompresses "archive" into "directory".
// Returns whether this was successful.
{
  // Bail out if the archive was not recognized.
  if (!compressed_archive_recognized(archive)) {
    gw_critical(_("cannot uncompress unrecognized archive"));
    return false;
  }
  // Ensure that the output directory is there.
  gw_mkdir_with_parents (directory);

  // Get the uncompression identifier.
  int uncompression_identifier = uncompression_identifier_get (archive);

  // Do the uncompression.
  int result = -1;
  switch (uncompression_identifier) {
  case 0:
    {
		gw_message("I'm not yet smart enough to handle the " + archive + " file type");
		break;
    }
  case 1:
    { // If you have a zip utility installed in Windows, etc.
      GwSpawn spawn (Directories->get_unzip());
      spawn.arg ("-o"); // overwrite without prompting
      if (!directory.empty ()) {
        spawn.arg ("-d"); // extract files into exdir
        spawn.arg (directory);
      }
      spawn.arg (archive);
      spawn.progress (_("Unpacking"), false);
      spawn.run ();
      result = 0;
      break;
    }
  case 2:
    {
      GwSpawn spawn(Directories->get_tar());
	  spawn.arg ("--force-local"); // to permit : in filename (like C:\Users\...)
      spawn.arg("-xvzf"); // x=eXtract, z=gunZip, f=Filename to extract
      if (!directory.empty()) {
        spawn.workingdirectory(directory);
      }
      spawn.arg(archive);
      spawn.progress(_("Unpacking"), false);
      spawn.run();
      result = spawn.exitstatus;
	  DEBUG("tar return code="+std::to_string(result));
      break;
    }
  }

  // Return whether things were ok.  
  return (result == 0);
}
Exemple #2
0
ustring XeTeX::run ()
{
  write_document_tex_file ();
  ustring pdf_file;
  if (runtime_check (rtXeTeX)) {
    pdf_file = gw_build_filename (working_directory, "document.pdf");
    bool re_run = false;
    unsigned int run_count = 0;
    do {
      run_count++;
      GwSpawn spawn (runtime_program (rtXeTeX));
      spawn.workingdirectory (working_directory);
      spawn.arg ("document.tex");
      spawn.read ();
      spawn.progress ("Formatting run " + convert_to_string (run_count), true);
      spawn.run ();
      re_run = false;
      for (unsigned int i = 0; i < spawn.standardout.size(); i++) {
        gw_message (spawn.standardout[i]);
        if (spawn.standardout[i].find ("re-run") != string::npos) 
        re_run = true;
      }
      for (unsigned int i = 0; i < spawn.standarderr.size(); i++) {
        gw_critical (spawn.standarderr[i]);
        if (spawn.standarderr[i].find ("re-run") != string::npos) 
          re_run = true;
      }
      // If the formatting process was cancelled, bail out, with no pdf file.
      if (spawn.cancelled) {
        return "";
      }
    } while (re_run && (run_count < 10));
  }
  // Info for user in logfile.
  gw_message (_("All the data for this document is available in temporal folder ") + working_directory + ".");
  gw_message (_("You can tune the files by hand, then run \"xetex document.tex\" in this folder to convert it into a PDF file."));
  return pdf_file;
}