文件改名

This commit is contained in:
2025-05-10 00:59:52 +08:00
parent 0fae462338
commit d40ae5e254
8 changed files with 148 additions and 196 deletions

View File

@@ -1,5 +1,4 @@
#ifndef HGL_ASSETS_SOURCE_INCLUDE #pragma once
#define HGL_ASSETS_SOURCE_INCLUDE
#include<hgl/type/String.h> #include<hgl/type/String.h>
@@ -10,24 +9,8 @@ namespace hgl
class InputStream; class InputStream;
}//namespace io }//namespace io
namespace assets namespace asset
{ {
/**
*
*/
enum class SourceType
{
Memory=0, ///<内存
Filesystem, ///<文件系统
Archive, ///<打包/压缩档
Database, ///<数据库
SaveDevice, ///<存储设备
StreamDevice, ///<流式设备(如摄像头、麦克风)
Network, ///<网络
ENUM_CLASS_RANGE(Memory,Network)
};//enum class SourceType
/** /**
* *
*/ */
@@ -44,7 +27,7 @@ namespace hgl
/** /**
* *
*/ */
class AssetsSource class AssetSource
{ {
U8String uri_short_name; U8String uri_short_name;
@@ -54,8 +37,8 @@ namespace hgl
public: public:
AssetsSource(const U8String &); AssetSource(const U8String &);
virtual ~AssetsSource(); virtual ~AssetSource();
virtual bool hasAnonymousAccess ()const{return false;} virtual bool hasAnonymousAccess ()const{return false;}
virtual bool hasNameAccess ()const{return false;} virtual bool hasNameAccess ()const{return false;}
@@ -65,14 +48,13 @@ namespace hgl
public: public:
virtual io::InputStream * Open (const U8String &){return nullptr;} virtual io::InputStream * Open (const U8String &){return nullptr;}
virtual AssetsSource * CreateSubSource (const U8String &){return nullptr;} virtual AssetSource * CreateSubSource (const U8String &){return nullptr;}
};//class AssetsSource };//class AssetSource
AssetsSource *CreateSourceByFilesystem(const U8String &sn,const OSString &pathname,const bool only_read); AssetSource *CreateSourceByFilesystem(const U8String &sn,const OSString &pathname,const bool only_read);
AssetsSource *GetSource(const U8String &uri_short_name); AssetSource *GetSource(const U8String &uri_short_name);
io::InputStream *GetAssets(const U8String &uri); io::InputStream *GetAssets(const U8String &uri);
}//namespace assets }//namespace asset
}//namespace hgl }//namespace hgl
#endif//HGL_ASSETS_SOURCE_INCLUDE

View File

@@ -1,24 +0,0 @@
#ifndef HGL_ASSETS_TYPE_INCLUDE
#define HGL_ASSETS_TYPE_INCLUDE
#include<hgl/TypeFunc.h>
namespace hgl
{
/**
* 资产类型
*/
enum class AssetsType
{
Binary=0, ///<二进制数据
Text, ///<文本
Bitmap, ///<位图
Vector, ///<矢量图
MIDI, ///<MIDI音乐
Wave, ///<声音数据
Video, ///<视频数据
ENUM_CLASS_RANGE(Binary,Video)
};//enum class AssetsType
}//namespace hgl
#endif//HGL_ASSETS_TYPE_INCLUDE

78
src/AssetSource.cpp Normal file
View File

@@ -0,0 +1,78 @@
#include<hgl/asset/AssetSource.h>
#include<hgl/type/Map.h>
namespace hgl::asset
{
namespace
{
Map<U8String,AssetSource *> assets_source_map;
}//namespace
bool RegistryAssetsSource(const U8String &uri_short_name,AssetSource *as)
{
if(!as)
return(false);
if(uri_short_name.IsEmpty())
return(false);
if(assets_source_map.ContainsKey(uri_short_name))
return(false);
assets_source_map.Add(uri_short_name,as);
return(true);
}
void UnregistryAssetsSource(const U8String &uri_short_name)
{
if(uri_short_name.IsEmpty())
return;
assets_source_map.DeleteByKey(uri_short_name);
}
AssetSource *GetSource(const U8String &uri_short_name)
{
if(uri_short_name.IsEmpty())
return(nullptr);
AssetSource *as;
if(assets_source_map.Get(uri_short_name,as))
return as;
return(nullptr);
}
io::InputStream *GetAssets(const U8String &uri)
{
int pos=uri.FindChar(':');
if(pos<=0)return(nullptr);
if(uri.Comp(pos,u8"://",3))
return(nullptr);
const U8String sn=uri.SubString(0,pos);
AssetSource *source=GetSource(uri);
if(!source)
return(nullptr);
const U8String surl=uri.SubString(pos+3);
return source->Open(surl);
}
AssetSource::AssetSource(const U8String &sn)
{
uri_short_name=sn;
RegistryAssetsSource(sn,this);
}
AssetSource::~AssetSource()
{
UnregistryAssetsSource(uri_short_name);
}
}//namespace hgl::asset

View File

@@ -0,0 +1,56 @@
#include<hgl/asset/AssetSource.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/io/FileInputStream.h>
#include<hgl/CodePage.h>
namespace hgl::asset
{
class AssetsSourceFilesytem:public AssetSource
{
OSString root_path;
bool only_read;
public:
AssetsSourceFilesytem(const U8String &sn,const OSString &path,const bool _or):AssetSource(sn)
{
root_path=path;
only_read=_or;
}
bool hasNameAccess()const override{return true;}
io::InputStream *Open(const U8String &filename)
{
const OSString &fullname=filesystem::MergeFilename(root_path,ToOSString(filename));
if(!filesystem::FileCanRead(fullname))
return(nullptr);
io::FileInputStream *fis=new io::FileInputStream;
if(fis->Open(fullname))
return fis;
delete fis;
return(nullptr);
}
};//class AssetsSourceFilesytem:public AssetSource
AssetSource *CreateSourceByFilesystem(const U8String &uri,const OSString &path,const bool only_read)
{
if(!uri.IsEmpty())
{
if(GetSource(uri))
return(nullptr);
}
if(path.IsEmpty())
return(nullptr);
if(!filesystem::IsDirectory(path))
return(nullptr);
return(new AssetsSourceFilesytem(uri,path,only_read));
}
}//namespace hgl::asset

View File

@@ -1,81 +0,0 @@
#include<hgl/assets/AssetsSource.h>
#include<hgl/type/Map.h>
namespace hgl
{
namespace assets
{
namespace
{
Map<U8String,AssetsSource *> assets_source_map;
}//namespace
bool RegistryAssetsSource(const U8String &uri_short_name,AssetsSource *as)
{
if(!as)
return(false);
if(uri_short_name.IsEmpty())
return(false);
if(assets_source_map.ContainsKey(uri_short_name))
return(false);
assets_source_map.Add(uri_short_name,as);
return(true);
}
void UnregistryAssetsSource(const U8String &uri_short_name)
{
if(uri_short_name.IsEmpty())
return;
assets_source_map.DeleteByKey(uri_short_name);
}
AssetsSource *GetSource(const U8String &uri_short_name)
{
if(uri_short_name.IsEmpty())
return(nullptr);
AssetsSource *as;
if(assets_source_map.Get(uri_short_name,as))
return as;
return(nullptr);
}
io::InputStream *GetAssets(const U8String &uri)
{
int pos=uri.FindChar(':');
if(pos<=0)return(nullptr);
if(uri.Comp(pos,u8"://",3))
return(nullptr);
const U8String sn=uri.SubString(0,pos);
AssetsSource *source=GetSource(uri);
if(!source)
return(nullptr);
const U8String surl=uri.SubString(pos+3);
return source->Open(surl);
}
AssetsSource::AssetsSource(const U8String &sn)
{
uri_short_name=sn;
RegistryAssetsSource(sn,this);
}
AssetsSource::~AssetsSource()
{
UnregistryAssetsSource(uri_short_name);
}
}//namespace assets
}//namespace hgl

View File

@@ -1,59 +0,0 @@
#include<hgl/assets/AssetsSource.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/io/FileInputStream.h>
#include<hgl/CodePage.h>
namespace hgl
{
namespace assets
{
class AssetsSourceFilesytem:public AssetsSource
{
OSString root_path;
bool only_read;
public:
AssetsSourceFilesytem(const U8String &sn,const OSString &path,const bool _or):AssetsSource(sn)
{
root_path=path;
only_read=_or;
}
bool hasNameAccess()const override{return true;}
io::InputStream *Open(const U8String &filename)
{
const OSString &fullname=filesystem::MergeFilename(root_path,ToOSString(filename));
if(!filesystem::FileCanRead(fullname))
return(nullptr);
io::FileInputStream *fis=new io::FileInputStream;
if(fis->Open(fullname))
return fis;
delete fis;
return(nullptr);
}
};//class AssetsSourceFilesytem:public AssetsSource
AssetsSource *CreateSourceByFilesystem(const U8String &uri,const OSString &path,const bool only_read)
{
if(!uri.IsEmpty())
{
if(GetSource(uri))
return(nullptr);
}
if(path.IsEmpty())
return(nullptr);
if(!filesystem::IsDirectory(path))
return(nullptr);
return(new AssetsSourceFilesytem(uri,path,only_read));
}
}//namespace assets
}//namespace hgl

View File

@@ -1,11 +1,11 @@
file(GLOB ASSETS_MANAGE_HEADER ${CMASSETS_MANAGE_ROOT_INCLUDE_PATH}/hgl/assets/*.h) file(GLOB ASSETS_MANAGE_HEADER ${CMASSETS_MANAGE_ROOT_INCLUDE_PATH}/hgl/asset/*.h)
set(ASSETS_MANAGE_SOURCE AssetsSource.cpp set(ASSETS_MANAGE_SOURCE AssetSource.cpp
AssetsSourceFilesystem.cpp) AssetSourceFilesystem.cpp)
IF(ANDROID) IF(ANDROID)
set(ASSETS_MANAGE_SOURCE ${ASSETS_MANAGE_SOURCE} set(ASSETS_MANAGE_SOURCE ${ASSETS_MANAGE_SOURCE}
AssetsSourceAndroid.cpp) AssetSourceAndroid.cpp)
ENDIF() ENDIF()
add_cm_library(CMAssetsManage "CM" ${ASSETS_MANAGE_HEADER} add_cm_library(CMAssetsManage "CM" ${ASSETS_MANAGE_HEADER}