Example #1
0
Catalog *SourceDigger::Dig(const wxArrayString& paths,
                           const wxArrayString& excludePaths,
                           const wxArrayString& keywords,
                           const wxString& charset)
{
    ExtractorsDB db;
    db.Read(wxConfig::Get());

    m_progressInfo->UpdateMessage(_("Scanning files..."));

    wxArrayString *all_files = FindFiles(paths, excludePaths, db);
    if (all_files == NULL)
        return NULL;

    TempDirectory tmpdir;
    wxArrayString partials;

    for (size_t i = 0; i < db.Data.size(); i++)
    {
        if ( all_files[i].empty() )
            continue; // no files of this kind

        m_progressInfo->UpdateMessage(
            // TRANSLATORS: '%s' is replaced with the kind of the files (e.g. C++, PHP, ...)
            wxString::Format(_("Parsing %s files..."), db.Data[i].Name.c_str()));
        if (!DigFiles(tmpdir, partials, all_files[i], db.Data[i], keywords, charset))
        {
            delete[] all_files;
            return NULL;
        }
    }

    delete[] all_files;

    if ( partials.empty() )
        return NULL; // couldn't parse any source files

    wxString mergedFile = tmpdir.CreateFileName("merged.pot");

    if ( !ConcatCatalogs(partials, mergedFile) )
        return NULL;

    Catalog *c = new Catalog(mergedFile, Catalog::CreationFlag_IgnoreHeader);

    if ( !c->IsOk() )
    {
        wxLogError(_("Failed to load extracted catalog."));
        delete c;
        return NULL;
    }

    return c;
}
Example #2
0
DWORD VCRedistx86Bootstrap(const TempDirectory& prereqs, const std::wstring& elevateDll)
{
    if (IsVCRedist2015x86Installed())
    {
        return 0;
    }
    auto vcredistX86 = prereqs.Path() + L"\\vc_redist.x86.exe"s;
    println(L"Downloading Visual C++ 2015 redistributable (x86)");
    DownloadStatus status;
    downloadFile(L"https://download.microsoft.com/download/C/E/5/CE514EAE-78A8-4381-86E8-29108D78DBD4/VC_redist.x86.exe", vcredistX86.c_str(), &status);
    println("");
    std::wstring cmdline = vcredistX86 + L" /install /quiet /norestart";
    println(L"Installing Visual C++ 2015 redistributable (x86)");
    LPSTARTUPINFO si;
    LPPROCESS_INFORMATION pi;
    BOOL success = CreateProcessElevatedIfNeeded(const_cast<LPWSTR>(cmdline.c_str()), prereqs.PathCStr(), si, pi, elevateDll.c_str());
    if (!success)
    {
        return GetLastError();
    }

    WaitForSingleObject(pi->hProcess, INFINITE);
    DWORD result;
    GetExitCodeProcess(pi->hProcess, &result);
    CloseHandle(pi->hThread);
    CloseHandle(pi->hProcess);
    println(L"Finished");
    return result;
}
Example #3
0
BOOL NetFxBootstrap(const TempDirectory& prereqs, const std::wstring& elevateDll)
{
    if (IsNetfx46Installed())
    {
        return true;
    }
    auto netFxInstall = prereqs.Path() + L"\\NDP46-KB3045560-Web.exe"s;
    println(L"Downloading .NET 4.6");
    DownloadStatus status;
    //downloadFile(L"https://download.microsoft.com/download/1/4/A/14A6C422-0D3C-4811-A31F-5EF91A83C368/NDP46-KB3045560-Web.exe", netFxInstall.c_str(), &status);
    downloadFile(L"https://download.microsoft.com/download/3/5/9/35980F81-60F4-4DE3-88FC-8F962B97253B/NDP461-KB3102438-Web.exe", netFxInstall.c_str(), &status);
    println("");
    std::wstring args = L"/q /norestart /ChainingPackage Winston";
    println(L"Installing .NET 4.6");
    auto result = Server().Launch(args, netFxInstall, prereqs.Path(), elevateDll);
    print(L"result ");
    println(result);
    return result;
}
Example #4
0
bool SourceDigger::DigFiles(TempDirectory& tmpdir,
                            wxArrayString& outFiles,
                            const wxArrayString& files,
                            Extractor &extract, const wxArrayString& keywords,
                            const wxString& charset)
{
    wxArrayString batchfiles;
    wxArrayString tempfiles;
    size_t i, last = 0;

    while (last < files.GetCount())
    {
        batchfiles.clear();
        for (i = last; i < last + BATCH_SIZE && i < files.size(); i++)
            batchfiles.Add(files[i]);
        last = i;

        wxString tempfile = tmpdir.CreateFileName("extracted.pot");
        if (!ExecuteGettext(
                    extract.GetCommand(batchfiles, keywords, tempfile, charset)))
        {
            return false;
        }

        tempfiles.push_back(tempfile);

        m_progressInfo->UpdateGauge((int)batchfiles.GetCount());

        if (m_progressInfo->Cancelled())
            return false;
    }

    if ( tempfiles.empty() )
        return false; // failed to parse any source files

    wxString outfile = tmpdir.CreateFileName("merged_chunks.pot");
    if ( !ConcatCatalogs(tempfiles, outfile) )
        return false;

    outFiles.push_back(outfile);
    return true;
}
    wxString Extract(TempDirectory& tmpdir,
                     const SourceCodeSpec& sourceSpec,
                     const std::vector<wxString>& files) const override
    {
        auto basepath = sourceSpec.BasePath;
#ifdef __WXMSW__
        basepath = CliSafeFileName(basepath);
        basepath.Replace("\\", "/");
#endif

        wxTextFile filelist;
        filelist.Create(tmpdir.CreateFileName("gettext_filelist.txt"));
        for (auto fn: files)
        {
#ifdef __WXMSW__
            // Gettext tools can't handle Unicode filenames well (due to using
            // char* arguments), so work around this by using the short names.
            if (!fn.IsAscii())
            {
                fn = CliSafeFileName(fn);
                fn.Replace("\\", "/");
            }
#endif
            filelist.AddLine(fn);
        }
        filelist.Write(wxTextFileType_Unix, wxConvFile);

        auto outfile = tmpdir.CreateFileName("gettext.pot");

        wxString cmdline;
        cmdline.Printf
        (
            "xgettext --force-po -o %s --directory=%s --files-from=%s --from-code=%s",
            QuoteCmdlineArg(outfile),
            QuoteCmdlineArg(basepath),
            QuoteCmdlineArg(filelist.GetName()),
            QuoteCmdlineArg(!sourceSpec.Charset.empty() ? sourceSpec.Charset : "UTF-8")
        );

        auto additional = GetAdditionalFlags();
        if (!additional.empty())
            cmdline += " " + additional;

        for (auto& kw: sourceSpec.Keywords)
        {
            cmdline += wxString::Format(" -k%s", QuoteCmdlineArg(kw));
        }

        wxString extraFlags;
        try
        {
            extraFlags = sourceSpec.XHeaders.at("X-Poedit-Flags-xgettext");
        }
        catch (std::out_of_range) {}

        if (!extraFlags.Contains("--add-comments"))
            cmdline += " --add-comments=TRANSLATORS:";

        if (!extraFlags.empty())
            cmdline += " " + extraFlags;

        if (!ExecuteGettext(cmdline))
            return "";

        return outfile;
    }
