示例#1
0
bool
File::Exists (/*[in]*/ const PathName & path)
{
  struct stat statbuf;
  if (stat(path.Get(), &statbuf) == 0)
    {
      if (S_ISDIR(statbuf.st_mode) != 0)
	{
	  SessionImpl::theSession->trace_access->WriteFormattedLine
	    ("core",
	     T_("%s is a directory"),
	     Q_(path));
	  return (false);
	}
      SessionImpl::theSession->trace_access->WriteFormattedLine
	("core",
	 T_("accessing file %s: OK"),
	 Q_(path));
      return (true);
    }
  int error = errno;
  if (error != ENOENT)
    {
      FATAL_CRT_ERROR ("stat", path.Get());
    }
  SessionImpl::theSession->trace_access->WriteFormattedLine
    ("core",
     T_("accessing file %s: NOK"),
     Q_(path));
  return (false);
}
示例#2
0
bool
SessionImpl::CheckCandidate (/*[in,out]*/ PathName &	path,
			     /*[in]*/ const char *	lpszFileInfo)
{
  bool found = false;
  if (IsMpmFile(path.Get()))
  {
    PathName trigger (Utils::GetRelativizedPath(path.Get(), MPM_ROOT_PATH));
    PathName installRoot;
    if (lpszFileInfo != 0 && pInstallPackageCallback != 0
	&& pInstallPackageCallback->InstallPackage(
	      lpszFileInfo, trigger.Get(), installRoot))
    {
      PathName temp = installRoot;
      temp += path.Get() + MPM_ROOT_PATH_LEN;
      if (File::Exists(temp))
      {
	path = temp;
	found = true;
      }
    }
  }
  else
  {
    found = File::Exists(path);
  }
  return (found);
}
示例#3
0
void
Directory::SetCurrentDirectory (/*[in]*/ const PathName &	path)
{
  if (chdir(path.Get()) != 0)
    {
      FATAL_CRT_ERROR ("chdir", path.Get());
    }
}
示例#4
0
int
main (/*[in]*/ int		argc,
      /*[in]*/ char **	argv)
{
  try
    {
      SessionWrapper pSession;
      Session::InitInfo initInfo;
      initInfo.SetProgramInvocationName (argv[0]);
      pSession.CreateSession (initInfo);
      if (argc != 2)
	{
	  tcerr << T_("Usage: mkocp OCPFILE") << endl;
	  throw (1);
	}
      PathName otp2ocp;
      if (! pSession->FindFile(T_("otp2ocp"), FileType::EXE, otp2ocp))
	{
	  tcerr << T_("mkocp: otp2ocp executable could not be found.") << endl;
	  throw (1);
	}
      char szFileName[BufferSizes::MaxPath];
      char szExt[BufferSizes::MaxPath];
      PathName::Split (argv[1],
		       0, 0,
		       szFileName, BufferSizes::MaxPath,
		       szExt, BufferSizes::MaxPath);
      PathName outputName;
      if (PathName::Compare(szExt, ".ocp") == 0)
	{
	  outputName = szFileName;
	}
      else
	{
	  outputName.Set (0, szFileName, szExt);
	}
      CommandLineBuilder commandLine;
      commandLine.AppendArgument (outputName.Get());
      Process::Run (otp2ocp.Get(), commandLine.Get());
      tcout << outputName.Get() << ".ocp" << endl;
      return (0);
    }
  catch (const MiKTeXException & e)
    {
      Utils::PrintException (e);
      return (1);
    }
  catch (const exception & e)
    {
      Utils::PrintException (e);
      return (1);
    }
  catch (int exitCode)
    {
      return (exitCode);
    }
}
示例#5
0
size_t
File::GetSize (/*[in]*/ const PathName &	path)
{
  struct stat statbuf;
  if (stat(path.Get(), &statbuf) != 0)
    {
      FATAL_CRT_ERROR ("stat", path.Get());
    }
  return (statbuf.st_size);
}
示例#6
0
void
File::Delete (/*[in]*/ const PathName & path)
{
  SessionImpl::theSession->trace_files->WriteFormattedLine ("core",
							    T_("deleting %s"),
							    Q_(path));

  if (remove(path.Get()) != 0)
    {
      FATAL_CRT_ERROR ("remove", path.Get());
    }
}
示例#7
0
unsigned long
File::GetNativeAttributes (/*[in]*/ const PathName & path)
{
  struct stat statbuf;

  if (stat(path.Get(), &statbuf) != 0)
    {
      FATAL_CRT_ERROR ("stat", path.Get());
    }

  return (static_cast<unsigned long>(statbuf.st_mode));
}
示例#8
0
void
Directory::Delete (/*[in]*/ const PathName & path)
{
  SessionImpl::theSession->trace_files->WriteFormattedLine
    ("core",
     T_("deleting directory %s"),
     Q_(path));

  if (rmdir(path.Get()) != 0)
    {
      FATAL_CRT_ERROR ("rmdir", path.Get());
    }
}
示例#9
0
BOOL
FinishPage::OnWizardFinish ()
{
  BOOL ret = CPropertyPage::OnWizardFinish();
  if (ret)
    {
      try
	{
	  CWnd * pWnd = GetDlgItem(IDC_VIEW_RELNOTES);
	  if (pWnd == 0)
	    {
	      UNEXPECTED_CONDITION ("FinishPage::OnWizardFinish");
	    }
	  if (viewReleaseNotes == BST_CHECKED)
	    {
	      if (pSheet->GetErrorFlag())
		{
		  theApp.showLogFileOnExit = true;
		}
	      else
		{
		  PathName pathRelNotes (theApp.GetInstallRoot(),
					 MIKTEX_PATH_RELNOTES_HTML);
		  if (ShellExecuteW(0,
				    L"open",
				    UW_(pathRelNotes.Get()),
				    0,
				    0,
				    SW_SHOWNORMAL)
		      <= reinterpret_cast<HINSTANCE>(32))
		    {
		      FATAL_MIKTEX_ERROR ("FinishPage::OnWizardFinish",
				  T_("The file could not be opened."),
					  pathRelNotes.Get());
		    }
		}
	    }
	}
      catch (const MiKTeXException & e)
	{
	  pSheet->ReportError (e);
	  ret = FALSE;
	}
      catch (const exception & e)
	{
	  pSheet->ReportError (e);
	  ret = FALSE;
	}
    }
  return (ret);
}
示例#10
0
void
Directory::Delete (/*[in]*/ const PathName &	path,
                            /*[in]*/ bool		recursive)
{
    if (recursive)
    {
        PathNameArray vecFiles;
        vecFiles.reserve (10);

        PathNameArray vecDirectories;
        vecDirectories.reserve (10);

        auto_ptr<DirectoryLister> pLister (DirectoryLister::Open(path));
        DirectoryEntry entry;
        while (pLister->GetNext(entry))
        {
            if (entry.isDirectory)
            {
                vecDirectories.push_back (PathName(path.Get(),
                                                   entry.name.c_str(),
                                                   0));
            }
            else
            {
                vecFiles.push_back (PathName(path.Get(), entry.name.c_str(), 0));
            }
        }
        pLister->Close ();

        PathNameArray::const_iterator it;

        // remove files
        for (it = vecFiles.begin(); it != vecFiles.end(); ++ it)
        {
            File::Delete (*it, true);
        }

        // remove directories recursively
        for (it = vecDirectories.begin(); it != vecDirectories.end(); ++ it)
        {
            // <recursivecall>
            Delete (*it, true);
            // </recursivecall>
        }
    }

    // remove this directory
    Directory::Delete (path);
}
示例#11
0
void
File::GetTimes (/*[in]*/ const PathName &	path,
		/*[out]*/ time_t &		creationTime,
		/*[out]*/ time_t &		lastAccessTime,
		/*[out]*/ time_t &		lastWriteTime)
{
  struct stat stat_;
  if (stat(path.Get(), &stat_) != 0)
    {
      FATAL_CRT_ERROR ("stat", path.Get());
    }
  creationTime = stat_.st_ctime;
  lastAccessTime = stat_.st_atime;
  lastWriteTime = stat_.st_mtime;
}
示例#12
0
void
File::SetNativeAttributes (/*[in]*/ const PathName &	path,
			   /*[in]*/ unsigned long	nativeAttributes)
{
  SessionImpl::theSession->trace_files->WriteFormattedLine
    ("core",
     T_("setting new attributes (%x) on %s"),
     static_cast<int>(nativeAttributes),
     Q_(path));

  if (chmod(path.Get(), static_cast<mode_t>(nativeAttributes)) != 0)
    {
      FATAL_CRT_ERROR ("chmod", path.Get());
    }
}
示例#13
0
miktex_find_input_file (/*[in]*/ const char *	lpszApplicationName,
			/*[in]*/ const char *	lpszFileName,
			/*[out]*/ char *	lpszPath)
{
  C_FUNC_BEGIN ();
  MIKTEX_ASSERT_STRING_OR_NIL (lpszApplicationName);
  MIKTEX_ASSERT_STRING (lpszFileName);
  MIKTEX_ASSERT_PATH_BUFFER (lpszPath);
  PathName temp;
  if (! SessionImpl::GetSession()->FindFile(lpszFileName,
					    FileType::None,
					    temp))
    {
      if (lpszApplicationName == 0)
	{
	  return (0);
	}
      string searchPath = CURRENT_DIRECTORY;
      searchPath += PATH_DELIMITER;
      searchPath += TEXMF_PLACEHOLDER;
      searchPath += MIKTEX_PATH_DIRECTORY_DELIMITER_STRING;
      searchPath += lpszApplicationName;
      searchPath += RECURSION_INDICATOR;
      if (! SessionImpl::GetSession()->FindFile(lpszFileName,
						searchPath.c_str(),
						temp))
	{
	  return (0);
	}
    }
  Utils::CopyString (lpszPath, BufferSizes::MaxPath, temp.Get());
  return (1);
  C_FUNC_END ();
}
示例#14
0
void
PostScript::DoSpecial (/*[in]*/ DvipsSpecial * pdvipsspecial)
{
  Execute ("%d %d a\n",
    pdvipsspecial->GetX() - pDviImpl->GetResolution(),
    pdvipsspecial->GetY() - pDviImpl->GetResolution());
  if (pdvipsspecial->GetProtection())
  {
    Execute ("@beginspecial\n");
    Execute ("@setspecial\n");
  }
  if (pdvipsspecial->GetString())
  {
    Execute ("%s\n", pdvipsspecial->GetString());
  }
  else if (pdvipsspecial->GetFileName())
  {
    PathName filename;
    if (! FindGraphicsFile(pdvipsspecial->GetFileName(), filename))
    {
      FATAL_MIKTEX_ERROR ("PostScript::DoSpecial",
	T_("Cannot find file."), pdvipsspecial->GetFileName());
    }
    ExecuteEncapsulatedPostScript (filename.Get());
  }
  if (pdvipsspecial->GetProtection())
  {
    Execute("@endspecial\n");
  }
}
bool
MakeXEmacsCommandLine (/*[out]*/ string &	program,
		       /*[out]*/ string &	arguments)
{
  PathName emacsDir;
  if (! ReadPath(
    HKEY_LOCAL_MACHINE,
    L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\xemacs.exe",
    L"Path",
    emacsDir))
  {
    return (false);
  }
  PathName pathEmacs;
  pathEmacs = emacsDir;
  pathEmacs += "runemacs.exe";
  if (! File::Exists(pathEmacs))
  {
    pathEmacs = emacsDir;
    pathEmacs += "xemacs.exe";
    if (! File::Exists(pathEmacs))
    {
      return (false);
    }
  }
  program = pathEmacs.Get();
  arguments = "+%l \"%f\"";
  return (true);
}
示例#16
0
Dib::Dib (/*[in]*/ const PathName & path)
  : hFile (INVALID_HANDLE_VALUE),
    hMap (0),
    pBitmapFileHeader (0)
{
  AttachFile (path.Get());
}
示例#17
0
void
File::Move (/*[in]*/ const PathName &	source,
	    /*[in]*/ const PathName &	dest)
{
  struct stat sourceStat;
  if (stat(source.Get(), &sourceStat) != 0)
    {
      FATAL_CRT_ERROR ("stat", source.Get());
    }

  PathName destDir (dest);
  destDir.MakeAbsolute ();
  destDir.RemoveFileSpec ();
  struct stat destStat;
  if (stat(destDir.Get(), &destStat) != 0)
    {
      FATAL_CRT_ERROR ("stat", destDir.Get());
    }
  
  bool sameDevice = (sourceStat.st_dev == destStat.st_dev);

  if (sameDevice)
    {
      SessionImpl::theSession->trace_files->WriteFormattedLine
	("core",
	 T_("renaming %s to %s"),
	 Q_(source),
	 Q_(dest));
      if (rename(source.Get(), dest.Get()) != 0)
	{
	  FATAL_CRT_ERROR ("rename", source.Get());
	}
    }
  else
    {
      Copy (source, dest);
      try
	{
	  Delete (source);
	}
      catch (const MiKTeXException &)
	{
	  try
	    {
	      if (Exists(source))
		{
		  Delete (dest);
		}
	    }
	  catch (const MiKTeXException &)
	    {
	    }
	  throw;
	}
    }
}
示例#18
0
void
PostScript::SendHeader (/*[in]*/ const char * lpszHeaderName)
{
  PathName fileName;
  if (! SessionWrapper(true)->FindFile(lpszHeaderName, FileType::PSHEADER, fileName))
  {
    FATAL_MIKTEX_ERROR (T_("PostScript::SendHeader"),
      T_("Cannot find PostScript header file."), lpszHeaderName);
  }
  tracePS->WriteFormattedLine ("libdvi", T_("Sending %s..."), Q_(fileName));
  ExecuteBatch (fileName.Get());
}
示例#19
0
void
Process::Run (/*[in]*/ const PathName &		fileName,
	      /*[in]*/ const char *		lpszArguments,
	      /*[int]*/ IRunProcessCallback *	pCallback)
{
  if (! Run(fileName, lpszArguments, pCallback, 0, 0))
    {
      FATAL_MIKTEX_ERROR ("Process::Run",
			  T_("The operation failed for some reason."),
			  fileName.Get());
    }
}
bool
MakeLaTeXWIDECommandLine (/*[out]*/ string &	program,
			  /*[out]*/ string &	arguments)
{
  PathName path;
  if (! LocateProgram("LaTeX WIDE", "LWide.exe", path))
  {
    return (false);
  }
  program = path.Get();
  arguments = "\"%f\" /l%l";
  return (true);
}
bool
MakeWinShellCommandLine (/*[out]*/ string &	program,
			 /*[out]*/ string &	arguments)
{
  PathName path;
  if (! LocateProgram("WinShell", "WinShell.exe", path))
  {
    return (false);
  }
  program = path.Get();
  arguments = "-c \"%f\" -l %l";
  return (true);
}
bool
MakeWinEdtCommandLine (/*[out]*/ string &	program,
		       /*[out]*/ string &	arguments)
{
  PathName pathWinEdt;
  if (! LocateWinEdt(pathWinEdt))
  {
    return (false);
  }
  program = pathWinEdt.Get();
  arguments = "\"[Open(|%f|);SelPar(%l,8)]\"";
  return (true);
}
bool
MakeVisualTeXCommandLine (/*[out]*/ string &	program,
			  /*[out]*/ string &	arguments)
{
  PathName path;
  if (! LocateProgram("Visual-TeX", "vtex.exe", path))
  {
    return (false);
  }
  program = path.Get();
  arguments = "\"%f\" /line:%l";
  return (true);
}
bool
MakeTeXnicCenterCommandLine (/*[out]*/ string &	program,
			     /*[out]*/ string &	arguments)
{
  PathName tc;
  if (! LocateTeXnicCenter(tc))
  {
    return (false);
  }
  program = tc.Get();
  arguments = "/ddecmd \"[goto('%f', '%l')]\"";
  return (true);
}
示例#25
0
void
PostScript::Uncompress (/*[in]*/ const char *	lpszFileName,
			/*[out]*/ PathName &	result)
{
  PathName source;
  if (! pDviImpl->FindGraphicsFile(lpszFileName, source))
  {
    FATAL_MIKTEX_ERROR ("PostScript::Uncompress",
      T_("Cannot find file."), lpszFileName);
  }
  Utils::UncompressFile (source.Get(), result);
  pDviImpl->RememberTempFile(lpszFileName, result);
}
bool
MakeNTEmacsCommandLine (/*[out]*/ string &	program,
		        /*[out]*/ string &	arguments)
{
  PathName pathEmacs;
  if (! LocateNTEmacs(pathEmacs, "runemacs.exe") && ! LocateNTEmacs(pathEmacs, "emacs.exe"))
  {
    return (false);
  }
  program = pathEmacs.Get();
  arguments = "+%l \"%f\"";
  return (true);
}
示例#27
0
void
PostScript::ExecuteBatch (/*[in]*/ const char * lpszFileName)
{
  string command;
  command.reserve (BufferSizes::MaxPath + 10);
  command = '(';
  PathName pathUnx (lpszFileName);
  pathUnx.Convert (ConvertPathNameFlags(ConvertPathNameFlags::ToUnix)
		   | ConvertPathNameFlags::MakeAbsolute);
  command += pathUnx.Get();
  command += ") run\n";
  Execute ("%s", command.c_str());
}
示例#28
0
bool
Fndb::Refresh (/*[in]*/ const PathName &	path,
	       /*[in]*/ ICreateFndbCallback *	pCallback)
{
  unsigned root = SessionImpl::GetSession()->DeriveTEXMFRoot(path);

  PathName pathFndbPath =
    SessionImpl::GetSession()->GetFilenameDatabasePathName(root);

  return (Fndb::Create(pathFndbPath.Get(),
		       SessionImpl::GetSession()->GetRootDirectory(root).Get(),
		       pCallback));
}
bool
MakeLaTeXMngCommandLine (/*[out]*/ string &	program,
			 /*[out]*/ string &	arguments)
{
  PathName path;
  if (! LocateProgram("LaTeXMng", "LaTeXMng.exe", path))
  {
    return (false);
  }
  program = path.Get();
  //latexmng -l%l %f
  arguments = "-l%l \"%f\"";
  return (true);
}
示例#30
0
void
Process::Run (/*[in]*/ const PathName &	fileName,
	      /*[in]*/ const char *	lpszArguments)
{
  if (! Process::Run (fileName,
		      lpszArguments,
		      reinterpret_cast<IRunProcessCallback*>(0),
		      0,
		      0))
    {
      FATAL_MIKTEX_ERROR ("Process::Run",
			  T_("The operation failed for some reason."),
			  fileName.Get());
    }
}