本文整理汇总了C++中PathName::MakeAbsolute方法的典型用法代码示例。如果您正苦于以下问题:C++ PathName::MakeAbsolute方法的具体用法?C++ PathName::MakeAbsolute怎么用?C++ PathName::MakeAbsolute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PathName
的用法示例。
在下文中一共展示了PathName::MakeAbsolute方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: destDir
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;
}
}
}
示例2: absPath
void
File::Delete (/*[in]*/ const PathName & path,
/*[in]*/ bool tryHarder,
/*[in]*/ bool updateFndb)
{
if (updateFndb
&& SessionImpl::GetSession()->IsTEXMFFile(path.Get(), 0, 0)
&& Fndb::FileExists(path))
{
Fndb::Remove (path);
}
FileAttributes attributes = File::GetAttributes(path);
bool done;
try
{
if ((attributes & FileAttributes::ReadOnly) != 0)
{
attributes &= ~ FileAttributes(FileAttributes::ReadOnly);
File::SetAttributes (path, attributes);
}
File::Delete (path);
done = true;
}
catch (const UnauthorizedAccessException &)
{
#if defined(MIKTEX_WINDOWS)
if (! tryHarder)
{
throw;
}
done = false;
#else
throw;
#endif
}
#if defined(MIKTEX_WINDOWS)
if (! done)
{
// move the file out of the way
PathName absPath (path);
if (! Utils::IsAbsolutePath(path.Get()))
{
absPath.MakeAbsolute ();
}
wchar_t szDir[BufferSizes::MaxPath];
if (IsWindowsNT())
{
DllProc3<BOOL, LPCWSTR, LPWSTR, DWORD>
getVolumePathNameW ("Kernel32.dll", "GetVolumePathNameW");
if (! getVolumePathNameW(absPath.ToWideCharString().c_str(),
szDir,
BufferSizes::MaxPath))
{
FATAL_WINDOWS_ERROR ("GetVolumePathNameA", absPath.Get());
}
}
else
{
#if defined(MIKTEX_SUPPORT_LEGACY_WINDOWS)
dir = absPath;
dir.RemoveFileSpec ();
#else
UNSUPPORTED_PLATFORM ();
#endif
}
wchar_t szTemp[BufferSizes::MaxPath];
if (GetTempFileNameW(szDir, L"mik", 0, szTemp) == 0)
{
FATAL_WINDOWS_ERROR ("GetTempFileNameW", WU_(szDir));
}
File::Delete (szTemp);
File::Move (absPath, szTemp);
SessionImpl::GetSession()->ScheduleFileRemoval (PathName(szTemp).Get());
}
#endif
}
示例3: FindSource
bool DviImpl::FindSource(const char* fileName, int line, DviPosition& position)
{
CheckCondition();
BEGIN_CRITICAL_SECTION(dviMutex)
{
trace_search->WriteFormattedLine("libdvi", T_("searching src special %d %s"), line, fileName);
SourceSpecial* pSourceSpecial1Best = nullptr;
SourceSpecial* pSourceSpecial2Best = nullptr;
int pageIdx1 = -1;
int pageIdx2 = -1;
// get fully qualified path to the directory location of the
// document
PathName documentLocation(fqDviFileName);
documentLocation.RemoveFileSpec();
// file name relative to the location of the DVI document
const char* lpszRelFileName;
// absolute file name
PathName fqFileName;
if (Utils::IsAbsolutePath(fileName))
{
lpszRelFileName = Utils::GetRelativizedPath(fileName, documentLocation.GetData());
fqFileName = fileName;
fqFileName.MakeAbsolute();
}
else
{
lpszRelFileName = fileName;
fqFileName = documentLocation;
fqFileName /= fileName;
fqFileName.MakeAbsolute();
}
//
// scan the document
//
for (int pageIdx = 0; pageIdx < GetNumberOfPages(); ++pageIdx)
{
DviPageImpl* dviPage;
try
{
dviPage = reinterpret_cast<DviPageImpl*>(GetLoadedPage(pageIdx));
}
catch (const OperationCancelledException&)
{
return false;
}
if (dviPage == nullptr)
{
throw DviPageNotFoundException("", T_("The DVI page could not be found."), MiKTeXException::KVMAP(), MIKTEX_SOURCE_LOCATION());
}
AutoUnlockPage autoUnlockPage(dviPage);
SourceSpecial* pSourceSpecial1 = nullptr;
SourceSpecial* pSourceSpecial2 = nullptr;
SourceSpecial* pSourceSpecial;
for (int j = -1; (pSourceSpecial = dviPage->GetNextSpecial<SourceSpecial>(j)) != nullptr; )
{
const char* name = pSourceSpecial->GetFileName();
// try exact match
bool nameMatch = (MyPathNameCompare(name, fileName) == 0);
// try fully qualified file names
if (!nameMatch)
{
PathName fqName;
if (Utils::IsAbsolutePath(name))
{
fqName = name;
fqName.MakeAbsolute();
}
else
{
fqName = documentLocation;
fqName /= name;
fqName.MakeAbsolute();
}
nameMatch = (MyPathNameCompare(fqName, fqFileName) == 0);
}
// try relative file names
if (!nameMatch && lpszRelFileName != nullptr)
{
const char* lpszRelName;
if (!Utils::IsAbsolutePath(name))
{
lpszRelName = name;
//.........这里部分代码省略.........
示例4: att
bool
SessionImpl::FindFileInternal (/*[in]*/ const char * lpszFileName,
/*[in]*/ const PathNameArray & directoryPatterns,
/*[in]*/ bool firstMatchOnly,
/*[in]*/ bool useFndb,
/*[in]*/ bool searchFileSystem,
/*[out]*/ vector<PathName> & result)
{
AutoTraceTime att ("find file", lpszFileName);
MIKTEX_ASSERT (useFndb || searchFileSystem);
bool found = false;
// if a fully qualified path name is given, then don't look out any
// further
if (Utils::IsAbsolutePath(lpszFileName))
{
PathName path (lpszFileName);
found = CheckCandidate(path, 0);
if (found)
{
result.push_back (path);
}
return (found);
}
// if an explicitly relative path name is given, then don't look out
// any further
if (IsExplicitlyRelativePath(lpszFileName))
{
PathName pathWD;
for (unsigned idx = 0; ! (found && firstMatchOnly) && GetWorkingDirectory(idx, pathWD); ++ idx)
{
PathName path (pathWD);
path += lpszFileName;
path.MakeAbsolute ();
if (CheckCandidate(path, 0))
{
found = true;
#if FIND_FILE_PREFER_RELATIVE_PATH_NAMES
// 2015-01-15
if (idx == 0)
{
MIKTEX_ASSERT(PathName::Compare(pathWD, PathName().SetToCurrentDirectory()) == 0);
path = lpszFileName;
}
#endif
result.push_back (path);
}
}
return (found);
}
// make use of the file name database
if (useFndb)
{
for (PathNameArray::const_iterator it = directoryPatterns.begin();
! (found && firstMatchOnly) && it != directoryPatterns.end();
++ it)
{
if (found && ! firstMatchOnly && IsMpmFile(it->Get()))
{
// don't trigger the package installer
continue;
}
FileNameDatabase * pFndb = GetFileNameDatabase(it->Get());
if (pFndb != 0)
{
// search fndb
AutoFndbRelease autoRelease (pFndb);
vector<PathName> paths;
vector<string> fileNameInfo;
bool foundInFndb = pFndb->Search(lpszFileName,
it->Get(),
firstMatchOnly,
paths,
fileNameInfo);
// we must release the FNDB handle since CheckCandidate() might request an unload of the FNDB
autoRelease.Reset ();
if (foundInFndb)
{
for (int idx = 0; idx < paths.size(); ++ idx)
{
if (CheckCandidate(paths[idx], fileNameInfo[idx].c_str()))
{
found = true;
result.push_back (paths[idx]);
}
}
}
}
else
{
// search the file system because the file name database does not exist
vector<PathName> paths;
if (SearchFileSystem(lpszFileName, it->Get(), firstMatchOnly, paths))
{
found = true;
//.........这里部分代码省略.........
示例5: path
FileNameDatabaseHeader::FndbOffset
FndbManager::ProcessFolder
(/*[in]*/ FileNameDatabaseHeader::FndbOffset foParent,
/*[in]*/ const char * lpszParentPath,
/*[in]*/ const char * lpszFolderName,
/*[in]*/ FileNameDatabaseHeader::FndbOffset foFolderName)
{
const size_t cReservedEntries = 0;
if (currentLevel > deepestLevel)
{
deepestLevel = currentLevel;
}
vector<string> subDirectoryNames;
subDirectoryNames.reserve (40);
vector<FILENAMEINFO> fileNames;
fileNames.reserve (100);
bool done = false;
PathName path (lpszParentPath, lpszFolderName);
path.MakeAbsolute ();
if (pCallback != 0)
{
if (! pCallback->OnProgress(currentLevel, path.Get()))
{
throw OperationCancelledException ();
}
char * lpszSubDirNames = 0;
char * lpszFileNames = 0;
char * lpszFileNameInfos = 0;
done =
pCallback->ReadDirectory(path.Get(),
&lpszSubDirNames,
&lpszFileNames,
&lpszFileNameInfos);
if (done)
{
AutoMemoryPointer xxx (lpszSubDirNames);
AutoMemoryPointer xxy (lpszFileNames);
AutoMemoryPointer xxz (lpszFileNameInfos);
const char * lpsz = lpszSubDirNames;
while (*lpsz != 0)
{
subDirectoryNames.push_back (lpsz);
lpsz += strlen(lpsz) + 1;
}
lpsz = lpszFileNames;
const char * lpsz2 = lpszFileNameInfos;
while (*lpsz != 0)
{
FILENAMEINFO filenameinfo;
filenameinfo.FileName = lpsz;
lpsz += strlen(lpsz) + 1;
if (lpsz2 != 0)
{
filenameinfo.Info = lpsz2;
lpsz2 += strlen(lpsz2) + 1;
}
fileNames.push_back (filenameinfo);
}
}
}
if (! done)
{
ReadDirectory (path.Get(), subDirectoryNames, fileNames);
}
numDirectories += static_cast<unsigned long>(subDirectoryNames.size());
numFiles += static_cast<unsigned long>(fileNames.size());
sort (subDirectoryNames.begin(),
subDirectoryNames.end(),
StringComparerIgnoringCase());
sort (fileNames.begin(), fileNames.end(), COMPAREFILENAMEINFO());
// store all names; build offset table
vector<FileNameDatabaseHeader::FndbOffset> vecfndboff;
vecfndboff.reserve ((storeFileNameInfo ? 2 : 1) * fileNames.size()
+ 2 * subDirectoryNames.size()
+ cReservedEntries);
vector<FILENAMEINFO>::iterator it;
vector<string>::iterator it2;
for (it = fileNames.begin(); it != fileNames.end(); ++ it)
{
vecfndboff.push_back (PushBack((*it).FileName.c_str()));
}
for (it2 = subDirectoryNames.begin(); it2 != subDirectoryNames.end(); ++ it2)
{
vecfndboff.push_back (PushBack((*it2).c_str()));
}
for (it2 = subDirectoryNames.begin(); it2 != subDirectoryNames.end(); ++ it2)
{
vecfndboff.push_back (null_byte);
}
//.........这里部分代码省略.........
示例6: if
FILE *
File::Open (/*[in]*/ const PathName & path,
/*[in]*/ FileMode mode,
/*[in]*/ FileAccess access,
/*[in]*/ bool isTextFile,
/*[in]*/ FileShare share)
{
UNUSED_ALWAYS (isTextFile);
UNUSED_ALWAYS (share);
SessionImpl::theSession->trace_files->WriteFormattedLine
("core",
T_("opening file %s (%d 0x%x %d %d)"),
Q_(path),
static_cast<int>(mode.Get()),
static_cast<int>(access.Get()),
static_cast<int>(share.Get()),
static_cast<int>(isTextFile));
int flags = 0;
string strFlags;
if (mode == FileMode::Create)
{
flags |= O_CREAT;
}
else if (mode == FileMode::Append)
{
flags |= O_APPEND;
}
if (access == FileAccess::ReadWrite)
{
flags |= O_RDWR;
if (mode == FileMode::Append)
{
strFlags += "a+";
}
else
{
strFlags += "r+";
}
}
else if (access == FileAccess::Read)
{
flags |= O_RDONLY;
strFlags += "r";
}
else if (access == FileAccess::Write)
{
flags |= O_WRONLY;
if (mode == FileMode::Append)
{
strFlags += "a";
}
else
{
flags |= O_TRUNC;
strFlags += "w";
}
}
if (mode == FileMode::Create)
{
PathName dir (path);
dir.MakeAbsolute ();
dir.RemoveFileSpec();
if (! Directory::Exists(dir))
{
Directory::Create (dir);
}
}
int fd;
fd =
open(path.Get(),
flags,
(((flags & O_CREAT) == 0)
? 0
: (0
| S_IRUSR | S_IWUSR
| S_IRGRP
| S_IROTH
| 0)));
if (fd < 0)
{
FATAL_CRT_ERROR ("open", path.Get());
}
try
{
return (FdOpen(fd, strFlags.c_str()));
}
catch (const exception &)
{
close (fd);
throw;
}
//.........这里部分代码省略.........