Example #6
0
void
dvipdft (/*[in]*/ int		argc,
	 /*[in]*/ const char **	argv)
{
  // must have at least one argument: the DVI file name
  if (argc == 1)
    {
      BadUsage ();
    }

  char szGSExePath[BufferSizes::MaxPath];
  SessionWrapper(true)->GetGhostscript (szGSExePath, 0);

  PathName dvipdfmExe;
  if (! SessionWrapper(true)->FindFile("dvipdfm",
				       FileType::EXE,
				       dvipdfmExe))
    {
      FatalError (MIKTEXTEXT("The Dvipdfm executable could not be found."));
    }

  // create a temporary directory
  TempDirectory tempDir;

  CommandLineBuilder arguments;
  PathName fileNoExt;

  // loop over all arguments except the last one
  for (int i = 1; i < argc - 1; ++ i)
    {
      arguments.AppendArgument (argv[i]);
      if (strcmp(argv[i], "-o") == 0 && i + 1 < argc - 1)
	{
	  ++ i;
	  arguments.AppendArgument (argv[i]);
	  fileNoExt = argv[i];
	  fileNoExt.SetExtension (0);
	}
    }

  const char * lpszUserFilename = argv[argc - 1];
  if (fileNoExt.GetLength() == 0)
    {
      fileNoExt = lpszUserFilename;
      fileNoExt.SetExtension (0);
    }

  // run dvipdfm with the fastest options for the first pass
  arguments.AppendOption ("-e");
  arguments.AppendOption ("-z", "0");
  arguments.AppendArgument (lpszUserFilename);
  int exitCode = 0;
  if (! Process::Run(dvipdfmExe.Get(), arguments.Get(), 0, &exitCode, 0))
    {
      FatalError (MIKTEXTEXT("%s could not be started."), dvipdfmExe.Get());
    }
  if (exitCode != 0)
    {
      throw (exitCode);
    }

  // run GhostScript to create thumbnails
  PathName outFileTemplate (tempDir.Get(), fileNoExt.Get(), "%d");
  arguments.Clear ();
  arguments.AppendOption ("-r", "10");
  arguments.AppendOption ("-dNOPAUSE");
  arguments.AppendOption ("-dBATCH");
  arguments.AppendOption ("-sDEVICE:", "png256");
  arguments.AppendOption ("-sOutputFile:", outFileTemplate.Get());
  arguments.AppendArgument (PathName(0, fileNoExt.Get(), ".pdf").Get());
  if (! Process::Run(szGSExePath, arguments.Get(), 0, &exitCode, 0))
    {
      FatalError (MIKTEXTEXT("%s could not be started."), szGSExePath);
    }
  if (exitCode != 0)
    {
      throw (exitCode);
    }

  // run dvipdfm with the users specified options for the last pass
  arguments.Clear ();
  arguments.AppendOption ("-dt");
  arguments.AppendArguments (argc - 1, &argv[1]);
  printf ("dvipdfm %s\n", arguments.Get());
  Utils::SetEnvironmentString ("MIKTEX_TEMP", tempDir.Get());
  if (! Process::Run(dvipdfmExe.Get(), arguments.Get(), 0, &exitCode, 0))
    {
      FatalError (MIKTEXTEXT("%s could not be started."), dvipdfmExe.Get());
    }
  if (exitCode != 0)
    {
      throw (exitCode);
    }

  tempDir.Delete ();
}