mirror of
https://github.com/1dot13/source.git
synced 2026-07-22 13:40:22 +02:00
- Deleted old and unused VFS folder (project)
o I forget to delete that, when merging the complete development trunk back into the official trunk - Deleted old an unused Multiplayer/test_space.* files git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@4496 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
@@ -1,403 +0,0 @@
|
||||
#ifdef PRECOMPILEDHEADERS
|
||||
#include "Tactical All.h"
|
||||
#include "strategic.h"
|
||||
#else
|
||||
#include "builddefines.h"
|
||||
#include "Bullets.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "wcheck.h"
|
||||
#include "stdlib.h"
|
||||
#include "debug.h"
|
||||
#include "math.h"
|
||||
#include "worlddef.h"
|
||||
#include "worldman.h"
|
||||
#include "renderworld.h"
|
||||
#include "Assignments.h"
|
||||
#include "Soldier Control.h"
|
||||
#include "Animation Control.h"
|
||||
#include "Animation Data.h"
|
||||
#include "Isometric Utils.h"
|
||||
#include "Event Pump.h"
|
||||
#include "Timer Control.h"
|
||||
#include "Render Fun.h"
|
||||
#include "Render Dirty.h"
|
||||
#include "mousesystem.h"
|
||||
#include "interface.h"
|
||||
#include "sysutil.h"
|
||||
#include "FileMan.h"
|
||||
#include "points.h"
|
||||
#include "Random.h"
|
||||
#include "ai.h"
|
||||
#include "Interactive Tiles.h"
|
||||
#include "soldier ani.h"
|
||||
#include "english.h"
|
||||
#include "overhead.h"
|
||||
#include "Soldier Profile.h"
|
||||
#include "Game Clock.h"
|
||||
#include "soldier create.h"
|
||||
#include "Merc Hiring.h"
|
||||
#include "Game Event Hook.h"
|
||||
#include "message.h"
|
||||
#include "strategicmap.h"
|
||||
#include "strategic.h"
|
||||
#include "items.h"
|
||||
#include "Soldier Add.h"
|
||||
#include "History.h"
|
||||
#include "Squads.h"
|
||||
#include "Strategic Merc Handler.h"
|
||||
#include "Dialogue Control.h"
|
||||
#include "Map Screen Interface.h"
|
||||
#include "Map Screen Interface Map.h"
|
||||
#include "screenids.h"
|
||||
#include "jascreens.h"
|
||||
#include "text.h"
|
||||
#include "Merc Contract.h"
|
||||
#include "LaptopSave.h"
|
||||
#include "personnel.h"
|
||||
#include "Auto Resolve.h"
|
||||
#include "Map Screen Interface Bottom.h"
|
||||
#include "Quests.h"
|
||||
#include "GameSettings.h"
|
||||
#endif
|
||||
|
||||
#include "MessageIdentifiers.h"
|
||||
#include "RakNetworkFactory.h"
|
||||
#include "RakPeerInterface.h"
|
||||
#include "RakNetStatistics.h"
|
||||
#include "RakNetTypes.h"
|
||||
#include "BitStream.h"
|
||||
#include <assert.h>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "tactical placement gui.h"
|
||||
#include "connect.h"
|
||||
#include "network.h"
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
#include "text.h"
|
||||
#include "Types.h"
|
||||
#include "connect.h"
|
||||
#include "message.h"
|
||||
#include "Event pump.h"
|
||||
#include "Soldier Init List.h"
|
||||
#include "Overhead.h"
|
||||
#include "weapons.h"
|
||||
#include "Merc Hiring.h"
|
||||
#include "soldier profile.h"
|
||||
|
||||
#include"laptop.h"
|
||||
#include "florist Order Form.h"
|
||||
#include "prebattle interface.h"
|
||||
#include "teamturns.h"
|
||||
extern INT8 SquadMovementGroups[ ];
|
||||
|
||||
#include "test_space.h"
|
||||
#include "soldier control.h"
|
||||
|
||||
bool ovh_advance;
|
||||
bool ovh_ready;
|
||||
|
||||
#include "opplist.h"
|
||||
#include "fresh_header.h"
|
||||
//int cnt = 40;
|
||||
#include "game init.h"
|
||||
|
||||
void test_func2 (void)//now bound to "0"
|
||||
{
|
||||
ScreenMsg( FONT_LTGREEN, MSG_MPSYSTEM, L"test_func2 - function testing ground:" );
|
||||
|
||||
|
||||
SOLDIERTYPE * pSoldier=MercPtrs[ 0 ];
|
||||
|
||||
|
||||
|
||||
//RemoveOneOpponent( pSoldier );
|
||||
//SOLDIERTYPE * pSoldier2=MercPtrs[ 127 ];
|
||||
//
|
||||
////pSoldier->AdjustNoAPToFinishMove( TRUE );
|
||||
//
|
||||
////pSoldier2->bVisible = 1;
|
||||
//ManSeesMan(pSoldier,pSoldier2,pSoldier2->sGridNo,pSoldier2->pathing.bLevel,0,1);
|
||||
|
||||
|
||||
/*
|
||||
INT16 sCellX, sCellY;
|
||||
sCellX = CenterX( 22163 );
|
||||
sCellY = CenterY( 22163 );
|
||||
|
||||
pSoldier->EVENT_InternalSetSoldierPosition( sCellX, sCellY ,FALSE, FALSE, FALSE );*/
|
||||
|
||||
|
||||
|
||||
|
||||
//SOLDIERTYPE * pSoldier=MercPtrs[ 0 ];
|
||||
//pSoldier->bLife=0;
|
||||
//SoldierCollapse( pSoldier );
|
||||
//SoldierTakeDamage( pFirer, ANIM_CROUCH, 1, 100, TAKE_DAMAGE_BLOODLOSS, NOBODY, NOWHERE, 0, TRUE );
|
||||
//TurnSoldierIntoCorpse( pFirer, FALSE, FALSE );
|
||||
|
||||
//SOLDIERTYPE * pSoldier=MercPtrs[ 0 ];
|
||||
////
|
||||
//pSoldier->fNoAPToFinishMove = TRUE;
|
||||
//
|
||||
//
|
||||
//fInterfacePanelDirty = DIRTYLEVEL2;
|
||||
|
||||
|
||||
|
||||
////EVENT_InitNewSoldierAnim(pSoldier,3,0,0);
|
||||
//pSoldier->ubDesiredHeight = ANIM_CROUCH;
|
||||
|
||||
//SOLDIERTYPE * pSoldier=MercPtrs[ 0 ];
|
||||
//pSoldier->usAnimState=50;
|
||||
//TurnSoldierIntoCorpse( pSoldier, TRUE, TRUE );
|
||||
|
||||
//gTacticalStatus.uiFlags |= SHOW_ALL_MERCS;
|
||||
//BeginTeamTurn (0);
|
||||
|
||||
|
||||
|
||||
;
|
||||
|
||||
//gTacticalStatus.ubCurrentTeam = OUR_TEAM;
|
||||
//guiPendingOverrideEvent = LA_ENDUIOUTURNLOCK;
|
||||
//ExitCombatMode();
|
||||
//fInterfacePanelDirty = DIRTYLEVEL2;
|
||||
|
||||
|
||||
//InitPlayerUIBar( FALSE );
|
||||
|
||||
|
||||
//UIHandleLUIEndLock( NULL );
|
||||
//if( (gTacticalStatus.uiFlags & TURNBASED) && (gTacticalStatus.uiFlags & INCOMBAT) )
|
||||
// ScreenMsg( FONT_LTGREEN, MSG_MPSYSTEM, L"combat turn based" );
|
||||
//else
|
||||
// ScreenMsg( FONT_LTGREEN, MSG_MPSYSTEM, L"not" );
|
||||
|
||||
|
||||
//SOLDIERTYPE * pSoldier=MercPtrs[ 0 ];
|
||||
//
|
||||
// if ( ( gAnimControl[ pSoldier->usAnimState ].uiFlags &( ANIM_FIREREADY | ANIM_FIRE ) ) )
|
||||
// {
|
||||
// ScreenMsg( FONT_LTGREEN, MSG_MPSYSTEM, L"Ready" );
|
||||
// }
|
||||
// else
|
||||
// ScreenMsg( FONT_LTGREEN, MSG_MPSYSTEM, L"Not" );
|
||||
|
||||
////fInterfacePanelDirty = DIRTYLEVEL2;
|
||||
////guiPendingOverrideEvent = LU_ENDUILOCK;
|
||||
////guiPendingOverrideEvent = LA_ENDUIOUTURNLOCK;
|
||||
//
|
||||
//
|
||||
//
|
||||
// ClearIntList();
|
||||
// //guiPendingOverrideEvent = LU_ENDUILOCK;
|
||||
// guiPendingOverrideEvent = LA_ENDUIOUTURNLOCK;
|
||||
// fInterfacePanelDirty = DIRTYLEVEL2;
|
||||
//
|
||||
// if ( gusSelectedSoldier != NOBODY )
|
||||
// {
|
||||
// SlideTo( NOWHERE, gusSelectedSoldier, NOBODY ,SETLOCATOR);
|
||||
// MercPtrs[ gusSelectedSoldier ]->DoMercBattleSound( BATTLE_SOUND_ATTN1 );
|
||||
// }
|
||||
// InitPlayerUIBar( 0 );
|
||||
//HandleTacticalUI( );
|
||||
//guiPendingOverrideEvent = LA_BEGINUIOURTURNLOCK;
|
||||
//int n = 0;
|
||||
//for(cnt=40+n ; cnt < 40+5+n ; cnt++)
|
||||
//{
|
||||
//
|
||||
//QuickCreateProfileMerc( CIV_TEAM, cnt );jk
|
||||
//
|
||||
//RecruitRPC( cnt );
|
||||
//Sleep(3000);
|
||||
//}
|
||||
//QuickCreateProfileMerc( CIV_TEAM, cnt );
|
||||
//RecruitRPC( cnt );
|
||||
//cnt++;
|
||||
|
||||
|
||||
//HandleDoorChangeFromGridNo( pSoldier, 18451, FALSE );
|
||||
|
||||
//OBJECTTYPE Object;
|
||||
//for (cnt=0; cnt<20;cnt++)
|
||||
//{
|
||||
//CreateItem( 201, 100, &Object );
|
||||
//
|
||||
//AutoPlaceObject( pSoldier, &Object, TRUE );
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
//INT16 sCellX, sCellY;
|
||||
////ConvertGridNoToCellXY( 13576, &sCellX, &sCellY );
|
||||
//
|
||||
// sCellX = CenterX( 13576 );
|
||||
// sCellY = CenterY( 13576 );
|
||||
//
|
||||
// //pSoldier->dXPos = sCellX;
|
||||
// //pSoldier->dYPos = sCellY;
|
||||
//
|
||||
// //pSoldier->sX = (INT16)sCellX;
|
||||
// //pSoldier->sY = (INT16)sCellY;
|
||||
// EVENT_InitNewSoldierAnim( pSoldier, 6, 0, FALSE );
|
||||
|
||||
//EVENT_SetSoldierPositionForceDelete( pSoldier, (FLOAT)sCellX, (FLOAT)sCellY );
|
||||
|
||||
//HaultSoldierFromSighting( pSoldier, 1 );
|
||||
//pSoldier->sScheduledStop=7961;
|
||||
////
|
||||
////EVENT_SetSoldierPosition( pSoldier, 1140, 1170 );
|
||||
//AdjustNoAPToFinishMove( pSoldier, TRUE );
|
||||
//pSoldier->fTurningFromPronePosition = FALSE;
|
||||
//
|
||||
////HaultSoldierFromSighting( pSoldier, 1 );
|
||||
|
||||
|
||||
|
||||
|
||||
//UINT16 usPathData[30];
|
||||
//usPathData[0]=3;
|
||||
//usPathData[1]=5;
|
||||
//usPathData[2]=7;
|
||||
//
|
||||
//pSoldier->sFinalDestination = 8446;
|
||||
//
|
||||
//pSoldier->usPathDataSize=3;
|
||||
//pSoldier->usPathIndex=0;
|
||||
//
|
||||
//memcpy(pSoldier->usPathingData,usPathData,sizeof(UINT16)*30);
|
||||
|
||||
|
||||
//INT16 sNewGridNo;
|
||||
|
||||
//sNewGridNo = NewGridNo( (UINT16)pSoldier->sGridNo, DirectionInc( (UINT8)pSoldier->usPathingData[ pSoldier->usPathDataSize ] ) );
|
||||
|
||||
//pSoldier->sFinalDestination = sNewGridNo;
|
||||
|
||||
//EVENT_InitNewSoldierAnim( pSoldier, 0, 0, FALSE );
|
||||
|
||||
|
||||
|
||||
//ovh_advance=true;
|
||||
//
|
||||
//
|
||||
// CHAR16 string[255];
|
||||
// memcpy(string,TeamTurnString[ 7 ], sizeof( CHAR16) * 255 );
|
||||
//
|
||||
// CHAR16 name[255];
|
||||
// mbstowcs( name, CLIENT_NAME, sizeof (char)*30 );
|
||||
//
|
||||
// CHAR16 full[255];
|
||||
// swprintf(full, L"%s - '%s'",string,name);
|
||||
////
|
||||
////
|
||||
// memcpy( TeamTurnString[ 7 ] , full, sizeof( CHAR16) * 255 );
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//BOOLEAN fMadeCorpse;
|
||||
// SOLDIERTYPE * pSoldier=MercPtrs[ 0 ];
|
||||
//pSoldier->bLife = 0;
|
||||
// HandleSoldierDeath( pSoldier, &fMadeCorpse );
|
||||
|
||||
//guiPendingOverrideEvent = LA_BEGINUIOURTURNLOCK;
|
||||
//
|
||||
//guiPendingOverrideEvent = CA_MERC_SHOOT;
|
||||
//
|
||||
//guiPendingOverrideEvent = G_GETTINGITEM;
|
||||
//
|
||||
//guiPendingOverrideEvent = LU_ON_TERRAIN;
|
||||
//
|
||||
//guiPendingOverrideEvent = ET_ON_TERRAIN;
|
||||
//
|
||||
//guiPendingOverrideEvent = A_CHANGE_TO_MOVE;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//HandleTacticalUI( );
|
||||
|
||||
|
||||
|
||||
//CHAR8 string[60];
|
||||
// wcscpy( string, "GetVideoObject" );
|
||||
//sprintf( string, "hello");
|
||||
/* char szDefault[255];
|
||||
sprintf(szDefault, "%s","hello");
|
||||
|
||||
|
||||
ScreenMsg( FONT_LTGREEN, MSG_MPSYSTEM, L"%S has connected.",szDefault );*/
|
||||
|
||||
//manual overide
|
||||
//manual_overide();
|
||||
//allow_bullet=1;
|
||||
//
|
||||
|
||||
//if(1)
|
||||
//{
|
||||
// stage=0;
|
||||
// ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"1" );
|
||||
// //FireBulletGivenTarget( MercPtrs[0], 875, 995, 1, 11, -74, 0, 0 );
|
||||
//
|
||||
//
|
||||
// INT32 iBullet;
|
||||
// BULLET * pBullet;
|
||||
|
||||
// iBullet = CreateBullet( 0, 0, 0,11 );
|
||||
// if (iBullet == -1)
|
||||
// {
|
||||
// ScreenMsg( FONT_YELLOW, MSG_MPSYSTEM, L"Failed to create bullet");
|
||||
// }
|
||||
// pBullet = GetBulletPtr( iBullet );
|
||||
|
||||
// //ScreenMsg( FONT_YELLOW, MSG_MPSYSTEM, L"Created Bullet");
|
||||
|
||||
// pBullet->fCheckForRoof=0;
|
||||
// pBullet->qIncrX=-917769;
|
||||
// pBullet->qIncrY=-507159;
|
||||
// pBullet->qIncrZ=-537679;
|
||||
// pBullet->sHitBy=-30;
|
||||
// pBullet->ddHorizAngle=-2.5959375990628013;
|
||||
// pBullet->fAimed=1;
|
||||
// pBullet->ubItemStatus=0;
|
||||
// pBullet->qCurrX=1231159031;
|
||||
// pBullet->qCurrY=1221083881;
|
||||
// pBullet->qCurrZ=182963121;
|
||||
// pBullet->iImpact=28;
|
||||
// pBullet->iRange=200;
|
||||
// pBullet->sTargetGridNo=15929;
|
||||
// pBullet->bStartCubesAboveLevelZ=2;
|
||||
// pBullet->bEndCubesAboveLevelZ=0;
|
||||
// pBullet->iDistanceLimit=328;
|
||||
|
||||
|
||||
// SOLDIERTYPE * pFirer=MercPtrs[ 0 ];
|
||||
|
||||
// //FireBullet( pFirer, pBullet, FALSE );
|
||||
// if(is_client)send_bullet( pBullet, 11 );//hayden
|
||||
|
||||
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// stage=1;
|
||||
// ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"0" );
|
||||
// FireBulletGivenTarget( MercPtrs[0], 875, 995, 1, 11, -74, 0, 0 );
|
||||
//}
|
||||
@@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#define ENABLE_COLLISION (is_server && pBullet->pFirer->ubID<120) || (!is_server && is_client && pBullet->pFirer->ubID<20) || (!is_server && !is_client)
|
||||
|
||||
void send_bullet( BULLET * pBullet, UINT16 usHandItem);
|
||||
|
||||
INT8 FireBullet( SOLDIERTYPE * pFirer, BULLET * pBullet, BOOLEAN fFake );
|
||||
|
||||
#define NOCDCHECK
|
||||
|
||||
extern bool ovh_advance;
|
||||
extern bool ovh_ready;
|
||||
void request_ovh(UINT8 ubID);
|
||||
@@ -1,132 +0,0 @@
|
||||
#include "vfs_dir_file.h"
|
||||
#include "../Interface/vfs_directory_interface.h"
|
||||
#include "../vfs_settings.h"
|
||||
#include "../os_functions.h"
|
||||
|
||||
vfs::CReadOnlyDirFile::CReadOnlyDirFile(vfs::Path const& filename, tLocation *directory)
|
||||
: vfs::CReadOnlyFile(filename), _location(directory)
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CReadOnlyDirFile::~CReadOnlyDirFile()
|
||||
{
|
||||
}
|
||||
|
||||
vfs::Path vfs::CReadOnlyDirFile::getPath()
|
||||
{
|
||||
if(_location)
|
||||
{
|
||||
return _location->getPath() + m_filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_filename;
|
||||
}
|
||||
}
|
||||
|
||||
bool vfs::CReadOnlyDirFile::_getRealPath(vfs::Path& path)
|
||||
{
|
||||
if(_location)
|
||||
{
|
||||
path = _location->getRealPath() + m_filename;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
vfs::FileAttributes vfs::CReadOnlyDirFile::getAttributes()
|
||||
{
|
||||
vfs::FileAttributes _attribs = vfs::CReadOnlyFile::getAttributes();
|
||||
|
||||
vfs::UInt32 attr = _attribs.getAttrib();
|
||||
attr |= vfs::FileAttributes::ATTRIB_READONLY;
|
||||
|
||||
return vfs::FileAttributes(attr, vfs::FileAttributes::LT_READONLY_DIRECTORY);
|
||||
}
|
||||
|
||||
bool vfs::CReadOnlyDirFile::openRead()
|
||||
{
|
||||
vfs::Path filename;
|
||||
if(!_getRealPath(filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _internalOpenRead(filename);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
vfs::CDirFile::CDirFile(vfs::Path const& filename, tLocation *directory)
|
||||
: CFile(filename), _location(directory)
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CDirFile::~CDirFile()
|
||||
{
|
||||
}
|
||||
|
||||
vfs::Path vfs::CDirFile::getPath()
|
||||
{
|
||||
if(_location)
|
||||
{
|
||||
return _location->getPath() + m_filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_filename;
|
||||
}
|
||||
}
|
||||
|
||||
bool vfs::CDirFile::deleteFile()
|
||||
{
|
||||
this->close();
|
||||
vfs::Path fname;
|
||||
if(_getRealPath(fname))
|
||||
{
|
||||
return os::deleteRealFile(fname);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool vfs::CDirFile::_getRealPath(vfs::Path& path)
|
||||
{
|
||||
if(_location)
|
||||
{
|
||||
path = _location->getRealPath() + m_filename;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
vfs::FileAttributes vfs::CDirFile::getAttributes()
|
||||
{
|
||||
vfs::FileAttributes _attribs = vfs::CFile::getAttributes();
|
||||
|
||||
return vfs::FileAttributes(_attribs.getAttrib(), vfs::FileAttributes::LT_DIRECTORY);
|
||||
}
|
||||
|
||||
bool vfs::CDirFile::openRead()
|
||||
{
|
||||
vfs::Path filename;
|
||||
if(!_getRealPath(filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _internalOpenRead(filename);
|
||||
}
|
||||
|
||||
bool vfs::CDirFile::openWrite(bool createWhenNotExist, bool truncate)
|
||||
{
|
||||
vfs::Path filename;
|
||||
if(!_getRealPath(filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _internalOpenWrite(filename, createWhenNotExist, truncate);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
#ifndef _VFS_DIR_FILE_H_
|
||||
#define _VFS_DIR_FILE_H_
|
||||
|
||||
#include "vfs_file.h"
|
||||
|
||||
#include "../Interface/vfs_file_interface.h"
|
||||
#include "../Interface/vfs_location_aware_file_interface.h"
|
||||
#include "../Interface/vfs_location_interface.h"
|
||||
#include "../Interface/vfs_directory_interface.h"
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class VFS_API CReadOnlyDirFile : public vfs::CReadOnlyFile
|
||||
{
|
||||
protected:
|
||||
typedef vfs::TDirectory<vfs::CReadOnlyDirFile::write_type> tLocation;
|
||||
public:
|
||||
CReadOnlyDirFile(vfs::Path const& filename, tLocation *directory);
|
||||
virtual ~CReadOnlyDirFile();
|
||||
|
||||
virtual vfs::FileAttributes getAttributes();
|
||||
|
||||
virtual vfs::Path getPath();
|
||||
|
||||
virtual bool openRead();
|
||||
|
||||
virtual bool _getRealPath(vfs::Path& path);
|
||||
private:
|
||||
tLocation* _location;
|
||||
};
|
||||
|
||||
class VFS_API CDirFile : public vfs::CFile
|
||||
{
|
||||
typedef vfs::TDirectory<vfs::CFile::write_type> tLocation;
|
||||
public:
|
||||
CDirFile(vfs::Path const& filename, tLocation *directory);
|
||||
virtual ~CDirFile();
|
||||
|
||||
virtual vfs::FileAttributes getAttributes();
|
||||
|
||||
virtual vfs::Path getPath();
|
||||
virtual bool deleteFile();
|
||||
|
||||
virtual bool openRead();
|
||||
virtual bool openWrite(bool createWhenNotExist = false, bool truncate = false);
|
||||
|
||||
virtual bool _getRealPath(vfs::Path& path);
|
||||
private:
|
||||
tLocation* _location;
|
||||
};
|
||||
} // end namespace
|
||||
|
||||
#endif // _VFS_DIR_FILE_H_
|
||||
|
||||
@@ -1,380 +0,0 @@
|
||||
#include "vfs_file.h"
|
||||
#include "../vfs_debug.h"
|
||||
#include "../vfs_settings.h"
|
||||
#include "../os_functions.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define ERROR_FILE(msg) BuildString().add(L"[").add(this->getPath()).add(L"] - ").add(msg).get()
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define IS_FILE_VALID() THROWIFFALSE( m_file.good(), ERROR_FILE(BuildString().add(L"invalid file object").add(m_file.eof() ? L" [EOF]" : L"").get()) );
|
||||
#else
|
||||
#define IS_FILE_VALID() THROWIFFALSE( m_file.good(), ERROR_FILE(BuildString().add(L"invalid file object").add(m_file.eof() ? L" [EOF]" : L"").get()) );
|
||||
#endif
|
||||
|
||||
static inline bool hasAttrib(vfs::UInt32 const& attrib, vfs::UInt32 Attribs)
|
||||
{
|
||||
return attrib == (attrib & Attribs);
|
||||
}
|
||||
|
||||
static inline void copyAttributes(vfs::UInt32 osFileAttributes, vfs::UInt32& vfsFileAttributes)
|
||||
{
|
||||
if(os::FileAttributes::ATTRIB_ARCHIVE == (os::FileAttributes::ATTRIB_ARCHIVE & osFileAttributes))
|
||||
{
|
||||
vfsFileAttributes |= vfs::FileAttributes::ATTRIB_ARCHIVE;
|
||||
}
|
||||
if(os::FileAttributes::ATTRIB_COMPRESSED == (os::FileAttributes::ATTRIB_COMPRESSED & osFileAttributes))
|
||||
{
|
||||
vfsFileAttributes |= vfs::FileAttributes::ATTRIB_COMPRESSED;
|
||||
}
|
||||
if(os::FileAttributes::ATTRIB_DIRECTORY == (os::FileAttributes::ATTRIB_DIRECTORY & osFileAttributes))
|
||||
{
|
||||
vfsFileAttributes |= vfs::FileAttributes::ATTRIB_DIRECTORY;
|
||||
}
|
||||
if(os::FileAttributes::ATTRIB_HIDDEN == (os::FileAttributes::ATTRIB_HIDDEN & osFileAttributes))
|
||||
{
|
||||
vfsFileAttributes |= vfs::FileAttributes::ATTRIB_HIDDEN;
|
||||
}
|
||||
if(os::FileAttributes::ATTRIB_NORMAL == (os::FileAttributes::ATTRIB_NORMAL & osFileAttributes))
|
||||
{
|
||||
vfsFileAttributes |= vfs::FileAttributes::ATTRIB_NORMAL;
|
||||
}
|
||||
if(os::FileAttributes::ATTRIB_OFFLINE == (os::FileAttributes::ATTRIB_OFFLINE & osFileAttributes))
|
||||
{
|
||||
vfsFileAttributes |= vfs::FileAttributes::ATTRIB_OFFLINE;
|
||||
}
|
||||
if(os::FileAttributes::ATTRIB_READONLY == (os::FileAttributes::ATTRIB_READONLY & osFileAttributes))
|
||||
{
|
||||
vfsFileAttributes |= vfs::FileAttributes::ATTRIB_READONLY;
|
||||
}
|
||||
if(os::FileAttributes::ATTRIB_SYSTEM == (os::FileAttributes::ATTRIB_SYSTEM & osFileAttributes))
|
||||
{
|
||||
vfsFileAttributes |= vfs::FileAttributes::ATTRIB_SYSTEM;
|
||||
}
|
||||
if(os::FileAttributes::ATTRIB_TEMPORARY == (os::FileAttributes::ATTRIB_TEMPORARY & osFileAttributes))
|
||||
{
|
||||
vfsFileAttributes |= vfs::FileAttributes::ATTRIB_TEMPORARY;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void _openFile(std::fstream& file, vfs::Path const& filename, std::ios::openmode mode)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
utf8string::str_t const& fname = filename.c_wcs();
|
||||
vfs::Settings::getUseUnicode() ?
|
||||
file.open( fname.c_str(), mode ) :
|
||||
file.open( utf8string::narrow(fname.c_str(),fname.length()).c_str(), mode );
|
||||
#else
|
||||
file.open(utf8string::as_utf8(filename()).c_str(), mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline std::ios::seekdir _seekDir(vfs::IBaseFile::ESeekDir seekDir)
|
||||
{
|
||||
if(seekDir == vfs::IBaseFile::SD_BEGIN)
|
||||
{
|
||||
return std::ios::beg;
|
||||
}
|
||||
else if(seekDir == vfs::IBaseFile::SD_CURRENT)
|
||||
{
|
||||
return std::ios::cur;
|
||||
}
|
||||
else if(seekDir == vfs::IBaseFile::SD_END)
|
||||
{
|
||||
return std::ios::end;
|
||||
}
|
||||
THROWEXCEPTION(BuildString().add(L"Unknown seek direction [").add(seekDir).add(L"]").get());
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
vfs::TFile<WriteType>::TFile(vfs::Path const& filename)
|
||||
: tBaseClass(filename), m_isOpen_read(false)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
vfs::TFile<WriteType>::~TFile()
|
||||
{
|
||||
m_file.clear();
|
||||
if(m_isOpen_read)
|
||||
{
|
||||
this->close();
|
||||
}
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
void vfs::TFile<WriteType>::close()
|
||||
{
|
||||
m_file.clear();
|
||||
if( m_file.is_open() )
|
||||
{
|
||||
m_file.close();
|
||||
}
|
||||
m_isOpen_read = false;
|
||||
IS_FILE_VALID();
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
vfs::FileAttributes vfs::TFile<WriteType>::getAttributes()
|
||||
{
|
||||
vfs::Path fullpath;
|
||||
THROWIFFALSE(this->_getRealPath(fullpath), ERROR_FILE(L""));
|
||||
|
||||
vfs::UInt32 osFileAttributes = 0;
|
||||
os::FileAttributes fa;
|
||||
THROWIFFALSE( fa.getFileAttributes(fullpath, osFileAttributes), ERROR_FILE(L"Could not read file Attributes") );
|
||||
|
||||
vfs::UInt32 _attribs = vfs::FileAttributes::ATTRIB_INVALID;
|
||||
copyAttributes(osFileAttributes, _attribs);
|
||||
|
||||
if(!this->implementsWritable())
|
||||
{
|
||||
_attribs &= ~vfs::FileAttributes::ATTRIB_NORMAL;
|
||||
_attribs |= vfs::FileAttributes::ATTRIB_READONLY;
|
||||
}
|
||||
|
||||
return vfs::FileAttributes(_attribs, vfs::FileAttributes::LT_NONE);
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
bool vfs::TFile<WriteType>::isOpenRead()
|
||||
{
|
||||
return m_isOpen_read;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
bool vfs::TFile<WriteType>::_internalOpenRead(vfs::Path const& path)
|
||||
{
|
||||
if( m_isOpen_read )
|
||||
return true;
|
||||
if( !m_file.good() )
|
||||
return false;
|
||||
|
||||
std::ios::openmode Mode;
|
||||
Mode = std::ios::in|std::ios::binary;
|
||||
// try to open
|
||||
_openFile(m_file, path, Mode);
|
||||
m_isOpen_read = m_file.is_open() && m_file.good();
|
||||
return m_isOpen_read;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
bool vfs::TFile<WriteType>::openRead()
|
||||
{
|
||||
return _internalOpenRead(this->m_filename);
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
vfs::size_t vfs::TFile<WriteType>::read(vfs::Byte* pData, vfs::size_t bytesToRead)
|
||||
{
|
||||
if(!m_file.eof())
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
|
||||
|
||||
m_file.read(static_cast<char*>(pData), bytesToRead);
|
||||
std::streamsize bytesRead = m_file.gcount();
|
||||
|
||||
// don't treat EOF as error
|
||||
THROWIFFALSE( m_file.good() || m_file.eof(), ERROR_FILE(L"read error") );
|
||||
return (vfs::size_t)bytesRead;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
vfs::size_t vfs::TFile<WriteType>::getReadPosition()
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
|
||||
return (vfs::size_t)m_file.tellg();
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
void vfs::TFile<WriteType>::setReadPosition(vfs::size_t positionInBytes)
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
|
||||
|
||||
m_file.seekg( (std::streamoff)positionInBytes );
|
||||
|
||||
IS_FILE_VALID();
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
void vfs::TFile<WriteType>::setReadPosition(vfs::offset_t offsetInBytes, IBaseFile::ESeekDir seekDir)
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
|
||||
|
||||
std::ios::seekdir ioSeekDir;
|
||||
TRYCATCH_RETHROW( ioSeekDir = _seekDir(seekDir), ERROR_FILE(L"seek error"));
|
||||
m_file.seekg( offsetInBytes, ioSeekDir );
|
||||
|
||||
IS_FILE_VALID();
|
||||
}
|
||||
|
||||
/********************************************************************************/
|
||||
/********************************************************************************/
|
||||
|
||||
|
||||
vfs::CFile::CFile(vfs::Path const& filename)
|
||||
: tBaseClass(filename), m_isOpen_write(false)
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CFile::~CFile()
|
||||
{
|
||||
m_file.clear();
|
||||
if(m_isOpen_read || m_isOpen_write)
|
||||
{
|
||||
this->close();
|
||||
}
|
||||
}
|
||||
|
||||
void vfs::CFile::close()
|
||||
{
|
||||
tBaseClass::close();
|
||||
m_isOpen_write = false;
|
||||
}
|
||||
|
||||
bool vfs::CFile::deleteFile()
|
||||
{
|
||||
this->close();
|
||||
return os::deleteRealFile(m_filename);
|
||||
}
|
||||
|
||||
bool vfs::CFile::isOpenWrite()
|
||||
{
|
||||
return m_isOpen_write;
|
||||
}
|
||||
|
||||
bool vfs::CFile::_internalOpenWrite(vfs::Path const& path, bool createWhenNotExist, bool truncate)
|
||||
{
|
||||
if( m_isOpen_write )
|
||||
return true;
|
||||
if( !m_file.good() )
|
||||
return false;
|
||||
|
||||
std::ios::openmode Mode;
|
||||
Mode = std::ios::in|std::ios::out|std::ios::binary;
|
||||
if(truncate)
|
||||
{
|
||||
Mode |= std::ios::trunc;
|
||||
}
|
||||
_openFile(m_file, path, Mode);
|
||||
if( !(m_isOpen_write = m_file.is_open() && m_file.good()) )
|
||||
{
|
||||
m_file.clear();
|
||||
if(createWhenNotExist)
|
||||
{
|
||||
// create file
|
||||
Mode = std::ios::out|std::ios::binary;
|
||||
if(truncate)
|
||||
{
|
||||
Mode |= std::ios::trunc;
|
||||
}
|
||||
_openFile(m_file, path, Mode);
|
||||
if( !(m_isOpen_write = m_file.is_open() && m_file.good()) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_file.close();
|
||||
Mode |= std::ios::in;
|
||||
_openFile(m_file, path, Mode);
|
||||
if( !(m_isOpen_write = m_file.is_open() && m_file.good()) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return m_isOpen_write;
|
||||
}
|
||||
|
||||
bool vfs::CFile::openWrite(bool createWhenNotExist, bool truncate)
|
||||
{
|
||||
return _internalOpenWrite(m_filename, createWhenNotExist, truncate);
|
||||
}
|
||||
|
||||
vfs::size_t vfs::CFile::write(const vfs::Byte* data, vfs::size_t bytesToWrite)
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_write, ERROR_FILE(L"file not opened") );
|
||||
|
||||
std::streampos start = m_file.tellp();
|
||||
THROWIFFALSE( m_file.write(data, bytesToWrite), ERROR_FILE(L"write error") );
|
||||
std::streampos bytesWritten = m_file.tellp() - start;
|
||||
|
||||
IS_FILE_VALID();
|
||||
|
||||
return (vfs::size_t)bytesWritten;
|
||||
}
|
||||
|
||||
vfs::size_t vfs::CFile::getWritePosition()
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
return (vfs::size_t)m_file.tellp();
|
||||
}
|
||||
|
||||
void vfs::CFile::setWritePosition(vfs::size_t positionInBytes)
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_write, ERROR_FILE(L"file not opened") );
|
||||
|
||||
m_file.seekp( (std::streamoff)positionInBytes );
|
||||
|
||||
IS_FILE_VALID();
|
||||
}
|
||||
|
||||
void vfs::CFile::setWritePosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir)
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_write, ERROR_FILE(L"file not opened") );
|
||||
|
||||
std::ios::seekdir ioSeekDir;
|
||||
TRYCATCH_RETHROW( ioSeekDir = _seekDir(seekDir), ERROR_FILE(L"seek error") );
|
||||
m_file.seekp(offsetInBytes,ioSeekDir);
|
||||
|
||||
IS_FILE_VALID();
|
||||
}
|
||||
|
||||
//vfs::size_t vfs::CFile::getSize()
|
||||
template<typename T>
|
||||
vfs::size_t vfs::TFile<T>::getSize()
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
|
||||
// if file was alredy opened, keep it open, otherwise close it
|
||||
bool closeAtExit = !m_isOpen_read;
|
||||
|
||||
THROWIFFALSE( m_isOpen_read || this->openRead(), ERROR_FILE(L"could not open file") )
|
||||
|
||||
// save the current position
|
||||
std::streampos current_position = m_file.tellg();
|
||||
|
||||
// move to end of the file
|
||||
m_file.seekg(0,std::ios::end);
|
||||
std::streampos file_size = m_file.tellg();
|
||||
|
||||
// move to old position
|
||||
m_file.seekg(current_position,std::ios::beg);
|
||||
THROWIFFALSE(current_position == m_file.tellg(), ERROR_FILE(L"could not restore seek position"));
|
||||
|
||||
if(closeAtExit)
|
||||
{
|
||||
this->close();
|
||||
}
|
||||
IS_FILE_VALID();
|
||||
return (vfs::size_t)file_size;
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
/******************************************************************/
|
||||
|
||||
template class vfs::TFile<vfs::IWriteType>;
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
#ifndef _VFS_FILE_H_
|
||||
#define _VFS_FILE_H_
|
||||
|
||||
#include "../vfs_types.h"
|
||||
#include "../Interface/vfs_file_interface.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
typedef std::basic_fstream<wchar_t> wfstream;
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
/******************************************************************/
|
||||
/******************************************************************/
|
||||
|
||||
template<typename WriteType=vfs::IWriteType>
|
||||
class VFS_API TFile : public vfs::TFileTemplate<vfs::IReadable,WriteType>
|
||||
{
|
||||
typedef vfs::TFileTemplate<vfs::IReadable,WriteType> tBaseClass;
|
||||
public :
|
||||
TFile(vfs::Path const& filename);
|
||||
virtual ~TFile();
|
||||
|
||||
virtual vfs::FileAttributes getAttributes();
|
||||
|
||||
virtual void close();
|
||||
virtual vfs::size_t getSize();
|
||||
|
||||
virtual bool isOpenRead();
|
||||
virtual bool openRead();
|
||||
virtual vfs::size_t read(vfs::Byte* data, vfs::size_t bytesToRead);
|
||||
|
||||
virtual vfs::size_t getReadPosition();
|
||||
virtual void setReadPosition(vfs::size_t positionInBytes);
|
||||
virtual void setReadPosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir);
|
||||
|
||||
protected:
|
||||
bool _internalOpenRead(vfs::Path const& path);
|
||||
protected:
|
||||
bool m_isOpen_read;
|
||||
std::fstream m_file;
|
||||
};
|
||||
|
||||
/******************************************************************/
|
||||
/******************************************************************/
|
||||
|
||||
// implements the IWritable interface for TFile
|
||||
class VFS_API CFile : public vfs::TFile<vfs::IWritable>
|
||||
{
|
||||
typedef vfs::TFile<vfs::IWritable> tBaseClass;
|
||||
public :
|
||||
CFile(vfs::Path const& filename);
|
||||
virtual ~CFile();
|
||||
|
||||
virtual void close();
|
||||
|
||||
virtual bool isOpenWrite();
|
||||
virtual bool openWrite(bool createWhenNotExist = false, bool truncate = false);
|
||||
virtual vfs::size_t write(const vfs::Byte* data, vfs::size_t bytesToWrite);
|
||||
|
||||
virtual vfs::size_t getWritePosition();
|
||||
virtual void setWritePosition(vfs::size_t positionInBytes);
|
||||
virtual void setWritePosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir);
|
||||
|
||||
virtual bool deleteFile();
|
||||
protected:
|
||||
bool _internalOpenWrite(vfs::Path const& path, bool createWhenNotExist = false, bool truncate = false);
|
||||
protected:
|
||||
bool m_isOpen_write;
|
||||
};
|
||||
|
||||
/******************************************************************/
|
||||
/******************************************************************/
|
||||
|
||||
typedef vfs::TFile<vfs::IWriteType> CReadOnlyFile; // needs explicit template instantiation
|
||||
|
||||
} // end namespace
|
||||
|
||||
#endif // _VFS_FILE_H_
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
#include "vfs_lib_file.h"
|
||||
#include "../vfs.h"
|
||||
|
||||
|
||||
#define ERROR_FILE(msg) BuildString().add(L"[").add(this->getPath()).add(L"] - ").add(msg).get()
|
||||
|
||||
ObjBlockAllocator<vfs::CLibFile>* vfs::CLibFile::_lfile_pool = NULL;
|
||||
|
||||
vfs::CLibFile* vfs::CLibFile::create(vfs::Path const& filename,
|
||||
tLocation *location,
|
||||
ILibrary *library,
|
||||
ObjBlockAllocator<vfs::CLibFile>* allocator)
|
||||
{
|
||||
#if 0
|
||||
vfs::CLibFile* pFile = new vfs::CLibFile();
|
||||
#else
|
||||
vfs::CLibFile* pFile;
|
||||
if(allocator)
|
||||
{
|
||||
pFile = allocator->New();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!_lfile_pool)
|
||||
{
|
||||
_lfile_pool = new ObjBlockAllocator<vfs::CLibFile>();
|
||||
CFileAllocator::registerAllocator(_lfile_pool);
|
||||
}
|
||||
pFile = _lfile_pool->New();
|
||||
}
|
||||
#endif
|
||||
pFile->m_filename = filename;
|
||||
pFile->m_location = location;
|
||||
pFile->m_library = library;
|
||||
return pFile;
|
||||
}
|
||||
|
||||
vfs::CLibFile::CLibFile()
|
||||
: tBaseClass(L""),
|
||||
m_isOpen_read(false),
|
||||
m_library(NULL),
|
||||
m_location(NULL)
|
||||
{
|
||||
};
|
||||
|
||||
vfs::CLibFile::~CLibFile()
|
||||
{
|
||||
}
|
||||
|
||||
void vfs::CLibFile::close()
|
||||
{
|
||||
if(m_isOpen_read)
|
||||
{
|
||||
m_library->close(this);
|
||||
m_isOpen_read = false;
|
||||
}
|
||||
}
|
||||
|
||||
vfs::FileAttributes vfs::CLibFile::getAttributes()
|
||||
{
|
||||
return vfs::FileAttributes(vfs::FileAttributes::ATTRIB_NORMAL | vfs::FileAttributes::ATTRIB_READONLY,
|
||||
vfs::FileAttributes::LT_LIBRARY);
|
||||
}
|
||||
|
||||
vfs::Path vfs::CLibFile::getPath()
|
||||
{
|
||||
if(m_location)
|
||||
{
|
||||
return m_location->getPath() + m_filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_filename;
|
||||
}
|
||||
}
|
||||
bool vfs::CLibFile::isOpenRead()
|
||||
{
|
||||
return m_isOpen_read;
|
||||
}
|
||||
|
||||
bool vfs::CLibFile::openRead()
|
||||
{
|
||||
if(!m_isOpen_read)
|
||||
{
|
||||
TRYCATCH_RETHROW(m_isOpen_read = m_library->openRead(this), ERROR_FILE(L"read open error"));
|
||||
}
|
||||
return m_isOpen_read;
|
||||
}
|
||||
|
||||
vfs::size_t vfs::CLibFile::read(vfs::Byte* data, vfs::size_t bytesToRead)
|
||||
{
|
||||
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
|
||||
try
|
||||
{
|
||||
return m_library->read(this, data, bytesToRead);
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(ERROR_FILE(L"read error"), &ex);
|
||||
}
|
||||
}
|
||||
|
||||
vfs::size_t vfs::CLibFile::getReadPosition()
|
||||
{
|
||||
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
|
||||
try
|
||||
{
|
||||
return m_library->getReadPosition(this);
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(ERROR_FILE(L"library error"), &ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void vfs::CLibFile::setReadPosition(vfs::size_t uiPositionInBytes)
|
||||
{
|
||||
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
|
||||
TRYCATCH_RETHROW(m_library->setReadPosition(this,uiPositionInBytes), ERROR_FILE(L"library error") );
|
||||
}
|
||||
|
||||
void vfs::CLibFile::setReadPosition(vfs::offset_t offsetInBytes, IBaseFile::ESeekDir seekDir)
|
||||
{
|
||||
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
|
||||
TRYCATCH_RETHROW(m_library->setReadPosition(this, offsetInBytes, seekDir), ERROR_FILE(L"library error"));
|
||||
}
|
||||
|
||||
vfs::size_t vfs::CLibFile::getSize()
|
||||
{
|
||||
THROWIFFALSE( m_isOpen_read || this->openRead(), ERROR_FILE(L"could not open file") );
|
||||
try
|
||||
{
|
||||
return m_library->getSize(this);
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(ERROR_FILE(L"library error"), &ex);
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
#ifndef _VFS_LIB_FILE_H_
|
||||
#define _VFS_LIB_FILE_H_
|
||||
|
||||
#include "../Interface/vfs_file_interface.h"
|
||||
#include "../Interface/vfs_location_interface.h"
|
||||
#include "../Interface/vfs_location_aware_file_interface.h"
|
||||
#include "../Interface/vfs_library_interface.h"
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
|
||||
class ILibrary;
|
||||
|
||||
class CLibFile : public vfs::TFileTemplate<vfs::IReadable,vfs::IWriteType>
|
||||
{
|
||||
typedef vfs::TFileTemplate<vfs::IReadable,vfs::IWriteType> tBaseClass;
|
||||
typedef vfs::TLocationTemplate<vfs::IReadable,vfs::IWriteType> tLocation;
|
||||
public:
|
||||
CLibFile();
|
||||
static CLibFile* create(vfs::Path const& filename,
|
||||
tLocation *location,
|
||||
vfs::ILibrary *library,
|
||||
ObjBlockAllocator<CLibFile>* allocator = NULL);
|
||||
|
||||
// don't delete objects that YOU have not created with 'new'
|
||||
// dtor has to remain public to be usable at all
|
||||
virtual ~CLibFile();
|
||||
|
||||
virtual vfs::FileAttributes getAttributes();
|
||||
|
||||
virtual void close();
|
||||
|
||||
virtual vfs::Path getPath();
|
||||
|
||||
virtual bool isOpenRead();
|
||||
virtual bool openRead();
|
||||
virtual vfs::size_t read(vfs::Byte* pData, vfs::size_t bytesToRead);
|
||||
|
||||
virtual vfs::size_t getReadPosition();
|
||||
virtual void setReadPosition(vfs::size_t positionInBytes);
|
||||
virtual void setReadPosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir);
|
||||
|
||||
virtual vfs::size_t getSize();
|
||||
protected:
|
||||
bool m_isOpen_read;
|
||||
ILibrary* m_library;
|
||||
tLocation* m_location;
|
||||
private:
|
||||
static ObjBlockAllocator<CLibFile>* _lfile_pool;
|
||||
};
|
||||
|
||||
} // end namespace
|
||||
|
||||
#endif // _VFS_LIB_FILE_H_
|
||||
|
||||
@@ -1,238 +0,0 @@
|
||||
#include "vfs_memory_file.h"
|
||||
#include "../vfs_file_raii.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#define ERROR_FILE(msg) BuildString().add(L"[").add(this->getPath()).add(L"] - ").add(msg).get()
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define IS_FILE_VALID() THROWIFFALSE( m_buffer.good(), ERROR_FILE(L"invalid file object") );
|
||||
#else
|
||||
#define IS_FILE_VALID() THROWIFFALSE( m_buffer.good(), ERROR_FILE(L"invalid file object") );
|
||||
#endif
|
||||
|
||||
static inline std::ios::seekdir _seekDir(vfs::IBaseFile::ESeekDir seekDir)
|
||||
{
|
||||
if(seekDir == vfs::IBaseFile::SD_BEGIN)
|
||||
{
|
||||
return std::ios::beg;
|
||||
}
|
||||
else if(seekDir == vfs::IBaseFile::SD_CURRENT)
|
||||
{
|
||||
return std::ios::cur;
|
||||
}
|
||||
else if(seekDir == vfs::IBaseFile::SD_END)
|
||||
{
|
||||
return std::ios::end;
|
||||
}
|
||||
THROWEXCEPTION(BuildString().add(L"Unknown seek direction [").add(seekDir).add(L"]").get());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
|
||||
vfs::CMemoryFile::CMemoryFile()
|
||||
: tBaseClass(vfs::Path()), m_isOpen_read(false), m_isOpen_write(false)
|
||||
{
|
||||
m_buffer.str("");
|
||||
}
|
||||
|
||||
vfs::CMemoryFile::CMemoryFile(vfs::Path const& fileName)
|
||||
: tBaseClass(fileName), m_isOpen_read(false), m_isOpen_write(false)
|
||||
{
|
||||
m_buffer.str("");
|
||||
}
|
||||
|
||||
vfs::CMemoryFile::~CMemoryFile()
|
||||
{
|
||||
m_buffer.str("");
|
||||
m_buffer.clear();
|
||||
}
|
||||
|
||||
vfs::FileAttributes vfs::CMemoryFile::getAttributes()
|
||||
{
|
||||
return vfs::FileAttributes(vfs::FileAttributes::ATTRIB_NORMAL, vfs::FileAttributes::LT_NONE);
|
||||
}
|
||||
|
||||
void vfs::CMemoryFile::close()
|
||||
{
|
||||
m_buffer.clear();
|
||||
m_isOpen_read = false;
|
||||
m_isOpen_write = false;
|
||||
IS_FILE_VALID();
|
||||
}
|
||||
vfs::size_t vfs::CMemoryFile::getSize()
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
|
||||
std::streampos size = 0;
|
||||
if(!m_buffer.str().empty())
|
||||
{
|
||||
std::streampos current_position = m_buffer.tellg();
|
||||
m_buffer.seekg(0,std::ios::end);
|
||||
size = m_buffer.tellg();
|
||||
m_buffer.seekg(current_position,std::ios::beg);
|
||||
}
|
||||
|
||||
IS_FILE_VALID();
|
||||
return (vfs::size_t)size;
|
||||
}
|
||||
|
||||
bool vfs::CMemoryFile::isOpenRead()
|
||||
{
|
||||
return m_isOpen_read;
|
||||
}
|
||||
|
||||
bool vfs::CMemoryFile::openRead()
|
||||
{
|
||||
if(!m_buffer.good())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return m_isOpen_read = true;
|
||||
}
|
||||
vfs::size_t vfs::CMemoryFile::read(vfs::Byte* data, vfs::size_t bytesToRead)
|
||||
{
|
||||
if(!m_buffer.eof())
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE(m_isOpen_read || this->openRead(), ERROR_FILE(L"open error"));
|
||||
|
||||
m_buffer.read(static_cast<Byte*>(data), bytesToRead);
|
||||
std::streamsize bytesRead = m_buffer.gcount();
|
||||
|
||||
THROWIFFALSE( m_buffer.good() || m_buffer.eof(), ERROR_FILE(L"read error") );
|
||||
return (vfs::size_t)bytesRead;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
vfs::size_t vfs::CMemoryFile::getReadPosition()
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE(m_isOpen_read || this->openRead(), ERROR_FILE(L"open error"));
|
||||
|
||||
return (vfs::size_t)m_buffer.tellg();
|
||||
}
|
||||
|
||||
void vfs::CMemoryFile::setReadPosition(vfs::size_t positionInBytes)
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_read || this->openRead(), ERROR_FILE(L"open error") );
|
||||
|
||||
m_buffer.seekg((std::streamoff)positionInBytes);
|
||||
|
||||
IS_FILE_VALID();
|
||||
}
|
||||
void vfs::CMemoryFile::setReadPosition(vfs::offset_t offsetInBytes, IBaseFile::ESeekDir seekDir)
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_read || this->openRead(), ERROR_FILE(L"open error") );
|
||||
|
||||
std::ios::seekdir ioSeekDir;
|
||||
TRYCATCH_RETHROW(ioSeekDir = _seekDir(seekDir), ERROR_FILE(L"seek error"));
|
||||
m_buffer.seekg(offsetInBytes, ioSeekDir);
|
||||
|
||||
IS_FILE_VALID();
|
||||
}
|
||||
|
||||
bool vfs::CMemoryFile::isOpenWrite()
|
||||
{
|
||||
return m_isOpen_write;
|
||||
}
|
||||
|
||||
bool vfs::CMemoryFile::openWrite(bool bCreateWhenNotExist, bool bTruncate)
|
||||
{
|
||||
if( !m_buffer.good() )
|
||||
return false;
|
||||
if( m_isOpen_write )
|
||||
return true;
|
||||
|
||||
if(bTruncate)
|
||||
{
|
||||
m_buffer.str("");
|
||||
m_buffer.clear();
|
||||
}
|
||||
m_isOpen_write = m_buffer.good();
|
||||
return m_isOpen_write;
|
||||
}
|
||||
|
||||
vfs::size_t vfs::CMemoryFile::write(const vfs::Byte* data, vfs::size_t bytesToWrite)
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_write || this->openWrite(), ERROR_FILE(L"open error") );
|
||||
|
||||
std::streampos start = 0;
|
||||
if(!m_buffer.str().empty())
|
||||
{
|
||||
start = m_buffer.tellp();
|
||||
}
|
||||
THROWIFFALSE( m_buffer.write(data, bytesToWrite), ERROR_FILE(L"write error") );
|
||||
std::streampos bytesWritten = m_buffer.tellp() - start;
|
||||
|
||||
IS_FILE_VALID();
|
||||
|
||||
return (vfs::size_t)bytesWritten;
|
||||
}
|
||||
|
||||
vfs::size_t vfs::CMemoryFile::getWritePosition()
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_write || this->openWrite(), ERROR_FILE(L"open error") );
|
||||
|
||||
return (vfs::size_t)m_buffer.tellp();
|
||||
}
|
||||
|
||||
void vfs::CMemoryFile::setWritePosition(vfs::size_t positionInBytes)
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_write || this->openWrite(), ERROR_FILE(L"open error") );
|
||||
|
||||
m_buffer.seekp((std::streamoff)positionInBytes);
|
||||
|
||||
IS_FILE_VALID();
|
||||
}
|
||||
|
||||
void vfs::CMemoryFile::setWritePosition(vfs::offset_t offsetInBytes, IBaseFile::ESeekDir seekDir)
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_write || this->openWrite(), ERROR_FILE(L"open error") );
|
||||
|
||||
std::ios::seekdir ioSeekDir;
|
||||
TRYCATCH_RETHROW( ioSeekDir = _seekDir(seekDir), ERROR_FILE(L"seek error") );
|
||||
m_buffer.seekp(offsetInBytes, ioSeekDir);
|
||||
|
||||
IS_FILE_VALID();
|
||||
}
|
||||
|
||||
void vfs::CMemoryFile::copyToBuffer(vfs::tReadableFile& rFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool needToClose = !rFile.isOpenRead();
|
||||
vfs::COpenReadFile readfile(&rFile);
|
||||
if(!needToClose)
|
||||
{
|
||||
readfile.release();
|
||||
}
|
||||
|
||||
typedef std::vector<vfs::Byte> tByteVector;
|
||||
|
||||
vfs::size_t size = rFile.getSize();
|
||||
tByteVector vBuffer(size);
|
||||
|
||||
rFile.read(&vBuffer[0], size);
|
||||
this->write(&vBuffer[0], size);
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(ERROR_FILE(L""), &ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool vfs::CMemoryFile::deleteFile()
|
||||
{
|
||||
m_buffer.clear();
|
||||
m_buffer.str("");
|
||||
return m_buffer.good();
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
#ifndef _VFS_MEMORY_FILE_H_
|
||||
#define _VFS_MEMORY_FILE_H_
|
||||
|
||||
#include "../Interface/vfs_file_interface.h"
|
||||
#include <sstream>
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class VFS_API CMemoryFile : public vfs::TFileTemplate<vfs::IReadable,vfs::IWritable>
|
||||
{
|
||||
typedef vfs::TFileTemplate<vfs::IReadable,vfs::IWritable> tBaseClass;
|
||||
public :
|
||||
CMemoryFile();
|
||||
CMemoryFile(vfs::Path const& filename);
|
||||
virtual ~CMemoryFile();
|
||||
|
||||
virtual vfs::FileAttributes getAttributes();
|
||||
|
||||
virtual void close();
|
||||
virtual vfs::size_t getSize();
|
||||
|
||||
virtual bool isOpenRead();
|
||||
virtual bool openRead();
|
||||
virtual vfs::size_t read(vfs::Byte* data, vfs::size_t bytesToRead);
|
||||
|
||||
virtual vfs::size_t getReadPosition();
|
||||
virtual void setReadPosition(vfs::size_t positionInBytes);
|
||||
virtual void setReadPosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir);
|
||||
|
||||
virtual bool isOpenWrite();
|
||||
virtual bool openWrite(bool bCreateWhenNotExist = false, bool bTruncate = false);
|
||||
virtual vfs::size_t write(const vfs::Byte* data, vfs::size_t bytesToWrite);
|
||||
|
||||
virtual vfs::size_t getWritePosition();
|
||||
virtual void setWritePosition(vfs::size_t positionInBytes);
|
||||
virtual void setWritePosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir);
|
||||
|
||||
virtual bool deleteFile();
|
||||
|
||||
// convenience method
|
||||
void copyToBuffer(vfs::tReadableFile& rFile);
|
||||
protected:
|
||||
std::stringstream m_buffer;
|
||||
bool m_isOpen_read, m_isOpen_write;
|
||||
};
|
||||
|
||||
} // end namespace
|
||||
|
||||
#endif // _VFS_MEMORY_FILE_H_
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
#ifndef _VFS_DIRECTORY_INTERFACE_H_
|
||||
#define _VFS_DIRECTORY_INTERFACE_H_
|
||||
|
||||
#include "vfs_location_interface.h"
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
template<class WriteType>
|
||||
class TDirectory : public vfs::TLocationTemplate<vfs::IReadable, WriteType>
|
||||
{
|
||||
public:
|
||||
typedef typename vfs::TLocationTemplate<vfs::IReadable, WriteType> tBaseClass;
|
||||
typedef typename tBaseClass::tFileType tFileType;
|
||||
typedef typename tBaseClass::tWriteType tWriteType;
|
||||
|
||||
TDirectory(vfs::Path const& mountPoint, vfs::Path const& realPath)
|
||||
: tBaseClass(mountPoint), m_realPath(realPath)
|
||||
{};
|
||||
virtual ~TDirectory()
|
||||
{};
|
||||
|
||||
vfs::Path const& getRealPath()
|
||||
{
|
||||
return m_realPath;
|
||||
}
|
||||
|
||||
virtual tFileType* addFile(vfs::Path const& sFilename, bool bDeleteOldFile=false) = 0;
|
||||
virtual bool addFile(typename tBaseClass::tFileType* pFile, bool bDeleteOldFile=false) = 0;
|
||||
|
||||
virtual bool createSubDirectory(vfs::Path const& sSubDirPath) = 0;
|
||||
virtual bool deleteDirectory(vfs::Path const& sDirPath) = 0;
|
||||
virtual bool deleteFileFromDirectory(vfs::Path const& sFileName) = 0;
|
||||
protected:
|
||||
const vfs::Path m_realPath;
|
||||
private:
|
||||
void operator=(TDirectory<WriteType> const& t);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // _VFS_DIRECTORY_INTERFACE_H_
|
||||
@@ -1,234 +0,0 @@
|
||||
#ifndef _VFS_FILE_INTERFACE_H_
|
||||
#define _VFS_FILE_INTERFACE_H_
|
||||
|
||||
#include "../vfs_types.h"
|
||||
#include "../vfs_path.h"
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
/**
|
||||
* FileAttributes
|
||||
*/
|
||||
class FileAttributes
|
||||
{
|
||||
public:
|
||||
enum Attributes {
|
||||
ATTRIB_INVALID = 0,
|
||||
ATTRIB_ARCHIVE = 1,
|
||||
ATTRIB_DIRECTORY = 2,
|
||||
ATTRIB_HIDDEN = 4,
|
||||
ATTRIB_NORMAL = 8,
|
||||
ATTRIB_READONLY = 16,
|
||||
ATTRIB_SYSTEM = 32,
|
||||
ATTRIB_TEMPORARY = 64,
|
||||
ATTRIB_COMPRESSED = 128,
|
||||
ATTRIB_OFFLINE = 256,
|
||||
};
|
||||
enum LocationType {
|
||||
LT_NONE = 0,
|
||||
LT_LIBRARY = 1,
|
||||
LT_DIRECTORY = 2,
|
||||
LT_READONLY_DIRECTORY = 4,
|
||||
};
|
||||
public:
|
||||
FileAttributes();
|
||||
FileAttributes(vfs::UInt32 attribs, LocationType location);
|
||||
|
||||
vfs::UInt32 getAttrib() const;
|
||||
vfs::UInt32 getLocation() const;
|
||||
|
||||
bool isAttribSet(vfs::UInt32 attribs) const;
|
||||
bool isAttribNotSet(vfs::UInt32 attribs) const;
|
||||
|
||||
bool isLocation(vfs::UInt32 location) const;
|
||||
private:
|
||||
void operator=(vfs::FileAttributes const& attr);
|
||||
|
||||
const vfs::UInt32 _attribs;
|
||||
const vfs::UInt32 _location;
|
||||
};
|
||||
|
||||
/**
|
||||
* IBaseFile
|
||||
*/
|
||||
class VFS_API IBaseFile
|
||||
{
|
||||
public:
|
||||
enum ESeekDir
|
||||
{
|
||||
SD_BEGIN,
|
||||
SD_CURRENT,
|
||||
SD_END,
|
||||
};
|
||||
public:
|
||||
IBaseFile(vfs::Path const& filename);
|
||||
virtual ~IBaseFile();
|
||||
|
||||
virtual vfs::FileAttributes getAttributes() = 0;
|
||||
|
||||
vfs::Path const& getName();
|
||||
virtual vfs::Path getPath();
|
||||
|
||||
virtual bool implementsWritable() = 0;
|
||||
virtual bool implementsReadable() = 0;
|
||||
|
||||
virtual void close() = 0;
|
||||
virtual vfs::size_t getSize() = 0;
|
||||
|
||||
virtual bool _getRealPath(vfs::Path& path);
|
||||
protected:
|
||||
vfs::Path m_filename;
|
||||
};
|
||||
|
||||
/**
|
||||
* IReadType , IReadable
|
||||
*/
|
||||
class IReadType{};
|
||||
class IReadable : public vfs::IReadType
|
||||
{
|
||||
public:
|
||||
virtual bool isOpenRead() = 0;
|
||||
virtual bool openRead() = 0;
|
||||
virtual vfs::size_t read(vfs::Byte* data, vfs::size_t bytesToRead) = 0;
|
||||
|
||||
virtual vfs::size_t getReadPosition() = 0;
|
||||
virtual void setReadPosition(vfs::size_t positionInBytes) = 0;
|
||||
virtual void setReadPosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir) = 0;
|
||||
};
|
||||
//class NonReadable : public IReadType{};
|
||||
|
||||
/**
|
||||
* IWriteType , IWritable
|
||||
*/
|
||||
class IWriteType{};
|
||||
class IWritable : public vfs::IWriteType
|
||||
{
|
||||
public:
|
||||
virtual bool isOpenWrite() = 0;
|
||||
virtual bool openWrite(bool createWhenNotExist = false, bool truncate = false) = 0;
|
||||
virtual vfs::size_t write(const vfs::Byte* data, vfs::size_t bytesToWrite) = 0;
|
||||
|
||||
virtual vfs::size_t getWritePosition() = 0;
|
||||
virtual void setWritePosition(vfs::size_t positionInBytes) = 0;
|
||||
virtual void setWritePosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir) = 0;
|
||||
|
||||
virtual bool deleteFile() = 0;
|
||||
};
|
||||
//class NonWritable: public IWriteType{};
|
||||
|
||||
/******************************************************************/
|
||||
/******************************************************************/
|
||||
|
||||
/**
|
||||
* IFileTemplate
|
||||
*/
|
||||
template<typename ReadType=vfs::IReadType, typename WriteType=vfs::IWriteType>
|
||||
class VFS_API TFileTemplate : public vfs::IBaseFile, public ReadType, public WriteType
|
||||
{
|
||||
public:
|
||||
typedef ReadType read_type;
|
||||
typedef WriteType write_type;
|
||||
|
||||
typedef vfs::TFileTemplate<read_type,vfs::IWritable> write_file_type;
|
||||
typedef vfs::TFileTemplate<vfs::IReadable,write_type> read_file_type;
|
||||
public:
|
||||
TFileTemplate(vfs::Path const& fileName)
|
||||
: vfs::IBaseFile(fileName), ReadType(), WriteType()
|
||||
{};
|
||||
virtual ~TFileTemplate()
|
||||
{};
|
||||
virtual bool implementsWritable()
|
||||
{
|
||||
return typeid(write_type) == typeid(vfs::IWritable);
|
||||
}
|
||||
virtual bool implementsReadable()
|
||||
{
|
||||
return typeid(read_type) == typeid(vfs::IReadable);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* TReadableFile
|
||||
*/
|
||||
template<class WriteType=vfs::IWriteType>
|
||||
class TReadableFile : public vfs::TFileTemplate<vfs::IReadable,WriteType>
|
||||
{
|
||||
typedef vfs::TFileTemplate<vfs::IReadable,WriteType> tBaseClass;
|
||||
public:
|
||||
typedef vfs::TReadableFile<WriteType> read_file_type;
|
||||
|
||||
/////////////////////////////////////////
|
||||
TReadableFile(vfs::Path const& sFilename)
|
||||
: tBaseClass(sFilename)
|
||||
{};
|
||||
virtual ~TReadableFile(){};
|
||||
|
||||
/////////////////////////////////////////
|
||||
read_file_type* operator=(vfs::IBaseFile const& t)
|
||||
{
|
||||
return read_file_type::cast(t);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////
|
||||
static read_file_type* cast(vfs::IBaseFile* bf)
|
||||
{
|
||||
if(bf && bf->implementsReadable())
|
||||
{
|
||||
return static_cast<read_file_type*>(bf);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
protected:
|
||||
TReadableFile();
|
||||
};
|
||||
|
||||
/**
|
||||
* TWritableFile
|
||||
*/
|
||||
template<class ReadType=vfs::IReadType>
|
||||
class TWritableFile : public vfs::TFileTemplate<ReadType,vfs::IWritable>
|
||||
{
|
||||
typedef vfs::TFileTemplate<ReadType,vfs::IWritable> tBaseClass;
|
||||
public:
|
||||
typedef vfs::TWritableFile<ReadType> write_file_type;
|
||||
|
||||
/////////////////////////////////////////
|
||||
TWritableFile(vfs::Path const& sFilename)
|
||||
: tBaseClass(sFilename)
|
||||
{};
|
||||
virtual ~TWritableFile(){};
|
||||
|
||||
/////////////////////////////////////////
|
||||
write_file_type& operator=(vfs::IBaseFile const& t)
|
||||
{
|
||||
return *write_file_type::cast(t);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////
|
||||
static write_file_type* cast(IBaseFile* bf)
|
||||
{
|
||||
if(bf && bf->implementsWritable())
|
||||
{
|
||||
return static_cast<write_file_type*>(bf);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
protected:
|
||||
TWritableFile();
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************/
|
||||
/******************************************************************/
|
||||
|
||||
/**
|
||||
* typedef's
|
||||
*/
|
||||
typedef vfs::TReadableFile<vfs::IWriteType> tReadableFile;
|
||||
typedef vfs::TWritableFile<vfs::IReadable> tWritableFile;
|
||||
|
||||
} // end namespace
|
||||
|
||||
#endif // _VFS_FILE_INTERFACE_H_
|
||||
@@ -1,93 +0,0 @@
|
||||
#include "vfs_file_interface.h"
|
||||
#include "vfs_library_interface.h"
|
||||
|
||||
/**********************************************************************
|
||||
* vfs::FileAttributes
|
||||
*/
|
||||
vfs::FileAttributes::FileAttributes()
|
||||
: _attribs(ATTRIB_NORMAL), _location(LT_NONE)
|
||||
{
|
||||
};
|
||||
|
||||
vfs::FileAttributes::FileAttributes(vfs::UInt32 attribs, LocationType location)
|
||||
: _attribs(attribs), _location(location)
|
||||
{
|
||||
};
|
||||
|
||||
vfs::UInt32 vfs::FileAttributes::getAttrib() const
|
||||
{
|
||||
return _attribs;
|
||||
};
|
||||
|
||||
vfs::UInt32 vfs::FileAttributes::getLocation() const
|
||||
{
|
||||
return _location;
|
||||
};
|
||||
|
||||
bool vfs::FileAttributes::isAttribSet(vfs::UInt32 attribs) const
|
||||
{
|
||||
return attribs == (attribs & _attribs);
|
||||
};
|
||||
|
||||
bool vfs::FileAttributes::isAttribNotSet(vfs::UInt32 attribs) const
|
||||
{
|
||||
return 0 == (attribs & _attribs);
|
||||
};
|
||||
|
||||
bool vfs::FileAttributes::isLocation(vfs::UInt32 location) const
|
||||
{
|
||||
return location == (location & _location);
|
||||
};
|
||||
|
||||
/**********************************************************************
|
||||
* vfs::IBaseFile
|
||||
*/
|
||||
|
||||
vfs::IBaseFile::IBaseFile(vfs::Path const& filename)
|
||||
: m_filename(filename)
|
||||
{};
|
||||
|
||||
vfs::IBaseFile::~IBaseFile()
|
||||
{};
|
||||
|
||||
vfs::Path const& vfs::IBaseFile::getName()
|
||||
{
|
||||
return m_filename;
|
||||
};
|
||||
|
||||
vfs::Path vfs::IBaseFile::getPath()
|
||||
{
|
||||
return this->getName();
|
||||
};
|
||||
|
||||
|
||||
bool vfs::IBaseFile::_getRealPath(vfs::Path& path)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* vfs::ILibrary
|
||||
*/
|
||||
|
||||
vfs::ILibrary::ILibrary(vfs::tReadableFile *libraryFile, vfs::Path const& mountPoint, bool ownFile)
|
||||
: tBaseClass(mountPoint), m_ownLibFile(ownFile), m_libraryFile(libraryFile)
|
||||
{
|
||||
}
|
||||
|
||||
vfs::ILibrary::~ILibrary()
|
||||
{
|
||||
if(m_libraryFile && m_ownLibFile)
|
||||
{
|
||||
m_libraryFile->close();
|
||||
delete m_libraryFile;
|
||||
m_libraryFile = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
vfs::Path const& vfs::ILibrary::getName()
|
||||
{
|
||||
return m_libraryFile->getName();
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
@@ -1,65 +0,0 @@
|
||||
#ifndef _VFS_ITERATOR_INTERFACE_H_
|
||||
#define _VFS_ITERATOR_INTERFACE_H_
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
template<typename T>
|
||||
class VFS_API TIterator
|
||||
{
|
||||
public:
|
||||
class IImplementation
|
||||
{
|
||||
friend class TIterator<T>;
|
||||
public:
|
||||
virtual ~IImplementation() {};
|
||||
virtual T* value() = 0;
|
||||
virtual void next() = 0;
|
||||
protected:
|
||||
virtual IImplementation* clone() = 0;
|
||||
};
|
||||
public:
|
||||
TIterator() : _obj(NULL), _iter_impl(NULL) {};
|
||||
TIterator(IImplementation* impl) : _obj(NULL), _iter_impl(impl)
|
||||
{
|
||||
if(_iter_impl)
|
||||
{
|
||||
_obj = _iter_impl->value();
|
||||
}
|
||||
}
|
||||
~TIterator()
|
||||
{
|
||||
if(_iter_impl) delete _iter_impl;
|
||||
};
|
||||
TIterator& operator=(TIterator const& t)
|
||||
{
|
||||
_obj = t._obj;
|
||||
_iter_impl = NULL;
|
||||
if(t._iter_impl)
|
||||
{
|
||||
_iter_impl = t._iter_impl->clone();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
//////////////////////////////
|
||||
T* value() { return _obj; };
|
||||
bool end() { return _obj == NULL; };
|
||||
void next()
|
||||
{
|
||||
if(_iter_impl)
|
||||
{
|
||||
_iter_impl->next();
|
||||
_obj = _iter_impl->value();
|
||||
if(!_obj)
|
||||
{
|
||||
delete _iter_impl;
|
||||
_iter_impl = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
T* _obj;
|
||||
IImplementation* _iter_impl;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // _VFS_ITERATOR_INTERFACE_H_
|
||||
@@ -1,36 +0,0 @@
|
||||
#ifndef _VFS_LIBRARY_INTERFACE_H_
|
||||
#define _VFS_LIBRARY_INTERFACE_H_
|
||||
|
||||
#include "vfs_location_interface.h"
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class VFS_API ILibrary : public vfs::TLocationTemplate<vfs::IReadable,vfs::IWriteType>
|
||||
{
|
||||
typedef vfs::TLocationTemplate<vfs::IReadable,vfs::IWriteType> tBaseClass;
|
||||
public:
|
||||
ILibrary(vfs::tReadableFile *libraryFile, vfs::Path const& mountPoint, bool ownFile = false);
|
||||
virtual ~ILibrary();
|
||||
|
||||
virtual bool init() = 0;
|
||||
virtual void closeLibrary() = 0;
|
||||
|
||||
virtual void close(tFileType *fileHandle) = 0;
|
||||
virtual bool openRead(tFileType *fileHandle) = 0;
|
||||
virtual vfs::size_t read(tFileType *fileHandle, vfs::Byte* data, vfs::size_t bytesToRead) = 0;
|
||||
|
||||
virtual vfs::size_t getReadPosition(tFileType *fileHandle) = 0;
|
||||
virtual void setReadPosition(tFileType *fileHandle, vfs::size_t positionInBytes) = 0;
|
||||
virtual void setReadPosition(tFileType *fileHandle, vfs::offset_t offsetInBytes, IBaseFile::ESeekDir seekDir) = 0;
|
||||
|
||||
virtual vfs::size_t getSize(tFileType *pFileHandle) = 0;
|
||||
|
||||
vfs::Path const& getName();
|
||||
protected:
|
||||
bool m_ownLibFile;
|
||||
vfs::tReadableFile* m_libraryFile;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // _VFS_LIBRARY_INTERFACE_H_
|
||||
@@ -1,43 +0,0 @@
|
||||
#ifndef _VFS_LOCATION_AWARE_FILE_INTERFACE_H_
|
||||
#define _VFS_LOCATION_AWARE_FILE_INTERFACE_H_
|
||||
|
||||
#include "vfs_file_interface.h"
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
|
||||
template<typename ReadType, typename WriteType>
|
||||
class IVFSLocation;
|
||||
|
||||
template<class WriteType> class IDirectory;
|
||||
|
||||
class ILibrary;
|
||||
|
||||
|
||||
/**
|
||||
* ILocationAware
|
||||
*/
|
||||
//template<typename ReadType, typename WriteType>
|
||||
//class ILocationAware
|
||||
//{
|
||||
//public:
|
||||
// typedef vfs::IVFSLocation<ReadType,WriteType> tLocationType;
|
||||
//public:
|
||||
// ILocationAware(vfs::IVFSLocation<ReadType,WriteType> *pLocation)
|
||||
// : _pLoc_(pLocation)
|
||||
// {};
|
||||
// virtual ~ILocationAware()
|
||||
// {};
|
||||
//protected:
|
||||
// tLocationType* _pLoc_;
|
||||
//};
|
||||
|
||||
/******************************************************************/
|
||||
/******************************************************************/
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // _VFS_LOCATION_AWARE_FILE_INTERFACE_H_
|
||||
|
||||
@@ -1,137 +0,0 @@
|
||||
#ifndef _VFS_LOCATION_INTERFACE_H_
|
||||
#define _VFS_LOCATION_INTERFACE_H_
|
||||
|
||||
#include "../vfs_types.h"
|
||||
#include "../vfs_debug.h"
|
||||
#include "vfs_file_interface.h"
|
||||
#include "vfs_iterator_interface.h"
|
||||
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <typeinfo>
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class VFS_API IBaseLocation
|
||||
{
|
||||
public:
|
||||
typedef TIterator<vfs::IBaseFile> Iterator;
|
||||
|
||||
virtual ~IBaseLocation()
|
||||
{};
|
||||
|
||||
virtual bool implementsWritable() = 0;
|
||||
virtual bool implementsReadable() = 0;
|
||||
|
||||
virtual vfs::Path const& getPath() = 0;
|
||||
virtual bool fileExists(vfs::Path const& sFileName) = 0;
|
||||
virtual vfs::IBaseFile* getFile(vfs::Path const& sFileName) = 0;
|
||||
|
||||
virtual Iterator begin() = 0;
|
||||
virtual void getSubDirList(std::list<vfs::Path>& rlSubDirs) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* TVFSLocation
|
||||
*/
|
||||
template<typename ReadType, typename WriteType>
|
||||
class VFS_API TLocationTemplate : public IBaseLocation
|
||||
{
|
||||
public:
|
||||
typedef vfs::TLocationTemplate<ReadType,WriteType> tLocationType;
|
||||
typedef vfs::TFileTemplate<ReadType,WriteType> tFileType;
|
||||
typedef ReadType tReadType;
|
||||
typedef WriteType tWriteType;
|
||||
typedef std::list<std::pair<tFileType*,vfs::Path> > tListFilesWithPath;
|
||||
public:
|
||||
TLocationTemplate(vfs::Path const& mountPoint)
|
||||
: m_mountPoint(mountPoint)
|
||||
{};
|
||||
virtual ~TLocationTemplate()
|
||||
{};
|
||||
|
||||
// has to be virtual , or the types of the caller (not the real object) will be tested
|
||||
virtual bool implementsWritable()
|
||||
{
|
||||
return typeid(tWriteType) == typeid(vfs::IWritable);
|
||||
}
|
||||
virtual bool implementsReadable()
|
||||
{
|
||||
return typeid(tReadType) == typeid(vfs::IReadable);
|
||||
}
|
||||
|
||||
vfs::Path const& getMountPoint()
|
||||
{
|
||||
return m_mountPoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* TLocationTemplate interface
|
||||
*/
|
||||
virtual vfs::Path const& getPath()
|
||||
{
|
||||
return m_mountPoint;
|
||||
}
|
||||
|
||||
virtual bool fileExists(vfs::Path const& sFileName) = 0;
|
||||
virtual vfs::IBaseFile* getFile(vfs::Path const& sFileName) = 0;
|
||||
virtual tFileType* getFileTyped(vfs::Path const& rFileName) = 0;
|
||||
protected:
|
||||
vfs::Path m_mountPoint;
|
||||
};
|
||||
|
||||
/**************************************************************************************/
|
||||
/**************************************************************************************/
|
||||
|
||||
template<typename WriteType=vfs::IWriteType>
|
||||
class TReadLocation : public TLocationTemplate<IReadable,WriteType>
|
||||
{
|
||||
public:
|
||||
typedef TReadLocation<WriteType> tLocationType;
|
||||
|
||||
static tLocationType* cast(vfs::IBaseLocation* bl)
|
||||
{
|
||||
if(bl && bl->implementsReadable())
|
||||
{
|
||||
return static_cast<tLocationType*>(bl);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
public:
|
||||
TReadLocation(vfs::Path const& sLocalPath)
|
||||
: vfs::TLocationTemplate<IReadable,WriteType>(sLocalPath)
|
||||
{};
|
||||
virtual ~TReadLocation(){};
|
||||
};
|
||||
|
||||
template<typename ReadType=vfs::IReadType>
|
||||
class TWriteLocation : public vfs::TLocationTemplate<ReadType,vfs::IWritable>
|
||||
{
|
||||
public:
|
||||
typedef TWriteLocation<ReadType> tLocationType;
|
||||
|
||||
static tLocationType* cast(vfs::IBaseLocation* bl)
|
||||
{
|
||||
if(bl && bl->implementsWritable())
|
||||
{
|
||||
return static_cast<tLocationType*>(bl);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
public:
|
||||
TWriteLocation(vfs::Path const& sLocalPath)
|
||||
: vfs::TLocationTemplate<ReadType,vfs::IWritable>(sLocalPath)
|
||||
{};
|
||||
virtual ~TWriteLocation(){};
|
||||
};
|
||||
|
||||
/**************************************************************************************/
|
||||
/**************************************************************************************/
|
||||
|
||||
typedef TReadLocation<vfs::IWriteType> tReadLocation;
|
||||
typedef TWriteLocation<vfs::IReadType> tWriteLocation;
|
||||
|
||||
} // end namespace
|
||||
|
||||
#endif // _VFS_LOCATION_INTERFACE_H_
|
||||
|
||||
@@ -1,231 +0,0 @@
|
||||
#include "vfs_7z_library.h"
|
||||
#include "vfs_lib_dir.h"
|
||||
#include "../File/vfs_lib_file.h"
|
||||
#include "../vfs_file_raii.h"
|
||||
|
||||
namespace sz
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
#include "7zCrc.h"
|
||||
#include "Archive/7z/7zAlloc.h"
|
||||
#include "Archive/7z/7zExtract.h"
|
||||
#include "Archive/7z/7zIn.h"
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
/*** my 7z extensions ***/
|
||||
/********************************************************************************************/
|
||||
|
||||
namespace szExt
|
||||
{
|
||||
typedef struct CSzVfsFile
|
||||
{
|
||||
vfs::tReadableFile* file;
|
||||
} CSzVfsFile;
|
||||
|
||||
typedef struct CVfsFileInStream
|
||||
{
|
||||
sz::ISeekInStream s;
|
||||
CSzVfsFile file;
|
||||
} CVfsFileInStream;
|
||||
|
||||
|
||||
static sz::SRes VfsFileInStream_Read(void *pp, void *buf, ::size_t *size)
|
||||
{
|
||||
CVfsFileInStream *p = (CVfsFileInStream *)pp;
|
||||
::size_t to_read = *size;
|
||||
sz::SRes res;
|
||||
try
|
||||
{
|
||||
*size = (::size_t)p->file.file->read((vfs::Byte*)buf,to_read);
|
||||
res = SZ_OK;
|
||||
}
|
||||
catch(CBasicException &ex)
|
||||
{
|
||||
logException(ex);
|
||||
res = SZ_ERROR_READ;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static sz::SRes VfsFileInStream_Seek(void *pp, sz::Int64 *pos, sz::ESzSeek origin)
|
||||
{
|
||||
CVfsFileInStream *p = (CVfsFileInStream *)pp;
|
||||
|
||||
vfs::IBaseFile::ESeekDir eSD;
|
||||
switch (origin)
|
||||
{
|
||||
case sz::SZ_SEEK_SET:
|
||||
eSD = vfs::IBaseFile::SD_BEGIN;
|
||||
break;
|
||||
case sz::SZ_SEEK_CUR:
|
||||
eSD = vfs::IBaseFile::SD_CURRENT;
|
||||
break;
|
||||
case sz::SZ_SEEK_END:
|
||||
eSD = vfs::IBaseFile::SD_END;
|
||||
break;
|
||||
default:
|
||||
return SZ_ERROR_PARAM;
|
||||
}
|
||||
vfs::offset_t _pos = (vfs::offset_t)(*pos);
|
||||
sz::SRes res;
|
||||
try
|
||||
{
|
||||
p->file.file->setReadPosition(_pos,eSD);
|
||||
*pos = p->file.file->getReadPosition();
|
||||
res = SZ_OK;
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
logException(ex);
|
||||
res = SZ_ERROR_READ;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void VfsFileInStream_CreateVTable(CVfsFileInStream *p)
|
||||
{
|
||||
p->s.Read = VfsFileInStream_Read;
|
||||
p->s.Seek = VfsFileInStream_Seek;
|
||||
}
|
||||
}; // end namespace szExt
|
||||
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
vfs::CUncompressed7zLibrary::CUncompressed7zLibrary(
|
||||
tReadableFile *libraryFile,
|
||||
vfs::Path const& mountPoint,
|
||||
bool ownFile,
|
||||
ObjBlockAllocator<vfs::CLibFile>* allocator)
|
||||
: vfs::CUncompressedLibraryBase(libraryFile, mountPoint, ownFile), _allocator(allocator)
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CUncompressed7zLibrary::~CUncompressed7zLibrary()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
#define k_Copy 0
|
||||
|
||||
sz::UInt64 GetSum(const sz::UInt64 *values, sz::UInt32 index)
|
||||
{
|
||||
sz::UInt64 sum = 0;
|
||||
sz::UInt32 i;
|
||||
for (i = 0; i < index; i++)
|
||||
{
|
||||
sum += values[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
bool vfs::CUncompressed7zLibrary::init()
|
||||
{
|
||||
if(!m_libraryFile)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
szExt::CVfsFileInStream archiveStream;
|
||||
sz::CLookToRead lookStream;
|
||||
sz::CSzArEx db;
|
||||
sz::SRes res;
|
||||
sz::ISzAlloc allocImp;
|
||||
sz::ISzAlloc allocTempImp;
|
||||
|
||||
vfs::COpenReadFile rfile(m_libraryFile);
|
||||
|
||||
archiveStream.file.file = m_libraryFile;
|
||||
|
||||
szExt::VfsFileInStream_CreateVTable(&archiveStream);
|
||||
sz::LookToRead_CreateVTable(&lookStream, False);
|
||||
|
||||
lookStream.realStream = &archiveStream.s;
|
||||
sz::LookToRead_Init(&lookStream);
|
||||
|
||||
allocImp.Alloc = sz::SzAlloc;
|
||||
allocImp.Free = sz::SzFree;
|
||||
|
||||
allocTempImp.Alloc = sz::SzAllocTemp;
|
||||
allocTempImp.Free = sz::SzFreeTemp;
|
||||
|
||||
sz::CrcGenerateTable();
|
||||
|
||||
sz::SzArEx_Init(&db);
|
||||
if( SZ_OK != (res = sz::SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp)) )
|
||||
{
|
||||
THROWEXCEPTION(BuildString().add(L"Could not open 7z archive [").add(m_libraryFile->getPath()).add(L"]").get());
|
||||
}
|
||||
|
||||
vfs::TDirectory<ILibrary::tWriteType>* pLD = NULL;
|
||||
vfs::Path oDir, oFile;
|
||||
vfs::Path oDirPath;
|
||||
|
||||
for(vfs::UInt32 i = 0; i < db.db.NumFiles; i++)
|
||||
{
|
||||
sz::CSzFileItem *f = db.db.Files + i;
|
||||
if (f->IsDir)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
vfs::Path sPath(f->Name);
|
||||
sPath.splitLast(oDir,oFile);
|
||||
oDirPath = m_mountPoint;
|
||||
if(!oDir.empty())
|
||||
{
|
||||
oDirPath += oDir;
|
||||
}
|
||||
|
||||
// determine offset and size
|
||||
sz::UInt32 folderIndex = db.FileIndexToFolderIndexMap[i];
|
||||
|
||||
sz::CSzFolder *folder = db.db.Folders + folderIndex;
|
||||
sz::UInt64 unpackSizeSpec = sz::SzFolder_GetUnpackSize(folder);
|
||||
size_t unpackSize = (size_t)unpackSizeSpec;
|
||||
sz::UInt64 startOffset = sz::SzArEx_GetFolderStreamPos(&db, folderIndex, 0);
|
||||
|
||||
//const sz::UInt64 *packSizes = db.db.PackSizes + db.FolderStartPackStreamIndex[folderIndex];
|
||||
|
||||
//CSzCoderInfo *coder = &folder->Coders[0];
|
||||
//if (coder->MethodID == k_Copy)
|
||||
//{
|
||||
// UInt32 si = 0;
|
||||
// UInt64 offset;
|
||||
// UInt64 inSize;
|
||||
// offset = GetSum(packSizes, si);
|
||||
// inSize = packSizes[si];
|
||||
//}
|
||||
|
||||
// get or create according directory object
|
||||
tDirCatalogue::iterator it = m_dirs.find(oDirPath);
|
||||
if(it != m_dirs.end())
|
||||
{
|
||||
pLD = it->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
pLD = new vfs::CLibDirectory(oDir,oDirPath);
|
||||
m_dirs.insert(std::make_pair(oDirPath,pLD));
|
||||
}
|
||||
// create file
|
||||
vfs::CLibFile *pFile = vfs::CLibFile::create(oFile,pLD,this,_allocator);
|
||||
// add file to directory
|
||||
THROWIFFALSE( pLD->addFile(pFile), L"" );
|
||||
|
||||
// link file data struct to file object
|
||||
m_fileData.insert(std::make_pair(pFile,SFileData(unpackSize, (vfs::size_t)startOffset)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
logException(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
#ifndef _VFS_7Z_LIBRARY_H_
|
||||
#define _VFS_7Z_LIBRARY_H_
|
||||
|
||||
#include "vfs_uncompressed_lib_base.h"
|
||||
#include "../File/vfs_lib_file.h"
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class CUncompressed7zLibrary : public vfs::CUncompressedLibraryBase
|
||||
{
|
||||
public:
|
||||
CUncompressed7zLibrary(tReadableFile *libraryFile,
|
||||
vfs::Path const& mountPoint,
|
||||
bool ownFile = false,
|
||||
ObjBlockAllocator<vfs::CLibFile>* allocator=NULL);
|
||||
virtual ~CUncompressed7zLibrary();
|
||||
|
||||
virtual bool init();
|
||||
private:
|
||||
ObjBlockAllocator<vfs::CLibFile>* _allocator;
|
||||
};
|
||||
} // end namespace
|
||||
|
||||
#endif // _VFS_7Z_LIBRARY_H_
|
||||
|
||||
@@ -1,401 +0,0 @@
|
||||
#include <cstring>
|
||||
|
||||
#include "../vfs_types.h"
|
||||
|
||||
#include "vfs_create_7z_library.h"
|
||||
#include "../vfs_file_raii.h"
|
||||
#include "../vfs_debug.h"
|
||||
|
||||
namespace sz
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
#include "7zCrc.h"
|
||||
#include "Archive/7z/7zIn.h"
|
||||
}
|
||||
};
|
||||
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
/******************************************************************************************/
|
||||
/******************************************************************************************/
|
||||
/******************************************************************************************/
|
||||
namespace szExt
|
||||
{
|
||||
inline ::size_t WRITEBYTE(std::ostream& out, sz::Byte const& value)
|
||||
{
|
||||
out.write((char*)&value,sizeof(sz::Byte));
|
||||
return 1;
|
||||
}
|
||||
template<typename T>
|
||||
inline ::size_t WRITEALL(std::ostream& out, T const& value)
|
||||
{
|
||||
out.write((char*)&value,sizeof(T));
|
||||
return sizeof(T);
|
||||
}
|
||||
template<typename T>
|
||||
inline ::size_t WRITEBUFFER(std::ostream& out, T* value, ::size_t num_elements)
|
||||
{
|
||||
out.write((char*)value, num_elements*sizeof(T));
|
||||
return num_elements*sizeof(T);
|
||||
}
|
||||
|
||||
/**
|
||||
* "compress" numbers by removing heading zero-bytes
|
||||
* - add additional byte that represents a bit-vector of bytes within a 64-bit/8-byte number
|
||||
* - if the number is smaller than 128, use the extra byte to store the value
|
||||
*/
|
||||
template<typename T>
|
||||
inline ::size_t WRITE(std::ostream& out, T const& value)
|
||||
{
|
||||
::size_t count = 0;
|
||||
sz::Byte data[8];
|
||||
sz::Byte firstByte = 0;
|
||||
sz::Byte* b = (sz::Byte*)&value;
|
||||
::size_t SIZE = sizeof(T);
|
||||
b+= SIZE-1;
|
||||
vfs::Int32 i;
|
||||
for(i = (vfs::Int32)(SIZE-1); i>=0; --i)
|
||||
{
|
||||
if( (*b & 0xFF) != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
b--;
|
||||
}
|
||||
if(i < 0)
|
||||
{
|
||||
count += WRITEBYTE(out,0);
|
||||
return count;
|
||||
}
|
||||
if(i == 0)
|
||||
{
|
||||
if(*b >= 0x80)
|
||||
{
|
||||
count += WRITEBYTE(out,0x80);
|
||||
}
|
||||
count += WRITEBYTE(out,*b);
|
||||
return count;
|
||||
}
|
||||
vfs::Int32 num = 0;
|
||||
for(;i >= 0; --i)
|
||||
{
|
||||
firstByte |= 1 << (8 - i - 1);
|
||||
data[i] = *b--;
|
||||
num++;
|
||||
}
|
||||
count += WRITEBYTE(out,firstByte);
|
||||
count += WRITEBUFFER(out,data,num);
|
||||
return count;
|
||||
}
|
||||
}
|
||||
/******************************************************************************************/
|
||||
/******************************************************************************************/
|
||||
/******************************************************************************************/
|
||||
|
||||
vfs::CCreateUncompressed7zLibrary::CCreateUncompressed7zLibrary()
|
||||
: m_pLibFile(NULL)
|
||||
{
|
||||
sz::CrcGenerateTable();
|
||||
}
|
||||
|
||||
vfs::CCreateUncompressed7zLibrary::~CCreateUncompressed7zLibrary()
|
||||
{
|
||||
m_pLibFile = NULL;
|
||||
|
||||
m_lFileInfo.clear();
|
||||
m_mapDirInfo.clear();
|
||||
}
|
||||
|
||||
bool vfs::CCreateUncompressed7zLibrary::addFile(vfs::tReadableFile* pFile)
|
||||
{
|
||||
if(!pFile)
|
||||
{
|
||||
// at least nothing bad happened
|
||||
return true;
|
||||
}
|
||||
try
|
||||
{
|
||||
vfs::COpenReadFile infile(pFile);
|
||||
}
|
||||
catch(CBasicException &ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Could not open File \"" << pFile->getPath()() << L"\"";
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
SFileInfo fi;
|
||||
vfs::Path filename = pFile->getPath();
|
||||
fi.name = filename.c_wcs();
|
||||
fi.size = pFile->getSize();
|
||||
if(m_lFileInfo.empty())
|
||||
{
|
||||
fi.offset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
SFileInfo const& fic = m_lFileInfo.back();
|
||||
fi.offset = fic.offset + fic.size;
|
||||
}
|
||||
|
||||
typedef std::vector<vfs::Byte> tByteVector;
|
||||
tByteVector data( (tByteVector::size_type)fi.size );
|
||||
THROWIFFALSE(fi.size == pFile->read(&data[0], (vfs::size_t)fi.size), L"");
|
||||
fi.CRC = sz::CrcCalc(&data[0],(::size_t)fi.size);
|
||||
m_ssFileStream.write(&data[0],(std::streamsize)fi.size);
|
||||
|
||||
m_lFileInfo.push_back(fi);
|
||||
|
||||
vfs::Path path,dummy;
|
||||
filename.splitLast(path,dummy);
|
||||
if(!path.empty())
|
||||
{
|
||||
tDirInfo::iterator it_find = m_mapDirInfo.find(path.c_wcs());
|
||||
if(it_find == m_mapDirInfo.end())
|
||||
{
|
||||
SFileInfo dir;
|
||||
dir.name = path.c_wcs();
|
||||
dir.offset = 0;
|
||||
dir.size = 0;
|
||||
dir.time_creation = 0;
|
||||
dir.time_last_access = 0;
|
||||
dir.time_write = 0;
|
||||
m_mapDirInfo.insert(std::make_pair(dir.name,dir));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeLibrary(vfs::Path const& sLibName)
|
||||
{
|
||||
vfs::COpenWriteFile outfile(sLibName,true);
|
||||
return writeLibrary(&outfile.file());
|
||||
}
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeLibrary(vfs::tWritableFile* pFile)
|
||||
{
|
||||
if(!pFile)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(m_lFileInfo.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_pLibFile = pFile;
|
||||
if(!m_pLibFile->isOpenWrite() && !m_pLibFile->openWrite(true,true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//
|
||||
writeNextHeader(m_ssInfoStream);
|
||||
//
|
||||
std::stringstream ssSigHeader;
|
||||
writeSignatureHeader(ssSigHeader);
|
||||
//
|
||||
m_pLibFile->write(ssSigHeader.str().c_str() , (vfs::size_t)ssSigHeader.str().length());
|
||||
//
|
||||
m_pLibFile->write(m_ssFileStream.str().c_str() , (vfs::size_t)m_ssFileStream.str().length());
|
||||
//
|
||||
m_pLibFile->write(m_ssInfoStream.str().c_str() , (vfs::size_t)m_ssInfoStream.str().length());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**************************************************************************************/
|
||||
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeSignatureHeader(std::ostream& out)
|
||||
{
|
||||
::size_t count=0;
|
||||
|
||||
// #define k7zSignatureSize -> not in namespace sz
|
||||
count += szExt::WRITEBUFFER(out, sz::k7zSignature, k7zSignatureSize);
|
||||
|
||||
sz::Byte Major = 0, Minor = 2;
|
||||
count += szExt::WRITEALL(out, (sz::Byte)Major );
|
||||
count += szExt::WRITEALL(out, (sz::Byte)Minor );
|
||||
|
||||
sz::UInt32 StartHeaderCRC, NextHeaderCRC;
|
||||
|
||||
SFileInfo const& fi = m_lFileInfo.back();
|
||||
sz::UInt64 NextHeaderOffset = fi.offset + fi.size;
|
||||
sz::UInt64 NextHeaderSize = m_ssInfoStream.str().length()*sizeof(char);
|
||||
NextHeaderCRC = sz::CrcCalc(m_ssInfoStream.str().c_str(),(::size_t)NextHeaderSize);
|
||||
|
||||
std::stringstream sstemp;
|
||||
count += szExt::WRITEALL(sstemp, (sz::UInt64)NextHeaderOffset );
|
||||
count += szExt::WRITEALL(sstemp, (sz::UInt64)NextHeaderSize );
|
||||
count += szExt::WRITEALL(sstemp, (sz::UInt32)NextHeaderCRC );
|
||||
StartHeaderCRC = sz::CrcCalc(sstemp.str().c_str(), sstemp.str().length()*sizeof(char));
|
||||
|
||||
count += szExt::WRITEALL(out, (sz::UInt32)StartHeaderCRC );
|
||||
out << sstemp.str();
|
||||
|
||||
return true;
|
||||
}
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeNextHeader(std::ostream& out)
|
||||
{
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdHeader);
|
||||
|
||||
// this->WriteArchiveProperties(out);
|
||||
|
||||
// this->WriteAdditionalStreamsInfo(out)
|
||||
|
||||
//
|
||||
this->writeMainStreamsInfo(out);
|
||||
|
||||
//
|
||||
this->writeFilesInfo(out);
|
||||
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdEnd );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeMainStreamsInfo(std::ostream& out)
|
||||
{
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdMainStreamsInfo );
|
||||
|
||||
this->writePackInfo(out);
|
||||
|
||||
this->writeUnPackInfo(out);
|
||||
|
||||
this->writeSubStreamsInfo(out);
|
||||
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdEnd );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool vfs::CCreateUncompressed7zLibrary::writePackInfo(std::ostream& out)
|
||||
{
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdPackInfo );
|
||||
szExt::WRITE(out, (sz::UInt64)0 ); // data offset
|
||||
szExt::WRITE(out, (sz::UInt32)m_lFileInfo.size() );
|
||||
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdSize );
|
||||
std::list<SFileInfo>::iterator it = m_lFileInfo.begin();
|
||||
for(;it != m_lFileInfo.end(); ++it)
|
||||
{
|
||||
szExt::WRITE(out, (sz::UInt64)it->size );
|
||||
}
|
||||
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdEnd );
|
||||
return true;
|
||||
}
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeUnPackInfo(std::ostream& out)
|
||||
{
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdUnpackInfo );
|
||||
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdFolder );
|
||||
szExt::WRITE(out, (sz::UInt64)m_lFileInfo.size() );
|
||||
szExt::WRITE(out, (sz::Byte)0 ); // External
|
||||
|
||||
std::list<SFileInfo>::iterator fit = m_lFileInfo.begin();
|
||||
for(;fit != m_lFileInfo.end(); ++fit)
|
||||
{
|
||||
this->writeFolder(out);
|
||||
}
|
||||
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdCodersUnpackSize );
|
||||
fit = m_lFileInfo.begin();
|
||||
for(;fit != m_lFileInfo.end(); ++fit)
|
||||
{
|
||||
szExt::WRITE(out, (sz::UInt64)fit->size );
|
||||
}
|
||||
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdEnd );
|
||||
|
||||
return true;
|
||||
}
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeSubStreamsInfo(std::ostream& out)
|
||||
{
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdSubStreamsInfo );
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdCRC );
|
||||
|
||||
szExt::WRITE(out, (sz::Byte)1 ); // early out - all CRCs defined
|
||||
std::list<SFileInfo>::iterator fit = m_lFileInfo.begin();
|
||||
for(;fit != m_lFileInfo.end(); ++fit )
|
||||
{
|
||||
szExt::WRITEALL(out, (sz::UInt32)fit->CRC);
|
||||
}
|
||||
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdEnd );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeFolder(std::ostream& out)
|
||||
{
|
||||
szExt::WRITE(out, (sz::UInt32)1 ); // NumCoders
|
||||
|
||||
szExt::WRITE(out, (sz::Byte)1 ); // MainByte
|
||||
|
||||
szExt::WRITE(out, (sz::Byte)0 ); // Methods
|
||||
|
||||
return true;
|
||||
}
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeFilesInfo(std::ostream& out)
|
||||
{
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdFilesInfo );
|
||||
|
||||
vfs::UInt64 num_files = (m_lFileInfo.size()+m_mapDirInfo.size());
|
||||
szExt::WRITE(out, (sz::UInt64)num_files );
|
||||
|
||||
// empty stream -> pack info in bit-vector
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdEmptyStream );
|
||||
sz::UInt64 num_empty64 = num_files/8 + (num_files%8 == 0 ? 0 : 1);
|
||||
::size_t num_empty = (::size_t)num_empty64;
|
||||
THROWIFFALSE(num_empty == num_empty64, L"WTF");
|
||||
|
||||
sz::Byte *empty_vector = new sz::Byte[num_empty];
|
||||
memset(empty_vector,0,(::size_t)num_empty);
|
||||
for(::size_t e=m_lFileInfo.size(); e < num_files; ++e)
|
||||
{
|
||||
::size_t index = e / 8;
|
||||
empty_vector[index] |= 1 << (7 - e%8);
|
||||
}
|
||||
szExt::WRITE(out, (sz::UInt64)num_empty ); // size
|
||||
szExt::WRITEBUFFER(out, empty_vector, (::size_t)num_empty);
|
||||
delete[] empty_vector;
|
||||
|
||||
// names
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdName );
|
||||
::size_t count = 0;
|
||||
std::stringstream name_stream;
|
||||
count += szExt::WRITE(name_stream, (sz::Byte)0 ); // switch
|
||||
std::list<SFileInfo>::iterator fit = m_lFileInfo.begin();
|
||||
for(;fit != m_lFileInfo.end(); ++fit)
|
||||
{
|
||||
count += (::size_t)this->writeFileName(name_stream, fit->name);
|
||||
}
|
||||
std::map<utf8string::str_t,SFileInfo>::iterator dit = m_mapDirInfo.begin();
|
||||
for(;dit != m_mapDirInfo.end(); ++dit)
|
||||
{
|
||||
count += (::size_t)this->writeFileName(name_stream, dit->second.name);
|
||||
}
|
||||
szExt::WRITE(out, (sz::UInt64)count ); // size
|
||||
szExt::WRITEBUFFER(out, name_stream.str().c_str(), name_stream.str().length() );
|
||||
|
||||
//szExt::WRITE(out, (sz::Byte)sz::k7zIdEmptyFile );
|
||||
//szExt::WRITE(out, (sz::Byte)sz::k7zIdCTime ); // create
|
||||
//szExt::WRITE(out, (sz::Byte)sz::k7zIdATime ); // last access
|
||||
//szExt::WRITE(out, (sz::Byte)sz::k7zIdMTime ); // write
|
||||
|
||||
//szExt::WRITE(out, (sz::Byte)sz::k7zIdWinAttributes );
|
||||
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdEnd );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
vfs::size_t vfs::CCreateUncompressed7zLibrary::writeFileName(std::ostream& out, utf8string const& filename)
|
||||
{
|
||||
::size_t count = 0;
|
||||
THROWIFFALSE(filename.length(), L"zero length name");
|
||||
count += szExt::WRITEBUFFER(out, filename.c_str(), filename.length());
|
||||
count += szExt::WRITE(out, (sz::Byte)0);
|
||||
count += szExt::WRITE(out, (sz::Byte)0);
|
||||
return (vfs::size_t)count;
|
||||
}
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
#ifndef _VFS_CREATE_7Z_LIBRARY_H_
|
||||
#define _VFS_CREATE_7Z_LIBRARY_H_
|
||||
|
||||
#include "../Interface/vfs_file_interface.h"
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
#include <list>
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class VFS_API CCreateUncompressed7zLibrary
|
||||
{
|
||||
public:
|
||||
CCreateUncompressed7zLibrary();
|
||||
virtual ~CCreateUncompressed7zLibrary();
|
||||
|
||||
bool addFile(vfs::tReadableFile* pFile);
|
||||
|
||||
bool writeLibrary(vfs::Path const& sLibName);
|
||||
bool writeLibrary(vfs::tWritableFile* pFile);
|
||||
protected:
|
||||
bool writeSignatureHeader(std::ostream& out);
|
||||
bool writeNextHeader(std::ostream& out);
|
||||
bool writeMainStreamsInfo(std::ostream &out);
|
||||
bool writePackInfo(std::ostream& out);
|
||||
bool writeUnPackInfo(std::ostream& out);
|
||||
bool writeSubStreamsInfo(std::ostream& out);
|
||||
bool writeFolder(std::ostream& out);
|
||||
bool writeFilesInfo(std::ostream& out);
|
||||
private:
|
||||
vfs::size_t writeFileName(std::ostream& out, utf8string const& filename);
|
||||
|
||||
protected:
|
||||
vfs::tWritableFile* m_pLibFile;
|
||||
|
||||
struct SFileInfo
|
||||
{
|
||||
SFileInfo()
|
||||
: name(L""), CRC(0), offset(0), size(0), time_creation(0), time_last_access(0), time_write(0)
|
||||
{};
|
||||
//////
|
||||
utf8string::str_t name;
|
||||
vfs::UInt32 CRC;
|
||||
vfs::UInt64 offset;
|
||||
vfs::UInt64 size;
|
||||
vfs::UInt64 time_creation,time_last_access,time_write;
|
||||
};
|
||||
typedef std::map<utf8string::str_t,SFileInfo> tDirInfo;
|
||||
|
||||
std::list<SFileInfo> m_lFileInfo;
|
||||
tDirInfo m_mapDirInfo;
|
||||
|
||||
// keeping pointers to files to write their contents lates is not enough,
|
||||
// as the file may only exist for a short time
|
||||
std::stringstream m_ssFileStream;
|
||||
|
||||
std::stringstream m_ssInfoStream;
|
||||
};
|
||||
} // end namespace
|
||||
|
||||
#endif // _VFS_CREATE_7Z_LIBRARY_H_
|
||||
|
||||
@@ -1,605 +0,0 @@
|
||||
#include "vfs_directory_tree.h"
|
||||
#include "../File/vfs_dir_file.h"
|
||||
#include "../Interface/vfs_location_aware_file_interface.h"
|
||||
#include "../os_functions.h"
|
||||
|
||||
#include <queue>
|
||||
#include <list>
|
||||
#include <set>
|
||||
|
||||
#define ERROR_FILE(msg) BuildString().add((msg)).add(L" : ").add(pFile->getPath()).get()
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
template<typename WriteType>
|
||||
class TSubDir : public vfs::TDirectory<typename vfs::TDirectoryTree<WriteType>::tWriteType>
|
||||
{
|
||||
typedef vfs::TDirectory<typename vfs::TDirectoryTree<WriteType>::tWriteType> tBaseClass;
|
||||
typedef typename tBaseClass::tFileType tFileType;
|
||||
|
||||
typedef std::map<vfs::Path, tFileType*, vfs::Path::Less> tFileCatalogue;
|
||||
public:
|
||||
typedef vfs::IBaseLocation::Iterator Iterator;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
class IterImpl : public vfs::IBaseLocation::Iterator::IImplementation
|
||||
{
|
||||
friend class TSubDir<WriteType>;
|
||||
typedef vfs::IBaseLocation::Iterator::IImplementation tBaseClass;
|
||||
|
||||
IterImpl(TSubDir<WriteType>* dir): _dir(dir)
|
||||
{
|
||||
THROWIFFALSE(_dir, L"");
|
||||
_iter = _dir->m_mapFiles.begin();
|
||||
}
|
||||
public:
|
||||
IterImpl() : tBaseClass(), _dir(NULL)
|
||||
{};
|
||||
virtual ~IterImpl()
|
||||
{};
|
||||
|
||||
virtual tFileType* value()
|
||||
{
|
||||
if(_iter != _dir->m_mapFiles.end())
|
||||
{
|
||||
return _iter->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
virtual void next()
|
||||
{
|
||||
if(_iter != _dir->m_mapFiles.end())
|
||||
{
|
||||
_iter++;
|
||||
}
|
||||
}
|
||||
protected:
|
||||
tBaseClass* clone()
|
||||
{
|
||||
IterImpl* iter = new IterImpl();
|
||||
iter->_dir = _dir;
|
||||
iter->_iter = _iter;
|
||||
return iter;
|
||||
}
|
||||
private:
|
||||
TSubDir<WriteType>* _dir;
|
||||
typename tFileCatalogue::iterator _iter;
|
||||
};
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
public:
|
||||
TSubDir(vfs::Path const& sMountPoint, vfs::Path const& sRealPath)
|
||||
: tBaseClass(sMountPoint,sRealPath)
|
||||
{};
|
||||
|
||||
virtual ~TSubDir();
|
||||
|
||||
virtual bool fileExists(vfs::Path const& rFileName);
|
||||
virtual vfs::IBaseFile* getFile(vfs::Path const& rFileName);
|
||||
virtual tFileType* getFileTyped(vfs::Path const& rFileName);
|
||||
|
||||
virtual tFileType* addFile(vfs::Path const& sFilename, bool bDeleteOldFile=false);
|
||||
virtual bool addFile(tFileType* pFile, bool bDeleteOldFile=false);
|
||||
|
||||
virtual bool createSubDirectory(vfs::Path const& sSubDirPath);
|
||||
virtual bool deleteDirectory(vfs::Path const& sDirPath);
|
||||
virtual bool deleteFileFromDirectory(vfs::Path const& sFileName);
|
||||
|
||||
virtual void getSubDirList(std::list<vfs::Path>& rlSubDirs);
|
||||
|
||||
virtual Iterator begin();
|
||||
private:
|
||||
tFileCatalogue m_mapFiles;
|
||||
};
|
||||
|
||||
template<>
|
||||
vfs::TSubDir<vfs::IWriteType>::tFileType* vfs::TSubDir<vfs::IWriteType>::addFile(vfs::Path const& sFilename, bool bDeleteOldFile);
|
||||
template<>
|
||||
vfs::TSubDir<vfs::IWritable>::tFileType* vfs::TSubDir<vfs::IWritable>::addFile(vfs::Path const& sFilename, bool bDeleteOldFile);
|
||||
|
||||
template<>
|
||||
bool vfs::TSubDir<vfs::IWriteType>::deleteDirectory(vfs::Path const& sDirPath);
|
||||
template<>
|
||||
bool vfs::TSubDir<vfs::IWritable>::deleteDirectory(vfs::Path const& sDirPath);
|
||||
|
||||
template<>
|
||||
bool vfs::TSubDir<vfs::IWriteType>::deleteFileFromDirectory(vfs::Path const& rFileName);
|
||||
template<>
|
||||
bool vfs::TSubDir<vfs::IWritable>::deleteFileFromDirectory(vfs::Path const& rFileName);
|
||||
}
|
||||
|
||||
/********************************************************/
|
||||
|
||||
template<typename WriteType>
|
||||
vfs::TSubDir<WriteType>::~TSubDir()
|
||||
{
|
||||
typename tFileCatalogue::iterator it = m_mapFiles.begin();
|
||||
for(; it != m_mapFiles.end(); ++it)
|
||||
{
|
||||
if(it->second)
|
||||
{
|
||||
it->second->close();
|
||||
delete it->second;
|
||||
}
|
||||
}
|
||||
m_mapFiles.clear();
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
bool vfs::TSubDir<WriteType>::fileExists(vfs::Path const& sFileName)
|
||||
{
|
||||
typename tFileCatalogue::iterator it = m_mapFiles.find(sFileName);
|
||||
bool success = (it != m_mapFiles.end()) && (it->second != NULL);
|
||||
return success;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
vfs::IBaseFile* vfs::TSubDir<WriteType>::getFile(vfs::Path const& sFileName)
|
||||
{
|
||||
return getFileTyped(sFileName);
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
typename vfs::TSubDir<WriteType>::tFileType* vfs::TSubDir<WriteType>::getFileTyped(vfs::Path const& sFileName)
|
||||
{
|
||||
typename tFileCatalogue::iterator it = m_mapFiles.find(sFileName);
|
||||
if(it != m_mapFiles.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
template<>
|
||||
vfs::TSubDir<vfs::IWriteType>::tFileType* vfs::TSubDir<vfs::IWriteType>::addFile(vfs::Path const& sFilename, bool bDeleteOldFile)
|
||||
{
|
||||
tFileType* pFile = m_mapFiles[sFilename];
|
||||
if(pFile)
|
||||
{
|
||||
if(!bDeleteOldFile)
|
||||
{
|
||||
// not allowed to replace old file
|
||||
return NULL;
|
||||
}
|
||||
delete pFile;
|
||||
}
|
||||
pFile = new vfs::CReadOnlyDirFile(sFilename,this);
|
||||
m_mapFiles[sFilename] = pFile;
|
||||
|
||||
return pFile;
|
||||
}
|
||||
|
||||
template<>
|
||||
vfs::TSubDir<vfs::IWritable>::tFileType* vfs::TSubDir<vfs::IWritable>::addFile(vfs::Path const& sFilename, bool bDeleteOldFile)
|
||||
{
|
||||
tFileType* pFile = m_mapFiles[sFilename];
|
||||
if(pFile)
|
||||
{
|
||||
if(!bDeleteOldFile)
|
||||
{
|
||||
// not allowed to replace old file
|
||||
return NULL;
|
||||
}
|
||||
delete pFile;
|
||||
}
|
||||
pFile = new vfs::CDirFile(sFilename,this);
|
||||
m_mapFiles[sFilename] = pFile;
|
||||
|
||||
return pFile;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
bool vfs::TSubDir<WriteType>::addFile(tFileType* pFile, bool bDeleteOldFile)
|
||||
{
|
||||
if(!pFile)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
tFileType* pOldFile = m_mapFiles[pFile->getName()];
|
||||
if( pOldFile && (pOldFile != pFile) )
|
||||
{
|
||||
if(bDeleteOldFile)
|
||||
{
|
||||
pOldFile->close();
|
||||
delete pOldFile;
|
||||
}
|
||||
}
|
||||
m_mapFiles[pFile->getName()] = pFile;
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool vfs::TSubDir<vfs::IWritable>::deleteDirectory(vfs::Path const& sDirPath)
|
||||
{
|
||||
if( !(this->m_mountPoint == sDirPath) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
tFileCatalogue::iterator it = m_mapFiles.begin();
|
||||
for(; it != m_mapFiles.end(); ++it)
|
||||
{
|
||||
tFileType* pFile = it->second;
|
||||
if(pFile)
|
||||
{
|
||||
pFile->close();
|
||||
if(!pFile->deleteFile())
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Could not delete file \"" << pFile->getPath()() << L"\"";
|
||||
THROWEXCEPTION( ERROR_FILE(L"Could not delete file") );
|
||||
}
|
||||
delete pFile;
|
||||
}
|
||||
}
|
||||
m_mapFiles.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool vfs::TSubDir<vfs::IWriteType>::deleteDirectory(vfs::Path const& sDirPath)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool vfs::TSubDir<vfs::IWritable>::deleteFileFromDirectory(vfs::Path const& rFileName)
|
||||
{
|
||||
tFileCatalogue::iterator it = m_mapFiles.find(rFileName);
|
||||
if( it != m_mapFiles.end() )
|
||||
{
|
||||
tFileType* pFile = it->second;
|
||||
if(pFile)
|
||||
{
|
||||
pFile->close();
|
||||
THROWIFFALSE(pFile->deleteFile(), ERROR_FILE(L"Could not delete file"));
|
||||
delete pFile;
|
||||
}
|
||||
m_mapFiles.erase(it);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool vfs::TSubDir<vfs::IWriteType>::deleteFileFromDirectory(vfs::Path const& rFileName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
bool vfs::TSubDir<WriteType>::createSubDirectory(vfs::Path const& sSubDirPath)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
void vfs::TSubDir<WriteType>::getSubDirList(std::list<vfs::Path>& rlSubDirs)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
typename vfs::TSubDir<WriteType>::Iterator vfs::TSubDir<WriteType>::begin()
|
||||
{
|
||||
return Iterator(new IterImpl(this));
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
template<typename WriteType>
|
||||
class vfs::TDirectoryTree<WriteType>::IterImpl : public vfs::IBaseLocation::Iterator::IImplementation
|
||||
{
|
||||
typedef vfs::IBaseLocation::Iterator::IImplementation tBaseClass;
|
||||
typedef vfs::TDirectoryTree<WriteType> tDirTree;
|
||||
public:
|
||||
IterImpl(tDirTree& tree);
|
||||
virtual ~IterImpl();
|
||||
|
||||
virtual typename tDirTree::tFileType* value();
|
||||
virtual void next();
|
||||
protected:
|
||||
virtual tBaseClass* clone()
|
||||
{
|
||||
IterImpl* iter = new IterImpl(_tree);
|
||||
iter->_subdir_iter = _subdir_iter;
|
||||
iter->_file_iter = _file_iter;
|
||||
return iter;
|
||||
}
|
||||
private:
|
||||
void operator=(typename vfs::TDirectoryTree<WriteType>::IterImpl const& tree);
|
||||
tDirTree& _tree;
|
||||
typename tDirTree::tDirCatalogue::iterator _subdir_iter;
|
||||
typename tDirTree::tLocationType::Iterator _file_iter;
|
||||
};
|
||||
|
||||
template<typename WriteType>
|
||||
vfs::TDirectoryTree<WriteType>::IterImpl::IterImpl(vfs::TDirectoryTree<WriteType>& tree)
|
||||
: tBaseClass(), _tree(tree)
|
||||
{
|
||||
_subdir_iter = _tree.m_catDirs.begin();
|
||||
if(_subdir_iter != _tree.m_catDirs.end())
|
||||
{
|
||||
TSubDir<WriteType> *sdir = dynamic_cast<TSubDir<WriteType>*>(_subdir_iter->second);
|
||||
typename TSubDir<WriteType>::Iterator it = sdir->begin();
|
||||
_file_iter = it;
|
||||
if(_file_iter.end())
|
||||
{
|
||||
next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
vfs::TDirectoryTree<WriteType>::IterImpl::~IterImpl()
|
||||
{
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
typename vfs::TDirectoryTree<WriteType>::tFileType* vfs::TDirectoryTree<WriteType>::IterImpl::value()
|
||||
{
|
||||
if(!_file_iter.end())
|
||||
{
|
||||
return static_cast<vfs::TDirectoryTree<WriteType>::tFileType*>(_file_iter.value());
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
void vfs::TDirectoryTree<WriteType>::IterImpl::next()
|
||||
{
|
||||
if(!_file_iter.end())
|
||||
{
|
||||
_file_iter.next();
|
||||
}
|
||||
// need to loop for the case when one or many sub directories are empty
|
||||
while(_file_iter.end())
|
||||
{
|
||||
if(_subdir_iter == _tree.m_catDirs.end())
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
_subdir_iter++;
|
||||
if(_subdir_iter != _tree.m_catDirs.end())
|
||||
{
|
||||
_file_iter = _subdir_iter->second->begin();
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
template<typename WriteType>
|
||||
vfs::TDirectoryTree<WriteType>::TDirectoryTree(vfs::Path const& sMountPoint, vfs::Path const& sRealPath)
|
||||
: tBaseClass(sMountPoint,sRealPath)
|
||||
{};
|
||||
|
||||
|
||||
template<typename WriteType>
|
||||
vfs::TDirectoryTree<WriteType>::~TDirectoryTree()
|
||||
{
|
||||
typename tDirCatalogue::iterator it = m_catDirs.begin();
|
||||
for(;it != m_catDirs.end(); ++it)
|
||||
{
|
||||
delete it->second;
|
||||
it->second = NULL;
|
||||
}
|
||||
m_catDirs.clear();
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
bool vfs::TDirectoryTree<WriteType>::init()
|
||||
{
|
||||
// contains local path
|
||||
typedef vfs::TSubDir<WriteType> tSubDir;
|
||||
typedef std::pair<vfs::Path,tSubDir*> tDirs;
|
||||
std::queue<tDirs> qSubDirs;
|
||||
qSubDirs.push(tDirs(vfs::Path(vfs::Const::EMPTY()),new tSubDir(this->m_mountPoint, this->m_realPath)));
|
||||
|
||||
m_catDirs[this->m_mountPoint] = qSubDirs.front().second;
|
||||
|
||||
utf8string sFilename;
|
||||
tSubDir *pCurrentDir;
|
||||
vfs::Path oCurDir;
|
||||
while(!qSubDirs.empty())
|
||||
{
|
||||
pCurrentDir = qSubDirs.front().second;
|
||||
oCurDir = this->m_realPath;
|
||||
if( !qSubDirs.front().first.empty())
|
||||
{
|
||||
oCurDir += qSubDirs.front().first;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
os::CIterateDirectory::EFileAttribute eFA;
|
||||
os::CIterateDirectory iterFS(oCurDir, vfs::Const::STAR());
|
||||
while ( iterFS.nextFile(sFilename, eFA) )
|
||||
{
|
||||
if (StrCmp::Equal(vfs::Const::DOT(),sFilename) || StrCmp::Equal(vfs::Const::DOTDOT(),sFilename) || StrCmp::Equal(vfs::Const::DOTSVN(),sFilename) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (eFA == os::CIterateDirectory::FA_DIRECTORY)
|
||||
{
|
||||
vfs::Path sLocal = qSubDirs.front().first + sFilename;
|
||||
|
||||
vfs::Path temp = this->m_mountPoint+sLocal;
|
||||
tSubDir *pNewDir = new tSubDir(sLocal, this->m_realPath+sLocal);
|
||||
qSubDirs.push(tDirs(sLocal,pNewDir));
|
||||
m_catDirs[temp] = pNewDir;
|
||||
}
|
||||
else
|
||||
{
|
||||
pCurrentDir->addFile(vfs::Path(sFilename));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(CBasicException &ex)
|
||||
{
|
||||
// probably directory doesn't exist. abort or continue???
|
||||
// -> abort AND continue
|
||||
logException(ex);
|
||||
return false;
|
||||
}
|
||||
qSubDirs.pop();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
typename vfs::TDirectoryTree<WriteType>::tFileType* vfs::TDirectoryTree<WriteType>::addFile(vfs::Path const& sFilename, bool bDeleteOldFile)
|
||||
{
|
||||
vfs::Path sDir,sFile;
|
||||
sFilename.splitLast(sDir,sFile);
|
||||
typename tDirCatalogue::iterator it = m_catDirs.find(sDir);
|
||||
if(it == m_catDirs.end())
|
||||
{
|
||||
vfs::Path sTemp,sCreateDir,sLeft,sRight = sDir;
|
||||
while(!sRight.empty())
|
||||
{
|
||||
sRight.splitFirst(sLeft,sTemp);
|
||||
sRight = sTemp;
|
||||
sCreateDir += sLeft;
|
||||
this->createSubDirectory(sCreateDir);
|
||||
}
|
||||
it = m_catDirs.find(sDir);
|
||||
if(it == m_catDirs.end())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if(it->second)
|
||||
{
|
||||
return it->second->addFile(sFile,bDeleteOldFile);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
bool vfs::TDirectoryTree<WriteType>::addFile(tFileType* pFile, bool bDeleteOldFile)
|
||||
{
|
||||
// no files from outside
|
||||
// these files are not connected with the correct directory object
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
bool vfs::TDirectoryTree<WriteType>::deleteDirectory(vfs::Path const& sDirPath)
|
||||
{
|
||||
typename tDirCatalogue::iterator it = m_catDirs.find(sDirPath);
|
||||
if(it == m_catDirs.end())
|
||||
{
|
||||
// no such directory
|
||||
return false;
|
||||
}
|
||||
if(it->second)
|
||||
{
|
||||
return it->second->deleteDirectory(sDirPath);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
bool vfs::TDirectoryTree<WriteType>::deleteFileFromDirectory(vfs::Path const& sFileName)
|
||||
{
|
||||
vfs::Path sDir,sFile;
|
||||
sFileName.splitLast(sDir,sFile);
|
||||
typename tDirCatalogue::iterator it = m_catDirs.find(sDir);
|
||||
if(it == m_catDirs.end())
|
||||
{
|
||||
// no such directory
|
||||
return false;
|
||||
}
|
||||
if(it->second)
|
||||
{
|
||||
return it->second->deleteFileFromDirectory(sFile);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* IVFSLocation interface
|
||||
*/
|
||||
template<typename WriteType>
|
||||
bool vfs::TDirectoryTree<WriteType>::fileExists(vfs::Path const& sFileName)
|
||||
{
|
||||
vfs::Path sDir, sFile;
|
||||
sFileName.splitLast(sDir, sFile);
|
||||
typename tDirCatalogue::iterator it = m_catDirs.find(sDir);
|
||||
if(it == m_catDirs.end())
|
||||
{
|
||||
// no such directory
|
||||
return false;
|
||||
}
|
||||
if(it->second)
|
||||
{
|
||||
return it->second->fileExists(sFile);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
vfs::IBaseFile* vfs::TDirectoryTree<WriteType>::getFile(vfs::Path const& sFileName)
|
||||
{
|
||||
return getFileTyped(sFileName);
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
typename vfs::TDirectoryTree<WriteType>::tFileType* vfs::TDirectoryTree<WriteType>::getFileTyped(vfs::Path const& sFileName)
|
||||
{
|
||||
vfs::Path sDir, sFile;
|
||||
sFileName.splitLast(sDir, sFile);
|
||||
typename tDirCatalogue::iterator it = m_catDirs.find(sDir);
|
||||
if(it == m_catDirs.end())
|
||||
{
|
||||
// no such directory
|
||||
return NULL;
|
||||
}
|
||||
if(it->second)
|
||||
{
|
||||
return it->second->getFileTyped(sFile);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
bool vfs::TDirectoryTree<WriteType>::createSubDirectory(vfs::Path const& sSubDirPath)
|
||||
{
|
||||
if(os::createRealDirectory( this->m_realPath + sSubDirPath ))
|
||||
{
|
||||
if( m_catDirs[sSubDirPath] == NULL)
|
||||
{
|
||||
m_catDirs[sSubDirPath] = new vfs::TSubDir<WriteType>(sSubDirPath, this->m_realPath + sSubDirPath);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
void vfs::TDirectoryTree<WriteType>::getSubDirList(std::list<vfs::Path>& rlSubDirs)
|
||||
{
|
||||
typename tDirCatalogue::iterator it = m_catDirs.begin();
|
||||
for(;it != m_catDirs.end(); ++it)
|
||||
{
|
||||
rlSubDirs.push_back(it->first);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
typename vfs::TDirectoryTree<WriteType>::Iterator vfs::TDirectoryTree<WriteType>::begin()
|
||||
{
|
||||
return Iterator(new IterImpl(*this));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
template class vfs::TDirectoryTree<vfs::IWritable>; // explicit template class instantiation
|
||||
template class vfs::TDirectoryTree<vfs::IWriteType>; // explicit template class instantiation
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
#ifndef _VFS_DIRECTORY_H_
|
||||
#define _VFS_DIRECTORY_H_
|
||||
|
||||
#include "../vfs_types.h"
|
||||
//#include "Interface/vfs_location_interface.h"
|
||||
#include "../Interface/vfs_file_interface.h"
|
||||
#include "../Interface/vfs_directory_interface.h"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
|
||||
/**
|
||||
* IDirectory<read,write>
|
||||
*/
|
||||
template<typename WriteType>
|
||||
class TDirectoryTree : public vfs::TDirectory<WriteType>
|
||||
{
|
||||
typedef std::map<vfs::Path, vfs::TDirectory<typename TDirectoryTree<WriteType>::tWriteType>*, vfs::Path::Less> tDirCatalogue;
|
||||
|
||||
class IterImpl;
|
||||
public:
|
||||
typedef vfs::TDirectory<WriteType> tBaseClass;
|
||||
typedef typename tBaseClass::tWriteType tWriteType;
|
||||
typedef typename tBaseClass::tFileType tFileType;
|
||||
|
||||
typedef TIterator<vfs::IBaseFile> Iterator;
|
||||
TDirectoryTree(vfs::Path const& sMountPoint, vfs::Path const& sRealPath);
|
||||
virtual ~TDirectoryTree();
|
||||
|
||||
bool init();
|
||||
|
||||
/**
|
||||
* TDirectory interface
|
||||
*/
|
||||
virtual tFileType* addFile(vfs::Path const& sFilename, bool bDeleteOldFile=false);
|
||||
virtual bool addFile(tFileType* pFile, bool bDeleteOldFile=false);
|
||||
|
||||
virtual bool createSubDirectory(vfs::Path const& sSubDirPath);
|
||||
virtual bool deleteDirectory(vfs::Path const& sDirPath);
|
||||
virtual bool deleteFileFromDirectory(vfs::Path const& sFileName);
|
||||
|
||||
/**
|
||||
* TVFSLocation interface
|
||||
*/
|
||||
virtual bool fileExists(vfs::Path const& sFileName);
|
||||
virtual vfs::IBaseFile* getFile(vfs::Path const& sFileName);
|
||||
virtual tFileType* getFileTyped(vfs::Path const& sFileName);
|
||||
virtual void getSubDirList(std::list<vfs::Path>& rlSubDirs);
|
||||
|
||||
virtual Iterator begin();
|
||||
protected:
|
||||
tDirCatalogue m_catDirs;
|
||||
};
|
||||
|
||||
typedef TDirectoryTree<vfs::IWritable> CDirectoryTree;
|
||||
typedef TDirectoryTree<vfs::IWriteType> CReadOnlyDirectoryTree;
|
||||
|
||||
} // end namespace
|
||||
|
||||
#endif // _VFS_DIRECTORY_H_
|
||||
@@ -1,178 +0,0 @@
|
||||
#include "vfs_lib_dir.h"
|
||||
#include "../Tools/Log.h"
|
||||
|
||||
class vfs::CLibDirectory::IterImpl : public vfs::IBaseLocation::Iterator::IImplementation
|
||||
{
|
||||
typedef vfs::IBaseLocation::Iterator::IImplementation tBaseClass;
|
||||
public:
|
||||
IterImpl(CLibDirectory& lib);
|
||||
virtual ~IterImpl();
|
||||
virtual vfs::CLibDirectory::tFileType* value();
|
||||
virtual void next();
|
||||
protected:
|
||||
virtual tBaseClass* clone();
|
||||
private:
|
||||
void operator=(vfs::CLibDirectory::IterImpl const& iter);
|
||||
|
||||
vfs::CLibDirectory& _lib;
|
||||
vfs::CLibDirectory::tFileCatalogue::iterator _iter;
|
||||
};
|
||||
|
||||
vfs::CLibDirectory::IterImpl::IterImpl(CLibDirectory& lib)
|
||||
: tBaseClass(), _lib(lib)
|
||||
{
|
||||
_iter = _lib.m_files.begin();
|
||||
}
|
||||
|
||||
vfs::CLibDirectory::IterImpl::~IterImpl()
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CLibDirectory::tFileType* vfs::CLibDirectory::IterImpl::value()
|
||||
{
|
||||
if(_iter != _lib.m_files.end())
|
||||
{
|
||||
return _iter->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void vfs::CLibDirectory::IterImpl::next()
|
||||
{
|
||||
if(_iter != _lib.m_files.end())
|
||||
{
|
||||
_iter++;
|
||||
}
|
||||
}
|
||||
|
||||
vfs::CLibDirectory::IterImpl::tBaseClass* vfs::CLibDirectory::IterImpl::clone()
|
||||
{
|
||||
IterImpl* iter = new IterImpl(_lib);
|
||||
iter->_iter = _iter;
|
||||
return iter;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
vfs::CLibDirectory::CLibDirectory(vfs::Path const& sLocalPath, vfs::Path const& sRealPath)
|
||||
: tBaseClass(sLocalPath,sRealPath)
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CLibDirectory::~CLibDirectory()
|
||||
{
|
||||
tFileCatalogue::iterator it = m_files.begin();
|
||||
for(; it != m_files.end(); ++it)
|
||||
{
|
||||
// don't delete objects here
|
||||
//delete it->second;
|
||||
}
|
||||
m_files.clear();
|
||||
}
|
||||
|
||||
vfs::CLibDirectory::tFileType* vfs::CLibDirectory::addFile(vfs::Path const& filename, bool deleteOldFile)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool vfs::CLibDirectory::addFile(tFileType* file, bool deleteOldFile)
|
||||
{
|
||||
if(!file)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
vfs::Path const& name = file->getName();
|
||||
tFileType* oldFile = m_files[name];
|
||||
if(oldFile && (oldFile != file) )
|
||||
{
|
||||
if(deleteOldFile)
|
||||
{
|
||||
delete oldFile;
|
||||
m_files[name] = file;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
m_files[name] = file;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vfs::CLibDirectory::deleteDirectory(vfs::Path const& dirPath)
|
||||
{
|
||||
//if( !(m_mountPoint == dirPath) )
|
||||
//{
|
||||
// return false;
|
||||
//}
|
||||
//if(implementsWritable())
|
||||
//{
|
||||
// tFileCatalogue::iterator it = m_files.begin();
|
||||
// for(; it != m_files.end(); ++it)
|
||||
// {
|
||||
// //delete it->second;
|
||||
// }
|
||||
// m_files.clear();
|
||||
// return true;
|
||||
//}
|
||||
CLog log(L"errors.log");
|
||||
log << "called 'vfs::CLibDirectory::deleteDirectory' which doesn't implement the IWritable interface" << CLog::ENDL;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool vfs::CLibDirectory::deleteFileFromDirectory(vfs::Path const& filename)
|
||||
{
|
||||
//if(implementsWritable())
|
||||
//{
|
||||
// tFileCatalogue::iterator it = m_files.find(filename);
|
||||
// if(it != m_files.end())
|
||||
// {
|
||||
// delete it->second;
|
||||
// m_files.erase(it);
|
||||
// return true;
|
||||
// }
|
||||
//}
|
||||
CLog log(L"errors.log");
|
||||
log << "called 'vfs::CLibDirectory::deleteFileFromDirectory' which doesn't implement the IWritable interface" << CLog::ENDL;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool vfs::CLibDirectory::fileExists(vfs::Path const& filename)
|
||||
{
|
||||
return (m_files[filename] != NULL);
|
||||
}
|
||||
|
||||
vfs::IBaseFile* vfs::CLibDirectory::getFile(vfs::Path const& filename)
|
||||
{
|
||||
return getFileTyped(filename);
|
||||
}
|
||||
|
||||
vfs::CLibDirectory::tFileType* vfs::CLibDirectory::getFileTyped(vfs::Path const& filename)
|
||||
{
|
||||
tFileCatalogue::iterator it = m_files.find(filename);
|
||||
if(it != m_files.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool vfs::CLibDirectory::createSubDirectory(vfs::Path const& subDirPath)
|
||||
{
|
||||
// libraries are readonly
|
||||
return false;
|
||||
}
|
||||
|
||||
void vfs::CLibDirectory::getSubDirList(std::list<vfs::Path>& rlSubDirs)
|
||||
{
|
||||
// nothing
|
||||
}
|
||||
|
||||
vfs::CLibDirectory::Iterator vfs::CLibDirectory::begin()
|
||||
{
|
||||
return Iterator(new IterImpl(*this));
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
@@ -1,43 +0,0 @@
|
||||
#ifndef _VFS_LIB_DIR_H_
|
||||
#define _VFS_LIB_DIR_H_
|
||||
|
||||
#include "../Interface/vfs_directory_interface.h"
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
|
||||
class CLibDirectory : public vfs::TDirectory<vfs::IWriteType>
|
||||
{
|
||||
typedef vfs::TDirectory<vfs::IWriteType> tBaseClass;
|
||||
typedef std::map<vfs::Path, tFileType*, vfs::Path::Less> tFileCatalogue;
|
||||
|
||||
class IterImpl;
|
||||
public:
|
||||
CLibDirectory(vfs::Path const& sLocalPath, vfs::Path const& sRealPath);
|
||||
virtual ~CLibDirectory();
|
||||
|
||||
/**
|
||||
* TDirectory interface
|
||||
*/
|
||||
virtual tFileType* addFile(vfs::Path const& filename, bool deleteOldFile=false);
|
||||
virtual bool addFile(tFileType* file, bool deleteOldFile=false);
|
||||
virtual bool deleteFileFromDirectory(vfs::Path const& filename);
|
||||
virtual bool createSubDirectory(vfs::Path const& subDirPath);
|
||||
virtual bool deleteDirectory(vfs::Path const& dirPath);
|
||||
|
||||
/**
|
||||
* TVFSLocation interface
|
||||
*/
|
||||
virtual bool fileExists(vfs::Path const& filename);
|
||||
virtual vfs::IBaseFile* getFile(vfs::Path const& filename);
|
||||
virtual tFileType* getFileTyped(vfs::Path const& filename);
|
||||
virtual void getSubDirList(std::list<vfs::Path>& rlSubDirs);
|
||||
|
||||
virtual Iterator begin();
|
||||
protected:
|
||||
tFileCatalogue m_files;
|
||||
};
|
||||
|
||||
} // -end- namespace
|
||||
|
||||
#endif // _VFS_LIB_DIR_H_
|
||||
@@ -1,152 +0,0 @@
|
||||
#include "vfs_slf_library.h"
|
||||
#include "vfs_lib_dir.h"
|
||||
#include "../vfs_config.h"
|
||||
#include "../Interface/vfs_directory_interface.h"
|
||||
#include "../File/vfs_lib_file.h"
|
||||
#include "../vfs_file_raii.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace slf
|
||||
{
|
||||
// copy from WinDef.h
|
||||
typedef unsigned long DWORD;
|
||||
typedef struct _FILETIME {
|
||||
DWORD dwLowDateTime;
|
||||
DWORD dwHighDateTime;
|
||||
} FILETIME, *PFILETIME, *LPFILETIME;
|
||||
|
||||
typedef void* HANDLE;
|
||||
|
||||
const vfs::UInt32 FILENAME_SIZE = 256;
|
||||
const vfs::UInt32 PATH_SIZE = 80;
|
||||
|
||||
const vfs::UInt32 FILE_OK = 0;
|
||||
const vfs::UInt32 FILE_DELETED = 0xff;
|
||||
const vfs::UInt32 FILE_OLD = 1;
|
||||
const vfs::UInt32 FILE_DOESNT_EXIST = 0xfe;
|
||||
|
||||
struct LIBHEADER
|
||||
{
|
||||
vfs::Byte sLibName[ FILENAME_SIZE ];
|
||||
vfs::Byte sPathToLibrary[ FILENAME_SIZE ];
|
||||
vfs::Int32 iEntries;
|
||||
vfs::Int32 iUsed;
|
||||
vfs::UInt16 iSort;
|
||||
vfs::UInt16 iVersion;
|
||||
vfs::UByte fContainsSubDirectories;
|
||||
vfs::Int32 iReserved;
|
||||
};
|
||||
|
||||
struct DIRENTRY
|
||||
{
|
||||
vfs::Byte sFileName[ FILENAME_SIZE ];
|
||||
vfs::UInt32 uiOffset;
|
||||
vfs::UInt32 uiLength;
|
||||
vfs::UInt8 ubState;
|
||||
vfs::UInt8 ubReserved;
|
||||
FILETIME sFileTime;
|
||||
vfs::UInt16 usReserved2;
|
||||
};
|
||||
}; // end namespace slf
|
||||
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
vfs::CSLFLibrary::CSLFLibrary(tReadableFile *pLibraryFile, vfs::Path const& sMountPoint, bool bOwnFile)
|
||||
: vfs::CUncompressedLibraryBase(pLibraryFile,sMountPoint,bOwnFile)
|
||||
{};
|
||||
|
||||
vfs::CSLFLibrary::~CSLFLibrary()
|
||||
{
|
||||
}
|
||||
|
||||
bool vfs::CSLFLibrary::init()
|
||||
{
|
||||
if(!m_libraryFile)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
vfs::COpenReadFile rfile(m_libraryFile);
|
||||
|
||||
slf::LIBHEADER LibFileHeader;
|
||||
vfs::size_t bytesRead = m_libraryFile->read((vfs::Byte*)&LibFileHeader, sizeof( slf::LIBHEADER ));
|
||||
THROWIFFALSE(bytesRead == sizeof( slf::LIBHEADER ), L"");
|
||||
|
||||
vfs::Path oLibPath;
|
||||
//if the library has a path
|
||||
if( strlen( (char*)LibFileHeader.sPathToLibrary ) != 0 )
|
||||
{
|
||||
oLibPath = vfs::Path( LibFileHeader.sPathToLibrary );
|
||||
}
|
||||
else
|
||||
{
|
||||
//else the library name does not contain a path ( most likely either an error or it is the default path )
|
||||
oLibPath = vfs::Path( vfs::Const::EMPTY() );
|
||||
}
|
||||
if(m_mountPoint.empty())
|
||||
{
|
||||
m_mountPoint = oLibPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_mountPoint += oLibPath;
|
||||
}
|
||||
|
||||
//place the file pointer at the begining of the file headers ( they are at the end of the file )
|
||||
m_libraryFile->setReadPosition(-( LibFileHeader.iEntries * (vfs::Int32)sizeof(slf::DIRENTRY) ), vfs::IBaseFile::SD_END);
|
||||
|
||||
//loop through the library and determine the number of files that are FILE_OK
|
||||
//ie. so we dont load the old or deleted files
|
||||
slf::DIRENTRY DirEntry;
|
||||
vfs::Path oDir, oFile;
|
||||
vfs::Path oDirPath;
|
||||
for(vfs::UInt32 uiLoop=0; uiLoop < (vfs::UInt32)LibFileHeader.iEntries; uiLoop++ )
|
||||
{
|
||||
//read in the file header
|
||||
bytesRead = m_libraryFile->read((Byte*)&DirEntry, sizeof( slf::DIRENTRY ));
|
||||
THROWIFFALSE(bytesRead == sizeof( slf::DIRENTRY ), L"");
|
||||
|
||||
if( DirEntry.ubState == slf::FILE_OK )
|
||||
{
|
||||
vfs::Path sPath(utf8string::as_utf16(DirEntry.sFileName));
|
||||
sPath.splitLast(oDir,oFile);
|
||||
oDirPath = m_mountPoint;
|
||||
if(!oDir.empty())
|
||||
{
|
||||
oDirPath += oDir;
|
||||
}
|
||||
|
||||
// get or create according directory object
|
||||
vfs::TDirectory<ILibrary::tWriteType>* pLD = NULL;
|
||||
tDirCatalogue::iterator it = m_dirs.find(oDirPath);
|
||||
if(it != m_dirs.end())
|
||||
{
|
||||
pLD = it->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
pLD = new vfs::CLibDirectory(oDirPath,oDirPath);
|
||||
m_dirs.insert(std::make_pair(oDirPath,pLD));
|
||||
}
|
||||
// create file
|
||||
vfs::CLibFile *pFile = vfs::CLibFile::create(oFile,pLD,this);
|
||||
// add file to directory
|
||||
THROWIFFALSE(pLD->addFile(pFile), L"");
|
||||
|
||||
// link file data struct to file object
|
||||
m_fileData.insert(std::make_pair(pFile, SFileData(DirEntry.uiLength, DirEntry.uiOffset)));
|
||||
} // end if
|
||||
} // end for
|
||||
return true;
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
logException(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#ifndef _VFS_SLF_LIBRARY_H_
|
||||
#define _VFS_SLF_LIBRARY_H_
|
||||
|
||||
#include "vfs_uncompressed_lib_base.h"
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class VFS_API CSLFLibrary : public vfs::CUncompressedLibraryBase
|
||||
{
|
||||
public:
|
||||
CSLFLibrary(tReadableFile *pLibraryFile, vfs::Path const& sMountPoint, bool bOwnFile = false);
|
||||
virtual ~CSLFLibrary();
|
||||
|
||||
virtual bool init();
|
||||
};
|
||||
|
||||
} // end namespace
|
||||
|
||||
#endif // _VFS_SLF_LIBRARY_H_
|
||||
|
||||
@@ -1,294 +0,0 @@
|
||||
#include "vfs_uncompressed_lib_base.h"
|
||||
|
||||
/********************************************************************************************/
|
||||
vfs::CUncompressedLibraryBase::SFileData& vfs::CUncompressedLibraryBase::_fileDataFromHandle(tFileType* handle)
|
||||
{
|
||||
tFileData::iterator it = m_fileData.find(handle);
|
||||
if(it != m_fileData.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
THROWEXCEPTION(L"Invalid file handle");
|
||||
}
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
class vfs::CUncompressedLibraryBase::IterImpl : public vfs::IBaseLocation::Iterator::IImplementation
|
||||
{
|
||||
typedef vfs::IBaseLocation::Iterator::IImplementation tBaseClass;
|
||||
public:
|
||||
IterImpl(CUncompressedLibraryBase& lib);
|
||||
virtual ~IterImpl();
|
||||
virtual tFileType* value();
|
||||
virtual void next();
|
||||
protected:
|
||||
virtual tBaseClass* clone()
|
||||
{
|
||||
IterImpl* iter = new IterImpl(*_lib);
|
||||
iter->_iter = _iter;
|
||||
return iter;
|
||||
}
|
||||
private:
|
||||
vfs::CUncompressedLibraryBase* _lib;
|
||||
vfs::CUncompressedLibraryBase::tFileData::iterator _iter;
|
||||
};
|
||||
|
||||
|
||||
vfs::CUncompressedLibraryBase::IterImpl::IterImpl(vfs::CUncompressedLibraryBase &lib)
|
||||
: tBaseClass(), _lib(&lib)
|
||||
{
|
||||
_iter = _lib->m_fileData.begin();
|
||||
}
|
||||
vfs::CUncompressedLibraryBase::IterImpl::~IterImpl()
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CUncompressedLibraryBase::tFileType* vfs::CUncompressedLibraryBase::IterImpl::value()
|
||||
{
|
||||
if(_iter != _lib->m_fileData.end())
|
||||
{
|
||||
return _iter->first;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void vfs::CUncompressedLibraryBase::IterImpl::next()
|
||||
{
|
||||
if(_iter != _lib->m_fileData.end())
|
||||
{
|
||||
_iter++;
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/************************************************************************/
|
||||
|
||||
vfs::CUncompressedLibraryBase::CUncompressedLibraryBase(vfs::tReadableFile *libraryFile, vfs::Path const& mountPoint, bool ownFile)
|
||||
: vfs::ILibrary(libraryFile,mountPoint,ownFile), m_numberOfOpenedFiles(0)
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CUncompressedLibraryBase::~CUncompressedLibraryBase()
|
||||
{
|
||||
this->closeLibrary();
|
||||
// delete sub dirs from catalogue
|
||||
tDirCatalogue::iterator it = m_dirs.begin();
|
||||
for(; it != m_dirs.end(); ++it)
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
// LibData is invalid
|
||||
// just clear it, since the file handles were deleted before
|
||||
m_fileData.clear();
|
||||
m_dirs.clear();
|
||||
}
|
||||
|
||||
void vfs::CUncompressedLibraryBase::closeLibrary()
|
||||
{
|
||||
tFileData::iterator it = m_fileData.begin();
|
||||
for(; it != m_fileData .end(); ++it)
|
||||
{
|
||||
// what if closing of (at least) one file fails?? continue or not??
|
||||
// in the end, these are not real files!
|
||||
IGNOREEXCEPTION(it->first->close());
|
||||
}
|
||||
}
|
||||
|
||||
bool vfs::CUncompressedLibraryBase::fileExists(vfs::Path const& filename)
|
||||
{
|
||||
vfs::Path sDir,sFile;
|
||||
filename.splitLast(sDir,sFile);
|
||||
tDirCatalogue::iterator it = m_dirs.find(sDir);
|
||||
if(it != m_dirs.end())
|
||||
{
|
||||
return it->second->fileExists(sFile);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
vfs::IBaseFile* vfs::CUncompressedLibraryBase::getFile(vfs::Path const& filename)
|
||||
{
|
||||
return getFileTyped(filename);
|
||||
}
|
||||
|
||||
vfs::CUncompressedLibraryBase::tFileType* vfs::CUncompressedLibraryBase::getFileTyped(vfs::Path const& filename)
|
||||
{
|
||||
vfs::Path sDir,sFile;
|
||||
filename.splitLast(sDir,sFile);
|
||||
tDirCatalogue::iterator it = m_dirs.find(sDir);
|
||||
if(it != m_dirs.end())
|
||||
{
|
||||
return it->second->getFileTyped(sFile);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void vfs::CUncompressedLibraryBase::close(tFileType *fileHandle)
|
||||
{
|
||||
try
|
||||
{
|
||||
SFileData& file = _fileDataFromHandle(fileHandle);
|
||||
|
||||
// reset read position
|
||||
// can't do this when opening file,
|
||||
// because you could try to open a file when it is already open and would so reset the read position
|
||||
file._currentReadPosition = 0;
|
||||
if(m_numberOfOpenedFiles > 0)
|
||||
{
|
||||
m_numberOfOpenedFiles--;
|
||||
if(m_numberOfOpenedFiles == 0)
|
||||
{
|
||||
m_libraryFile->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(L"", &ex);
|
||||
}
|
||||
}
|
||||
bool vfs::CUncompressedLibraryBase::openRead(tFileType *fileHandle)
|
||||
{
|
||||
try
|
||||
{
|
||||
_fileDataFromHandle(fileHandle);
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(L"", &ex);
|
||||
}
|
||||
|
||||
m_numberOfOpenedFiles++;
|
||||
if(m_numberOfOpenedFiles == 1)
|
||||
{
|
||||
if(!m_libraryFile->isOpenRead() && !m_libraryFile->openRead())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// already open
|
||||
return true;
|
||||
}
|
||||
|
||||
vfs::size_t vfs::CUncompressedLibraryBase::read(tFileType *fileHandle, vfs::Byte* data, vfs::size_t bytesToRead)
|
||||
{
|
||||
try
|
||||
{
|
||||
SFileData& file = _fileDataFromHandle(fileHandle);
|
||||
|
||||
if( (file._currentReadPosition + bytesToRead) > file._fileSize )
|
||||
{
|
||||
bytesToRead = file._fileSize - file._currentReadPosition;
|
||||
}
|
||||
if(bytesToRead == 0)
|
||||
{
|
||||
// eof
|
||||
return 0;
|
||||
}
|
||||
// set lib-file's read-location to match location of lib-file
|
||||
m_libraryFile->setReadPosition(file._fileOffset + file._currentReadPosition, IBaseFile::SD_BEGIN);
|
||||
|
||||
vfs::size_t bytesRead = m_libraryFile->read(data, bytesToRead);
|
||||
THROWIFFALSE( bytesToRead == bytesRead, L"Number of bytes doesn't match" );
|
||||
file._currentReadPosition += bytesRead;
|
||||
return bytesRead;
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(L"", &ex);
|
||||
}
|
||||
}
|
||||
|
||||
vfs::size_t vfs::CUncompressedLibraryBase::getReadPosition(tFileType *fileHandle)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _fileDataFromHandle(fileHandle)._currentReadPosition;
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(L"", &ex);
|
||||
}
|
||||
}
|
||||
|
||||
void vfs::CUncompressedLibraryBase::setReadPosition(tFileType *fileHandle, vfs::size_t positionInBytes)
|
||||
{
|
||||
try
|
||||
{
|
||||
SFileData& file = _fileDataFromHandle(fileHandle);
|
||||
THROWIFFALSE( positionInBytes < file._fileSize, L"" );
|
||||
|
||||
// uiCurrentReadPosition is offset to file-offset
|
||||
file._currentReadPosition = positionInBytes;
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(L"", &ex);
|
||||
}
|
||||
}
|
||||
|
||||
void vfs::CUncompressedLibraryBase::setReadPosition(tFileType *fileHandle, vfs::offset_t offsetInBytes, IBaseFile::ESeekDir seekDir)
|
||||
{
|
||||
try
|
||||
{
|
||||
SFileData& file = _fileDataFromHandle(fileHandle);
|
||||
|
||||
vfs::size_t pos = (vfs::size_t) (offsetInBytes < 0 ? -offsetInBytes : offsetInBytes);
|
||||
THROWIFFALSE( pos < file._fileSize, L"" );
|
||||
|
||||
if(seekDir == IBaseFile::SD_BEGIN)
|
||||
{
|
||||
THROWIFFALSE(offsetInBytes >= 0, L"");
|
||||
file._currentReadPosition = offsetInBytes;
|
||||
}
|
||||
else if(seekDir == IBaseFile::SD_CURRENT)
|
||||
{
|
||||
vfs::offset_t pos = file._currentReadPosition + offsetInBytes;
|
||||
THROWIFFALSE( (pos >= 0) && (pos <= (vfs::offset_t)file._fileSize), L"" );
|
||||
|
||||
file._currentReadPosition = (vfs::size_t) pos;
|
||||
}
|
||||
else if(seekDir == IBaseFile::SD_END)
|
||||
{
|
||||
THROWIFFALSE(offsetInBytes <= 0, L"");
|
||||
file._currentReadPosition = file._fileSize + offsetInBytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
THROWEXCEPTION(L"Unknown seek direction");
|
||||
}
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(L"", &ex);
|
||||
}
|
||||
}
|
||||
|
||||
vfs::size_t vfs::CUncompressedLibraryBase::getSize(tFileType *fileHandle)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _fileDataFromHandle(fileHandle)._fileSize;
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(L"", &ex);
|
||||
}
|
||||
}
|
||||
|
||||
void vfs::CUncompressedLibraryBase::getSubDirList(std::list<vfs::Path>& rlSubDirs)
|
||||
{
|
||||
tDirCatalogue::iterator it = m_dirs.begin();
|
||||
for(;it != m_dirs.end(); ++it)
|
||||
{
|
||||
rlSubDirs.push_back(it->first);
|
||||
}
|
||||
}
|
||||
|
||||
vfs::CUncompressedLibraryBase::Iterator vfs::CUncompressedLibraryBase::begin()
|
||||
{
|
||||
return Iterator(new IterImpl(*this));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
#ifndef _VFS_UNCOMPRESSED_LIB_BASE_H_
|
||||
#define _VFS_UNCOMPRESSED_LIB_BASE_H_
|
||||
|
||||
#include "../Interface/vfs_library_interface.h"
|
||||
#include "../Interface/vfs_directory_interface.h"
|
||||
#include <sstream>
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
|
||||
class VFS_API CUncompressedLibraryBase : public vfs::ILibrary
|
||||
{
|
||||
protected:
|
||||
typedef std::map<vfs::Path, vfs::TDirectory<vfs::ILibrary::tWriteType>*, vfs::Path::Less> tDirCatalogue;
|
||||
struct SFileData
|
||||
{
|
||||
SFileData(vfs::size_t const& fileSize, vfs::size_t const& fileOffset)
|
||||
: _fileSize(fileSize), _fileOffset(fileOffset), _currentReadPosition(0)
|
||||
{};
|
||||
vfs::size_t _fileSize, _fileOffset, _currentReadPosition;
|
||||
};
|
||||
typedef std::map<tFileType*, SFileData> tFileData;
|
||||
|
||||
class IterImpl;
|
||||
public:
|
||||
CUncompressedLibraryBase(vfs::tReadableFile *libraryFile, vfs::Path const& mountPoint, bool ownFile = false);
|
||||
virtual ~CUncompressedLibraryBase();
|
||||
|
||||
/**
|
||||
* TVFSLocation interface
|
||||
*/
|
||||
virtual bool fileExists(vfs::Path const& filename);
|
||||
virtual vfs::IBaseFile* getFile(vfs::Path const& filename);
|
||||
virtual tFileType* getFileTyped(vfs::Path const& filename);
|
||||
virtual void getSubDirList(std::list<vfs::Path>& rlSubDirs);
|
||||
|
||||
/**
|
||||
* ILibrary interface
|
||||
*/
|
||||
virtual bool init() = 0;
|
||||
virtual void closeLibrary();
|
||||
|
||||
virtual void close(tFileType *fileHandle);
|
||||
virtual bool openRead(tFileType *fileHandle);
|
||||
virtual vfs::size_t read(tFileType *fileHandle, vfs::Byte* data, vfs::size_t bytesToRead);
|
||||
|
||||
virtual vfs::size_t getReadPosition(tFileType *fileHandle);
|
||||
virtual void setReadPosition(tFileType *fileHandle, vfs::size_t positionInBytes);
|
||||
virtual void setReadPosition(tFileType *fileHandle, vfs::offset_t offsetInBytes, IBaseFile::ESeekDir seekDir);
|
||||
|
||||
virtual vfs::size_t getSize(tFileType *fileHandle);
|
||||
|
||||
virtual Iterator begin();
|
||||
protected:
|
||||
tDirCatalogue m_dirs;
|
||||
tFileData m_fileData;
|
||||
vfs::UInt32 m_numberOfOpenedFiles;
|
||||
private:
|
||||
SFileData& _fileDataFromHandle(tFileType* handle);
|
||||
};
|
||||
} // end namespace
|
||||
|
||||
#endif // _VFS_UNCOMPRESSED_LIB_BASE_H_
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
#include "HPTimer.h"
|
||||
|
||||
CHPTimer::CHPTimer()
|
||||
{
|
||||
#ifdef WIN32
|
||||
QueryPerformanceFrequency(&ticksPerSecond);
|
||||
#endif
|
||||
}
|
||||
|
||||
CHPTimer::~CHPTimer()
|
||||
{
|
||||
}
|
||||
|
||||
void CHPTimer::startTimer()
|
||||
{
|
||||
#ifdef WIN32
|
||||
QueryPerformanceCounter(&tick);
|
||||
#elif __linux__
|
||||
gettimeofday(&t1,0);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void CHPTimer::stopTimer()
|
||||
{
|
||||
#ifdef WIN32
|
||||
QueryPerformanceCounter(&tick2);
|
||||
#elif __linux__
|
||||
gettimeofday(&t2,0);
|
||||
#endif
|
||||
}
|
||||
|
||||
double CHPTimer::getElapsedTimeInSeconds()
|
||||
{
|
||||
#ifdef WIN32
|
||||
return (double)(tick2.QuadPart - tick.QuadPart)/(double)ticksPerSecond.QuadPart;
|
||||
#elif __linux__
|
||||
return (double)(t2.tv_usec - t1.tv_usec)/1000000.0;
|
||||
#endif
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
#ifndef _HPTIMER_
|
||||
#define _HPTIMER_
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
#elif __linux__
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
class CHPTimer
|
||||
{
|
||||
public:
|
||||
CHPTimer();
|
||||
~CHPTimer();
|
||||
|
||||
void startTimer();
|
||||
void stopTimer();
|
||||
|
||||
double getElapsedTimeInSeconds();
|
||||
protected:
|
||||
#ifdef WIN32
|
||||
LARGE_INTEGER ticksPerSecond;
|
||||
LARGE_INTEGER tick,tick2;
|
||||
#elif __linux__
|
||||
timeval t1,t2;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // _HPTIMER_
|
||||
@@ -1,147 +0,0 @@
|
||||
#define NOMINMAX
|
||||
#include "Prof.h"
|
||||
|
||||
#include "../vfs_types.h"
|
||||
#include "../File/vfs_file.h"
|
||||
#include <sstream>
|
||||
|
||||
class CProfileStarter
|
||||
{
|
||||
public:
|
||||
CProfileStarter()
|
||||
{
|
||||
CProf::getProf();
|
||||
}
|
||||
};
|
||||
static CProfileStarter starter;
|
||||
|
||||
CProf& CProf::getProf()
|
||||
{
|
||||
static CProf* _prof = new CProf;
|
||||
return *_prof;
|
||||
}
|
||||
|
||||
CProf::CProf()
|
||||
{
|
||||
m_vMarker.resize(1024);
|
||||
_nextMarker = 0;
|
||||
}
|
||||
|
||||
void CProf::clear()
|
||||
{
|
||||
for(unsigned int i = 0; i < _nextMarker; ++i)
|
||||
{
|
||||
m_vMarker[i].markername = "";
|
||||
m_vMarker[i].time = 0;
|
||||
m_vMarker[i].call_count = 0;
|
||||
m_vMarker[i].success_count = 0;
|
||||
m_vMarker[i].fail_count = 0;
|
||||
}
|
||||
_nextMarker = 0;
|
||||
}
|
||||
|
||||
|
||||
CProf::tMarkerID CProf::registerMarker(const char *marker)
|
||||
{
|
||||
m_vMarker[_nextMarker].markername = marker;
|
||||
return _nextMarker++;
|
||||
}
|
||||
|
||||
void CProf::startMarker(tMarkerID id)
|
||||
{
|
||||
m_vMarker[id].timer.startTimer();
|
||||
}
|
||||
|
||||
void CProf::stopMarker(tMarkerID id, bool success)
|
||||
{
|
||||
m_vMarker[id].timer.stopTimer();
|
||||
m_vMarker[id].time += m_vMarker[id].timer.getElapsedTimeInSeconds();
|
||||
m_vMarker[id].call_count++;
|
||||
if(success) m_vMarker[id].success_count++;
|
||||
else m_vMarker[id].fail_count++;
|
||||
}
|
||||
|
||||
inline std::string multChar(std::string::value_type c, unsigned int multiplicity)
|
||||
{
|
||||
std::string s;
|
||||
s.resize(multiplicity);
|
||||
for(unsigned int i=0; i<multiplicity; ++i)
|
||||
{
|
||||
s[i] = c;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
inline long double perCent(unsigned long value, unsigned long ref)
|
||||
{
|
||||
return 100.0 * ((double)(value)/double(ref));
|
||||
}
|
||||
|
||||
inline long double oneDigit(long double number)
|
||||
{
|
||||
unsigned long temp = (unsigned long)(number * 10);
|
||||
return (temp / 10.0);
|
||||
}
|
||||
|
||||
bool CProf::printProfilerState(vfs::Path const& file)
|
||||
{
|
||||
vfs::CFile oFile(file);
|
||||
if(!oFile.openWrite(true,true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// get largest value
|
||||
long double max_time = 0;
|
||||
std::string::size_type max_prefix = 0;
|
||||
for(unsigned int i=0; i<m_vMarker.size(); ++i)
|
||||
{
|
||||
if(m_vMarker[i].time > max_time)
|
||||
{
|
||||
max_time = m_vMarker[i].time;
|
||||
}
|
||||
std::string::size_type prefix_length = m_vMarker[i].markername.length();
|
||||
if(prefix_length > max_prefix)
|
||||
{
|
||||
max_prefix = prefix_length;
|
||||
}
|
||||
}
|
||||
const unsigned int WIDTH = 40;
|
||||
std::stringstream line;
|
||||
long double ld_success, ld_failure;
|
||||
for(unsigned int i=0; i<m_vMarker.size(); ++i)
|
||||
{
|
||||
if(m_vMarker[i].markername.empty())
|
||||
{
|
||||
break;
|
||||
}
|
||||
if(m_vMarker[i].markername.length() < WIDTH)
|
||||
{
|
||||
unsigned int space = WIDTH - m_vMarker[i].markername.length();
|
||||
line << m_vMarker[i].markername << multChar(' ',space) << " | ";
|
||||
}
|
||||
else
|
||||
{
|
||||
line << m_vMarker[i].markername.substr(0,WIDTH) << " | ";
|
||||
}
|
||||
if(max_time != 0)
|
||||
{
|
||||
unsigned int num_stars = (unsigned int)(WIDTH * (m_vMarker[i].time / max_time));
|
||||
ld_success = perCent(m_vMarker[i].success_count,m_vMarker[i].call_count);
|
||||
ld_failure = perCent(m_vMarker[i].fail_count,m_vMarker[i].call_count);
|
||||
line << "[" << oneDigit(ld_success) << "|" << oneDigit(ld_failure) << "] "
|
||||
<< multChar('*', num_stars) << multChar(' ', WIDTH - num_stars) << " | ";
|
||||
}
|
||||
line << "C: " << m_vMarker[i].call_count << ", T: " << m_vMarker[i].time << std::endl;
|
||||
//line << std::endl;
|
||||
}
|
||||
std::string useless_copy = line.str();
|
||||
oFile.write(useless_copy.c_str(), (vfs::size_t)(useless_copy.length()*sizeof(std::string::value_type)));
|
||||
oFile.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
void DumpProfileState(vfs::Path const& path)
|
||||
{
|
||||
CProf::getProf().printProfilerState(path);
|
||||
}
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
#ifndef _PROF_H_
|
||||
#define _PROF_H_
|
||||
|
||||
#include "HPTimer.h"
|
||||
#include "../vfs_types.h"
|
||||
#include "../vfs_path.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define DO_PROFILE 1
|
||||
#if DO_PROFILE
|
||||
#define REGISTERMARKER(id,name) static CProf::tMarkerID id = CProf::getProf().registerMarker(name)
|
||||
#define STARTMARKER(id) (CProf::getProf().startMarker(id))
|
||||
#define STOPMARKER(id,success) (CProf::getProf().stopMarker(id,success))
|
||||
|
||||
#define DUMPPROFILERSTATSTOFILE(file) CProf::getProf().printProfilerState(file)
|
||||
#else
|
||||
#define REGISTERMARKER(id,name)
|
||||
#define STARTMARKER(id)
|
||||
#define STOPMARKER(id,success)
|
||||
|
||||
#define DUMPPROFILERSTATSTOFILE(file)
|
||||
#endif
|
||||
|
||||
|
||||
class VFS_API CProf
|
||||
{
|
||||
public:
|
||||
typedef unsigned int tMarkerID;
|
||||
static CProf& getProf();
|
||||
|
||||
void clear();
|
||||
|
||||
tMarkerID registerMarker(const char *marker);
|
||||
|
||||
void startMarker(tMarkerID id);
|
||||
void stopMarker(tMarkerID id, bool success);
|
||||
|
||||
bool printProfilerState(vfs::Path const& file);
|
||||
private:
|
||||
CProf();
|
||||
|
||||
struct MARKER
|
||||
{
|
||||
MARKER() : call_count(0), success_count(0), fail_count(0), time(0.0) {};
|
||||
std::string markername;
|
||||
unsigned long call_count;
|
||||
unsigned long success_count;
|
||||
unsigned long fail_count;
|
||||
long double time;
|
||||
CHPTimer timer;
|
||||
};
|
||||
std::vector<MARKER> m_vMarker;
|
||||
unsigned int _nextMarker;
|
||||
};
|
||||
|
||||
class ProfileMarker
|
||||
{
|
||||
public:
|
||||
ProfileMarker(CProf::tMarkerID id, bool default_exit=true)
|
||||
: _id(id), _exit_success(default_exit)
|
||||
{
|
||||
STARTMARKER(_id);
|
||||
}
|
||||
~ProfileMarker()
|
||||
{
|
||||
STOPMARKER(_id,_exit_success);
|
||||
}
|
||||
void exit(bool success)
|
||||
{
|
||||
_exit_success = success;
|
||||
}
|
||||
private:
|
||||
CProf::tMarkerID _id;
|
||||
bool _exit_success;
|
||||
};
|
||||
|
||||
VFS_API void DumpProfileState(vfs::Path const& path);
|
||||
|
||||
#endif // _PROF_H_
|
||||
@@ -1,774 +0,0 @@
|
||||
#include "vfs_config.h"
|
||||
#include "PropertyContainer.h"
|
||||
|
||||
#include "vfs.h"
|
||||
#include "File/vfs_file.h"
|
||||
#include "File/vfs_memory_file.h"
|
||||
#include "vfs_file_raii.h"
|
||||
#include "os_functions.h"
|
||||
|
||||
#include "Tools/Tools.h"
|
||||
#include "Tools/ParserTools.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
/*************************************************************************************/
|
||||
/*************************************************************************************/
|
||||
|
||||
bool CPropertyContainer::CSection::has(utf8string const& key)
|
||||
{
|
||||
return mapProps.find(key) != mapProps.end();
|
||||
}
|
||||
|
||||
bool CPropertyContainer::CSection::add(utf8string const& key, utf8string const& value)
|
||||
{
|
||||
if(!mapProps[key].empty())
|
||||
{
|
||||
mapProps[key] += L", ";
|
||||
}
|
||||
mapProps[key] += value;
|
||||
return true;
|
||||
}
|
||||
|
||||
utf8string& CPropertyContainer::CSection::value(utf8string const& key)
|
||||
{
|
||||
return mapProps[key];
|
||||
}
|
||||
bool CPropertyContainer::CSection::value(utf8string const& key, utf8string& value)
|
||||
{
|
||||
tProps::iterator sit = mapProps.find(key);
|
||||
if(sit != mapProps.end())
|
||||
{
|
||||
value.r_wcs().assign(sit->second.c_wcs());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void CPropertyContainer::CSection::print(std::ostream& out, utf8string::str_t sPrefix)
|
||||
{
|
||||
tProps::iterator sit = mapProps.begin();
|
||||
for(; sit != mapProps.end(); ++sit)
|
||||
{
|
||||
out << utf8string::as_utf8(sPrefix) << sit->first.utf8() << " = " << sit->second.utf8() << "\r\n";
|
||||
}
|
||||
}
|
||||
|
||||
void CPropertyContainer::CSection::clear()
|
||||
{
|
||||
mapProps.clear();
|
||||
}
|
||||
|
||||
/*************************************************************************************/
|
||||
/*************************************************************************************/
|
||||
void CPropertyContainer::clearContainer()
|
||||
{
|
||||
tSections::iterator it = m_mapProps.begin();
|
||||
for(;it != m_mapProps.end(); ++it)
|
||||
{
|
||||
it->second.clear();
|
||||
}
|
||||
m_mapProps.clear();
|
||||
}
|
||||
|
||||
bool CPropertyContainer::extractSection(utf8string::str_t const& readStr, vfs::size_t startPos, utf8string::str_t& sSection)
|
||||
{
|
||||
// extract section name
|
||||
vfs::size_t close = readStr.find_first_of(L"]", startPos);
|
||||
if( close != vfs::npos && close > startPos)
|
||||
{
|
||||
startPos += 1;
|
||||
sSection = vfs::trimString(readStr,startPos,(vfs::size_t)(close-1));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CPropertyContainer::EOperation CPropertyContainer::extractKeyValue(utf8string::str_t const &readStr, vfs::size_t startPos, utf8string::str_t& sKey, utf8string::str_t& sValue)
|
||||
{
|
||||
vfs::size_t iEqual = readStr.find_first_of(L"+=", startPos);
|
||||
if(iEqual == vfs::npos)
|
||||
{
|
||||
//std::cout << "WARNING : could not extract key-value pair : " << readStr << std::endl;
|
||||
return CPropertyContainer::Error;
|
||||
}
|
||||
// extract key
|
||||
sKey = vfs::trimString(readStr,0,iEqual-1);
|
||||
// extract value
|
||||
EOperation op = CPropertyContainer::Set;
|
||||
if( readStr.at(iEqual) == L'+' )
|
||||
{
|
||||
if( (iEqual+1) < readStr.size() && (readStr.at(iEqual+1) == L'=') )
|
||||
{
|
||||
iEqual += 1;
|
||||
op = CPropertyContainer::Add;
|
||||
}
|
||||
}
|
||||
sValue = vfs::trimString(readStr,iEqual+1,readStr.size());
|
||||
return op;
|
||||
}
|
||||
|
||||
|
||||
bool CPropertyContainer::initFromIniFile(vfs::Path const& sFileName)
|
||||
{
|
||||
// try to open via VirtualFileSystem
|
||||
if(getVFS()->fileExists(sFileName))
|
||||
{
|
||||
return initFromIniFile(getVFS()->getReadFile(sFileName));
|
||||
}
|
||||
else
|
||||
{
|
||||
vfs::CFile file(sFileName);
|
||||
return initFromIniFile(vfs::tReadableFile::cast(&file));
|
||||
}
|
||||
}
|
||||
|
||||
bool CPropertyContainer::initFromIniFile(vfs::tReadableFile *pFile)
|
||||
{
|
||||
if(!pFile)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string sBuffer;
|
||||
utf8string::str_t sCurrentSection;
|
||||
int line_counter = 0;
|
||||
CReadLine rl(*pFile);
|
||||
while(rl.getLine(sBuffer))
|
||||
{
|
||||
line_counter++;
|
||||
// very simple parsing : key = value
|
||||
if(!sBuffer.empty())
|
||||
{
|
||||
// remove leading white spaces
|
||||
::size_t iStart = sBuffer.find_first_not_of(" \t",0);
|
||||
if(iStart == std::string::npos)
|
||||
{
|
||||
// only white space characters
|
||||
continue;
|
||||
}
|
||||
char first = sBuffer.at(iStart);
|
||||
switch(first)
|
||||
{
|
||||
case '!':
|
||||
case ';':
|
||||
case '#':
|
||||
// comment -> do nothing
|
||||
break;
|
||||
case '[':
|
||||
{
|
||||
utf8string u8s;
|
||||
try
|
||||
{
|
||||
utf8string::as_utf16(sBuffer.substr(iStart, sBuffer.length()-iStart), u8s.r_wcs());
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Conversion error in file \"" << pFile->getPath().c_wcs()
|
||||
<< L"\", line " << line_counter;
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
if(this->extractSection(u8s.c_wcs(), 0, sCurrentSection))
|
||||
{
|
||||
m_mapProps[sCurrentSection];
|
||||
}
|
||||
else
|
||||
{
|
||||
//std::cout << "WARNING : could not extract section name : " << sBuffer << std::endl;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
// probably key-value pair
|
||||
utf8string::str_t u8s;
|
||||
try
|
||||
{
|
||||
utf8string::as_utf16(sBuffer.substr(iStart, sBuffer.length()-iStart), u8s);
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Conversion error in file \"" << pFile->getPath().c_wcs()
|
||||
<< L"\", line " << line_counter;
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
utf8string::str_t sKey, sValue;
|
||||
EOperation op = this->extractKeyValue(u8s, 0, sKey, sValue);
|
||||
if(op != Error)
|
||||
{
|
||||
// add key-value pair to map
|
||||
if(m_mapProps.find(sCurrentSection) != m_mapProps.end())
|
||||
{
|
||||
if(op == Set)
|
||||
{
|
||||
this->section(sCurrentSection).value(sKey) = sValue;
|
||||
}
|
||||
else if(op == Add)
|
||||
{
|
||||
this->section(sCurrentSection).add(sKey, sValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//std::cout << "ERROR : could not find section ["<<sCurrentSection << "]in container" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}; // end switch
|
||||
} // end if (empty)
|
||||
} // end while(!eof)
|
||||
return true;
|
||||
}
|
||||
|
||||
static vfs::UByte utf8bom[3] = {0xef,0xbb,0xbf};
|
||||
|
||||
bool CPropertyContainer::writeToIniFile(vfs::Path const& sFilename, bool bCreateNew)
|
||||
{
|
||||
#ifdef WIN32
|
||||
const char ENDL[] = "\r\n";
|
||||
#else
|
||||
const char ENDL[] = "\n";
|
||||
#endif
|
||||
if(bCreateNew)
|
||||
{
|
||||
vfs::tWritableFile* file;
|
||||
bool delete_file = false;
|
||||
try
|
||||
{
|
||||
vfs::COpenWriteFile wfile(sFilename,true,true);
|
||||
file = &wfile.file();
|
||||
wfile.release();
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
logException(ex);
|
||||
// vfs not initialized?
|
||||
vfs::CFile* cfile = new vfs::CFile(sFilename);
|
||||
cfile->openWrite(true,true);
|
||||
file = vfs::tWritableFile::cast(cfile);
|
||||
delete_file = true;
|
||||
}
|
||||
tSections::iterator sit = m_mapProps.begin();
|
||||
std::stringstream ss;
|
||||
std::string str;
|
||||
ss << (char*)utf8bom;
|
||||
for(; sit != m_mapProps.end(); ++sit)
|
||||
{
|
||||
ss.str("");
|
||||
ss << "[" << sit->first.utf8() << "]" << ENDL;
|
||||
str = ss.str();
|
||||
file->write(str.c_str(), str.length());
|
||||
|
||||
ss.clear();
|
||||
ss.str("");
|
||||
CSection& section = sit->second;
|
||||
section.print(ss);
|
||||
ss << ENDL;
|
||||
str = ss.str();
|
||||
file->write(str.c_str(),str.length());
|
||||
}
|
||||
file->close();
|
||||
if(delete_file)
|
||||
{
|
||||
delete file;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// try to open via VirtualFileSystem
|
||||
vfs::tReadableFile *pFile = NULL;
|
||||
vfs::CMemoryFile rfile;
|
||||
if(getVFS()->fileExists(sFilename))
|
||||
{
|
||||
pFile = getVFS()->getReadFile(sFilename);
|
||||
rfile.copyToBuffer(*pFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
// file doesn't exist or VFS not initialized yet
|
||||
vfs::IBaseFile* pFile = new vfs::CFile(sFilename);
|
||||
if(pFile)
|
||||
{
|
||||
rfile.copyToBuffer(*vfs::tReadableFile::cast(pFile));
|
||||
delete pFile;
|
||||
}
|
||||
}
|
||||
std::stringstream outbuffer;
|
||||
|
||||
std::string sBuffer;
|
||||
utf8string::str_t sCurrentSection;
|
||||
|
||||
std::set<utf8string> setKeys;
|
||||
std::set<utf8string> setSections;
|
||||
tSections::iterator sit = m_mapProps.begin();
|
||||
for(; sit != m_mapProps.end(); ++sit)
|
||||
{
|
||||
setSections.insert(sit->first);
|
||||
}
|
||||
|
||||
CReadLine rl(*vfs::tReadableFile::cast(&rfile));
|
||||
outbuffer << (char*)(utf8bom);
|
||||
vfs::UInt32 line_counter = 0;
|
||||
while(rl.getLine(sBuffer))
|
||||
{
|
||||
line_counter++;
|
||||
if(!sBuffer.empty())
|
||||
{
|
||||
// remove leading white spaces
|
||||
::size_t iStart = sBuffer.find_first_not_of(" \t",0);
|
||||
char first = sBuffer.at(iStart);
|
||||
switch(first)
|
||||
{
|
||||
case '!':
|
||||
case ';':
|
||||
case '#':
|
||||
outbuffer << sBuffer << ENDL;
|
||||
break;
|
||||
case '[':
|
||||
{
|
||||
utf8string u8s;
|
||||
try
|
||||
{
|
||||
utf8string::as_utf16(sBuffer.substr(iStart, sBuffer.length()-iStart), u8s.r_wcs());
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Conversion error in file \"" << pFile->getPath().c_wcs()
|
||||
<< L"\", line " << line_counter;
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
utf8string::str_t oldSection = sCurrentSection;
|
||||
if(this->extractSection(u8s.c_wcs(), 0, sCurrentSection))
|
||||
{
|
||||
if(setSections.find(sCurrentSection) == setSections.end())
|
||||
{
|
||||
// section already handled ?!?!?!
|
||||
// just print duplicate version
|
||||
outbuffer << utf8string::as_utf8(sBuffer) << ENDL;
|
||||
break;
|
||||
}
|
||||
if(!setKeys.empty())
|
||||
{
|
||||
// there are new keys in the previous section
|
||||
CSection& oldsec = m_mapProps[oldSection];
|
||||
|
||||
std::set<utf8string>::iterator kit = setKeys.begin();
|
||||
for(; kit != setKeys.end(); ++kit)
|
||||
{
|
||||
outbuffer << utf8string::as_utf8(*kit) << " = " << utf8string::as_utf8(oldsec.value(*kit)) << ENDL;
|
||||
}
|
||||
// all remaining keys were written, clear set
|
||||
setKeys.clear();
|
||||
outbuffer << ENDL;
|
||||
}
|
||||
CSection& sec = m_mapProps[sCurrentSection];
|
||||
CSection::tProps::iterator it = sec.mapProps.begin();
|
||||
for(; it != sec.mapProps.end(); ++it)
|
||||
{
|
||||
setKeys.insert(it->first);
|
||||
}
|
||||
}
|
||||
outbuffer << utf8string::as_utf8(sBuffer) << ENDL;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
// probably key-value pair
|
||||
utf8string u8s;
|
||||
try
|
||||
{
|
||||
utf8string::as_utf16(sBuffer.substr(iStart, sBuffer.length()-iStart), u8s.r_wcs());
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Conversion error in file \"" << pFile->getPath().c_wcs()
|
||||
<< L"\", line " << line_counter;
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
utf8string::str_t sKey, sValue;
|
||||
if(this->extractKeyValue(u8s.c_wcs(), 0, sKey, sValue))
|
||||
{
|
||||
if(setKeys.find(sKey) != setKeys.end())
|
||||
{
|
||||
outbuffer << utf8string::as_utf8(sKey) << " = " << utf8string::as_utf8(m_mapProps[sCurrentSection].value(sKey)) << "\r\n";
|
||||
setKeys.erase(sKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
outbuffer << utf8string::as_utf8(sBuffer) << ENDL;
|
||||
}
|
||||
if(setKeys.empty())
|
||||
{
|
||||
setSections.erase(sCurrentSection);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}; // end switch
|
||||
}
|
||||
else
|
||||
{
|
||||
outbuffer << ENDL;
|
||||
}
|
||||
}
|
||||
if(!setKeys.empty())
|
||||
{
|
||||
CSection& sec = m_mapProps[sCurrentSection];
|
||||
std::set<utf8string>::iterator kit = setKeys.begin();
|
||||
for(; kit != setKeys.end(); ++kit)
|
||||
{
|
||||
outbuffer << utf8string::as_utf8(*kit) << " = " << utf8string::as_utf8(sec.value(*kit)) << ENDL;
|
||||
}
|
||||
setKeys.clear();
|
||||
if(setKeys.empty())
|
||||
{
|
||||
setSections.erase(sCurrentSection);
|
||||
}
|
||||
}
|
||||
std::set<utf8string>::iterator it = setSections.begin();
|
||||
for(; it != setSections.end(); ++it)
|
||||
{
|
||||
outbuffer << ENDL << "[" << utf8string::as_utf8(*it) << "]" << ENDL;
|
||||
std::stringstream ss;
|
||||
m_mapProps[*it].print(outbuffer);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
vfs::COpenWriteFile wfile(sFilename,true,true);
|
||||
wfile.file().write(outbuffer.str().c_str(),(vfs::size_t)outbuffer.str().length());
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
logException(ex);
|
||||
vfs::CFile file(sFilename);
|
||||
if(file.openWrite(true,true))
|
||||
{
|
||||
file.write(outbuffer.str().c_str(),(vfs::size_t)outbuffer.str().length());
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CPropertyContainer::printProperties()
|
||||
{
|
||||
tSections::iterator pit = m_mapProps.begin();
|
||||
for(;pit != m_mapProps.end(); ++pit)
|
||||
{
|
||||
std::cout << "[" << pit->first.utf8() << "]\n";
|
||||
pit->second.print(std::cout, L" ");
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CPropertyContainer::CSection& CPropertyContainer::section(utf8string const& sSection)
|
||||
{
|
||||
return m_mapProps[sSection];
|
||||
}
|
||||
|
||||
bool CPropertyContainer::getValueForKey(utf8string const& sSection, utf8string const& sKey, utf8string &sValue)
|
||||
{
|
||||
tSections::iterator pit = m_mapProps.find(vfs::trimString(sSection,0,(vfs::size_t)sSection.length()));
|
||||
if( pit != m_mapProps.end() )
|
||||
{
|
||||
return pit->second.value( vfs::trimString(sKey,0,(vfs::size_t)sKey.length()), sValue );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::hasProperty(utf8string const& sSection, utf8string const& sKey)
|
||||
{
|
||||
tSections::iterator pit = m_mapProps.find(vfs::trimString(sSection,0,(vfs::size_t)sSection.length()));
|
||||
if( pit != m_mapProps.end() )
|
||||
{
|
||||
return pit->second.has(vfs::trimString(sKey,0,sKey.length()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
utf8string const& CPropertyContainer::getStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string const& sDefaultValue)
|
||||
{
|
||||
CPropertyContainer::tSections::iterator sit = m_mapProps.find(sSection);
|
||||
if(sit != m_mapProps.end())
|
||||
{
|
||||
CPropertyContainer::CSection::tProps::iterator pit = sit->second.mapProps.find(sKey);
|
||||
if(pit != sit->second.mapProps.end())
|
||||
{
|
||||
return pit->second;
|
||||
}
|
||||
}
|
||||
return sDefaultValue;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::getStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string& sValue, utf8string const& sDefaultValue)
|
||||
{
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
sValue = sDefaultValue;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::getStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string::char_t* sValue, vfs::size_t len, utf8string const& sDefaultValue)
|
||||
{
|
||||
utf8string s;
|
||||
if(getValueForKey(sSection,sKey,s))
|
||||
{
|
||||
vfs::size_t l = std::min<vfs::size_t>(s.length(), len-1);
|
||||
wcsncpy(sValue,s.c_str(), l);
|
||||
sValue[l] = 0;
|
||||
return true;
|
||||
}
|
||||
vfs::size_t l = std::min<vfs::size_t>(sDefaultValue.length(), len-1);
|
||||
wcsncpy(sValue,sDefaultValue.c_str(), l);
|
||||
sValue[l] = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
vfs::Int64 CPropertyContainer::getIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 iDefaultValue, vfs::Int64 iMinValue, vfs::Int64 iMaxValue)
|
||||
{
|
||||
return std::min<vfs::Int64>(iMaxValue, std::max<vfs::Int64>(iMinValue, this->getIntProperty(sSection, sKey, iDefaultValue)));
|
||||
}
|
||||
|
||||
vfs::Int64 CPropertyContainer::getIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 iDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
vfs::Int64 iRetVal;
|
||||
if(convertTo<vfs::Int64>(sValue,iRetVal))
|
||||
{
|
||||
return iRetVal;
|
||||
}
|
||||
}
|
||||
return iDefaultValue;
|
||||
}
|
||||
|
||||
vfs::UInt64 CPropertyContainer::getUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 iDefaultValue, vfs::UInt64 iMinValue, vfs::UInt64 iMaxValue)
|
||||
{
|
||||
return std::min<vfs::UInt64>(iMaxValue, std::max<vfs::UInt64>(iMinValue, this->getIntProperty(sSection, sKey, iDefaultValue)));
|
||||
}
|
||||
|
||||
vfs::UInt64 CPropertyContainer::getUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 iDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
vfs::UInt64 iRetVal;
|
||||
if(convertTo<vfs::UInt64>(sValue,iRetVal))
|
||||
{
|
||||
return iRetVal;
|
||||
}
|
||||
}
|
||||
return iDefaultValue;
|
||||
}
|
||||
|
||||
double CPropertyContainer::getFloatProperty(utf8string const& sSection, utf8string const& sKey, double fDefaultValue, double fMinValue, double fMaxValue)
|
||||
{
|
||||
return std::min<double>(fMaxValue, std::max<double>(fMinValue, this->getFloatProperty(sSection, sKey, fDefaultValue)));
|
||||
}
|
||||
|
||||
double CPropertyContainer::getFloatProperty(utf8string const& sSection, utf8string const& sKey, double fDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
double fRetVal;
|
||||
if(convertTo<double>(sValue,fRetVal))
|
||||
{
|
||||
return fRetVal;
|
||||
}
|
||||
}
|
||||
return fDefaultValue;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::getBoolProperty(utf8string const& sSection, utf8string const& sKey, bool bDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
vfs::Int32 iRetVal;
|
||||
if( StrCmp::Equal(sValue,L"true") || ( convertTo<>(sValue,iRetVal) && (iRetVal != 0) ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if( StrCmp::Equal(sValue,"false") || ( convertTo<>(sValue,iRetVal) && (iRetVal == 0) ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// else return bDefaultValue
|
||||
}
|
||||
return bDefaultValue;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::getStringListProperty(utf8string const& sSection, utf8string const& sKey, std::list<utf8string> &lValueList, utf8string sDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
utf8string entry;
|
||||
CSplitStringList splitter(sValue);
|
||||
while(splitter.nextListEntry(entry))
|
||||
{
|
||||
lValueList.push_back(vfs::trimString(entry,0,entry.length()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::getIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::Int64> &lValueList, vfs::Int64 iDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
utf8string entry;
|
||||
CSplitStringList splitter(sValue);
|
||||
while(splitter.nextListEntry(entry))
|
||||
{
|
||||
vfs::Int64 iRetVal;
|
||||
if(convertTo<vfs::Int64>(entry,iRetVal))
|
||||
{
|
||||
lValueList.push_back(iRetVal);
|
||||
}
|
||||
else
|
||||
{
|
||||
lValueList.push_back(iDefaultValue);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::getUIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::UInt64> &lValueList, vfs::UInt64 iDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
utf8string entry;
|
||||
CSplitStringList splitter(sValue);
|
||||
while(splitter.nextListEntry(entry))
|
||||
{
|
||||
vfs::UInt64 iRetVal;
|
||||
if(convertTo<vfs::UInt64>(entry,iRetVal))
|
||||
{
|
||||
lValueList.push_back(iRetVal);
|
||||
}
|
||||
else
|
||||
{
|
||||
lValueList.push_back(iDefaultValue);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool CPropertyContainer::getFloatListProperty(utf8string const& sSection, utf8string const& sKey, std::list<double> &lValueList, double fDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
utf8string entry;
|
||||
CSplitStringList splitter(sValue);
|
||||
while(splitter.nextListEntry(entry))
|
||||
{
|
||||
double fRetVal;
|
||||
if(convertTo<double>(entry,fRetVal))
|
||||
{
|
||||
lValueList.push_back(fRetVal);
|
||||
}
|
||||
else
|
||||
{
|
||||
lValueList.push_back(fDefaultValue);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::getBoolListProperty(utf8string const& sSection, utf8string const& sKey, std::list<bool> &lValueList, bool bDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
utf8string entry;
|
||||
CSplitStringList splitter(sValue);
|
||||
while(splitter.nextListEntry(entry))
|
||||
{
|
||||
vfs::Int32 iRetVal;
|
||||
if( StrCmp::Equal(entry,L"true") || ( convertTo<>(entry,iRetVal) && (iRetVal != 0) ) )
|
||||
{
|
||||
lValueList.push_back(true);
|
||||
}
|
||||
else if( StrCmp::Equal(entry,L"false") || ( convertTo<>(entry,iRetVal) && (iRetVal == 0) ) )
|
||||
{
|
||||
lValueList.push_back(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
lValueList.push_back(bDefaultValue);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CPropertyContainer::setStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string const& sValue)
|
||||
{
|
||||
this->section(sSection).value(sKey) = sValue;
|
||||
}
|
||||
|
||||
void CPropertyContainer::setIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 const& iValue)
|
||||
{
|
||||
this->section(sSection).value(sKey) = toString<wchar_t,vfs::Int64>(iValue);
|
||||
}
|
||||
void CPropertyContainer::setUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 const& iValue)
|
||||
{
|
||||
this->section(sSection).value(sKey) = toString<wchar_t,vfs::UInt64>(iValue);
|
||||
}
|
||||
void CPropertyContainer::setFloatProperty(utf8string const& sSection, utf8string const& sKey, double const& fValue)
|
||||
{
|
||||
this->section(sSection).value(sKey) = toString<wchar_t,double>(fValue);
|
||||
}
|
||||
void CPropertyContainer::setBoolProperty(utf8string const& sSection, utf8string const& sKey, bool const& bValue)
|
||||
{
|
||||
this->section(sSection).value(sKey) = toString<wchar_t,bool>(bValue);
|
||||
}
|
||||
|
||||
void CPropertyContainer::setStringListProperty(utf8string const& sSection, utf8string const& sKey, std::list<utf8string> const& slValue)
|
||||
{
|
||||
this->section(sSection).value(sKey) = toStringList<utf8string>(slValue);
|
||||
}
|
||||
|
||||
void CPropertyContainer::setIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::Int64> const& ilValue)
|
||||
{
|
||||
this->section(sSection).value(sKey) = toStringList<vfs::Int64>(ilValue);
|
||||
}
|
||||
|
||||
void CPropertyContainer::setFloatListProperty(utf8string const& sSection, utf8string const& sKey, std::list<double> const& flValue)
|
||||
{
|
||||
this->section(sSection).value(sKey) = toStringList<double>(flValue);
|
||||
}
|
||||
|
||||
void CPropertyContainer::setBoolListProperty(utf8string const& sSection, utf8string const& sKey, std::list<bool> const& blValue)
|
||||
{
|
||||
this->section(sSection).value(sKey) = toStringList<bool>(blValue);
|
||||
}
|
||||
|
||||
/**************************************************************************************************/
|
||||
/**************************************************************************************************/
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
#ifndef _PROPERTY_CONTAINER_H_
|
||||
#define _PROPERTY_CONTAINER_H_
|
||||
|
||||
#include "vfs_types.h"
|
||||
#include "Interface/vfs_file_interface.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <set>
|
||||
|
||||
class VFS_API CPropertyContainer
|
||||
{
|
||||
public:
|
||||
class TagMap
|
||||
{
|
||||
typedef std::map<utf8string,utf8string> tTagMap;
|
||||
public:
|
||||
TagMap();
|
||||
utf8string const& container(utf8string::char_t* container = NULL);
|
||||
utf8string const& section(utf8string::char_t* section = NULL);
|
||||
utf8string const& sectionID(utf8string::char_t* section_id = NULL);
|
||||
utf8string const& key(utf8string::char_t* key = NULL);
|
||||
utf8string const& keyID(utf8string::char_t* key_id = NULL);
|
||||
private:
|
||||
tTagMap _map;
|
||||
};
|
||||
public:
|
||||
CPropertyContainer(){};
|
||||
~CPropertyContainer(){};
|
||||
|
||||
void clearContainer();
|
||||
|
||||
bool initFromIniFile(vfs::Path const& sFileName);
|
||||
bool initFromIniFile(vfs::tReadableFile *pFile);
|
||||
bool writeToIniFile(vfs::Path const& sFileName, bool bCreateNew = false);
|
||||
|
||||
bool initFromXMLFile(vfs::Path const& sFileName, TagMap& tagmap);
|
||||
bool writeToXMLFile(vfs::Path const& sFileName, TagMap& tagmap);
|
||||
|
||||
void printProperties();
|
||||
|
||||
bool hasProperty(utf8string const& sSection, utf8string const& sKey);
|
||||
//
|
||||
utf8string const& getStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string const& sDefaultValue=L"");
|
||||
bool getStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string& sValue, utf8string const& sDefaultValue=L"");
|
||||
bool getStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string::char_t* sValue, vfs::size_t len, utf8string const& sDefaultValue=L"");
|
||||
//
|
||||
vfs::Int64 getIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 iDefaultValue);
|
||||
vfs::Int64 getIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 iDefaultValue, vfs::Int64 iMinValue, vfs::Int64 iMaxValue);
|
||||
//
|
||||
vfs::UInt64 getUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 iDefaultValue);
|
||||
vfs::UInt64 getUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 iDefaultValue, vfs::UInt64 iMinValue, vfs::UInt64 iMaxValue);
|
||||
//
|
||||
double getFloatProperty(utf8string const& sSection, utf8string const& sKey, double fDefaultValue);
|
||||
double getFloatProperty(utf8string const& sSection, utf8string const& sKey, double fDefaultValue, double fMinValue, double fMaxValue);
|
||||
//
|
||||
bool getBoolProperty(utf8string const& sSection, utf8string const& sKey, bool bDefaultValue);
|
||||
//
|
||||
bool getStringListProperty(utf8string const& sSection, utf8string const& sKey, std::list<utf8string> &lValueList, utf8string sDefaultValue);
|
||||
bool getIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::Int64> &lValueList, vfs::Int64 iDefaultValue);
|
||||
bool getUIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::UInt64> &lValueList, vfs::UInt64 iDefaultValue);
|
||||
bool getFloatListProperty(utf8string const& sSection, utf8string const& sKey, std::list<double> &lValueList, double fDefaultValue);
|
||||
bool getBoolListProperty(utf8string const& sSection, utf8string const& sKey, std::list<bool> &lValueList, bool bDefaultValue);
|
||||
//
|
||||
void setStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string const& sValue);
|
||||
//
|
||||
void setIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 const& iValue);
|
||||
void setUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 const& iValue);
|
||||
void setFloatProperty(utf8string const& sSection, utf8string const& sKey, double const& fValue);
|
||||
void setBoolProperty(utf8string const& sSection, utf8string const& sKey, bool const& bValue);
|
||||
//
|
||||
void setStringListProperty(utf8string const& sSection, utf8string const& sKey, std::list<utf8string> const& slValue);
|
||||
void setIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::Int64> const& ilValue);
|
||||
void setUIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::UInt64> const& ilValue);
|
||||
void setFloatListProperty(utf8string const& sSection, utf8string const& sKey, std::list<double> const& flValue);
|
||||
void setBoolListProperty(utf8string const& sSection, utf8string const& sKey, std::list<bool> const& blValue);
|
||||
private:
|
||||
enum EOperation
|
||||
{
|
||||
Error, Set, Add,
|
||||
};
|
||||
bool extractSection(utf8string::str_t const& readStr, vfs::size_t startPos, utf8string::str_t& sSection);
|
||||
EOperation extractKeyValue(utf8string::str_t const &readStr, vfs::size_t startPos, utf8string::str_t& sKey, utf8string::str_t& sValue);
|
||||
private:
|
||||
class CSection
|
||||
{
|
||||
friend class CPropertyContainer;
|
||||
typedef std::map<utf8string,utf8string, utf8string::Less> tProps;
|
||||
public:
|
||||
bool has(utf8string const& key);
|
||||
bool add(utf8string const& key, utf8string const& value);
|
||||
bool value(utf8string const& key, utf8string& value);
|
||||
utf8string& value(utf8string const& key);
|
||||
void print(std::ostream& out, utf8string::str_t sPrefix = L"");
|
||||
void clear();
|
||||
private:
|
||||
tProps mapProps;
|
||||
};
|
||||
typedef std::map<utf8string, CSection, utf8string::Less> tSections;
|
||||
|
||||
bool getValueForKey(utf8string const& sSection, utf8string const& sKey, utf8string &sValue);
|
||||
|
||||
CSection& section(utf8string const& sSection);
|
||||
|
||||
tSections m_mapProps;
|
||||
};
|
||||
|
||||
#endif // _PROPERTY_CONTAINER_H_
|
||||
@@ -1,240 +0,0 @@
|
||||
#include "Log.h"
|
||||
#include <cstring>
|
||||
|
||||
#ifdef WIN32
|
||||
const char CLog::ENDL[] = "\r\n";
|
||||
#else
|
||||
const char CLog::ENDL[] = "\n";
|
||||
#endif
|
||||
|
||||
std::list<CLog*>& CLog::_logs()
|
||||
{
|
||||
static std::list<CLog*> logs;
|
||||
return logs;
|
||||
}
|
||||
|
||||
CLog* CLog::create(vfs::Path const& fileName, bool append, EFlushMode flushMode)
|
||||
{
|
||||
_logs().push_back(new CLog(fileName, append, flushMode));
|
||||
return _logs().back();
|
||||
}
|
||||
void CLog::flushFinally()
|
||||
{
|
||||
std::list<CLog*>::iterator it = _logs().begin();
|
||||
for(; it != _logs().end(); ++it)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
_logs().clear();
|
||||
}
|
||||
|
||||
void CLog::flushAll()
|
||||
{
|
||||
std::list<CLog*>::iterator it = _logs().begin();
|
||||
for(; it != _logs().end(); ++it)
|
||||
{
|
||||
(*it)->flush();
|
||||
(*it)->_file = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
utf8string CLog::_shared_id_str;
|
||||
|
||||
utf8string const& CLog::getSharedString()
|
||||
{
|
||||
return _shared_id_str;
|
||||
}
|
||||
|
||||
void CLog::setSharedString(utf8string const& str)
|
||||
{
|
||||
_shared_id_str = str;
|
||||
}
|
||||
|
||||
|
||||
CLog::CLog(vfs::Path const& fileName, bool append, EFlushMode flushMode)
|
||||
: _filename(fileName), _file(NULL), _own_file(false),
|
||||
_first_write(true), _flush_mode(flushMode), _append(append),
|
||||
_buffer_size(0), _buffer_test_size(512)
|
||||
{};
|
||||
|
||||
CLog::~CLog()
|
||||
{
|
||||
_test_flush(true);
|
||||
if(_file && _own_file)
|
||||
{
|
||||
delete _file;
|
||||
}
|
||||
}
|
||||
|
||||
CLog& CLog::operator<<(unsigned int const& t)
|
||||
{
|
||||
return pushNumber(t);
|
||||
}
|
||||
CLog& CLog::operator<<(unsigned short const& t)
|
||||
{
|
||||
return pushNumber(t);
|
||||
}
|
||||
CLog& CLog::operator<<(unsigned char const& t)
|
||||
{
|
||||
return pushNumber(t);
|
||||
}
|
||||
CLog& CLog::operator<<(int const& t)
|
||||
{
|
||||
return pushNumber(t);
|
||||
}
|
||||
CLog& CLog::operator<<(short const& t)
|
||||
{
|
||||
return pushNumber(t);
|
||||
}
|
||||
CLog& CLog::operator<<(char const& t)
|
||||
{
|
||||
return pushNumber(t);
|
||||
}
|
||||
CLog& CLog::operator<<(float const& t)
|
||||
{
|
||||
return pushNumber(t);
|
||||
}
|
||||
CLog& CLog::operator<<(double const& t)
|
||||
{
|
||||
return pushNumber(t);
|
||||
}
|
||||
|
||||
CLog& CLog::operator<<(const char* t)
|
||||
{
|
||||
_buffer << t;
|
||||
_buffer_size += strlen(t);
|
||||
_test_flush();
|
||||
return *this;
|
||||
}
|
||||
CLog& CLog::operator<<(const wchar_t* t)
|
||||
{
|
||||
std::string s = utf8string::as_utf8(t);
|
||||
_buffer << s;
|
||||
_buffer_size += s.length();
|
||||
_test_flush();
|
||||
return *this;
|
||||
}
|
||||
CLog& CLog::operator<<(std::string const& t)
|
||||
{
|
||||
_buffer << t;
|
||||
_buffer_size += t.length();
|
||||
_test_flush();
|
||||
return *this;
|
||||
}
|
||||
CLog& CLog::operator<<(std::wstring const& t)
|
||||
{
|
||||
std::string s = utf8string::as_utf8(t);
|
||||
_buffer << s;
|
||||
_buffer_size += s.length();
|
||||
_test_flush();
|
||||
return *this;
|
||||
}
|
||||
CLog& CLog::operator<<(utf8string const& t)
|
||||
{
|
||||
std::string s = t.utf8();
|
||||
_buffer << s;
|
||||
_buffer_size += s.length();
|
||||
_test_flush();
|
||||
return *this;
|
||||
}
|
||||
|
||||
CLog& CLog::endl()
|
||||
{
|
||||
_buffer << CLog::ENDL;
|
||||
_buffer_size += sizeof(CLog::ENDL)-1;
|
||||
_test_flush();
|
||||
return *this;
|
||||
}
|
||||
|
||||
void CLog::setAppend(bool append)
|
||||
{
|
||||
_append = append;
|
||||
}
|
||||
|
||||
void CLog::setBufferSize(vfs::UInt32 bufferSize)
|
||||
{
|
||||
_buffer_test_size = bufferSize;
|
||||
}
|
||||
|
||||
void CLog::_test_flush(bool force)
|
||||
{
|
||||
if( (_flush_mode == FLUSH_IMMEDIATELY) ||
|
||||
(_flush_mode == FLUSH_BUFFER && _buffer_size > _buffer_test_size) ||
|
||||
(/*_flush_mode == FLUSH_ON_DELETE &&*/ force == true) )
|
||||
{
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
#include <ctime>
|
||||
void CLog::flush()
|
||||
{
|
||||
::size_t buflen = _buffer.str().length();
|
||||
if(buflen == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(!_file)
|
||||
{
|
||||
try
|
||||
{
|
||||
vfs::COpenWriteFile file_raii(_filename,true,!_append);
|
||||
_file = &file_raii.file();
|
||||
file_raii.release();
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
logException(ex);
|
||||
// write file anyway
|
||||
_file = vfs::tWritableFile::cast(new vfs::CFile(_filename));
|
||||
_file->openWrite(true,!_append);
|
||||
_own_file = true;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vfs::COpenWriteFile wfile(_file);
|
||||
if(_append)
|
||||
{
|
||||
wfile.file().setWritePosition(0,vfs::IBaseFile::SD_END);
|
||||
}
|
||||
|
||||
if(_first_write)
|
||||
{
|
||||
time_t rawtime;
|
||||
time ( &rawtime );
|
||||
std::string datetime(ctime(&rawtime));
|
||||
std::string s_out;
|
||||
|
||||
vfs::size_t wloc = wfile.file().getWritePosition();
|
||||
if(wloc > 0)
|
||||
{
|
||||
s_out = CLog::ENDL;
|
||||
}
|
||||
s_out += " *** ";
|
||||
s_out += datetime.substr(0,datetime.length()-1);
|
||||
s_out += " *** ";
|
||||
s_out += CLog::ENDL;
|
||||
s_out += "[ ";
|
||||
s_out += _shared_id_str.utf8();
|
||||
s_out += " ]";
|
||||
s_out += CLog::ENDL;
|
||||
s_out += CLog::ENDL;
|
||||
|
||||
wfile.file().write(s_out.c_str(), s_out.length());
|
||||
_first_write = false;
|
||||
}
|
||||
|
||||
wfile.file().write(_buffer.str().c_str(), buflen);
|
||||
_buffer.str("");
|
||||
_buffer.clear();
|
||||
_buffer_size = 0;
|
||||
|
||||
_append = true;
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
#ifndef _LOG_H_
|
||||
#define _LOG_H_
|
||||
|
||||
#include "Tools.h"
|
||||
#include "../vfs_types.h"
|
||||
#include "../Interface/vfs_file_interface.h"
|
||||
#include "../File/vfs_file.h"
|
||||
#include "../vfs_file_raii.h"
|
||||
|
||||
class VFS_API CLog
|
||||
{
|
||||
public:
|
||||
enum EFlushMode
|
||||
{
|
||||
FLUSH_ON_DELETE,
|
||||
FLUSH_BUFFER,
|
||||
FLUSH_IMMEDIATELY,
|
||||
};
|
||||
public:
|
||||
|
||||
CLog(vfs::Path const& fileName, bool append = false, EFlushMode flushMode = FLUSH_ON_DELETE);
|
||||
~CLog();
|
||||
|
||||
static CLog* create(vfs::Path const& fileName, bool append = false, EFlushMode flushMode = FLUSH_ON_DELETE);
|
||||
static void flushAll();
|
||||
static void flushFinally();
|
||||
|
||||
static utf8string const& getSharedString();
|
||||
static void setSharedString(utf8string const& str);
|
||||
|
||||
CLog& operator<<(unsigned int const& t);
|
||||
CLog& operator<<(unsigned short const& t);
|
||||
CLog& operator<<(unsigned char const& t);
|
||||
CLog& operator<<(int const& t);
|
||||
CLog& operator<<(short const& t);
|
||||
CLog& operator<<(char const& t);
|
||||
CLog& operator<<(float const& t);
|
||||
CLog& operator<<(double const& t);
|
||||
|
||||
CLog& operator<<(const char* t);
|
||||
CLog& operator<<(const wchar_t* t);
|
||||
CLog& operator<<(std::string const& t);
|
||||
CLog& operator<<(std::wstring const& t);
|
||||
CLog& operator<<(utf8string const& t);
|
||||
|
||||
CLog& endl();
|
||||
static const char ENDL[];
|
||||
|
||||
void setAppend(bool append = true);
|
||||
void setBufferSize(vfs::UInt32 bufferSize);
|
||||
|
||||
void flush();
|
||||
private:
|
||||
void _test_flush(bool force=false);
|
||||
|
||||
template<typename T_>
|
||||
CLog& pushNumber(T_ const& t)
|
||||
{
|
||||
_buffer << toString<char>(t);
|
||||
_buffer_size += sizeof(T_);
|
||||
_test_flush();
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
vfs::Path _filename;
|
||||
vfs::tWritableFile* _file;
|
||||
bool _own_file;
|
||||
bool _first_write;
|
||||
EFlushMode _flush_mode;
|
||||
bool _append;
|
||||
::size_t _buffer_size, _buffer_test_size;
|
||||
std::stringstream _buffer;
|
||||
private:
|
||||
static std::list<CLog*>& _logs();
|
||||
static utf8string _shared_id_str;
|
||||
};
|
||||
|
||||
|
||||
#endif // _LOG_H_
|
||||
@@ -1,502 +0,0 @@
|
||||
#include "ParserTools.h"
|
||||
#include "Tools.h"
|
||||
#include "../vfs.h"
|
||||
#include "../File/vfs_file.h"
|
||||
#include "../vfs_file_raii.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
/*************************************************************************************/
|
||||
/*************************************************************************************/
|
||||
|
||||
CReadLine::CReadLine(vfs::tReadableFile& rFile)
|
||||
: _file(rFile), _buffer_pos(0), _eof(false)
|
||||
{
|
||||
memset(_buffer,0,sizeof(_buffer));
|
||||
|
||||
vfs::COpenReadFile rfile(&_file);
|
||||
_bytes_left = rfile.file().getSize();
|
||||
fillBuffer();
|
||||
vfs::UByte utf8bom[3] = {0xef,0xbb,0xbf};
|
||||
if(memcmp(utf8bom, &_buffer[0],3) == 0)
|
||||
{
|
||||
_buffer_pos += 3;
|
||||
}
|
||||
rfile.release();
|
||||
};
|
||||
|
||||
CReadLine::~CReadLine()
|
||||
{
|
||||
if(_file.isOpenRead())
|
||||
{
|
||||
_file.close();
|
||||
}
|
||||
}
|
||||
|
||||
bool CReadLine::fillBuffer()
|
||||
{
|
||||
if(_eof)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
vfs::size_t bytesRead = BUFFER_SIZE < _bytes_left ? BUFFER_SIZE : _bytes_left;
|
||||
try
|
||||
{
|
||||
vfs::COpenReadFile rfile(&_file);
|
||||
|
||||
// fill the buffer from the start, BUFFER_SIZE charactes at max (_buffer has BUFFER_SIZE+1 elements)
|
||||
THROWIFFALSE(bytesRead == _file.read(&_buffer[0], bytesRead), L"");
|
||||
rfile.release();
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(L"", &ex);
|
||||
}
|
||||
|
||||
_bytes_left -= bytesRead;
|
||||
_eof = (_bytes_left == 0);
|
||||
|
||||
|
||||
// bite-wise read files usually terminate a line with \n (or \r\n on WIN32)
|
||||
// line-wise read files just returns 0-terminated string
|
||||
|
||||
// always terminate the string with 0
|
||||
_buffer[bytesRead] = 0;
|
||||
|
||||
_buffer_pos = 0;
|
||||
_buffer_last = bytesRead;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CReadLine::fromBuffer(std::string& line)
|
||||
{
|
||||
bool done = false;
|
||||
while(!done)
|
||||
{
|
||||
if(_buffer_pos < _buffer_last)
|
||||
{
|
||||
// start where we left last time
|
||||
vfs::Byte *temp = &_buffer[_buffer_pos];
|
||||
vfs::size_t start_pos = _buffer_pos;
|
||||
// go until we hit 0. since our buffer is always 0 terminated, the second test should be redundant.
|
||||
while(*temp && (_buffer_pos < _buffer_last))
|
||||
{
|
||||
// stop when we find a line terminator
|
||||
if(*temp == '\n' || *temp == '\r' /* || *temp == '\0' */)
|
||||
{
|
||||
break;
|
||||
}
|
||||
temp++;
|
||||
_buffer_pos++;
|
||||
}
|
||||
// need to append substring, as we might have refilles the buffer (because there was no \n or \r\n terminator)
|
||||
line.append( (char*)&_buffer[start_pos], _buffer_pos - start_pos );
|
||||
|
||||
// if we reach the (real) end of the buffer (that always terminate with 0), this means
|
||||
// that there was no line terminator and that we have to refill the buffer.
|
||||
if( _buffer_pos < BUFFER_SIZE && (*temp == '\n' || *temp == '\r' || *temp == 0) )
|
||||
{
|
||||
// found the line terminator
|
||||
if(*temp == '\r')
|
||||
{
|
||||
// the \r is most probably followed by \n. 'swallow' both characters
|
||||
*temp++;
|
||||
_buffer_pos++;
|
||||
if( (_buffer_pos < BUFFER_SIZE) && (*temp == '\n' || *temp == 0) )
|
||||
{
|
||||
// increase buffer position, so that we can start with a valid character in the next run
|
||||
_buffer_pos++;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
done = !fillBuffer();
|
||||
}
|
||||
}
|
||||
else if(*temp == '\n' || *temp == 0)
|
||||
{
|
||||
// increase buffer position, so that we can start with a valid character in the next run
|
||||
_buffer_pos++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
done = !fillBuffer();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
done = !fillBuffer();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CReadLine::getLine(std::string& line)
|
||||
{
|
||||
line.clear();
|
||||
return fromBuffer(line);
|
||||
}
|
||||
|
||||
/*************************************************************************************/
|
||||
/*************************************************************************************/
|
||||
|
||||
CSplitStringList::CSplitStringList(utf8string const& sList)
|
||||
: m_list(sList), current(0), next(0)
|
||||
{};
|
||||
|
||||
CSplitStringList::~CSplitStringList()
|
||||
{};
|
||||
|
||||
bool CSplitStringList::nextListEntry(utf8string &sEntry)
|
||||
{
|
||||
if(next != utf8string::str_t::npos)
|
||||
{
|
||||
next = m_list.c_wcs().find_first_of(L",", current+1);
|
||||
if(next != utf8string::str_t::npos)
|
||||
{
|
||||
sEntry.r_wcs().assign(vfs::trimString(m_list,current,next-1).c_wcs());
|
||||
current = next+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// last or only entry
|
||||
sEntry.r_wcs().assign(vfs::trimString(m_list,current,m_list.length()).c_wcs());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*************************************************************************************/
|
||||
/*************************************************************************************/
|
||||
|
||||
CTransferRules::CTransferRules()
|
||||
: m_eDefaultAction(ACCEPT)
|
||||
{};
|
||||
|
||||
|
||||
bool CTransferRules::initFromTxtFile(vfs::Path const& sPath)
|
||||
{
|
||||
// try to open via VirtualFileSystem
|
||||
if(getVFS()->fileExists(sPath))
|
||||
{
|
||||
return initFromTxtFile(getVFS()->getReadFile(sPath));
|
||||
}
|
||||
else
|
||||
{
|
||||
// file doesn't exist or VFS not initialized yet
|
||||
vfs::IBaseFile* pFile = new vfs::CFile(sPath);
|
||||
if(pFile)
|
||||
{
|
||||
bool success = initFromTxtFile(vfs::tReadableFile::cast(pFile));
|
||||
delete pFile;
|
||||
return success;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CTransferRules::initFromTxtFile(vfs::tReadableFile* pFile)
|
||||
{
|
||||
if(pFile && pFile->openRead())
|
||||
{
|
||||
vfs::COpenReadFile rfile(pFile);
|
||||
std::string sBuffer;
|
||||
vfs::UInt32 line_counter = 0;
|
||||
CReadLine rl(*pFile);
|
||||
while(rl.getLine(sBuffer))
|
||||
{
|
||||
line_counter++;
|
||||
// very simple parsing : key = value
|
||||
if(!sBuffer.empty())
|
||||
{
|
||||
// remove leading white spaces
|
||||
::size_t iStart = sBuffer.find_first_not_of(" \t",0);
|
||||
char first = sBuffer.at(iStart);
|
||||
switch(first)
|
||||
{
|
||||
case '!':
|
||||
case ';':
|
||||
case '#':
|
||||
// comment -> do nothing
|
||||
break;
|
||||
default:
|
||||
::size_t iEnd = sBuffer.find_first_of(" \t", iStart);
|
||||
if(iEnd != std::string::npos)
|
||||
{
|
||||
SRule rule;
|
||||
std::string action = sBuffer.substr(iStart, iEnd - iStart);
|
||||
if( StrCmp::Equal(action, "deny") )
|
||||
{
|
||||
rule.action = CTransferRules::DENY;
|
||||
}
|
||||
else if( StrCmp::Equal(action, "accept") )
|
||||
{
|
||||
rule.action = CTransferRules::ACCEPT;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wstring trybuffer = L"Invalid UTF-8 character in string";
|
||||
IGNOREEXCEPTION( trybuffer = utf8string(sBuffer).c_wcs() ); /* just make sure we don't break off when string conversion fails */
|
||||
std::wstringstream wss;
|
||||
wss << L"Unknown action in file \"" << pFile->getPath().c_wcs()
|
||||
<< L", line " << line_counter << " : " << utf8string(sBuffer).c_wcs();
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
}
|
||||
try
|
||||
{
|
||||
rule.pattern = vfs::Path(vfs::trimString(sBuffer, iEnd, sBuffer.length()));
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Could not convert string, invalid utf8 encoding in file \"" << pFile->getPath().c_wcs()
|
||||
<< L"\", line " << line_counter;
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
m_listRules.push_back(rule);
|
||||
}
|
||||
break;
|
||||
}; // end switch
|
||||
} // end if (empty)
|
||||
} // end while(!eof)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CTransferRules::setDefaultAction(CTransferRules::EAction act)
|
||||
{
|
||||
m_eDefaultAction = act;
|
||||
}
|
||||
|
||||
CTransferRules::EAction CTransferRules::getDefaultAction()
|
||||
{
|
||||
return m_eDefaultAction;
|
||||
}
|
||||
|
||||
CTransferRules::EAction CTransferRules::applyRule(utf8string const& sStr)
|
||||
{
|
||||
tPatternList::iterator sit = m_listRules.begin();
|
||||
for(; sit != m_listRules.end(); ++sit)
|
||||
{
|
||||
if(matchPattern(sit->pattern(), sStr))
|
||||
{
|
||||
return sit->action;
|
||||
}
|
||||
}
|
||||
return m_eDefaultAction;
|
||||
}
|
||||
|
||||
/*************************************************************************************/
|
||||
/*************************************************************************************/
|
||||
|
||||
#ifdef USE_CODE_PAGE
|
||||
|
||||
typedef vfs::UInt16 UINT16;
|
||||
extern UINT16 gsKeyTranslationTable[1024];
|
||||
|
||||
CodePageReader::EMode CodePageReader::extractMode(std::string const &readStr, size_t startPos)
|
||||
{
|
||||
vfs::Int32 iEqual = readStr.find_first_of("=",startPos);
|
||||
if(iEqual < 0)
|
||||
{
|
||||
return Error;
|
||||
}
|
||||
// extract keyword
|
||||
std::string key = vfs::trimString(readStr,0,iEqual-1);
|
||||
if(!StrCmp::Equal(key, "mode"))
|
||||
{
|
||||
return Error;
|
||||
}
|
||||
// extract mode
|
||||
EMode mode = Error;
|
||||
std::string sMode = vfs::trimString(readStr,iEqual+1,readStr.size());
|
||||
if(StrCmp::Equal(sMode, "normal"))
|
||||
{
|
||||
mode = Normal;
|
||||
}
|
||||
else if(StrCmp::Equal(sMode, "shift"))
|
||||
{
|
||||
mode = Shift;
|
||||
}
|
||||
else if(StrCmp::Equal(sMode, "ctrl"))
|
||||
{
|
||||
mode = Ctrl;
|
||||
}
|
||||
else if(StrCmp::Equal(sMode, "alt"))
|
||||
{
|
||||
mode = Alt;
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
|
||||
bool CodePageReader::extractCode(std::string const& str, int iStart, vfs::UInt32& rInsertPoint, utf8string::str_t& u8s)
|
||||
{
|
||||
vfs::Int32 iEqual = str.find_first_of("=",iStart);
|
||||
if(iEqual < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// extract insert point
|
||||
std::string sip = vfs::TrimString(str,0,iEqual-1);
|
||||
if(!ConvertTo<vfs::UInt32>(sip, rInsertPoint))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
utf8string::str_t u8temp;
|
||||
IGNOREEXCEPTION(utf8string::as_utf16(str.substr(iEqual, str.length()-iEqual), u8temp));
|
||||
|
||||
vfs::Int32 iCodeStart, iCodeEnd;
|
||||
iCodeStart = u8temp.find_first_of(L"{", 0);
|
||||
if(iCodeStart < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
iCodeEnd = u8temp.find_last_of(L"}");
|
||||
if(iCodeEnd < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
u8s = u8temp.substr(iCodeStart+1, iCodeEnd-iCodeStart-1);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CodePageReader::readCodePage(vfs::Path const& codepagefile)
|
||||
{
|
||||
if(!GetVFS()->fileExists(codepagefile))
|
||||
{
|
||||
return;
|
||||
}
|
||||
vfs::COpenReadFile rfile(codepagefile);
|
||||
CReadLine rline(rfile.file());
|
||||
std::string sBuffer;
|
||||
vfs::UInt32 line_counter = 0;
|
||||
EMode mode = Normal;
|
||||
while(rline.GetLine(sBuffer))
|
||||
{
|
||||
line_counter++;
|
||||
// very simple parsing : key = value
|
||||
if(!sBuffer.empty())
|
||||
{
|
||||
// remove leading white spaces
|
||||
int iStart = sBuffer.find_first_not_of(" \t",0);
|
||||
char first = sBuffer.at(iStart);
|
||||
switch(first)
|
||||
{
|
||||
case '!':
|
||||
case ';':
|
||||
case '#':
|
||||
// comment -> do nothing
|
||||
break;
|
||||
case 'm':
|
||||
mode = ExtractMode(sBuffer,iStart);
|
||||
if(mode == Error)
|
||||
{
|
||||
utf8string::str_t u8s;
|
||||
IGNOREEXCEPTION(utf8string::as_utf16(sBuffer, u8s));
|
||||
std::wstringstream wss;
|
||||
wss << L"Could not determine mode from line [" << line_counter << L"] : " << u8s;
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
utf8string::str_t u8s;
|
||||
vfs::UInt32 uiInsertPoint;
|
||||
if(!ExtractCode(sBuffer, iStart,uiInsertPoint,u8s))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(mode == Shift) uiInsertPoint += 256;
|
||||
else if(mode == Ctrl) uiInsertPoint += 512;
|
||||
else if(mode == Alt) uiInsertPoint += 768;
|
||||
|
||||
if(uiInsertPoint >= 1023)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for(unsigned int i=0; i < u8s.length(); ++i)
|
||||
{
|
||||
if(uiInsertPoint+i < 1024)
|
||||
{
|
||||
gsKeyTranslationTable[uiInsertPoint+i] = u8s.at(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************/
|
||||
/*************************************************************************************/
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace charSet
|
||||
{
|
||||
static std::map<ECharSet,std::set<wchar_t> > _sets;
|
||||
};
|
||||
|
||||
inline bool testSet(int char_set, charSet::ECharSet es, wchar_t wc)
|
||||
{
|
||||
if(char_set & es)
|
||||
{
|
||||
std::set<wchar_t>& wcset = charSet::_sets[es];
|
||||
return wcset.find(wc) != wcset.end();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool charSet::isFromSet(char wc, unsigned int char_set)
|
||||
{
|
||||
return charSet::isFromSet((wchar_t)wc, char_set);
|
||||
}
|
||||
bool charSet::isFromSet(int wc, unsigned int char_set)
|
||||
{
|
||||
return charSet::IsFromSet((wchar_t)wc, char_set);
|
||||
}
|
||||
bool charSet::isFromSet(unsigned int wc, unsigned int char_set)
|
||||
{
|
||||
return charSet::IsFromSet((wchar_t)wc, char_set);
|
||||
}
|
||||
|
||||
bool charSet::isFromSet(wchar_t wc, unsigned int char_set)
|
||||
{
|
||||
bool inSet = false;
|
||||
if( inSet |= TestSet(char_set, charSet::CS_SPACE, wc)) return true;
|
||||
if( inSet |= TestSet(char_set, charSet::CS_ALPHA_LC, wc)) return true;
|
||||
if( inSet |= TestSet(char_set, charSet::CS_ALPHA_UC, wc)) return true;
|
||||
if( inSet |= TestSet(char_set, charSet::CS_NUMERIC, wc)) return true;
|
||||
if( inSet |= TestSet(char_set, charSet::CS_SPECIAL_ALPHA_LC, wc)) return true;
|
||||
if( inSet |= TestSet(char_set, charSet::CS_SPECIAL_ALPHA_UC, wc)) return true;
|
||||
if( inSet |= TestSet(char_set, charSet::CS_SPECIAL_NON_CHAR, wc)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void charSet::addToCharSet(ECharSet eset, std::wstring cset)
|
||||
{
|
||||
std::set<wchar_t>& wcset = charSet::_sets[eset];
|
||||
for(unsigned int i = 0; i < cset.length(); ++i)
|
||||
{
|
||||
wcset.insert(cset.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
void charSet::initializeCharSets()
|
||||
{
|
||||
charSet::AddToCharSet(charSet::CS_SPACE, L" ");
|
||||
charSet::AddToCharSet(charSet::CS_ALPHA_LC, L"abcdefghijklmnopqrstuvwxyz");
|
||||
charSet::AddToCharSet(charSet::CS_ALPHA_UC, L"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
charSet::AddToCharSet(charSet::CS_NUMERIC, L"0123456789");
|
||||
charSet::AddToCharSet(charSet::CS_SPECIAL_ALPHA_LC, L"äöüßáàâéèêóòôúùô");
|
||||
charSet::AddToCharSet(charSet::CS_SPECIAL_ALPHA_UC, L"ÄÖÜÁÀÂÉÈÊÓÒÔÚÙÛ");
|
||||
charSet::AddToCharSet(charSet::CS_SPECIAL_NON_CHAR, L"~*+-_.,:;'´`#°^!\"§$%&/()=?\\{}[]");
|
||||
}
|
||||
|
||||
#endif // USE_CODE_PAGE
|
||||
|
||||
/*************************************************************************************/
|
||||
/*************************************************************************************/
|
||||
@@ -1,130 +0,0 @@
|
||||
#ifndef _PARSER_TOOLS_H_
|
||||
#define _PARSER_TOOLS_H_
|
||||
|
||||
#include "../vfs_types.h"
|
||||
#include "../Interface/vfs_file_interface.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
/**************************************************************/
|
||||
/**************************************************************/
|
||||
const vfs::size_t BUFFER_SIZE = 1024;
|
||||
|
||||
class CReadLine
|
||||
{
|
||||
public:
|
||||
CReadLine(vfs::tReadableFile& rFile);
|
||||
~CReadLine();
|
||||
|
||||
bool fillBuffer();
|
||||
bool fromBuffer(std::string& line);
|
||||
bool getLine(std::string& line);
|
||||
private:
|
||||
vfs::Byte _buffer[BUFFER_SIZE+1];
|
||||
vfs::tReadableFile& _file;
|
||||
vfs::size_t _bytes_left;
|
||||
vfs::size_t _buffer_pos;
|
||||
vfs::size_t _buffer_last;
|
||||
bool _eof;
|
||||
|
||||
void operator=(CReadLine const& rl);
|
||||
};
|
||||
|
||||
/**************************************************************/
|
||||
/**************************************************************/
|
||||
|
||||
class CSplitStringList
|
||||
{
|
||||
public:
|
||||
CSplitStringList(utf8string const& sList);
|
||||
~CSplitStringList();
|
||||
|
||||
bool nextListEntry(utf8string &sEntry);
|
||||
private:
|
||||
const utf8string m_list;
|
||||
utf8string::size_t current,next;
|
||||
|
||||
void operator=(CSplitStringList const& strlist);
|
||||
};
|
||||
|
||||
|
||||
/**************************************************************/
|
||||
/**************************************************************/
|
||||
|
||||
class CTransferRules
|
||||
{
|
||||
public:
|
||||
enum EAction
|
||||
{
|
||||
DENY,
|
||||
ACCEPT,
|
||||
};
|
||||
public:
|
||||
CTransferRules();
|
||||
|
||||
bool initFromTxtFile(vfs::Path const& sPath);
|
||||
bool initFromTxtFile(vfs::tReadableFile* pFile);
|
||||
|
||||
void setDefaultAction(EAction act);
|
||||
EAction getDefaultAction();
|
||||
|
||||
EAction applyRule(utf8string const& sStr);
|
||||
private:
|
||||
struct SRule
|
||||
{
|
||||
EAction action;
|
||||
vfs::Path pattern;
|
||||
};
|
||||
typedef std::list<SRule> tPatternList;
|
||||
tPatternList m_listRules;
|
||||
EAction m_eDefaultAction;
|
||||
};
|
||||
|
||||
/**************************************************************/
|
||||
/**************************************************************/
|
||||
|
||||
//#define USE_CODE_PAGE
|
||||
|
||||
#ifdef USE_CODE_PAGE
|
||||
class CodePageReader
|
||||
{
|
||||
public:
|
||||
enum EMode
|
||||
{
|
||||
Error, Normal, Shift, Ctrl, Alt
|
||||
};
|
||||
void ReadCodePage(vfs::Path const& codepagefile);
|
||||
private:
|
||||
CodePageReader::EMode ExtractMode(std::string const &readStr, size_t startPos);
|
||||
bool ExtractCode(std::string const& str, int iStart, vfs::UInt32& rInsertPoint, utf8string::str_t& u8s);
|
||||
};
|
||||
|
||||
namespace charSet
|
||||
{
|
||||
enum ECharSet
|
||||
{
|
||||
CS_SPACE = 1,
|
||||
CS_ALPHA_LC = 2,
|
||||
CS_ALPHA_UC = 4,
|
||||
CS_ALPHA = CS_ALPHA_LC + CS_ALPHA_UC,
|
||||
CS_NUMERIC = 8,
|
||||
CS_ALPHA_NUM = CS_ALPHA + CS_NUMERIC,
|
||||
CS_SPECIAL_ALPHA_LC = 16,
|
||||
CS_SPECIAL_ALPHA_UC = 32,
|
||||
CS_SPECIAL_ALPHA = CS_SPECIAL_ALPHA_LC + CS_SPECIAL_ALPHA_UC,
|
||||
CS_SPECIAL_NON_CHAR = 65,
|
||||
};
|
||||
|
||||
bool IsFromSet(char wc, unsigned int char_set);
|
||||
bool IsFromSet(int wc, unsigned int char_set);
|
||||
bool IsFromSet(unsigned int wc, unsigned int char_set);
|
||||
bool IsFromSet(wchar_t wc, unsigned int char_set);
|
||||
|
||||
void AddToCharSet(ECharSet eset, std::wstring cset);
|
||||
|
||||
void InitializeCharSets();
|
||||
};
|
||||
#endif // USE_CODE_PAGE
|
||||
|
||||
#endif // _PARSER_TOOLS_H_
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
#include "Tools.h"
|
||||
|
||||
template<>
|
||||
utf8string toStringList<utf8string>(std::list<utf8string> const& rValList)
|
||||
{
|
||||
std::wstringstream ss;
|
||||
std::list<utf8string>::const_iterator cit = rValList.begin();
|
||||
if(cit != rValList.end())
|
||||
{
|
||||
ss << (*cit);
|
||||
cit++;
|
||||
for(;cit != rValList.end(); ++cit)
|
||||
{
|
||||
ss << L" , " << (*cit);
|
||||
}
|
||||
}
|
||||
if(!ss)
|
||||
{
|
||||
return L"";
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
#ifndef _TOOLS_H_
|
||||
#define _TOOLS_H_
|
||||
|
||||
#include "../utf8string.h"
|
||||
#include <list>
|
||||
|
||||
template<typename CharType, typename ValueType>
|
||||
std::basic_string<CharType> toString(ValueType const& rVal)
|
||||
{
|
||||
std::basic_stringstream<CharType> tss;
|
||||
if( !(tss << rVal))
|
||||
{
|
||||
return std::basic_string<CharType>();
|
||||
}
|
||||
return tss.str();
|
||||
}
|
||||
|
||||
template<typename T_>
|
||||
bool convertTo(utf8string const& sStr, T_ &rVal)
|
||||
{
|
||||
std::wstringstream ss;
|
||||
ss.str(sStr.c_wcs());
|
||||
if(!(ss >> rVal))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T_>
|
||||
utf8string toStringList(std::list<T_> const& rValList)
|
||||
{
|
||||
std::wstringstream ss;
|
||||
typename std::list<T_>::const_iterator cit = rValList.begin();
|
||||
if(cit != rValList.end())
|
||||
{
|
||||
ss << *cit;
|
||||
cit++;
|
||||
for(;cit != rValList.end(); ++cit)
|
||||
{
|
||||
ss << L" , " << *cit;
|
||||
}
|
||||
}
|
||||
if(!ss)
|
||||
{
|
||||
return L"";
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template<>
|
||||
utf8string toStringList<utf8string>(std::list<utf8string> const& rValList);
|
||||
|
||||
#endif // _TOOLS_H_
|
||||
@@ -1,641 +0,0 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9,00"
|
||||
Name="VFS"
|
||||
ProjectGUID="{C63466D6-49B5-4C54-AA0D-864F6171FD9B}"
|
||||
RootNamespace="Utils"
|
||||
Keyword="Win32Proj"
|
||||
TargetFrameworkVersion="196613"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="..\lib\VS2008\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2008\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
CharacterSet="0"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\ext\7z;..\ext\utf8\source"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;VFS_STATIC"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="..\lib\VS2008\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2008\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
CharacterSet="0"
|
||||
WholeProgramOptimization="0"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
AdditionalIncludeDirectories="..\ext\7z;..\ext\utf8\source"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;VFS_STATIC"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="false"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="true"
|
||||
DebugInformationFormat="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="MapEditorD|Win32"
|
||||
OutputDirectory="..\lib\VS2008\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2008\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
CharacterSet="0"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\ext\7z;..\ext\utf8\source"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;VFS_STATIC"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="MapEditor|Win32"
|
||||
OutputDirectory="..\lib\VS2008\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2008\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
CharacterSet="0"
|
||||
WholeProgramOptimization="0"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
AdditionalIncludeDirectories="..\ext\7z;..\ext\utf8\source"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;VFS_STATIC"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="false"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="true"
|
||||
DebugInformationFormat="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release_WithDebugInfo|Win32"
|
||||
OutputDirectory="..\lib\VS2008\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2008\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
CharacterSet="0"
|
||||
WholeProgramOptimization="0"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
EnableIntrinsicFunctions="true"
|
||||
AdditionalIncludeDirectories="..\ext\7z;..\ext\utf8\source"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;VFS_STATIC"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="false"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Interface"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Interface\vfs_directory_interface.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interface\vfs_file_interface.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interface\vfs_interface_members.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interface\vfs_iterator_interface.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interface\vfs_library_interface.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interface\vfs_location_aware_file_interface.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interface\vfs_location_interface.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Location"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_7z_library.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_7z_library.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_create_7z_library.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_create_7z_library.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_directory_tree.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_directory_tree.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_lib_dir.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_lib_dir.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_slf_library.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_slf_library.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_uncompressed_lib_base.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_uncompressed_lib_base.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="File"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\File\vfs_dir_file.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\File\vfs_dir_file.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\File\vfs_file.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\File\vfs_file.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\File\vfs_lib_file.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\File\vfs_lib_file.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\File\vfs_memory_file.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\File\vfs_memory_file.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Profiler"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Profiler\HPTimer.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Profiler\HPTimer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Profiler\Prof.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Profiler\Prof.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Tools"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Tools\Log.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Tools\Log.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Tools\ParserTools.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Tools\ParserTools.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Tools\Tools.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Tools\Tools.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="utfcpp"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\ext\utf8\source\utf8\checked.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\ext\utf8\source\utf8\core.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\ext\utf8\source\utf8\unchecked.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\ext\utf8\source\utf8.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\os_functions.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\os_functions.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\PropertyContainer.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\PropertyContainer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\utf8string.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\utf8string.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_config.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_debug.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_debug.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_file_raii.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_file_raii.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_init.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_init.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_path.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_path.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_profile.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_profile.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_settings.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_settings.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_types.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_types.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_vfile.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_vfile.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_vloc.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_vloc.h"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
@@ -1,166 +0,0 @@
|
||||
//
|
||||
// Snap: Implementation of the TReadDir class
|
||||
// This class reads the contents of a directory file-by-file
|
||||
//
|
||||
#include "iteratedir.h"
|
||||
#include "vfs_debug.h"
|
||||
#include <sstream>
|
||||
|
||||
#include "utf8string.h"
|
||||
|
||||
#ifndef WIN32
|
||||
int file_select(struct direct *entry)
|
||||
{
|
||||
/* if((strcmp(entry->d_name,".") == 0) || ( strcmp(entry->d_name,"..") == 0))
|
||||
{
|
||||
return (FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (TRUE);
|
||||
}*/
|
||||
return (TRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
extern bool g_VFS_NO_UNICODE;
|
||||
|
||||
os::CIterateDirectory::CIterateDirectory(vfs::Path const& sPath, utf8string const& searchPattern)
|
||||
{
|
||||
#ifdef WIN32
|
||||
if(g_VFS_NO_UNICODE)
|
||||
{
|
||||
std::string s;
|
||||
utf8string::narrow((sPath+searchPattern)().c_wcs(), s);
|
||||
fSearchHandle = FindFirstFileA(s.c_str(), &fFileInfoA);
|
||||
}
|
||||
else
|
||||
{
|
||||
fSearchHandle = FindFirstFileW((sPath+searchPattern)().c_wcs().c_str(), &fFileInfoW);
|
||||
}
|
||||
if (fSearchHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
std::wstringstream wss;
|
||||
wss << L"Error accessing path [" << (sPath+searchPattern)() << L"], error code : " << error;
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
}
|
||||
#else
|
||||
count = scandir(sPath().utf8().c_str(),&files,NULL,NULL);
|
||||
current_pos = 0;
|
||||
#endif
|
||||
fFirstRequest = true;
|
||||
}
|
||||
|
||||
os::CIterateDirectory::~CIterateDirectory()
|
||||
{
|
||||
#ifdef WIN32
|
||||
FindClose(fSearchHandle);
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
bool os::CIterateDirectory::NextFile(utf8string &fileName, CIterateDirectory::EFileAttribute &attrib)
|
||||
{
|
||||
#ifdef WIN32
|
||||
THROWIFFALSE(fSearchHandle != INVALID_HANDLE_VALUE, L"Invalid Handle Value");
|
||||
if (fFirstRequest)
|
||||
{
|
||||
fFirstRequest = false;
|
||||
}
|
||||
//else
|
||||
{
|
||||
if(g_VFS_NO_UNICODE)
|
||||
{
|
||||
if( !FindNextFileA(fSearchHandle, &fFileInfoA) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
fileName.r_wcs().assign( utf8string::widen( fFileInfoA.cFileName, strlen(fFileInfoA.cFileName) ) );
|
||||
attrib = (fFileInfoA.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? CIterateDirectory::FA_DIRECTORY : CIterateDirectory::FA_FILE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !FindNextFileW(fSearchHandle, &fFileInfoW) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
fileName.r_wcs().assign(fFileInfoW.cFileName);
|
||||
attrib = (fFileInfoW.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? CIterateDirectory::FA_DIRECTORY : CIterateDirectory::FA_FILE;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
if(current_pos < count)
|
||||
{
|
||||
struct dirent* entry = files[current_pos];
|
||||
fileName.assign(VfsString(entry->d_name)());
|
||||
attrib = (entry->d_type == DT_DIR) ? CIterateDir::FA_DIRECTORY : CIterateDir::FA_FILE;
|
||||
current_pos++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool os::CreateRealDirecory(vfs::Path& sDir, bool bDoNotCreate)
|
||||
{
|
||||
#if WIN32
|
||||
if(bDoNotCreate)
|
||||
{
|
||||
bool bDirExists = false;
|
||||
if(g_VFS_NO_UNICODE)
|
||||
{
|
||||
WIN32_FIND_DATAA fd;
|
||||
memset(&fd,0,sizeof(WIN32_FIND_DATAA));
|
||||
|
||||
std::string s;
|
||||
utf8string::narrow(sDir().c_wcs(), s);
|
||||
|
||||
HANDLE hFile = FindFirstFileA( s.c_str(), &fd);
|
||||
bDirExists = fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY;
|
||||
FindClose(hFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
WIN32_FIND_DATAW fd;
|
||||
memset(&fd,0,sizeof(WIN32_FIND_DATAW));
|
||||
HANDLE hFile = FindFirstFileW( sDir().c_wcs().c_str(), &fd);
|
||||
bDirExists = fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY;
|
||||
FindClose(hFile);
|
||||
}
|
||||
return bDirExists;
|
||||
}
|
||||
BOOL success;
|
||||
utf8string::str_t const& str = sDir().c_wcs();
|
||||
success = g_VFS_NO_UNICODE ?
|
||||
CreateDirectoryA( utf8string::narrow( str.c_str(), str.length() ).c_str(), NULL ) :
|
||||
CreateDirectoryW(sDir().c_wcs().c_str(),NULL);
|
||||
if(success == 0)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
if(error == ERROR_ALREADY_EXISTS)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
bool os::DeleteRealFile(vfs::Path &sDir)
|
||||
{
|
||||
#ifdef WIN32
|
||||
utf8string::str_t const& str = sDir().c_wcs();
|
||||
BOOL del = g_VFS_NO_UNICODE ?
|
||||
DeleteFileA( utf8string::narrow(str.c_str(), str.length()).c_str() ) :
|
||||
DeleteFileW( str.c_str() );
|
||||
return (del != FALSE);
|
||||
#else
|
||||
return (remove( sDir().utf8().c_str() ) == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
//
|
||||
// Snap: Declaration of the TReadDir class
|
||||
// This class reads the contents of a directory file-by-file
|
||||
//
|
||||
#ifndef _ITERATEDIR_H_
|
||||
#define _ITERATEDIR_H_
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/dir.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include "vfs_types.h"
|
||||
|
||||
namespace os
|
||||
{
|
||||
|
||||
class CIterateDirectory
|
||||
{
|
||||
public:
|
||||
enum EFileAttribute
|
||||
{
|
||||
FA_DIRECTORY,
|
||||
FA_FILE
|
||||
};
|
||||
public:
|
||||
CIterateDirectory(vfs::Path const& sPath, utf8string const& searchPattern);
|
||||
~CIterateDirectory();
|
||||
|
||||
bool NextFile(utf8string &fileName, CIterateDirectory::EFileAttribute &attrib);
|
||||
private:
|
||||
#ifdef WIN32
|
||||
HANDLE fSearchHandle;
|
||||
union
|
||||
{
|
||||
WIN32_FIND_DATAA fFileInfoA;
|
||||
WIN32_FIND_DATAW fFileInfoW;
|
||||
};
|
||||
#else
|
||||
struct direct **files;
|
||||
int count, current_pos;
|
||||
#endif
|
||||
bool fFirstRequest;
|
||||
};
|
||||
|
||||
bool CreateRealDirecory(vfs::Path &sDir, bool bDoNotCreate=false);
|
||||
|
||||
bool DeleteRealFile(vfs::Path &sDir);
|
||||
}; // end namespace
|
||||
|
||||
#endif // #ifndef _ITERATEDIR_H_
|
||||
|
||||
@@ -1,319 +0,0 @@
|
||||
#include "os_functions.h"
|
||||
#include "vfs_debug.h"
|
||||
#include <sstream>
|
||||
#include "Tools/Log.h"
|
||||
#include "utf8string.h"
|
||||
#include "vfs_settings.h"
|
||||
|
||||
#ifndef WIN32
|
||||
int file_select(struct direct *entry)
|
||||
{
|
||||
/* if((strcmp(entry->d_name,".") == 0) || ( strcmp(entry->d_name,"..") == 0))
|
||||
{
|
||||
return (FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (TRUE);
|
||||
}*/
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
os::CIterateDirectory::CIterateDirectory(vfs::Path const& sPath, utf8string const& searchPattern)
|
||||
{
|
||||
#ifdef WIN32
|
||||
if(!vfs::Settings::getUseUnicode())
|
||||
{
|
||||
std::string s;
|
||||
utf8string::narrow((sPath+searchPattern).c_wcs(), s);
|
||||
fSearchHandle = FindFirstFileA(s.c_str(), &fFileInfoA);
|
||||
}
|
||||
else
|
||||
{
|
||||
fSearchHandle = FindFirstFileW((sPath+searchPattern).c_wcs().c_str(), &fFileInfoW);
|
||||
}
|
||||
if (fSearchHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
std::wstringstream wss;
|
||||
wss << L"Error accessing path [" << (sPath+searchPattern)() << L"], error code : " << error;
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
}
|
||||
#else
|
||||
count = scandir(utf8string::as_utf8(sPath()).c_str(),&files,NULL,NULL);
|
||||
current_pos = 0;
|
||||
#endif
|
||||
fFirstRequest = true;
|
||||
}
|
||||
|
||||
os::CIterateDirectory::~CIterateDirectory()
|
||||
{
|
||||
#ifdef WIN32
|
||||
FindClose(fSearchHandle);
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
bool os::CIterateDirectory::nextFile(utf8string &fileName, CIterateDirectory::EFileAttribute &attrib)
|
||||
{
|
||||
#ifdef WIN32
|
||||
THROWIFFALSE(fSearchHandle != INVALID_HANDLE_VALUE, L"Invalid Handle Value");
|
||||
if (fFirstRequest)
|
||||
{
|
||||
fFirstRequest = false;
|
||||
}
|
||||
//else
|
||||
{
|
||||
if(!vfs::Settings::getUseUnicode())
|
||||
{
|
||||
if( !FindNextFileA(fSearchHandle, &fFileInfoA) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
fileName.r_wcs().assign( utf8string::widen( fFileInfoA.cFileName, strlen(fFileInfoA.cFileName) ) );
|
||||
attrib = (fFileInfoA.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? CIterateDirectory::FA_DIRECTORY : CIterateDirectory::FA_FILE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !FindNextFileW(fSearchHandle, &fFileInfoW) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
fileName.r_wcs().assign(fFileInfoW.cFileName);
|
||||
attrib = (fFileInfoW.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? CIterateDirectory::FA_DIRECTORY : CIterateDirectory::FA_FILE;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
if(current_pos < count)
|
||||
{
|
||||
struct dirent* entry = files[current_pos];
|
||||
fileName = utf8string(entry->d_name);
|
||||
attrib = (entry->d_type == DT_DIR) ? CIterateDirectory::FA_DIRECTORY : CIterateDirectory::FA_FILE;
|
||||
current_pos++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool os::createRealDirectory(vfs::Path const& sDir, bool bDoNotCreate)
|
||||
{
|
||||
#if WIN32
|
||||
if(bDoNotCreate)
|
||||
{
|
||||
bool bDirExists = false;
|
||||
if(!vfs::Settings::getUseUnicode())
|
||||
{
|
||||
WIN32_FIND_DATAA fd;
|
||||
memset(&fd,0,sizeof(WIN32_FIND_DATAA));
|
||||
|
||||
std::string s;
|
||||
utf8string::narrow(sDir.c_wcs(), s);
|
||||
|
||||
HANDLE hFile = FindFirstFileA( s.c_str(), &fd);
|
||||
if(hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
CLog log(L"errors.log", true);
|
||||
log << L"Directory [" << sDir() << L"] does not exist : " << (int)error << CLog::ENDL;
|
||||
}
|
||||
|
||||
// WANNE - MP: This should fix the missing sync folder event if it exists (by Frostregen)
|
||||
bDirExists = (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) > 0;
|
||||
//bDirExists = fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY;
|
||||
|
||||
FindClose(hFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
WIN32_FIND_DATAW fd;
|
||||
memset(&fd,0,sizeof(WIN32_FIND_DATAW));
|
||||
HANDLE hFile = FindFirstFileW( sDir.c_str(), &fd);
|
||||
if(hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
CLog log(L"errors.log", true);
|
||||
log << L"Directory [" << sDir() << L"] does not exist : " << (int)error << CLog::ENDL;
|
||||
}
|
||||
|
||||
// WANNE - MP: This should fix the missing sync folder event if it exists (by Frostregen)
|
||||
bDirExists = (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) > 0;
|
||||
//bDirExists = fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY;
|
||||
|
||||
FindClose(hFile);
|
||||
}
|
||||
return bDirExists;
|
||||
}
|
||||
BOOL success;
|
||||
utf8string::str_t const& str = sDir.c_wcs();
|
||||
success = vfs::Settings::getUseUnicode() ?
|
||||
CreateDirectoryW(sDir.c_str(),NULL) :
|
||||
CreateDirectoryA( utf8string::narrow( str.c_str(), str.length() ).c_str(), NULL );
|
||||
if(success == 0)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
if(error == ERROR_ALREADY_EXISTS)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
CLog log(L"errors.log", true);
|
||||
log << L"Could not create directory [" << sDir() << L"] : " << (int)error << CLog::ENDL;
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool os::FileAttributes::getFileAttributes(vfs::Path const& sDir, vfs::UInt32& uiAttribs)
|
||||
{
|
||||
#ifdef WIN32
|
||||
DWORD attribs = vfs::Settings::getUseUnicode() ?
|
||||
GetFileAttributesW(sDir.c_str()) :
|
||||
GetFileAttributesA(utf8string::narrow(sDir.c_str(), sDir.length()).c_str());
|
||||
|
||||
if(attribs == INVALID_FILE_ATTRIBUTES)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
CLog log(L"errors.log");
|
||||
log << L"Invalid File Attributes : " << (int)error << CLog::ENDL;
|
||||
return false;
|
||||
}
|
||||
|
||||
for(vfs::UInt32 attribMask = 0x80000000; attribMask > 0; attribMask >>= 1)
|
||||
{
|
||||
switch(attribs & attribMask)
|
||||
{
|
||||
case FILE_ATTRIBUTE_ARCHIVE:
|
||||
uiAttribs |= ATTRIB_ARCHIVE;
|
||||
break;
|
||||
case FILE_ATTRIBUTE_DIRECTORY:
|
||||
uiAttribs |= ATTRIB_DIRECTORY;
|
||||
break;
|
||||
case FILE_ATTRIBUTE_HIDDEN:
|
||||
uiAttribs |= ATTRIB_HIDDEN;
|
||||
break;
|
||||
case FILE_ATTRIBUTE_NORMAL:
|
||||
uiAttribs |= ATTRIB_NORMAL;
|
||||
break;
|
||||
case FILE_ATTRIBUTE_READONLY:
|
||||
uiAttribs |= ATTRIB_READONLY;
|
||||
break;
|
||||
case FILE_ATTRIBUTE_SYSTEM:
|
||||
uiAttribs |= ATTRIB_SYSTEM;
|
||||
break;
|
||||
case FILE_ATTRIBUTE_TEMPORARY:
|
||||
uiAttribs |= ATTRIB_TEMPORARY;
|
||||
break;
|
||||
case FILE_ATTRIBUTE_COMPRESSED:
|
||||
uiAttribs |= ATTRIB_COMPRESSED;
|
||||
break;
|
||||
case FILE_ATTRIBUTE_OFFLINE:
|
||||
uiAttribs |= ATTRIB_OFFLINE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool os::deleteRealFile(vfs::Path const& sDir)
|
||||
{
|
||||
#ifdef WIN32
|
||||
BOOL del = vfs::Settings::getUseUnicode() ?
|
||||
DeleteFileW( sDir.c_str() ) :
|
||||
DeleteFileA( utf8string::narrow(sDir.c_str(), sDir.length()).c_str() );
|
||||
return (del != FALSE);
|
||||
#else
|
||||
return (remove( utf8string::as_utf8(sDir()).c_str() ) == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void os::getExecutablePath(vfs::Path& sDir, vfs::Path& sFile)
|
||||
{
|
||||
#ifdef WIN32
|
||||
DWORD error;
|
||||
if(!vfs::Settings::getUseUnicode())
|
||||
{
|
||||
char path[256];
|
||||
if( 0 != (error = ::GetModuleFileNameA(NULL, path, 256)) )
|
||||
{
|
||||
vfs::Path(utf8string::widen(path,256)).splitLast(sDir, sFile);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t path[256];
|
||||
if( 0 != (error = ::GetModuleFileNameW(NULL, path, 256)) )
|
||||
{
|
||||
vfs::Path(path).splitLast(sDir, sFile);
|
||||
}
|
||||
}
|
||||
if(error == 0)
|
||||
{
|
||||
DWORD code = GetLastError();
|
||||
THROWEXCEPTION( BuildString().add(L"Could not get current directory [").add(
|
||||
(!vfs::Settings::getUseUnicode()) ? L"[no unicode]" : L"[unicode]").add(L"], error code : ").add(code).get());
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
void os::getCurrentDirectory(vfs::Path& sPath)
|
||||
{
|
||||
#ifdef WIN32
|
||||
DWORD error;
|
||||
vfs::Path path;
|
||||
if( !vfs::Settings::getUseUnicode() )
|
||||
{
|
||||
char path[256];
|
||||
if( 0 != (error = ::GetCurrentDirectoryA(256, path)) )
|
||||
{
|
||||
sPath = vfs::Path(utf8string::widen(path,256));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t path[256];
|
||||
if( 0 != (error = ::GetCurrentDirectoryW(256, path)) )
|
||||
{
|
||||
sPath = vfs::Path(path);
|
||||
}
|
||||
}
|
||||
if(error == 0)
|
||||
{
|
||||
DWORD code = GetLastError();
|
||||
THROWEXCEPTION(BuildString().add(L"Could not get current directory [").add(
|
||||
(!vfs::Settings::getUseUnicode()) ? L"[no unicode]" : L"[unicode]").add(L"], error code : ").add(code).get());
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
void os::setCurrectDirectory(vfs::Path const& sPath)
|
||||
{
|
||||
#ifdef WIN32
|
||||
if(!vfs::Settings::getUseUnicode())
|
||||
{
|
||||
std::string str;
|
||||
utf8string::narrow( sPath.c_wcs(), str );
|
||||
THROWIFFALSE( ::SetCurrentDirectoryA( str.c_str() ) == TRUE,
|
||||
BuildString().add(L"Could not set current directory [no unicode] : ").add(sPath).get() );
|
||||
}
|
||||
else
|
||||
{
|
||||
THROWIFFALSE( ::SetCurrentDirectoryW( sPath.c_str() ) == TRUE,
|
||||
BuildString().add(L"Could not set current directory [unicode] : ").add(sPath).get() );
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
#ifndef _OS_FUNCTIONS_H_
|
||||
#define _OS_FUNCTIONS_H_
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/dir.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include "vfs_config.h"
|
||||
#include "vfs_types.h"
|
||||
#include "vfs_path.h"
|
||||
|
||||
namespace os
|
||||
{
|
||||
|
||||
class CIterateDirectory
|
||||
{
|
||||
public:
|
||||
enum EFileAttribute
|
||||
{
|
||||
FA_DIRECTORY,
|
||||
FA_FILE
|
||||
};
|
||||
public:
|
||||
CIterateDirectory(vfs::Path const& sPath, utf8string const& searchPattern);
|
||||
~CIterateDirectory();
|
||||
|
||||
bool nextFile(utf8string &fileName, CIterateDirectory::EFileAttribute &attrib);
|
||||
private:
|
||||
#ifdef WIN32
|
||||
HANDLE fSearchHandle;
|
||||
union
|
||||
{
|
||||
WIN32_FIND_DATAA fFileInfoA;
|
||||
WIN32_FIND_DATAW fFileInfoW;
|
||||
};
|
||||
#else
|
||||
struct direct **files;
|
||||
int count, current_pos;
|
||||
#endif
|
||||
bool fFirstRequest;
|
||||
};
|
||||
|
||||
class FileAttributes
|
||||
{
|
||||
public:
|
||||
enum Attributes
|
||||
{
|
||||
ATTRIB_INVALID = 0,
|
||||
ATTRIB_ARCHIVE = 1,
|
||||
ATTRIB_DIRECTORY = 2,
|
||||
ATTRIB_HIDDEN = 4,
|
||||
ATTRIB_NORMAL = 8,
|
||||
ATTRIB_READONLY = 16,
|
||||
ATTRIB_SYSTEM = 32,
|
||||
ATTRIB_TEMPORARY = 64,
|
||||
ATTRIB_COMPRESSED = 128,
|
||||
ATTRIB_OFFLINE = 256,
|
||||
};
|
||||
bool getFileAttributes(vfs::Path const& sDir, vfs::UInt32& uiAttribs);
|
||||
};
|
||||
|
||||
|
||||
VFS_API bool createRealDirectory(vfs::Path const& sDir, bool bDoNotCreate=false);
|
||||
|
||||
bool deleteRealFile(vfs::Path const& sDir);
|
||||
|
||||
VFS_API void getExecutablePath(vfs::Path& sDir, vfs::Path& sFile);
|
||||
VFS_API void getCurrentDirectory(vfs::Path& sDir);
|
||||
VFS_API void setCurrectDirectory(vfs::Path const& sPath);
|
||||
|
||||
}; // end namespace
|
||||
|
||||
#endif // _OS_FUNCTIONS_H_
|
||||
|
||||
@@ -1,499 +0,0 @@
|
||||
#include "utf8string.h"
|
||||
#include "utf8.h"
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include "vfs_debug.h"
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace _StrCmp
|
||||
{
|
||||
////////////////////////////////////////////////////////////////
|
||||
inline void Advance( const char*& s1, const char*& s2 )
|
||||
{
|
||||
while (*s1 && *s2 && toupper(*s1) == toupper(*s2))
|
||||
{
|
||||
++s1;
|
||||
++s2;
|
||||
}
|
||||
}
|
||||
inline void Advance( const wchar_t*& s1, const wchar_t*& s2 )
|
||||
{
|
||||
// should be 'towupper'
|
||||
while (*s1 && *s2 && toupper(*s1) == toupper(*s2))
|
||||
{
|
||||
++s1;
|
||||
++s2;
|
||||
}
|
||||
}
|
||||
template<typename CharType>
|
||||
inline void AdvanceCase( const CharType*& s1, const CharType*& s2 )
|
||||
{
|
||||
while (*s1 && *s2 && (*s1 == *s2))
|
||||
{
|
||||
++s1;
|
||||
++s2;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////
|
||||
template<typename CharType>
|
||||
inline bool Equal( const CharType* s1, const CharType* s2 )
|
||||
{
|
||||
return !(*s1 || *s2);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////
|
||||
inline bool Less( const wchar_t* s1, const wchar_t* s2 )
|
||||
{
|
||||
if (!*s1) return *s2 != 0;
|
||||
if (!*s2) return false;
|
||||
// should be 'towupper'
|
||||
return toupper(*s1) < toupper(*s2);
|
||||
}
|
||||
inline bool Less( const char* s1, const char* s2 )
|
||||
{
|
||||
if (!*s1) return *s2 != 0;
|
||||
if (!*s2) return false;
|
||||
return toupper(*s1) < toupper(*s2);
|
||||
}
|
||||
template<typename CharType>
|
||||
inline bool LessCase( const CharType* s1, const CharType* s2 )
|
||||
{
|
||||
if (!*s1) return *s2 != 0;
|
||||
if (!*s2) return false;
|
||||
return (*s1) < (*s2);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool utf8string::lessCase(const utf8string::char_t* s1, const utf8string::char_t* s2)
|
||||
{
|
||||
_StrCmp::AdvanceCase(s1,s2);
|
||||
return _StrCmp::LessCase(s1,s2);
|
||||
|
||||
}
|
||||
|
||||
bool utf8string::less(const utf8string::char_t* s1, const utf8string::char_t* s2)
|
||||
{
|
||||
_StrCmp::Advance(s1,s2);
|
||||
return _StrCmp::Less(s1,s2);
|
||||
}
|
||||
|
||||
bool utf8string::equalCase(const utf8string::char_t* s1, const utf8string::char_t* s2)
|
||||
{
|
||||
_StrCmp::AdvanceCase(s1,s2);
|
||||
return _StrCmp::Equal(s1,s2);
|
||||
}
|
||||
|
||||
bool utf8string::equal(const utf8string::char_t* s1, const utf8string::char_t* s2)
|
||||
{
|
||||
_StrCmp::Advance(s1,s2);
|
||||
return _StrCmp::Equal(s1,s2);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
/// class constructors
|
||||
////////////////////////////////////////////////////////////////////
|
||||
utf8string::utf8string()
|
||||
{
|
||||
}
|
||||
utf8string::utf8string(const char* str)
|
||||
{
|
||||
utf8string::as_utf16(str,_str);
|
||||
}
|
||||
utf8string::utf8string(std::string const& str)
|
||||
{
|
||||
utf8string::as_utf16(str,_str);
|
||||
}
|
||||
utf8string::utf8string(const wchar_t* str)
|
||||
{
|
||||
_str.assign(str);
|
||||
}
|
||||
utf8string::utf8string(std::wstring const& str)
|
||||
{
|
||||
_str.assign(str);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
/// static class methods
|
||||
////////////////////////////////////////////////////////////////////
|
||||
utf8string::str_t utf8string::as_utf16(std::string const& str)
|
||||
{
|
||||
utf8string::str_t s;
|
||||
utf8string::as_utf16(str, s);
|
||||
return s;
|
||||
}
|
||||
void utf8string::as_utf16(std::string const& str, utf8string::str_t &str16)
|
||||
{
|
||||
try
|
||||
{
|
||||
::size_t d = utf8::distance(str.begin(), str.end());
|
||||
str16.resize(d);
|
||||
utf8::utf8to16(str.begin(), str.end(), &str16[0]);
|
||||
}
|
||||
catch(utf8::invalid_utf8& ex)
|
||||
{
|
||||
utf8::uint8_t c = ex.utf8_octet();
|
||||
THROWEXCEPTION(BuildString().add(L"Invalid UTF8 character '").add((wchar_t)c).add(L"'=").add((unsigned char)c).get());
|
||||
}
|
||||
catch(utf8::not_enough_room &ex)
|
||||
{
|
||||
std::wstring err;
|
||||
IGNOREEXCEPTION(utf8string::as_utf16(ex.what(),err));
|
||||
THROWEXCEPTION(BuildString().add(L"Incomplete UTF8 string [").add(err).add(L"]").get());
|
||||
}
|
||||
}
|
||||
|
||||
utf8string::str_t utf8string::as_utf16(const char* str)
|
||||
{
|
||||
utf8string::str_t s;
|
||||
utf8string::as_utf16(str, s);
|
||||
return s;
|
||||
}
|
||||
void utf8string::as_utf16(const char* str, utf8string::str_t &str16)
|
||||
{
|
||||
if(str == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
::size_t len = strlen(str);
|
||||
::size_t d = utf8::distance(str,str+len);
|
||||
str16.resize(d);
|
||||
utf8::utf8to16(str, str+len, &str16[0]);
|
||||
}
|
||||
catch(utf8::invalid_utf8& ex)
|
||||
{
|
||||
utf8::uint8_t c = ex.utf8_octet();
|
||||
THROWEXCEPTION(BuildString().add(L"Invalid UTF8 character '").add((wchar_t)c).add(L"'=").add((unsigned char)c).get());
|
||||
}
|
||||
catch(utf8::not_enough_room &ex)
|
||||
{
|
||||
std::wstring err;
|
||||
IGNOREEXCEPTION(utf8string::as_utf16(ex.what(), err));
|
||||
THROWEXCEPTION(BuildString().add(L"Incomplete UTF8 string [").add(err).add(L"]").get());
|
||||
}
|
||||
}
|
||||
|
||||
std::string utf8string::as_utf8(utf8string const& str)
|
||||
{
|
||||
return str.utf8();
|
||||
}
|
||||
std::string utf8string::as_utf8(std::wstring const& str)
|
||||
{
|
||||
if(str.empty())
|
||||
{
|
||||
return "";
|
||||
}
|
||||
#if 0
|
||||
std::string s;
|
||||
utf8::utf16to8(str.begin(), str.end(), std::back_inserter(s));
|
||||
#else
|
||||
static std::vector<char> buffer;
|
||||
buffer.resize(std::max< ::size_t>(buffer.size(), str.length()*3));
|
||||
char* end = utf8::utf16to8(str.begin(), str.end(), &buffer[0]);
|
||||
std::string s(&buffer[0],end);
|
||||
#endif
|
||||
return s;
|
||||
}
|
||||
|
||||
// if 'strlength' is 0, length is determined automatically
|
||||
std::string utf8string::as_utf8(const wchar_t* str, utf8string::size_t strlength)
|
||||
{
|
||||
std::string s;
|
||||
if(str != NULL)
|
||||
{
|
||||
::size_t len = strlength;
|
||||
if(len == 0)
|
||||
{
|
||||
len = wcslen(str);
|
||||
}
|
||||
if(len != 0)
|
||||
{
|
||||
utf8::utf16to8(str,str+len,std::back_inserter(s));
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// convenience method, for the case it should be used in generic code (overloading)
|
||||
std::string utf8string::as_utf8(std::string const& str)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
utf8string::size_t utf8string::narrow(std::wstring const& src, std::string& dst)
|
||||
{
|
||||
utf8string::size_t len = utf8string::narrow(src.c_str(),src.length(),NULL,0);
|
||||
dst.resize(len);
|
||||
return utf8string::narrow(src.c_str(),src.length(),&dst[0],len);
|
||||
}
|
||||
std::string utf8string::narrow(wchar_t const* str, utf8string::size_t length)
|
||||
{
|
||||
utf8string::size_t len = utf8string::narrow(str,length,NULL,0);
|
||||
std::string s;
|
||||
s.resize(len);
|
||||
utf8string::narrow(str,length,&s[0],len);
|
||||
return s;
|
||||
}
|
||||
utf8string::size_t utf8string::narrow(wchar_t const* src_str, utf8string::size_t src_len, char* dst_str, utf8string::size_t dst_len)
|
||||
{
|
||||
if(src_str && src_len>0)
|
||||
{
|
||||
if(!dst_str || dst_len==0)
|
||||
{
|
||||
return wcstombs(NULL, src_str, src_len);
|
||||
}
|
||||
return wcstombs(dst_str, src_str, std::min<utf8string::size_t>(src_len,dst_len));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
//
|
||||
std::wstring utf8string::widen(char const* str, utf8string::size_t length)
|
||||
{
|
||||
utf8string::size_t len = utf8string::widen(str,length,NULL,0);
|
||||
std::wstring ws;
|
||||
ws.resize(len);
|
||||
utf8string::widen(str,length,&ws[0],len);
|
||||
return ws;
|
||||
}
|
||||
utf8string::size_t utf8string::widen(std::string const& src, std::wstring& dst)
|
||||
{
|
||||
utf8string::size_t len = utf8string::widen(src.c_str(),src.length(),NULL,0);
|
||||
dst.resize(len);
|
||||
return utf8string::widen(src.c_str(),src.length(),&dst[0],len);
|
||||
}
|
||||
utf8string::size_t utf8string::widen(char const* src_str, size_t src_len, wchar_t* dst_str, size_t dst_len)
|
||||
{
|
||||
if(src_str && src_len>0)
|
||||
{
|
||||
if(!dst_str || dst_len==0)
|
||||
{
|
||||
return mbstowcs(NULL, src_str, src_len);
|
||||
}
|
||||
return mbstowcs(dst_str, src_str, std::min<size_t>(src_len,dst_len));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool utf8string::empty() const
|
||||
{
|
||||
return _str.empty();
|
||||
}
|
||||
utf8string::size_t utf8string::length() const
|
||||
{
|
||||
return _str.length();
|
||||
}
|
||||
|
||||
utf8string utf8string::operator+(utf8string const& str)
|
||||
{
|
||||
return utf8string(_str + str._str);
|
||||
}
|
||||
utf8string utf8string::operator+=(utf8string const& str)
|
||||
{
|
||||
_str += str._str;
|
||||
return utf8string(_str);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
bool operator<(utf8string const& s1, utf8string const& s2)
|
||||
{
|
||||
return s1._str < s2._str;
|
||||
}
|
||||
|
||||
std::wstringstream& operator<<(std::wstringstream& out, utf8string const& str)
|
||||
{
|
||||
out.write(str.c_str(), (std::streamsize)str.length());
|
||||
return out;
|
||||
}
|
||||
|
||||
std::wstringstream& operator<<(std::wstringstream& out, utf8string::str_t const& str)
|
||||
{
|
||||
out.write(str.c_str(), (std::streamsize)str.length());
|
||||
return out;
|
||||
}
|
||||
|
||||
std::wstringstream& operator<<(std::wstringstream& out, const utf8string::char_t* str)
|
||||
{
|
||||
out.write(str, (std::streamsize)wcslen(str));
|
||||
return out;
|
||||
}
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
// case IN-sensitive
|
||||
bool StrCmp::Equal(const char* s1, const char* s2)
|
||||
{
|
||||
_StrCmp::Advance(s1,s2);
|
||||
return _StrCmp::Equal(s1,s2);
|
||||
}
|
||||
bool StrCmp::Equal(std::string const& s1, std::string const& s2)
|
||||
{
|
||||
const char* p1 = s1.c_str();
|
||||
const char* p2 = s2.c_str();
|
||||
_StrCmp::Advance(p1,p2);
|
||||
return _StrCmp::Equal(p1,p2);
|
||||
}
|
||||
bool StrCmp::Equal(std::string const& s1, const char* s2)
|
||||
{
|
||||
const char* p1 = s1.c_str();
|
||||
_StrCmp::Advance(p1,s2);
|
||||
return _StrCmp::Equal(p1,s2);
|
||||
}
|
||||
bool StrCmp::Equal(const char* s1, std::string const& s2)
|
||||
{
|
||||
const char* p2 = s2.c_str();
|
||||
_StrCmp::Advance(s1,p2);
|
||||
return _StrCmp::Equal(s1,p2);
|
||||
}
|
||||
//
|
||||
bool StrCmp::Equal(const wchar_t* s1, const wchar_t* s2)
|
||||
{
|
||||
_StrCmp::Advance(s1,s2);
|
||||
return _StrCmp::Equal(s1,s2);
|
||||
}
|
||||
bool StrCmp::Equal(std::wstring const& s1, std::wstring const& s2)
|
||||
{
|
||||
const wchar_t* p1 = s1.c_str();
|
||||
const wchar_t* p2 = s2.c_str();
|
||||
_StrCmp::Advance(p1,p2);
|
||||
return _StrCmp::Equal(p1,p2);
|
||||
}
|
||||
bool StrCmp::Equal(std::wstring const& s1, const wchar_t* s2)
|
||||
{
|
||||
const wchar_t* p1 = s1.c_str();
|
||||
_StrCmp::Advance(p1,s2);
|
||||
return _StrCmp::Equal(p1,s2);
|
||||
}
|
||||
bool StrCmp::Equal(const wchar_t* s1, std::wstring const& s2)
|
||||
{
|
||||
const wchar_t* p2 = s2.c_str();
|
||||
_StrCmp::Advance(s1,p2);
|
||||
return _StrCmp::Equal(s1,p2);
|
||||
}
|
||||
//
|
||||
bool StrCmp::Equal(utf8string const& s1, utf8string const& s2)
|
||||
{
|
||||
const wchar_t* p1 = s1.c_str();
|
||||
const wchar_t* p2 = s2.c_str();
|
||||
_StrCmp::Advance(p1,p2);
|
||||
return _StrCmp::Equal(p1,p2);
|
||||
}
|
||||
bool StrCmp::Equal(utf8string const& s1, std::wstring const& s2)
|
||||
{
|
||||
const wchar_t* p1 = s1.c_str();
|
||||
const wchar_t* p2 = s2.c_str();
|
||||
_StrCmp::Advance(p1,p2);
|
||||
return _StrCmp::Equal(p1,p2);
|
||||
}
|
||||
bool StrCmp::Equal(std::wstring const& s1, utf8string const& s2)
|
||||
{
|
||||
const wchar_t* p1 = s1.c_str();
|
||||
const wchar_t* p2 = s2.c_str();
|
||||
_StrCmp::Advance(p1,p2);
|
||||
return _StrCmp::Equal(p1,p2);
|
||||
}
|
||||
bool StrCmp::Equal(utf8string const& s1, const wchar_t* s2)
|
||||
{
|
||||
const wchar_t* p1 = s1.c_str();
|
||||
_StrCmp::Advance(p1,s2);
|
||||
return _StrCmp::Equal(p1,s2);
|
||||
}
|
||||
bool StrCmp::Equal(const wchar_t* s1, utf8string const& s2)
|
||||
{
|
||||
const wchar_t* p2 = s2.c_str();
|
||||
_StrCmp::Advance(s1,p2);
|
||||
return _StrCmp::Equal(s1,p2);
|
||||
}
|
||||
// case Sensitive
|
||||
bool StrCmp::EqualCase(const char* s1, const char* s2)
|
||||
{
|
||||
_StrCmp::AdvanceCase(s1,s2);
|
||||
return _StrCmp::Equal(s1,s2);
|
||||
}
|
||||
bool StrCmp::EqualCase(std::string const& s1, std::string const& s2)
|
||||
{
|
||||
const char* p1 = s1.c_str();
|
||||
const char* p2 = s2.c_str();
|
||||
_StrCmp::AdvanceCase(p1,p2);
|
||||
return _StrCmp::Equal(p1,p2);
|
||||
}
|
||||
bool StrCmp::EqualCase(std::string const& s1, const char* s2)
|
||||
{
|
||||
const char* p1 = s1.c_str();
|
||||
_StrCmp::AdvanceCase(p1,s2);
|
||||
return _StrCmp::Equal(p1,s2);
|
||||
}
|
||||
bool StrCmp::EqualCase(const char* s1, std::string const& s2)
|
||||
{
|
||||
const char* p2 = s2.c_str();
|
||||
_StrCmp::AdvanceCase(s1,p2);
|
||||
return _StrCmp::Equal(s1,p2);
|
||||
}
|
||||
//
|
||||
bool StrCmp::EqualCase(const wchar_t* s1, const wchar_t* s2)
|
||||
{
|
||||
_StrCmp::AdvanceCase(s1,s2);
|
||||
return _StrCmp::Equal(s1,s2);
|
||||
}
|
||||
bool StrCmp::EqualCase(std::wstring const& s1, std::wstring const& s2)
|
||||
{
|
||||
const wchar_t* p1 = s1.c_str();
|
||||
const wchar_t* p2 = s2.c_str();
|
||||
_StrCmp::AdvanceCase(p1,p2);
|
||||
return _StrCmp::Equal(p1,p2);
|
||||
}
|
||||
bool StrCmp::EqualCase(std::wstring const& s1, const wchar_t* s2)
|
||||
{
|
||||
const wchar_t* p1 = s1.c_str();
|
||||
_StrCmp::AdvanceCase(p1,s2);
|
||||
return _StrCmp::Equal(p1,s2);
|
||||
}
|
||||
bool StrCmp::EqualCase(const wchar_t* s1, std::wstring const& s2)
|
||||
{
|
||||
const wchar_t* p2 = s2.c_str();
|
||||
_StrCmp::AdvanceCase(s1,p2);
|
||||
return _StrCmp::Equal(s1,p2);
|
||||
}
|
||||
//
|
||||
bool StrCmp::EqualCase(utf8string const& s1, utf8string const& s2)
|
||||
{
|
||||
const wchar_t* p1 = s1.c_str();
|
||||
const wchar_t* p2 = s2.c_str();
|
||||
_StrCmp::AdvanceCase(p1,p2);
|
||||
return _StrCmp::Equal(p1,p2);
|
||||
}
|
||||
bool StrCmp::EqualCase(utf8string const& s1, std::wstring const& s2)
|
||||
{
|
||||
const wchar_t* p1 = s1.c_str();
|
||||
const wchar_t* p2 = s2.c_str();
|
||||
_StrCmp::AdvanceCase(p1,p2);
|
||||
return _StrCmp::Equal(p1,p2);
|
||||
}
|
||||
bool StrCmp::EqualCase(std::wstring const& s1, utf8string const& s2)
|
||||
{
|
||||
const wchar_t* p1 = s1.c_str();
|
||||
const wchar_t* p2 = s2.c_str();
|
||||
_StrCmp::AdvanceCase(p1,p2);
|
||||
return _StrCmp::Equal(p1,p2);
|
||||
}
|
||||
bool StrCmp::EqualCase(utf8string const& s1, const wchar_t* s2)
|
||||
{
|
||||
const wchar_t* p1 = s1.c_str();
|
||||
_StrCmp::AdvanceCase(p1,s2);
|
||||
return _StrCmp::Equal(p1,s2);
|
||||
}
|
||||
bool StrCmp::EqualCase(const wchar_t* s1, utf8string const& s2)
|
||||
{
|
||||
const wchar_t* p2 = s2.c_str();
|
||||
_StrCmp::AdvanceCase(s1,p2);
|
||||
return _StrCmp::Equal(s1,p2);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
#ifndef _UTF8STRING_H_
|
||||
#define _UTF8STRING_H_
|
||||
|
||||
#include "vfs_config.h"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
// simple UTF8 wrapper, uses utf8 implementation from http://utfcpp.sourceforge.net/
|
||||
class VFS_API utf8string
|
||||
{
|
||||
friend bool operator<(utf8string const& s1, utf8string const& s2);
|
||||
friend class StrAccess;
|
||||
public:
|
||||
typedef std::wstring str_t;
|
||||
typedef str_t::value_type char_t;
|
||||
typedef str_t::value_type* ptr_t;
|
||||
|
||||
typedef str_t::size_type size_t;
|
||||
////////////////////////////////////////////////////////////////////
|
||||
static bool less(const utf8string::char_t* s1, const utf8string::char_t* s2);
|
||||
static bool equal(const utf8string::char_t* s1, const utf8string::char_t* s2);
|
||||
// case sensitive
|
||||
static bool lessCase(const utf8string::char_t* s1, const utf8string::char_t* s2);
|
||||
static bool equalCase(const utf8string::char_t* s1, const utf8string::char_t* s2);
|
||||
|
||||
template<bool (*funName)(const utf8string::char_t* s1, const utf8string::char_t* s2)>
|
||||
class Op{
|
||||
public:
|
||||
bool operator()(const utf8string& s1, const utf8string& s2) const
|
||||
{
|
||||
return funName(s1.c_str(),s2.c_str());
|
||||
}
|
||||
};
|
||||
typedef Op<utf8string::less> Less;
|
||||
typedef Op<utf8string::lessCase> LessCase;
|
||||
typedef Op<utf8string::equal> Equal;
|
||||
typedef Op<utf8string::equalCase> EqualCase;
|
||||
public:
|
||||
utf8string();
|
||||
utf8string(const char* str);
|
||||
utf8string(std::string const& str);
|
||||
utf8string(const wchar_t* str);
|
||||
utf8string(std::wstring const& str);
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
static utf8string::str_t as_utf16(const char* str);
|
||||
static void as_utf16(const char* str, utf8string::str_t &str16);
|
||||
static utf8string::str_t as_utf16(std::string const& str);
|
||||
static void as_utf16(std::string const& str, utf8string::str_t &str16);
|
||||
// fast conversion without creating an internal copy
|
||||
static std::string as_utf8(utf8string const& str);
|
||||
static std::string as_utf8(std::wstring const& str);
|
||||
// if 'strlen' is 0, length is determined automatically
|
||||
static std::string as_utf8(const wchar_t* str, utf8string::size_t strlength=0);
|
||||
//
|
||||
static std::string narrow(wchar_t const* str, utf8string::size_t length);
|
||||
static utf8string::size_t narrow(wchar_t const* src_str, utf8string::size_t src_len, char* dst_str, utf8string::size_t dst_len);
|
||||
static utf8string::size_t narrow(std::wstring const& src, std::string& dst);
|
||||
//
|
||||
static std::wstring widen(char const* str, utf8string::size_t length);
|
||||
static utf8string::size_t widen(char const* src_str, utf8string::size_t src_len, wchar_t* dst_str, utf8string::size_t dst_len);
|
||||
static utf8string::size_t widen(std::string const& src, std::wstring& dst);
|
||||
|
||||
// convenience method, for the case it should be used in generic code (overloading)
|
||||
static std::string as_utf8(std::string const& str);
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// convert string to UTF8 encoding
|
||||
inline std::string utf8() const { return as_utf8(_str); }
|
||||
|
||||
// returns const reference to copy or compare string
|
||||
inline std::wstring const& c_wcs() const { return _str; }
|
||||
|
||||
inline const wchar_t* c_str() const { return _str.c_str(); }
|
||||
|
||||
// returns reference to modify string
|
||||
inline std::wstring& r_wcs() { return _str; }
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool empty() const;
|
||||
utf8string::size_t length() const;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
utf8string operator+(utf8string const& str);
|
||||
utf8string operator+=(utf8string const& str);
|
||||
private:
|
||||
str_t _str;
|
||||
};
|
||||
|
||||
bool operator<(utf8string const& s1, utf8string const& s2);
|
||||
VFS_API std::wstringstream& operator<<(std::wstringstream& out, utf8string const& str);
|
||||
VFS_API std::wstringstream& operator<<(std::wstringstream& out, utf8string::str_t const& str);
|
||||
VFS_API std::wstringstream& operator<<(std::wstringstream& out, const utf8string::char_t* str);
|
||||
|
||||
// explicit compare
|
||||
namespace StrCmp
|
||||
{
|
||||
// case IN-sensitive
|
||||
VFS_API bool Equal(const char* s1, const char* s2);
|
||||
VFS_API bool Equal(std::string const& s1, std::string const& s2);
|
||||
VFS_API bool Equal(std::string const& s1, const char* s2);
|
||||
VFS_API bool Equal(const char* s1, std::string const& s2);
|
||||
//
|
||||
VFS_API bool Equal(const wchar_t* s1, const wchar_t* s2);
|
||||
VFS_API bool Equal(std::wstring const& s1, std::wstring const& s2);
|
||||
VFS_API bool Equal(std::wstring const& s1, const wchar_t* s2);
|
||||
VFS_API bool Equal(const wchar_t* s1, std::wstring const& s2);
|
||||
//
|
||||
VFS_API bool Equal(utf8string const& s1, utf8string const& s2);
|
||||
VFS_API bool Equal(utf8string const& s1, std::wstring const& s2);
|
||||
VFS_API bool Equal(std::wstring const& s1, utf8string const& s2);
|
||||
VFS_API bool Equal(utf8string const& s1, const wchar_t* s2);
|
||||
VFS_API bool Equal(const wchar_t* s1, utf8string const& s2);
|
||||
// case Sensitive
|
||||
VFS_API bool EqualCase(const char* s1, const char* s2);
|
||||
VFS_API bool EqualCase(std::string const& s1, std::string const& s2);
|
||||
VFS_API bool EqualCase(std::string const& s1, const char* s2);
|
||||
VFS_API bool EqualCase(const char* s1, std::string const& s2);
|
||||
//
|
||||
VFS_API bool EqualCase(const wchar_t* s1, const wchar_t* s2);
|
||||
VFS_API bool EqualCase(std::wstring const& s1, std::wstring const& s2);
|
||||
VFS_API bool EqualCase(std::wstring const& s1, const wchar_t* s2);
|
||||
VFS_API bool EqualCase(const wchar_t* s1, std::wstring const& s2);
|
||||
//
|
||||
VFS_API bool EqualCase(utf8string const& s1, utf8string const& s2);
|
||||
VFS_API bool EqualCase(utf8string const& s1, std::wstring const& s2);
|
||||
VFS_API bool EqualCase(std::wstring const& s1, utf8string const& s2);
|
||||
VFS_API bool EqualCase(utf8string const& s1, const wchar_t* s2);
|
||||
VFS_API bool EqualCase(const wchar_t* s1, utf8string const& s2);
|
||||
}
|
||||
|
||||
#endif // _UTF8STRING_H_
|
||||
-607
@@ -1,607 +0,0 @@
|
||||
#include "vfs_types.h"
|
||||
#include "vfs.h"
|
||||
|
||||
#include "Interface/vfs_directory_interface.h"
|
||||
#include "Interface/vfs_file_interface.h"
|
||||
#include "File/vfs_file.h"
|
||||
#include "File/vfs_dir_file.h"
|
||||
#include "File/vfs_lib_file.h"
|
||||
#include "vfs_file_raii.h"
|
||||
#include "vfs_vfile.h"
|
||||
|
||||
#include "PropertyContainer.h"
|
||||
|
||||
#include <stack>
|
||||
|
||||
|
||||
std::vector<BasicAllocator*> CFileAllocator::_valloc;
|
||||
|
||||
void CFileAllocator::registerAllocator(BasicAllocator* allocator)
|
||||
{
|
||||
_valloc.push_back(allocator);
|
||||
}
|
||||
void CFileAllocator::clear()
|
||||
{
|
||||
std::vector<BasicAllocator*>::iterator it = _valloc.begin();
|
||||
for(; it != _valloc.end(); ++it)
|
||||
{
|
||||
delete *it;
|
||||
*it = NULL;
|
||||
}
|
||||
_valloc.clear();
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************/
|
||||
/********************************************************************/
|
||||
|
||||
class vfs::CVirtualFileSystem::CRegularIterator : public vfs::CVirtualFileSystem::Iterator::IImplementation
|
||||
{
|
||||
friend class vfs::CVirtualFileSystem;
|
||||
typedef vfs::CVirtualFileSystem::Iterator::IImplementation tBaseClass;
|
||||
|
||||
CRegularIterator(vfs::CVirtualFileSystem* pVFS);
|
||||
public:
|
||||
CRegularIterator() : tBaseClass(), m_VFS(NULL)
|
||||
{};
|
||||
virtual ~CRegularIterator()
|
||||
{};
|
||||
|
||||
virtual vfs::tReadableFile* value();
|
||||
virtual void next();
|
||||
protected:
|
||||
virtual tBaseClass* clone()
|
||||
{
|
||||
CRegularIterator* iter = new CRegularIterator();
|
||||
iter->m_VFS = m_VFS;
|
||||
iter->_vloc_iter = _vloc_iter;
|
||||
iter->_vfile_iter = _vfile_iter;
|
||||
return iter;
|
||||
}
|
||||
private:
|
||||
vfs::CVirtualFileSystem* m_VFS;
|
||||
vfs::CVirtualFileSystem::tVFS::iterator _vloc_iter;
|
||||
vfs::CVirtualLocation::Iterator _vfile_iter;
|
||||
};
|
||||
|
||||
vfs::CVirtualFileSystem::CRegularIterator::CRegularIterator(vfs::CVirtualFileSystem* pVFS)
|
||||
: tBaseClass(), m_VFS(pVFS)
|
||||
{
|
||||
_vloc_iter = m_VFS->m_mapFS.begin();
|
||||
if(_vloc_iter != m_VFS->m_mapFS.end())
|
||||
{
|
||||
_vfile_iter = _vloc_iter->second->iterate();
|
||||
}
|
||||
}
|
||||
|
||||
vfs::tReadableFile* vfs::CVirtualFileSystem::CRegularIterator::value()
|
||||
{
|
||||
bool bExclusiveVLoc = false;
|
||||
if(_vloc_iter != m_VFS->m_mapFS.end())
|
||||
{
|
||||
bExclusiveVLoc = _vloc_iter->second->getIsExclusive();
|
||||
}
|
||||
if(!_vfile_iter.end())
|
||||
{
|
||||
vfs::CVirtualFile* pVFile = _vfile_iter.value();
|
||||
if(pVFile)
|
||||
{
|
||||
if(bExclusiveVLoc)
|
||||
{
|
||||
return vfs::tReadableFile::cast(pVFile->file(vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE));
|
||||
}
|
||||
else
|
||||
{
|
||||
return vfs::tReadableFile::cast(pVFile->file(vfs::CVirtualFile::SF_TOP));
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
void vfs::CVirtualFileSystem::CRegularIterator::next()
|
||||
{
|
||||
if(!_vfile_iter.end())
|
||||
{
|
||||
_vfile_iter.next();
|
||||
}
|
||||
while(_vfile_iter.end())
|
||||
{
|
||||
if(_vloc_iter != m_VFS->m_mapFS.end())
|
||||
{
|
||||
_vloc_iter++;
|
||||
if(_vloc_iter != m_VFS->m_mapFS.end())
|
||||
{
|
||||
_vfile_iter = _vloc_iter->second->iterate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
/********************************************************************/
|
||||
|
||||
class vfs::CVirtualFileSystem::CMatchingIterator : public vfs::CVirtualFileSystem::Iterator::IImplementation
|
||||
{
|
||||
friend class vfs::CVirtualFileSystem;
|
||||
typedef vfs::CVirtualFileSystem::Iterator::IImplementation tBaseClass;
|
||||
|
||||
CMatchingIterator(vfs::Path const& sPattern, vfs::CVirtualFileSystem* pVFS);
|
||||
public:
|
||||
CMatchingIterator() : tBaseClass(), m_VFS(NULL)
|
||||
{};
|
||||
virtual ~CMatchingIterator()
|
||||
{};
|
||||
|
||||
virtual vfs::tReadableFile* value();
|
||||
virtual void next();
|
||||
protected:
|
||||
virtual tBaseClass* clone()
|
||||
{
|
||||
CMatchingIterator* iter = new CMatchingIterator();
|
||||
iter->m_sLocPattern = m_sLocPattern;
|
||||
iter->m_sFilePattern = m_sFilePattern;
|
||||
iter->m_VFS = m_VFS;
|
||||
iter->_vloc_iter = _vloc_iter;
|
||||
iter->_vfile_iter = _vfile_iter;
|
||||
return iter;
|
||||
}
|
||||
private:
|
||||
bool nextLocationMatch();
|
||||
bool nextFileMatch();
|
||||
private:
|
||||
vfs::Path m_sLocPattern, m_sFilePattern;
|
||||
vfs::CVirtualFileSystem* m_VFS;
|
||||
vfs::CVirtualFileSystem::tVFS::iterator _vloc_iter;
|
||||
vfs::CVirtualLocation::Iterator _vfile_iter;
|
||||
};
|
||||
|
||||
vfs::CVirtualFileSystem::CMatchingIterator::CMatchingIterator(vfs::Path const& sPattern, vfs::CVirtualFileSystem* pVFS)
|
||||
: tBaseClass(), m_VFS(pVFS)
|
||||
{
|
||||
if(sPattern() == vfs::Const::STAR())
|
||||
{
|
||||
m_sLocPattern = vfs::Path(vfs::Const::STAR());
|
||||
m_sFilePattern = vfs::Path(vfs::Const::STAR());
|
||||
}
|
||||
else
|
||||
{
|
||||
sPattern.splitLast(m_sLocPattern,m_sFilePattern);
|
||||
}
|
||||
|
||||
_vloc_iter = m_VFS->m_mapFS.begin();
|
||||
while(_vloc_iter != m_VFS->m_mapFS.end())
|
||||
{
|
||||
if( matchPattern(m_sLocPattern(),_vloc_iter->second->cPath()) )
|
||||
{
|
||||
bool bExclusiveVLoc = _vloc_iter->second->getIsExclusive();
|
||||
_vfile_iter = _vloc_iter->second->iterate();
|
||||
while(!_vfile_iter.end())
|
||||
{
|
||||
vfs::IBaseFile* pFile = NULL;
|
||||
if(bExclusiveVLoc)
|
||||
{
|
||||
pFile = _vfile_iter.value()->file(vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE);
|
||||
}
|
||||
else
|
||||
{
|
||||
pFile = _vfile_iter.value()->file(vfs::CVirtualFile::SF_TOP);
|
||||
}
|
||||
if(pFile)
|
||||
{
|
||||
vfs::Path const& filename = pFile->getName();
|
||||
if( matchPattern(m_sFilePattern(),filename()) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
_vfile_iter.next();
|
||||
}
|
||||
}
|
||||
_vloc_iter++;
|
||||
}
|
||||
}
|
||||
|
||||
vfs::tReadableFile* vfs::CVirtualFileSystem::CMatchingIterator::value()
|
||||
{
|
||||
bool bExclusiveVLoc = false;
|
||||
if( _vloc_iter != m_VFS->m_mapFS.end() )
|
||||
{
|
||||
bExclusiveVLoc = _vloc_iter->second->getIsExclusive();
|
||||
}
|
||||
if(!_vfile_iter.end())
|
||||
{
|
||||
vfs::CVirtualFile* pVFile = _vfile_iter.value();
|
||||
if(pVFile)
|
||||
{
|
||||
vfs::IBaseFile* pFile = NULL;
|
||||
if(bExclusiveVLoc)
|
||||
{
|
||||
pFile = _vfile_iter.value()->file(vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE);
|
||||
}
|
||||
else
|
||||
{
|
||||
pFile = _vfile_iter.value()->file(vfs::CVirtualFile::SF_TOP);
|
||||
}
|
||||
return vfs::tReadableFile::cast(pFile);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool vfs::CVirtualFileSystem::CMatchingIterator::nextLocationMatch()
|
||||
{
|
||||
while(_vloc_iter != m_VFS->m_mapFS.end())
|
||||
{
|
||||
_vloc_iter++;
|
||||
if(_vloc_iter != m_VFS->m_mapFS.end())
|
||||
{
|
||||
if(matchPattern(m_sLocPattern(),_vloc_iter->second->cPath()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool vfs::CVirtualFileSystem::CMatchingIterator::nextFileMatch()
|
||||
{
|
||||
bool bExclusiveVLoc = false;
|
||||
if( _vloc_iter != m_VFS->m_mapFS.end() )
|
||||
{
|
||||
bExclusiveVLoc = _vloc_iter->second->getIsExclusive();
|
||||
}
|
||||
while(!_vfile_iter.end())
|
||||
{
|
||||
_vfile_iter.next();
|
||||
if(!_vfile_iter.end())
|
||||
{
|
||||
vfs::IBaseFile* pFile = NULL;
|
||||
if(bExclusiveVLoc)
|
||||
{
|
||||
pFile = _vfile_iter.value()->file(vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE);
|
||||
}
|
||||
else
|
||||
{
|
||||
pFile = _vfile_iter.value()->file(vfs::CVirtualFile::SF_TOP);
|
||||
}
|
||||
if(pFile)
|
||||
{
|
||||
vfs::Path const& filename = pFile->getName();
|
||||
if(matchPattern(m_sFilePattern(),filename()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void vfs::CVirtualFileSystem::CMatchingIterator::next()
|
||||
{
|
||||
if(nextFileMatch())
|
||||
{
|
||||
return;
|
||||
}
|
||||
while(nextLocationMatch())
|
||||
{
|
||||
_vfile_iter = _vloc_iter->second->iterate();
|
||||
if(!_vfile_iter.end())
|
||||
{
|
||||
bool bExclusiveVLoc = _vloc_iter->second->getIsExclusive();
|
||||
vfs::IBaseFile* pFile = NULL;
|
||||
if(bExclusiveVLoc)
|
||||
{
|
||||
pFile = _vfile_iter.value()->file(vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE);
|
||||
}
|
||||
else
|
||||
{
|
||||
pFile = _vfile_iter.value()->file(vfs::CVirtualFile::SF_TOP);
|
||||
}
|
||||
if(pFile && matchPattern(m_sFilePattern(),pFile->getName()()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if(nextFileMatch())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
/********************************************************************/
|
||||
|
||||
vfs::CVirtualFileSystem* getVFS()
|
||||
{
|
||||
return vfs::CVirtualFileSystem::getVFS();
|
||||
}
|
||||
|
||||
vfs::CVirtualFileSystem* vfs::CVirtualFileSystem::m_pSingleton = NULL;
|
||||
|
||||
vfs::CVirtualFileSystem* vfs::CVirtualFileSystem::getVFS()
|
||||
{
|
||||
if(!m_pSingleton)
|
||||
{
|
||||
m_pSingleton = new CVirtualFileSystem();
|
||||
}
|
||||
return m_pSingleton;
|
||||
}
|
||||
|
||||
void vfs::CVirtualFileSystem::shutdownVFS()
|
||||
{
|
||||
if(m_pSingleton)
|
||||
{
|
||||
delete m_pSingleton;
|
||||
m_pSingleton = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
vfs::CVirtualFileSystem::CVirtualFileSystem()
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CVirtualFileSystem::~CVirtualFileSystem()
|
||||
{
|
||||
tVFS::iterator it = m_mapFS.begin();
|
||||
for(; it != m_mapFS.end(); ++it)
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
m_mapFS.clear();
|
||||
}
|
||||
|
||||
vfs::CProfileStack* vfs::CVirtualFileSystem::getProfileStack()
|
||||
{
|
||||
return &m_oProfileStack;
|
||||
}
|
||||
|
||||
vfs::CVirtualFileSystem::Iterator vfs::CVirtualFileSystem::begin()
|
||||
{
|
||||
return Iterator(new vfs::CVirtualFileSystem::CRegularIterator(this));
|
||||
}
|
||||
|
||||
vfs::CVirtualFileSystem::Iterator vfs::CVirtualFileSystem::begin(vfs::Path const& sPattern)
|
||||
{
|
||||
return Iterator(new vfs::CVirtualFileSystem::CMatchingIterator(sPattern,this));
|
||||
}
|
||||
|
||||
bool vfs::CVirtualFileSystem::addLocation(vfs::IBaseLocation* pLocation, utf8string const& sProfileName, bool bIsWritable)
|
||||
{
|
||||
vfs::CVirtualProfile *pProf = m_oProfileStack.getProfile(sProfileName);
|
||||
if(!pProf)
|
||||
{
|
||||
pProf = new vfs::CVirtualProfile(sProfileName, bIsWritable);
|
||||
m_oProfileStack.pushProfile(pProf);
|
||||
}
|
||||
pProf->addLocation(pLocation);
|
||||
|
||||
std::list<vfs::Path> lSubDirs;
|
||||
pLocation->getSubDirList(lSubDirs);
|
||||
std::list<vfs::Path>::const_iterator sd_cit = lSubDirs.begin();
|
||||
for(;sd_cit != lSubDirs.end(); ++sd_cit)
|
||||
{
|
||||
this->getVirtualLocation(*sd_cit, true);
|
||||
}
|
||||
|
||||
vfs::IBaseLocation::Iterator it = pLocation->begin();
|
||||
for(; !it.end(); it.next())
|
||||
{
|
||||
vfs::IBaseFile *pFile = it.value();
|
||||
vfs::Path const& sPath = pFile->getPath();
|
||||
vfs::Path dir,file;
|
||||
sPath.splitLast(dir,file);
|
||||
|
||||
CVirtualLocation* pLoc = this->getVirtualLocation(dir,true);
|
||||
pLoc->addFile(pFile,sProfileName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
vfs::tReadableFile* vfs::CVirtualFileSystem::getReadFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF)
|
||||
{
|
||||
return vfs::tReadableFile::cast(this->getFile(rLocalFilePath,eSF));
|
||||
}
|
||||
|
||||
vfs::tWritableFile* vfs::CVirtualFileSystem::getWriteFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF)
|
||||
{
|
||||
return vfs::tWritableFile::cast(this->getFile(rLocalFilePath,eSF));
|
||||
}
|
||||
|
||||
vfs::IBaseFile* vfs::CVirtualFileSystem::getFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF)
|
||||
{
|
||||
vfs::Path sDir,sFile;
|
||||
rLocalFilePath.splitLast(sDir,sFile);
|
||||
|
||||
vfs::CVirtualLocation* pVLoc = this->getVirtualLocation(sDir);
|
||||
if(pVLoc)
|
||||
{
|
||||
vfs::CVirtualFile *pVFile = pVLoc->getVirtualFile(sFile);
|
||||
if(pVFile)
|
||||
{
|
||||
if(pVLoc->getIsExclusive())
|
||||
{
|
||||
return pVFile->file(vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE);
|
||||
}
|
||||
return pVFile->file(eSF);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vfs::tReadableFile* vfs::CVirtualFileSystem::getReadFile(vfs::Path const& rLocalFilePath, utf8string const& sProfileName)
|
||||
{
|
||||
return vfs::tReadableFile::cast(this->getFile(rLocalFilePath, sProfileName));
|
||||
}
|
||||
|
||||
vfs::tWritableFile* vfs::CVirtualFileSystem::getWriteFile(vfs::Path const& rLocalFilePath, utf8string const& sProfileName)
|
||||
{
|
||||
return vfs::tWritableFile::cast(this->getFile(rLocalFilePath, sProfileName));
|
||||
}
|
||||
|
||||
vfs::IBaseFile* vfs::CVirtualFileSystem::getFile(vfs::Path const& rLocalFilePath, utf8string const& sProfileName)
|
||||
{
|
||||
vfs::Path sDir,sFile;
|
||||
rLocalFilePath.splitLast(sDir,sFile);
|
||||
|
||||
tVFS::iterator it_loc = m_mapFS.find(sDir);
|
||||
if(it_loc == m_mapFS.end())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
vfs::CVirtualLocation* pVLoc = it_loc->second;
|
||||
if(pVLoc)
|
||||
{
|
||||
return pVLoc->getFile(sFile,sProfileName);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool vfs::CVirtualFileSystem::fileExists(vfs::Path const& rLocalFilePath, std::string const& sProfileName)
|
||||
{
|
||||
return this->getFile(rLocalFilePath, sProfileName) != NULL;
|
||||
}
|
||||
|
||||
bool vfs::CVirtualFileSystem::fileExists(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF)
|
||||
{
|
||||
return this->getFile(rLocalFilePath, eSF) != NULL;
|
||||
}
|
||||
|
||||
vfs::CVirtualLocation* vfs::CVirtualFileSystem::getVirtualLocation(vfs::Path const& sPath, bool bCreate)
|
||||
{
|
||||
tVFS::iterator it = m_mapFS.find(sPath);
|
||||
if(it == m_mapFS.end())
|
||||
{
|
||||
if(bCreate)
|
||||
{
|
||||
vfs::CVirtualLocation* pVLoc = new vfs::CVirtualLocation(sPath);
|
||||
m_mapFS.insert(std::make_pair(sPath,pVLoc));
|
||||
return pVLoc;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
bool vfs::CVirtualFileSystem::removeDirectoryFromFS(vfs::Path const& sDir)
|
||||
{
|
||||
vfs::Path pattern = sDir + "*";
|
||||
std::list<vfs::Path> files;
|
||||
|
||||
Iterator it = this->begin(pattern);
|
||||
for(; !it.end(); it.next())
|
||||
{
|
||||
if(it.value()->implementsWritable())
|
||||
{
|
||||
files.push_back(it.value()->getPath());
|
||||
}
|
||||
}
|
||||
bool success = true;
|
||||
std::list<vfs::Path>::iterator fit = files.begin();
|
||||
for(; fit != files.end(); ++fit)
|
||||
{
|
||||
success &= this->removeFileFromFS(*fit);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
bool vfs::CVirtualFileSystem::removeFileFromFS(vfs::Path const& sFilePath)
|
||||
{
|
||||
vfs::Path sPath,sFile;
|
||||
sFilePath.splitLast(sPath,sFile);
|
||||
vfs::CVirtualProfile *pProf = m_oProfileStack.getWriteProfile();
|
||||
if(pProf)
|
||||
{
|
||||
vfs::IBaseLocation *pBL = pProf->getLocation(sPath);
|
||||
if(pBL && pBL->implementsWritable())
|
||||
{
|
||||
vfs::TDirectory<vfs::IWritable> *pDir = dynamic_cast<vfs::TDirectory<vfs::IWritable>*>(pBL);
|
||||
if(pDir)
|
||||
{
|
||||
bool bSuccess = false;
|
||||
// remove file from virtual structures first
|
||||
vfs::IBaseFile* file = pDir->getFile(sFilePath);
|
||||
if(file)
|
||||
{
|
||||
vfs::Path sDir,sFile;
|
||||
sFilePath.splitLast(sDir,sFile);
|
||||
vfs::CVirtualLocation *pVLoc = this->getVirtualLocation(sDir);
|
||||
if(pVLoc)
|
||||
{
|
||||
bSuccess = pVLoc->removeFile(file);
|
||||
}
|
||||
}
|
||||
// delete actual file
|
||||
return bSuccess && pDir->deleteFileFromDirectory(sFilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool vfs::CVirtualFileSystem::createNewFile(vfs::Path const& sFilename)
|
||||
{
|
||||
vfs::Path sPath,sFile;
|
||||
sFilename.splitLast(sPath,sFile);
|
||||
vfs::CVirtualProfile *pProf = m_oProfileStack.getWriteProfile();
|
||||
if(pProf)
|
||||
{
|
||||
bool bIsExclusive = false;
|
||||
bool bNewLocation = false;
|
||||
vfs::IBaseLocation *pProfLoc = pProf->getLocation(sPath);
|
||||
if(!pProfLoc)
|
||||
{
|
||||
// try to find closest match
|
||||
vfs::Path sTemp, sCreateDir, sRight, sLeft = sPath;
|
||||
while(!pProfLoc && !sLeft.empty())
|
||||
{
|
||||
sLeft.splitLast(sTemp,sRight);
|
||||
sLeft = sTemp;
|
||||
sCreateDir = sRight + sCreateDir;
|
||||
pProfLoc = pProf->getLocation(sLeft);
|
||||
}
|
||||
// see if the closest match is exclusive
|
||||
// if yes, then the the new path is a subdirectory and has to be exclusive too
|
||||
vfs::CVirtualLocation *pVLoc = this->getVirtualLocation(sLeft,true);
|
||||
if(pVLoc)
|
||||
{
|
||||
bIsExclusive = pVLoc->getIsExclusive();
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// THROWEXCEPTION(L"location (closest match) should exist");
|
||||
//}
|
||||
bNewLocation = true;
|
||||
}
|
||||
if(pProfLoc && pProfLoc->implementsWritable())
|
||||
{
|
||||
// create file and add to location
|
||||
vfs::TDirectory<vfs::IWritable> *pDir = dynamic_cast<vfs::TDirectory<vfs::IWritable>*>(pProfLoc);
|
||||
vfs::IBaseFile* pFile = pDir->addFile(sFilename);
|
||||
if(bNewLocation)
|
||||
{
|
||||
pProf->addLocation(pProfLoc);
|
||||
}
|
||||
if(pFile)
|
||||
{
|
||||
CVirtualLocation* pLoc = this->getVirtualLocation(sPath,true);
|
||||
if(bIsExclusive)
|
||||
{
|
||||
pLoc->setIsExclusive(bIsExclusive);
|
||||
}
|
||||
pLoc->addFile(pFile,pProf->cName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// throw ?
|
||||
return false;
|
||||
}
|
||||
|
||||
/************************************************************************************************/
|
||||
@@ -1,77 +0,0 @@
|
||||
#ifndef _VFS_H_
|
||||
#define _VFS_H_
|
||||
|
||||
#include "Interface/vfs_file_interface.h"
|
||||
#include "Interface/vfs_location_interface.h"
|
||||
#include "Interface/vfs_iterator_interface.h"
|
||||
#include "vfs_vloc.h"
|
||||
#include "vfs_vfile.h"
|
||||
#include "vfs_types.h"
|
||||
#include <map>
|
||||
|
||||
class CFileAllocator
|
||||
{
|
||||
public:
|
||||
static void registerAllocator(BasicAllocator* allocator);
|
||||
|
||||
static void clear();
|
||||
private:
|
||||
static std::vector<BasicAllocator*> _valloc;
|
||||
};
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class CProfileStack;
|
||||
|
||||
class VFS_API CVirtualFileSystem
|
||||
{
|
||||
typedef std::map<vfs::Path,CVirtualLocation*,vfs::Path::Less> tVFS;
|
||||
|
||||
class CRegularIterator;
|
||||
class CMatchingIterator;
|
||||
public:
|
||||
typedef TIterator<vfs::tReadableFile> Iterator;
|
||||
|
||||
~CVirtualFileSystem();
|
||||
|
||||
static CVirtualFileSystem* getVFS();
|
||||
static void shutdownVFS();
|
||||
|
||||
vfs::CProfileStack* getProfileStack();
|
||||
|
||||
vfs::CVirtualLocation* getVirtualLocation(vfs::Path const& sPath, bool bCreate = false);
|
||||
bool addLocation(vfs::IBaseLocation* pLocation,
|
||||
utf8string const& sProfileName,
|
||||
bool bIsWritable = false);
|
||||
|
||||
bool fileExists(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP );
|
||||
bool fileExists(vfs::Path const& rLocalFilePath, std::string const& sProfileName);
|
||||
|
||||
vfs::IBaseFile* getFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP );
|
||||
vfs::IBaseFile* getFile(vfs::Path const& rLocalFilePath, utf8string const& sProfileName);
|
||||
|
||||
vfs::tReadableFile* getReadFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP );
|
||||
vfs::tReadableFile* getReadFile(vfs::Path const& rLocalFilePath, utf8string const& sProfileName);
|
||||
|
||||
vfs::tWritableFile* getWriteFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP );
|
||||
vfs::tWritableFile* getWriteFile(vfs::Path const& rLocalFilePath, utf8string const& sProfileName);
|
||||
|
||||
bool removeFileFromFS(vfs::Path const& sFilePath);
|
||||
bool removeDirectoryFromFS(vfs::Path const& sDir);
|
||||
bool createNewFile(vfs::Path const& sFileName);
|
||||
|
||||
Iterator begin();
|
||||
Iterator begin(vfs::Path const& sPattern);
|
||||
private:
|
||||
vfs::CProfileStack m_oProfileStack;
|
||||
tVFS m_mapFS;
|
||||
private:
|
||||
CVirtualFileSystem();
|
||||
static CVirtualFileSystem* m_pSingleton;
|
||||
};
|
||||
|
||||
} // end namespace
|
||||
|
||||
VFS_API vfs::CVirtualFileSystem* getVFS();
|
||||
|
||||
#endif // _VFS_H_
|
||||
@@ -1,29 +0,0 @@
|
||||
#ifndef _VFS_CONFIG_H_
|
||||
#define _VFS_CONFIG_H_
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _MSC_VER
|
||||
#ifndef PRINT_DLL_INTERFACE_WARNING
|
||||
#pragma warning ( disable : 4251 )
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
// VFS_STATIC overrides VFS_EXPORT
|
||||
#ifdef VFS_STATIC
|
||||
#define VFS_API
|
||||
#endif
|
||||
|
||||
#ifndef VFS_STATIC
|
||||
#ifdef VFS_EXPORT
|
||||
#define VFS_API __declspec(dllexport)
|
||||
#else
|
||||
#define VFS_API __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#define VFS_API
|
||||
#endif
|
||||
|
||||
#endif // _VFS_CONFIG_H_
|
||||
@@ -1,179 +0,0 @@
|
||||
#include "vfs_debug.h"
|
||||
|
||||
#include "utf8string.h"
|
||||
#include "vfs_file_raii.h"
|
||||
#include "File/vfs_file.h"
|
||||
|
||||
#include "Tools/Log.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <ctime>
|
||||
|
||||
CBasicException::CBasicException(const wchar_t* text, const char* function, int line, const char* file, CBasicException* ex)
|
||||
: std::exception() //(utf8string::as_utf8(text).c_str())
|
||||
{
|
||||
if(ex)
|
||||
{
|
||||
m_CallStack.insert(m_CallStack.end(), ex->m_CallStack.begin(), ex->m_CallStack.end());
|
||||
}
|
||||
_LINE = line;
|
||||
_FILE = file;
|
||||
_FUNCTION = function;
|
||||
|
||||
time_t rawtime;
|
||||
time ( &rawtime );
|
||||
std::string datetime(ctime(&rawtime));
|
||||
IGNOREEXCEPTION(_time = utf8string(datetime.substr(0,datetime.length()-1)));
|
||||
|
||||
SEntry en;
|
||||
en.message = text;
|
||||
en.line = line;
|
||||
en.file = file;
|
||||
en.function = function;
|
||||
en.time = _time;
|
||||
m_CallStack.push_back(en);
|
||||
};
|
||||
|
||||
CBasicException::CBasicException(utf8string const& text, utf8string const& function, int line, const char* file, CBasicException* ex)
|
||||
: std::exception() //(text.utf8().c_str())
|
||||
{
|
||||
if(ex)
|
||||
{
|
||||
m_CallStack.insert(m_CallStack.end(), ex->m_CallStack.begin(), ex->m_CallStack.end());
|
||||
}
|
||||
_LINE = line;
|
||||
_FILE = file;
|
||||
_FUNCTION = function;
|
||||
|
||||
time_t rawtime;
|
||||
time ( &rawtime );
|
||||
std::string datetime(ctime(&rawtime));
|
||||
IGNOREEXCEPTION(_time = utf8string(datetime.substr(0,datetime.length()-1)));
|
||||
|
||||
SEntry en;
|
||||
en.message = text;
|
||||
en.line = line;
|
||||
en.file = file;
|
||||
en.function = function;
|
||||
en.time = _time;
|
||||
m_CallStack.push_back(en);
|
||||
};
|
||||
|
||||
CBasicException::~CBasicException() throw()
|
||||
{
|
||||
}
|
||||
|
||||
utf8string CBasicException::getLastEntryString() const
|
||||
{
|
||||
if(!m_CallStack.empty())
|
||||
{
|
||||
CALLSTACK::const_reverse_iterator rit = m_CallStack.rbegin();
|
||||
std::wstringstream wss;
|
||||
wss << rit->file.c_wcs()
|
||||
<< L" (l. "
|
||||
<< rit->line
|
||||
<< ") : ["
|
||||
<< rit->function.c_wcs()
|
||||
<< L"] - "
|
||||
<< rit->message.c_wcs();
|
||||
return wss.str();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
const char* CBasicException::what() const throw()
|
||||
{
|
||||
static std::string msg;
|
||||
if(!m_CallStack.empty())
|
||||
{
|
||||
//msg = m_CallStack.front().message.utf8();
|
||||
msg = this->getExceptionString().utf8();
|
||||
}
|
||||
return msg.c_str();
|
||||
}
|
||||
|
||||
|
||||
utf8string CBasicException::getExceptionString() const
|
||||
{
|
||||
if(!m_CallStack.empty())
|
||||
{
|
||||
std::wstringstream wss;
|
||||
CALLSTACK::const_reverse_iterator rit = m_CallStack.rbegin();
|
||||
for(; rit != m_CallStack.rend(); ++rit)
|
||||
{
|
||||
wss << L"========== " << rit->time << L" ==========\r\n";
|
||||
wss << L"File : " << rit->file << L"\r\n";
|
||||
wss << L"Line : " << rit->line << L"\r\n";
|
||||
wss << L"Location : " << rit->function << L"\r\n\r\n";
|
||||
wss << L" " << rit->message << L"\r\n";
|
||||
}
|
||||
return wss.str();
|
||||
}
|
||||
return L"";
|
||||
}
|
||||
|
||||
void CBasicException::writeFile(vfs::Path const& sPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
vfs::COpenWriteFile oFile(sPath,true,true);
|
||||
utf8string s = this->getExceptionString();
|
||||
oFile.file().write(s.utf8().c_str(), s.length());
|
||||
oFile.file().close();
|
||||
}
|
||||
catch(CBasicException &ex)
|
||||
{
|
||||
CBasicException ex2(L"Could not write exception file into VFS",
|
||||
_FUNCTION_FORMAT_,__LINE__,__FILE__, &ex);
|
||||
CBasicException out("Writing exception to disc failed : is there no writable profile?",
|
||||
_FUNCTION_FORMAT_,__LINE__,__FILE__, this);
|
||||
|
||||
out.m_CallStack.insert(out.m_CallStack.begin(),ex.m_CallStack.begin(),ex.m_CallStack.end());
|
||||
|
||||
vfs::Path sDir,sFile;
|
||||
sPath.splitLast(sDir,sFile);
|
||||
vfs::CFile oFile(sFile);
|
||||
|
||||
try
|
||||
{
|
||||
// can also fail, but there is only so much we can do
|
||||
vfs::COpenWriteFile file( vfs::tWritableFile::cast(&oFile) );
|
||||
utf8string s = out.getExceptionString();
|
||||
file.file().write(s.utf8().c_str(), s.length());
|
||||
}
|
||||
catch(CBasicException &fex)
|
||||
{
|
||||
RETHROWEXCEPTION(L"Could write exception file at all",&fex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void logException(CBasicException const& ex)
|
||||
{
|
||||
static bool is_logging = false;
|
||||
if(is_logging)
|
||||
{
|
||||
// drop message
|
||||
return;
|
||||
}
|
||||
//////////////////
|
||||
is_logging = true;
|
||||
//////////////////
|
||||
|
||||
static CLog& exlog = *CLog::create(L"game_exceptions.log", false, CLog::FLUSH_IMMEDIATELY);
|
||||
try
|
||||
{
|
||||
exlog << ">>>>>>>>>>>>>>>>>>>>>" << CLog::ENDL;
|
||||
exlog << ex.getExceptionString();
|
||||
exlog << "<<<<<<<<<<<<<<<<<<<<<" << CLog::ENDL << CLog::ENDL;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
// don't throw at all
|
||||
}
|
||||
|
||||
//////////////////
|
||||
is_logging = false;
|
||||
//////////////////
|
||||
}
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
#ifndef _VFS_DEBUG_H_
|
||||
#define _VFS_DEBUG_H_
|
||||
|
||||
#include "vfs_types.h"
|
||||
#include "vfs_path.h"
|
||||
#include <list>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
class VFS_API std::exception;
|
||||
#endif
|
||||
|
||||
class VFS_API CBasicException : public std::exception
|
||||
{
|
||||
public:
|
||||
CBasicException(const wchar_t* text, const char* function, int line, const char* file, CBasicException* ex=NULL);
|
||||
CBasicException(utf8string const& text, utf8string const& function, int line, const char* file, CBasicException* ex=NULL);
|
||||
|
||||
virtual ~CBasicException() throw();
|
||||
|
||||
virtual const char* what() const throw();
|
||||
|
||||
utf8string getLastEntryString() const;
|
||||
utf8string getExceptionString() const;
|
||||
|
||||
void writeFile(vfs::Path const& sPath);
|
||||
|
||||
struct SEntry
|
||||
{
|
||||
utf8string time;
|
||||
utf8string message;
|
||||
utf8string function;
|
||||
int line;
|
||||
utf8string file;
|
||||
};
|
||||
typedef std::list<SEntry> CALLSTACK;
|
||||
CALLSTACK m_CallStack;
|
||||
|
||||
int _LINE;
|
||||
utf8string _FILE;
|
||||
utf8string _FUNCTION;
|
||||
utf8string _time;
|
||||
};
|
||||
|
||||
void logException(CBasicException const& ex);
|
||||
|
||||
#ifdef WIN32
|
||||
#define _FUNCTION_FORMAT_ __FUNCTION__
|
||||
#else
|
||||
//#define _FUNCTION_FORMAT_ __FUNCTION__
|
||||
#define _FUNCTION_FORMAT_ __PRETTY_FUNCTION__
|
||||
#endif
|
||||
|
||||
#define THROWEXCEPTION(message) throw CBasicException((message), _FUNCTION_FORMAT_, __LINE__, __FILE__, NULL)
|
||||
#define RETHROWEXCEPTION(message,ex) throw CBasicException((message), _FUNCTION_FORMAT_, __LINE__, __FILE__, (ex))
|
||||
|
||||
#define THROWIFFALSE(boolexpr,message) if(!(boolexpr)){THROWEXCEPTION((message));}
|
||||
|
||||
#define TRYCATCH_RETHROW(expr,message) \
|
||||
{ \
|
||||
try { (expr); } \
|
||||
catch(CBasicException &ex){ throw CBasicException((message),_FUNCTION_FORMAT_,__LINE__,__FILE__,&ex); } \
|
||||
}
|
||||
|
||||
#define IGNOREEXCEPTION(expr) \
|
||||
{ \
|
||||
try{ (expr); } \
|
||||
catch(CBasicException& ex){ logException(ex); } \
|
||||
}
|
||||
|
||||
#endif // _VFS_DEBUG_H_
|
||||
@@ -1,121 +0,0 @@
|
||||
#include "vfs_file_raii.h"
|
||||
#include "vfs.h"
|
||||
|
||||
#include <sstream>
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
vfs::COpenReadFile::COpenReadFile(vfs::Path const& sPath, vfs::CVirtualFile::ESearchFile eSF)
|
||||
{
|
||||
vfs::IBaseFile *pFile = getVFS()->getFile(sPath,eSF);
|
||||
THROWIFFALSE(pFile,
|
||||
BuildString().add(L"file \"").add(sPath).add(L"\" does not exist").get());
|
||||
|
||||
m_pFile = vfs::tReadableFile::cast(pFile);
|
||||
|
||||
THROWIFFALSE(m_pFile,
|
||||
BuildString().add(L"File \"").add(sPath).add(L"\" is not readable").get());
|
||||
|
||||
THROWIFFALSE(m_pFile->openRead(),
|
||||
BuildString().add(L"Could not open file : ").add(m_pFile->getPath()).get());
|
||||
}
|
||||
|
||||
vfs::COpenReadFile::COpenReadFile(vfs::tReadableFile *pFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_pFile = pFile;
|
||||
THROWIFFALSE(m_pFile,
|
||||
BuildString().add(L"Invalid file object").get());
|
||||
|
||||
THROWIFFALSE(m_pFile->openRead(),
|
||||
BuildString().add(L"Could not open file : ").add(pFile->getPath()).get());
|
||||
}
|
||||
catch(CBasicException &ex)
|
||||
{
|
||||
RETHROWEXCEPTION(L"",&ex);
|
||||
}
|
||||
}
|
||||
vfs::COpenReadFile::~COpenReadFile()
|
||||
{
|
||||
if(m_pFile)
|
||||
{
|
||||
m_pFile->close();
|
||||
m_pFile = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
vfs::tReadableFile& vfs::COpenReadFile::file()
|
||||
{
|
||||
return *m_pFile;
|
||||
}
|
||||
|
||||
void vfs::COpenReadFile::release()
|
||||
{
|
||||
m_pFile = NULL;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
vfs::COpenWriteFile::COpenWriteFile(vfs::Path const& sPath,
|
||||
bool bCreate,
|
||||
bool bTruncate,
|
||||
vfs::CVirtualFile::ESearchFile eSF)
|
||||
{
|
||||
vfs::IBaseFile *pFile = getVFS()->getFile(sPath,eSF);
|
||||
if(!pFile && bCreate)
|
||||
{
|
||||
if(getVFS()->createNewFile(sPath))
|
||||
{
|
||||
pFile = getVFS()->getFile(sPath,eSF);
|
||||
}
|
||||
else
|
||||
{
|
||||
THROWEXCEPTION(BuildString().add(L"Could not create VFS file \"").add(sPath).add(L"\"").get());
|
||||
}
|
||||
}
|
||||
THROWIFFALSE(pFile,
|
||||
BuildString().add(L"File \"").add(sPath).add(L"\" not found").get());
|
||||
|
||||
m_pFile = vfs::tWritableFile::cast(pFile);
|
||||
|
||||
THROWIFFALSE(m_pFile,
|
||||
BuildString().add(L"File \"").add(sPath).add(L"\" exists, but is not writable").get());
|
||||
|
||||
THROWIFFALSE(m_pFile->openWrite(bCreate,bTruncate),
|
||||
BuildString().add(L"File \"").add(sPath).add(L"\" could not be opened for writing").get());
|
||||
}
|
||||
vfs::COpenWriteFile::COpenWriteFile(vfs::tWritableFile *pFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_pFile = pFile;
|
||||
THROWIFFALSE(m_pFile,
|
||||
BuildString().add(L"Invalid file object").get());
|
||||
THROWIFFALSE(m_pFile->openWrite(true,false),
|
||||
BuildString().add(L"Could not open file : ").add(m_pFile->getPath()).get());
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(L"",&ex);
|
||||
};
|
||||
}
|
||||
vfs::COpenWriteFile::~COpenWriteFile()
|
||||
{
|
||||
if(m_pFile)
|
||||
{
|
||||
m_pFile->close();
|
||||
m_pFile = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
vfs::tWritableFile& vfs::COpenWriteFile::file()
|
||||
{
|
||||
return *m_pFile;
|
||||
}
|
||||
|
||||
void vfs::COpenWriteFile::release()
|
||||
{
|
||||
m_pFile = NULL;
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
#ifndef _VFS_FILE_RAII_H_
|
||||
#define _VFS_FILE_RAII_H_
|
||||
|
||||
#include "Interface/vfs_file_interface.h"
|
||||
#include "vfs_vfile.h"
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class VFS_API COpenReadFile
|
||||
{
|
||||
public:
|
||||
COpenReadFile(vfs::Path const& sPath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP);
|
||||
COpenReadFile(vfs::tReadableFile *pFile);
|
||||
~COpenReadFile();
|
||||
|
||||
vfs::tReadableFile& file();
|
||||
void release();
|
||||
private:
|
||||
vfs::tReadableFile* m_pFile;
|
||||
};
|
||||
|
||||
class VFS_API COpenWriteFile
|
||||
{
|
||||
public:
|
||||
COpenWriteFile( vfs::Path const& sPath,
|
||||
bool bCreate = false,
|
||||
bool bTruncate = false,
|
||||
vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE);
|
||||
COpenWriteFile(vfs::tWritableFile *pFile);
|
||||
~COpenWriteFile();
|
||||
|
||||
vfs::tWritableFile& file();
|
||||
void release();
|
||||
private:
|
||||
vfs::tWritableFile* m_pFile;
|
||||
};
|
||||
|
||||
} // end namespace
|
||||
|
||||
#endif // _VFS_FILE_RAII_H_
|
||||
@@ -1,252 +0,0 @@
|
||||
#include "vfs_settings.h"
|
||||
#include "vfs_init.h"
|
||||
#include "vfs.h"
|
||||
#include "File/vfs_file.h"
|
||||
#include "File/vfs_memory_file.h"
|
||||
#include "Location/vfs_directory_tree.h"
|
||||
#include "Location/vfs_slf_library.h"
|
||||
#include "Location/vfs_7z_library.h"
|
||||
#include "Location/vfs_create_7z_library.h"
|
||||
|
||||
#include "PropertyContainer.h"
|
||||
#include "Tools/Log.h"
|
||||
|
||||
#define LOG_VFS_INITIALIZATION
|
||||
#ifdef LOG_VFS_INITIALIZATION
|
||||
#define LOG(x) x
|
||||
#else
|
||||
#define LOG(x)
|
||||
#endif
|
||||
|
||||
|
||||
/********************************************************************/
|
||||
/********************************************************************/
|
||||
|
||||
bool initVirtualFileSystem(vfs::Path const& vfs_ini)
|
||||
{
|
||||
std::list<vfs::Path> li;
|
||||
li.push_back(vfs_ini);
|
||||
return initVirtualFileSystem(li);
|
||||
}
|
||||
bool initVirtualFileSystem(std::list<vfs::Path> const& vfs_ini_list)
|
||||
{
|
||||
CPropertyContainer oVFSProps;
|
||||
std::list<vfs::Path>::const_iterator clit = vfs_ini_list.begin();
|
||||
for(; clit != vfs_ini_list.end(); ++clit)
|
||||
{
|
||||
oVFSProps.initFromIniFile(*clit);
|
||||
}
|
||||
return initVirtualFileSystem(oVFSProps);
|
||||
}
|
||||
bool initVirtualFileSystem(CPropertyContainer& oVFSProps)
|
||||
{
|
||||
LOG(CLog _LOG(vfs::Path(L"vfs_init.log")));
|
||||
|
||||
vfs::CVirtualFileSystem *pVirtFileSys = getVFS();
|
||||
|
||||
LOG(_LOG << "Initializing Virtual File System" << CLog::ENDL);
|
||||
|
||||
if(!vfs::Settings::getUseUnicode()){ LOG(_LOG.endl() << "UNICODE disabled" << CLog::ENDL); }
|
||||
|
||||
LOG(_LOG.endl() << "reading profiles .. ");
|
||||
std::list<utf8string> lProfiles, lLocSections;
|
||||
oVFSProps.getStringListProperty(L"vfs_config",L"PROFILES",lProfiles,L"");
|
||||
if(lProfiles.empty())
|
||||
{
|
||||
LOG(_LOG << " ERROR");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(_LOG << " OK");
|
||||
}
|
||||
LOG(_LOG.endl() << " profiles to read : ");
|
||||
std::list<utf8string>::const_iterator cit_profiles = lProfiles.begin();
|
||||
for(; cit_profiles != lProfiles.end(); ++cit_profiles)
|
||||
{
|
||||
LOG(_LOG << (*cit_profiles) << ", ");
|
||||
}
|
||||
LOG(_LOG.endl());
|
||||
|
||||
std::list<utf8string>::const_iterator prof_cit = lProfiles.begin();
|
||||
for(; prof_cit != lProfiles.end(); ++prof_cit)
|
||||
{
|
||||
LOG(_LOG.endl() << " reading profile [");
|
||||
utf8string sProfSection = utf8string("PROFILE_") + utf8string(*prof_cit);
|
||||
utf8string sProfName = oVFSProps.getStringProperty(sProfSection,L"NAME",L"");
|
||||
LOG(_LOG << sProfName << "] .. ");
|
||||
|
||||
vfs::Path profileRoot = oVFSProps.getStringProperty(sProfSection,L"PROFILE_ROOT",L"");
|
||||
|
||||
lLocSections.clear();
|
||||
oVFSProps.getStringListProperty(sProfSection,L"LOCATIONS",lLocSections,L"");
|
||||
|
||||
LOG(_LOG << "OK");
|
||||
LOG(_LOG.endl() << " locations to read : ");
|
||||
std::list<utf8string>::const_iterator cit_locations = lLocSections.begin();
|
||||
for(; cit_locations != lLocSections.end(); ++cit_locations)
|
||||
{
|
||||
LOG(_LOG << (*cit_locations) << ", ");
|
||||
}
|
||||
LOG(_LOG.endl().endl());
|
||||
|
||||
std::list<utf8string>::iterator loc_it = lLocSections.begin();
|
||||
bool bIsWritable = oVFSProps.getBoolProperty(sProfSection,L"WRITE",false);
|
||||
for(; loc_it != lLocSections.end(); ++loc_it)
|
||||
{
|
||||
LOG(_LOG << " reading location [ ");
|
||||
utf8string sLocSection = utf8string("LOC_") + utf8string(*loc_it);
|
||||
vfs::Path sLocPath, sLocMountPoint;
|
||||
utf8string sLocType;
|
||||
|
||||
sLocPath = oVFSProps.getStringProperty(sLocSection,"PATH","");
|
||||
sLocMountPoint = oVFSProps.getStringProperty(sLocSection,L"MOUNT_POINT",L"");
|
||||
sLocType = oVFSProps.getStringProperty(sLocSection,L"TYPE",L"NOT_FOUND");
|
||||
bool bOptional = oVFSProps.getBoolProperty(sLocSection,L"OPTIONAL",false);
|
||||
if(StrCmp::Equal(sLocType,L"LIBRARY"))
|
||||
{
|
||||
LOG(_LOG << sLocType << " | " << (*loc_it) << " ] .. ");
|
||||
vfs::tReadableFile *pLibFile = NULL;
|
||||
bool bOwnFile = false;
|
||||
if(!sLocPath.empty())
|
||||
{
|
||||
pLibFile = vfs::tReadableFile::cast( new vfs::CFile(profileRoot + sLocPath) );
|
||||
bOwnFile = true;
|
||||
}
|
||||
if(!pLibFile)
|
||||
{
|
||||
sLocPath = oVFSProps.getStringProperty(sLocSection,L"VFS_PATH",L"");
|
||||
if(!sLocPath.empty())
|
||||
{
|
||||
pLibFile = pVirtFileSys->getReadFile(profileRoot + sLocPath);
|
||||
}
|
||||
}
|
||||
if(pLibFile)
|
||||
{
|
||||
utf8string full_str = pLibFile->getName()();
|
||||
utf8string ext = full_str.c_wcs().substr(full_str.length()-3,3);
|
||||
vfs::ILibrary *pLib = NULL;
|
||||
if(StrCmp::Equal(ext,L"slf"))
|
||||
{
|
||||
pLib = new vfs::CSLFLibrary( pLibFile, sLocMountPoint );
|
||||
}
|
||||
else if(StrCmp::Equal(ext,L".7z"))
|
||||
{
|
||||
pLib = new vfs::CUncompressed7zLibrary( pLibFile, sLocMountPoint );
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(_LOG << "ERROR" << CLog::ENDL);
|
||||
THROWEXCEPTION(BuildString().add(L"File [").add(sLocPath).add(L"] in not an SLF or 7z library").get());
|
||||
}
|
||||
if(!pLib->init())
|
||||
{
|
||||
if(!bOptional)
|
||||
{
|
||||
LOG(_LOG << "ERROR" << CLog::ENDL);
|
||||
BuildString bs;
|
||||
bs.add(L"Could not initialize library [").add(sLocPath).add(L" ]").add(
|
||||
L" in : profile [ ").add(sProfName).add(L" ],").add(
|
||||
L" location [ ").add((*loc_it)).add(L" ],").add(
|
||||
L" path [ ").add((profileRoot + sLocPath)).add(L" ]");
|
||||
THROWEXCEPTION(bs.get());
|
||||
}
|
||||
LOG(_LOG << "optional library ignored" << CLog::ENDL);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(_LOG << "OK" << CLog::ENDL);
|
||||
}
|
||||
pVirtFileSys->addLocation(vfs::tReadLocation::cast(pLib), sProfName, bIsWritable);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(_LOG << "ERROR" << CLog::ENDL);
|
||||
THROWEXCEPTION(L"File not found");
|
||||
}
|
||||
}
|
||||
else if(StrCmp::Equal(sLocType,L"DIRECTORY"))
|
||||
{
|
||||
LOG(_LOG << sLocType << " | " << (*loc_it) << " ] .. ");
|
||||
vfs::IBaseLocation *pDirLocation = NULL;
|
||||
bool init_success = false;
|
||||
if(bIsWritable)
|
||||
{
|
||||
vfs::CDirectoryTree *pDirTree = new vfs::CDirectoryTree(sLocMountPoint,profileRoot + sLocPath);
|
||||
init_success = pDirTree->init();
|
||||
pDirLocation = pDirTree;
|
||||
}
|
||||
else
|
||||
{
|
||||
vfs::CReadOnlyDirectoryTree *pDirTree = new vfs::CReadOnlyDirectoryTree(sLocMountPoint,profileRoot + sLocPath);
|
||||
init_success = pDirTree->init();
|
||||
pDirLocation = pDirTree;
|
||||
}
|
||||
if(!init_success)
|
||||
{
|
||||
LOG(_LOG << "ERROR" << CLog::ENDL);
|
||||
BuildString bs;
|
||||
bs.add(L"Could not initialize directory [\"").add(sLocPath).add(L"\"]").add(
|
||||
L" in : profile [\"").add(sProfName).add(L"\"],").add(
|
||||
L" location [\"").add((*loc_it)).add(L"\"],").add(
|
||||
L" path [\"").add(profileRoot + sLocPath).add(L"\"]");
|
||||
THROWEXCEPTION(bs.get());
|
||||
}
|
||||
pVirtFileSys->addLocation(pDirLocation,sProfName,bIsWritable);
|
||||
LOG(_LOG << "OK" << CLog::ENDL);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(_LOG << "]" << CLog::ENDL);
|
||||
}
|
||||
//else if( sLocType == "NOT_FOUND")
|
||||
//{
|
||||
// std::wstringstream wss;
|
||||
// wss << L"No Type specified for location [" << sLocSection << L"]";
|
||||
// THROWEXCEPTION(wss.str().c_str());
|
||||
//}
|
||||
}
|
||||
if(bIsWritable)
|
||||
{
|
||||
vfs::CProfileStack *pPS = pVirtFileSys->getProfileStack();
|
||||
vfs::CVirtualProfile *pProf = pPS->getProfile(sProfName);
|
||||
if(!pProf)
|
||||
{
|
||||
pProf = new vfs::CVirtualProfile(sProfName,true);
|
||||
pPS->pushProfile(pProf);
|
||||
}
|
||||
else if(!pProf->cWritable)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Profile [" << sProfName << L"] is supposed to be writable!";
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
}
|
||||
initWriteProfile(*pProf, profileRoot);
|
||||
}
|
||||
}
|
||||
LOG(_LOG.endl() << "VFS successfully initialized" << CLog::ENDL);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool initWriteProfile(vfs::CVirtualProfile &rProf, vfs::Path const& profileRoot)
|
||||
{
|
||||
typedef vfs::TDirectory<vfs::IWritable> tWDir;
|
||||
tWDir *pDir = NULL;
|
||||
vfs::IBaseLocation *pLoc = rProf.getLocation(vfs::Path(vfs::Const::EMPTY()));
|
||||
if(pLoc)
|
||||
{
|
||||
pDir = dynamic_cast<tWDir*>(pLoc);
|
||||
}
|
||||
else
|
||||
{
|
||||
vfs::CDirectoryTree *pDirTree = NULL;
|
||||
pDirTree = new vfs::CDirectoryTree(vfs::Path(vfs::Const::EMPTY()),profileRoot);
|
||||
if(!pDirTree->init())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
getVFS()->addLocation(pDirTree,rProf.cName,true);
|
||||
pDir = pDirTree;
|
||||
}
|
||||
return pDir != NULL;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
#ifndef _VFS_INIT_H_
|
||||
#define _VFS_INIT_H_
|
||||
|
||||
#include "vfs_types.h"
|
||||
#include "vfs_profile.h"
|
||||
#include "PropertyContainer.h"
|
||||
|
||||
VFS_API bool initWriteProfile(vfs::CVirtualProfile &rProf, vfs::Path const& profileRoot);
|
||||
VFS_API bool initVirtualFileSystem(vfs::Path const& vfs_ini);
|
||||
VFS_API bool initVirtualFileSystem(std::list<vfs::Path> const& vfs_ini_list);
|
||||
VFS_API bool initVirtualFileSystem(CPropertyContainer& props);
|
||||
|
||||
#endif // _VFS_INIT_H_
|
||||
@@ -1,500 +0,0 @@
|
||||
#include "vfs_path.h"
|
||||
#include "vfs_debug.h"
|
||||
#include "vfs_settings.h"
|
||||
|
||||
static void unifySeparators(utf8string::str_t &sPath)
|
||||
{
|
||||
utf8string::char_t &raw = sPath[0];
|
||||
utf8string::ptr_t raw_ptr = &raw;
|
||||
while(*raw_ptr != 0)
|
||||
{
|
||||
if(*raw_ptr == '\\' || *raw_ptr == '/')
|
||||
{
|
||||
*raw_ptr = vfs::Const::SEPARATOR_CHAR();
|
||||
}
|
||||
raw_ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* call after unifying separators
|
||||
*/
|
||||
static vfs::UInt32 removeSeparators(utf8string::str_t &str)
|
||||
{
|
||||
vfs::UInt32 sepcount = 0;
|
||||
vfs::Int32 numsep = 0;
|
||||
::size_t put_pos = 0;
|
||||
::size_t len = str.length();
|
||||
utf8string::char_t& raw = str[0];
|
||||
utf8string::ptr_t old_ptr = &raw;
|
||||
utf8string::ptr_t new_ptr = &raw;
|
||||
utf8string::ptr_t last_ptr = &raw;
|
||||
while(*old_ptr != 0)
|
||||
{
|
||||
if(*old_ptr == vfs::Const::SEPARATOR_CHAR())
|
||||
{
|
||||
numsep++;
|
||||
if(numsep == 1)
|
||||
{
|
||||
sepcount++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// we have normal text (again)
|
||||
numsep = 0;
|
||||
}
|
||||
if(numsep <= 1)
|
||||
{
|
||||
*new_ptr = *old_ptr;
|
||||
last_ptr = new_ptr++;
|
||||
put_pos++;
|
||||
}
|
||||
old_ptr++;
|
||||
}
|
||||
if(*last_ptr == vfs::Const::SEPARATOR_CHAR())
|
||||
{
|
||||
put_pos--;
|
||||
if(sepcount>0)
|
||||
{
|
||||
sepcount--;
|
||||
}
|
||||
}
|
||||
if(put_pos < len)
|
||||
{
|
||||
str.erase(put_pos);
|
||||
}
|
||||
return sepcount;
|
||||
}
|
||||
|
||||
static void removeLastSeparator(utf8string::str_t &str)
|
||||
{
|
||||
if( *str.rbegin() == vfs::Const::SEPARATOR_CHAR() )
|
||||
{
|
||||
str.erase( str.length()-1);
|
||||
}
|
||||
}
|
||||
|
||||
static void removeDots(utf8string::str_t &str, vfs::UInt32 number_of_separators)
|
||||
{
|
||||
utf8string::char_t& raw = str[0];
|
||||
utf8string::ptr_t old_ptr = &raw;
|
||||
utf8string::ptr_t new_ptr = &raw;
|
||||
utf8string::size_t LENGTH = str.length();
|
||||
bool dirty = false;
|
||||
|
||||
// see if we start with ./ (not . as this might be a hidden files on unix systems)
|
||||
if( (LENGTH > 1) && (*old_ptr == vfs::Const::DOT_CHAR()) && (*(old_ptr+1) == vfs::Const::SEPARATOR_CHAR()) )
|
||||
{
|
||||
old_ptr += 2;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
std::vector<utf8string::ptr_t> sub_strings;
|
||||
sub_strings.resize(number_of_separators);
|
||||
int pos=0;
|
||||
|
||||
if(*old_ptr != 0 && *old_ptr == vfs::Const::SEPARATOR_CHAR())
|
||||
{
|
||||
if(!dirty)
|
||||
{
|
||||
// in-place : just move along
|
||||
new_ptr++;
|
||||
old_ptr++;
|
||||
}
|
||||
else
|
||||
{
|
||||
*new_ptr++ = *old_ptr++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
sub_strings[pos++] = new_ptr;
|
||||
|
||||
while(*old_ptr != 0)
|
||||
{
|
||||
if(*old_ptr != vfs::Const::SEPARATOR_CHAR())
|
||||
{
|
||||
if(!dirty)
|
||||
{
|
||||
new_ptr++;
|
||||
old_ptr++;
|
||||
}
|
||||
else
|
||||
{
|
||||
*new_ptr++ = *old_ptr++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
*new_ptr++ = *old_ptr++;
|
||||
sub_strings[pos++] = new_ptr;
|
||||
|
||||
if((&raw+3) < old_ptr)
|
||||
{
|
||||
if( (*(old_ptr-4) == vfs::Const::SEPARATOR_CHAR()) &&
|
||||
(*(old_ptr-3) == vfs::Const::DOT_CHAR()) &&
|
||||
(*(old_ptr-2) == vfs::Const::DOT_CHAR()) &&
|
||||
(*(old_ptr-1) == vfs::Const::SEPARATOR_CHAR()) )
|
||||
{
|
||||
if(pos > 1)
|
||||
{
|
||||
new_ptr = sub_strings[pos-3];
|
||||
pos -= 2;
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
else if((*(old_ptr-3) == vfs::Const::SEPARATOR_CHAR()) &&
|
||||
(*(old_ptr-2) == vfs::Const::DOT_CHAR()) &&
|
||||
(*(old_ptr-1) == vfs::Const::SEPARATOR_CHAR()) )
|
||||
{
|
||||
if(pos > 0)
|
||||
{
|
||||
new_ptr = sub_strings[pos-2];
|
||||
pos -= 1;
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if((&raw+2) < old_ptr)
|
||||
{
|
||||
if( (*(old_ptr-3) == vfs::Const::SEPARATOR_CHAR()) &&
|
||||
(*(old_ptr-2) == vfs::Const::DOT_CHAR()) &&
|
||||
(*(old_ptr-1) == vfs::Const::SEPARATOR_CHAR()) )
|
||||
{
|
||||
if(pos > 0)
|
||||
{
|
||||
new_ptr = sub_strings[pos-2];
|
||||
pos -= 1;
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
::size_t ttt = (new_ptr - &raw);
|
||||
if(ttt < LENGTH)
|
||||
{
|
||||
str.erase(ttt);
|
||||
}
|
||||
}
|
||||
|
||||
static void getFirstLastSeparator(const utf8string::char_t* sPath, vfs::size_t &iFirst, vfs::size_t &iLast)
|
||||
{
|
||||
const utf8string::char_t* ptr = sPath;
|
||||
vfs::size_t pos = 0;
|
||||
while(*ptr != 0)
|
||||
{
|
||||
if(*ptr == vfs::Const::SEPARATOR_CHAR())
|
||||
{
|
||||
if(iFirst == vfs::npos)
|
||||
{
|
||||
iFirst = pos;
|
||||
}
|
||||
iLast = pos;
|
||||
}
|
||||
pos++;
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
bool vfs::Path::Less::operator ()(vfs::Path const& s1, vfs::Path const& s2) const
|
||||
{
|
||||
return utf8string::less(s1._path.c_str(), s2._path.c_str());
|
||||
}
|
||||
bool vfs::Path::Equal::operator ()(vfs::Path const& s1, vfs::Path const& s2) const
|
||||
{
|
||||
return utf8string::equal(s1._path.c_str(), s2._path.c_str());
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
vfs::Path::Path()
|
||||
{
|
||||
}
|
||||
|
||||
vfs::Path::Path(utf8string const& sPath)
|
||||
: _path(sPath.c_wcs())
|
||||
{
|
||||
doCheck();
|
||||
}
|
||||
|
||||
vfs::Path::Path(const char* sPath)
|
||||
{
|
||||
if(vfs::Settings::getUseUnicode())
|
||||
{
|
||||
utf8string::as_utf16(sPath,_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
utf8string::widen(std::string(sPath),_path);
|
||||
}
|
||||
doCheck();
|
||||
}
|
||||
|
||||
vfs::Path::Path(std::string const& sPath)
|
||||
{
|
||||
if(vfs::Settings::getUseUnicode())
|
||||
{
|
||||
utf8string::as_utf16(sPath,_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
utf8string::widen(sPath,_path);
|
||||
}
|
||||
doCheck();
|
||||
}
|
||||
|
||||
vfs::Path::Path(const wchar_t* sPath)
|
||||
: _path(sPath)
|
||||
{
|
||||
doCheck();
|
||||
}
|
||||
|
||||
const utf8string::char_t* vfs::Path::c_str() const
|
||||
{
|
||||
return _path.c_str();
|
||||
}
|
||||
|
||||
const utf8string::str_t& vfs::Path::c_wcs() const
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
|
||||
const utf8string::str_t& vfs::Path::operator()() const
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
|
||||
std::string vfs::Path::to_string() const
|
||||
{
|
||||
if(vfs::Settings::getUseUnicode())
|
||||
{
|
||||
return utf8string::as_utf8(_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string s;
|
||||
utf8string::narrow(_path,s);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
bool vfs::Path::empty() const
|
||||
{
|
||||
// is there a case where a non-empty string can become empty after a check?
|
||||
// if it is so then i don't care
|
||||
return _path.empty();
|
||||
}
|
||||
utf8string::size_t vfs::Path::length() const
|
||||
{
|
||||
return _path.length();
|
||||
}
|
||||
|
||||
|
||||
void vfs::Path::doCheck()
|
||||
{
|
||||
if(!_path.empty())
|
||||
{
|
||||
unifySeparators(_path);
|
||||
|
||||
vfs::UInt32 number_of_separators = removeSeparators(_path);
|
||||
|
||||
if(number_of_separators>0)
|
||||
{
|
||||
removeDots(_path,number_of_separators+1);
|
||||
getFirstLastSeparator(_path.c_str(),_sep.first,_sep.last);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void pathSplitLast(utf8string::str_t const& path,
|
||||
utf8string::str_t &head,
|
||||
utf8string::str_t &last,
|
||||
vfs::size_t const& sep_first,
|
||||
vfs::size_t const& sep_last)
|
||||
{
|
||||
if(path.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(&head == &path || &last == &path)
|
||||
{
|
||||
THROWEXCEPTION(L"cannot use output parameters that are equal to 'this'");
|
||||
}
|
||||
#if 1
|
||||
// use results from "GetFirstLastSeparator(..)"
|
||||
if(sep_last != vfs::npos)
|
||||
{
|
||||
head.assign(path.substr(0,sep_last));
|
||||
last.assign(path.substr(sep_last+1, path.length()-sep_last-1));
|
||||
return;
|
||||
}
|
||||
#else
|
||||
utf8string::size_t position = path.length();
|
||||
while(--position != vfs::npos)
|
||||
{
|
||||
utf8string::char_t const& c = path.at(position);
|
||||
if(c == '\\' || c == '/')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(position != vfs::npos)
|
||||
{
|
||||
head.assign(path.substr(0,position++));
|
||||
last.assign(path.substr(position,path.length()-position));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
head.assign(vfs::Const::EMPTY());
|
||||
last.assign(path);
|
||||
}
|
||||
|
||||
|
||||
void vfs::Path::splitLast(vfs::Path &rsHead, vfs::Path &rsLast) const
|
||||
{
|
||||
|
||||
pathSplitLast(_path, rsHead._path, rsLast._path, _sep.first, _sep.last);
|
||||
getFirstLastSeparator(rsHead.c_str(), rsHead._sep.first, rsHead._sep.last);
|
||||
getFirstLastSeparator(rsLast.c_str(), rsLast._sep.first, rsLast._sep.last);
|
||||
// no need to check, as the original path is already checked
|
||||
//rPath.DoCheck();
|
||||
//rFile.DoCheck();
|
||||
}
|
||||
|
||||
static void pathSplitFirst(utf8string::str_t const& path,
|
||||
utf8string::str_t &first,
|
||||
utf8string::str_t &tail,
|
||||
vfs::size_t const& sep_first,
|
||||
vfs::size_t const& sep_last)
|
||||
{
|
||||
if(path.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(&first == &path || &tail == &path)
|
||||
{
|
||||
THROWEXCEPTION(L"cannot use output parameters that are equal to 'this'");
|
||||
}
|
||||
|
||||
#if 1
|
||||
// use results from "GetFirstLastSeparator(..)"
|
||||
if(sep_first != vfs::npos)
|
||||
{
|
||||
first.assign(path.substr(0,sep_first));
|
||||
tail.assign(path.substr(sep_first+1, path.length()-sep_first-1));
|
||||
return;
|
||||
}
|
||||
#else
|
||||
utf8string::size_t position = 0;
|
||||
while(position < path.length())
|
||||
{
|
||||
utf8string::char_t const& c = path.at(position);
|
||||
if(c == '\\' || c == '/')
|
||||
{
|
||||
break;
|
||||
}
|
||||
position++;
|
||||
}
|
||||
if(position < path.length())
|
||||
{
|
||||
first.assign(path.substr(0,position++));
|
||||
tail.assign(path.substr(position,path.length()-position));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
first.assign(path);
|
||||
tail.assign(vfs::Const::EMPTY());
|
||||
}
|
||||
|
||||
void vfs::Path::splitFirst(vfs::Path &rsFirst, vfs::Path &rsTail) const
|
||||
{
|
||||
pathSplitFirst(_path, rsFirst._path, rsTail._path, _sep.first, _sep.last);
|
||||
getFirstLastSeparator(rsFirst.c_str(), rsFirst._sep.first, rsFirst._sep.last);
|
||||
getFirstLastSeparator(rsTail.c_str(), rsTail._sep.first, rsTail._sep.last);
|
||||
// no need to check, as the original path is already checked
|
||||
//rPath.doCheck();
|
||||
//rFile.doCheck();
|
||||
}
|
||||
|
||||
bool vfs::Path::extension(utf8string &sExt) const
|
||||
{
|
||||
if(_path.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
utf8string::size_t SIZE = _path.length();
|
||||
if(_path.at(SIZE-1) == L'.')
|
||||
{
|
||||
// not an extension
|
||||
return false;
|
||||
}
|
||||
for(utf8string::size_t i=SIZE-2; i > 0; i--)
|
||||
{
|
||||
if(_path.at(i) == L'.')
|
||||
{
|
||||
sExt.r_wcs().assign(&_path.at(i+1),SIZE-i-1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
vfs::Path& vfs::Path::operator+=(utf8string const& p)
|
||||
{
|
||||
return *this += vfs::Path(p);
|
||||
}
|
||||
|
||||
vfs::Path& vfs::Path::operator+=(vfs::Path const& p)
|
||||
{
|
||||
if(_path.empty())
|
||||
{
|
||||
_path = p._path;
|
||||
}
|
||||
else if(!p.empty())
|
||||
{
|
||||
_path += vfs::Const::SEPARATOR();
|
||||
_path += p._path;
|
||||
getFirstLastSeparator(_path.c_str(),_sep.first,_sep.last);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
vfs::Path operator+(vfs::Path const& p1, vfs::Path const& p2)
|
||||
{
|
||||
vfs::Path newpath = p1;
|
||||
newpath += p2;
|
||||
return newpath;
|
||||
}
|
||||
|
||||
bool vfs::Path::operator==(vfs::Path const& p2)
|
||||
{
|
||||
return utf8string::equal(_path.c_str(), p2._path.c_str());
|
||||
}
|
||||
|
||||
bool operator==(vfs::Path const& p1, vfs::Path const& p2)
|
||||
{
|
||||
return StrCmp::Equal(p1.c_str(), p2.c_str());
|
||||
}
|
||||
bool operator==(vfs::Path const& p1, utf8string const& p2)
|
||||
{
|
||||
return StrCmp::Equal(p1.c_str(), p2);
|
||||
}
|
||||
bool operator==(vfs::Path const& p1, utf8string::str_t const& p2)
|
||||
{
|
||||
return StrCmp::Equal(p1.c_str(), p2);
|
||||
}
|
||||
bool operator==(vfs::Path const& p1, const utf8string::char_t* p2)
|
||||
{
|
||||
return StrCmp::Equal(p1.c_str(), p2);
|
||||
}
|
||||
|
||||
template<>
|
||||
BuildString& BuildString::add<vfs::Path>(vfs::Path const& value)
|
||||
{
|
||||
this->add(value.c_str());
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
#ifndef _VFS_PATH_H_
|
||||
#define _VFS_PATH_H_
|
||||
|
||||
#include "vfs_config.h"
|
||||
#include "vfs_types.h"
|
||||
#include "utf8string.h"
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class VFS_API Path
|
||||
{
|
||||
friend class PathAccess;
|
||||
public:
|
||||
class Less{
|
||||
public:
|
||||
bool operator()(vfs::Path const& s1, vfs::Path const& s2) const;
|
||||
};
|
||||
class Equal{
|
||||
public:
|
||||
bool operator()(vfs::Path const& s1, vfs::Path const& s2) const;
|
||||
};
|
||||
public:
|
||||
Path();
|
||||
Path(const char* sPath);
|
||||
Path(std::string const& sPath);
|
||||
Path(const wchar_t* sPath);
|
||||
Path(utf8string const& sPath);
|
||||
|
||||
const utf8string::char_t* c_str() const;
|
||||
const utf8string::str_t& c_wcs() const;
|
||||
const utf8string::str_t& operator()() const;
|
||||
|
||||
std::string to_string() const;
|
||||
|
||||
Path& operator+=(Path const& p);
|
||||
Path& operator+=(utf8string const& p);
|
||||
|
||||
bool empty() const;
|
||||
|
||||
utf8string::size_t length() const;
|
||||
|
||||
void doCheck();
|
||||
|
||||
void splitLast(vfs::Path &rsHead, vfs::Path &rsLast) const;
|
||||
void splitFirst(vfs::Path &rsFirst, vfs::Path &rsTail) const;
|
||||
|
||||
bool extension(utf8string &sExt) const;
|
||||
|
||||
bool operator==(vfs::Path const& p2);
|
||||
private:
|
||||
utf8string::str_t _path;
|
||||
struct SeparatorPosition
|
||||
{
|
||||
SeparatorPosition() : first(vfs::npos), last(vfs::npos) {}
|
||||
vfs::size_t first, last;
|
||||
} _sep;
|
||||
};
|
||||
}
|
||||
|
||||
template<>
|
||||
BuildString& BuildString::add<vfs::Path>(vfs::Path const& value);
|
||||
|
||||
|
||||
// add only valid Path objects
|
||||
vfs::Path operator+(vfs::Path const& p1, vfs::Path const& p2);
|
||||
|
||||
// compare path to string (that can be an invalid path)
|
||||
bool operator==(vfs::Path const& p1, vfs::Path const& p2);
|
||||
// use with care as these string can be different from the internal representation although they seem to be equal
|
||||
bool operator==(vfs::Path const& p1, utf8string const& p2);
|
||||
bool operator==(vfs::Path const& p1, utf8string::str_t const& p2);
|
||||
bool operator==(vfs::Path const& p1, const utf8string::char_t* p2);
|
||||
|
||||
#endif // _VFS_PATH_H_
|
||||
|
||||
@@ -1,393 +0,0 @@
|
||||
#include "vfs_profile.h"
|
||||
#include "vfs.h"
|
||||
#include "Location/vfs_lib_dir.h"
|
||||
#include "Location/vfs_directory_tree.h"
|
||||
|
||||
#include "Tools/Log.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
|
||||
class vfs::CVirtualProfile::IterImpl : public vfs::CVirtualProfile::Iterator::IImplementation
|
||||
{
|
||||
friend class vfs::CVirtualProfile;
|
||||
typedef vfs::CVirtualProfile::Iterator::IImplementation tBaseClass;
|
||||
|
||||
IterImpl(CVirtualProfile* profile) : tBaseClass(), m_profile(profile)
|
||||
{
|
||||
THROWIFFALSE(profile, L"");
|
||||
// only unique locations
|
||||
_loc_iter = m_profile->m_setLocations.begin();
|
||||
}
|
||||
public:
|
||||
IterImpl() : tBaseClass(), m_profile(NULL)
|
||||
{};
|
||||
virtual ~IterImpl()
|
||||
{};
|
||||
//////
|
||||
virtual vfs::IBaseLocation* value()
|
||||
{
|
||||
if(_loc_iter != m_profile->m_setLocations.end())
|
||||
{
|
||||
return *_loc_iter;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
virtual void next()
|
||||
{
|
||||
if(_loc_iter != m_profile->m_setLocations.end())
|
||||
{
|
||||
_loc_iter++;
|
||||
}
|
||||
}
|
||||
protected:
|
||||
virtual tBaseClass* clone()
|
||||
{
|
||||
IterImpl* iter = new IterImpl();
|
||||
iter->m_profile = m_profile;
|
||||
iter->_loc_iter = _loc_iter;
|
||||
return iter;
|
||||
}
|
||||
private:
|
||||
vfs::CVirtualProfile* m_profile;
|
||||
vfs::CVirtualProfile::tUniqueLoc::iterator _loc_iter;
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
class vfs::CVirtualProfile::FileIterImpl : public vfs::CVirtualProfile::FileIterator::IImplementation
|
||||
{
|
||||
friend class vfs::CVirtualProfile;
|
||||
typedef vfs::CVirtualProfile::FileIterator::IImplementation tBaseClass;
|
||||
FileIterImpl(vfs::Path const& sPattern, CVirtualProfile* profile);
|
||||
|
||||
public:
|
||||
FileIterImpl() : tBaseClass(), m_profile(NULL)
|
||||
{};
|
||||
virtual ~FileIterImpl()
|
||||
{};
|
||||
/////
|
||||
virtual vfs::IBaseFile* value()
|
||||
{
|
||||
return file;
|
||||
}
|
||||
virtual void next();
|
||||
protected:
|
||||
virtual tBaseClass* clone()
|
||||
{
|
||||
FileIterImpl* iter2 = new FileIterImpl();
|
||||
iter2->m_pattern = m_pattern;
|
||||
iter2->m_profile = m_profile;
|
||||
iter2->iter = iter;
|
||||
iter2->fiter = fiter;
|
||||
iter2->file = file;
|
||||
return iter2;
|
||||
}
|
||||
private:
|
||||
vfs::Path m_pattern;
|
||||
vfs::CVirtualProfile* m_profile;
|
||||
vfs::CVirtualProfile::Iterator iter;
|
||||
vfs::IBaseLocation::Iterator fiter;
|
||||
vfs::IBaseFile* file;
|
||||
};
|
||||
|
||||
vfs::CVirtualProfile::FileIterImpl::FileIterImpl(vfs::Path const& sPattern, CVirtualProfile* profile)
|
||||
: tBaseClass(), m_pattern(sPattern), m_profile(profile)
|
||||
{
|
||||
THROWIFFALSE(profile, L"");
|
||||
iter = m_profile->begin();
|
||||
while(!iter.end())
|
||||
{
|
||||
fiter = iter.value()->begin();
|
||||
while(!fiter.end())
|
||||
{
|
||||
file = fiter.value();
|
||||
if( matchPattern(m_pattern(), file->getPath()()) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
fiter.next();
|
||||
}
|
||||
iter.next();
|
||||
}
|
||||
file = NULL;
|
||||
}
|
||||
|
||||
void vfs::CVirtualProfile::FileIterImpl::next()
|
||||
{
|
||||
if(!fiter.end())
|
||||
{
|
||||
fiter.next();
|
||||
}
|
||||
while(!iter.end())
|
||||
{
|
||||
while(!fiter.end())
|
||||
{
|
||||
file = fiter.value();
|
||||
if( matchPattern(m_pattern(), file->getPath()()) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
fiter.next();
|
||||
}
|
||||
iter.next();
|
||||
if(!iter.end())
|
||||
{
|
||||
fiter = iter.value()->begin();
|
||||
}
|
||||
}
|
||||
file = NULL;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
vfs::CVirtualProfile::CVirtualProfile(utf8string const& sProfileName, bool bWritable)
|
||||
: cName(sProfileName), cWritable(bWritable)
|
||||
{};
|
||||
|
||||
vfs::CVirtualProfile::~CVirtualProfile()
|
||||
{
|
||||
tUniqueLoc::iterator it = m_setLocations.begin();
|
||||
for(; it != m_setLocations.end(); ++it)
|
||||
{
|
||||
delete (*it);
|
||||
//(*it) = NULL;
|
||||
}
|
||||
m_setLocations.clear();
|
||||
m_mapLocations.clear();
|
||||
};
|
||||
|
||||
vfs::CVirtualProfile::Iterator vfs::CVirtualProfile::begin()
|
||||
{
|
||||
return Iterator(new IterImpl(this));
|
||||
}
|
||||
|
||||
vfs::CVirtualProfile::FileIterator vfs::CVirtualProfile::files(vfs::Path const& sPattern)
|
||||
{
|
||||
return FileIterator( new FileIterImpl(sPattern, this));
|
||||
}
|
||||
|
||||
void vfs::CVirtualProfile::addLocation(vfs::IBaseLocation* pLoc)
|
||||
{
|
||||
if(pLoc)
|
||||
{
|
||||
m_setLocations.insert(pLoc);
|
||||
std::list<vfs::Path> lDirs;
|
||||
pLoc->getSubDirList(lDirs);
|
||||
std::list<vfs::Path>::const_iterator cit = lDirs.begin();
|
||||
for(;cit != lDirs.end(); ++cit)
|
||||
{
|
||||
vfs::IBaseLocation *pNewLoc = m_mapLocations[*cit];
|
||||
if(!pNewLoc)
|
||||
{
|
||||
m_mapLocations[*cit] = pLoc;
|
||||
}
|
||||
else if(pNewLoc == pLoc)
|
||||
{
|
||||
// seems to be an update. do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
THROWEXCEPTION(L"Location already taken");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vfs::IBaseLocation* vfs::CVirtualProfile::getLocation(vfs::Path const& sPath) const
|
||||
{
|
||||
tLocations::const_iterator it = m_mapLocations.find(sPath);
|
||||
if(it != m_mapLocations.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vfs::IBaseFile* vfs::CVirtualProfile::getFile(vfs::Path const& sPath) const
|
||||
{
|
||||
vfs::Path sDir,sFile;
|
||||
sPath.splitLast(sDir,sFile);
|
||||
tLocations::const_iterator it = m_mapLocations.find(sDir);
|
||||
if(it != m_mapLocations.end())
|
||||
{
|
||||
return it->second->getFile(sPath);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
class vfs::CProfileStack::IterImpl : public vfs::CProfileStack::Iterator::IImplementation
|
||||
{
|
||||
friend class CProfileStack;
|
||||
typedef CProfileStack::Iterator::IImplementation tBaseClass;
|
||||
|
||||
IterImpl(CProfileStack* pPStack) : tBaseClass(), m_pPStack(pPStack)
|
||||
{
|
||||
THROWIFFALSE(m_pPStack, L"");
|
||||
_prof_iter = m_pPStack->m_profiles.begin();
|
||||
}
|
||||
public:
|
||||
IterImpl() : tBaseClass(), m_pPStack(NULL)
|
||||
{};
|
||||
~IterImpl()
|
||||
{};
|
||||
//////
|
||||
virtual vfs::CVirtualProfile* value()
|
||||
{
|
||||
if(_prof_iter != m_pPStack->m_profiles.end())
|
||||
{
|
||||
return *_prof_iter;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
virtual void next()
|
||||
{
|
||||
if(_prof_iter != m_pPStack->m_profiles.end())
|
||||
{
|
||||
_prof_iter++;
|
||||
}
|
||||
}
|
||||
protected:
|
||||
virtual tBaseClass* clone()
|
||||
{
|
||||
IterImpl* iter = new IterImpl();
|
||||
iter->m_pPStack = m_pPStack;
|
||||
iter->_prof_iter = _prof_iter;
|
||||
return iter;
|
||||
}
|
||||
private:
|
||||
vfs::CProfileStack* m_pPStack;
|
||||
std::list<vfs::CVirtualProfile*>::iterator _prof_iter;
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
vfs::CProfileStack::CProfileStack()
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CProfileStack::~CProfileStack()
|
||||
{
|
||||
std::list<CVirtualProfile*>::iterator it = m_profiles.begin();
|
||||
for(; it != m_profiles.end(); ++it)
|
||||
{
|
||||
delete (*it);
|
||||
(*it) = NULL;
|
||||
}
|
||||
m_profiles.clear();
|
||||
}
|
||||
|
||||
vfs::CVirtualProfile* vfs::CProfileStack::getProfile(utf8string const& sName) const
|
||||
{
|
||||
std::list<CVirtualProfile*>::const_iterator it = m_profiles.begin();
|
||||
for(;it != m_profiles.end(); ++it)
|
||||
{
|
||||
if( StrCmp::EqualCase((*it)->cName, sName) )
|
||||
{
|
||||
return *it;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vfs::CVirtualProfile* vfs::CProfileStack::getWriteProfile()
|
||||
{
|
||||
std::list<vfs::CVirtualProfile*>::const_iterator it = m_profiles.begin();
|
||||
for(;it != m_profiles.end(); ++it)
|
||||
{
|
||||
if((*it)->cWritable)
|
||||
{
|
||||
return *it;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vfs::CVirtualProfile* vfs::CProfileStack::topProfile() const
|
||||
{
|
||||
if(!m_profiles.empty())
|
||||
{
|
||||
return m_profiles.front();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool vfs::CProfileStack::popProfile()
|
||||
{
|
||||
// there might be some files in this profile that are referenced in a CLog object
|
||||
// we need to it to release the file
|
||||
CLog::flushAll();
|
||||
// an observer pattern would probably be the better solution,
|
||||
// but for now lets do it this way
|
||||
|
||||
vfs::CVirtualProfile* prof = this->topProfile();
|
||||
if(prof)
|
||||
{
|
||||
vfs::CVirtualProfile::Iterator loc_it = prof->begin();
|
||||
for(; !loc_it.end(); loc_it.next())
|
||||
{
|
||||
vfs::IBaseLocation* loc = loc_it.value();
|
||||
vfs::IBaseLocation::Iterator f_it = loc->begin();
|
||||
for(; !f_it.end(); f_it.next())
|
||||
{
|
||||
vfs::IBaseFile* file = f_it.value();
|
||||
vfs::Path sDir, sFile;
|
||||
if(file)
|
||||
{
|
||||
file->getPath().splitLast(sDir,sFile);
|
||||
vfs::CVirtualLocation* vloc = getVFS()->getVirtualLocation(sDir);
|
||||
if(vloc)
|
||||
{
|
||||
if( !vloc->removeFile(file) )
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Could not remove file ["
|
||||
<< file->getPath()()
|
||||
<< L"] in Profile ["
|
||||
<< prof->cName << L"]";
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Virtual location [" << sDir() << L"] doesn't exist. Maybe the VFS was not properly setup.";
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"File is NULL during iteration over files in location [" << loc->getPath()() << L"]";
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
// delete only when nothing went wrong
|
||||
this->m_profiles.pop_front();
|
||||
delete prof;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void vfs::CProfileStack::pushProfile(CVirtualProfile* pProfile)
|
||||
{
|
||||
if(!getProfile(pProfile->cName))
|
||||
{
|
||||
m_profiles.push_front(pProfile);
|
||||
return;
|
||||
}
|
||||
THROWEXCEPTION(L"A profile with this name already exists");
|
||||
}
|
||||
|
||||
vfs::CProfileStack::Iterator vfs::CProfileStack::begin()
|
||||
{
|
||||
return Iterator(new IterImpl(this));
|
||||
}
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
#ifndef _VFS_PROFILE_H_
|
||||
#define _VFS_PROFILE_H_
|
||||
|
||||
#include "vfs_types.h"
|
||||
#include "Interface/vfs_location_interface.h"
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class VFS_API CVirtualProfile
|
||||
{
|
||||
typedef std::map<vfs::Path,vfs::IBaseLocation*, vfs::Path::Less> tLocations;
|
||||
typedef std::set<vfs::IBaseLocation*> tUniqueLoc;
|
||||
|
||||
class IterImpl;
|
||||
class FileIterImpl;
|
||||
public:
|
||||
typedef TIterator<vfs::IBaseLocation> Iterator;
|
||||
typedef TIterator<vfs::IBaseFile> FileIterator;
|
||||
|
||||
CVirtualProfile(utf8string const& sProfileName, bool bWritable = false);
|
||||
~CVirtualProfile();
|
||||
|
||||
const utf8string cName;
|
||||
const bool cWritable;
|
||||
|
||||
Iterator begin();
|
||||
FileIterator files(vfs::Path const& sPattern);
|
||||
|
||||
void addLocation(vfs::IBaseLocation* pLoc);
|
||||
vfs::IBaseLocation* getLocation(vfs::Path const& sPath) const;
|
||||
vfs::IBaseFile* getFile(vfs::Path const& sPath) const;
|
||||
private:
|
||||
void operator=(vfs::CVirtualProfile const& vprof);
|
||||
tLocations m_mapLocations;
|
||||
tUniqueLoc m_setLocations;
|
||||
};
|
||||
|
||||
class VFS_API CProfileStack
|
||||
{
|
||||
class IterImpl;
|
||||
public:
|
||||
typedef vfs::TIterator<CVirtualProfile> Iterator;
|
||||
|
||||
CProfileStack();
|
||||
~CProfileStack();
|
||||
|
||||
CVirtualProfile* getWriteProfile();
|
||||
CVirtualProfile* getProfile(utf8string const& sName) const;
|
||||
|
||||
CVirtualProfile* topProfile() const;
|
||||
/**
|
||||
* All files from the top profile will be removed from the VFS and the profile object will be deleted.
|
||||
*/
|
||||
bool popProfile();
|
||||
void pushProfile(CVirtualProfile* pProfile);
|
||||
|
||||
Iterator begin();
|
||||
private:
|
||||
std::list<vfs::CVirtualProfile*> m_profiles;
|
||||
};
|
||||
|
||||
} // end namespace
|
||||
|
||||
#endif
|
||||
@@ -1,13 +0,0 @@
|
||||
#include "vfs_settings.h"
|
||||
|
||||
static bool s_UseUnicode = true;
|
||||
|
||||
void vfs::Settings::setUseUnicode(bool useUnicode)
|
||||
{
|
||||
s_UseUnicode = useUnicode;
|
||||
}
|
||||
|
||||
bool vfs::Settings::getUseUnicode()
|
||||
{
|
||||
return s_UseUnicode;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
#ifndef _VFS_SETTIGNS_H_
|
||||
#define _VFS_SETTIGNS_H_
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class Settings
|
||||
{
|
||||
public:
|
||||
static void setUseUnicode(bool useUnicode);
|
||||
static bool getUseUnicode();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // _VFS_SETTIGNS_H_
|
||||
@@ -1,115 +0,0 @@
|
||||
#include "vfs_types.h"
|
||||
#include "vfs_debug.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
const vfs::size_t npos = vfs::size_t(-1);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<>
|
||||
std::string vfs::trimString<std::string>(std::string const& sStr, vfs::size_t iMinPos, vfs::size_t iMaxPos)
|
||||
{
|
||||
if(iMinPos >= iMaxPos || iMaxPos == vfs::npos)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
::size_t iStart,iEnd;
|
||||
iStart = sStr.find_first_not_of(" \t\r\n",(::size_t)iMinPos);
|
||||
iEnd = sStr.find_last_not_of(" \t\r\n",(::size_t)iMaxPos);
|
||||
if( (iStart != std::string::npos) && (iEnd != std::string::npos) )
|
||||
{
|
||||
return sStr.substr(iStart,iEnd-iStart+1);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
template<>
|
||||
std::wstring vfs::trimString<std::wstring>(std::wstring const& sStr, vfs::size_t iMinPos, vfs::size_t iMaxPos)
|
||||
{
|
||||
if(iMinPos >= iMaxPos || iMaxPos == vfs::npos)
|
||||
{
|
||||
return L"";
|
||||
}
|
||||
::size_t iStart,iEnd;
|
||||
iStart = sStr.find_first_not_of(L" \t\r\n",(::size_t)iMinPos);
|
||||
iEnd = sStr.find_last_not_of(L" \t\r\n",(::size_t)iMaxPos);
|
||||
if( (iStart != std::wstring::npos) && (iEnd != std::wstring::npos) )
|
||||
{
|
||||
return sStr.substr(iStart,iEnd-iStart+1);
|
||||
}
|
||||
return L"";
|
||||
}
|
||||
template<>
|
||||
utf8string vfs::trimString<utf8string>(utf8string const& sStr, vfs::size_t iMinPos, vfs::size_t iMaxPos)
|
||||
{
|
||||
return vfs::trimString(sStr.c_wcs(), iMinPos, iMaxPos);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<>
|
||||
BuildString& BuildString::add<utf8string>(utf8string const& value)
|
||||
{
|
||||
this->add(value.c_str());
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* try to recursively match the pattern
|
||||
*/
|
||||
bool matchPattern(utf8string const& sPattern, utf8string const& sStr)
|
||||
{
|
||||
return matchPattern(sPattern,sStr.c_wcs());
|
||||
}
|
||||
|
||||
bool matchPattern(utf8string const& sPattern, utf8string::str_t const& sStr)
|
||||
{
|
||||
utf8string::str_t const& pat = sPattern.c_wcs();
|
||||
|
||||
utf8string::size_t star = pat.find_first_of(vfs::Const::STAR());
|
||||
if(star == utf8string::str_t::npos)
|
||||
{
|
||||
return StrCmp::Equal( pat, sStr );
|
||||
}
|
||||
else if(star == 0)
|
||||
{
|
||||
if(pat.length() == 1)
|
||||
{
|
||||
// there is only the '*' -> matches all strings
|
||||
return true;
|
||||
}
|
||||
utf8string::char_t atpos1 = pat.at(1);
|
||||
utf8string::size_t match = utf8string::size_t(-1);
|
||||
do
|
||||
{
|
||||
match = sStr.find_first_of(atpos1,match+1);
|
||||
if(match == utf8string::str_t::npos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} while(!matchPattern( pat.substr(1,pat.length()-1), sStr.substr(match,sStr.length()-match) ));
|
||||
return true;
|
||||
}
|
||||
else // if(star > 0)
|
||||
{
|
||||
// check if characters before * match
|
||||
if(!StrCmp::Equal(pat.substr(0,star), sStr.substr(0,star)) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return matchPattern( pat.substr(star,pat.length()-star), sStr.substr(star,sStr.length()-star) );
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
-164
@@ -1,164 +0,0 @@
|
||||
#ifndef _VFS_TYPES_H_
|
||||
#define _VFS_TYPES_H_
|
||||
|
||||
#include <iostream>
|
||||
#include "utf8string.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
#ifdef WIN32
|
||||
typedef unsigned __int64 UInt64;
|
||||
typedef unsigned __int32 UInt32;
|
||||
typedef unsigned __int16 UInt16;
|
||||
typedef unsigned __int8 UInt8;
|
||||
typedef unsigned __int8 UByte;
|
||||
|
||||
typedef __int64 Int64;
|
||||
typedef __int32 Int32;
|
||||
typedef __int16 Int16;
|
||||
typedef __int8 Int8;
|
||||
typedef __int8 Byte;
|
||||
#elif __linux__
|
||||
typedef uint64_t UInt64;
|
||||
typedef uint32_t UInt32;
|
||||
typedef uint16_t UInt16;
|
||||
typedef uint8_t UInt8;
|
||||
typedef uint8_t UByte;
|
||||
|
||||
typedef int64_t Int64;
|
||||
typedef int32_t Int32;
|
||||
typedef int16_t Int16;
|
||||
typedef int8_t Int8;
|
||||
typedef char Byte;
|
||||
#endif
|
||||
|
||||
typedef ::size_t size_t;
|
||||
typedef ::off_t offset_t;
|
||||
|
||||
extern const vfs::size_t npos;
|
||||
}
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
namespace Const
|
||||
{
|
||||
inline const utf8string::str_t EMPTY() { return L""; };
|
||||
//inline const utf8string::char_t EMPTY_CHAR() { return L''; };
|
||||
|
||||
inline const utf8string::str_t DOT() { return L"."; };
|
||||
inline const utf8string::char_t DOT_CHAR() { return L'.'; };
|
||||
|
||||
inline const utf8string::str_t DOTDOT() { return L".."; };
|
||||
inline const utf8string::str_t DOTSVN() { return L".svn"; };
|
||||
|
||||
inline const utf8string::str_t STAR() { return L"*"; };
|
||||
inline const utf8string::str_t DSTAR() { return L"**"; };
|
||||
|
||||
#ifdef WIN32
|
||||
inline const utf8string::str_t SEPARATOR() { return L"\\"; };
|
||||
inline const utf8string::char_t SEPARATOR_CHAR() { return L'\\'; };
|
||||
#else
|
||||
inline const utf8string::str_t SEPARATOR() { return L"/"; };
|
||||
inline const utf8string::char_t SEPARATOR_CHAR() { return L'/'; };
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
// remove leading and trailing white characters;
|
||||
template<typename StringType>
|
||||
StringType trimString(StringType const& sStr, vfs::size_t iMinPos, vfs::size_t iMaxPos);
|
||||
|
||||
template<>
|
||||
std::string trimString<std::string>(std::string const& sStr, vfs::size_t iMinPos, vfs::size_t iMaxPos);
|
||||
|
||||
template<>
|
||||
std::wstring trimString<std::wstring>(std::wstring const& sStr, vfs::size_t iMinPos, vfs::size_t iMaxPos);
|
||||
|
||||
template<>
|
||||
utf8string trimString<utf8string>(utf8string const& sStr, vfs::size_t iMinPos, vfs::size_t iMaxPos);
|
||||
}
|
||||
|
||||
class VFS_API BuildString
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
BuildString& add(T const& value)
|
||||
{
|
||||
_strstr << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
utf8string::str_t get()
|
||||
{
|
||||
return _strstr.str();
|
||||
}
|
||||
private:
|
||||
std::basic_stringstream<utf8string::char_t> _strstr;
|
||||
};
|
||||
|
||||
template<>
|
||||
BuildString& BuildString::add<utf8string>(utf8string const& value);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
bool matchPattern(utf8string const& sPattern, utf8string const& sStr);
|
||||
bool matchPattern(utf8string const& sPattern, utf8string::str_t const& sStr);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
class BasicAllocator
|
||||
{
|
||||
public:
|
||||
virtual ~BasicAllocator() {};
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class ObjBlockAllocator : public BasicAllocator
|
||||
{
|
||||
public:
|
||||
ObjBlockAllocator(unsigned int blockSize=1024)
|
||||
: BasicAllocator(), BLOCK_SIZE(blockSize), _ObjNew(0) {};
|
||||
const unsigned int BLOCK_SIZE;
|
||||
///
|
||||
T* New(unsigned int *ID = NULL)
|
||||
{
|
||||
unsigned int block_id = _ObjNew/BLOCK_SIZE;
|
||||
unsigned int file_id = _ObjNew % BLOCK_SIZE;
|
||||
if(block_id >= _ObjPool.size())
|
||||
{
|
||||
tBlock* b = new tBlock();
|
||||
b->resize(BLOCK_SIZE);
|
||||
_ObjPool.push_back(b);
|
||||
}
|
||||
tBlock* block = _ObjPool[block_id];
|
||||
T* obj = &(*block)[file_id];
|
||||
if(ID)
|
||||
{
|
||||
*ID = _ObjNew;
|
||||
}
|
||||
_ObjNew++;
|
||||
return obj;
|
||||
}
|
||||
///
|
||||
virtual ~ObjBlockAllocator()
|
||||
{
|
||||
for(unsigned int i = 0; i < _ObjPool.size(); ++i)
|
||||
{
|
||||
delete _ObjPool[i];
|
||||
}
|
||||
}
|
||||
private:
|
||||
void operator=(ObjBlockAllocator<T> const& t);
|
||||
|
||||
typedef std::vector<T> tBlock;
|
||||
std::vector<tBlock*> _ObjPool;
|
||||
unsigned int _ObjNew;
|
||||
};
|
||||
|
||||
#endif // _VFS_TYPES_H_
|
||||
@@ -1,197 +0,0 @@
|
||||
#include "vfs_vfile.h"
|
||||
#include "vfs_vloc.h"
|
||||
#include "vfs.h"
|
||||
|
||||
// static member
|
||||
ObjBlockAllocator<vfs::CVirtualFile>* vfs::CVirtualFile::_vfile_pool = NULL;
|
||||
|
||||
vfs::CVirtualFile* vfs::CVirtualFile::create(vfs::Path const& sFilePath, vfs::CProfileStack& rPStack)
|
||||
{
|
||||
unsigned int ID=0;
|
||||
#ifdef VFILE_BLOCK_CREATE
|
||||
if(!_vfile_pool)
|
||||
{
|
||||
_vfile_pool = new ObjBlockAllocator<vfs::CVirtualFile>();
|
||||
CFileAllocator::registerAllocator(_vfile_pool);
|
||||
}
|
||||
CVirtualFile* file = _vfile_pool->New(&ID);
|
||||
#else
|
||||
CVirtualFile* file = new CVirtualFile();
|
||||
#endif
|
||||
file->_path = sFilePath;
|
||||
file->_pstack = &rPStack;
|
||||
file->_myID = ID;
|
||||
return file;
|
||||
}
|
||||
|
||||
void vfs::CVirtualFile::destroy()
|
||||
{
|
||||
#ifndef VFILE_BLOCK_CREATE
|
||||
delete this;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
vfs::CVirtualFile::CVirtualFile()
|
||||
: _path(L""), _top_pname(L"_INVALID_"), _top_file(NULL), _pstack(NULL), _myID(vfs::UInt32(-1))
|
||||
{
|
||||
};
|
||||
|
||||
vfs::CVirtualFile::~CVirtualFile()
|
||||
{
|
||||
}
|
||||
|
||||
vfs::Path const& vfs::CVirtualFile::path()
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
|
||||
void vfs::CVirtualFile::add(vfs::IBaseFile *pFile, utf8string sProfileName, bool bReplace)
|
||||
{
|
||||
if(pFile)
|
||||
{
|
||||
// if there is no file then just set it
|
||||
// if bReplace is set to true then override all other settings and just set the file
|
||||
if(!_top_file || bReplace)
|
||||
{
|
||||
_top_file = pFile;
|
||||
_top_pname = sProfileName;
|
||||
return;
|
||||
}
|
||||
// file already set, but new file is? exacly the same file
|
||||
if(pFile == _top_file)
|
||||
{
|
||||
THROWIFFALSE( StrCmp::Equal(sProfileName,_top_pname), L"same file, different profile name");
|
||||
}
|
||||
// OK, not the same file, but these two different files are supposed to have the asme filename
|
||||
THROWIFFALSE( _top_file->getName() == pFile->getName(), L"different filenames");
|
||||
// set new file only when its profile is on top of the current file's profile
|
||||
bool bFoundOld = false, bFoundNew = false;
|
||||
vfs::CProfileStack::Iterator it = _pstack->begin();
|
||||
for(; !it.end(); it.next())
|
||||
{
|
||||
if(_top_pname == it.value()->cName)
|
||||
{
|
||||
bFoundOld = true;
|
||||
break;
|
||||
}
|
||||
else if(sProfileName == it.value()->cName)
|
||||
{
|
||||
bFoundNew = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(bFoundNew && !bFoundOld)
|
||||
{
|
||||
_top_file = pFile;
|
||||
_top_pname = sProfileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns : returns true if pFile is not top file or top file could be replaced with another file
|
||||
* returns false if there is no more files with given name. in this case object should be destroyed
|
||||
*/
|
||||
bool vfs::CVirtualFile::remove(vfs::IBaseFile *pFile)
|
||||
{
|
||||
if(_top_file == pFile)
|
||||
{
|
||||
if(_path == pFile->getPath())
|
||||
{
|
||||
// need to replace '_top_file'
|
||||
vfs::CProfileStack::Iterator prof_it = _pstack->begin();
|
||||
for(; !prof_it.end(); prof_it.next())
|
||||
{
|
||||
CVirtualProfile *pProf = prof_it.value();
|
||||
if(pProf)
|
||||
{
|
||||
vfs::IBaseFile *file = pProf->getFile(_path);
|
||||
if(file && (file != pFile))
|
||||
{
|
||||
_top_file = file;
|
||||
_top_pname = pProf->cName;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// no more files
|
||||
_top_file = NULL;
|
||||
_top_pname = "";
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
THROWEXCEPTION(L"Same file object but different file paths? WTH?");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
vfs::IBaseFile* vfs::CVirtualFile::file(ESearchFile eSearch)
|
||||
{
|
||||
if(eSearch == SF_TOP)
|
||||
{
|
||||
return _top_file;
|
||||
}
|
||||
else if(eSearch == SF_FIRST_WRITABLE)
|
||||
{
|
||||
CVirtualProfile *pVProf = _pstack->getWriteProfile();
|
||||
if(pVProf)
|
||||
{
|
||||
return pVProf->getFile(_path);
|
||||
}
|
||||
}
|
||||
else if(eSearch == SF_STOP_ON_WRITABLE_PROFILE)
|
||||
{
|
||||
vfs::CProfileStack::Iterator prof_it = _pstack->begin();
|
||||
for(; !prof_it.end(); prof_it.next())
|
||||
{
|
||||
CVirtualProfile *pProf = prof_it.value();
|
||||
if(pProf)
|
||||
{
|
||||
if(pProf->cWritable)
|
||||
{
|
||||
return pProf->getFile(_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
vfs::IBaseFile *pFile = pProf->getFile(_path);
|
||||
if(pFile)
|
||||
{
|
||||
return pFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vfs::IBaseFile* vfs::CVirtualFile::file(utf8string const& sProfileName)
|
||||
{
|
||||
if(sProfileName == _top_pname)
|
||||
{
|
||||
return vfs::tReadableFile::cast(_top_file);
|
||||
}
|
||||
else
|
||||
{
|
||||
CVirtualProfile* pProf = _pstack->getProfile(sProfileName);
|
||||
if(pProf)
|
||||
{
|
||||
CVirtualProfile::Iterator loc_it = pProf->begin();
|
||||
for(; !loc_it.end(); loc_it.next())
|
||||
{
|
||||
if(loc_it.value() && loc_it.value()->fileExists(_path))
|
||||
{
|
||||
if(loc_it.value())
|
||||
{
|
||||
return loc_it.value()->getFile(_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
#ifndef _VFS_VFILE_H_
|
||||
#define _VFS_VFILE_H_
|
||||
|
||||
#include "vfs_profile.h"
|
||||
#include <vector>
|
||||
|
||||
#define VFILE_BLOCK_CREATE
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class CVirtualFile
|
||||
{
|
||||
public:
|
||||
enum ESearchFile
|
||||
{
|
||||
SF_TOP,
|
||||
SF_FIRST_WRITABLE,
|
||||
SF_STOP_ON_WRITABLE_PROFILE,
|
||||
};
|
||||
public:
|
||||
CVirtualFile();
|
||||
~CVirtualFile();
|
||||
void destroy();
|
||||
static CVirtualFile* create(vfs::Path const& sFilePath, vfs::CProfileStack& rPStack);
|
||||
|
||||
vfs::Path const& path();
|
||||
void add(vfs::IBaseFile *pFile, utf8string sProfileName, bool bReplace = false);
|
||||
bool remove(vfs::IBaseFile *pFile);
|
||||
//////////////////////////////////////////////////
|
||||
vfs::IBaseFile* file(ESearchFile eSearch);
|
||||
vfs::IBaseFile* file(utf8string const& sProfileName);
|
||||
//////////////////////////////////////////////////
|
||||
private:
|
||||
vfs::Path _path;
|
||||
utf8string _top_pname;
|
||||
vfs::IBaseFile* _top_file;
|
||||
CProfileStack* _pstack;
|
||||
private:
|
||||
vfs::UInt32 _myID;
|
||||
#ifdef VFILE_BLOCK_CREATE
|
||||
static ObjBlockAllocator<vfs::CVirtualFile>* _vfile_pool;
|
||||
#endif
|
||||
};
|
||||
} // end namspace
|
||||
|
||||
#endif // _VFS_VFILE_H_
|
||||
@@ -1,149 +0,0 @@
|
||||
#include "vfs_vloc.h"
|
||||
#include "vfs_vfile.h"
|
||||
#include "vfs_profile.h"
|
||||
#include "vfs.h"
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
class vfs::CVirtualLocation::VFileIterator : public vfs::CVirtualLocation::Iterator::IImplementation
|
||||
{
|
||||
friend class vfs::CVirtualLocation;
|
||||
typedef vfs::CVirtualLocation::Iterator::IImplementation tBaseClass;
|
||||
|
||||
VFileIterator(vfs::CVirtualLocation* pLoc): tBaseClass(), m_pLoc(pLoc)
|
||||
{
|
||||
THROWIFFALSE(pLoc, L"");
|
||||
_vfile_iter = m_pLoc->m_VFiles.begin();
|
||||
}
|
||||
public:
|
||||
VFileIterator() : tBaseClass(), m_pLoc(NULL)
|
||||
{};
|
||||
virtual ~VFileIterator()
|
||||
{};
|
||||
virtual vfs::CVirtualFile* value()
|
||||
{
|
||||
if(m_pLoc && _vfile_iter != m_pLoc->m_VFiles.end())
|
||||
{
|
||||
return _vfile_iter->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
virtual void next()
|
||||
{
|
||||
if(m_pLoc && _vfile_iter != m_pLoc->m_VFiles.end())
|
||||
{
|
||||
_vfile_iter++;
|
||||
}
|
||||
}
|
||||
protected:
|
||||
virtual tBaseClass* clone()
|
||||
{
|
||||
VFileIterator* iter = new VFileIterator(m_pLoc);
|
||||
iter->_vfile_iter = _vfile_iter;
|
||||
return iter;
|
||||
}
|
||||
private:
|
||||
vfs::CVirtualLocation* m_pLoc;
|
||||
vfs::CVirtualLocation::tVFiles::iterator _vfile_iter;
|
||||
};
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
vfs::CVirtualLocation::CVirtualLocation(vfs::Path const& path)
|
||||
: cPath(path), m_exclusive(false)
|
||||
{};
|
||||
|
||||
vfs::CVirtualLocation::~CVirtualLocation()
|
||||
{
|
||||
tVFiles::iterator it = m_VFiles.begin();
|
||||
for(; it != m_VFiles.end(); ++it)
|
||||
{
|
||||
it->second->destroy();
|
||||
}
|
||||
m_VFiles.clear();
|
||||
}
|
||||
|
||||
void vfs::CVirtualLocation::setIsExclusive(bool exclusive)
|
||||
{
|
||||
m_exclusive = exclusive;
|
||||
}
|
||||
bool vfs::CVirtualLocation::getIsExclusive()
|
||||
{
|
||||
return m_exclusive;
|
||||
}
|
||||
|
||||
void vfs::CVirtualLocation::addFile(vfs::IBaseFile* file, utf8string const& profileName)
|
||||
{
|
||||
tVFiles::iterator it = m_VFiles.find(file->getName());
|
||||
vfs::CVirtualFile *pVFile = NULL;
|
||||
if(it == m_VFiles.end())
|
||||
{
|
||||
vfs::Path fp = file->getPath();
|
||||
vfs::CProfileStack& stack = *(getVFS()->getProfileStack());
|
||||
pVFile = vfs::CVirtualFile::create(fp,stack);
|
||||
it = m_VFiles.insert(m_VFiles.end(), std::pair<vfs::Path,vfs::CVirtualFile*>(file->getName(),pVFile));
|
||||
}
|
||||
it->second->add(file,profileName,true);
|
||||
}
|
||||
|
||||
vfs::IBaseFile* vfs::CVirtualLocation::getFile(vfs::Path const& filename, utf8string const& profileName) const
|
||||
{
|
||||
tVFiles::const_iterator cit = m_VFiles.find(filename);
|
||||
if(cit != m_VFiles.end() && cit->second)
|
||||
{
|
||||
if(profileName.empty())
|
||||
{
|
||||
if(m_exclusive)
|
||||
{
|
||||
return cit->second->file(vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE);
|
||||
}
|
||||
else
|
||||
{
|
||||
return cit->second->file(vfs::CVirtualFile::SF_TOP);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// you know what you are doing
|
||||
return cit->second->file(profileName);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
vfs::CVirtualFile* vfs::CVirtualLocation::getVirtualFile(vfs::Path const& filename)
|
||||
{
|
||||
tVFiles::const_iterator cit = m_VFiles.find(filename);
|
||||
if(cit != m_VFiles.end())
|
||||
{
|
||||
return cit->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool vfs::CVirtualLocation::removeFile(vfs::IBaseFile* file)
|
||||
{
|
||||
if(file)
|
||||
{
|
||||
vfs::Path sDir,sFile;
|
||||
file->getPath().splitLast(sDir,sFile);
|
||||
tVFiles::iterator it = m_VFiles.find(sFile);
|
||||
if(it != m_VFiles.end())
|
||||
{
|
||||
if(!it->second->remove(file))
|
||||
{
|
||||
//CVirtualFile* vfile = it->second;
|
||||
//delete vfile;
|
||||
m_VFiles.erase(it);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
vfs::CVirtualLocation::Iterator vfs::CVirtualLocation::iterate()
|
||||
{
|
||||
return Iterator(new VFileIterator(this));
|
||||
}
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
#ifndef _VFS_VLOC_H_
|
||||
#define _VFS_VLOC_H_
|
||||
|
||||
#include "vfs_types.h"
|
||||
#include "Interface/vfs_file_interface.h"
|
||||
#include "Interface/vfs_iterator_interface.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class CVirtualFile;
|
||||
|
||||
class CVirtualLocation
|
||||
{
|
||||
class VFileIterator;
|
||||
typedef std::map<vfs::Path, CVirtualFile*, vfs::Path::Less> tVFiles;
|
||||
public:
|
||||
typedef vfs::TIterator<CVirtualFile> Iterator;
|
||||
|
||||
CVirtualLocation(vfs::Path const& sPath);
|
||||
~CVirtualLocation();
|
||||
|
||||
const vfs::Path cPath;
|
||||
|
||||
void setIsExclusive(bool exclusive);
|
||||
bool getIsExclusive();
|
||||
|
||||
void addFile(vfs::IBaseFile* pile, utf8string const& profileName);
|
||||
vfs::IBaseFile* getFile(vfs::Path const& filename, utf8string const& profileName = "") const;
|
||||
vfs::CVirtualFile* getVirtualFile(vfs::Path const& filename);
|
||||
|
||||
bool removeFile(vfs::IBaseFile* file);
|
||||
|
||||
Iterator iterate();
|
||||
private:
|
||||
void operator=(vfs::CVirtualLocation const& vloc);
|
||||
|
||||
bool m_exclusive;
|
||||
tVFiles m_VFiles;
|
||||
};
|
||||
} // end namespace
|
||||
|
||||
#endif // _VFS_VLOC_H_
|
||||
Reference in New Issue
Block a user