mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
# towards locale-independent pathnames on Linux
c.f. http://www.wildfiregames.com/forum/index.php?showtopic=14541&st=0&p=217250&#entry217250 and 2011-03-19 meeting This was SVN commit r9090.
This commit is contained in:
@@ -203,11 +203,11 @@ VfsPath CColladaManager::GetLoadableFilename(const VfsPath& pathnameNoExtension,
|
||||
// (TODO: the comments and variable names say "pmd" but actually they can
|
||||
// be "psa" too.)
|
||||
|
||||
VfsPath dae(fs::change_extension(pathnameNoExtension, L".dae"));
|
||||
VfsPath dae(Path::ChangeExtension(pathnameNoExtension, L".dae"));
|
||||
if (! VfsFileExists(dae))
|
||||
{
|
||||
// No .dae - got to use the .pmd, assuming there is one
|
||||
return fs::change_extension(pathnameNoExtension, extn);
|
||||
return Path::ChangeExtension(pathnameNoExtension, extn);
|
||||
}
|
||||
|
||||
// There is a .dae - see if there's an up-to-date cached copy
|
||||
@@ -216,7 +216,7 @@ VfsPath CColladaManager::GetLoadableFilename(const VfsPath& pathnameNoExtension,
|
||||
if (g_VFS->GetFileInfo(dae, &fileInfo) < 0)
|
||||
{
|
||||
// This shouldn't occur for any sensible reasons
|
||||
LOGERROR(L"Failed to stat DAE file '%ls'", dae.string().c_str());
|
||||
LOGERROR(L"Failed to stat DAE file '%ls'", dae.c_str());
|
||||
return VfsPath();
|
||||
}
|
||||
|
||||
@@ -240,16 +240,16 @@ VfsPath CColladaManager::GetLoadableFilename(const VfsPath& pathnameNoExtension,
|
||||
extension += extn;
|
||||
|
||||
// realDaePath_ is "[..]/mods/whatever/art/meshes/whatever.dae"
|
||||
fs::wpath realDaePath_;
|
||||
std::wstring realDaePath_;
|
||||
LibError ret = g_VFS->GetRealPath(dae, realDaePath_);
|
||||
debug_assert(ret == INFO::OK);
|
||||
wchar_t realDaeBuf[PATH_MAX];
|
||||
wcscpy_s(realDaeBuf, ARRAY_SIZE(realDaeBuf), realDaePath_.string().c_str());
|
||||
wcscpy_s(realDaeBuf, ARRAY_SIZE(realDaeBuf), realDaePath_.c_str());
|
||||
const wchar_t* realDaePath = wcsstr(realDaeBuf, L"mods/");
|
||||
|
||||
// cachedPmdVfsPath is "cache/mods/whatever/art/meshes/whatever_{hash}.pmd"
|
||||
VfsPath cachedPmdVfsPath = VfsPath(L"cache/") / realDaePath;
|
||||
cachedPmdVfsPath = fs::change_extension(cachedPmdVfsPath, extension);
|
||||
VfsPath cachedPmdVfsPath = Path::Join(L"cache/", realDaePath);
|
||||
cachedPmdVfsPath = Path::ChangeExtension(cachedPmdVfsPath, extension);
|
||||
|
||||
// If it's not in the cache, we'll have to create it first
|
||||
if (! VfsFileExists(cachedPmdVfsPath))
|
||||
|
||||
@@ -71,7 +71,7 @@ void CMapReader::LoadMap(const VfsPath& pathname, CTerrain *pTerrain_,
|
||||
|
||||
m_CameraStartupTarget = INVALID_ENTITY;
|
||||
|
||||
filename_xml = fs::change_extension(pathname, L".xml");
|
||||
filename_xml = Path::ChangeExtension(pathname, L".xml");
|
||||
|
||||
// In some cases (particularly tests) we don't want to bother storing a large
|
||||
// mostly-empty .pmp file, so we let the XML file specify basic terrain instead.
|
||||
@@ -256,7 +256,7 @@ int CMapReader::ApplyData()
|
||||
|
||||
PSRETURN CMapSummaryReader::LoadMap(const VfsPath& pathname)
|
||||
{
|
||||
VfsPath filename_xml = fs::change_extension(pathname, L".xml");
|
||||
VfsPath filename_xml = Path::ChangeExtension(pathname, L".xml");
|
||||
|
||||
CXeromyces xmb_file;
|
||||
if (xmb_file.Load(g_VFS, filename_xml) != PSRETURN_OK)
|
||||
|
||||
@@ -62,7 +62,7 @@ void CMapWriter::SaveMap(const VfsPath& pathname, CTerrain* pTerrain,
|
||||
// write it out
|
||||
packer.Write(pathname);
|
||||
|
||||
VfsPath pathnameXML = fs::change_extension(pathname, L".xml");
|
||||
VfsPath pathnameXML = Path::ChangeExtension(pathname, L".xml");
|
||||
WriteXML(pathnameXML, pWaterMan, pSkyMan, pLightEnv, pCamera, pCinema, pSimulation2);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,10 +40,10 @@ CMeshManager::~CMeshManager()
|
||||
|
||||
CModelDefPtr CMeshManager::GetMesh(const VfsPath& pathname)
|
||||
{
|
||||
const VfsPath name = fs::change_extension(pathname, L"");
|
||||
const VfsPath name = Path::ChangeExtension(pathname, L"");
|
||||
|
||||
// Find the mesh if it's already been loaded and cached
|
||||
mesh_map::iterator iter = m_MeshMap.find(name.string());
|
||||
mesh_map::iterator iter = m_MeshMap.find(name);
|
||||
if (iter != m_MeshMap.end() && !iter->second.expired())
|
||||
return CModelDefPtr(iter->second);
|
||||
|
||||
@@ -53,19 +53,19 @@ CModelDefPtr CMeshManager::GetMesh(const VfsPath& pathname)
|
||||
|
||||
if (pmdFilename.empty())
|
||||
{
|
||||
LOGERROR(L"Could not load mesh '%ls'", pathname.string().c_str());
|
||||
LOGERROR(L"Could not load mesh '%ls'", pathname.c_str());
|
||||
return CModelDefPtr();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
CModelDefPtr model (CModelDef::Load(pmdFilename, name));
|
||||
m_MeshMap[name.string()] = model;
|
||||
m_MeshMap[name] = model;
|
||||
return model;
|
||||
}
|
||||
catch (PSERROR_File&)
|
||||
{
|
||||
LOGERROR(L"Could not load mesh '%ls'", pathname.string().c_str());
|
||||
LOGERROR(L"Could not load mesh '%ls'", pathname.c_str());
|
||||
return CModelDefPtr();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ bool CObjectBase::Load(const VfsPath& pathname)
|
||||
m_VariantGroups.clear();
|
||||
|
||||
m_Pathname = pathname;
|
||||
m_ShortName = fs::basename(pathname);
|
||||
m_ShortName = Path::Basename(pathname);
|
||||
|
||||
|
||||
// Set up the vector<vector<T>> m_Variants to contain the right number
|
||||
@@ -142,11 +142,11 @@ bool CObjectBase::Load(const VfsPath& pathname)
|
||||
|
||||
if (option_name == el_mesh)
|
||||
{
|
||||
currentVariant->m_ModelFilename = VfsPath(L"art/meshes")/(std::wstring)option.GetText().FromUTF8();
|
||||
currentVariant->m_ModelFilename = Path::Join(L"art/meshes", option.GetText().FromUTF8());
|
||||
}
|
||||
else if (option_name == el_texture)
|
||||
{
|
||||
currentVariant->m_TextureFilename = VfsPath(L"art/textures/skins")/(std::wstring)option.GetText().FromUTF8();
|
||||
currentVariant->m_TextureFilename = Path::Join(L"art/textures/skins", option.GetText().FromUTF8());
|
||||
}
|
||||
else if (option_name == el_decal)
|
||||
{
|
||||
@@ -178,7 +178,7 @@ bool CObjectBase::Load(const VfsPath& pathname)
|
||||
}
|
||||
else if (ae.Name == at_file)
|
||||
{
|
||||
anim.m_FileName = VfsPath(L"art/animation")/(std::wstring)ae.Value.FromUTF8();
|
||||
anim.m_FileName = Path::Join(L"art/animation", ae.Value.FromUTF8());
|
||||
}
|
||||
else if (ae.Name == at_speed)
|
||||
{
|
||||
@@ -224,7 +224,7 @@ bool CObjectBase::Load(const VfsPath& pathname)
|
||||
|
||||
if (currentGroup->size() == 0)
|
||||
{
|
||||
LOGERROR(L"Actor group has zero variants ('%ls')", pathname.string().c_str());
|
||||
LOGERROR(L"Actor group has zero variants ('%ls')", pathname.c_str());
|
||||
}
|
||||
|
||||
++currentGroup;
|
||||
@@ -239,7 +239,7 @@ bool CObjectBase::Load(const VfsPath& pathname)
|
||||
}
|
||||
else if (child_name == el_material)
|
||||
{
|
||||
m_Material = VfsPath(L"art/materials")/(std::wstring)child.GetText().FromUTF8();
|
||||
m_Material = Path::Join(L"art/materials", child.GetText().FromUTF8());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ std::vector<u8> CObjectBase::CalculateVariationKey(const std::vector<std::set<CS
|
||||
// and then insert the new ones:
|
||||
for (std::vector<CObjectBase::Prop>::iterator it = var.m_Props.begin(); it != var.m_Props.end(); ++it)
|
||||
if (! it->m_ModelName.empty())
|
||||
chosenProps.insert(make_pair(it->m_PropPointName, it->m_ModelName.string()));
|
||||
chosenProps.insert(make_pair(it->m_PropPointName, it->m_ModelName));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -508,7 +508,7 @@ std::set<CStr> CObjectBase::CalculateRandomVariation(const std::set<CStr>& initi
|
||||
// and then insert the new ones:
|
||||
for (std::vector<CObjectBase::Prop>::iterator it = var.m_Props.begin(); it != var.m_Props.end(); ++it)
|
||||
if (! it->m_ModelName.empty())
|
||||
chosenProps.insert(make_pair(it->m_PropPointName, it->m_ModelName.string()));
|
||||
chosenProps.insert(make_pair(it->m_PropPointName, it->m_ModelName));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -589,7 +589,7 @@ std::vector<std::vector<CStr> > CObjectBase::GetVariantGroups() const
|
||||
{
|
||||
if (! props[k].m_ModelName.empty())
|
||||
{
|
||||
CObjectBase* prop = m_ObjectManager.FindObjectBase(props[k].m_ModelName.string().c_str());
|
||||
CObjectBase* prop = m_ObjectManager.FindObjectBase(props[k].m_ModelName.c_str());
|
||||
if (prop)
|
||||
objectsQueue.push(prop);
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ bool CObjectEntry::BuildVariation(const std::vector<std::set<CStr> >& selections
|
||||
CModelDefPtr modeldef (objectManager.GetMeshManager().GetMesh(m_ModelName));
|
||||
if (!modeldef)
|
||||
{
|
||||
LOGERROR(L"CObjectEntry::BuildVariation(): Model %ls failed to load", m_ModelName.string().c_str());
|
||||
LOGERROR(L"CObjectEntry::BuildVariation(): Model %ls failed to load", m_ModelName.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ bool CObjectEntry::BuildVariation(const std::vector<std::set<CStr> >& selections
|
||||
{
|
||||
// start up idling
|
||||
if (!model->SetAnimation(GetRandomAnimation("idle")))
|
||||
LOGERROR(L"Failed to set idle animation in model \"%ls\"", m_ModelName.string().c_str());
|
||||
LOGERROR(L"Failed to set idle animation in model \"%ls\"", m_ModelName.c_str());
|
||||
}
|
||||
|
||||
// build props - TODO, RC - need to fix up bounds here
|
||||
@@ -173,14 +173,14 @@ bool CObjectEntry::BuildVariation(const std::vector<std::set<CStr> >& selections
|
||||
// Pluck out the special attachpoint 'projectile'
|
||||
if (prop.m_PropPointName == "projectile")
|
||||
{
|
||||
m_ProjectileModelName = prop.m_ModelName.string();
|
||||
m_ProjectileModelName = prop.m_ModelName;
|
||||
continue;
|
||||
}
|
||||
|
||||
CObjectEntry* oe = objectManager.FindObjectVariation(prop.m_ModelName.string().c_str(), selections);
|
||||
CObjectEntry* oe = objectManager.FindObjectVariation(prop.m_ModelName.c_str(), selections);
|
||||
if (!oe)
|
||||
{
|
||||
LOGERROR(L"Failed to build prop model \"%ls\" on actor \"%ls\"", prop.m_ModelName.string().c_str(), m_Base->m_ShortName.c_str());
|
||||
LOGERROR(L"Failed to build prop model \"%ls\" on actor \"%ls\"", prop.m_ModelName.c_str(), m_Base->m_ShortName.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ bool CObjectEntry::BuildVariation(const std::vector<std::set<CStr> >& selections
|
||||
propmodel->ToCModel()->SetAnimation(oe->GetRandomAnimation("idle"));
|
||||
}
|
||||
else
|
||||
LOGERROR(L"Failed to find matching prop point called \"%hs\" in model \"%ls\" for actor \"%ls\"", ppn.c_str(), m_ModelName.string().c_str(), m_Base->m_ShortName.c_str());
|
||||
LOGERROR(L"Failed to find matching prop point called \"%hs\" in model \"%ls\" for actor \"%ls\"", ppn.c_str(), m_ModelName.c_str(), m_Base->m_ShortName.c_str());
|
||||
}
|
||||
|
||||
// setup flags
|
||||
|
||||
@@ -85,7 +85,7 @@ CObjectBase* CObjectManager::FindObjectBase(const CStrW& objectname)
|
||||
|
||||
CObjectBase* obj = new CObjectBase(*this);
|
||||
|
||||
VfsPath pathname(VfsPath(L"art/actors/")/(std::wstring)objectname);
|
||||
VfsPath pathname = Path::Join(L"art/actors/", objectname);
|
||||
|
||||
if (obj->Load(pathname))
|
||||
{
|
||||
@@ -123,7 +123,7 @@ CObjectEntry* CObjectManager::FindObjectVariation(CObjectBase* base, const std::
|
||||
// Look to see whether this particular variation has already been loaded
|
||||
|
||||
std::vector<u8> choices = base->CalculateVariationKey(selections);
|
||||
ObjectKey key (base->m_Pathname.string(), choices);
|
||||
ObjectKey key (base->m_Pathname, choices);
|
||||
|
||||
std::map<ObjectKey, CObjectEntry*>::iterator it = m_Objects.find(key);
|
||||
if (it != m_Objects.end())
|
||||
|
||||
@@ -108,11 +108,11 @@ bool CEmitter::LoadXml(const VfsPath& pathname)
|
||||
|
||||
if( root.GetNodeName() != el_Emitter )
|
||||
{
|
||||
LOGERROR(L"CEmitter::LoadXml: XML root was not \"Emitter\" in file %ls. Load failed.", pathname.string().c_str() );
|
||||
LOGERROR(L"CEmitter::LoadXml: XML root was not \"Emitter\" in file %ls. Load failed.", pathname.c_str() );
|
||||
return( false );
|
||||
}
|
||||
|
||||
m_tag = fs::basename(pathname);
|
||||
m_tag = Path::Basename(pathname);
|
||||
|
||||
//TODO figure out if we need to use Type attribute to construct different emitter types,
|
||||
// probably have to move some of this code into a static factory method or out into ParticleEngine class
|
||||
|
||||
@@ -51,7 +51,7 @@ CSkeletonAnimManager::~CSkeletonAnimManager()
|
||||
// doesn't refer to valid animation file
|
||||
CSkeletonAnimDef* CSkeletonAnimManager::GetAnimation(const VfsPath& pathname)
|
||||
{
|
||||
VfsPath name = fs::change_extension(pathname, L"");
|
||||
VfsPath name = Path::ChangeExtension(pathname, L"");
|
||||
|
||||
// Find if it's already been loaded
|
||||
boost::unordered_map<VfsPath, CSkeletonAnimDef*>::iterator iter = m_Animations.find(name);
|
||||
@@ -65,7 +65,7 @@ CSkeletonAnimDef* CSkeletonAnimManager::GetAnimation(const VfsPath& pathname)
|
||||
|
||||
if (psaFilename.empty())
|
||||
{
|
||||
LOGERROR(L"Could not load animation '%ls'", pathname.string().c_str());
|
||||
LOGERROR(L"Could not load animation '%ls'", pathname.c_str());
|
||||
def = NULL;
|
||||
}
|
||||
else
|
||||
@@ -81,9 +81,9 @@ CSkeletonAnimDef* CSkeletonAnimManager::GetAnimation(const VfsPath& pathname)
|
||||
}
|
||||
|
||||
if (def)
|
||||
LOGMESSAGE(L"CSkeletonAnimManager::GetAnimation(%ls): Loaded successfully", pathname.string().c_str());
|
||||
LOGMESSAGE(L"CSkeletonAnimManager::GetAnimation(%ls): Loaded successfully", pathname.c_str());
|
||||
else
|
||||
LOGERROR(L"CSkeletonAnimManager::GetAnimation(%ls): Failed loading, marked file as bad", pathname.string().c_str());
|
||||
LOGERROR(L"CSkeletonAnimManager::GetAnimation(%ls): Failed loading, marked file as bad", pathname.c_str());
|
||||
|
||||
// Add to map
|
||||
m_Animations[name] = def; // NULL if failed to load - we won't try loading it again
|
||||
|
||||
@@ -56,7 +56,7 @@ CTerrainPropertiesPtr CTerrainProperties::FromXML(const CTerrainPropertiesPtr& p
|
||||
{
|
||||
LOGERROR(
|
||||
L"TerrainProperties: Loading %ls: Root node is not terrains (found \"%hs\")",
|
||||
pathname.string().c_str(),
|
||||
pathname.c_str(),
|
||||
rootName.c_str());
|
||||
return CTerrainPropertiesPtr();
|
||||
}
|
||||
@@ -81,7 +81,7 @@ CTerrainPropertiesPtr CTerrainProperties::FromXML(const CTerrainPropertiesPtr& p
|
||||
{
|
||||
LOGWARNING(
|
||||
L"TerrainProperties: Loading %ls: Unexpected node %hs\n",
|
||||
pathname.string().c_str(),
|
||||
pathname.c_str(),
|
||||
XeroFile.GetElementString(child.GetNodeName()).c_str());
|
||||
// Keep reading - typos shouldn't be showstoppers
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <map>
|
||||
|
||||
#include "lib/ogl.h"
|
||||
#include "lib/path_util.h"
|
||||
#include "lib/res/graphics/ogl_tex.h"
|
||||
|
||||
#include "TerrainTextureEntry.h"
|
||||
@@ -53,7 +54,7 @@ CTerrainTextureEntry::CTerrainTextureEntry(CTerrainPropertiesPtr props, const Vf
|
||||
for (;it!=m_Groups.end();++it)
|
||||
(*it)->AddTerrain(this);
|
||||
|
||||
m_Tag = CStrW(fs::basename(path)).ToUTF8();
|
||||
m_Tag = CStrW(Path::Basename(path)).ToUTF8();
|
||||
}
|
||||
|
||||
CTerrainTextureEntry::~CTerrainTextureEntry()
|
||||
|
||||
@@ -124,8 +124,8 @@ void CTerrainTextureManager::LoadTextures(const CTerrainPropertiesPtr& props, co
|
||||
// 'real' texture name
|
||||
for(size_t i = 0; i < pathnames.size(); i++)
|
||||
{
|
||||
if(boost::algorithm::ends_with(pathnames[i].leaf(), L".cached.dds"))
|
||||
pathnames[i] = pathnames[i].branch_path() / boost::algorithm::erase_last_copy(pathnames[i].leaf(), L".cached.dds");
|
||||
if(boost::algorithm::ends_with(Path::Filename(pathnames[i]), L".cached.dds"))
|
||||
pathnames[i] = Path::Join(Path::Path(pathnames[i]), boost::algorithm::erase_last_copy(Path::Filename(pathnames[i]), L".cached.dds"));
|
||||
}
|
||||
|
||||
// Remove any duplicates created by the stripping
|
||||
@@ -143,14 +143,14 @@ void CTerrainTextureManager::LoadTextures(const CTerrainPropertiesPtr& props, co
|
||||
if(!tex_is_known_extension(pathnames[i]))
|
||||
continue;
|
||||
|
||||
VfsPath pathnameXML = fs::change_extension(pathnames[i], L".xml");
|
||||
VfsPath pathnameXML = Path::ChangeExtension(pathnames[i], L".xml");
|
||||
CTerrainPropertiesPtr myprops;
|
||||
// Has XML file -> attempt to load properties
|
||||
if (VfsFileExists(pathnameXML))
|
||||
{
|
||||
myprops = GetPropertiesFromFile(props, pathnameXML);
|
||||
if (myprops)
|
||||
LOGMESSAGE(L"CTerrainTextureManager: Successfully loaded override xml %ls for texture %ls", pathnameXML.string().c_str(), pathnames[i].string().c_str());
|
||||
LOGMESSAGE(L"CTerrainTextureManager: Successfully loaded override xml %ls for texture %ls", pathnameXML.c_str(), pathnames[i].c_str());
|
||||
}
|
||||
|
||||
// Error or non-existant xml file -> use parent props
|
||||
@@ -163,19 +163,19 @@ void CTerrainTextureManager::LoadTextures(const CTerrainPropertiesPtr& props, co
|
||||
|
||||
void CTerrainTextureManager::RecurseDirectory(const CTerrainPropertiesPtr& parentProps, const VfsPath& path)
|
||||
{
|
||||
//LOGMESSAGE(L"CTextureManager::RecurseDirectory(%ls)", path.string().c_str());
|
||||
//LOGMESSAGE(L"CTextureManager::RecurseDirectory(%ls)", path.c_str());
|
||||
|
||||
CTerrainPropertiesPtr props;
|
||||
|
||||
// Load terrains.xml first, if it exists
|
||||
VfsPath pathname = path/L"terrains.xml";
|
||||
VfsPath pathname = Path::Join(path, L"terrains.xml");
|
||||
if (VfsFileExists(pathname))
|
||||
props = GetPropertiesFromFile(parentProps, pathname);
|
||||
|
||||
// No terrains.xml, or read failures -> use parent props (i.e.
|
||||
if (!props)
|
||||
{
|
||||
LOGMESSAGE(L"CTerrainTextureManager::RecurseDirectory(%ls): no terrains.xml (or errors while loading) - using parent properties", path.string().c_str());
|
||||
LOGMESSAGE(L"CTerrainTextureManager::RecurseDirectory(%ls): no terrains.xml (or errors while loading) - using parent properties", path.c_str());
|
||||
props = parentProps;
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ void CTerrainTextureManager::RecurseDirectory(const CTerrainPropertiesPtr& paren
|
||||
(void)g_VFS->GetDirectoryEntries(path, 0, &subdirectoryNames);
|
||||
for (size_t i=0;i<subdirectoryNames.size();i++)
|
||||
{
|
||||
VfsPath subdirectoryPath = AddSlash(path/subdirectoryNames[i]);
|
||||
VfsPath subdirectoryPath = Path::AddSlash(Path::Join(path, subdirectoryNames[i]));
|
||||
RecurseDirectory(props, subdirectoryPath);
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ CTextureConverter::SettingsFile* CTextureConverter::LoadSettings(const VfsPath&
|
||||
|
||||
if (root.GetNodeName() != el_textures)
|
||||
{
|
||||
LOGERROR(L"Invalid texture settings file \"%ls\" (unrecognised root element)", path.string().c_str());
|
||||
LOGERROR(L"Invalid texture settings file \"%ls\" (unrecognised root element)", path.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -317,14 +317,14 @@ bool CTextureConverter::ConvertTexture(const CTexturePtr& texture, const VfsPath
|
||||
size_t fileSize;
|
||||
if (m_VFS->LoadFile(src, file, fileSize) < 0)
|
||||
{
|
||||
LOGERROR(L"Failed to load texture \"%ls\"", src.string().c_str());
|
||||
LOGERROR(L"Failed to load texture \"%ls\"", src.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
Tex tex;
|
||||
if (tex_decode(file, fileSize, &tex) < 0)
|
||||
{
|
||||
LOGERROR(L"Failed to decode texture \"%ls\"", src.string().c_str());
|
||||
LOGERROR(L"Failed to decode texture \"%ls\"", src.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -334,7 +334,7 @@ bool CTextureConverter::ConvertTexture(const CTexturePtr& texture, const VfsPath
|
||||
// Convert to uncompressed BGRA with no mipmaps
|
||||
if (tex_transform_to(&tex, (tex.flags | TEX_BGR | TEX_ALPHA) & ~(TEX_DXT | TEX_MIPMAPS)) < 0)
|
||||
{
|
||||
LOGERROR(L"Failed to transform texture \"%ls\"", src.string().c_str());
|
||||
LOGERROR(L"Failed to transform texture \"%ls\"", src.c_str());
|
||||
tex_free(&tex);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#define INCLUDED_TEXTURECONVERTER
|
||||
|
||||
#include "lib/file/vfs/vfs.h"
|
||||
#include "lib/posix/posix_pthread.h"
|
||||
#include "lib/external_libraries/sdl.h"
|
||||
|
||||
#include "TextureManager.h"
|
||||
|
||||
@@ -42,7 +42,7 @@ struct TPhash
|
||||
std::size_t operator()(CTextureProperties const& a) const
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
boost::hash_combine(seed, a.m_Path.string());
|
||||
boost::hash_combine(seed, a.m_Path);
|
||||
boost::hash_combine(seed, a.m_Filter);
|
||||
boost::hash_combine(seed, a.m_Wrap);
|
||||
boost::hash_combine(seed, a.m_Aniso);
|
||||
@@ -170,7 +170,7 @@ public:
|
||||
Handle h = ogl_tex_load(m_VFS, path, RES_UNIQUE);
|
||||
if (h <= 0)
|
||||
{
|
||||
LOGERROR(L"Texture failed to load; \"%ls\"", texture->m_Properties.m_Path.string().c_str());
|
||||
LOGERROR(L"Texture failed to load; \"%ls\"", texture->m_Properties.m_Path.c_str());
|
||||
|
||||
// Replace with error texture to make it obvious
|
||||
texture->SetHandle(m_ErrorHandle);
|
||||
@@ -210,7 +210,7 @@ public:
|
||||
// Upload to GL
|
||||
if (!m_DisableGL && ogl_tex_upload(h) < 0)
|
||||
{
|
||||
LOGERROR(L"Texture failed to upload: \"%ls\"", texture->m_Properties.m_Path.string().c_str());
|
||||
LOGERROR(L"Texture failed to upload: \"%ls\"", texture->m_Properties.m_Path.c_str());
|
||||
|
||||
ogl_tex_free(h);
|
||||
|
||||
@@ -287,7 +287,7 @@ public:
|
||||
PrepareCacheKey(texture, hash, version);
|
||||
VfsPath looseCachePath = m_CacheLoader.LooseCachePath(sourcePath, hash, version);
|
||||
|
||||
// LOGWARNING(L"Converting texture \"%ls\"", srcPath.string().c_str());
|
||||
// LOGWARNING(L"Converting texture \"%ls\"", srcPath.c_str());
|
||||
|
||||
CTextureConverter::Settings settings = GetConverterSettings(texture);
|
||||
|
||||
@@ -302,7 +302,7 @@ public:
|
||||
CTexturePtr texture = CreateTexture(textureProps);
|
||||
CTextureConverter::Settings settings = GetConverterSettings(texture);
|
||||
|
||||
if (!m_TextureConverter.ConvertTexture(texture, sourcePath, L"cache"/archiveCachePath, settings))
|
||||
if (!m_TextureConverter.ConvertTexture(texture, sourcePath, Path::Join(L"cache", archiveCachePath), settings))
|
||||
return false;
|
||||
|
||||
while (true)
|
||||
@@ -333,7 +333,7 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGERROR(L"Texture failed to convert: \"%ls\"", texture->m_Properties.m_Path.string().c_str());
|
||||
LOGERROR(L"Texture failed to convert: \"%ls\"", texture->m_Properties.m_Path.c_str());
|
||||
texture->SetHandle(m_ErrorHandle);
|
||||
}
|
||||
texture->m_State = CTexture::LOADED;
|
||||
@@ -403,18 +403,18 @@ public:
|
||||
*/
|
||||
CTextureConverter::Settings GetConverterSettings(const CTexturePtr& texture)
|
||||
{
|
||||
VfsPath srcPath = texture->m_Properties.m_Path;
|
||||
fs::wpath srcPath = texture->m_Properties.m_Path;
|
||||
|
||||
std::vector<CTextureConverter::SettingsFile*> files;
|
||||
VfsPath p;
|
||||
for (VfsPath::iterator it = srcPath.begin(); it != srcPath.end(); ++it)
|
||||
for (fs::wpath::iterator it = srcPath.begin(); it != srcPath.end(); ++it)
|
||||
{
|
||||
VfsPath settingsPath = p/L"textures.xml";
|
||||
VfsPath settingsPath = Path::Join(p, L"textures.xml");
|
||||
m_HotloadFiles[settingsPath].insert(texture);
|
||||
CTextureConverter::SettingsFile* f = GetSettingsFile(settingsPath);
|
||||
if (f)
|
||||
files.push_back(f);
|
||||
p /= *it;
|
||||
p = Path::Join(p, *it);
|
||||
}
|
||||
return m_TextureConverter.ComputeSettings(srcPath.leaf(), files);
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
#include "ps/CLogger.h"
|
||||
#include "ps/XML/RelaxNG.h"
|
||||
|
||||
static fs::wpath MOD_PATH(DataDir()/L"mods/_test.mesh");
|
||||
static fs::wpath CACHE_PATH(DataDir()/L"_testcache");
|
||||
static NativePath MOD_PATH(Path::Join(DataDir(), L"mods/_test.mesh"));
|
||||
static NativePath CACHE_PATH(Path::Join(DataDir(), L"_testcache"));
|
||||
|
||||
const wchar_t* srcDAE = L"collada/sphere.dae";
|
||||
const wchar_t* srcPMD = L"collada/sphere.pmd";
|
||||
@@ -51,15 +51,15 @@ class TestMeshManager : public CxxTest::TestSuite
|
||||
|
||||
// Make sure the required directories doesn't exist when we start,
|
||||
// in case the previous test aborted and left them full of junk
|
||||
if(exists(MOD_PATH))
|
||||
if(DirectoryExists(MOD_PATH))
|
||||
DeleteDirectory(MOD_PATH);
|
||||
if(exists(CACHE_PATH))
|
||||
if(DirectoryExists(CACHE_PATH))
|
||||
DeleteDirectory(CACHE_PATH);
|
||||
|
||||
g_VFS = CreateVfs(20*MiB);
|
||||
|
||||
TS_ASSERT_OK(g_VFS->Mount(L"", MOD_PATH));
|
||||
TS_ASSERT_OK(g_VFS->Mount(L"collada/", DataDir()/L"tests/collada", VFS_MOUNT_MUST_EXIST));
|
||||
TS_ASSERT_OK(g_VFS->Mount(L"collada/", Path::Join(DataDir(), L"tests/collada"), VFS_MOUNT_MUST_EXIST));
|
||||
|
||||
// Mount _testcache onto virtual /cache - don't use the normal cache
|
||||
// directory because that's full of loads of cached files from the
|
||||
@@ -126,7 +126,7 @@ public:
|
||||
|
||||
CModelDefPtr modeldef = meshManager->GetMesh(testPMD);
|
||||
TS_ASSERT(modeldef);
|
||||
if (modeldef) TS_ASSERT_WSTR_EQUALS(modeldef->GetName().string(), testBase);
|
||||
if (modeldef) TS_ASSERT_WSTR_EQUALS(modeldef->GetName(), testBase);
|
||||
}
|
||||
|
||||
void test_load_pmd_without_extension()
|
||||
@@ -135,7 +135,7 @@ public:
|
||||
|
||||
CModelDefPtr modeldef = meshManager->GetMesh(testBase);
|
||||
TS_ASSERT(modeldef);
|
||||
if (modeldef) TS_ASSERT_WSTR_EQUALS(modeldef->GetName().string(), testBase);
|
||||
if (modeldef) TS_ASSERT_WSTR_EQUALS(modeldef->GetName(), testBase);
|
||||
}
|
||||
|
||||
void test_caching()
|
||||
@@ -155,7 +155,7 @@ public:
|
||||
|
||||
CModelDefPtr modeldef = meshManager->GetMesh(testDAE);
|
||||
TS_ASSERT(modeldef);
|
||||
if (modeldef) TS_ASSERT_WSTR_EQUALS(modeldef->GetName().string(), testBase);
|
||||
if (modeldef) TS_ASSERT_WSTR_EQUALS(modeldef->GetName(), testBase);
|
||||
}
|
||||
|
||||
void test_load_dae_caching()
|
||||
@@ -166,7 +166,7 @@ public:
|
||||
VfsPath daeName1 = colladaManager->GetLoadableFilename(testBase, CColladaManager::PMD);
|
||||
VfsPath daeName2 = colladaManager->GetLoadableFilename(testBase, CColladaManager::PMD);
|
||||
TS_ASSERT(!daeName1.empty());
|
||||
TS_ASSERT_WSTR_EQUALS(daeName1.string(), daeName2.string());
|
||||
TS_ASSERT_WSTR_EQUALS(daeName1, daeName2);
|
||||
// TODO: it'd be nice to test that it really isn't doing the DAE->PMD
|
||||
// conversion a second time, but there doesn't seem to be an easy way
|
||||
// to check that
|
||||
@@ -229,7 +229,7 @@ public:
|
||||
copyFile(srcSkeletonDefs, testSkeletonDefs);
|
||||
CModelDefPtr modeldef = meshManager->GetMesh(testDAE);
|
||||
TS_ASSERT(modeldef);
|
||||
if (modeldef) TS_ASSERT_WSTR_EQUALS(modeldef->GetName().string(), testBase);
|
||||
if (modeldef) TS_ASSERT_WSTR_EQUALS(modeldef->GetName(), testBase);
|
||||
|
||||
TS_ASSERT(v.Validate(L"doc", L"<test>2.0</test>"));
|
||||
}
|
||||
|
||||
@@ -32,11 +32,11 @@ public:
|
||||
|
||||
void setUp()
|
||||
{
|
||||
DeleteDirectory(DataDir()/L"_testcache"); // clean up in case the last test run failed
|
||||
DeleteDirectory(Path::Join(DataDir(), L"_testcache")); // clean up in case the last test run failed
|
||||
|
||||
m_VFS = CreateVfs(20*MiB);
|
||||
TS_ASSERT_OK(m_VFS->Mount(L"", DataDir()/L"mods/_test.tex", VFS_MOUNT_MUST_EXIST));
|
||||
TS_ASSERT_OK(m_VFS->Mount(L"cache/", DataDir()/L"_testcache"));
|
||||
TS_ASSERT_OK(m_VFS->Mount(L"", Path::Join(DataDir(), L"mods/_test.tex"), VFS_MOUNT_MUST_EXIST));
|
||||
TS_ASSERT_OK(m_VFS->Mount(L"cache/", Path::Join(DataDir(), L"_testcache")));
|
||||
|
||||
tex_codec_register_all();
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
tex_codec_unregister_all();
|
||||
|
||||
m_VFS.reset();
|
||||
DeleteDirectory(DataDir()/L"_testcache");
|
||||
DeleteDirectory(Path::Join(DataDir(), L"_testcache"));
|
||||
}
|
||||
|
||||
void test_convert_quality()
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "graphics/TextureManager.h"
|
||||
#include "lib/external_libraries/sdl.h"
|
||||
#include "lib/path_util.h"
|
||||
#include "lib/file/vfs/vfs.h"
|
||||
#include "lib/res/h_mgr.h"
|
||||
#include "lib/tex/tex.h"
|
||||
@@ -33,11 +34,11 @@ public:
|
||||
|
||||
void setUp()
|
||||
{
|
||||
DeleteDirectory(DataDir()/L"_testcache"); // clean up in case the last test run failed
|
||||
DeleteDirectory(Path::Join(DataDir(), L"_testcache")); // clean up in case the last test run failed
|
||||
|
||||
m_VFS = CreateVfs(20*MiB);
|
||||
TS_ASSERT_OK(m_VFS->Mount(L"", DataDir()/L"mods/_test.tex", VFS_MOUNT_MUST_EXIST));
|
||||
TS_ASSERT_OK(m_VFS->Mount(L"cache/", DataDir()/L"_testcache"));
|
||||
TS_ASSERT_OK(m_VFS->Mount(L"", Path::Join(DataDir(), L"mods/_test.tex"), VFS_MOUNT_MUST_EXIST));
|
||||
TS_ASSERT_OK(m_VFS->Mount(L"cache/", Path::Join(DataDir(), L"_testcache")));
|
||||
|
||||
h_mgr_init();
|
||||
tex_codec_register_all();
|
||||
@@ -53,7 +54,7 @@ public:
|
||||
h_mgr_shutdown();
|
||||
|
||||
m_VFS.reset();
|
||||
DeleteDirectory(DataDir()/L"_testcache");
|
||||
DeleteDirectory(Path::Join(DataDir(), L"_testcache"));
|
||||
}
|
||||
|
||||
void test_load_basic()
|
||||
|
||||
+2
-2
@@ -1083,7 +1083,7 @@ void CGUI::LoadXmlFile(const VfsPath& Filename, boost::unordered_set<VfsPath>& P
|
||||
}
|
||||
catch (PSERROR_GUI& e)
|
||||
{
|
||||
LOGERROR(L"Errors loading GUI file %ls (%d)", Filename.string().c_str(), e.getCode());
|
||||
LOGERROR(L"Errors loading GUI file %ls (%d)", Filename.c_str(), e.getCode());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1578,7 +1578,7 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite
|
||||
|
||||
if (attr_name == "texture")
|
||||
{
|
||||
image.m_TextureName = VfsPath(L"art/textures/ui")/(std::wstring)attr_value;
|
||||
image.m_TextureName = Path::Join(L"art/textures/ui", attr_value);
|
||||
}
|
||||
else
|
||||
if (attr_name == "size")
|
||||
|
||||
@@ -115,7 +115,7 @@ void CGUIManager::LoadPage(SGUIPage& page)
|
||||
page.gui.reset(new CGUI());
|
||||
page.gui->Initialize();
|
||||
|
||||
VfsPath path = VfsPath(L"gui")/page.name.c_str();
|
||||
VfsPath path = Path::Join(L"gui", page.name.c_str());
|
||||
page.inputs.insert(path);
|
||||
|
||||
CXeromyces xero;
|
||||
@@ -144,7 +144,7 @@ void CGUIManager::LoadPage(SGUIPage& page)
|
||||
|
||||
CStrW name (node.GetText().FromUTF8());
|
||||
TIMER(name.c_str());
|
||||
VfsPath path (VfsPath(L"gui")/name.c_str());
|
||||
VfsPath path = Path::Join(L"gui", name.c_str());
|
||||
page.gui->LoadXmlFile(path, page.inputs);
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ LibError CGUIManager::ReloadChangedFiles(const VfsPath& path)
|
||||
{
|
||||
if (it->inputs.count(path))
|
||||
{
|
||||
LOGMESSAGE(L"GUI file '%ls' changed - reloading page '%ls'", path.string().c_str(), it->name.c_str());
|
||||
LOGMESSAGE(L"GUI file '%ls' changed - reloading page '%ls'", path.c_str(), it->name.c_str());
|
||||
LoadPage(*it);
|
||||
// TODO: this can crash if LoadPage runs an init script which modifies the page stack and breaks our iterators
|
||||
}
|
||||
|
||||
@@ -384,7 +384,7 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, const CStr& SpriteName,
|
||||
// TODO: Should check (nicely) that this is a valid file?
|
||||
SGUIImage Image;
|
||||
|
||||
Image.m_TextureName = VfsPath(L"art/textures/ui")/wstring_from_utf8(SpriteName.substr(10));
|
||||
Image.m_TextureName = Path::Join(L"art/textures/ui", wstring_from_utf8(SpriteName.substr(10)));
|
||||
|
||||
CClientArea ca(CRect(0, 0, 0, 0), CRect(0, 0, 100, 100));
|
||||
Image.m_Size = ca;
|
||||
|
||||
@@ -306,7 +306,7 @@ bool AtlasIsAvailable(void* UNUSED(cbdata))
|
||||
return ATLAS_IsAvailable();
|
||||
}
|
||||
|
||||
CScriptVal LoadMapSettings(void* cbdata, std::wstring pathname)
|
||||
CScriptVal LoadMapSettings(void* cbdata, VfsPath pathname)
|
||||
{
|
||||
CGUIManager* guiManager = static_cast<CGUIManager*> (cbdata);
|
||||
|
||||
@@ -433,8 +433,8 @@ void ForceGC(void* cbdata)
|
||||
|
||||
void DumpSimState(void* UNUSED(cbdata))
|
||||
{
|
||||
fs::wpath path (psLogDir()/L"sim_dump.txt");
|
||||
std::ofstream file (path.external_file_string().c_str(), std::ofstream::out | std::ofstream::trunc);
|
||||
NativePath path = Path::Join(psLogDir(), L"sim_dump.txt");
|
||||
std::ofstream file (StringFromNativePath(path).c_str(), std::ofstream::out | std::ofstream::trunc);
|
||||
g_Game->GetSimulation2()->DumpDebugState(file);
|
||||
}
|
||||
|
||||
@@ -487,7 +487,7 @@ void GuiScriptingInit(ScriptInterface& scriptInterface)
|
||||
scriptInterface.RegisterFunction<void, std::string, &OpenURL>("OpenURL");
|
||||
scriptInterface.RegisterFunction<void, &RestartInAtlas>("RestartInAtlas");
|
||||
scriptInterface.RegisterFunction<bool, &AtlasIsAvailable>("AtlasIsAvailable");
|
||||
scriptInterface.RegisterFunction<CScriptVal, std::wstring, &LoadMapSettings>("LoadMapSettings");
|
||||
scriptInterface.RegisterFunction<CScriptVal, VfsPath, &LoadMapSettings>("LoadMapSettings");
|
||||
scriptInterface.RegisterFunction<CScriptVal, &GetMapSettings>("GetMapSettings");
|
||||
scriptInterface.RegisterFunction<void, entity_id_t, &CameraFollow>("CameraFollow");
|
||||
scriptInterface.RegisterFunction<void, entity_id_t, &CameraFollowFPS>("CameraFollowFPS");
|
||||
|
||||
@@ -41,14 +41,14 @@ static void def_override_gl_upload_caps()
|
||||
}
|
||||
|
||||
|
||||
static const fs::wpath& def_get_log_dir()
|
||||
static const NativePath& def_get_log_dir()
|
||||
{
|
||||
static fs::wpath logDir;
|
||||
static NativePath logDir;
|
||||
if(logDir.empty())
|
||||
{
|
||||
fs::wpath exePathname;
|
||||
NativePath exePathname;
|
||||
(void)sys_get_executable_name(exePathname);
|
||||
logDir = exePathname.branch_path();
|
||||
logDir = Path::Path(exePathname);
|
||||
}
|
||||
return logDir;
|
||||
}
|
||||
@@ -153,7 +153,7 @@ void ah_override_gl_upload_caps()
|
||||
ah.override_gl_upload_caps();
|
||||
}
|
||||
|
||||
const fs::wpath& ah_get_log_dir()
|
||||
const NativePath& ah_get_log_dir()
|
||||
{
|
||||
return ah.get_log_dir();
|
||||
}
|
||||
|
||||
@@ -91,6 +91,8 @@ extern const wchar_t*, translate, (const wchar_t* text), (text), return)
|
||||
#ifndef INCLUDED_APP_HOOKS
|
||||
#define INCLUDED_APP_HOOKS
|
||||
|
||||
#include "lib/native_path.h"
|
||||
|
||||
// trampolines for user code to call the hooks. they encapsulate
|
||||
// the details of how exactly to do this.
|
||||
|
||||
@@ -115,7 +117,7 @@ extern void ah_override_gl_upload_caps();
|
||||
*
|
||||
* @return path ending with directory separator (e.g. '/').
|
||||
**/
|
||||
extern const fs::wpath& ah_get_log_dir();
|
||||
extern const NativePath& ah_get_log_dir();
|
||||
|
||||
/**
|
||||
* gather all app-related logs/information and write it to file.
|
||||
@@ -177,7 +179,7 @@ extern ErrorReactionInternal ah_display_error(const wchar_t* text, size_t flags)
|
||||
struct AppHooks
|
||||
{
|
||||
void (*override_gl_upload_caps)();
|
||||
const fs::wpath& (*get_log_dir)();
|
||||
const NativePath& (*get_log_dir)();
|
||||
void (*bundle_logs)(FILE* f);
|
||||
const wchar_t* (*translate)(const wchar_t* text);
|
||||
void (*translate_free)(const wchar_t* text);
|
||||
|
||||
@@ -32,7 +32,13 @@
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <queue> // std::priority_queue
|
||||
#include <boost/unordered_map.hpp>
|
||||
|
||||
#if CONFIG_ENABLE_BOOST
|
||||
# include <boost/unordered_map.hpp>
|
||||
# define MAP boost::unordered_map
|
||||
#else
|
||||
# define MAP STL_HASH_MAP
|
||||
#endif
|
||||
|
||||
/*
|
||||
Cache for items of variable size and value/"cost".
|
||||
@@ -307,7 +313,7 @@ again:
|
||||
}
|
||||
|
||||
protected:
|
||||
class Map : public boost::unordered_map<Key, Entry>
|
||||
class Map : public MAP<Key, Entry>
|
||||
{
|
||||
public:
|
||||
static Entry& entry_from_it(typename Map::iterator it) { return it->second; }
|
||||
|
||||
+4
-4
@@ -36,7 +36,7 @@
|
||||
// causing a warning if the tested macro is undefined.
|
||||
// - allow override via compiler settings by checking #ifndef.
|
||||
|
||||
// pre-compiled headers
|
||||
// precompiled headers
|
||||
#ifndef CONFIG_ENABLE_PCH
|
||||
# define CONFIG_ENABLE_PCH 1 // improve build performance
|
||||
#endif
|
||||
@@ -68,12 +68,12 @@
|
||||
|
||||
// static type checking with Dehydra
|
||||
#ifndef CONFIG_DEHYDRA
|
||||
# define CONFIG_DEHYDRA 0
|
||||
# define CONFIG_DEHYDRA 0
|
||||
#endif
|
||||
|
||||
// include Boost filesystem and shared_ptr in PCH?
|
||||
// allow the use of Boost? (affects PCH and several individual modules)
|
||||
#ifndef CONFIG_ENABLE_BOOST
|
||||
# define CONFIG_ENABLE_BOOST 1
|
||||
# define CONFIG_ENABLE_BOOST 1
|
||||
#endif
|
||||
|
||||
#endif // #ifndef INCLUDED_CONFIG
|
||||
|
||||
@@ -174,8 +174,8 @@ LibError debug_WriteCrashlog(const wchar_t* text)
|
||||
return ERR::REENTERED; // NOWARN
|
||||
|
||||
FILE* f;
|
||||
fs::wpath pathname = ah_get_log_dir()/L"crashlog.txt";
|
||||
errno_t err = _wfopen_s(&f, pathname.string().c_str(), L"w");
|
||||
NativePath pathname = Path::Join(ah_get_log_dir(), L"crashlog.txt");
|
||||
errno_t err = _wfopen_s(&f, pathname.c_str(), L"w");
|
||||
if(err != 0)
|
||||
{
|
||||
state = FAILED; // must come before DEBUG_DISPLAY_ERROR
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#if OS_WIN
|
||||
|
||||
#include "lib/path_util.h"
|
||||
#include "lib/sysdep/os/win/wutil.h"
|
||||
#include "lib/external_libraries/dbghelp.h"
|
||||
|
||||
@@ -42,8 +43,8 @@ void dbghelp_ImportFunctions()
|
||||
// application loaded.") and then the system directory, whose
|
||||
// dbghelp.dll is too old. we therefore specify the full path
|
||||
// to our executable directory, which contains a newer dbghelp.dll.
|
||||
const fs::wpath pathname = wutil_DetectExecutablePath()/L"dbghelp.dll";
|
||||
HMODULE hDbghelp = LoadLibraryW(pathname.string().c_str());
|
||||
const NativePath pathname = Path::Join(wutil_DetectExecutablePath(), L"dbghelp.dll");
|
||||
HMODULE hDbghelp = LoadLibraryW(pathname.c_str());
|
||||
debug_assert(hDbghelp);
|
||||
#define FUNC(ret, name, params) p##name = (ret (__stdcall*) params)GetProcAddress(hDbghelp, #name);
|
||||
#include "lib/external_libraries/dbghelp_funcs.h"
|
||||
|
||||
@@ -88,10 +88,10 @@ struct IArchiveWriter
|
||||
* precisely because they aren't in archives, and the cache would
|
||||
* thrash anyway, so this is deemed acceptable.
|
||||
*
|
||||
* @param sourcepathname the path to the source file on the filesystem
|
||||
* @param pathname the path to use for the file inside the archive
|
||||
* @param pathname the actual file to add
|
||||
* @param pathnameInArchive the name to store in the archive
|
||||
**/
|
||||
virtual LibError AddFile(const fs::wpath& sourcepathname, const fs::wpath& pathame) = 0;
|
||||
virtual LibError AddFile(const NativePath& pathname, const NativePath& pathameInArchive) = 0;
|
||||
};
|
||||
|
||||
typedef shared_ptr<IArchiveWriter> PIArchiveWriter;
|
||||
|
||||
@@ -566,7 +566,7 @@ static LibError vfs_opt_init(const char* trace_filename, const char* archive_fn_
|
||||
|
||||
// get next not-yet-existing archive filename.
|
||||
static NextNumberedFilenameState archive_nfi;
|
||||
dir_NextNumberedFilename(&fsPosix, archive_fn_fmt, &archive_nfi, archive_fn);
|
||||
dir_NextNumberedPath::Filename(&fsPosix, archive_fn_fmt, &archive_nfi, archive_fn);
|
||||
|
||||
// get list of existing archives in root dir.
|
||||
// note: this is needed by should_rebuild_main_archive and later in
|
||||
@@ -674,7 +674,7 @@ static LibError build_mini_archive(const char* mini_archive_fn_fmt)
|
||||
char mini_archive_fn[PATH_MAX];
|
||||
static NextNumberedFilenameState nfi;
|
||||
Filesystem_Posix fsPosix;
|
||||
dir_NextNumberedFilename(&fsPosix, mini_archive_fn_fmt, &nfi, mini_archive_fn);
|
||||
dir_NextNumberedPath::Filename(&fsPosix, mini_archive_fn_fmt, &nfi, mini_archive_fn);
|
||||
|
||||
RETURN_ERR(archive_build(mini_archive_fn, V_fns));
|
||||
delete[] V_fns;
|
||||
|
||||
@@ -64,10 +64,10 @@ enum ZipMethod
|
||||
class LFH
|
||||
{
|
||||
public:
|
||||
void Init(const FileInfo& fileInfo, off_t csize, ZipMethod method, u32 checksum, const fs::wpath& pathname)
|
||||
void Init(const FileInfo& fileInfo, off_t csize, ZipMethod method, u32 checksum, const NativePath& pathname)
|
||||
{
|
||||
const fs::path pathname_c = path_from_wpath(pathname);
|
||||
const size_t pathnameLength = pathname_c.string().length();
|
||||
const std::string pathnameUTF8 = utf8_from_wstring(pathname);
|
||||
const size_t pathnameSize = pathnameUTF8.length();
|
||||
|
||||
m_magic = lfh_magic;
|
||||
m_x1 = to_le16(0);
|
||||
@@ -77,10 +77,10 @@ public:
|
||||
m_crc = to_le32(checksum);
|
||||
m_csize = to_le32(u32_from_larger(csize));
|
||||
m_usize = to_le32(u32_from_larger(fileInfo.Size()));
|
||||
m_fn_len = to_le16(u16_from_larger(pathnameLength));
|
||||
m_fn_len = to_le16(u16_from_larger(pathnameSize));
|
||||
m_e_len = to_le16(0);
|
||||
|
||||
memcpy((char*)this + sizeof(LFH), pathname_c.string().c_str(), pathnameLength);
|
||||
memcpy((char*)this + sizeof(LFH), pathnameUTF8.c_str(), pathnameSize);
|
||||
}
|
||||
|
||||
size_t Size() const
|
||||
@@ -112,10 +112,10 @@ cassert(sizeof(LFH) == 30);
|
||||
class CDFH
|
||||
{
|
||||
public:
|
||||
void Init(const FileInfo& fileInfo, off_t ofs, off_t csize, ZipMethod method, u32 checksum, const fs::wpath& pathname, size_t slack)
|
||||
void Init(const FileInfo& fileInfo, off_t ofs, off_t csize, ZipMethod method, u32 checksum, const NativePath& pathname, size_t slack)
|
||||
{
|
||||
const fs::path pathname_c = path_from_wpath(pathname);
|
||||
const size_t pathnameLength = pathname_c.string().length();
|
||||
const std::string pathnameUTF8 = utf8_from_wstring(pathname);
|
||||
const size_t pathnameLength = pathnameUTF8.length();
|
||||
|
||||
m_magic = cdfh_magic;
|
||||
m_x1 = to_le32(0);
|
||||
@@ -132,14 +132,14 @@ public:
|
||||
m_x3 = to_le32(0);
|
||||
m_lfh_ofs = to_le32(u32_from_larger(ofs));
|
||||
|
||||
memcpy((char*)this + sizeof(CDFH), pathname_c.string().c_str(), pathnameLength);
|
||||
memcpy((char*)this + sizeof(CDFH), pathnameUTF8.c_str(), pathnameLength);
|
||||
}
|
||||
|
||||
fs::wpath Pathname() const
|
||||
NativePath Pathname() const
|
||||
{
|
||||
const size_t length = (size_t)read_le16(&m_fn_len);
|
||||
const char* pathname = (const char*)this + sizeof(CDFH); // not 0-terminated!
|
||||
return wstring_from_utf8(std::string(pathname, length));
|
||||
return NativePathFromString(std::string(pathname, length));
|
||||
}
|
||||
|
||||
off_t HeaderOffset() const
|
||||
@@ -264,12 +264,12 @@ public:
|
||||
return 'A';
|
||||
}
|
||||
|
||||
virtual fs::wpath Path() const
|
||||
virtual NativePath Path() const
|
||||
{
|
||||
return m_file->Pathname();
|
||||
}
|
||||
|
||||
virtual LibError Load(const std::wstring& UNUSED(name), const shared_ptr<u8>& buf, size_t size) const
|
||||
virtual LibError Load(const NativePath& UNUSED(name), const shared_ptr<u8>& buf, size_t size) const
|
||||
{
|
||||
AdjustOffset();
|
||||
|
||||
@@ -381,7 +381,7 @@ private:
|
||||
class ArchiveReader_Zip : public IArchiveReader
|
||||
{
|
||||
public:
|
||||
ArchiveReader_Zip(const fs::wpath& pathname)
|
||||
ArchiveReader_Zip(const NativePath& pathname)
|
||||
: m_file(new File(pathname, 'r'))
|
||||
{
|
||||
FileInfo fileInfo;
|
||||
@@ -411,10 +411,10 @@ public:
|
||||
if(!cdfh)
|
||||
WARN_RETURN(ERR::CORRUPTED);
|
||||
|
||||
const VfsPath relativePathname(cdfh->Pathname().string()); // convert from fs::wpath
|
||||
const std::wstring name = relativePathname.leaf();
|
||||
if(name != L".") // ignore directories (i.e. paths ending in slash)
|
||||
const VfsPath relativePathname(cdfh->Pathname());
|
||||
if(relativePathname.empty() || !path_is_dir_sep(relativePathname[relativePathname.length()-1])) // ignore directories
|
||||
{
|
||||
const NativePath name = Path::Filename(relativePathname);
|
||||
FileInfo fileInfo(name, cdfh->USize(), cdfh->MTime());
|
||||
shared_ptr<ArchiveFile_Zip> archiveFile(new ArchiveFile_Zip(m_file, cdfh->HeaderOffset(), cdfh->CSize(), cdfh->Checksum(), cdfh->Method()));
|
||||
cb(relativePathname, fileInfo, archiveFile, cbData);
|
||||
@@ -514,7 +514,7 @@ private:
|
||||
off_t m_fileSize;
|
||||
};
|
||||
|
||||
PIArchiveReader CreateArchiveReader_Zip(const fs::wpath& archivePathname)
|
||||
PIArchiveReader CreateArchiveReader_Zip(const NativePath& archivePathname)
|
||||
{
|
||||
return PIArchiveReader(new ArchiveReader_Zip(archivePathname));
|
||||
}
|
||||
@@ -527,7 +527,7 @@ PIArchiveReader CreateArchiveReader_Zip(const fs::wpath& archivePathname)
|
||||
class ArchiveWriter_Zip : public IArchiveWriter
|
||||
{
|
||||
public:
|
||||
ArchiveWriter_Zip(const fs::wpath& archivePathname, bool noDeflate)
|
||||
ArchiveWriter_Zip(const NativePath& archivePathname, bool noDeflate)
|
||||
: m_file(new File(archivePathname, 'w')), m_fileSize(0)
|
||||
, m_unalignedWriter(new UnalignedWriter(m_file, 0))
|
||||
, m_numEntries(0), m_noDeflate(noDeflate)
|
||||
@@ -552,19 +552,19 @@ public:
|
||||
|
||||
(void)pool_destroy(&m_cdfhPool);
|
||||
|
||||
const fs::wpath pathname = m_file->Pathname(); // for truncate()
|
||||
const NativePath pathname = m_file->Pathname(); // (must be retrieved before resetting m_file)
|
||||
m_file.reset();
|
||||
|
||||
m_fileSize += off_t(cd_size+sizeof(ECDR));
|
||||
|
||||
// remove padding added by UnalignedWriter
|
||||
wtruncate(pathname.string().c_str(), m_fileSize);
|
||||
wtruncate(pathname.c_str(), m_fileSize);
|
||||
}
|
||||
|
||||
LibError AddFile(const fs::wpath& sourcepathname, const fs::wpath& pathname)
|
||||
LibError AddFile(const NativePath& pathname, const NativePath& pathnameInArchive)
|
||||
{
|
||||
FileInfo fileInfo;
|
||||
RETURN_ERR(GetFileInfo(sourcepathname, &fileInfo));
|
||||
RETURN_ERR(GetFileInfo(pathname, &fileInfo));
|
||||
const off_t usize = fileInfo.Size();
|
||||
// skip 0-length files.
|
||||
// rationale: zip.cpp needs to determine whether a CDFH entry is
|
||||
@@ -578,14 +578,14 @@ public:
|
||||
return INFO::SKIPPED;
|
||||
|
||||
PFile file(new File);
|
||||
RETURN_ERR(file->Open(sourcepathname, 'r'));
|
||||
RETURN_ERR(file->Open(pathname, 'r'));
|
||||
|
||||
const size_t pathnameLength = pathname.string().length();
|
||||
const size_t pathnameLength = pathnameInArchive.length();
|
||||
|
||||
// choose method and the corresponding codec
|
||||
ZipMethod method;
|
||||
PICodec codec;
|
||||
if(m_noDeflate || IsFileTypeIncompressible(pathname))
|
||||
if(m_noDeflate || IsFileTypeIncompressible(pathnameInArchive))
|
||||
{
|
||||
method = ZIP_METHOD_NONE;
|
||||
codec = CreateCodec_ZLibNone();
|
||||
@@ -615,7 +615,7 @@ public:
|
||||
// build LFH
|
||||
{
|
||||
LFH* lfh = (LFH*)buf.get();
|
||||
lfh->Init(fileInfo, (off_t)csize, method, checksum, pathname);
|
||||
lfh->Init(fileInfo, (off_t)csize, method, checksum, pathnameInArchive);
|
||||
}
|
||||
|
||||
// append a CDFH to the central directory (in memory)
|
||||
@@ -626,7 +626,7 @@ public:
|
||||
if(!cdfh)
|
||||
WARN_RETURN(ERR::NO_MEM);
|
||||
const size_t slack = m_cdfhPool.da.pos - prev_pos - cdfhSize;
|
||||
cdfh->Init(fileInfo, ofs, (off_t)csize, method, checksum, pathname, slack);
|
||||
cdfh->Init(fileInfo, ofs, (off_t)csize, method, checksum, pathnameInArchive, slack);
|
||||
m_numEntries++;
|
||||
|
||||
// write LFH, pathname and cdata to file
|
||||
@@ -638,9 +638,9 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
static bool IsFileTypeIncompressible(const fs::wpath& pathname)
|
||||
static bool IsFileTypeIncompressible(const NativePath& pathname)
|
||||
{
|
||||
const std::wstring extension = fs::extension(pathname);
|
||||
const NativePath extension = Path::Extension(pathname);
|
||||
|
||||
// file extensions that we don't want to compress
|
||||
static const wchar_t* incompressibleExtensions[] =
|
||||
@@ -669,7 +669,7 @@ private:
|
||||
bool m_noDeflate;
|
||||
};
|
||||
|
||||
PIArchiveWriter CreateArchiveWriter_Zip(const fs::wpath& archivePathname, bool noDeflate)
|
||||
PIArchiveWriter CreateArchiveWriter_Zip(const NativePath& archivePathname, bool noDeflate)
|
||||
{
|
||||
return PIArchiveWriter(new ArchiveWriter_Zip(archivePathname, noDeflate));
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
#include "lib/file/archive/archive.h"
|
||||
|
||||
LIB_API PIArchiveReader CreateArchiveReader_Zip(const fs::wpath& archivePathname);
|
||||
LIB_API PIArchiveWriter CreateArchiveWriter_Zip(const fs::wpath& archivePathname, bool noDeflate);
|
||||
LIB_API PIArchiveReader CreateArchiveReader_Zip(const NativePath& archivePathname);
|
||||
LIB_API PIArchiveWriter CreateArchiveWriter_Zip(const NativePath& archivePathname, bool noDeflate);
|
||||
|
||||
#endif // #ifndef INCLUDED_ARCHIVE_ZIP
|
||||
|
||||
@@ -23,15 +23,17 @@
|
||||
#ifndef INCLUDED_FILE_LOADER
|
||||
#define INCLUDED_FILE_LOADER
|
||||
|
||||
#include "lib/native_path.h"
|
||||
|
||||
struct IFileLoader
|
||||
{
|
||||
virtual ~IFileLoader();
|
||||
|
||||
virtual size_t Precedence() const = 0;
|
||||
virtual wchar_t LocationCode() const = 0;
|
||||
virtual fs::wpath Path() const = 0;
|
||||
virtual NativePath Path() const = 0;
|
||||
|
||||
virtual LibError Load(const std::wstring& name, const shared_ptr<u8>& buf, size_t size) const = 0;
|
||||
virtual LibError Load(const NativePath& name, const shared_ptr<u8>& buf, size_t size) const = 0;
|
||||
};
|
||||
|
||||
typedef shared_ptr<IFileLoader> PIFileLoader;
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "lib/file/io/io.h"
|
||||
|
||||
|
||||
RealDirectory::RealDirectory(const fs::wpath& path, size_t priority, size_t flags)
|
||||
RealDirectory::RealDirectory(const NativePath& path, size_t priority, size_t flags)
|
||||
: m_path(path), m_priority(priority), m_flags(flags)
|
||||
{
|
||||
}
|
||||
@@ -46,9 +46,9 @@ RealDirectory::RealDirectory(const fs::wpath& path, size_t priority, size_t flag
|
||||
}
|
||||
|
||||
|
||||
/*virtual*/ LibError RealDirectory::Load(const std::wstring& name, const shared_ptr<u8>& buf, size_t size) const
|
||||
/*virtual*/ LibError RealDirectory::Load(const NativePath& name, const shared_ptr<u8>& buf, size_t size) const
|
||||
{
|
||||
const fs::wpath pathname(m_path/name);
|
||||
const NativePath pathname = Path::Join(m_path, name);
|
||||
|
||||
PFile file(new File);
|
||||
RETURN_ERR(file->Open(pathname, 'r'));
|
||||
@@ -58,9 +58,9 @@ RealDirectory::RealDirectory(const fs::wpath& path, size_t priority, size_t flag
|
||||
}
|
||||
|
||||
|
||||
LibError RealDirectory::Store(const std::wstring& name, const shared_ptr<u8>& fileContents, size_t size)
|
||||
LibError RealDirectory::Store(const NativePath& name, const shared_ptr<u8>& fileContents, size_t size)
|
||||
{
|
||||
const fs::wpath pathname(m_path/name);
|
||||
const NativePath pathname = Path::Join(m_path, name);
|
||||
|
||||
{
|
||||
PFile file(new File);
|
||||
@@ -72,7 +72,7 @@ LibError RealDirectory::Store(const std::wstring& name, const shared_ptr<u8>& fi
|
||||
// length. ftruncate can't be used because Windows' FILE_FLAG_NO_BUFFERING
|
||||
// only allows resizing to sector boundaries, so the file must first
|
||||
// be closed.
|
||||
wtruncate(pathname.string().c_str(), size);
|
||||
wtruncate(pathname.c_str(), size);
|
||||
|
||||
return INFO::OK;
|
||||
}
|
||||
@@ -85,8 +85,8 @@ void RealDirectory::Watch()
|
||||
}
|
||||
|
||||
|
||||
PRealDirectory CreateRealSubdirectory(const PRealDirectory& realDirectory, const std::wstring& subdirectoryName)
|
||||
PRealDirectory CreateRealSubdirectory(const PRealDirectory& realDirectory, const NativePath& subdirectoryName)
|
||||
{
|
||||
const fs::wpath path = AddSlash(realDirectory->Path()/subdirectoryName);
|
||||
const NativePath path = Path::AddSlash(Path::Join(realDirectory->Path(), subdirectoryName));
|
||||
return PRealDirectory(new RealDirectory(path, realDirectory->Priority(), realDirectory->Flags()));
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class RealDirectory : public IFileLoader
|
||||
{
|
||||
NONCOPYABLE(RealDirectory);
|
||||
public:
|
||||
RealDirectory(const fs::wpath& path, size_t priority, size_t flags);
|
||||
RealDirectory(const NativePath& path, size_t priority, size_t flags);
|
||||
|
||||
size_t Priority() const
|
||||
{
|
||||
@@ -45,13 +45,13 @@ public:
|
||||
// IFileLoader
|
||||
virtual size_t Precedence() const;
|
||||
virtual wchar_t LocationCode() const;
|
||||
virtual fs::wpath Path() const
|
||||
virtual NativePath Path() const
|
||||
{
|
||||
return m_path;
|
||||
}
|
||||
virtual LibError Load(const std::wstring& name, const shared_ptr<u8>& buf, size_t size) const;
|
||||
virtual LibError Load(const NativePath& name, const shared_ptr<u8>& buf, size_t size) const;
|
||||
|
||||
LibError Store(const std::wstring& name, const shared_ptr<u8>& fileContents, size_t size);
|
||||
LibError Store(const NativePath& name, const shared_ptr<u8>& fileContents, size_t size);
|
||||
|
||||
void Watch();
|
||||
|
||||
@@ -59,7 +59,7 @@ private:
|
||||
// note: paths are relative to the root directory, so storing the
|
||||
// entire path instead of just the portion relative to the mount point
|
||||
// is not all too wasteful.
|
||||
const fs::wpath m_path;
|
||||
const NativePath m_path;
|
||||
|
||||
const size_t m_priority;
|
||||
|
||||
@@ -72,6 +72,6 @@ private:
|
||||
|
||||
typedef shared_ptr<RealDirectory> PRealDirectory;
|
||||
|
||||
extern PRealDirectory CreateRealSubdirectory(const PRealDirectory& realDirectory, const std::wstring& subdirectoryName);
|
||||
extern PRealDirectory CreateRealSubdirectory(const PRealDirectory& realDirectory, const NativePath& subdirectoryName);
|
||||
|
||||
#endif // #ifndef INCLUDED_REAL_DIRECTORY
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
|
||||
TraceEntry t1(TraceEntry::Load, L"example.txt", 1234);
|
||||
TS_ASSERT_EQUALS(t1.Action(), TraceEntry::Load);
|
||||
TS_ASSERT_WSTR_EQUALS(t1.Pathname().string(), L"example.txt");
|
||||
TS_ASSERT_WSTR_EQUALS(t1.Pathname(), L"example.txt");
|
||||
TS_ASSERT_EQUALS(t1.Size(), (size_t)1234);
|
||||
|
||||
buf1 = t1.EncodeAsText();
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
|
||||
TraceEntry t2(TraceEntry::Store, L"example two.txt", 16777216);
|
||||
TS_ASSERT_EQUALS(t2.Action(), TraceEntry::Store);
|
||||
TS_ASSERT_WSTR_EQUALS(t2.Pathname().string(), L"example two.txt");
|
||||
TS_ASSERT_WSTR_EQUALS(t2.Pathname(), L"example two.txt");
|
||||
TS_ASSERT_EQUALS(t2.Size(), (size_t)16777216);
|
||||
|
||||
buf2 = t2.EncodeAsText();
|
||||
@@ -52,20 +52,20 @@ public:
|
||||
|
||||
TraceEntry t3(buf1);
|
||||
TS_ASSERT_EQUALS(t3.Action(), TraceEntry::Load);
|
||||
TS_ASSERT_WSTR_EQUALS(t3.Pathname().string(), L"example.txt");
|
||||
TS_ASSERT_WSTR_EQUALS(t3.Pathname(), L"example.txt");
|
||||
TS_ASSERT_EQUALS(t3.Size(), (size_t)1234);
|
||||
|
||||
TraceEntry t4(buf2);
|
||||
TS_ASSERT_EQUALS(t4.Action(), TraceEntry::Store);
|
||||
TS_ASSERT_WSTR_EQUALS(t4.Pathname().string(), L"example two.txt");
|
||||
TS_ASSERT_WSTR_EQUALS(t4.Pathname(), L"example two.txt");
|
||||
TS_ASSERT_EQUALS(t4.Size(), (size_t)16777216);
|
||||
}
|
||||
|
||||
void test_maxpath()
|
||||
{
|
||||
std::wstring path1 = std::wstring(PATH_MAX, L'x');
|
||||
NativePath path1(PATH_MAX, L'x');
|
||||
std::wstring buf1 = L"0: L \"" + path1 + L"\" 0\n";
|
||||
TraceEntry t1(buf1);
|
||||
TS_ASSERT_WSTR_EQUALS(t1.Pathname().string(), path1);
|
||||
TS_ASSERT_WSTR_EQUALS(t1.Pathname(), path1);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
TraceEntry::TraceEntry(EAction action, const fs::wpath& pathname, size_t size)
|
||||
TraceEntry::TraceEntry(EAction action, const NativePath& pathname, size_t size)
|
||||
: m_timestamp((float)timer_Time())
|
||||
, m_action(action)
|
||||
, m_pathname(pathname)
|
||||
@@ -74,7 +74,7 @@ TraceEntry::TraceEntry(const std::wstring& text)
|
||||
stream >> dummy;
|
||||
debug_assert(dummy == '"');
|
||||
|
||||
std::wstring pathname;
|
||||
NativePath pathname;
|
||||
std::getline(stream, pathname, L'"');
|
||||
m_pathname = pathname;
|
||||
|
||||
@@ -90,7 +90,7 @@ std::wstring TraceEntry::EncodeAsText() const
|
||||
{
|
||||
const wchar_t action = (wchar_t)m_action;
|
||||
wchar_t buf[1000];
|
||||
swprintf_s(buf, ARRAY_SIZE(buf), L"%#010f: %c \"%ls\" %lu\n", m_timestamp, action, m_pathname.string().c_str(), (unsigned long)m_size);
|
||||
swprintf_s(buf, ARRAY_SIZE(buf), L"%#010f: %c \"%ls\" %lu\n", m_timestamp, action, m_pathname.c_str(), (unsigned long)m_size);
|
||||
return buf;
|
||||
}
|
||||
|
||||
@@ -105,20 +105,20 @@ public:
|
||||
|
||||
}
|
||||
|
||||
virtual void NotifyLoad(const fs::wpath& UNUSED(pathname), size_t UNUSED(size))
|
||||
virtual void NotifyLoad(const NativePath& UNUSED(pathname), size_t UNUSED(size))
|
||||
{
|
||||
}
|
||||
|
||||
virtual void NotifyStore(const fs::wpath& UNUSED(pathname), size_t UNUSED(size))
|
||||
virtual void NotifyStore(const NativePath& UNUSED(pathname), size_t UNUSED(size))
|
||||
{
|
||||
}
|
||||
|
||||
virtual LibError Load(const fs::wpath& UNUSED(pathname))
|
||||
virtual LibError Load(const NativePath& UNUSED(pathname))
|
||||
{
|
||||
return INFO::OK;
|
||||
}
|
||||
|
||||
virtual LibError Store(const fs::wpath& UNUSED(pathname)) const
|
||||
virtual LibError Store(const NativePath& UNUSED(pathname)) const
|
||||
{
|
||||
return INFO::OK;
|
||||
}
|
||||
@@ -156,23 +156,23 @@ public:
|
||||
(void)pool_destroy(&m_pool);
|
||||
}
|
||||
|
||||
virtual void NotifyLoad(const fs::wpath& pathname, size_t size)
|
||||
virtual void NotifyLoad(const NativePath& pathname, size_t size)
|
||||
{
|
||||
new(Allocate()) TraceEntry(TraceEntry::Load, pathname, size);
|
||||
}
|
||||
|
||||
virtual void NotifyStore(const fs::wpath& pathname, size_t size)
|
||||
virtual void NotifyStore(const NativePath& pathname, size_t size)
|
||||
{
|
||||
new(Allocate()) TraceEntry(TraceEntry::Store, pathname, size);
|
||||
}
|
||||
|
||||
virtual LibError Load(const fs::wpath& pathname)
|
||||
virtual LibError Load(const NativePath& pathname)
|
||||
{
|
||||
pool_free_all(&m_pool);
|
||||
|
||||
errno = 0;
|
||||
FILE* file;
|
||||
errno_t err = _wfopen_s(&file, pathname.string().c_str(), L"rt");
|
||||
errno_t err = _wfopen_s(&file, pathname.c_str(), L"rt");
|
||||
if(err != 0)
|
||||
return LibError_from_errno();
|
||||
|
||||
@@ -188,11 +188,11 @@ public:
|
||||
return INFO::OK;
|
||||
}
|
||||
|
||||
virtual LibError Store(const fs::wpath& pathname) const
|
||||
virtual LibError Store(const NativePath& pathname) const
|
||||
{
|
||||
errno = 0;
|
||||
FILE* file;
|
||||
errno_t err = _wfopen_s(&file, pathname.string().c_str(), L"at");
|
||||
errno_t err = _wfopen_s(&file, pathname.c_str(), L"at");
|
||||
if(err != 0)
|
||||
return LibError_from_errno();
|
||||
for(size_t i = 0; i < NumEntries(); i++)
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
#ifndef INCLUDED_TRACE
|
||||
#define INCLUDED_TRACE
|
||||
|
||||
#include "lib/native_path.h"
|
||||
|
||||
// stores information about an IO event.
|
||||
class TraceEntry
|
||||
{
|
||||
@@ -45,7 +47,7 @@ public:
|
||||
Store = 'S'
|
||||
};
|
||||
|
||||
TraceEntry(EAction action, const fs::wpath& pathname, size_t size);
|
||||
TraceEntry(EAction action, const NativePath& pathname, size_t size);
|
||||
TraceEntry(const std::wstring& text);
|
||||
|
||||
EAction Action() const
|
||||
@@ -53,7 +55,7 @@ public:
|
||||
return m_action;
|
||||
}
|
||||
|
||||
const fs::wpath& Pathname() const
|
||||
const NativePath& Pathname() const
|
||||
{
|
||||
return m_pathname;
|
||||
}
|
||||
@@ -76,7 +78,7 @@ private:
|
||||
|
||||
EAction m_action;
|
||||
|
||||
fs::wpath m_pathname;
|
||||
NativePath m_pathname;
|
||||
|
||||
// size of file.
|
||||
// rationale: other applications using this trace format might not
|
||||
@@ -91,8 +93,8 @@ struct ITrace
|
||||
{
|
||||
virtual ~ITrace();
|
||||
|
||||
virtual void NotifyLoad(const fs::wpath& pathname, size_t size) = 0;
|
||||
virtual void NotifyStore(const fs::wpath& pathname, size_t size) = 0;
|
||||
virtual void NotifyLoad(const NativePath& pathname, size_t size) = 0;
|
||||
virtual void NotifyStore(const NativePath& pathname, size_t size) = 0;
|
||||
|
||||
/**
|
||||
* store all entries into a file.
|
||||
@@ -103,7 +105,7 @@ struct ITrace
|
||||
* because storing filename strings in a binary format would be a
|
||||
* bit awkward.
|
||||
**/
|
||||
virtual LibError Store(const fs::wpath& pathname) const = 0;
|
||||
virtual LibError Store(const NativePath& pathname) const = 0;
|
||||
|
||||
/**
|
||||
* load entries from file.
|
||||
@@ -112,7 +114,7 @@ struct ITrace
|
||||
*
|
||||
* replaces any existing entries.
|
||||
**/
|
||||
virtual LibError Load(const fs::wpath& osPathname) = 0;
|
||||
virtual LibError Load(const NativePath& osPathname) = 0;
|
||||
|
||||
virtual const TraceEntry* Entries() const = 0;
|
||||
virtual size_t NumEntries() const = 0;
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#include "precompiled.h"
|
||||
#include "lib/file/file.h"
|
||||
|
||||
#include "lib/posix/posix_filesystem.h"
|
||||
#include "lib/posix/posix_aio.h"
|
||||
#include "lib/file/common/file_stats.h"
|
||||
|
||||
|
||||
@@ -36,7 +38,7 @@ ERROR_ASSOCIATE(ERR::IO, L"Error during IO", EIO);
|
||||
|
||||
namespace FileImpl {
|
||||
|
||||
LibError Open(const fs::wpath& pathname, wchar_t accessType, int& fd)
|
||||
LibError Open(const NativePath& pathname, wchar_t accessType, int& fd)
|
||||
{
|
||||
int oflag = 0;
|
||||
switch(accessType)
|
||||
@@ -59,7 +61,7 @@ LibError Open(const fs::wpath& pathname, wchar_t accessType, int& fd)
|
||||
// prevent exploits by disallowing writes to our files by other users.
|
||||
// note that the system-wide installed cache is read-only.
|
||||
const mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH; // 0644
|
||||
fd = wopen(pathname.string().c_str(), oflag, mode);
|
||||
fd = wopen(pathname.c_str(), oflag, mode);
|
||||
if(fd < 0)
|
||||
return LibError_from_errno(false);
|
||||
|
||||
|
||||
@@ -27,6 +27,10 @@
|
||||
#ifndef INCLUDED_FILE
|
||||
#define INCLUDED_FILE
|
||||
|
||||
struct aiocb;
|
||||
|
||||
#include "lib/native_path.h"
|
||||
|
||||
namespace ERR
|
||||
{
|
||||
const LibError FILE_ACCESS = -110300;
|
||||
@@ -35,7 +39,7 @@ namespace ERR
|
||||
|
||||
namespace FileImpl
|
||||
{
|
||||
LIB_API LibError Open(const fs::wpath& pathname, wchar_t mode, int& fd);
|
||||
LIB_API LibError Open(const NativePath& pathname, wchar_t mode, int& fd);
|
||||
LIB_API void Close(int& fd);
|
||||
LIB_API LibError IO(int fd, wchar_t mode, off_t ofs, u8* buf, size_t size);
|
||||
LIB_API LibError Issue(aiocb& req, int fd, wchar_t mode, off_t alignedOfs, u8* alignedBuf, size_t alignedSize);
|
||||
@@ -51,7 +55,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
LibError Open(const fs::wpath& pathname, wchar_t mode)
|
||||
LibError Open(const NativePath& pathname, wchar_t mode)
|
||||
{
|
||||
RETURN_ERR(FileImpl::Open(pathname, mode, m_fd));
|
||||
m_pathname = pathname;
|
||||
@@ -64,7 +68,7 @@ public:
|
||||
FileImpl::Close(m_fd);
|
||||
}
|
||||
|
||||
File(const fs::wpath& pathname, wchar_t mode)
|
||||
File(const NativePath& pathname, wchar_t mode)
|
||||
{
|
||||
(void)Open(pathname, mode);
|
||||
}
|
||||
@@ -74,7 +78,7 @@ public:
|
||||
Close();
|
||||
}
|
||||
|
||||
const fs::wpath& Pathname() const
|
||||
const NativePath& Pathname() const
|
||||
{
|
||||
return m_pathname;
|
||||
}
|
||||
@@ -100,7 +104,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
fs::wpath m_pathname;
|
||||
NativePath m_pathname;
|
||||
int m_fd;
|
||||
wchar_t m_mode;
|
||||
};
|
||||
|
||||
@@ -42,18 +42,18 @@ struct DirDeleter
|
||||
};
|
||||
|
||||
// is name "." or ".."?
|
||||
static bool IsDummyDirectory(const std::wstring& name)
|
||||
static bool IsDummyDirectory(const NativePath& name)
|
||||
{
|
||||
if(name[0] != '.')
|
||||
return false;
|
||||
return (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'));
|
||||
}
|
||||
|
||||
LibError GetDirectoryEntries(const fs::wpath& path, FileInfos* files, DirectoryNames* subdirectoryNames)
|
||||
LibError GetDirectoryEntries(const NativePath& path, FileInfos* files, DirectoryNames* subdirectoryNames)
|
||||
{
|
||||
// open directory
|
||||
errno = 0;
|
||||
WDIR* pDir = wopendir(path.string().c_str());
|
||||
WDIR* pDir = wopendir(path.c_str());
|
||||
if(!pDir)
|
||||
return LibError_from_errno(false);
|
||||
shared_ptr<WDIR> osDir(pDir, DirDeleter());
|
||||
@@ -70,7 +70,7 @@ LibError GetDirectoryEntries(const fs::wpath& path, FileInfos* files, DirectoryN
|
||||
return LibError_from_errno();
|
||||
}
|
||||
|
||||
const std::wstring name(osEnt->d_name);
|
||||
const NativePath name(osEnt->d_name);
|
||||
RETURN_ERR(path_component_validate(name.c_str()));
|
||||
|
||||
// get file information (mode, size, mtime)
|
||||
@@ -81,8 +81,8 @@ LibError GetDirectoryEntries(const fs::wpath& path, FileInfos* files, DirectoryN
|
||||
#else
|
||||
// .. call regular stat().
|
||||
errno = 0;
|
||||
const fs::wpath pathname(path/name);
|
||||
if(wstat(pathname.string().c_str(), &s) != 0)
|
||||
const NativePath pathname = Path::Join(path, name);
|
||||
if(wstat(pathname.c_str(), &s) != 0)
|
||||
return LibError_from_errno();
|
||||
#endif
|
||||
|
||||
@@ -94,44 +94,48 @@ LibError GetDirectoryEntries(const fs::wpath& path, FileInfos* files, DirectoryN
|
||||
}
|
||||
|
||||
|
||||
LibError GetFileInfo(const fs::wpath& pathname, FileInfo* pfileInfo)
|
||||
LibError GetFileInfo(const NativePath& pathname, FileInfo* pfileInfo)
|
||||
{
|
||||
errno = 0;
|
||||
struct stat s;
|
||||
memset(&s, 0, sizeof(s));
|
||||
if(wstat(pathname.string().c_str(), &s) != 0)
|
||||
if(wstat(pathname.c_str(), &s) != 0)
|
||||
return LibError_from_errno();
|
||||
|
||||
*pfileInfo = FileInfo(pathname.leaf(), s.st_size, s.st_mtime);
|
||||
*pfileInfo = FileInfo(Path::Filename(pathname), s.st_size, s.st_mtime);
|
||||
return INFO::OK;
|
||||
}
|
||||
|
||||
|
||||
LibError CreateDirectories(const fs::wpath& path, mode_t mode)
|
||||
LibError CreateDirectories(const NativePath& path, mode_t mode)
|
||||
{
|
||||
if(path.empty() || fs::exists(path))
|
||||
if(path.empty())
|
||||
return INFO::OK;
|
||||
|
||||
struct stat s;
|
||||
if(wstat(path.c_str(), &s) == 0)
|
||||
{
|
||||
if(!path.empty() && !fs::is_directory(path)) // encountered a file
|
||||
if(!S_ISDIR(s.st_mode)) // encountered a file
|
||||
WARN_RETURN(ERR::FAIL);
|
||||
return INFO::OK;
|
||||
}
|
||||
|
||||
// If we were passed a path ending with '/', strip the '/' now so that
|
||||
// we can consistently use branch_path to find parent directory names
|
||||
if (path.leaf() == L".")
|
||||
return CreateDirectories(path.branch_path(), mode);
|
||||
// we can consistently use Path to find parent directory names
|
||||
if(path_is_dir_sep(path[path.length()-1]))
|
||||
return CreateDirectories(Path::Path(path), mode);
|
||||
|
||||
RETURN_ERR(CreateDirectories(path.branch_path(), mode));
|
||||
RETURN_ERR(CreateDirectories(Path::Path(path), mode));
|
||||
|
||||
errno = 0;
|
||||
if(wmkdir(path.string().c_str(), mode) != 0)
|
||||
if(wmkdir(path.c_str(), mode) != 0)
|
||||
return LibError_from_errno();
|
||||
|
||||
return INFO::OK;
|
||||
}
|
||||
|
||||
|
||||
LibError DeleteDirectory(const fs::wpath& path)
|
||||
LibError DeleteDirectory(const NativePath& path)
|
||||
{
|
||||
// note: we have to recursively empty the directory before it can
|
||||
// be deleted (required by Windows and POSIX rmdir()).
|
||||
@@ -142,18 +146,18 @@ LibError DeleteDirectory(const fs::wpath& path)
|
||||
// delete files
|
||||
for(size_t i = 0; i < files.size(); i++)
|
||||
{
|
||||
const fs::wpath pathname(path/files[i].Name());
|
||||
const NativePath pathname = Path::Join(path, files[i].Name());
|
||||
errno = 0;
|
||||
if(wunlink(pathname.string().c_str()) != 0)
|
||||
if(wunlink(pathname.c_str()) != 0)
|
||||
return LibError_from_errno();
|
||||
}
|
||||
|
||||
// recurse over subdirectoryNames
|
||||
for(size_t i = 0; i < subdirectoryNames.size(); i++)
|
||||
RETURN_ERR(DeleteDirectory(path/subdirectoryNames[i]));
|
||||
RETURN_ERR(DeleteDirectory(Path::Join(path, subdirectoryNames[i])));
|
||||
|
||||
errno = 0;
|
||||
if(wrmdir(path.string().c_str()) != 0)
|
||||
if(wrmdir(path.c_str()) != 0)
|
||||
return LibError_from_errno();
|
||||
|
||||
return INFO::OK;
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
#ifndef INCLUDED_FILE_SYSTEM
|
||||
#define INCLUDED_FILE_SYSTEM
|
||||
|
||||
#include "lib/native_path.h"
|
||||
#include "lib/posix/posix_filesystem.h"
|
||||
|
||||
// (bundling size and mtime avoids a second expensive call to stat())
|
||||
class FileInfo
|
||||
{
|
||||
public:
|
||||
@@ -30,47 +34,43 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
FileInfo(const std::wstring& name, off_t size, time_t mtime)
|
||||
: m_name(name), m_size(size), m_mtime(mtime)
|
||||
FileInfo(const NativePath& name, off_t size, time_t mtime)
|
||||
: name(name), size(size), mtime(mtime)
|
||||
{
|
||||
}
|
||||
|
||||
const std::wstring& Name() const
|
||||
const NativePath& Name() const
|
||||
{
|
||||
return m_name;
|
||||
return name;
|
||||
}
|
||||
|
||||
off_t Size() const
|
||||
{
|
||||
return m_size;
|
||||
return size;
|
||||
}
|
||||
|
||||
time_t MTime() const
|
||||
{
|
||||
return m_mtime;
|
||||
return mtime;
|
||||
}
|
||||
|
||||
private:
|
||||
std::wstring m_name;
|
||||
off_t m_size;
|
||||
time_t m_mtime;
|
||||
NativePath name;
|
||||
off_t size;
|
||||
time_t mtime;
|
||||
};
|
||||
|
||||
extern LibError GetFileInfo(const fs::wpath& pathname, FileInfo* fileInfo);
|
||||
extern LibError GetFileInfo(const NativePath& pathname, FileInfo* fileInfo);
|
||||
|
||||
typedef std::vector<FileInfo> FileInfos;
|
||||
typedef std::vector<std::wstring> DirectoryNames;
|
||||
typedef std::vector<NativePath> DirectoryNames;
|
||||
|
||||
// jw 2007-12-20: we'd love to replace this with boost::filesystem,
|
||||
// but basic_directory_iterator does not yet cache file_size and
|
||||
// last_write_time in file_status. (they each entail a stat() call,
|
||||
// which is unacceptably slow.)
|
||||
extern LibError GetDirectoryEntries(const fs::wpath& path, FileInfos* files, DirectoryNames* subdirectoryNames);
|
||||
extern LibError GetDirectoryEntries(const NativePath& path, FileInfos* files, DirectoryNames* subdirectoryNames);
|
||||
|
||||
// same as fs::create_directories, except that mkdir is invoked with
|
||||
// same as boost::filesystem::create_directories, except that mkdir is invoked with
|
||||
// <mode> instead of 0755.
|
||||
extern LibError CreateDirectories(const fs::wpath& path, mode_t mode);
|
||||
extern LibError CreateDirectories(const NativePath& path, mode_t mode);
|
||||
|
||||
extern LibError DeleteDirectory(const fs::wpath& dirPath);
|
||||
extern LibError DeleteDirectory(const NativePath& dirPath);
|
||||
|
||||
#endif // #ifndef INCLUDED_FILE_SYSTEM
|
||||
|
||||
@@ -48,7 +48,7 @@ LibError GetPathnames(const PIVFS& fs, const VfsPath& path, const wchar_t* filte
|
||||
for(size_t i = 0; i < files.size(); i++)
|
||||
{
|
||||
if(match_wildcard(files[i].Name().c_str(), filter))
|
||||
pathnames.push_back(path/files[i].Name());
|
||||
pathnames.push_back(Path::Join(path, files[i].Name()));
|
||||
}
|
||||
|
||||
return INFO::OK;
|
||||
@@ -69,9 +69,9 @@ void SortFiles(FileInfos& files)
|
||||
}
|
||||
|
||||
|
||||
struct NameLess : public std::binary_function<const std::wstring, const std::wstring, bool>
|
||||
struct NameLess : public std::binary_function<const NativePath, const NativePath, bool>
|
||||
{
|
||||
bool operator()(const std::wstring& name1, const std::wstring& name2) const
|
||||
bool operator()(const NativePath& name1, const NativePath& name2) const
|
||||
{
|
||||
return wcscasecmp(name1.c_str(), name2.c_str()) < 0;
|
||||
}
|
||||
@@ -91,7 +91,7 @@ LibError ForEachFile(const PIVFS& fs, const VfsPath& startPath, FileCallback cb,
|
||||
// (a FIFO queue is more efficient than recursion because it uses less
|
||||
// stack space and avoids seeks due to breadth-first traversal.)
|
||||
std::queue<VfsPath> pendingDirectories;
|
||||
pendingDirectories.push(AddSlash(startPath));
|
||||
pendingDirectories.push(Path::AddSlash(startPath));
|
||||
while(!pendingDirectories.empty())
|
||||
{
|
||||
const VfsPath& path = pendingDirectories.front();
|
||||
@@ -104,7 +104,7 @@ LibError ForEachFile(const PIVFS& fs, const VfsPath& startPath, FileCallback cb,
|
||||
if(!match_wildcard(fileInfo.Name().c_str(), pattern))
|
||||
continue;
|
||||
|
||||
const VfsPath pathname(path/fileInfo.Name()); // (FileInfo only stores the name)
|
||||
const VfsPath pathname(Path::Join(path, fileInfo.Name())); // (FileInfo only stores the name)
|
||||
cb(pathname, fileInfo, cbData);
|
||||
}
|
||||
|
||||
@@ -114,10 +114,10 @@ LibError ForEachFile(const PIVFS& fs, const VfsPath& startPath, FileCallback cb,
|
||||
for(size_t i = 0; i < subdirectoryNames.size(); i++)
|
||||
{
|
||||
VfsPath pathname;
|
||||
if (path.string() == L"/") // special case for startPath == L""
|
||||
pathname = AddSlash(VfsPath(subdirectoryNames[i]));
|
||||
if(path == L"/") // special case for startPath == L""
|
||||
pathname = Path::AddSlash(VfsPath(subdirectoryNames[i]));
|
||||
else
|
||||
pathname = AddSlash(path/subdirectoryNames[i]);
|
||||
pathname = Path::AddSlash(Path::Join(path, subdirectoryNames[i]));
|
||||
|
||||
pendingDirectories.push(pathname);
|
||||
}
|
||||
@@ -137,8 +137,8 @@ void NextNumberedFilename(const PIVFS& fs, const VfsPath& pathnameFormat, size_t
|
||||
// add 3rd -> without this measure it would get number 1, not 3.
|
||||
if(nextNumber == 0)
|
||||
{
|
||||
const std::wstring nameFormat = pathnameFormat.leaf();
|
||||
const VfsPath path = AddSlash(pathnameFormat.branch_path());
|
||||
const NativePath nameFormat = Path::Filename(pathnameFormat);
|
||||
const VfsPath path = Path::AddSlash(Path::Path(pathnameFormat));
|
||||
|
||||
size_t maxNumber = 0;
|
||||
FileInfos files;
|
||||
@@ -161,7 +161,7 @@ void NextNumberedFilename(const PIVFS& fs, const VfsPath& pathnameFormat, size_t
|
||||
do
|
||||
{
|
||||
wchar_t pathnameBuf[PATH_MAX];
|
||||
swprintf_s(pathnameBuf, ARRAY_SIZE(pathnameBuf), pathnameFormat.string().c_str(), nextNumber++);
|
||||
swprintf_s(pathnameBuf, ARRAY_SIZE(pathnameBuf), pathnameFormat.c_str(), nextNumber++);
|
||||
nextPathname = pathnameBuf;
|
||||
}
|
||||
while(fs->GetFileInfo(nextPathname, 0) == INFO::OK);
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "lib/file/io/block_cache.h"
|
||||
|
||||
#include "lib/config2.h" // CONFIG2_CACHE_READ_ONLY
|
||||
#include "lib/posix/posix_mman.h" // mprotect
|
||||
#include "lib/file/common/file_stats.h"
|
||||
#include "lib/lockfree.h"
|
||||
#include "lib/allocators/pool.h"
|
||||
@@ -42,9 +43,9 @@ BlockId::BlockId()
|
||||
{
|
||||
}
|
||||
|
||||
BlockId::BlockId(const fs::wpath& pathname, off_t ofs)
|
||||
BlockId::BlockId(const NativePath& pathname, off_t ofs)
|
||||
{
|
||||
m_id = fnv_hash64(pathname.string().c_str(), pathname.string().length()*sizeof(pathname.string()[0]));
|
||||
m_id = fnv_hash64(pathname.c_str(), pathname.length()*sizeof(pathname[0]));
|
||||
const size_t indexBits = 16;
|
||||
m_id <<= indexBits;
|
||||
const off_t blockIndex = off_t(ofs / BLOCK_SIZE);
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#ifndef INCLUDED_BLOCK_CACHE
|
||||
#define INCLUDED_BLOCK_CACHE
|
||||
|
||||
#include "lib/native_path.h"
|
||||
|
||||
/**
|
||||
* ID that uniquely identifies a block within a file
|
||||
**/
|
||||
@@ -34,7 +36,7 @@ class BlockId
|
||||
{
|
||||
public:
|
||||
BlockId();
|
||||
BlockId(const fs::wpath& pathname, off_t ofs);
|
||||
BlockId(const NativePath& pathname, off_t ofs);
|
||||
bool operator==(const BlockId& rhs) const;
|
||||
bool operator!=(const BlockId& rhs) const;
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "precompiled.h"
|
||||
#include "lib/file/io/io.h"
|
||||
|
||||
#include "lib/posix/posix_aio.h"
|
||||
#include "lib/allocators/allocators.h" // AllocatorChecker
|
||||
#include "lib/file/file.h"
|
||||
#include "lib/file/common/file_stats.h"
|
||||
|
||||
+15
-16
@@ -47,9 +47,9 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
virtual LibError Mount(const VfsPath& mountPoint, const fs::wpath& path, size_t flags /* = 0 */, size_t priority /* = 0 */)
|
||||
virtual LibError Mount(const VfsPath& mountPoint, const NativePath& path, size_t flags /* = 0 */, size_t priority /* = 0 */)
|
||||
{
|
||||
if(!fs::exists(path))
|
||||
if(!DirectoryExists(path))
|
||||
{
|
||||
if(flags & VFS_MOUNT_MUST_EXIST)
|
||||
return ERR::VFS_DIR_NOT_FOUND; // NOWARN
|
||||
@@ -119,7 +119,7 @@ public:
|
||||
CHECK_ERR(vfs_Lookup(pathname, &m_rootDirectory, directory, 0, VFS_LOOKUP_ADD|VFS_LOOKUP_CREATE));
|
||||
|
||||
const PRealDirectory& realDirectory = directory->AssociatedDirectory();
|
||||
const std::wstring& name = pathname.leaf();
|
||||
const NativePath name = Path::Filename(pathname);
|
||||
RETURN_ERR(realDirectory->Store(name, fileContents, size));
|
||||
|
||||
// wipe out any cached blocks. this is necessary to cover the (rare) case
|
||||
@@ -129,7 +129,7 @@ public:
|
||||
const VfsFile file(name, size, time(0), realDirectory->Priority(), realDirectory);
|
||||
directory->AddFile(file);
|
||||
|
||||
m_trace->NotifyStore(pathname.string().c_str(), size);
|
||||
m_trace->NotifyStore(pathname.c_str(), size);
|
||||
return INFO::OK;
|
||||
}
|
||||
|
||||
@@ -140,8 +140,7 @@ public:
|
||||
{
|
||||
VfsDirectory* directory; VfsFile* file;
|
||||
// per 2010-05-01 meeting, this shouldn't raise 'scary error
|
||||
// dialogs', which often fail to display the culprit pathname
|
||||
// (debug_DumpStack doesn't correctly analyze fs::[w]path).
|
||||
// dialogs', which might fail to display the culprit pathname
|
||||
// instead, callers should log the error, including pathname.
|
||||
RETURN_ERR(vfs_Lookup(pathname, &m_rootDirectory, directory, &file));
|
||||
|
||||
@@ -164,7 +163,7 @@ public:
|
||||
|
||||
stats_io_user_request(size);
|
||||
stats_cache(isCacheHit? CR_HIT : CR_MISS, size);
|
||||
m_trace->NotifyLoad(pathname.string().c_str(), size);
|
||||
m_trace->NotifyLoad(pathname.c_str(), size);
|
||||
|
||||
return INFO::OK;
|
||||
}
|
||||
@@ -177,20 +176,20 @@ public:
|
||||
return textRepresentation;
|
||||
}
|
||||
|
||||
virtual LibError GetRealPath(const VfsPath& pathname, fs::wpath& realPathname)
|
||||
virtual LibError GetRealPath(const VfsPath& pathname, NativePath& realPathname)
|
||||
{
|
||||
VfsDirectory* directory; VfsFile* file;
|
||||
CHECK_ERR(vfs_Lookup(pathname, &m_rootDirectory, directory, &file));
|
||||
realPathname = file->Loader()->Path() / pathname.leaf();
|
||||
realPathname = Path::Join(file->Loader()->Path(), Path::Filename(pathname));
|
||||
return INFO::OK;
|
||||
}
|
||||
|
||||
virtual LibError GetVirtualPath(const fs::wpath& realPathname, VfsPath& pathname)
|
||||
virtual LibError GetVirtualPath(const NativePath& realPathname, VfsPath& pathname)
|
||||
{
|
||||
const fs::wpath realPath = AddSlash(realPathname.branch_path());
|
||||
const NativePath realPath = Path::AddSlash(Path::Path(realPathname));
|
||||
VfsPath path;
|
||||
RETURN_ERR(FindRealPathR(realPath, m_rootDirectory, L"", path));
|
||||
pathname = path / realPathname.leaf();
|
||||
pathname = Path::Join(path, Path::Filename(realPathname));
|
||||
return INFO::OK;
|
||||
}
|
||||
|
||||
@@ -200,7 +199,7 @@ public:
|
||||
|
||||
VfsDirectory* directory;
|
||||
RETURN_ERR(vfs_Lookup(pathname, &m_rootDirectory, directory, 0));
|
||||
const std::wstring name = pathname.leaf();
|
||||
const NativePath name = Path::Filename(pathname);
|
||||
directory->Invalidate(name);
|
||||
|
||||
return INFO::OK;
|
||||
@@ -212,7 +211,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
LibError FindRealPathR(const fs::wpath& realPath, const VfsDirectory& directory, const VfsPath& curPath, VfsPath& path)
|
||||
LibError FindRealPathR(const NativePath& realPath, const VfsDirectory& directory, const VfsPath& curPath, VfsPath& path)
|
||||
{
|
||||
PRealDirectory realDirectory = directory.AssociatedDirectory();
|
||||
if(realDirectory && realDirectory->Path() == realPath)
|
||||
@@ -224,9 +223,9 @@ private:
|
||||
const VfsDirectory::VfsSubdirectories& subdirectories = directory.Subdirectories();
|
||||
for(VfsDirectory::VfsSubdirectories::const_iterator it = subdirectories.begin(); it != subdirectories.end(); ++it)
|
||||
{
|
||||
const std::wstring& subdirectoryName = it->first;
|
||||
const NativePath& subdirectoryName = it->first;
|
||||
const VfsDirectory& subdirectory = it->second;
|
||||
LibError ret = FindRealPathR(realPath, subdirectory, AddSlash(curPath/subdirectoryName), path);
|
||||
LibError ret = FindRealPathR(realPath, subdirectory, Path::AddSlash(Path::Join(curPath, subdirectoryName)), path);
|
||||
if(ret == INFO::OK)
|
||||
return INFO::OK;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ struct IVFS
|
||||
* if files with archive extensions are seen, their contents are added
|
||||
* as well.
|
||||
**/
|
||||
virtual LibError Mount(const VfsPath& mountPoint, const fs::wpath& path, size_t flags = 0, size_t priority = 0) = 0;
|
||||
virtual LibError Mount(const VfsPath& mountPoint, const NativePath& path, size_t flags = 0, size_t priority = 0) = 0;
|
||||
|
||||
/**
|
||||
* Retrieve information about a file (similar to POSIX stat).
|
||||
@@ -151,7 +151,7 @@ struct IVFS
|
||||
*
|
||||
* this is useful for passing paths to external libraries.
|
||||
**/
|
||||
virtual LibError GetRealPath(const VfsPath& pathname, fs::wpath& realPathname) = 0;
|
||||
virtual LibError GetRealPath(const VfsPath& pathname, NativePath& realPathname) = 0;
|
||||
|
||||
/**
|
||||
* retrieve the VFS pathname that corresponds to a real file.
|
||||
@@ -162,7 +162,7 @@ struct IVFS
|
||||
* number of directories; this could be accelerated by only checking
|
||||
* directories below a mount point with a matching real path.
|
||||
**/
|
||||
virtual LibError GetVirtualPath(const fs::wpath& realPathname, VfsPath& pathname) = 0;
|
||||
virtual LibError GetVirtualPath(const NativePath& realPathname, VfsPath& pathname) = 0;
|
||||
|
||||
/**
|
||||
* indicate that a file has changed; remove its data from the cache and
|
||||
|
||||
@@ -37,11 +37,11 @@
|
||||
#include "lib/timer.h"
|
||||
|
||||
|
||||
static LibError CreateDirectory(const fs::wpath& path)
|
||||
static LibError CreateDirectory(const NativePath& path)
|
||||
{
|
||||
{
|
||||
const mode_t mode = S_IRWXU; // 0700 as prescribed by XDG basedir
|
||||
const int ret = wmkdir(path.string().c_str(), mode);
|
||||
const int ret = wmkdir(path.c_str(), mode);
|
||||
if(ret == 0) // success
|
||||
return INFO::OK;
|
||||
}
|
||||
@@ -55,7 +55,7 @@ static LibError CreateDirectory(const fs::wpath& path)
|
||||
// but first ensure it's really a directory (otherwise, a
|
||||
// file is "in the way" and needs to be deleted)
|
||||
struct stat s;
|
||||
const int ret = wstat(path.string().c_str(), &s);
|
||||
const int ret = wstat(path.c_str(), &s);
|
||||
debug_assert(ret == 0); // (wmkdir said it existed)
|
||||
debug_assert(S_ISDIR(s.st_mode));
|
||||
return INFO::OK;
|
||||
@@ -93,10 +93,14 @@ LibError vfs_Lookup(const VfsPath& pathname, VfsDirectory* startDirectory, VfsDi
|
||||
}
|
||||
|
||||
// for each directory component:
|
||||
VfsPath::iterator it; // (used outside of loop to get filename)
|
||||
for(it = pathname.begin(); it != --pathname.end(); ++it)
|
||||
size_t pos = 0; // (needed outside of loop)
|
||||
for(;;)
|
||||
{
|
||||
const std::wstring& subdirectoryName = *it;
|
||||
const size_t nextSlash = pathname.find_first_of('/', pos);
|
||||
if(nextSlash == VfsPath::npos)
|
||||
break;
|
||||
const NativePath subdirectoryName = pathname.substr(pos, nextSlash-pos);
|
||||
pos = nextSlash+1;
|
||||
|
||||
VfsDirectory* subdirectory = directory->GetSubdirectory(subdirectoryName);
|
||||
if(!subdirectory)
|
||||
@@ -109,10 +113,10 @@ LibError vfs_Lookup(const VfsPath& pathname, VfsDirectory* startDirectory, VfsDi
|
||||
|
||||
if(createMissingDirectories && !subdirectory->AssociatedDirectory())
|
||||
{
|
||||
fs::wpath currentPath;
|
||||
NativePath currentPath;
|
||||
if(directory->AssociatedDirectory()) // (is NULL when mounting into root)
|
||||
currentPath = directory->AssociatedDirectory()->Path();
|
||||
currentPath /= subdirectoryName;
|
||||
currentPath = Path::Join(currentPath, subdirectoryName);
|
||||
|
||||
RETURN_ERR(CreateDirectory(currentPath));
|
||||
|
||||
@@ -128,8 +132,8 @@ LibError vfs_Lookup(const VfsPath& pathname, VfsDirectory* startDirectory, VfsDi
|
||||
|
||||
if(pfile)
|
||||
{
|
||||
const std::wstring& filename = *it;
|
||||
debug_assert(filename != L"."); // asked for file but specified directory path
|
||||
const NativePath& filename = pathname.substr(pos);
|
||||
debug_assert(!filename.empty()); // asked for file but specified directory path
|
||||
*pfile = directory->GetFile(filename);
|
||||
if(!*pfile)
|
||||
return ERR::VFS_FILE_NOT_FOUND; // NOWARN
|
||||
|
||||
@@ -22,13 +22,3 @@
|
||||
|
||||
#include "precompiled.h"
|
||||
#include "lib/file/vfs/vfs_path.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
std::size_t hash_value(VfsPath const& b)
|
||||
{
|
||||
boost::hash<std::wstring> hasher;
|
||||
return hasher(b.string());
|
||||
}
|
||||
|
||||
|
||||
@@ -23,9 +23,7 @@
|
||||
#ifndef INCLUDED_VFS_PATH
|
||||
#define INCLUDED_VFS_PATH
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
||||
struct VfsPathTraits;
|
||||
#include "lib/path_util.h"
|
||||
|
||||
/**
|
||||
* VFS path of the form "(dir/)*file?"
|
||||
@@ -37,45 +35,9 @@ struct VfsPathTraits;
|
||||
*
|
||||
* there is no restriction on path length; when dimensioning character
|
||||
* arrays, prefer PATH_MAX.
|
||||
*
|
||||
* rationale: a distinct specialization of basic_path prevents inadvertent
|
||||
* assignment from other path types.
|
||||
**/
|
||||
typedef fs::basic_path<std::wstring, VfsPathTraits> VfsPath;
|
||||
typedef std::wstring VfsPath;
|
||||
|
||||
typedef std::vector<VfsPath> VfsPaths;
|
||||
|
||||
std::size_t hash_value(VfsPath const& b);
|
||||
|
||||
struct VfsPathTraits
|
||||
{
|
||||
typedef std::wstring internal_string_type;
|
||||
typedef std::wstring external_string_type;
|
||||
|
||||
static external_string_type to_external(const VfsPath&, const internal_string_type& src)
|
||||
{
|
||||
return src;
|
||||
}
|
||||
|
||||
static internal_string_type to_internal(const external_string_type& src)
|
||||
{
|
||||
return src;
|
||||
}
|
||||
};
|
||||
|
||||
namespace boost
|
||||
{
|
||||
#ifdef BOOST_FILESYSTEM2_NAMESPACE
|
||||
namespace BOOST_FILESYSTEM2_NAMESPACE
|
||||
#else
|
||||
namespace BOOST_FILESYSTEM_NAMESPACE
|
||||
#endif
|
||||
{
|
||||
template<> struct is_basic_path<VfsPath>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #ifndef INCLUDED_VFS_PATH
|
||||
|
||||
@@ -104,12 +104,12 @@ private:
|
||||
|
||||
LibError AddFiles(const FileInfos& files) const
|
||||
{
|
||||
const fs::wpath path(m_realDirectory->Path());
|
||||
const NativePath path(m_realDirectory->Path());
|
||||
|
||||
for(size_t i = 0; i < files.size(); i++)
|
||||
{
|
||||
const fs::wpath pathname = path/files[i].Name();
|
||||
const std::wstring extension = fs::extension(pathname);
|
||||
const NativePath pathname = Path::Join(path, files[i].Name());
|
||||
const NativePath extension = Path::Extension(pathname);
|
||||
if(wcscasecmp(extension.c_str(), L".zip") == 0)
|
||||
{
|
||||
PIArchiveReader archiveReader = CreateArchiveReader_Zip(pathname);
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
VfsFile::VfsFile(const std::wstring& name, size_t size, time_t mtime, size_t priority, const PIFileLoader& loader)
|
||||
VfsFile::VfsFile(const NativePath& name, size_t size, time_t mtime, size_t priority, const PIFileLoader& loader)
|
||||
: m_name(name), m_size(size), m_mtime(mtime), m_priority(priority), m_loader(loader)
|
||||
{
|
||||
}
|
||||
@@ -78,7 +78,7 @@ static bool ShouldReplaceWith(const VfsFile& previousFile, const VfsFile& newFil
|
||||
|
||||
VfsFile* VfsDirectory::AddFile(const VfsFile& file)
|
||||
{
|
||||
std::pair<std::wstring, VfsFile> value = std::make_pair(file.Name(), file);
|
||||
std::pair<NativePath, VfsFile> value = std::make_pair(file.Name(), file);
|
||||
std::pair<VfsFiles::iterator, bool> ret = m_files.insert(value);
|
||||
if(!ret.second) // already existed
|
||||
{
|
||||
@@ -98,15 +98,15 @@ VfsFile* VfsDirectory::AddFile(const VfsFile& file)
|
||||
|
||||
// rationale: passing in a pre-constructed VfsDirectory and copying that into
|
||||
// our map would be slower and less convenient for the caller.
|
||||
VfsDirectory* VfsDirectory::AddSubdirectory(const std::wstring& name)
|
||||
VfsDirectory* VfsDirectory::AddSubdirectory(const NativePath& name)
|
||||
{
|
||||
std::pair<std::wstring, VfsDirectory> value = std::make_pair(name, VfsDirectory());
|
||||
std::pair<NativePath, VfsDirectory> value = std::make_pair(name, VfsDirectory());
|
||||
std::pair<VfsSubdirectories::iterator, bool> ret = m_subdirectories.insert(value);
|
||||
return &(*ret.first).second;
|
||||
}
|
||||
|
||||
|
||||
VfsFile* VfsDirectory::GetFile(const std::wstring& name)
|
||||
VfsFile* VfsDirectory::GetFile(const NativePath& name)
|
||||
{
|
||||
VfsFiles::iterator it = m_files.find(name);
|
||||
if(it == m_files.end())
|
||||
@@ -115,7 +115,7 @@ VfsFile* VfsDirectory::GetFile(const std::wstring& name)
|
||||
}
|
||||
|
||||
|
||||
VfsDirectory* VfsDirectory::GetSubdirectory(const std::wstring& name)
|
||||
VfsDirectory* VfsDirectory::GetSubdirectory(const NativePath& name)
|
||||
{
|
||||
VfsSubdirectories::iterator it = m_subdirectories.find(name);
|
||||
if(it == m_subdirectories.end())
|
||||
@@ -138,7 +138,7 @@ bool VfsDirectory::ShouldPopulate()
|
||||
}
|
||||
|
||||
|
||||
void VfsDirectory::Invalidate(const std::wstring& name)
|
||||
void VfsDirectory::Invalidate(const NativePath& name)
|
||||
{
|
||||
m_files.erase(name);
|
||||
m_shouldPopulate = 1;
|
||||
@@ -195,7 +195,7 @@ void DirectoryDescriptionR(std::wstring& descriptions, const VfsDirectory& direc
|
||||
const VfsDirectory::VfsSubdirectories& subdirectories = directory.Subdirectories();
|
||||
for(VfsDirectory::VfsSubdirectories::const_iterator it = subdirectories.begin(); it != subdirectories.end(); ++it)
|
||||
{
|
||||
const std::wstring& name = it->first;
|
||||
const NativePath& name = it->first;
|
||||
const VfsDirectory& subdirectory = it->second;
|
||||
descriptions += indentation;
|
||||
descriptions += std::wstring(L"[") + name + L"]\n";
|
||||
|
||||
@@ -36,9 +36,9 @@
|
||||
class VfsFile
|
||||
{
|
||||
public:
|
||||
VfsFile(const std::wstring& name, size_t size, time_t mtime, size_t priority, const PIFileLoader& provider);
|
||||
VfsFile(const NativePath& name, size_t size, time_t mtime, size_t priority, const PIFileLoader& provider);
|
||||
|
||||
const std::wstring& Name() const
|
||||
const NativePath& Name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
std::wstring m_name;
|
||||
NativePath m_name;
|
||||
size_t m_size;
|
||||
time_t m_mtime;
|
||||
|
||||
@@ -77,8 +77,8 @@ private:
|
||||
class VfsDirectory
|
||||
{
|
||||
public:
|
||||
typedef std::map<std::wstring, VfsFile> VfsFiles;
|
||||
typedef std::map<std::wstring, VfsDirectory> VfsSubdirectories;
|
||||
typedef std::map<NativePath, VfsFile> VfsFiles;
|
||||
typedef std::map<NativePath, VfsDirectory> VfsSubdirectories;
|
||||
|
||||
VfsDirectory();
|
||||
|
||||
@@ -90,19 +90,19 @@ public:
|
||||
/**
|
||||
* @return address of existing or newly inserted subdirectory.
|
||||
**/
|
||||
VfsDirectory* AddSubdirectory(const std::wstring& name);
|
||||
VfsDirectory* AddSubdirectory(const NativePath& name);
|
||||
|
||||
/**
|
||||
* @return file with the given name.
|
||||
* (note: non-const to allow changes to the file)
|
||||
**/
|
||||
VfsFile* GetFile(const std::wstring& name);
|
||||
VfsFile* GetFile(const NativePath& name);
|
||||
|
||||
/**
|
||||
* @return subdirectory with the given name.
|
||||
* (note: non-const to allow changes to the subdirectory)
|
||||
**/
|
||||
VfsDirectory* GetSubdirectory(const std::wstring& name);
|
||||
VfsDirectory* GetSubdirectory(const NativePath& name);
|
||||
|
||||
// note: exposing only iterators wouldn't enable callers to reserve space.
|
||||
|
||||
@@ -137,7 +137,7 @@ public:
|
||||
* indicate that a file has changed; ensure its new version supersedes
|
||||
* the old by removing it and marking the directory for re-population.
|
||||
**/
|
||||
void Invalidate(const std::wstring& name);
|
||||
void Invalidate(const NativePath& name);
|
||||
|
||||
/**
|
||||
* empty file and subdirectory lists (e.g. when rebuilding VFS).
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/* Copyright (c) 2010 Wildfire Games
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_NATIVE_PATH
|
||||
#define INCLUDED_NATIVE_PATH
|
||||
|
||||
#include <string>
|
||||
|
||||
// rationale:
|
||||
// this is conceptually a different kind of path, not a superset of VfsPath,
|
||||
// hence NativePath instead of Path (PathUtil is a bit clunky as a
|
||||
// namespace anyway).
|
||||
// a typedef instead of wrapper class avoids the need for accessor functions
|
||||
// (e.g. boost::filesystem::string()) at the cost of somewhat diminished safety.
|
||||
// users are responsible for ensuring the path doesn't contain any forbidden
|
||||
// characters (including any code points >= 0x100 on anything but Windows)
|
||||
typedef std::wstring NativePath;
|
||||
|
||||
static inline NativePath NativePathFromString(const std::string& string)
|
||||
{
|
||||
return NativePath(string.begin(), string.end());
|
||||
}
|
||||
|
||||
#if OS_WIN
|
||||
|
||||
static inline std::wstring StringFromNativePath(const NativePath& npath)
|
||||
{
|
||||
return npath;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static inline std::string StringFromNativePath(const NativePath& npath)
|
||||
{
|
||||
std::string string(npath.length(), '\0');
|
||||
for(size_t i = 0; i < npath.length(); i++)
|
||||
{
|
||||
debug_assert(npath[i] <= UCHAR_MAX);
|
||||
string[i] = npath[i];
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // #ifndef INCLUDED_NATIVE_PATH
|
||||
@@ -129,14 +129,3 @@ const wchar_t* path_name_only(const wchar_t* path)
|
||||
path_component_validate(name);
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
fs::wpath wpath_from_path(const fs::path& pathname)
|
||||
{
|
||||
return wstring_from_utf8(pathname.string());
|
||||
}
|
||||
|
||||
fs::path path_from_wpath(const fs::wpath& pathname)
|
||||
{
|
||||
return utf8_from_wstring(pathname.string());
|
||||
}
|
||||
|
||||
+48
-30
@@ -37,6 +37,9 @@
|
||||
#ifndef INCLUDED_PATH_UTIL
|
||||
#define INCLUDED_PATH_UTIL
|
||||
|
||||
#include "lib/native_path.h"
|
||||
#include "lib/posix/posix_filesystem.h"
|
||||
|
||||
namespace ERR
|
||||
{
|
||||
const LibError PATH_EMPTY = -100300;
|
||||
@@ -77,83 +80,98 @@ LIB_API bool path_is_subpath(const wchar_t* s1, const wchar_t* s2);
|
||||
LIB_API const wchar_t* path_name_only(const wchar_t* path);
|
||||
|
||||
|
||||
template<class Path>
|
||||
Path AddSlash(const Path& path)
|
||||
{
|
||||
return (path.leaf() == L".")? path : path/L"/";
|
||||
}
|
||||
namespace Path {
|
||||
|
||||
LIB_API fs::wpath wpath_from_path(const fs::path& pathname);
|
||||
LIB_API fs::path path_from_wpath(const fs::wpath& pathname);
|
||||
|
||||
|
||||
static inline std::wstring Path(const std::wstring& pathname)
|
||||
static inline NativePath Path(const NativePath& pathname)
|
||||
{
|
||||
size_t n = pathname.find_last_of('/');
|
||||
if(n == std::wstring::npos)
|
||||
if(n == NativePath::npos)
|
||||
{
|
||||
n = pathname.find_last_of('\\');
|
||||
if(n == std::wstring::npos)
|
||||
if(n == NativePath::npos)
|
||||
return L"";
|
||||
}
|
||||
return pathname.substr(0, n);
|
||||
}
|
||||
|
||||
static inline std::wstring Filename(const std::wstring& pathname)
|
||||
static inline NativePath Filename(const NativePath& pathname)
|
||||
{
|
||||
size_t n = pathname.find_last_of('/');
|
||||
if(n == std::wstring::npos)
|
||||
if(n == NativePath::npos)
|
||||
{
|
||||
n = pathname.find_last_of('\\');
|
||||
if(n == std::wstring::npos)
|
||||
if(n == NativePath::npos)
|
||||
return pathname;
|
||||
}
|
||||
return pathname.substr(n+1);
|
||||
}
|
||||
|
||||
|
||||
static inline std::wstring Basename(const std::wstring& filename)
|
||||
static inline NativePath Basename(const NativePath& pathname)
|
||||
{
|
||||
const size_t n = filename.find_last_of('.');
|
||||
if(n == std::wstring::npos)
|
||||
const NativePath filename = Filename(pathname);
|
||||
const size_t idxDot = filename.find_last_of('.');
|
||||
if(idxDot == NativePath::npos)
|
||||
return filename;
|
||||
return filename.substr(0, n);
|
||||
return filename.substr(0, idxDot);
|
||||
}
|
||||
|
||||
static inline std::wstring Extension(const std::wstring& filename)
|
||||
static inline NativePath Extension(const NativePath& pathname)
|
||||
{
|
||||
const size_t n = filename.find_last_of('.');
|
||||
if(n == std::wstring::npos)
|
||||
return std::wstring();
|
||||
return filename.substr(n);
|
||||
const size_t idxDot = pathname.find_last_of('.');
|
||||
if(idxDot == NativePath::npos)
|
||||
return NativePath();
|
||||
return pathname.substr(idxDot);
|
||||
}
|
||||
|
||||
static inline std::wstring Join(const std::wstring& path1, const std::wstring& path2)
|
||||
static inline NativePath Join(const NativePath& path1, const NativePath& path2)
|
||||
{
|
||||
std::wstring ret = path1;
|
||||
NativePath ret = path1;
|
||||
if(!path1.empty() && path1[path1.length()-1] != '/' && path1[path1.length()-1] != '\\')
|
||||
ret += '/';
|
||||
ret += path2;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline std::wstring ChangeExtension(const std::wstring& pathname, const std::wstring& extension)
|
||||
static inline NativePath Join(const NativePath& path1, const NativePath& path2, const NativePath& path3)
|
||||
{
|
||||
return Join(Join(path1, path2), path3);
|
||||
}
|
||||
|
||||
static inline NativePath AddSlash(const NativePath& path)
|
||||
{
|
||||
return (!path.empty() && path_is_dir_sep(path[path.length()-1]))? path : path+L'/';
|
||||
}
|
||||
|
||||
static inline NativePath ChangeExtension(const NativePath& pathname, const NativePath& extension)
|
||||
{
|
||||
return Join(Path(pathname), Basename(Filename(pathname))+extension);
|
||||
}
|
||||
|
||||
static inline bool FileExists(const std::wstring& pathname)
|
||||
} // namespace Path
|
||||
|
||||
static inline bool FileExists(const NativePath& pathname)
|
||||
{
|
||||
struct stat s;
|
||||
const bool exists = wstat(pathname.c_str(), &s) == 0;
|
||||
return exists;
|
||||
}
|
||||
|
||||
static inline u64 FileSize(const std::wstring& pathname)
|
||||
static inline u64 FileSize(const NativePath& pathname)
|
||||
{
|
||||
struct stat s;
|
||||
debug_assert(wstat(pathname.c_str(), &s) == 0);
|
||||
return s.st_size;
|
||||
}
|
||||
|
||||
static inline bool DirectoryExists(const NativePath& path)
|
||||
{
|
||||
WDIR* dir = wopendir(path.c_str());
|
||||
if(dir)
|
||||
{
|
||||
wclosedir(dir);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif // #ifndef INCLUDED_PATH_UTIL
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// (included from precompiled.h)
|
||||
#ifndef INCLUDED_PCH_BOOST
|
||||
#define INCLUDED_PCH_BOOST
|
||||
|
||||
#include "lib/external_libraries/suppress_boost_warnings.h"
|
||||
|
||||
@@ -20,7 +21,6 @@
|
||||
#include <boost/filesystem.hpp>
|
||||
namespace fs = boost::filesystem;
|
||||
#include <boost/shared_ptr.hpp>
|
||||
using boost::shared_ptr;
|
||||
|
||||
// (these ones are used more rarely, so we don't enable them in minimal configurations)
|
||||
#if !MINIMAL_PCH
|
||||
@@ -36,3 +36,5 @@ using boost::function;
|
||||
#include <boost/bind.hpp>
|
||||
using boost::bind;
|
||||
#endif // !MINIMAL_PCH
|
||||
|
||||
#endif // #ifndef INCLUDED_PCH_BOOST
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// (included from precompiled.h)
|
||||
#ifndef INCLUDED_PCH_STDLIB
|
||||
#define INCLUDED_PCH_STDLIB
|
||||
|
||||
#if !MINIMAL_PCH
|
||||
// all new-form C library headers
|
||||
@@ -80,3 +81,5 @@
|
||||
# include <hash_set>
|
||||
#endif
|
||||
#endif // !MINIMAL_PCH
|
||||
|
||||
#endif // #ifndef INCLUDED_PCH_STDLIB
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// (included from precompiled.h)
|
||||
#ifndef INCLUDED_PCH_WARNINGS
|
||||
#define INCLUDED_PCH_WARNINGS
|
||||
|
||||
#include "lib/sysdep/compiler.h" // MSC_VERSION
|
||||
|
||||
@@ -49,3 +50,5 @@
|
||||
//# pragma warning(default:4619) // #pragma warning: there is no [such] warning number (false alarms in STL)
|
||||
//# pragma warning(default:4668) // not defined as a preprocessor macro, replacing with '0' (frequent in Windows)
|
||||
#endif
|
||||
|
||||
#endif // #ifndef INCLUDED_PCH_WARNINGS
|
||||
|
||||
@@ -67,15 +67,17 @@ need only be renamed (e.g. _open, _stat).
|
||||
#endif
|
||||
|
||||
#include "lib/posix/posix_types.h"
|
||||
#include "lib/posix/posix_aio.h"
|
||||
#include "lib/posix/posix_dlfcn.h"
|
||||
#include "lib/posix/posix_filesystem.h"
|
||||
#include "lib/posix/posix_mman.h"
|
||||
#include "lib/posix/posix_pthread.h"
|
||||
|
||||
// disabled to reduce dependencies. include them where needed.
|
||||
//#include "lib/posix/posix_aio.h"
|
||||
//#include "lib/posix/posix_dlfcn.h"
|
||||
//#include "lib/posix/posix_filesystem.h"
|
||||
//#include "lib/posix/posix_mman.h"
|
||||
//#include "lib/posix/posix_pthread.h"
|
||||
//#include "lib/posix/posix_sock.h"
|
||||
//#include "lib/posix/posix_terminal.h"
|
||||
//#include "lib/posix/posix_time.h"
|
||||
#include "lib/posix/posix_utsname.h"
|
||||
//#include "lib/posix/posix_utsname.h"
|
||||
|
||||
|
||||
// note: the following need only be #defined (instead of defining a
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fcntl.h> // O_CREAT etc.
|
||||
|
||||
#if OS_WIN
|
||||
# include "lib/sysdep/os/win/wposix/wfilesystem.h"
|
||||
#else
|
||||
@@ -30,4 +32,4 @@
|
||||
|
||||
#include "lib/posix/posix_errno.h" // for user convenience
|
||||
|
||||
#include "lib/sysdep/filesystem.h"
|
||||
#include "lib/sysdep/filesystem.h" // wchar_t API
|
||||
|
||||
@@ -32,16 +32,18 @@
|
||||
// included from lib/types.h in place of posix.h; this helps avoid conflicts
|
||||
// due to incompatible winsock definitions.
|
||||
|
||||
#include "lib/sysdep/os.h" // OS_WIN
|
||||
|
||||
// (must come before any system headers because it fixes off_t)
|
||||
#if OS_WIN
|
||||
# include "lib/sysdep/os/win/wposix/wposix_types.h"
|
||||
#else
|
||||
|
||||
#include <math.h>
|
||||
#include <wchar.h>
|
||||
#include <sys/types.h>
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
# include <math.h>
|
||||
# include <wchar.h>
|
||||
# include <sys/types.h>
|
||||
# include <stddef.h>
|
||||
# include <limits.h>
|
||||
|
||||
// unix/linux/glibc/gcc says that this macro has to be defined when including
|
||||
// stdint.h from C++ for stdint.h to define SIZE_MAX and friends
|
||||
@@ -55,7 +57,7 @@
|
||||
# define SIZE_MAX ((size_t)-1)
|
||||
# endif
|
||||
|
||||
#include <unistd.h>
|
||||
# include <unistd.h>
|
||||
|
||||
#endif // #if !OS_WIN
|
||||
|
||||
|
||||
@@ -36,9 +36,8 @@
|
||||
# define MINIMAL_PCH 0
|
||||
#endif
|
||||
|
||||
#include "lib/config.h" // CONFIG_ENABLE_PCH
|
||||
#include "lib/sysdep/compiler.h" // MSC_VERSION, HAVE_PCH
|
||||
#include "lib/sysdep/os.h" // (must come before posix_types.h)
|
||||
#include "lib/config.h" // CONFIG_ENABLE_BOOST, CONFIG_ENABLE_PCH
|
||||
#include "lib/sysdep/compiler.h" // MSC_VERSION, HAVE_PCH
|
||||
|
||||
// must come before any STL headers are included
|
||||
#if MSC_VERSION && defined(NDEBUG)
|
||||
@@ -46,14 +45,12 @@
|
||||
#endif
|
||||
|
||||
// disable some common and annoying warnings
|
||||
// must come after compiler.h, but as soon as possible so that
|
||||
// headers below are covered
|
||||
// (as soon as possible so that headers below are covered)
|
||||
#include "lib/pch/pch_warnings.h"
|
||||
|
||||
#if ICC_VERSION
|
||||
#include <mathimf.h> // (must come before <cmath> or <math.h> (replaces them))
|
||||
double __cdecl abs(double x); // not declared by mathimf
|
||||
long double __cdecl abs(long double x); // required for Eigen
|
||||
#endif
|
||||
|
||||
|
||||
@@ -63,8 +60,8 @@ long double __cdecl abs(long double x); // required for Eigen
|
||||
|
||||
#include "lib/posix/posix_types.h" // (must come before any system headers because it fixes off_t)
|
||||
#include "lib/code_annotation.h"
|
||||
#include "lib/code_generation.h"
|
||||
#include "lib/sysdep/arch.h"
|
||||
#include "lib/sysdep/os.h"
|
||||
#include "lib/sysdep/stl.h"
|
||||
#include "lib/lib_api.h"
|
||||
#include "lib/types.h"
|
||||
@@ -74,11 +71,12 @@ long double __cdecl abs(long double x); // required for Eigen
|
||||
|
||||
#if CONFIG_ENABLE_BOOST
|
||||
# include "lib/pch/pch_boost.h"
|
||||
using boost::shared_ptr;
|
||||
#elif HAVE_CPP0X
|
||||
#include <memory>
|
||||
# include <memory>
|
||||
using std::shared_ptr;
|
||||
#else
|
||||
#include <memory>
|
||||
# include <memory>
|
||||
using std::tr1::shared_ptr;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "lib/ogl.h"
|
||||
#include "lib/path_util.h"
|
||||
#include "lib/sysdep/cursor.h"
|
||||
#include "ogl_tex.h"
|
||||
#include "lib/res/h_mgr.h"
|
||||
@@ -188,20 +189,20 @@ static void Cursor_dtor(Cursor* c)
|
||||
static LibError Cursor_reload(Cursor* c, const PIVFS& vfs, const VfsPath& name, Handle)
|
||||
{
|
||||
const VfsPath path(L"art/textures/cursors");
|
||||
const VfsPath pathname(path/name);
|
||||
const VfsPath pathname(Path::Join(path, name));
|
||||
|
||||
// read pixel offset of the cursor's hotspot [the bit of it that's
|
||||
// drawn at (g_mouse_x,g_mouse_y)] from file.
|
||||
int hotspotx = 0, hotspoty = 0;
|
||||
{
|
||||
const VfsPath pathnameHotspot = fs::change_extension(pathname, L".txt");
|
||||
const VfsPath pathnameHotspot = Path::ChangeExtension(pathname, L".txt");
|
||||
shared_ptr<u8> buf; size_t size;
|
||||
RETURN_ERR(vfs->LoadFile(pathnameHotspot, buf, size));
|
||||
std::wstringstream s(std::wstring((const wchar_t*)buf.get(), size));
|
||||
s >> hotspotx >> hotspoty;
|
||||
}
|
||||
|
||||
const VfsPath pathnameImage = fs::change_extension(pathname, L".png");
|
||||
const VfsPath pathnameImage = Path::ChangeExtension(pathname, L".png");
|
||||
|
||||
// try loading as system cursor (2d, hardware accelerated)
|
||||
if(load_sys_cursor(vfs, pathnameImage, hotspotx, hotspoty, &c->system_cursor) == INFO::OK)
|
||||
|
||||
@@ -165,7 +165,7 @@ static LibError Ogl_Shader_reload(Ogl_Shader* shdr, const PIVFS& vfs, const VfsP
|
||||
{
|
||||
char* infolog = new char[log_length];
|
||||
pglGetShaderInfoLog(shdr->id, log_length, 0, infolog);
|
||||
debug_printf(L"Compile log for shader %ls (type %ls):\n%hs", pathname.string().c_str(), type.c_str(), infolog);
|
||||
debug_printf(L"Compile log for shader %ls (type %ls):\n%hs", pathname.c_str(), type.c_str(), infolog);
|
||||
delete[] infolog;
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ static LibError Ogl_Shader_reload(Ogl_Shader* shdr, const PIVFS& vfs, const VfsP
|
||||
// useful some time.
|
||||
ogl_WarnIfError();
|
||||
|
||||
debug_printf(L"Failed to compile shader %ls (type %ls)\n", pathname.string().c_str(), type.c_str());
|
||||
debug_printf(L"Failed to compile shader %ls (type %ls)\n", pathname.c_str(), type.c_str());
|
||||
|
||||
err = ERR::SHDR_COMPILE;
|
||||
goto fail_shadercreated;
|
||||
@@ -284,7 +284,7 @@ static LibError do_load_shader(
|
||||
|
||||
if (Type.empty())
|
||||
{
|
||||
LOGERROR(L"%ls: Missing attribute \"type\" in element \"Shader\".", pathname.string().c_str());
|
||||
LOGERROR(L"%ls: Missing attribute \"type\" in element \"Shader\".", pathname.c_str());
|
||||
WARN_RETURN(ERR::CORRUPTED);
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ static LibError do_load_shader(
|
||||
|
||||
if (!shadertype)
|
||||
{
|
||||
LOGERROR(L"%ls: Unknown shader type \"%hs\" (valid are: VERTEX_SHADER, FRAGMENT_SHADER).", pathname.string().c_str(), Type.c_str());
|
||||
LOGERROR(L"%ls: Unknown shader type \"%hs\" (valid are: VERTEX_SHADER, FRAGMENT_SHADER).", pathname.c_str(), Type.c_str());
|
||||
WARN_RETURN(ERR::CORRUPTED);
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ static LibError do_load_shader(
|
||||
|
||||
if (pathnameShader.empty())
|
||||
{
|
||||
LOGERROR(L"%ls: Missing shader name.", pathname.string().c_str());
|
||||
LOGERROR(L"%ls: Missing shader name.", pathname.c_str());
|
||||
WARN_RETURN(ERR::CORRUPTED);
|
||||
}
|
||||
|
||||
@@ -355,7 +355,7 @@ static LibError Ogl_Program_reload(Ogl_Program* p, const PIVFS& vfs, const VfsPa
|
||||
|
||||
if (Root.GetNodeName() != el_program)
|
||||
{
|
||||
LOGERROR(L"%ls: XML root was not \"Program\".", pathname.string().c_str());
|
||||
LOGERROR(L"%ls: XML root was not \"Program\".", pathname.c_str());
|
||||
WARN_RETURN(ERR::CORRUPTED);
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@ static LibError Ogl_Program_reload(Ogl_Program* p, const PIVFS& vfs, const VfsPa
|
||||
|
||||
if (Shader.GetNodeName() != el_shader)
|
||||
{
|
||||
LOGERROR(L"%ls: Only \"Shader\" may be child of \"Shaders\".", pathname.string().c_str());
|
||||
LOGERROR(L"%ls: Only \"Shader\" may be child of \"Shaders\".", pathname.c_str());
|
||||
WARN_RETURN(ERR::CORRUPTED);
|
||||
}
|
||||
|
||||
@@ -385,7 +385,7 @@ static LibError Ogl_Program_reload(Ogl_Program* p, const PIVFS& vfs, const VfsPa
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGWARNING(L"%ls: Unknown child of \"Program\".", pathname.string().c_str());
|
||||
LOGWARNING(L"%ls: Unknown child of \"Program\".", pathname.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -403,13 +403,13 @@ static LibError Ogl_Program_reload(Ogl_Program* p, const PIVFS& vfs, const VfsPa
|
||||
{
|
||||
char* infolog = new char[log_length];
|
||||
pglGetProgramInfoLog(p->id, log_length, 0, infolog);
|
||||
debug_printf(L"Linker log for %ls:\n%hs\n", pathname.string().c_str(), infolog);
|
||||
debug_printf(L"Linker log for %ls:\n%hs\n", pathname.c_str(), infolog);
|
||||
delete[] infolog;
|
||||
}
|
||||
|
||||
if (!linked)
|
||||
{
|
||||
debug_printf(L"Link failed for %ls\n", pathname.string().c_str());
|
||||
debug_printf(L"Link failed for %ls\n", pathname.c_str());
|
||||
WARN_RETURN(ERR::SHDR_LINK);
|
||||
}
|
||||
|
||||
|
||||
@@ -517,7 +517,7 @@ Handle ogl_tex_load(const PIVFS& vfs, const VfsPath& pathname, size_t flags)
|
||||
// is still in memory; otherwise, a negative error code.
|
||||
Handle ogl_tex_find(const VfsPath& pathname)
|
||||
{
|
||||
const uintptr_t key = fnv_hash(pathname.string().c_str(), pathname.string().length()*sizeof(pathname.string()[0]));
|
||||
const uintptr_t key = fnv_hash(pathname.c_str(), pathname.length()*sizeof(pathname[0]));
|
||||
return h_find(H_OglTex, key);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
class TestTex : public CxxTest::TestSuite
|
||||
{
|
||||
void generate_encode_decode_compare(size_t w, size_t h, size_t flags, size_t bpp, const std::wstring& extension)
|
||||
void generate_encode_decode_compare(size_t w, size_t h, size_t flags, size_t bpp, const NativePath& extension)
|
||||
{
|
||||
// generate test data
|
||||
const size_t size = w*h*bpp/8;
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <map>
|
||||
|
||||
#include "ogl_tex.h"
|
||||
#include "lib/path_util.h"
|
||||
#include "lib/res/h_mgr.h"
|
||||
|
||||
struct GlyphData
|
||||
@@ -84,8 +85,8 @@ static LibError UniFont_reload(UniFont* f, const PIVFS& vfs, const VfsPath& base
|
||||
|
||||
// Read font definition file into a stringstream
|
||||
shared_ptr<u8> buf; size_t size;
|
||||
const VfsPath fntName(basename.string() + L".fnt");
|
||||
RETURN_ERR(vfs->LoadFile(path/fntName, buf, size)); // [cumulative for 12: 36ms]
|
||||
const VfsPath fntName(basename + L".fnt");
|
||||
RETURN_ERR(vfs->LoadFile(Path::Join(path, fntName), buf, size)); // [cumulative for 12: 36ms]
|
||||
std::istringstream FNTStream(std::string((const char*)buf.get(), size));
|
||||
|
||||
int Version;
|
||||
@@ -149,8 +150,8 @@ static LibError UniFont_reload(UniFont* f, const PIVFS& vfs, const VfsPath& base
|
||||
|
||||
// Load glyph texture
|
||||
// [cumulative for 12: 20ms]
|
||||
const VfsPath imgName(basename.string() + L".png");
|
||||
Handle ht = ogl_tex_load(vfs, path/imgName);
|
||||
const VfsPath imgName(basename + L".png");
|
||||
Handle ht = ogl_tex_load(vfs, Path::Join(path, imgName));
|
||||
RETURN_ERR(ht);
|
||||
(void)ogl_tex_set_filter(ht, GL_NEAREST);
|
||||
// override is necessary because the GL format is chosen as LUMINANCE,
|
||||
@@ -187,7 +188,7 @@ static LibError UniFont_to_string(const UniFont* f, wchar_t* buf)
|
||||
if (f->ht) // not true if this is called after dtor (which it is)
|
||||
{
|
||||
const VfsPath& path = h_filename(f->ht);
|
||||
swprintf_s(buf, H_STRING_LEN, L"Font %ls", path.string().c_str());
|
||||
swprintf_s(buf, H_STRING_LEN, L"Font %ls", path.c_str());
|
||||
}
|
||||
else
|
||||
swprintf_s(buf, H_STRING_LEN, L"Font");
|
||||
|
||||
@@ -572,7 +572,7 @@ Handle h_alloc(H_Type type, const PIVFS& vfs, const VfsPath& pathname, size_t fl
|
||||
{
|
||||
RETURN_ERR(type_validate(type));
|
||||
|
||||
const uintptr_t key = fnv_hash(pathname.string().c_str(), pathname.string().length()*sizeof(pathname.string()[0]));
|
||||
const uintptr_t key = fnv_hash(pathname.c_str(), pathname.length()*sizeof(pathname[0]));
|
||||
|
||||
// see if we can reuse an existing handle
|
||||
Handle h = reuse_existing_handle(key, type, flags);
|
||||
@@ -622,11 +622,11 @@ static LibError h_free_idx(ssize_t idx, HDATA* hd)
|
||||
wchar_t buf[H_STRING_LEN];
|
||||
if(vtbl->to_string(hd->user, buf) < 0)
|
||||
wcscpy_s(buf, ARRAY_SIZE(buf), L"(error)");
|
||||
debug_printf(L"H_MGR| free %ls %ls accesses=%lu %ls\n", hd->type->name, hd->pathname.string().c_str(), (unsigned long)hd->num_derefs, buf);
|
||||
debug_printf(L"H_MGR| free %ls %ls accesses=%lu %ls\n", hd->type->name, hd->pathname.c_str(), (unsigned long)hd->num_derefs, buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
hd->pathname.~VfsPath(); // FIXME: ugly hack, but necessary to reclaim std::wstring memory
|
||||
hd->pathname.~VfsPath(); // FIXME: ugly hack, but necessary to reclaim memory
|
||||
memset(hd, 0, sizeof(*hd));
|
||||
new (&hd->pathname) VfsPath; // FIXME too: necessary because otherwise it'll break if we reuse this page
|
||||
|
||||
@@ -699,7 +699,7 @@ VfsPath h_filename(const Handle h)
|
||||
// TODO: what if iterating through all handles is too slow?
|
||||
LibError h_reload(const PIVFS& vfs, const VfsPath& pathname)
|
||||
{
|
||||
const u32 key = fnv_hash(pathname.string().c_str(), pathname.string().length()*sizeof(pathname.string()[0]));
|
||||
const u32 key = fnv_hash(pathname.c_str(), pathname.length()*sizeof(pathname[0]));
|
||||
|
||||
// destroy (note: not free!) all handles backed by this file.
|
||||
// do this before reloading any of them, because we don't specify reload
|
||||
@@ -843,7 +843,7 @@ static void Shutdown()
|
||||
{
|
||||
if (pages[j])
|
||||
for(size_t k = 0; k < hdata_per_page; ++k)
|
||||
pages[j][k].pathname.~VfsPath(); // FIXME: ugly hack, but necessary to reclaim std::wstring memory
|
||||
pages[j][k].pathname.~VfsPath(); // FIXME: ugly hack, but necessary to reclaim memory
|
||||
free(pages[j]);
|
||||
pages[j] = 0;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "lib/external_libraries/vorbis.h"
|
||||
|
||||
#include "lib/byte_order.h"
|
||||
#include "lib/path_util.h"
|
||||
#include "lib/file/file.h"
|
||||
|
||||
|
||||
@@ -51,7 +52,7 @@ class VorbisFileAdapter
|
||||
public:
|
||||
VorbisFileAdapter(const PFile& openedFile)
|
||||
: file(openedFile)
|
||||
, size(fs::file_size(openedFile->Pathname()))
|
||||
, size(FileSize(openedFile->Pathname()))
|
||||
, offset(0)
|
||||
{
|
||||
}
|
||||
@@ -257,7 +258,7 @@ private:
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
LibError OpenOggStream(const fs::wpath& pathname, OggStreamPtr& stream)
|
||||
LibError OpenOggStream(const NativePath& pathname, OggStreamPtr& stream)
|
||||
{
|
||||
PFile file(new File);
|
||||
RETURN_ERR(file->Open(pathname, L'r'));
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
|
||||
typedef shared_ptr<OggStream> OggStreamPtr;
|
||||
|
||||
extern LibError OpenOggStream(const fs::wpath& pathname, OggStreamPtr& stream);
|
||||
extern LibError OpenOggStream(const NativePath& pathname, OggStreamPtr& stream);
|
||||
|
||||
/**
|
||||
* A non-streaming OggStream (reading the whole file in advance)
|
||||
|
||||
@@ -182,8 +182,9 @@ extern bool self_test_active;
|
||||
|
||||
|
||||
// for convenience, to avoid having to include all of these manually
|
||||
#include "lib_errors.h"
|
||||
#include "posix/posix.h"
|
||||
#include "lib/lib_errors.h"
|
||||
#include "lib/native_path.h"
|
||||
#include "lib/posix/posix.h"
|
||||
|
||||
#define CXXTEST_HAVE_EH
|
||||
#define CXXTEST_HAVE_STD
|
||||
@@ -284,6 +285,6 @@ void ScriptTestSetup(ScriptInterface&);
|
||||
// Default game data directory
|
||||
// (TODO: game-specific functions like this probably shouldn't be inside lib/, but it's useful
|
||||
// here since lots of tests use it)
|
||||
fs::wpath DataDir(); // defined in test_setup.cpp
|
||||
NativePath DataDir(); // defined in test_setup.cpp
|
||||
|
||||
#endif // #ifndef INCLUDED_SELF_TEST
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#ifndef INCLUDED_DIR_WATCH
|
||||
#define INCLUDED_DIR_WATCH
|
||||
|
||||
#include "lib/path_util.h"
|
||||
|
||||
struct DirWatch;
|
||||
typedef shared_ptr<DirWatch> PDirWatch;
|
||||
|
||||
@@ -47,7 +49,7 @@ typedef shared_ptr<DirWatch> PDirWatch;
|
||||
* convenient to store PDirWatch there instead of creating a second
|
||||
* tree structure here.
|
||||
**/
|
||||
LIB_API LibError dir_watch_Add(const fs::wpath& path, PDirWatch& dirWatch);
|
||||
LIB_API LibError dir_watch_Add(const NativePath& path, PDirWatch& dirWatch);
|
||||
|
||||
class DirWatchNotification
|
||||
{
|
||||
@@ -59,24 +61,24 @@ public:
|
||||
Changed
|
||||
};
|
||||
|
||||
DirWatchNotification(const fs::wpath& pathname, EType type)
|
||||
: m_pathname(pathname), m_type(type)
|
||||
DirWatchNotification(const NativePath& pathname, EType type)
|
||||
: pathname(pathname), type(type)
|
||||
{
|
||||
}
|
||||
|
||||
const fs::wpath& Pathname() const
|
||||
const NativePath& Pathname() const
|
||||
{
|
||||
return m_pathname;
|
||||
return pathname;
|
||||
}
|
||||
|
||||
EType Type() const
|
||||
{
|
||||
return m_type;
|
||||
return type;
|
||||
}
|
||||
|
||||
private:
|
||||
fs::wpath m_pathname;
|
||||
EType m_type;
|
||||
NativePath pathname;
|
||||
EType type;
|
||||
};
|
||||
|
||||
typedef std::vector<DirWatchNotification> DirWatchNotifications;
|
||||
|
||||
@@ -75,7 +75,7 @@ struct DirWatch
|
||||
FAMCancelMonitor(&fc, &req);
|
||||
}
|
||||
|
||||
fs::wpath path;
|
||||
NativePath path;
|
||||
int reqnum;
|
||||
};
|
||||
|
||||
@@ -156,7 +156,7 @@ static void* fam_event_loop(void*)
|
||||
}
|
||||
}
|
||||
|
||||
LibError dir_watch_Add(const fs::wpath& path, PDirWatch& dirWatch)
|
||||
LibError dir_watch_Add(const NativePath& npath, PDirWatch& dirWatch)
|
||||
{
|
||||
// init already failed; don't try again or complain
|
||||
if(initialized == -1)
|
||||
@@ -189,16 +189,16 @@ LibError dir_watch_Add(const fs::wpath& path, PDirWatch& dirWatch)
|
||||
// but it would only save tens of milliseconds of CPU time, so it's probably
|
||||
// not worthwhile
|
||||
|
||||
const fs::path path_c = path_from_wpath(path);
|
||||
const std::string path = StringFromNativePath(npath);
|
||||
FAMRequest req;
|
||||
if(FAMMonitorDirectory(&fc, path_c.string().c_str(), &req, tmpDirWatch.get()) < 0)
|
||||
if(FAMMonitorDirectory(&fc, path.c_str(), &req, tmpDirWatch.get()) < 0)
|
||||
{
|
||||
debug_warn(L"res_watch_dir failed!");
|
||||
WARN_RETURN(ERR::FAIL); // no way of getting error code?
|
||||
}
|
||||
|
||||
dirWatch.swap(tmpDirWatch);
|
||||
dirWatch->path = path;
|
||||
dirWatch->path = npath;
|
||||
dirWatch->reqnum = req.reqnum;
|
||||
|
||||
return INFO::OK;
|
||||
@@ -237,7 +237,7 @@ LibError dir_watch_Poll(DirWatchNotifications& notifications)
|
||||
continue;
|
||||
}
|
||||
DirWatch* dirWatch = (DirWatch*)polled_notifications[i].userdata;
|
||||
fs::wpath pathname = dirWatch->path/wstring_from_utf8(polled_notifications[i].filename);
|
||||
NativePath pathname = Path::Join(dirWatch->path, NativePathFromString(polled_notifications[i].filename));
|
||||
notifications.push_back(DirWatchNotification(pathname, type));
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
LibError sys_get_executable_name(fs::wpath& pathname)
|
||||
LibError sys_get_executable_name(std::wstring& pathname)
|
||||
{
|
||||
const char* path;
|
||||
Dl_info dl_info;
|
||||
|
||||
@@ -78,7 +78,7 @@ LibError gfx_get_video_mode(int* xres, int* yres, int* bpp, int* freq)
|
||||
}
|
||||
|
||||
|
||||
LibError sys_get_executable_name(fs::wpath& pathname)
|
||||
LibError sys_get_executable_name(std::wstring& pathname)
|
||||
{
|
||||
static char name[PATH_MAX];
|
||||
static bool init = false;
|
||||
|
||||
@@ -39,10 +39,10 @@ struct WDIR
|
||||
wdirent ent;
|
||||
};
|
||||
|
||||
WDIR* wopendir(const wchar_t* path)
|
||||
WDIR* wopendir(const wchar_t* wpath)
|
||||
{
|
||||
fs::path path_c(path_from_wpath(path));
|
||||
DIR* d = opendir(path_c.string().c_str());
|
||||
const std::string path = StringFromNativePath(wpath);
|
||||
DIR* d = opendir(path.c_str());
|
||||
if(!d)
|
||||
return 0;
|
||||
WDIR* wd = new WDIR;
|
||||
@@ -70,17 +70,17 @@ int wclosedir(WDIR* wd)
|
||||
}
|
||||
|
||||
|
||||
int wopen(const wchar_t* pathname, int oflag)
|
||||
int wopen(const wchar_t* wpathname, int oflag)
|
||||
{
|
||||
debug_assert(!(oflag & O_CREAT));
|
||||
fs::path pathname_c(path_from_wpath(pathname));
|
||||
return open(pathname_c.string().c_str(), oflag);
|
||||
const std::string pathname = StringFromNativePath(wpathname);
|
||||
return open(pathname.c_str(), oflag);
|
||||
}
|
||||
|
||||
int wopen(const wchar_t* pathname, int oflag, mode_t mode)
|
||||
int wopen(const wchar_t* wpathname, int oflag, mode_t mode)
|
||||
{
|
||||
fs::path pathname_c(path_from_wpath(pathname));
|
||||
return open(pathname_c.string().c_str(), oflag, mode);
|
||||
const std::string pathname = StringFromNativePath(wpathname);
|
||||
return open(pathname.c_str(), oflag, mode);
|
||||
}
|
||||
|
||||
int wclose(int fd)
|
||||
@@ -89,51 +89,51 @@ int wclose(int fd)
|
||||
}
|
||||
|
||||
|
||||
int wtruncate(const wchar_t* pathname, off_t length)
|
||||
int wtruncate(const wchar_t* wpathname, off_t length)
|
||||
{
|
||||
fs::path pathname_c(path_from_wpath(pathname));
|
||||
return truncate(pathname_c.string().c_str(), length);
|
||||
const std::string pathname = StringFromNativePath(wpathname);
|
||||
return truncate(pathname.c_str(), length);
|
||||
}
|
||||
|
||||
int wunlink(const wchar_t* pathname)
|
||||
int wunlink(const wchar_t* wpathname)
|
||||
{
|
||||
fs::path pathname_c(path_from_wpath(pathname));
|
||||
return unlink(pathname_c.string().c_str());
|
||||
const std::string pathname = StringFromNativePath(wpathname);
|
||||
return unlink(pathname.c_str());
|
||||
}
|
||||
|
||||
int wrmdir(const wchar_t* path)
|
||||
int wrmdir(const wchar_t* wpath)
|
||||
{
|
||||
fs::path path_c(path_from_wpath(path));
|
||||
return rmdir(path_c.string().c_str());
|
||||
const std::string path = StringFromNativePath(wpath);
|
||||
return rmdir(path.c_str());
|
||||
}
|
||||
|
||||
int wrename(const wchar_t* pathnameOld, const wchar_t* pathnameNew)
|
||||
int wrename(const wchar_t* wpathnameOld, const wchar_t* wpathnameNew)
|
||||
{
|
||||
fs::path pathnameOld_c(path_from_wpath(pathnameOld));
|
||||
fs::path pathnameNew_c(path_from_wpath(pathnameNew));
|
||||
return rename(pathnameOld_c.string().c_str(), pathnameNew_c.string().c_str());
|
||||
const std::string pathnameOld = StringFromNativePath(wpathnameOld);
|
||||
const std::string pathnameNew = StringFromNativePath(wpathnameNew);
|
||||
return rename(pathnameOld.c_str(), pathnameNew.c_str());
|
||||
}
|
||||
|
||||
wchar_t* wrealpath(const wchar_t* pathname, wchar_t* resolved)
|
||||
wchar_t* wrealpath(const wchar_t* wpathname, wchar_t* wresolved)
|
||||
{
|
||||
char resolved_buf[PATH_MAX];
|
||||
fs::path pathname_c(path_from_wpath(pathname));
|
||||
const char* resolved_c = realpath(pathname_c.string().c_str(), resolved_buf);
|
||||
if(!resolved_c)
|
||||
char resolvedBuf[PATH_MAX];
|
||||
const std::string pathname = StringFromNativePath(wpathname);
|
||||
const char* resolved = realpath(pathname.c_str(), resolvedBuf);
|
||||
if(!resolved)
|
||||
return 0;
|
||||
std::wstring resolved_s = wstring_from_utf8(resolved_c);
|
||||
wcscpy_s(resolved, PATH_MAX, resolved_s.c_str());
|
||||
return resolved;
|
||||
NativePath nresolved = NativePathFromString(resolved);
|
||||
wcscpy_s(wresolved, PATH_MAX, nresolved.c_str());
|
||||
return wresolved;
|
||||
}
|
||||
|
||||
int wstat(const wchar_t* pathname, struct stat* buf)
|
||||
int wstat(const wchar_t* wpathname, struct stat* buf)
|
||||
{
|
||||
fs::path pathname_c(path_from_wpath(pathname));
|
||||
return stat(pathname_c.string().c_str(), buf);
|
||||
const std::string pathname = StringFromNativePath(wpathname);
|
||||
return stat(pathname.c_str(), buf);
|
||||
}
|
||||
|
||||
int wmkdir(const wchar_t* path, mode_t mode)
|
||||
int wmkdir(const wchar_t* wpath, mode_t mode)
|
||||
{
|
||||
fs::path path_c(path_from_wpath(path));
|
||||
return mkdir(path_c.string().c_str(), mode);
|
||||
const std::string path = StringFromNativePath(wpath);
|
||||
return mkdir(path.c_str(), mode);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "precompiled.h"
|
||||
#include "lib/sysdep/os/win/mahaf.h"
|
||||
|
||||
#include "lib/path_util.h"
|
||||
#include "lib/module_init.h"
|
||||
|
||||
#include "lib/sysdep/os/win/wutil.h"
|
||||
@@ -259,7 +260,7 @@ static void UninstallDriver()
|
||||
}
|
||||
|
||||
|
||||
static void StartDriver(const fs::wpath& driverPathname)
|
||||
static void StartDriver(const NativePath& driverPathname)
|
||||
{
|
||||
const SC_HANDLE hSCM = OpenServiceControlManager();
|
||||
if(!hSCM)
|
||||
@@ -289,7 +290,7 @@ static void StartDriver(const fs::wpath& driverPathname)
|
||||
// NB: Windows 7 seems to insist upon backslashes (i.e. external_file_string)
|
||||
hService = CreateServiceW(hSCM, AKEN_NAME, AKEN_NAME,
|
||||
SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
|
||||
driverPathname.external_file_string().c_str(), 0, 0, 0, startName, 0);
|
||||
driverPathname.c_str(), 0, 0, 0, startName, 0);
|
||||
debug_assert(hService != 0);
|
||||
}
|
||||
|
||||
@@ -322,17 +323,17 @@ static bool Is64BitOs()
|
||||
#endif
|
||||
}
|
||||
|
||||
static fs::wpath DriverPathname()
|
||||
static NativePath DriverPathname()
|
||||
{
|
||||
const wchar_t* const bits = Is64BitOs()? L"64" : L"";
|
||||
const char* const bits = Is64BitOs()? "64" : "";
|
||||
#ifdef NDEBUG
|
||||
const wchar_t* const debug = L"";
|
||||
const char* const debug = "";
|
||||
#else
|
||||
const wchar_t* const debug = L"d";
|
||||
const char* const debug = "d";
|
||||
#endif
|
||||
wchar_t filename[PATH_MAX];
|
||||
swprintf_s(filename, ARRAY_SIZE(filename), L"aken%ls%ls.sys", bits, debug);
|
||||
return wutil_ExecutablePath()/filename;
|
||||
char filename[PATH_MAX];
|
||||
sprintf_s(filename, ARRAY_SIZE(filename), "aken%s%s.sys", bits, debug);
|
||||
return Path::Join(wutil_ExecutablePath(), NativePathFromString(filename));
|
||||
}
|
||||
|
||||
|
||||
@@ -344,7 +345,7 @@ static LibError Init()
|
||||
return ERR::NOT_SUPPORTED; // NOWARN
|
||||
|
||||
{
|
||||
const fs::wpath driverPathname = DriverPathname();
|
||||
const NativePath driverPathname = DriverPathname();
|
||||
StartDriver(driverPathname);
|
||||
}
|
||||
|
||||
|
||||
@@ -1871,8 +1871,8 @@ void wdbg_sym_WriteMinidump(EXCEPTION_POINTERS* exception_pointers)
|
||||
|
||||
WinScopedLock lock(WDBG_SYM_CS);
|
||||
|
||||
fs::wpath path = ah_get_log_dir()/L"crashlog.dmp";
|
||||
HANDLE hFile = CreateFileW(path.string().c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, 0, CREATE_ALWAYS, 0, 0);
|
||||
NativePath path = Path::Join(ah_get_log_dir(), L"crashlog.dmp");
|
||||
HANDLE hFile = CreateFileW(path.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, 0, CREATE_ALWAYS, 0, 0);
|
||||
if(hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DEBUG_DISPLAY_ERROR(L"wdbg_sym_WriteMinidump: unable to create crashlog.dmp.");
|
||||
|
||||
@@ -44,12 +44,12 @@ WINIT_REGISTER_MAIN_SHUTDOWN(wdir_watch_Shutdown);
|
||||
class DirHandle
|
||||
{
|
||||
public:
|
||||
DirHandle(const fs::wpath& path)
|
||||
DirHandle(const NativePath& path)
|
||||
{
|
||||
WinScopedPreserveLastError s; // CreateFile
|
||||
const DWORD share = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
|
||||
const DWORD flags = FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED;
|
||||
m_hDir = CreateFileW(path.string().c_str(), FILE_LIST_DIRECTORY, share, 0, OPEN_EXISTING, flags, 0);
|
||||
m_hDir = CreateFileW(path.c_str(), FILE_LIST_DIRECTORY, share, 0, OPEN_EXISTING, flags, 0);
|
||||
}
|
||||
|
||||
~DirHandle()
|
||||
@@ -81,7 +81,7 @@ class DirWatchRequest
|
||||
{
|
||||
NONCOPYABLE(DirWatchRequest);
|
||||
public:
|
||||
DirWatchRequest(const fs::wpath& path)
|
||||
DirWatchRequest(const NativePath& path)
|
||||
: m_path(path), m_dirHandle(path), m_data(new u8[dataSize])
|
||||
{
|
||||
m_ovl = (OVERLAPPED*)calloc(1, sizeof(OVERLAPPED)); // rationale for dynamic alloc: see decl
|
||||
@@ -124,7 +124,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
const fs::wpath& Path() const
|
||||
const NativePath& Path() const
|
||||
{
|
||||
return m_path;
|
||||
}
|
||||
@@ -162,12 +162,12 @@ public:
|
||||
const FILE_NOTIFY_INFORMATION* fni = (const FILE_NOTIFY_INFORMATION*)m_data;
|
||||
for(;;)
|
||||
{
|
||||
// convert name from BSTR (non-zero-terminated) to std::wstring
|
||||
// convert name from BSTR (non-zero-terminated) to NativePath
|
||||
cassert(sizeof(wchar_t) == sizeof(WCHAR));
|
||||
const size_t nameChars = fni->FileNameLength / sizeof(WCHAR);
|
||||
const std::wstring name(fni->FileName, nameChars);
|
||||
const NativePath name(fni->FileName, nameChars);
|
||||
|
||||
const fs::wpath pathname(Path()/name);
|
||||
const NativePath pathname = Path::Join(Path(), name);
|
||||
const DirWatchNotification::EType type = TypeFromAction(fni->Action);
|
||||
notifications.push_back(DirWatchNotification(pathname, type));
|
||||
|
||||
@@ -199,7 +199,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
fs::wpath m_path;
|
||||
NativePath m_path;
|
||||
DirHandle m_dirHandle;
|
||||
|
||||
// rationale:
|
||||
@@ -368,9 +368,9 @@ private:
|
||||
class DirWatchManager
|
||||
{
|
||||
public:
|
||||
LibError Add(const fs::wpath& path, PDirWatch& dirWatch)
|
||||
LibError Add(const NativePath& path, PDirWatch& dirWatch)
|
||||
{
|
||||
debug_assert(path.leaf() == L"."); // must be a directory path (i.e. end in slash)
|
||||
debug_assert(path_is_dir_sep(path.back())); // must be a directory path
|
||||
|
||||
// check if this is a subdirectory of a tree that's already being
|
||||
// watched (this is much faster than issuing a new watch; it also
|
||||
@@ -378,7 +378,7 @@ public:
|
||||
for(IntrusiveLink* link = m_sentinel.Next(); link != &m_sentinel; link = link->Next())
|
||||
{
|
||||
DirWatch* const existingDirWatch = (DirWatch*)(uintptr_t(link) - offsetof(DirWatch, link));
|
||||
if(path_is_subpath(path.string().c_str(), existingDirWatch->request->Path().string().c_str()))
|
||||
if(path_is_subpath(path.c_str(), existingDirWatch->request->Path().c_str()))
|
||||
{
|
||||
dirWatch.reset(new DirWatch(&m_sentinel, existingDirWatch->request));
|
||||
return INFO::OK;
|
||||
@@ -412,7 +412,7 @@ static DirWatchManager* s_dirWatchManager;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
LibError dir_watch_Add(const fs::wpath& path, PDirWatch& dirWatch)
|
||||
LibError dir_watch_Add(const NativePath& path, PDirWatch& dirWatch)
|
||||
{
|
||||
WinScopedLock lock(WDIR_WATCH_CS);
|
||||
return s_dirWatchManager->Add(path, dirWatch);
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "lib/path_util.h"
|
||||
#include "lib/sysdep/os/win/win.h"
|
||||
#include "lib/sysdep/os/win/wutil.h"
|
||||
|
||||
@@ -42,10 +43,9 @@
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static LibError ReadVersionString(const fs::wpath& modulePathname_, wchar_t* out_ver, size_t out_ver_len)
|
||||
static LibError ReadVersionString(const NativePath& modulePathname, wchar_t* out_ver, size_t out_ver_len)
|
||||
{
|
||||
WinScopedPreserveLastError s; // GetFileVersion*, Ver*
|
||||
const std::wstring modulePathname = modulePathname_.string();
|
||||
|
||||
// determine size of and allocate memory for version information.
|
||||
DWORD unused;
|
||||
@@ -83,7 +83,7 @@ static LibError ReadVersionString(const fs::wpath& modulePathname_, wchar_t* out
|
||||
}
|
||||
|
||||
|
||||
void wdll_ver_Append(const fs::wpath& pathname, std::wstring& list)
|
||||
void wdll_ver_Append(const NativePath& pathname, VersionList& list)
|
||||
{
|
||||
if(pathname.empty())
|
||||
return; // avoid error in ReadVersionString
|
||||
@@ -91,10 +91,10 @@ void wdll_ver_Append(const fs::wpath& pathname, std::wstring& list)
|
||||
// pathname may not have an extension (e.g. driver names from the
|
||||
// registry). note that always appending ".dll" would be incorrect
|
||||
// since some have ".sys" extension.
|
||||
fs::wpath modulePathname(pathname);
|
||||
if(fs::extension(modulePathname).empty())
|
||||
modulePathname = fs::change_extension(modulePathname, L".dll");
|
||||
const std::wstring moduleName(modulePathname.leaf());
|
||||
NativePath modulePathname(pathname);
|
||||
if(Path::Extension(modulePathname).empty())
|
||||
modulePathname = Path::ChangeExtension(modulePathname, L".dll");
|
||||
const NativePath moduleName(Path::Filename(modulePathname));
|
||||
|
||||
// read file version. try this with and without FS redirection since
|
||||
// pathname might assume both.
|
||||
|
||||
@@ -27,17 +27,20 @@
|
||||
#ifndef INCLUDED_WDLL_VER
|
||||
#define INCLUDED_WDLL_VER
|
||||
|
||||
#include "lib/native_path.h"
|
||||
|
||||
typedef std::wstring VersionList;
|
||||
|
||||
/**
|
||||
* Read DLL version information and append it to a string.
|
||||
*
|
||||
* @param pathname of DLL (preferably the complete path, so that we don't
|
||||
* inadvertently load another one on the library search path.)
|
||||
* If no extension is given, .dll will be appended.
|
||||
* @param list
|
||||
*
|
||||
* The text output includes the module name.
|
||||
* On failure, the version is given as "unknown".
|
||||
**/
|
||||
extern void wdll_ver_Append(const fs::wpath& pathname, std::wstring& list);
|
||||
extern void wdll_ver_Append(const NativePath& pathname, VersionList& list);
|
||||
|
||||
#endif // #ifndef INCLUDED_WDLL_VER
|
||||
|
||||
@@ -93,7 +93,7 @@ static LibError win_get_gfx_card()
|
||||
|
||||
|
||||
// note: this implementation doesn't require OpenGL to be initialized.
|
||||
static LibError AppendDriverVersionsFromRegistry(std::wstring& versionList)
|
||||
static LibError AppendDriverVersionsFromRegistry(VersionList& versionList)
|
||||
{
|
||||
// rationale:
|
||||
// - we could easily determine the 2d driver via EnumDisplaySettings,
|
||||
@@ -171,7 +171,7 @@ static LibError AppendDriverVersionsFromRegistry(std::wstring& versionList)
|
||||
|
||||
#include "lib/timer.h"
|
||||
|
||||
static void AppendDriverVersionsFromKnownFiles(std::wstring& versionList)
|
||||
static void AppendDriverVersionsFromKnownFiles(VersionList& versionList)
|
||||
{
|
||||
// (check all known file names regardless of gfx_card, which may change and
|
||||
// defeat our parsing. this takes about 5..10 ms)
|
||||
@@ -195,7 +195,7 @@ LibError win_get_gfx_info()
|
||||
{
|
||||
LibError err = win_get_gfx_card();
|
||||
|
||||
std::wstring versionList;
|
||||
VersionList versionList;
|
||||
if(AppendDriverVersionsFromRegistry(versionList) != INFO::OK) // (fails on Windows 7)
|
||||
AppendDriverVersionsFromKnownFiles(versionList);
|
||||
if(versionList.empty())
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <map>
|
||||
|
||||
#include "lib/sysdep/os/win/wposix/crt_posix.h" // correct definitions of _open() etc.
|
||||
#include "lib/posix/posix_filesystem.h"
|
||||
|
||||
#include "lib/sysdep/os/win/wposix/wposix_internal.h"
|
||||
#include "lib/sysdep/os/win/wposix/wfilesystem.h" // mode_t
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#include "precompiled.h"
|
||||
#include "lib/sysdep/os/win/wposix/wdlfcn.h"
|
||||
|
||||
#include "lib/utf8.h"
|
||||
#include "lib/path_util.h"
|
||||
#include "lib/sysdep/os/win/wposix/wposix_internal.h"
|
||||
|
||||
|
||||
@@ -55,8 +57,8 @@ void* dlopen(const char* so_name, int flags)
|
||||
{
|
||||
debug_assert(!(flags & RTLD_GLOBAL));
|
||||
|
||||
fs::path pathname = fs::change_extension(so_name, ".dll");
|
||||
HMODULE hModule = LoadLibraryA(pathname.string().c_str());
|
||||
NativePath pathname = Path::ChangeExtension(wstring_from_utf8(so_name), L".dll");
|
||||
HMODULE hModule = LoadLibraryW(pathname.c_str());
|
||||
return void_from_HMODULE(hModule);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,9 @@
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
#include "lib/sysdep/os/win/wposix/wfilesystem.h"
|
||||
#include "lib/posix/posix_filesystem.h" // includes wfilesystem.h
|
||||
|
||||
#include "lib/allocators/allocators.h" // single_calloc
|
||||
#include "lib/allocators/allocators.h" // single_calloc
|
||||
#include "lib/sysdep/os/win/wposix/wposix_internal.h"
|
||||
#include "lib/sysdep/os/win/wposix/waio.h"
|
||||
#include "lib/sysdep/os/win/wposix/wtime_internal.h" // wtime_utc_filetime_to_time_t
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include <process.h>
|
||||
|
||||
#include "lib/sysdep/cpu.h" // cpu_CAS
|
||||
|
||||
#include "lib/posix/posix_filesystem.h" // O_CREAT
|
||||
#include "lib/sysdep/os/win/wposix/wposix_internal.h"
|
||||
#include "lib/sysdep/os/win/wposix/wtime.h" // timespec
|
||||
#include "lib/sysdep/os/win/wseh.h" // wseh_ExceptionFilter
|
||||
|
||||
@@ -38,8 +38,9 @@
|
||||
#include <process.h> // _beginthreadex
|
||||
#include <WindowsX.h> // message crackers
|
||||
|
||||
#include "lib/posix/posix_pthread.h"
|
||||
#include "lib/module_init.h"
|
||||
#include "lib/path_util.h"
|
||||
#include "lib/posix/posix_pthread.h"
|
||||
#include "lib/sysdep/os/win/wutil.h"
|
||||
#include "lib/sysdep/os/win/winit.h"
|
||||
#include "lib/sysdep/os/win/wmi.h" // for SDL_GetVideoInfo
|
||||
@@ -1477,20 +1478,20 @@ void SDL_Quit()
|
||||
}
|
||||
|
||||
|
||||
static fs::wpath GetStdoutPathname()
|
||||
static NativePath GetStdoutPathname()
|
||||
{
|
||||
// the current directory is unreliable, so use the full path to
|
||||
// the current executable.
|
||||
wchar_t pathnameEXE[MAX_PATH];
|
||||
const DWORD charsWritten = GetModuleFileNameW(0, pathnameEXE, ARRAY_SIZE(pathnameEXE));
|
||||
debug_assert(charsWritten);
|
||||
const fs::wpath path = fs::wpath(pathnameEXE).branch_path();
|
||||
const NativePath path = Path::Path(pathnameEXE);
|
||||
|
||||
// add the EXE name to the filename to allow multiple executables
|
||||
// with their own redirections. (we can't use wutil_ExecutablePath
|
||||
// because it doesn't return the basename)
|
||||
std::wstring name = fs::basename(pathnameEXE);
|
||||
fs::wpath pathname(path/(name+L"_stdout.txt"));
|
||||
NativePath name = Path::Basename(pathnameEXE);
|
||||
NativePath pathname = Path::Join(path, (name+L"_stdout.txt"));
|
||||
|
||||
return pathname;
|
||||
}
|
||||
@@ -1502,7 +1503,7 @@ static void RedirectStdout()
|
||||
if(wutil_IsValidHandle(GetStdHandle(STD_OUTPUT_HANDLE)))
|
||||
return;
|
||||
|
||||
const fs::wpath pathname = GetStdoutPathname();
|
||||
const NativePath pathname = GetStdoutPathname();
|
||||
|
||||
// ignore BoundsChecker warnings here. subsystem is set to "Windows"
|
||||
// to prevent the OS from opening a console on startup (ugly).
|
||||
@@ -1511,7 +1512,7 @@ static void RedirectStdout()
|
||||
FILE* f = 0;
|
||||
// (return value ignored - it indicates 'file already exists' even
|
||||
// if f is valid)
|
||||
(void)_wfreopen_s(&f, pathname.string().c_str(), L"wt", stdout);
|
||||
(void)_wfreopen_s(&f, pathname.c_str(), L"wt", stdout);
|
||||
// executable directory (probably Program Files) is read-only for
|
||||
// non-Administrators. we can't pick another directory because
|
||||
// ah_log_dir might not be valid until the app's init has run,
|
||||
|
||||
@@ -33,35 +33,34 @@
|
||||
#include <set>
|
||||
|
||||
#include "lib/path_util.h"
|
||||
#include "lib/file/file_system.h"
|
||||
#include "lib/sysdep/os/win/wdll_ver.h"
|
||||
#include "lib/sysdep/os/win/wversion.h"
|
||||
#include "lib/sysdep/os/win/wutil.h"
|
||||
#include "lib/sysdep/os/win/wmi.h"
|
||||
|
||||
|
||||
static bool IsOpenAlDllName(const std::wstring& name)
|
||||
static bool IsOpenAlDllName(const NativePath& name)
|
||||
{
|
||||
// (matches "*oal.dll" and "*OpenAL*", as with OpenAL router's search)
|
||||
return name.find(L"oal.dll") != std::wstring::npos || name.find(L"OpenAL") != std::wstring::npos;
|
||||
return name.find(L"oal.dll") != NativePath::npos || name.find(L"OpenAL") != NativePath::npos;
|
||||
}
|
||||
|
||||
// ensures each OpenAL DLL is only listed once (even if present in several
|
||||
// directories on our search path).
|
||||
typedef std::set<std::wstring> StringSet;
|
||||
typedef std::set<NativePath> StringSet;
|
||||
|
||||
// find all OpenAL DLLs in a dir.
|
||||
// call in library search order (exe dir, then win sys dir); otherwise,
|
||||
// DLLs in the executable's starting directory hide those of the
|
||||
// same name in the system directory.
|
||||
static void add_oal_dlls_in_dir(const fs::wpath& path, StringSet& dlls, std::wstring& versionList)
|
||||
static void add_oal_dlls_in_dir(const NativePath& path, StringSet& dlls, VersionList& versionList)
|
||||
{
|
||||
for(fs::wdirectory_iterator it(path); it != fs::wdirectory_iterator(); ++it)
|
||||
FileInfos files;
|
||||
(void)GetDirectoryEntries(path, &files, 0);
|
||||
for(size_t i = 0; i < files.size(); i++)
|
||||
{
|
||||
if(!fs::is_regular(it->status()))
|
||||
continue;
|
||||
|
||||
const fs::wpath& pathname = it->path();
|
||||
const std::wstring& name = pathname.leaf();
|
||||
const NativePath name = files[i].Name();
|
||||
if(!IsOpenAlDllName(name))
|
||||
continue;
|
||||
|
||||
@@ -70,7 +69,7 @@ static void add_oal_dlls_in_dir(const fs::wpath& path, StringSet& dlls, std::wst
|
||||
if(!ret.second) // insert failed - element already there
|
||||
continue;
|
||||
|
||||
wdll_ver_Append(pathname, versionList);
|
||||
wdll_ver_Append(Path::Join(path, name), versionList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +86,7 @@ static void add_oal_dlls_in_dir(const fs::wpath& path, StringSet& dlls, std::wst
|
||||
// the version info for that bogus driver path, we'll skip this code there.
|
||||
// (delay-loading dsound.dll eliminates any overhead)
|
||||
|
||||
static fs::wpath directSoundDriverPath;
|
||||
static NativePath directSoundDriverPath;
|
||||
|
||||
// store sound card name and path to DirectSound driver.
|
||||
// called for each DirectSound driver, but aborts after first valid driver.
|
||||
@@ -100,14 +99,14 @@ static BOOL CALLBACK DirectSoundCallback(void* guid, const wchar_t* UNUSED(descr
|
||||
|
||||
// note: $system\\drivers is not in LoadLibrary's search list,
|
||||
// so we have to give the full pathname.
|
||||
directSoundDriverPath = wutil_SystemPath()/L"drivers"/module;
|
||||
directSoundDriverPath = Path::Join(wutil_SystemPath(), L"drivers", module);
|
||||
|
||||
// we assume the first "driver name" (sound card) is the one we want;
|
||||
// stick with that and stop calling.
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static const fs::wpath& GetDirectSoundDriverPath()
|
||||
static const NativePath& GetDirectSoundDriverPath()
|
||||
{
|
||||
#define DS_OK 0
|
||||
typedef BOOL (CALLBACK* LPDSENUMCALLBACKW)(void*, const wchar_t*, const wchar_t*, void*);
|
||||
@@ -133,7 +132,7 @@ LibError win_get_snd_info()
|
||||
swprintf_s(snd_card, SND_CARD_LEN, L"%ls", wmiMap[L"ProductName"].bstrVal);
|
||||
|
||||
// find all DLLs related to OpenAL and retrieve their versions.
|
||||
std::wstring versionList;
|
||||
VersionList versionList;
|
||||
if(wversion_Number() < WVERSION_VISTA)
|
||||
wdll_ver_Append(GetDirectSoundDriverPath(), versionList);
|
||||
StringSet dlls; // ensures uniqueness
|
||||
|
||||
@@ -38,7 +38,9 @@
|
||||
#include "lib/sysdep/os/win/error_dialog.h"
|
||||
#include "lib/sysdep/os/win/wutil.h"
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#if CONFIG_ENABLE_BOOST
|
||||
# include <boost/algorithm/string.hpp>
|
||||
#endif
|
||||
|
||||
|
||||
#if MSC_VERSION
|
||||
@@ -361,7 +363,7 @@ LibError sys_error_description_r(int user_err, wchar_t* buf, size_t max_chars)
|
||||
}
|
||||
|
||||
|
||||
LibError sys_get_module_filename(void* addr, fs::wpath& pathname)
|
||||
LibError sys_get_module_filename(void* addr, NativePath& pathname)
|
||||
{
|
||||
MEMORY_BASIC_INFORMATION mbi;
|
||||
const SIZE_T bytesWritten = VirtualQuery(addr, &mbi, sizeof(mbi));
|
||||
@@ -380,7 +382,7 @@ LibError sys_get_module_filename(void* addr, fs::wpath& pathname)
|
||||
}
|
||||
|
||||
|
||||
LibError sys_get_executable_name(fs::wpath& pathname)
|
||||
LibError sys_get_executable_name(NativePath& pathname)
|
||||
{
|
||||
wchar_t pathnameBuf[MAX_PATH+1];
|
||||
const DWORD charsWritten = GetModuleFileNameW(0, pathnameBuf, (DWORD)ARRAY_SIZE(pathnameBuf));
|
||||
@@ -391,6 +393,7 @@ LibError sys_get_executable_name(fs::wpath& pathname)
|
||||
return INFO::OK;
|
||||
}
|
||||
|
||||
|
||||
std::wstring sys_get_user_name()
|
||||
{
|
||||
wchar_t usernameBuf[256];
|
||||
@@ -400,6 +403,7 @@ std::wstring sys_get_user_name()
|
||||
return usernameBuf;
|
||||
}
|
||||
|
||||
|
||||
// callback for shell directory picker: used to set starting directory
|
||||
// (for user convenience).
|
||||
static int CALLBACK BrowseCallback(HWND hWnd, unsigned int msg, LPARAM UNUSED(lParam), LPARAM lpData)
|
||||
@@ -414,15 +418,14 @@ static int CALLBACK BrowseCallback(HWND hWnd, unsigned int msg, LPARAM UNUSED(lP
|
||||
return 0;
|
||||
}
|
||||
|
||||
LibError sys_pick_directory(fs::wpath& path)
|
||||
LibError sys_pick_directory(NativePath& path)
|
||||
{
|
||||
// (must not use multi-threaded apartment due to BIF_NEWDIALOGSTYLE)
|
||||
const HRESULT hr = CoInitialize(0);
|
||||
debug_assert(hr == S_OK || hr == S_FALSE); // S_FALSE == already initialized
|
||||
|
||||
// the above BFFM_SETSELECTIONW can't deal with '/' separators,
|
||||
// which is what string() returns.
|
||||
const std::wstring initialPath = path.external_directory_string();
|
||||
// NB: BFFM_SETSELECTIONW can't deal with '/' separators
|
||||
const NativePath initialPath = path;
|
||||
|
||||
// note: bi.pszDisplayName isn't the full path, so it isn't of any use.
|
||||
BROWSEINFOW bi;
|
||||
@@ -454,6 +457,7 @@ LibError sys_pick_directory(fs::wpath& path)
|
||||
return LibError_from_GLE();
|
||||
}
|
||||
|
||||
|
||||
LibError sys_open_url(const std::string& url)
|
||||
{
|
||||
HINSTANCE r = ShellExecuteA(NULL, "open", url.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||||
@@ -463,6 +467,7 @@ LibError sys_open_url(const std::string& url)
|
||||
WARN_RETURN(ERR::FAIL);
|
||||
}
|
||||
|
||||
|
||||
LibError sys_generate_random_bytes(u8* buffer, size_t size)
|
||||
{
|
||||
HCRYPTPROV hCryptProv = 0;
|
||||
@@ -479,6 +484,9 @@ LibError sys_generate_random_bytes(u8* buffer, size_t size)
|
||||
return INFO::OK;
|
||||
}
|
||||
|
||||
|
||||
#if CONFIG_ENABLE_BOOST
|
||||
|
||||
/*
|
||||
* Given a string of the form
|
||||
* "example.com:80"
|
||||
@@ -587,3 +595,5 @@ done:
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> // __argc
|
||||
|
||||
#include "lib/path_util.h"
|
||||
#include "lib/file/file.h"
|
||||
#include "lib/file/vfs/vfs.h"
|
||||
#include "lib/posix/posix.h"
|
||||
@@ -266,31 +267,30 @@ bool wutil_HasCommandLineArgument(const wchar_t* arg)
|
||||
//-----------------------------------------------------------------------------
|
||||
// directories
|
||||
|
||||
fs::wpath wutil_DetectExecutablePath()
|
||||
NativePath wutil_DetectExecutablePath()
|
||||
{
|
||||
wchar_t buf[MAX_PATH+1] = {0};
|
||||
const DWORD len = GetModuleFileNameW(GetModuleHandle(0), buf, MAX_PATH);
|
||||
wchar_t modulePathname[MAX_PATH+1] = {0};
|
||||
const DWORD len = GetModuleFileNameW(GetModuleHandle(0), modulePathname, MAX_PATH);
|
||||
debug_assert(len != 0);
|
||||
const fs::wpath modulePathname(buf);
|
||||
return modulePathname.branch_path();
|
||||
return Path::Path(modulePathname);
|
||||
}
|
||||
|
||||
// (NB: wutil_Init is called before static ctors => use placement new)
|
||||
static fs::wpath* systemPath;
|
||||
static fs::wpath* executablePath;
|
||||
static fs::wpath* appdataPath;
|
||||
static NativePath* systemPath;
|
||||
static NativePath* executablePath;
|
||||
static NativePath* appdataPath;
|
||||
|
||||
const fs::wpath& wutil_SystemPath()
|
||||
const NativePath& wutil_SystemPath()
|
||||
{
|
||||
return *systemPath;
|
||||
}
|
||||
|
||||
const fs::wpath& wutil_ExecutablePath()
|
||||
const NativePath& wutil_ExecutablePath()
|
||||
{
|
||||
return *executablePath;
|
||||
}
|
||||
|
||||
const fs::wpath& wutil_AppdataPath()
|
||||
const NativePath& wutil_AppdataPath()
|
||||
{
|
||||
return *appdataPath;
|
||||
}
|
||||
@@ -305,11 +305,11 @@ static void GetDirectories()
|
||||
{
|
||||
const UINT charsWritten = GetSystemDirectoryW(path, MAX_PATH);
|
||||
debug_assert(charsWritten != 0);
|
||||
systemPath = new(wutil_Allocate(sizeof(fs::wpath))) fs::wpath(path);
|
||||
systemPath = new(wutil_Allocate(sizeof(NativePath))) NativePath(path);
|
||||
}
|
||||
|
||||
// executable's directory
|
||||
executablePath = new(wutil_Allocate(sizeof(fs::wpath))) fs::wpath(wutil_DetectExecutablePath());
|
||||
executablePath = new(wutil_Allocate(sizeof(NativePath))) NativePath(wutil_DetectExecutablePath());
|
||||
|
||||
// application data
|
||||
{
|
||||
@@ -317,18 +317,18 @@ static void GetDirectories()
|
||||
HANDLE token = 0;
|
||||
const HRESULT ret = SHGetFolderPathW(hwnd, CSIDL_APPDATA, token, 0, path);
|
||||
debug_assert(SUCCEEDED(ret));
|
||||
appdataPath = new(wutil_Allocate(sizeof(fs::wpath))) fs::wpath(path);
|
||||
appdataPath = new(wutil_Allocate(sizeof(NativePath))) NativePath(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void FreeDirectories()
|
||||
{
|
||||
systemPath->~basic_path();
|
||||
systemPath->~NativePath();
|
||||
wutil_Free(systemPath);
|
||||
executablePath->~basic_path();
|
||||
executablePath->~NativePath();
|
||||
wutil_Free(executablePath);
|
||||
appdataPath->~basic_path();
|
||||
appdataPath->~NativePath();
|
||||
wutil_Free(appdataPath);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#ifndef INCLUDED_WUTIL
|
||||
#define INCLUDED_WUTIL
|
||||
|
||||
#include "lib/native_path.h"
|
||||
#include "lib/sysdep/os/win/win.h"
|
||||
|
||||
template<typename H>
|
||||
@@ -169,11 +170,11 @@ extern bool wutil_HasCommandLineArgument(const wchar_t* arg);
|
||||
|
||||
// used by wutil_ExecutablePath, but provided in case other code
|
||||
// needs to know this before our wutil_Init runs.
|
||||
extern fs::wpath wutil_DetectExecutablePath();
|
||||
extern NativePath wutil_DetectExecutablePath();
|
||||
|
||||
extern const fs::wpath& wutil_SystemPath();
|
||||
extern const fs::wpath& wutil_ExecutablePath();
|
||||
extern const fs::wpath& wutil_AppdataPath();
|
||||
extern const NativePath& wutil_SystemPath();
|
||||
extern const NativePath& wutil_ExecutablePath();
|
||||
extern const NativePath& wutil_AppdataPath();
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#define INCLUDED_SYSDEP
|
||||
|
||||
#include "lib/debug.h" // ErrorReactionInternal
|
||||
#include "lib/native_path.h"
|
||||
|
||||
#include <cstdarg> // needed for sys_vswprintf
|
||||
|
||||
@@ -110,7 +111,7 @@ extern LibError sys_error_description_r(int err, wchar_t* buf, size_t max_chars)
|
||||
*
|
||||
* note: this is useful for handling exceptions in other modules.
|
||||
**/
|
||||
LibError sys_get_module_filename(void* addr, fs::wpath& pathname);
|
||||
LibError sys_get_module_filename(void* addr, NativePath& pathname);
|
||||
|
||||
/**
|
||||
* Get path to the current executable.
|
||||
@@ -120,7 +121,7 @@ LibError sys_get_module_filename(void* addr, fs::wpath& pathname);
|
||||
*
|
||||
* this is useful for determining installation directory, e.g. for VFS.
|
||||
**/
|
||||
LIB_API LibError sys_get_executable_name(fs::wpath& pathname);
|
||||
LIB_API LibError sys_get_executable_name(NativePath& pathname);
|
||||
|
||||
/**
|
||||
* Get the current user's login name.
|
||||
@@ -136,7 +137,7 @@ extern std::wstring sys_get_user_name();
|
||||
* faster browsing. if INFO::OK is returned, it receives
|
||||
* chosen directory path.
|
||||
**/
|
||||
extern LibError sys_pick_directory(fs::wpath& path);
|
||||
extern LibError sys_pick_directory(NativePath& path);
|
||||
|
||||
/**
|
||||
* Open the user's default web browser to the given URL.
|
||||
|
||||
@@ -49,16 +49,16 @@ public:
|
||||
|
||||
void test_sys_get_executable_name()
|
||||
{
|
||||
fs::wpath path;
|
||||
NativePath path;
|
||||
|
||||
// Try it first with the real executable (i.e. the
|
||||
// one that's running this test code)
|
||||
TS_ASSERT_EQUALS(sys_get_executable_name(path), INFO::OK);
|
||||
// Check it's absolute
|
||||
TSM_ASSERT(std::wstring(L"Path: ")+path.string(), path_is_absolute(path.string().c_str()));
|
||||
TSM_ASSERT(NativePath(L"Path: ")+path, path_is_absolute(path.c_str()));
|
||||
// Check the file exists
|
||||
struct stat s;
|
||||
TSM_ASSERT_EQUALS(std::wstring(L"Path: ")+path.string(), wstat(path.string().c_str(), &s), 0);
|
||||
TSM_ASSERT_EQUALS(NativePath(L"Path: ")+path, wstat(path.c_str(), &s), 0);
|
||||
|
||||
// Do some platform-specific tests, based on the
|
||||
// implementations of sys_get_executable_name:
|
||||
@@ -111,12 +111,12 @@ public:
|
||||
{
|
||||
Mock_dladdr d(rootstr+"/example/executable");
|
||||
TS_ASSERT_EQUALS(sys_get_executable_name(path), INFO::OK);
|
||||
TS_ASSERT_WSTR_EQUALS(path.string(), rootstrw+L"/example/executable");
|
||||
TS_ASSERT_WSTR_EQUALS(path, rootstrw+L"/example/executable");
|
||||
}
|
||||
{
|
||||
Mock_dladdr d(rootstr+"/example/./a/b/../e/../../executable");
|
||||
TS_ASSERT_EQUALS(sys_get_executable_name(path), INFO::OK);
|
||||
TS_ASSERT_WSTR_EQUALS(path.string(), rootstrw+L"/example/executable");
|
||||
TS_ASSERT_WSTR_EQUALS(path, rootstrw+L"/example/executable");
|
||||
}
|
||||
|
||||
// Try with relative paths
|
||||
@@ -124,19 +124,19 @@ public:
|
||||
Mock_dladdr d("./executable");
|
||||
Mock_getcwd m(rootstr+"/example");
|
||||
TS_ASSERT_EQUALS(sys_get_executable_name(path), INFO::OK);
|
||||
TS_ASSERT_WSTR_EQUALS(path.string(), rootstrw+L"/example/executable");
|
||||
TS_ASSERT_WSTR_EQUALS(path, rootstrw+L"/example/executable");
|
||||
}
|
||||
{
|
||||
Mock_dladdr d("./executable");
|
||||
Mock_getcwd m(rootstr+"/example/");
|
||||
TS_ASSERT_EQUALS(sys_get_executable_name(path), INFO::OK);
|
||||
TS_ASSERT_WSTR_EQUALS(path.string(), rootstrw+L"/example/executable");
|
||||
TS_ASSERT_WSTR_EQUALS(path, rootstrw+L"/example/executable");
|
||||
}
|
||||
{
|
||||
Mock_dladdr d("../d/../../f/executable");
|
||||
Mock_getcwd m(rootstr+"/example/a/b/c");
|
||||
TS_ASSERT_EQUALS(sys_get_executable_name(path), INFO::OK);
|
||||
TS_ASSERT_WSTR_EQUALS(path.string(), rootstrw+L"/example/a/f/executable");
|
||||
TS_ASSERT_WSTR_EQUALS(path, rootstrw+L"/example/a/f/executable");
|
||||
}
|
||||
|
||||
// Try with pathless names
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
#include "lib/timer.h"
|
||||
#include "lib/bits.h"
|
||||
#include "lib/path_util.h"
|
||||
#include "lib/sysdep/cpu.h"
|
||||
|
||||
#include "tex_codec.h"
|
||||
@@ -565,7 +566,7 @@ bool tex_is_known_extension(const VfsPath& pathname)
|
||||
{
|
||||
const TexCodecVTbl* dummy;
|
||||
// found codec for it => known extension
|
||||
const std::wstring extension = fs::extension(pathname);
|
||||
const NativePath extension = Path::Extension(pathname);
|
||||
if(tex_codec_for_filename(extension, &dummy) == INFO::OK)
|
||||
return true;
|
||||
|
||||
@@ -698,7 +699,7 @@ size_t tex_hdr_size(const VfsPath& filename)
|
||||
{
|
||||
const TexCodecVTbl* c;
|
||||
|
||||
const std::wstring extension = fs::extension(filename);
|
||||
const NativePath extension = Path::Extension(filename);
|
||||
CHECK_ERR(tex_codec_for_filename(extension, &c));
|
||||
return c->hdr_size(0);
|
||||
}
|
||||
@@ -750,7 +751,7 @@ LibError tex_decode(const shared_ptr<u8>& data, size_t data_size, Tex* t)
|
||||
}
|
||||
|
||||
|
||||
LibError tex_encode(Tex* t, const std::wstring& extension, DynArray* da)
|
||||
LibError tex_encode(Tex* t, const NativePath& extension, DynArray* da)
|
||||
{
|
||||
CHECK_TEX(t);
|
||||
CHECK_ERR(tex_validate_plain_format(t->bpp, t->flags));
|
||||
|
||||
@@ -290,7 +290,7 @@ extern LibError tex_decode(const shared_ptr<u8>& data, size_t data_size, Tex* t)
|
||||
* when no longer needed. Invalid unless function succeeds.
|
||||
* @return LibError
|
||||
**/
|
||||
extern LibError tex_encode(Tex* t, const std::wstring& extension, DynArray* da);
|
||||
extern LibError tex_encode(Tex* t, const NativePath& extension, DynArray* da);
|
||||
|
||||
/**
|
||||
* store the given image data into a Tex object; this will be as if
|
||||
|
||||
@@ -74,7 +74,7 @@ static bool bmp_is_hdr(const u8* file)
|
||||
}
|
||||
|
||||
|
||||
static bool bmp_is_ext(const std::wstring& extension)
|
||||
static bool bmp_is_ext(const NativePath& extension)
|
||||
{
|
||||
return !wcscasecmp(extension.c_str(), L".bmp");
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ void tex_codec_unregister_all()
|
||||
// or return ERR::TEX_UNKNOWN_FORMAT if unknown.
|
||||
// note: does not raise a warning because it is used by
|
||||
// tex_is_known_extension.
|
||||
LibError tex_codec_for_filename(const std::wstring& extension, const TexCodecVTbl** c)
|
||||
LibError tex_codec_for_filename(const NativePath& extension, const TexCodecVTbl** c)
|
||||
{
|
||||
for(*c = codecs; *c; *c = (*c)->next)
|
||||
{
|
||||
|
||||
@@ -96,7 +96,7 @@ struct TexCodecVTbl
|
||||
* @param extension (including '.')
|
||||
* @return bool
|
||||
**/
|
||||
bool (*is_ext)(const std::wstring& extension);
|
||||
bool (*is_ext)(const NativePath& extension);
|
||||
|
||||
/**
|
||||
* return size of the file header supported by this codec.
|
||||
@@ -170,7 +170,7 @@ extern int tex_codec_register(TexCodecVTbl* c);
|
||||
* called by tex_is_known_extension) if no codec indicates they can
|
||||
* handle the given extension.
|
||||
**/
|
||||
extern LibError tex_codec_for_filename(const std::wstring& extension, const TexCodecVTbl** c);
|
||||
extern LibError tex_codec_for_filename(const NativePath& extension, const TexCodecVTbl** c);
|
||||
|
||||
/**
|
||||
* find codec that recognizes the header's magic field.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user