*
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
#include "IFSContentProvider.h"
|
||||
#include "../../log/CLog.h"
|
||||
namespace LifeCore
|
||||
{
|
||||
static const String pakPathSplitter(_text("\\"));
|
||||
|
||||
IFSContentProvider::IFSContentProvider(const String& file)
|
||||
{
|
||||
IFSFolder* folder = new IFSFolder();
|
||||
g_rootFolder = file;
|
||||
folder->Provider = this;
|
||||
folder->Name = GetDirectoryName(file);
|
||||
|
||||
folder->EntryName = file;
|
||||
|
||||
fileSystem = new IFileSystem(folder);
|
||||
|
||||
IFolder* root = fileSystem->GetRootFolder();
|
||||
|
||||
//printf("%s", file.c_str());
|
||||
ScanDir(file, root);
|
||||
}
|
||||
IFSContentProvider::~IFSContentProvider()
|
||||
{
|
||||
if(fileSystem)
|
||||
delete fileSystem;
|
||||
}
|
||||
void IFSContentProvider::ScanDir( String path, IFolder* directory)
|
||||
{
|
||||
WIN32_FIND_DATA FindData;
|
||||
String modified_address = path;
|
||||
DWORD tmp = 0;
|
||||
modified_address += _text("*");
|
||||
HANDLE Handle = FindFirstFile(modified_address.c_str() , &FindData);
|
||||
while( FindNextFile(Handle, &FindData) )
|
||||
{
|
||||
String file_name = FindData.cFileName;
|
||||
if( FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
|
||||
{
|
||||
if(STRCMP(FindData.cFileName, _text("..")))
|
||||
{
|
||||
String new_path = path;
|
||||
new_path += file_name;
|
||||
new_path += _text("\\");
|
||||
|
||||
IFSFolder* folder = new IFSFolder();
|
||||
folder->Provider = this;
|
||||
folder->Name = file_name;
|
||||
folder->EntryName = new_path;
|
||||
directory->AddFolder(folder);
|
||||
ScanDir( new_path, folder );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
String filepath = path + file_name;
|
||||
HANDLE hf = CreateFile(filepath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
IFSFile* file = new IFSFile();
|
||||
file->FileName = file_name;
|
||||
file->Provider = this;
|
||||
file->Size = GetFileSize(hf,&tmp);
|
||||
file->EntryName = filepath;
|
||||
directory->AddFile(file);
|
||||
CloseHandle(hf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef IFSCONTENTPROVIDER_H__
|
||||
#define IFSCONTENTPROVIDER_H__
|
||||
|
||||
#include "../IContentProvider.h"
|
||||
#include "../../LString.h"
|
||||
#include "../IFileSystem.h"
|
||||
#include "IFSFolder.h"
|
||||
#include <windows.h>
|
||||
|
||||
namespace LifeCore
|
||||
{
|
||||
class IFSContentProvider : public IContentProvider
|
||||
{
|
||||
public:
|
||||
~IFSContentProvider();
|
||||
void Close(){}
|
||||
IFileSystem* getFileSystem(){return fileSystem;}
|
||||
IFSContentProvider(const String& file);
|
||||
String g_rootFolder;
|
||||
IFileSystem* fileSystem;
|
||||
|
||||
private:
|
||||
void ScanDir( String path, IFolder* directory);
|
||||
};
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,62 @@
|
||||
#include "IFSFile.h"
|
||||
#include "IFSContentProvider.h"
|
||||
|
||||
namespace LifeCore
|
||||
{
|
||||
IFSFile::IFSFile()
|
||||
{
|
||||
}
|
||||
IFSFile::IFSFile(const String& path, int size)
|
||||
{
|
||||
isOpen = false;
|
||||
EntryName = path;
|
||||
HANDLE file = CreateFileA(path.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if(GetLastError() != ERROR_ALREADY_EXISTS)
|
||||
{
|
||||
if(size > 0)
|
||||
{
|
||||
SetFilePointer(file, size - 1, 0, FILE_BEGIN);
|
||||
char data = 0;
|
||||
DWORD numWrite = 0;
|
||||
WriteFile(file, &data, 1, &numWrite, NULL);
|
||||
}
|
||||
}
|
||||
CloseHandle(file);
|
||||
}
|
||||
|
||||
bool IFSFile::ReadAsync(char* buffer, size_t count_read)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(buffer);
|
||||
UNREFERENCED_PARAMETER(count_read);
|
||||
//TODO read!
|
||||
return true;
|
||||
}
|
||||
IDataStreamPtr IFSFile::OpenWrite(int mode)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(mode);
|
||||
g_stream = new IFSStream(EntryName, FA_WRITE, this->Size);
|
||||
return IDataStreamPtr(g_stream);
|
||||
}
|
||||
IDataStreamPtr IFSFile::OpenReadWrite(int mode)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(mode);
|
||||
return IDataStreamPtr(0);
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
IDataStreamPtr IFSFile::OpenRead()
|
||||
{
|
||||
g_stream = new IFSStream(EntryName, FA_READ, this->Size);
|
||||
return IDataStreamPtr(g_stream);
|
||||
//g_stream = new IZipStream((this->Provider as IZipFileContentProvider).GetSource(), EntryName, FA_READ);
|
||||
//return g_stream;
|
||||
}
|
||||
void IFSFile::Close()
|
||||
{
|
||||
if(g_stream)
|
||||
{
|
||||
g_stream->Close();
|
||||
delete g_stream;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef IFSFILE_H__
|
||||
#define IFSFILE_H__
|
||||
|
||||
//#include "IDataStream.h"
|
||||
#include "../../LString.h"
|
||||
#include "../IFile.h"
|
||||
#include "IFSStream.h"
|
||||
|
||||
namespace LifeCore
|
||||
{
|
||||
class IFSFile : public IFile
|
||||
{
|
||||
public:
|
||||
IFSFile();
|
||||
IFSFile(const String& path, int size);
|
||||
~IFSFile(){}
|
||||
String EntryName;
|
||||
bool ReadAsync(char* buffer, size_t count_read);
|
||||
IDataStreamPtr OpenWrite(int mode);
|
||||
IDataStreamPtr OpenReadWrite(int mode);
|
||||
IDataStreamPtr OpenRead();
|
||||
void Close();
|
||||
private:
|
||||
int offsetIndex;
|
||||
IFSStream* g_stream;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,53 @@
|
||||
#include "IFSFolder.h"
|
||||
|
||||
namespace LifeCore
|
||||
{
|
||||
IFSFolder::~IFSFolder(void)
|
||||
{
|
||||
for( FolderMap::iterator it = g_folderCollection.begin(); it != g_folderCollection.end(); it++ )
|
||||
delete it->second;
|
||||
}
|
||||
IFSFolder::IFSFolder()
|
||||
|
||||
{
|
||||
}
|
||||
IFSFolder::IFSFolder(const String& folderName, const String& entryName)
|
||||
{
|
||||
this->Name = folderName;
|
||||
this->EntryName = entryName;
|
||||
|
||||
CreateDirectoryA(EntryName.c_str(), NULL);
|
||||
}
|
||||
IFolder* IFSFolder::NewFolder(const String& name)
|
||||
{
|
||||
IFolder* test;
|
||||
if(this->GetFolder(name, &test) != SC_OK)
|
||||
{
|
||||
IFSFolder* newFolder = new IFSFolder(name, this->EntryName + name + _text("\\"));
|
||||
newFolder->setParent(this);
|
||||
newFolder->Provider = this->Provider;
|
||||
this->AddFolder(newFolder);
|
||||
return newFolder;
|
||||
}
|
||||
else
|
||||
{
|
||||
return test;
|
||||
}
|
||||
}
|
||||
IFile* IFSFolder::NewFile(const String& name, int size)
|
||||
{
|
||||
IFile* f;
|
||||
if(this->GetFile(name, &f) != SC_OK)
|
||||
{
|
||||
IFSFile* newFile = new IFSFile(this->EntryName + name, size);
|
||||
newFile->FileName = name;
|
||||
newFile->Provider = this->Provider;
|
||||
this->AddFile(newFile);
|
||||
return newFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
return f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef IFSFOLDER_H__
|
||||
#define IFSFOLDER_H__
|
||||
|
||||
#include "../../IDataStream.h"
|
||||
#include "../../LString.h"
|
||||
#include "../IFolder.h"
|
||||
#include "IFSFile.h"
|
||||
#include "../IContentProvider.h"
|
||||
#include <map>
|
||||
|
||||
namespace LifeCore
|
||||
{
|
||||
class IFSFolder : public IFolder
|
||||
{
|
||||
public:
|
||||
IFSFolder();
|
||||
IFSFolder(const String& folderName, const String& entryName);
|
||||
~IFSFolder(void);
|
||||
IContentProvider* Provider;
|
||||
String EntryName;
|
||||
IFolder* NewFolder(const String& name);
|
||||
IFile* NewFile(const String& name, int size);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,86 @@
|
||||
#ifndef IFSSTREAM_H__
|
||||
#define IFSSTREAM_H__
|
||||
|
||||
#include "../../IDataStream.h"
|
||||
#include "../../LString.h"
|
||||
#include <assert.h>
|
||||
#include <windows.h>
|
||||
|
||||
namespace LifeCore
|
||||
{
|
||||
class IFSStream : public IDataStream
|
||||
{
|
||||
private:
|
||||
int openMode;
|
||||
size_t stmLength;
|
||||
HANDLE pFile;
|
||||
public:
|
||||
~IFSStream()
|
||||
{
|
||||
//printf("DESTRUCTING WIN FILE STREAM\n");
|
||||
Close();
|
||||
}
|
||||
void Close()
|
||||
{
|
||||
//printf("CLOSING WIN FILE STREAM\n");
|
||||
if(pFile)
|
||||
CloseHandle(pFile);
|
||||
pFile = (HANDLE)0;
|
||||
}
|
||||
IFSStream(String& path, int fileAccessMode, size_t size)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(size);
|
||||
this->stmLength = 0;
|
||||
openMode = fileAccessMode;
|
||||
if (fileAccessMode == FA_READ)
|
||||
{
|
||||
pFile = CreateFileA(path.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
pFile = CreateFileA(path.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
}
|
||||
|
||||
this->stmLength = SetFilePointer(pFile, 0, NULL, FILE_END);
|
||||
SetFilePointer(pFile, 0, NULL, FILE_BEGIN);
|
||||
}
|
||||
size_t Read(void* pBuffer, size_t countBytes)
|
||||
{
|
||||
DWORD numBytes = 0;
|
||||
|
||||
ReadFile(pFile,pBuffer,countBytes, &numBytes, NULL);
|
||||
return numBytes;
|
||||
}
|
||||
size_t Write(const void* pBuffer, size_t countBytes)
|
||||
{
|
||||
DWORD numBytes = 0;
|
||||
WriteFile(pFile,pBuffer,countBytes,&numBytes, NULL);
|
||||
return numBytes;
|
||||
}
|
||||
void Seek(size_t position)
|
||||
{
|
||||
SetFilePointer(pFile, position, NULL, FILE_BEGIN);
|
||||
}
|
||||
size_t Tell()
|
||||
{
|
||||
return SetFilePointer(pFile, 0, NULL, FILE_CURRENT);
|
||||
}
|
||||
size_t Length()
|
||||
{
|
||||
int pos = Tell();
|
||||
int length = SetFilePointer(pFile, 0, NULL, SEEK_END);
|
||||
SetFilePointer(pFile, pos, NULL, SEEK_SET);
|
||||
return length;
|
||||
}
|
||||
bool CanRead()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool CanWrite()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user