mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
added mod system. Closes #34
This commit is contained in:
parent
a62a7413d1
commit
3a98f7a048
|
@ -61,6 +61,7 @@ os.mkdir(package_dir)
|
||||||
print "adding files"
|
print "adding files"
|
||||||
shutil.copy("readme.txt", package_dir)
|
shutil.copy("readme.txt", package_dir)
|
||||||
shutil.copy("license.txt", package_dir)
|
shutil.copy("license.txt", package_dir)
|
||||||
|
shutil.copy("storage.cfg", package_dir)
|
||||||
|
|
||||||
if include_data and not use_bundle:
|
if include_data and not use_bundle:
|
||||||
os.mkdir(os.path.join(package_dir, "data"))
|
os.mkdir(os.path.join(package_dir, "data"))
|
||||||
|
@ -133,6 +134,7 @@ if use_bundle:
|
||||||
os.mkdir(serverbundle_resource_dir)
|
os.mkdir(serverbundle_resource_dir)
|
||||||
os.mkdir(os.path.join(serverbundle_resource_dir, "data"))
|
os.mkdir(os.path.join(serverbundle_resource_dir, "data"))
|
||||||
os.mkdir(os.path.join(serverbundle_resource_dir, "data/maps"))
|
os.mkdir(os.path.join(serverbundle_resource_dir, "data/maps"))
|
||||||
|
os.mkdir(os.path.join(serverbundle_resource_dir, "data/mapres"))
|
||||||
copydir("data/maps", serverbundle_resource_dir)
|
copydir("data/maps", serverbundle_resource_dir)
|
||||||
shutil.copy("other/icons/Teeworlds_srv.icns", serverbundle_resource_dir)
|
shutil.copy("other/icons/Teeworlds_srv.icns", serverbundle_resource_dir)
|
||||||
shutil.copy(name+"_srv"+exe_ext, serverbundle_bin_dir)
|
shutil.copy(name+"_srv"+exe_ext, serverbundle_bin_dir)
|
||||||
|
|
|
@ -73,7 +73,7 @@ public:
|
||||||
virtual void Connect(const char *pAddress) = 0;
|
virtual void Connect(const char *pAddress) = 0;
|
||||||
virtual void Disconnect() = 0;
|
virtual void Disconnect() = 0;
|
||||||
virtual void Quit() = 0;
|
virtual void Quit() = 0;
|
||||||
virtual const char *DemoPlayer_Play(const char *pFilename) = 0;
|
virtual const char *DemoPlayer_Play(const char *pFilename, int StorageType) = 0;
|
||||||
virtual void DemoRecorder_Start(const char *pFilename) = 0;
|
virtual void DemoRecorder_Start(const char *pFilename) = 0;
|
||||||
|
|
||||||
// networking
|
// networking
|
||||||
|
@ -121,9 +121,6 @@ public:
|
||||||
return SendMsg(&Packer, Flags);
|
return SendMsg(&Packer, Flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
virtual const char *UserDirectory() = 0;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
virtual const char *ErrorString() = 0;
|
virtual const char *ErrorString() = 0;
|
||||||
virtual const char *LatestVersion() = 0;
|
virtual const char *LatestVersion() = 0;
|
||||||
|
|
|
@ -585,7 +585,7 @@ void CClient::ServerInfoRequest()
|
||||||
|
|
||||||
int CClient::LoadData()
|
int CClient::LoadData()
|
||||||
{
|
{
|
||||||
m_DebugFont = Graphics()->LoadTexture("debug_font.png", CImageInfo::FORMAT_AUTO, IGraphics::TEXLOAD_NORESAMPLE);
|
m_DebugFont = Graphics()->LoadTexture("debug_font.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, IGraphics::TEXLOAD_NORESAMPLE);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -990,7 +990,7 @@ void CClient::ProcessPacket(CNetChunk *pPacket)
|
||||||
|
|
||||||
m_MapdownloadChunk = 0;
|
m_MapdownloadChunk = 0;
|
||||||
str_copy(m_aMapdownloadName, pMap, sizeof(m_aMapdownloadName));
|
str_copy(m_aMapdownloadName, pMap, sizeof(m_aMapdownloadName));
|
||||||
m_MapdownloadFile = Storage()->OpenFile(m_aMapdownloadFilename, IOFLAG_WRITE);
|
m_MapdownloadFile = Storage()->OpenFile(m_aMapdownloadFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
|
||||||
m_MapdownloadCrc = MapCrc;
|
m_MapdownloadCrc = MapCrc;
|
||||||
m_MapdownloadTotalsize = -1;
|
m_MapdownloadTotalsize = -1;
|
||||||
m_MapdownloadAmount = 0;
|
m_MapdownloadAmount = 0;
|
||||||
|
@ -1537,13 +1537,6 @@ void CClient::Update()
|
||||||
m_ServerBrowser.Update();
|
m_ServerBrowser.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *CClient::UserDirectory()
|
|
||||||
{
|
|
||||||
static char saPath[1024] = {0};
|
|
||||||
fs_storage_path("Teeworlds", saPath, sizeof(saPath));
|
|
||||||
return saPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CClient::VersionUpdate()
|
void CClient::VersionUpdate()
|
||||||
{
|
{
|
||||||
if(m_VersionInfo.m_State == 0)
|
if(m_VersionInfo.m_State == 0)
|
||||||
|
@ -1871,7 +1864,7 @@ void CClient::Con_AddFavorite(IConsole::IResult *pResult, void *pUserData)
|
||||||
pSelf->m_ServerBrowser.AddFavorite(Addr);
|
pSelf->m_ServerBrowser.AddFavorite(Addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *CClient::DemoPlayer_Play(const char *pFilename)
|
const char *CClient::DemoPlayer_Play(const char *pFilename, int StorageType)
|
||||||
{
|
{
|
||||||
int Crc;
|
int Crc;
|
||||||
const char *pError;
|
const char *pError;
|
||||||
|
@ -1881,7 +1874,7 @@ const char *CClient::DemoPlayer_Play(const char *pFilename)
|
||||||
// try to start playback
|
// try to start playback
|
||||||
m_DemoPlayer.SetListner(this);
|
m_DemoPlayer.SetListner(this);
|
||||||
|
|
||||||
if(m_DemoPlayer.Load(Storage(), m_pConsole, pFilename))
|
if(m_DemoPlayer.Load(Storage(), m_pConsole, pFilename, StorageType))
|
||||||
return "error loading demo";
|
return "error loading demo";
|
||||||
|
|
||||||
// load map
|
// load map
|
||||||
|
@ -1926,7 +1919,7 @@ const char *CClient::DemoPlayer_Play(const char *pFilename)
|
||||||
void CClient::Con_Play(IConsole::IResult *pResult, void *pUserData)
|
void CClient::Con_Play(IConsole::IResult *pResult, void *pUserData)
|
||||||
{
|
{
|
||||||
CClient *pSelf = (CClient *)pUserData;
|
CClient *pSelf = (CClient *)pUserData;
|
||||||
pSelf->DemoPlayer_Play(pResult->GetString(0));
|
pSelf->DemoPlayer_Play(pResult->GetString(0), IStorage::TYPE_ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::DemoRecorder_Start(const char *pFilename)
|
void CClient::DemoRecorder_Start(const char *pFilename)
|
||||||
|
|
|
@ -259,8 +259,6 @@ public:
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
virtual const char *UserDirectory();
|
|
||||||
|
|
||||||
void InitEngine(const char *pAppname);
|
void InitEngine(const char *pAppname);
|
||||||
void RegisterInterfaces();
|
void RegisterInterfaces();
|
||||||
void InitInterfaces();
|
void InitInterfaces();
|
||||||
|
@ -283,7 +281,7 @@ public:
|
||||||
|
|
||||||
void RegisterCommands();
|
void RegisterCommands();
|
||||||
|
|
||||||
const char *DemoPlayer_Play(const char *pFilename);
|
const char *DemoPlayer_Play(const char *pFilename, int StorageType);
|
||||||
void DemoRecorder_Start(const char *pFilename);
|
void DemoRecorder_Start(const char *pFilename);
|
||||||
|
|
||||||
virtual class CEngine *Engine() { return &m_Engine; }
|
virtual class CEngine *Engine() { return &m_Engine; }
|
||||||
|
|
|
@ -354,7 +354,7 @@ int CGraphics_OpenGL::LoadTextureRaw(int Width, int Height, int Format, const vo
|
||||||
}
|
}
|
||||||
|
|
||||||
// simple uncompressed RGBA loaders
|
// simple uncompressed RGBA loaders
|
||||||
int CGraphics_OpenGL::LoadTexture(const char *pFilename, int StoreFormat, int Flags)
|
int CGraphics_OpenGL::LoadTexture(const char *pFilename, int StorageType, int StoreFormat, int Flags)
|
||||||
{
|
{
|
||||||
int l = str_length(pFilename);
|
int l = str_length(pFilename);
|
||||||
int Id;
|
int Id;
|
||||||
|
@ -362,7 +362,7 @@ int CGraphics_OpenGL::LoadTexture(const char *pFilename, int StoreFormat, int Fl
|
||||||
|
|
||||||
if(l < 3)
|
if(l < 3)
|
||||||
return -1;
|
return -1;
|
||||||
if(LoadPNG(&Img, pFilename))
|
if(LoadPNG(&Img, pFilename, StorageType))
|
||||||
{
|
{
|
||||||
if (StoreFormat == CImageInfo::FORMAT_AUTO)
|
if (StoreFormat == CImageInfo::FORMAT_AUTO)
|
||||||
StoreFormat = Img.m_Format;
|
StoreFormat = Img.m_Format;
|
||||||
|
@ -375,7 +375,7 @@ int CGraphics_OpenGL::LoadTexture(const char *pFilename, int StoreFormat, int Fl
|
||||||
return m_InvalidTexture;
|
return m_InvalidTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CGraphics_OpenGL::LoadPNG(CImageInfo *pImg, const char *pFilename)
|
int CGraphics_OpenGL::LoadPNG(CImageInfo *pImg, const char *pFilename, int StorageType)
|
||||||
{
|
{
|
||||||
char aCompleteFilename[512];
|
char aCompleteFilename[512];
|
||||||
unsigned char *pBuffer;
|
unsigned char *pBuffer;
|
||||||
|
@ -384,7 +384,7 @@ int CGraphics_OpenGL::LoadPNG(CImageInfo *pImg, const char *pFilename)
|
||||||
// open file for reading
|
// open file for reading
|
||||||
png_init(0,0); // ignore_convention
|
png_init(0,0); // ignore_convention
|
||||||
|
|
||||||
IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_READ, aCompleteFilename, sizeof(aCompleteFilename));
|
IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_READ, StorageType, aCompleteFilename, sizeof(aCompleteFilename));
|
||||||
if(File)
|
if(File)
|
||||||
io_close(File);
|
io_close(File);
|
||||||
else
|
else
|
||||||
|
@ -450,7 +450,7 @@ void CGraphics_OpenGL::ScreenshotDirect(const char *pFilename)
|
||||||
char aWholePath[1024];
|
char aWholePath[1024];
|
||||||
png_t Png; // ignore_convention
|
png_t Png; // ignore_convention
|
||||||
|
|
||||||
IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_WRITE, aWholePath, sizeof(aWholePath));
|
IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE, aWholePath, sizeof(aWholePath));
|
||||||
if(File)
|
if(File)
|
||||||
io_close(File);
|
io_close(File);
|
||||||
|
|
||||||
|
@ -898,7 +898,7 @@ void CGraphics_SDL::Swap()
|
||||||
{
|
{
|
||||||
IOHANDLE io;
|
IOHANDLE io;
|
||||||
str_format(aFilename, sizeof(aFilename), "screenshots/screenshot%s-%05d.png", aDate, Index);
|
str_format(aFilename, sizeof(aFilename), "screenshots/screenshot%s-%05d.png", aDate, Index);
|
||||||
io = m_pStorage->OpenFile(aFilename, IOFLAG_READ);
|
io = m_pStorage->OpenFile(aFilename, IOFLAG_READ, IStorage::TYPE_SAVE);
|
||||||
if(io)
|
if(io)
|
||||||
io_close(io);
|
io_close(io);
|
||||||
else
|
else
|
||||||
|
|
|
@ -87,8 +87,8 @@ public:
|
||||||
virtual int LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags);
|
virtual int LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags);
|
||||||
|
|
||||||
// simple uncompressed RGBA loaders
|
// simple uncompressed RGBA loaders
|
||||||
virtual int LoadTexture(const char *pFilename, int StoreFormat, int Flags);
|
virtual int LoadTexture(const char *pFilename, int StorageType, int StoreFormat, int Flags);
|
||||||
virtual int LoadPNG(CImageInfo *pImg, const char *pFilename);
|
virtual int LoadPNG(CImageInfo *pImg, const char *pFilename, int StorageType);
|
||||||
|
|
||||||
void ScreenshotDirect(const char *pFilename);
|
void ScreenshotDirect(const char *pFilename);
|
||||||
|
|
||||||
|
|
|
@ -325,7 +325,7 @@ int CSound::LoadWV(const char *pFilename)
|
||||||
if(!m_pStorage)
|
if(!m_pStorage)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ms_File = m_pStorage->OpenFile(pFilename, IOFLAG_READ); // TODO: use system.h stuff for this
|
ms_File = m_pStorage->OpenFile(pFilename, IOFLAG_READ, IStorage::TYPE_ALL);
|
||||||
if(!ms_File)
|
if(!ms_File)
|
||||||
{
|
{
|
||||||
dbg_msg("sound/wv", "failed to open %s", pFilename);
|
dbg_msg("sound/wv", "failed to open %s", pFilename);
|
||||||
|
|
|
@ -70,7 +70,7 @@ struct CFontSizeData
|
||||||
class CFont
|
class CFont
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
char m_aFilename[128];
|
char m_aFilename[512];
|
||||||
FT_Face m_FtFace;
|
FT_Face m_FtFace;
|
||||||
CFontSizeData m_aSizes[NUM_FONT_SIZES];
|
CFontSizeData m_aSizes[NUM_FONT_SIZES];
|
||||||
};
|
};
|
||||||
|
|
|
@ -74,10 +74,10 @@ public:
|
||||||
virtual void BlendAdditive() = 0;
|
virtual void BlendAdditive() = 0;
|
||||||
virtual int MemoryUsage() const = 0;
|
virtual int MemoryUsage() const = 0;
|
||||||
|
|
||||||
virtual int LoadPNG(CImageInfo *pImg, const char *pFilename) =0;
|
virtual int LoadPNG(CImageInfo *pImg, const char *pFilename, int StorageType) =0;
|
||||||
virtual int UnloadTexture(int Index) = 0;
|
virtual int UnloadTexture(int Index) = 0;
|
||||||
virtual int LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags) = 0;
|
virtual int LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags) = 0;
|
||||||
virtual int LoadTexture(const char *pFilename, int StoreFormat, int Flags) = 0;
|
virtual int LoadTexture(const char *pFilename, int StorageType, int StoreFormat, int Flags) = 0;
|
||||||
virtual void TextureSet(int TextureID) = 0;
|
virtual void TextureSet(int TextureID) = 0;
|
||||||
|
|
||||||
struct CLineItem
|
struct CLineItem
|
||||||
|
|
|
@ -1043,7 +1043,7 @@ int CServer::LoadMap(const char *pMapName)
|
||||||
|
|
||||||
// load compelate map into memory for download
|
// load compelate map into memory for download
|
||||||
{
|
{
|
||||||
IOHANDLE File = Storage()->OpenFile(aBuf, IOFLAG_READ);
|
IOHANDLE File = Storage()->OpenFile(aBuf, IOFLAG_READ, IStorage::TYPE_ALL);
|
||||||
m_CurrentMapSize = (int)io_length(File);
|
m_CurrentMapSize = (int)io_length(File);
|
||||||
if(m_pCurrentMapData)
|
if(m_pCurrentMapData)
|
||||||
mem_free(m_pCurrentMapData);
|
mem_free(m_pCurrentMapData);
|
||||||
|
|
|
@ -74,7 +74,7 @@ public:
|
||||||
{
|
{
|
||||||
if(!m_pStorage)
|
if(!m_pStorage)
|
||||||
return;
|
return;
|
||||||
m_ConfigFile = m_pStorage->OpenFile("settings.cfg", IOFLAG_WRITE);
|
m_ConfigFile = m_pStorage->OpenFile("settings.cfg", IOFLAG_WRITE, IStorage::TYPE_SAVE);
|
||||||
|
|
||||||
if(!m_ConfigFile)
|
if(!m_ConfigFile)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -300,7 +300,7 @@ void CConsole::ExecuteFile(const char *pFilename)
|
||||||
m_pFirstExec = &ThisFile;
|
m_pFirstExec = &ThisFile;
|
||||||
|
|
||||||
// exec the file
|
// exec the file
|
||||||
IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_READ);
|
IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_READ, IStorage::TYPE_ALL);
|
||||||
|
|
||||||
char aBuf[256];
|
char aBuf[256];
|
||||||
if(File)
|
if(File)
|
||||||
|
|
|
@ -65,11 +65,11 @@ struct CDatafile
|
||||||
char *m_pData;
|
char *m_pData;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool CDataFileReader::Open(class IStorage *pStorage, const char *pFilename)
|
bool CDataFileReader::Open(class IStorage *pStorage, const char *pFilename, int StorageType)
|
||||||
{
|
{
|
||||||
dbg_msg("datafile", "loading. filename='%s'", pFilename);
|
dbg_msg("datafile", "loading. filename='%s'", pFilename);
|
||||||
|
|
||||||
IOHANDLE File = pStorage->OpenFile(pFilename, IOFLAG_READ);
|
IOHANDLE File = pStorage->OpenFile(pFilename, IOFLAG_READ, StorageType);
|
||||||
if(!File)
|
if(!File)
|
||||||
{
|
{
|
||||||
dbg_msg("datafile", "could not open '%s'", pFilename);
|
dbg_msg("datafile", "could not open '%s'", pFilename);
|
||||||
|
@ -394,7 +394,7 @@ unsigned CDataFileReader::Crc()
|
||||||
bool CDataFileWriter::Open(class IStorage *pStorage, const char *pFilename)
|
bool CDataFileWriter::Open(class IStorage *pStorage, const char *pFilename)
|
||||||
{
|
{
|
||||||
dbg_assert(!m_File, "a file already exists");
|
dbg_assert(!m_File, "a file already exists");
|
||||||
m_File = pStorage->OpenFile(pFilename, IOFLAG_WRITE);
|
m_File = pStorage->OpenFile(pFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
|
||||||
if(!m_File)
|
if(!m_File)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ public:
|
||||||
|
|
||||||
bool IsOpen() const { return m_pDataFile != 0; }
|
bool IsOpen() const { return m_pDataFile != 0; }
|
||||||
|
|
||||||
bool Open(class IStorage *pStorage, const char *pFilename);
|
bool Open(class IStorage *pStorage, const char *pFilename, int StorageType);
|
||||||
bool Close();
|
bool Close();
|
||||||
|
|
||||||
void *GetData(int Index);
|
void *GetData(int Index);
|
||||||
|
|
|
@ -40,12 +40,12 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con
|
||||||
char aMapFilename[128];
|
char aMapFilename[128];
|
||||||
// try the normal maps folder
|
// try the normal maps folder
|
||||||
str_format(aMapFilename, sizeof(aMapFilename), "maps/%s.map", pMap);
|
str_format(aMapFilename, sizeof(aMapFilename), "maps/%s.map", pMap);
|
||||||
IOHANDLE MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_READ);
|
IOHANDLE MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_READ, IStorage::TYPE_ALL);
|
||||||
if(!MapFile)
|
if(!MapFile)
|
||||||
{
|
{
|
||||||
// try the downloaded maps
|
// try the downloaded maps
|
||||||
str_format(aMapFilename, sizeof(aMapFilename), "downloadedmaps/%s_%08x.map", pMap, Crc);
|
str_format(aMapFilename, sizeof(aMapFilename), "downloadedmaps/%s_%08x.map", pMap, Crc);
|
||||||
MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_READ);
|
MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_READ, IStorage::TYPE_ALL);
|
||||||
}
|
}
|
||||||
if(!MapFile)
|
if(!MapFile)
|
||||||
{
|
{
|
||||||
|
@ -55,7 +55,7 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_File = pStorage->OpenFile(pFilename, IOFLAG_WRITE);
|
m_File = pStorage->OpenFile(pFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
|
||||||
if(!m_File)
|
if(!m_File)
|
||||||
{
|
{
|
||||||
io_close(MapFile);
|
io_close(MapFile);
|
||||||
|
@ -513,10 +513,10 @@ void CDemoPlayer::Unpause()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename)
|
int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, int StorageType)
|
||||||
{
|
{
|
||||||
m_pConsole = pConsole;
|
m_pConsole = pConsole;
|
||||||
m_File = pStorage->OpenFile(pFilename, IOFLAG_READ);
|
m_File = pStorage->OpenFile(pFilename, IOFLAG_READ, StorageType);
|
||||||
if(!m_File)
|
if(!m_File)
|
||||||
{
|
{
|
||||||
char aBuf[256];
|
char aBuf[256];
|
||||||
|
@ -566,7 +566,7 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const
|
||||||
int Crc = (m_Info.m_Header.m_aCrc[0]<<24) | (m_Info.m_Header.m_aCrc[1]<<16) | (m_Info.m_Header.m_aCrc[2]<<8) | (m_Info.m_Header.m_aCrc[3]);
|
int Crc = (m_Info.m_Header.m_aCrc[0]<<24) | (m_Info.m_Header.m_aCrc[1]<<16) | (m_Info.m_Header.m_aCrc[2]<<8) | (m_Info.m_Header.m_aCrc[3]);
|
||||||
char aMapFilename[128];
|
char aMapFilename[128];
|
||||||
str_format(aMapFilename, sizeof(aMapFilename), "downloadedmaps/%s_%08x.map", m_Info.m_Header.m_aMap, Crc);
|
str_format(aMapFilename, sizeof(aMapFilename), "downloadedmaps/%s_%08x.map", m_Info.m_Header.m_aMap, Crc);
|
||||||
IOHANDLE MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_READ);
|
IOHANDLE MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_READ, IStorage::TYPE_ALL);
|
||||||
|
|
||||||
if(MapFile)
|
if(MapFile)
|
||||||
{
|
{
|
||||||
|
@ -580,7 +580,7 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const
|
||||||
io_read(m_File, pMapData, MapSize);
|
io_read(m_File, pMapData, MapSize);
|
||||||
|
|
||||||
// save map
|
// save map
|
||||||
MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_WRITE);
|
MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
|
||||||
io_write(MapFile, pMapData, MapSize);
|
io_write(MapFile, pMapData, MapSize);
|
||||||
io_close(MapFile);
|
io_close(MapFile);
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ public:
|
||||||
|
|
||||||
void SetListner(IListner *pListner);
|
void SetListner(IListner *pListner);
|
||||||
|
|
||||||
int Load(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename);
|
int Load(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, int StorageType);
|
||||||
int Play();
|
int Play();
|
||||||
void Pause();
|
void Pause();
|
||||||
void Unpause();
|
void Unpause();
|
||||||
|
|
|
@ -28,7 +28,7 @@ public:
|
||||||
IStorage *pStorage = Kernel()->RequestInterface<IStorage>();
|
IStorage *pStorage = Kernel()->RequestInterface<IStorage>();
|
||||||
if(!pStorage)
|
if(!pStorage)
|
||||||
return false;
|
return false;
|
||||||
return m_DataFile.Open(pStorage, pMapName);
|
return m_DataFile.Open(pStorage, pMapName, IStorage::TYPE_ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool IsLoaded()
|
virtual bool IsLoaded()
|
||||||
|
|
|
@ -119,7 +119,7 @@ public:
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// try to open file
|
// try to open file
|
||||||
File = pStorage->OpenFile("masters.cfg", IOFLAG_READ);
|
File = pStorage->OpenFile("masters.cfg", IOFLAG_READ, IStorage::TYPE_SAVE);
|
||||||
if(!File)
|
if(!File)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ public:
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// try to open file
|
// try to open file
|
||||||
File = pStorage->OpenFile("masters.cfg", IOFLAG_WRITE);
|
File = pStorage->OpenFile("masters.cfg", IOFLAG_WRITE, IStorage::TYPE_SAVE);
|
||||||
if(!File)
|
if(!File)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <base/system.h>
|
#include <base/system.h>
|
||||||
#include <engine/storage.h>
|
#include <engine/storage.h>
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
#include "linereader.h"
|
||||||
|
|
||||||
// compiled-in data-dir path
|
// compiled-in data-dir path
|
||||||
#define DATA_DIR "data"
|
#define DATA_DIR "data"
|
||||||
|
@ -10,36 +11,29 @@
|
||||||
class CStorage : public IStorage
|
class CStorage : public IStorage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
char m_aApplicationSavePath[512];
|
enum
|
||||||
char m_aDatadir[512];
|
{
|
||||||
|
MAX_PATHS = 16,
|
||||||
|
MAX_PATH_LENGTH = 512
|
||||||
|
};
|
||||||
|
|
||||||
|
char m_aaStoragePaths[MAX_PATHS][MAX_PATH_LENGTH];
|
||||||
|
int m_NumPaths;
|
||||||
|
char m_aDatadir[MAX_PATH_LENGTH];
|
||||||
|
char m_aUserdir[MAX_PATH_LENGTH];
|
||||||
|
|
||||||
CStorage()
|
CStorage()
|
||||||
{
|
{
|
||||||
m_aApplicationSavePath[0] = 0;
|
mem_zero(m_aaStoragePaths, sizeof(m_aaStoragePaths));
|
||||||
|
m_NumPaths = 0;
|
||||||
m_aDatadir[0] = 0;
|
m_aDatadir[0] = 0;
|
||||||
|
m_aUserdir[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Init(const char *pApplicationName, int NumArgs, const char **ppArguments)
|
int Init(const char *pApplicationName, int NumArgs, const char **ppArguments)
|
||||||
{
|
{
|
||||||
char aPath[1024] = {0};
|
// get userdir
|
||||||
fs_storage_path(pApplicationName, m_aApplicationSavePath, sizeof(m_aApplicationSavePath));
|
fs_storage_path(pApplicationName, m_aUserdir, sizeof(m_aUserdir));
|
||||||
if(fs_makedir(m_aApplicationSavePath) == 0)
|
|
||||||
{
|
|
||||||
str_format(aPath, sizeof(aPath), "%s/screenshots", m_aApplicationSavePath);
|
|
||||||
fs_makedir(aPath);
|
|
||||||
|
|
||||||
str_format(aPath, sizeof(aPath), "%s/maps", m_aApplicationSavePath);
|
|
||||||
fs_makedir(aPath);
|
|
||||||
|
|
||||||
str_format(aPath, sizeof(aPath), "%s/dumps", m_aApplicationSavePath);
|
|
||||||
fs_makedir(aPath);
|
|
||||||
|
|
||||||
str_format(aPath, sizeof(aPath), "%s/downloadedmaps", m_aApplicationSavePath);
|
|
||||||
fs_makedir(aPath);
|
|
||||||
|
|
||||||
str_format(aPath, sizeof(aPath), "%s/demos", m_aApplicationSavePath);
|
|
||||||
fs_makedir(aPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check for datadir override
|
// check for datadir override
|
||||||
for(int i = 1; i < NumArgs; i++)
|
for(int i = 1; i < NumArgs; i++)
|
||||||
|
@ -50,54 +44,160 @@ public:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// get datadir
|
||||||
return FindDatadir(ppArguments[0]);
|
FindDatadir(ppArguments[0]);
|
||||||
|
|
||||||
|
// load paths from storage.cfg
|
||||||
|
LoadPaths(ppArguments[0]);
|
||||||
|
|
||||||
|
if(!m_NumPaths)
|
||||||
|
{
|
||||||
|
dbg_msg("storage", "using standard paths");
|
||||||
|
AddDefaultPaths();
|
||||||
|
}
|
||||||
|
|
||||||
|
// add save directories
|
||||||
|
if(m_NumPaths && (!m_aaStoragePaths[TYPE_SAVE][0] || !fs_makedir(m_aaStoragePaths[TYPE_SAVE])))
|
||||||
|
{
|
||||||
|
char aPath[MAX_PATH_LENGTH];
|
||||||
|
fs_makedir(GetPath(TYPE_SAVE, "screenshots", aPath, sizeof(aPath)));
|
||||||
|
fs_makedir(GetPath(TYPE_SAVE, "maps", aPath, sizeof(aPath)));
|
||||||
|
fs_makedir(GetPath(TYPE_SAVE, "dumps", aPath, sizeof(aPath)));
|
||||||
|
fs_makedir(GetPath(TYPE_SAVE, "downloadedmaps", aPath, sizeof(aPath)));
|
||||||
|
fs_makedir(GetPath(TYPE_SAVE, "demos", aPath, sizeof(aPath)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_NumPaths ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoadPaths(const char *pArgv0)
|
||||||
|
{
|
||||||
|
// check current directory
|
||||||
|
IOHANDLE File = io_open("storage.cfg", IOFLAG_READ);
|
||||||
|
if(!File)
|
||||||
|
{
|
||||||
|
// check usable path in argv[0]
|
||||||
|
unsigned int Pos = ~0U;
|
||||||
|
for(unsigned i = 0; pArgv0[i]; i++)
|
||||||
|
if(pArgv0[i] == '/' || pArgv0[i] == '\\')
|
||||||
|
Pos = i;
|
||||||
|
if(Pos < MAX_PATH_LENGTH)
|
||||||
|
{
|
||||||
|
char aBuffer[MAX_PATH_LENGTH];
|
||||||
|
str_copy(aBuffer, pArgv0, Pos+1);
|
||||||
|
str_append(aBuffer, "/storage.cfg", sizeof(aBuffer));
|
||||||
|
File = io_open(aBuffer, IOFLAG_READ);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Pos >= MAX_PATH_LENGTH || !File)
|
||||||
|
{
|
||||||
|
dbg_msg("storage", "couldn't open storage.cfg");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char *pLine;
|
||||||
|
CLineReader LineReader;
|
||||||
|
LineReader.Init(File);
|
||||||
|
|
||||||
|
while((pLine = LineReader.Get()))
|
||||||
|
{
|
||||||
|
if(str_length(pLine) > 9 && !str_comp_num(pLine, "add_path ", 9))
|
||||||
|
AddPath(pLine+9);
|
||||||
|
}
|
||||||
|
|
||||||
|
io_close(File);
|
||||||
|
|
||||||
|
if(!m_NumPaths)
|
||||||
|
dbg_msg("storage", "no paths found in storage.cfg");
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddDefaultPaths()
|
||||||
|
{
|
||||||
|
AddPath("$USERDIR");
|
||||||
|
AddPath("$DATADIR");
|
||||||
|
AddPath("$CURRENTDIR");
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddPath(const char *pPath)
|
||||||
|
{
|
||||||
|
if(m_NumPaths >= MAX_PATHS || !pPath[0])
|
||||||
|
return;
|
||||||
|
|
||||||
|
int OldNum = m_NumPaths;
|
||||||
|
|
||||||
|
if(!str_comp(pPath, "$USERDIR"))
|
||||||
|
{
|
||||||
|
if(m_aUserdir[0])
|
||||||
|
str_copy(m_aaStoragePaths[m_NumPaths++], m_aUserdir, MAX_PATH_LENGTH);
|
||||||
|
}
|
||||||
|
else if(!str_comp(pPath, "$DATADIR"))
|
||||||
|
{
|
||||||
|
if(m_aDatadir[0])
|
||||||
|
str_copy(m_aaStoragePaths[m_NumPaths++], m_aDatadir, MAX_PATH_LENGTH);
|
||||||
|
}
|
||||||
|
else if(!str_comp(pPath, "$CURRENTDIR"))
|
||||||
|
{
|
||||||
|
m_aaStoragePaths[m_NumPaths++][0] = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(fs_is_dir(pPath))
|
||||||
|
str_copy(m_aaStoragePaths[m_NumPaths++], pPath, MAX_PATH_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(OldNum != m_NumPaths)
|
||||||
|
dbg_msg("storage", "added path '%s'", pPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FindDatadir(const char *pArgv0)
|
void FindDatadir(const char *pArgv0)
|
||||||
{
|
{
|
||||||
// 1) use provided data-dir override
|
// 1) use provided data-dir override
|
||||||
if(m_aDatadir[0])
|
if(m_aDatadir[0])
|
||||||
{
|
{
|
||||||
if(fs_is_dir(m_aDatadir))
|
char aBuffer[MAX_PATH_LENGTH];
|
||||||
return 0;
|
str_format(aBuffer, sizeof(aBuffer), "%s/mapres", m_aDatadir);
|
||||||
else
|
if(!fs_is_dir(aBuffer))
|
||||||
{
|
{
|
||||||
dbg_msg("engine/datadir", "specified data-dir '%s' does not exist", m_aDatadir);
|
dbg_msg("storage", "specified data directory '%s' does not exist", m_aDatadir);
|
||||||
return -1;
|
m_aDatadir[0] = 0;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2) use data-dir in PWD if present
|
// 2) use data-dir in PWD if present
|
||||||
if(fs_is_dir("data/mapres"))
|
if(fs_is_dir("data/mapres"))
|
||||||
{
|
{
|
||||||
str_copy(m_aDatadir, "data", sizeof(m_aDatadir));
|
str_copy(m_aDatadir, "data", sizeof(m_aDatadir));
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3) use compiled-in data-dir if present
|
// 3) use compiled-in data-dir if present
|
||||||
if (fs_is_dir(DATA_DIR "/mapres"))
|
if(fs_is_dir(DATA_DIR "/mapres"))
|
||||||
{
|
{
|
||||||
str_copy(m_aDatadir, DATA_DIR, sizeof(m_aDatadir));
|
str_copy(m_aDatadir, DATA_DIR, sizeof(m_aDatadir));
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4) check for usable path in argv[0]
|
// 4) check for usable path in argv[0]
|
||||||
{
|
{
|
||||||
unsigned int Pos = ~0U;
|
unsigned int Pos = ~0U;
|
||||||
for(unsigned i = 0; pArgv0[i]; i++)
|
for(unsigned i = 0; pArgv0[i]; i++)
|
||||||
if(pArgv0[i] == '/')
|
if(pArgv0[i] == '/' || pArgv0[i] == '\\')
|
||||||
Pos = i;
|
Pos = i;
|
||||||
|
|
||||||
if (Pos < sizeof(m_aDatadir))
|
if(Pos < MAX_PATH_LENGTH)
|
||||||
{
|
{
|
||||||
char aBaseDir[sizeof(m_aDatadir)];
|
char aBaseDir[MAX_PATH_LENGTH];
|
||||||
str_copy(aBaseDir, pArgv0, Pos);
|
str_copy(aBaseDir, pArgv0, Pos+1);
|
||||||
aBaseDir[Pos] = '\0';
|
|
||||||
str_format(m_aDatadir, sizeof(m_aDatadir), "%s/data", aBaseDir);
|
str_format(m_aDatadir, sizeof(m_aDatadir), "%s/data", aBaseDir);
|
||||||
|
str_append(aBaseDir, "/data/mapres", sizeof(aBaseDir));
|
||||||
|
|
||||||
if (fs_is_dir(m_aDatadir))
|
if(fs_is_dir(aBaseDir))
|
||||||
return 0;
|
return;
|
||||||
|
else
|
||||||
|
m_aDatadir[0] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,11 +205,11 @@ public:
|
||||||
// 5) check for all default locations
|
// 5) check for all default locations
|
||||||
{
|
{
|
||||||
const char *aDirs[] = {
|
const char *aDirs[] = {
|
||||||
"/usr/share/teeworlds/data",
|
"/usr/share/teeworlds/data/mapres",
|
||||||
"/usr/share/games/teeworlds/data",
|
"/usr/share/games/teeworlds/data/mapres",
|
||||||
"/usr/local/share/teeworlds/data",
|
"/usr/local/share/teeworlds/data/mapres",
|
||||||
"/usr/local/share/games/teeworlds/data",
|
"/usr/local/share/games/teeworlds/data/mapres",
|
||||||
"/opt/teeworlds/data"
|
"/opt/teeworlds/data/mapres"
|
||||||
};
|
};
|
||||||
const int DirsCount = sizeof(aDirs) / sizeof(aDirs[0]);
|
const int DirsCount = sizeof(aDirs) / sizeof(aDirs[0]);
|
||||||
|
|
||||||
|
@ -119,55 +219,41 @@ public:
|
||||||
if (fs_is_dir(aDirs[i]))
|
if (fs_is_dir(aDirs[i]))
|
||||||
{
|
{
|
||||||
str_copy(m_aDatadir, aDirs[i], sizeof(m_aDatadir));
|
str_copy(m_aDatadir, aDirs[i], sizeof(m_aDatadir));
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// no data-dir found
|
// no data-dir found
|
||||||
dbg_msg("engine/datadir", "warning no data directory found");
|
dbg_msg("storage", "warning no data directory found");
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ListDirectory(int Types, const char *pPath, FS_LISTDIR_CALLBACK pfnCallback, void *pUser)
|
virtual void ListDirectory(int Type, const char *pPath, FS_LISTDIR_CALLBACK pfnCallback, void *pUser)
|
||||||
{
|
{
|
||||||
char aBuffer[1024];
|
char aBuffer[MAX_PATH_LENGTH];
|
||||||
|
if(Type == TYPE_ALL)
|
||||||
// list current directory
|
|
||||||
if(Types&TYPE_CURRENT)
|
|
||||||
{
|
{
|
||||||
fs_listdir(pPath, pfnCallback, TYPE_CURRENT, pUser);
|
// list all available directories
|
||||||
|
for(int i = 0; i < m_NumPaths; ++i)
|
||||||
|
fs_listdir(GetPath(i, pPath, aBuffer, sizeof(aBuffer)), pfnCallback, i, pUser);
|
||||||
}
|
}
|
||||||
|
else if(Type >= 0 && Type < m_NumPaths)
|
||||||
// list users directory
|
|
||||||
if(Types&TYPE_SAVE)
|
|
||||||
{
|
{
|
||||||
str_format(aBuffer, sizeof(aBuffer), "%s/%s", m_aApplicationSavePath, pPath);
|
// list wanted directory
|
||||||
fs_listdir(aBuffer, pfnCallback, TYPE_SAVE, pUser);
|
fs_listdir(GetPath(Type, pPath, aBuffer, sizeof(aBuffer)), pfnCallback, Type, pUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
// list datadir directory
|
|
||||||
if(Types&TYPE_DATA)
|
|
||||||
{
|
|
||||||
str_format(aBuffer, sizeof(aBuffer), "%s/%s", m_aDatadir, pPath);
|
|
||||||
fs_listdir(aBuffer, pfnCallback, TYPE_DATA, pUser);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const char *GetDirectory(int Type) const
|
const char *GetPath(int Type, const char *pDir, char *pBuffer, unsigned BufferSize)
|
||||||
{
|
{
|
||||||
switch(Type)
|
str_format(pBuffer, BufferSize, "%s%s%s", m_aaStoragePaths[Type], !m_aaStoragePaths[Type][0] ? "" : "/", pDir);
|
||||||
{
|
return pBuffer;
|
||||||
case TYPE_SAVE: return m_aApplicationSavePath;
|
|
||||||
case TYPE_DATA: return m_aDatadir;
|
|
||||||
default: return "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual IOHANDLE OpenFile(const char *pFilename, int Flags, char *pBuffer = 0, int BufferSize = 0)
|
virtual IOHANDLE OpenFile(const char *pFilename, int Flags, int Type, char *pBuffer = 0, int BufferSize = 0)
|
||||||
{
|
{
|
||||||
char aBuffer[1024];
|
char aBuffer[MAX_PATH_LENGTH];
|
||||||
if(!pBuffer)
|
if(!pBuffer)
|
||||||
{
|
{
|
||||||
pBuffer = aBuffer;
|
pBuffer = aBuffer;
|
||||||
|
@ -176,45 +262,42 @@ public:
|
||||||
|
|
||||||
if(Flags&IOFLAG_WRITE)
|
if(Flags&IOFLAG_WRITE)
|
||||||
{
|
{
|
||||||
str_format(pBuffer, BufferSize, "%s/%s", m_aApplicationSavePath, pFilename);
|
return io_open(GetPath(TYPE_SAVE, pFilename, pBuffer, BufferSize), Flags);
|
||||||
return io_open(pBuffer, Flags);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IOHANDLE Handle = 0;
|
IOHANDLE Handle = 0;
|
||||||
|
|
||||||
// check current directory
|
if(Type == TYPE_ALL)
|
||||||
Handle = io_open(pFilename, Flags);
|
{
|
||||||
if(Handle)
|
// check all available directories
|
||||||
return Handle;
|
for(int i = 0; i < m_NumPaths; ++i)
|
||||||
|
{
|
||||||
// check user directory
|
Handle = io_open(GetPath(i, pFilename, pBuffer, BufferSize), Flags);
|
||||||
str_format(pBuffer, BufferSize, "%s/%s", m_aApplicationSavePath, pFilename);
|
if(Handle)
|
||||||
Handle = io_open(pBuffer, Flags);
|
return Handle;
|
||||||
if(Handle)
|
}
|
||||||
return Handle;
|
}
|
||||||
|
else if(Type >= 0 && Type < m_NumPaths)
|
||||||
// check normal data directory
|
{
|
||||||
str_format(pBuffer, BufferSize, "%s/%s", m_aDatadir, pFilename);
|
// check wanted directory
|
||||||
Handle = io_open(pBuffer, Flags);
|
Handle = io_open(GetPath(Type, pFilename, pBuffer, BufferSize), Flags);
|
||||||
if(Handle)
|
if(Handle)
|
||||||
return Handle;
|
return Handle;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pBuffer[0] = 0;
|
pBuffer[0] = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool RemoveFile(const char *pFilename)
|
virtual bool RemoveFile(const char *pFilename, int Type)
|
||||||
{
|
{
|
||||||
char aBuffer[1024];
|
if(Type < 0 || Type >= m_NumPaths)
|
||||||
str_format(aBuffer, sizeof(aBuffer), "%s/%s", m_aApplicationSavePath, pFilename);
|
return false;
|
||||||
bool Fail = remove(aBuffer);
|
|
||||||
|
char aBuffer[MAX_PATH_LENGTH];
|
||||||
if(Fail)
|
return remove(GetPath(Type, pFilename, aBuffer, sizeof(aBuffer)));
|
||||||
Fail = remove(pFilename);
|
|
||||||
|
|
||||||
return !Fail;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static IStorage *Create(const char *pApplicationName, int NumArgs, const char **ppArguments)
|
static IStorage *Create(const char *pApplicationName, int NumArgs, const char **ppArguments)
|
||||||
|
@ -222,6 +305,7 @@ public:
|
||||||
CStorage *p = new CStorage();
|
CStorage *p = new CStorage();
|
||||||
if(p && p->Init(pApplicationName, NumArgs, ppArguments))
|
if(p && p->Init(pApplicationName, NumArgs, ppArguments))
|
||||||
{
|
{
|
||||||
|
dbg_msg("storage", "initialisation failed");
|
||||||
delete p;
|
delete p;
|
||||||
p = 0;
|
p = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,16 +9,13 @@ class IStorage : public IInterface
|
||||||
public:
|
public:
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
TYPE_SAVE = 1,
|
TYPE_SAVE = 0,
|
||||||
TYPE_CURRENT = 2,
|
TYPE_ALL = -1
|
||||||
TYPE_DATA = 4,
|
|
||||||
TYPE_ALL = ~0
|
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void ListDirectory(int Types, const char *pPath, FS_LISTDIR_CALLBACK pfnCallback, void *pUser) = 0;
|
virtual void ListDirectory(int Type, const char *pPath, FS_LISTDIR_CALLBACK pfnCallback, void *pUser) = 0;
|
||||||
virtual const char *GetDirectory(int Type) const = 0;
|
virtual IOHANDLE OpenFile(const char *pFilename, int Flags, int Type, char *pBuffer = 0, int BufferSize = 0) = 0;
|
||||||
virtual IOHANDLE OpenFile(const char *pFilename, int Flags, char *pBuffer = 0, int BufferSize = 0) = 0;
|
virtual bool RemoveFile(const char *pFilename, int Type) = 0;
|
||||||
virtual bool RemoveFile(const char *pFilename) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern IStorage *CreateStorage(const char *pApplicationName, int NumArgs, const char **ppArguments);
|
extern IStorage *CreateStorage(const char *pApplicationName, int NumArgs, const char **ppArguments);
|
||||||
|
|
|
@ -588,7 +588,7 @@ void CGameConsole::Dump(int Type)
|
||||||
{
|
{
|
||||||
IOHANDLE io;
|
IOHANDLE io;
|
||||||
str_format(aFilename, sizeof(aFilename), "dumps/%s_dump%s-%05d.txt", Type==1?"remote_console":"local_console", aDate, i);
|
str_format(aFilename, sizeof(aFilename), "dumps/%s_dump%s-%05d.txt", Type==1?"remote_console":"local_console", aDate, i);
|
||||||
io = Storage()->OpenFile(aFilename, IOFLAG_WRITE);
|
io = Storage()->OpenFile(aFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
|
||||||
if(io)
|
if(io)
|
||||||
{
|
{
|
||||||
#if defined(CONF_FAMILY_WINDOWS)
|
#if defined(CONF_FAMILY_WINDOWS)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <engine/graphics.h>
|
#include <engine/graphics.h>
|
||||||
#include <engine/map.h>
|
#include <engine/map.h>
|
||||||
|
#include <engine/storage.h>
|
||||||
#include <game/client/component.h>
|
#include <game/client/component.h>
|
||||||
#include <game/mapitems.h>
|
#include <game/mapitems.h>
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ void CMapImages::OnMapLoad()
|
||||||
char Buf[256];
|
char Buf[256];
|
||||||
char *pName = (char *)pMap->GetData(pImg->m_ImageName);
|
char *pName = (char *)pMap->GetData(pImg->m_ImageName);
|
||||||
str_format(Buf, sizeof(Buf), "mapres/%s.png", pName);
|
str_format(Buf, sizeof(Buf), "mapres/%s.png", pName);
|
||||||
m_aTextures[i] = Graphics()->LoadTexture(Buf, CImageInfo::FORMAT_AUTO, 0);
|
m_aTextures[i] = Graphics()->LoadTexture(Buf, IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -135,7 +135,7 @@ void CMapLayers::OnRender()
|
||||||
Client()->GetServerInfo(&CurrentServerInfo);
|
Client()->GetServerInfo(&CurrentServerInfo);
|
||||||
char aFilename[256];
|
char aFilename[256];
|
||||||
str_format(aFilename, sizeof(aFilename), "dumps/tilelayer_dump_%s-%d-%d-%dx%d.txt", CurrentServerInfo.m_aMap, g, l, pTMap->m_Width, pTMap->m_Height);
|
str_format(aFilename, sizeof(aFilename), "dumps/tilelayer_dump_%s-%d-%d-%dx%d.txt", CurrentServerInfo.m_aMap, g, l, pTMap->m_Width, pTMap->m_Height);
|
||||||
IOHANDLE File = Storage()->OpenFile(aFilename, IOFLAG_WRITE);
|
IOHANDLE File = Storage()->OpenFile(aFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
|
||||||
if(File)
|
if(File)
|
||||||
{
|
{
|
||||||
#if defined(CONF_FAMILY_WINDOWS)
|
#if defined(CONF_FAMILY_WINDOWS)
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <engine/textrender.h>
|
#include <engine/textrender.h>
|
||||||
#include <engine/serverbrowser.h>
|
#include <engine/serverbrowser.h>
|
||||||
#include <engine/keys.h>
|
#include <engine/keys.h>
|
||||||
|
#include <engine/storage.h>
|
||||||
#include <engine/shared/config.h>
|
#include <engine/shared/config.h>
|
||||||
|
|
||||||
#include <game/version.h>
|
#include <game/version.h>
|
||||||
|
@ -1259,7 +1260,7 @@ void CMenus::RenderBackground()
|
||||||
//Graphics()->Clear(1,1,1);
|
//Graphics()->Clear(1,1,1);
|
||||||
//render_sunrays(0,0);
|
//render_sunrays(0,0);
|
||||||
if(gs_TextureBlob == -1)
|
if(gs_TextureBlob == -1)
|
||||||
gs_TextureBlob = Graphics()->LoadTexture("blob.png", CImageInfo::FORMAT_AUTO, 0);
|
gs_TextureBlob = Graphics()->LoadTexture("blob.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
|
||||||
|
|
||||||
|
|
||||||
float sw = 300*Graphics()->ScreenAspect();
|
float sw = 300*Graphics()->ScreenAspect();
|
||||||
|
|
|
@ -159,7 +159,7 @@ class CMenus : public CComponent
|
||||||
char m_aFilename[128];
|
char m_aFilename[128];
|
||||||
char m_aName[128];
|
char m_aName[128];
|
||||||
bool m_IsDir;
|
bool m_IsDir;
|
||||||
int m_DirType;
|
int m_StorageType;
|
||||||
|
|
||||||
bool operator<(const CDemoItem &Other) { return !str_comp(m_aFilename, "..") ? true : !str_comp(Other.m_aFilename, "..") ? false :
|
bool operator<(const CDemoItem &Other) { return !str_comp(m_aFilename, "..") ? true : !str_comp(Other.m_aFilename, "..") ? false :
|
||||||
m_IsDir && !Other.m_IsDir ? true : !m_IsDir && Other.m_IsDir ? false :
|
m_IsDir && !Other.m_IsDir ? true : !m_IsDir && Other.m_IsDir ? false :
|
||||||
|
@ -174,7 +174,7 @@ class CMenus : public CComponent
|
||||||
|
|
||||||
void DemolistOnUpdate(bool Reset);
|
void DemolistOnUpdate(bool Reset);
|
||||||
void DemolistPopulate();
|
void DemolistPopulate();
|
||||||
static void DemolistFetchCallback(const char *pName, int IsDir, int DirType, void *pUser);
|
static void DemolistFetchCallback(const char *pName, int IsDir, int StorageType, void *pUser);
|
||||||
|
|
||||||
// found in menus.cpp
|
// found in menus.cpp
|
||||||
int Render();
|
int Render();
|
||||||
|
|
|
@ -417,7 +417,7 @@ int CMenus::UiDoListboxEnd(float *pScrollValue, bool *pItemActivated)
|
||||||
return gs_ListBoxNewSelected;
|
return gs_ListBoxNewSelected;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMenus::DemolistFetchCallback(const char *pName, int IsDir, int DirType, void *pUser)
|
void CMenus::DemolistFetchCallback(const char *pName, int IsDir, int StorageType, void *pUser)
|
||||||
{
|
{
|
||||||
CMenus *pSelf = (CMenus *)pUser;
|
CMenus *pSelf = (CMenus *)pUser;
|
||||||
int Length = str_length(pName);
|
int Length = str_length(pName);
|
||||||
|
@ -433,14 +433,14 @@ void CMenus::DemolistFetchCallback(const char *pName, int IsDir, int DirType, vo
|
||||||
else
|
else
|
||||||
str_format(Item.m_aName, min(static_cast<int>(sizeof(Item.m_aName)), Length), " %s", pName);
|
str_format(Item.m_aName, min(static_cast<int>(sizeof(Item.m_aName)), Length), " %s", pName);
|
||||||
Item.m_IsDir = IsDir != 0;
|
Item.m_IsDir = IsDir != 0;
|
||||||
Item.m_DirType = DirType;
|
Item.m_StorageType = StorageType;
|
||||||
pSelf->m_lDemos.add(Item);
|
pSelf->m_lDemos.add(Item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMenus::DemolistPopulate()
|
void CMenus::DemolistPopulate()
|
||||||
{
|
{
|
||||||
m_lDemos.clear();
|
m_lDemos.clear();
|
||||||
Storage()->ListDirectory(IStorage::TYPE_SAVE|IStorage::TYPE_CURRENT, m_aCurrentDemoFolder, DemolistFetchCallback, this);
|
Storage()->ListDirectory(IStorage::TYPE_ALL, m_aCurrentDemoFolder, DemolistFetchCallback, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMenus::DemolistOnUpdate(bool Reset)
|
void CMenus::DemolistOnUpdate(bool Reset)
|
||||||
|
@ -466,10 +466,8 @@ void CMenus::RenderDemoList(CUIRect MainView)
|
||||||
if(m_DemolistSelectedIndex >= 0 && !m_DemolistSelectedIsDir)
|
if(m_DemolistSelectedIndex >= 0 && !m_DemolistSelectedIsDir)
|
||||||
{
|
{
|
||||||
char aBuf[512];
|
char aBuf[512];
|
||||||
str_format(aBuf, sizeof(aBuf), "%s%s%s/%s", Storage()->GetDirectory(m_lDemos[m_DemolistSelectedIndex].m_DirType),
|
str_format(aBuf, sizeof(aBuf), "%s/%s", m_aCurrentDemoFolder, m_lDemos[m_DemolistSelectedIndex].m_aFilename);
|
||||||
Storage()->GetDirectory(m_lDemos[m_DemolistSelectedIndex].m_DirType)[0] ? "/" : "",
|
Storage()->RemoveFile(aBuf, m_lDemos[m_DemolistSelectedIndex].m_StorageType);
|
||||||
m_aCurrentDemoFolder, m_lDemos[m_DemolistSelectedIndex].m_aFilename);
|
|
||||||
Storage()->RemoveFile(aBuf);
|
|
||||||
DemolistPopulate();
|
DemolistPopulate();
|
||||||
DemolistOnUpdate(false);
|
DemolistOnUpdate(false);
|
||||||
}
|
}
|
||||||
|
@ -529,10 +527,8 @@ void CMenus::RenderDemoList(CUIRect MainView)
|
||||||
else // file
|
else // file
|
||||||
{
|
{
|
||||||
char aBuf[512];
|
char aBuf[512];
|
||||||
str_format(aBuf, sizeof(aBuf), "%s%s%s/%s", Storage()->GetDirectory(m_lDemos[m_DemolistSelectedIndex].m_DirType),
|
str_format(aBuf, sizeof(aBuf), "%s/%s", m_aCurrentDemoFolder, m_lDemos[m_DemolistSelectedIndex].m_aFilename);
|
||||||
Storage()->GetDirectory(m_lDemos[m_DemolistSelectedIndex].m_DirType)[0] ? "/" : "",
|
const char *pError = Client()->DemoPlayer_Play(aBuf, m_lDemos[m_DemolistSelectedIndex].m_StorageType);
|
||||||
m_aCurrentDemoFolder, m_lDemos[m_DemolistSelectedIndex].m_aFilename);
|
|
||||||
const char *pError = Client()->DemoPlayer_Play(aBuf);
|
|
||||||
if(pError)
|
if(pError)
|
||||||
PopupMessage(Localize("Error"), str_comp(pError, "error loading demo") ? pError : Localize("error loading demo"), Localize("Ok"));
|
PopupMessage(Localize("Error"), str_comp(pError, "error loading demo") ? pError : Localize("error loading demo"), Localize("Ok"));
|
||||||
else
|
else
|
||||||
|
|
|
@ -650,7 +650,7 @@ public:
|
||||||
|
|
||||||
void LoadLanguageIndexfile(IStorage *pStorage, IConsole *pConsole, sorted_array<CLanguage> *pLanguages)
|
void LoadLanguageIndexfile(IStorage *pStorage, IConsole *pConsole, sorted_array<CLanguage> *pLanguages)
|
||||||
{
|
{
|
||||||
IOHANDLE File = pStorage->OpenFile("data/languages/index.txt", IOFLAG_READ);
|
IOHANDLE File = pStorage->OpenFile("languages/index.txt", IOFLAG_READ, IStorage::TYPE_ALL);
|
||||||
if(!File)
|
if(!File)
|
||||||
{
|
{
|
||||||
pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", "couldn't open index file");
|
pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", "couldn't open index file");
|
||||||
|
@ -681,7 +681,7 @@ void LoadLanguageIndexfile(IStorage *pStorage, IConsole *pConsole, sorted_array<
|
||||||
}
|
}
|
||||||
|
|
||||||
char aFileName[128];
|
char aFileName[128];
|
||||||
str_format(aFileName, sizeof(aFileName), "data/languages/%s.txt", pLine);
|
str_format(aFileName, sizeof(aFileName), "languages/%s.txt", pLine);
|
||||||
pLanguages->add(CLanguage(pReplacement+3, aFileName));
|
pLanguages->add(CLanguage(pReplacement+3, aFileName));
|
||||||
}
|
}
|
||||||
io_close(File);
|
io_close(File);
|
||||||
|
@ -724,7 +724,7 @@ void CMenus::RenderSettingsGeneral(CUIRect MainView)
|
||||||
if(OldSelected != s_SelectedLanguage)
|
if(OldSelected != s_SelectedLanguage)
|
||||||
{
|
{
|
||||||
str_copy(g_Config.m_ClLanguagefile, s_Languages[s_SelectedLanguage].m_FileName, sizeof(g_Config.m_ClLanguagefile));
|
str_copy(g_Config.m_ClLanguagefile, s_Languages[s_SelectedLanguage].m_FileName, sizeof(g_Config.m_ClLanguagefile));
|
||||||
g_Localization.Load(s_Languages[s_SelectedLanguage].m_FileName, Console());
|
g_Localization.Load(s_Languages[s_SelectedLanguage].m_FileName, Storage(), Console());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ void CSkins::SkinScan(const char *pName, int IsDir, int DirType, void *pUser)
|
||||||
char aBuf[512];
|
char aBuf[512];
|
||||||
str_format(aBuf, sizeof(aBuf), "skins/%s", pName);
|
str_format(aBuf, sizeof(aBuf), "skins/%s", pName);
|
||||||
CImageInfo Info;
|
CImageInfo Info;
|
||||||
if(!pSelf->Graphics()->LoadPNG(&Info, aBuf))
|
if(!pSelf->Graphics()->LoadPNG(&Info, aBuf, DirType))
|
||||||
{
|
{
|
||||||
str_format(aBuf, sizeof(aBuf), "failed to load skin from %s", pName);
|
str_format(aBuf, sizeof(aBuf), "failed to load skin from %s", pName);
|
||||||
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "game", aBuf);
|
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "game", aBuf);
|
||||||
|
|
|
@ -224,7 +224,7 @@ void CGameClient::OnInit()
|
||||||
//m_pServerBrowser = Kernel()->RequestInterface<IServerBrowser>();
|
//m_pServerBrowser = Kernel()->RequestInterface<IServerBrowser>();
|
||||||
|
|
||||||
// set the language
|
// set the language
|
||||||
g_Localization.Load(g_Config.m_ClLanguagefile, Console());
|
g_Localization.Load(g_Config.m_ClLanguagefile, Storage(), Console());
|
||||||
|
|
||||||
// init all components
|
// init all components
|
||||||
for(int i = 0; i < m_All.m_Num; i++)
|
for(int i = 0; i < m_All.m_Num; i++)
|
||||||
|
@ -239,7 +239,12 @@ void CGameClient::OnInit()
|
||||||
// load default font
|
// load default font
|
||||||
static CFont *pDefaultFont;
|
static CFont *pDefaultFont;
|
||||||
//default_font = gfx_font_load("data/fonts/sazanami-gothic.ttf");
|
//default_font = gfx_font_load("data/fonts/sazanami-gothic.ttf");
|
||||||
pDefaultFont = TextRender()->LoadFont("data/fonts/vera.ttf");
|
|
||||||
|
char aFilename[512];
|
||||||
|
IOHANDLE File = Storage()->OpenFile("fonts/vera.ttf", IOFLAG_READ, IStorage::TYPE_ALL, aFilename, sizeof(aFilename));
|
||||||
|
if(File)
|
||||||
|
io_close(File);
|
||||||
|
pDefaultFont = TextRender()->LoadFont(aFilename);
|
||||||
TextRender()->SetDefaultFont(pDefaultFont);
|
TextRender()->SetDefaultFont(pDefaultFont);
|
||||||
|
|
||||||
g_Config.m_ClThreadsoundloading = 0;
|
g_Config.m_ClThreadsoundloading = 0;
|
||||||
|
@ -254,7 +259,7 @@ void CGameClient::OnInit()
|
||||||
for(int i = 0; i < g_pData->m_NumImages; i++)
|
for(int i = 0; i < g_pData->m_NumImages; i++)
|
||||||
{
|
{
|
||||||
g_GameClient.m_pMenus->RenderLoading(gs_LoadCurrent/(float)gs_LoadTotal);
|
g_GameClient.m_pMenus->RenderLoading(gs_LoadCurrent/(float)gs_LoadTotal);
|
||||||
g_pData->m_aImages[i].m_Id = Graphics()->LoadTexture(g_pData->m_aImages[i].m_pFilename, CImageInfo::FORMAT_AUTO, 0);
|
g_pData->m_aImages[i].m_Id = Graphics()->LoadTexture(g_pData->m_aImages[i].m_pFilename, IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
|
||||||
gs_LoadCurrent++;
|
gs_LoadCurrent++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -559,6 +559,7 @@ CQuad *CEditor::GetSelectedQuad()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: fix/rework the whole file dialog stuff
|
||||||
static void CallbackOpenDir(const char *pFileName, void *pUser)
|
static void CallbackOpenDir(const char *pFileName, void *pUser)
|
||||||
{
|
{
|
||||||
CEditor *pEditor = (CEditor*)pUser;
|
CEditor *pEditor = (CEditor*)pUser;
|
||||||
|
@ -586,7 +587,7 @@ static void CallbackOpenMap(const char *pFileName, void *pUser)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char aCompleteFilename[512];
|
char aCompleteFilename[512];
|
||||||
str_format(aCompleteFilename, sizeof(aCompleteFilename), "%s/%s", pEditor->Client()->UserDirectory(), pFileName);
|
//str_format(aCompleteFilename, sizeof(aCompleteFilename), "%s/%s", pEditor->Client()->UserDirectory(), pFileName);
|
||||||
if(fs_is_dir(aCompleteFilename))
|
if(fs_is_dir(aCompleteFilename))
|
||||||
{
|
{
|
||||||
CallbackOpenDir(pFileName, pUser);
|
CallbackOpenDir(pFileName, pUser);
|
||||||
|
@ -609,7 +610,7 @@ static void CallbackAppendMap(const char *pFileName, void *pUser)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char aCompleteFilename[512];
|
char aCompleteFilename[512];
|
||||||
str_format(aCompleteFilename, sizeof(aCompleteFilename), "%s/%s", pEditor->Client()->UserDirectory(), pFileName);
|
//str_format(aCompleteFilename, sizeof(aCompleteFilename), "%s/%s", pEditor->Client()->UserDirectory(), pFileName);
|
||||||
if(fs_is_dir(aCompleteFilename))
|
if(fs_is_dir(aCompleteFilename))
|
||||||
{
|
{
|
||||||
CallbackOpenDir(pFileName, pUser);
|
CallbackOpenDir(pFileName, pUser);
|
||||||
|
@ -632,7 +633,7 @@ static void CallbackSaveMap(const char *pFileName, void *pUser)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char aCompleteFilename[512];
|
char aCompleteFilename[512];
|
||||||
str_format(aCompleteFilename, sizeof(aCompleteFilename), "%s/%s", pEditor->Client()->UserDirectory(), pFileName);
|
//str_format(aCompleteFilename, sizeof(aCompleteFilename), "%s/%s", pEditor->Client()->UserDirectory(), pFileName);
|
||||||
if(fs_is_dir(aCompleteFilename))
|
if(fs_is_dir(aCompleteFilename))
|
||||||
{
|
{
|
||||||
CallbackOpenDir(pFileName, pUser);
|
CallbackOpenDir(pFileName, pUser);
|
||||||
|
@ -1899,7 +1900,7 @@ void CEditor::ReplaceImage(const char *pFileName, void *pUser)
|
||||||
{
|
{
|
||||||
CEditor *pEditor = (CEditor *)pUser;
|
CEditor *pEditor = (CEditor *)pUser;
|
||||||
CEditorImage ImgInfo(pEditor);
|
CEditorImage ImgInfo(pEditor);
|
||||||
if(!pEditor->Graphics()->LoadPNG(&ImgInfo, pFileName))
|
if(!pEditor->Graphics()->LoadPNG(&ImgInfo, pFileName, IStorage::TYPE_ALL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CEditorImage *pImg = pEditor->m_Map.m_lImages[pEditor->m_SelectedImage];
|
CEditorImage *pImg = pEditor->m_Map.m_lImages[pEditor->m_SelectedImage];
|
||||||
|
@ -1914,7 +1915,7 @@ void CEditor::AddImage(const char *pFileName, void *pUser)
|
||||||
{
|
{
|
||||||
CEditor *pEditor = (CEditor *)pUser;
|
CEditor *pEditor = (CEditor *)pUser;
|
||||||
CEditorImage ImgInfo(pEditor);
|
CEditorImage ImgInfo(pEditor);
|
||||||
if(!pEditor->Graphics()->LoadPNG(&ImgInfo, pFileName))
|
if(!pEditor->Graphics()->LoadPNG(&ImgInfo, pFileName, IStorage::TYPE_ALL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CEditorImage *pImg = new CEditorImage(pEditor);
|
CEditorImage *pImg = new CEditorImage(pEditor);
|
||||||
|
@ -2146,17 +2147,26 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect ToolBar, CUIRect View)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void EditorListdirCallback(const char *pName, int IsDir, int DirType, void *pUser)
|
static void EditorListdirCallback(const char *pName, int IsDir, int StorageType, void *pUser)
|
||||||
{
|
{
|
||||||
CEditor *pEditor = (CEditor*)pUser;
|
CEditor *pEditor = (CEditor*)pUser;
|
||||||
|
int Length = str_length(pName);
|
||||||
if(pName[0] == '.' && (pName[1] == 0 ||
|
if(pName[0] == '.' && (pName[1] == 0 ||
|
||||||
(pName[1] == '.' && pName[2] == 0 && (!str_comp(pEditor->m_aFileDialogPath, "maps") || !str_comp(pEditor->m_aFileDialogPath, "mapres")))))
|
(pName[1] == '.' && pName[2] == 0 && (!str_comp(pEditor->m_aFileDialogPath, "maps") || !str_comp(pEditor->m_aFileDialogPath, "mapres")))))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pEditor->m_FileList.add(string(pName));
|
CEditor::CFilelistItem Item;
|
||||||
|
str_copy(Item.m_aFilename, pName, sizeof(Item.m_aFilename));
|
||||||
|
if(IsDir)
|
||||||
|
str_format(Item.m_aName, sizeof(Item.m_aName), "%s/", pName);
|
||||||
|
else
|
||||||
|
str_format(Item.m_aName, static_cast<int>(sizeof(Item.m_aName)), " %s", pName);
|
||||||
|
Item.m_IsDir = IsDir != 0;
|
||||||
|
Item.m_StorageType = StorageType;
|
||||||
|
pEditor->m_FileList.add(Item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CEditor::AddFileDialogEntry(const char *pName, CUIRect *pView)
|
void CEditor::AddFileDialogEntry(const CFilelistItem *pItem, CUIRect *pView)
|
||||||
{
|
{
|
||||||
if(m_FilesCur > m_FilesNum)
|
if(m_FilesCur > m_FilesNum)
|
||||||
m_FilesNum = m_FilesCur;
|
m_FilesNum = m_FilesCur;
|
||||||
|
@ -2169,9 +2179,9 @@ void CEditor::AddFileDialogEntry(const char *pName, CUIRect *pView)
|
||||||
pView->HSplitTop(15.0f, &Button, pView);
|
pView->HSplitTop(15.0f, &Button, pView);
|
||||||
pView->HSplitTop(2.0f, 0, pView);
|
pView->HSplitTop(2.0f, 0, pView);
|
||||||
|
|
||||||
if(DoButton_File((void*)(10+(int)Button.y), pName, 0, &Button, 0, 0))
|
if(DoButton_File((void*)(10+(int)Button.y), pItem->m_aName, 0, &Button, 0, 0))
|
||||||
{
|
{
|
||||||
str_copy(m_aFileDialogFileName, pName, sizeof(m_aFileDialogFileName));
|
str_copy(m_aFileDialogFileName, pItem->m_aFilename, sizeof(m_aFileDialogFileName));
|
||||||
|
|
||||||
str_format(m_aFileDialogCompleteFilename, sizeof(m_aFileDialogCompleteFilename), "%s/%s", m_aFileDialogPath, m_aFileDialogFileName);
|
str_format(m_aFileDialogCompleteFilename, sizeof(m_aFileDialogCompleteFilename), "%s/%s", m_aFileDialogPath, m_aFileDialogFileName);
|
||||||
|
|
||||||
|
@ -2248,7 +2258,7 @@ void CEditor::RenderFileDialog()
|
||||||
UI()->ClipEnable(&View);
|
UI()->ClipEnable(&View);
|
||||||
|
|
||||||
for(int i = 0; i < m_FileList.size(); i++)
|
for(int i = 0; i < m_FileList.size(); i++)
|
||||||
AddFileDialogEntry(m_FileList[i].cstr(), &View);
|
AddFileDialogEntry(&m_FileList[i], &View);
|
||||||
|
|
||||||
// disable clipping again
|
// disable clipping again
|
||||||
UI()->ClipDisable();
|
UI()->ClipDisable();
|
||||||
|
@ -2274,14 +2284,14 @@ void CEditor::RenderFileDialog()
|
||||||
void CEditor::FilelistPopulate()
|
void CEditor::FilelistPopulate()
|
||||||
{
|
{
|
||||||
m_FileList.clear();
|
m_FileList.clear();
|
||||||
Storage()->ListDirectory(m_FileDialogDirTypes, m_aFileDialogPath, EditorListdirCallback, this);
|
Storage()->ListDirectory(m_FileDialogStorageType, m_aFileDialogPath, EditorListdirCallback, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CEditor::InvokeFileDialog(int ListDirTypes, const char *pTitle, const char *pButtonText,
|
void CEditor::InvokeFileDialog(int StorageType, const char *pTitle, const char *pButtonText,
|
||||||
const char *pBasePath, const char *pDefaultName,
|
const char *pBasePath, const char *pDefaultName,
|
||||||
void (*pfnFunc)(const char *pFileName, void *pUser), void *pUser)
|
void (*pfnFunc)(const char *pFileName, void *pUser), void *pUser)
|
||||||
{
|
{
|
||||||
m_FileDialogDirTypes = ListDirTypes;
|
m_FileDialogStorageType = StorageType;
|
||||||
m_pFileDialogTitle = pTitle;
|
m_pFileDialogTitle = pTitle;
|
||||||
m_pFileDialogButtonText = pButtonText;
|
m_pFileDialogButtonText = pButtonText;
|
||||||
m_pfnFileDialogFunc = pfnFunc;
|
m_pfnFileDialogFunc = pfnFunc;
|
||||||
|
@ -3072,10 +3082,10 @@ void CEditor::Init()
|
||||||
m_UI.SetGraphics(m_pGraphics, m_pTextRender);
|
m_UI.SetGraphics(m_pGraphics, m_pTextRender);
|
||||||
m_Map.m_pEditor = this;
|
m_Map.m_pEditor = this;
|
||||||
|
|
||||||
ms_CheckerTexture = Graphics()->LoadTexture("editor/checker.png", CImageInfo::FORMAT_AUTO, 0);
|
ms_CheckerTexture = Graphics()->LoadTexture("editor/checker.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
|
||||||
ms_BackgroundTexture = Graphics()->LoadTexture("editor/background.png", CImageInfo::FORMAT_AUTO, 0);
|
ms_BackgroundTexture = Graphics()->LoadTexture("editor/background.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
|
||||||
ms_CursorTexture = Graphics()->LoadTexture("editor/cursor.png", CImageInfo::FORMAT_AUTO, 0);
|
ms_CursorTexture = Graphics()->LoadTexture("editor/cursor.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
|
||||||
ms_EntitiesTexture = Graphics()->LoadTexture("editor/entities.png", CImageInfo::FORMAT_AUTO, 0);
|
ms_EntitiesTexture = Graphics()->LoadTexture("editor/entities.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
|
||||||
|
|
||||||
m_TilesetPicker.m_pEditor = this;
|
m_TilesetPicker.m_pEditor = this;
|
||||||
m_TilesetPicker.MakePalette();
|
m_TilesetPicker.MakePalette();
|
||||||
|
|
|
@ -459,7 +459,7 @@ public:
|
||||||
|
|
||||||
m_aFileName[0] = 0;
|
m_aFileName[0] = 0;
|
||||||
|
|
||||||
m_FileDialogDirTypes = 0;
|
m_FileDialogStorageType = 0;
|
||||||
m_pFileDialogTitle = 0;
|
m_pFileDialogTitle = 0;
|
||||||
m_pFileDialogButtonText = 0;
|
m_pFileDialogButtonText = 0;
|
||||||
m_pFileDialogUser = 0;
|
m_pFileDialogUser = 0;
|
||||||
|
@ -508,7 +508,7 @@ public:
|
||||||
virtual void UpdateAndRender();
|
virtual void UpdateAndRender();
|
||||||
|
|
||||||
void FilelistPopulate();
|
void FilelistPopulate();
|
||||||
void InvokeFileDialog(int ListdirType, const char *pTitle, const char *pButtonText,
|
void InvokeFileDialog(int StorageType, const char *pTitle, const char *pButtonText,
|
||||||
const char *pBasepath, const char *pDefaultName,
|
const char *pBasepath, const char *pDefaultName,
|
||||||
void (*pfnFunc)(const char *pFilename, void *pUser), void *pUser);
|
void (*pfnFunc)(const char *pFilename, void *pUser), void *pUser);
|
||||||
|
|
||||||
|
@ -531,7 +531,7 @@ public:
|
||||||
|
|
||||||
char m_aFileName[512];
|
char m_aFileName[512];
|
||||||
|
|
||||||
int m_FileDialogDirTypes;
|
int m_FileDialogStorageType;
|
||||||
const char *m_pFileDialogTitle;
|
const char *m_pFileDialogTitle;
|
||||||
const char *m_pFileDialogButtonText;
|
const char *m_pFileDialogButtonText;
|
||||||
void (*m_pfnFileDialogFunc)(const char *pFileName, void *pUser);
|
void (*m_pfnFileDialogFunc)(const char *pFileName, void *pUser);
|
||||||
|
@ -540,7 +540,19 @@ public:
|
||||||
char m_aFileDialogPath[512];
|
char m_aFileDialogPath[512];
|
||||||
char m_aFileDialogCompleteFilename[512];
|
char m_aFileDialogCompleteFilename[512];
|
||||||
int m_FilesNum;
|
int m_FilesNum;
|
||||||
sorted_array<string> m_FileList;
|
|
||||||
|
struct CFilelistItem
|
||||||
|
{
|
||||||
|
char m_aFilename[128];
|
||||||
|
char m_aName[128];
|
||||||
|
bool m_IsDir;
|
||||||
|
int m_StorageType;
|
||||||
|
|
||||||
|
bool operator<(const CFilelistItem &Other) { return !str_comp(m_aFilename, "..") ? true : !str_comp(Other.m_aFilename, "..") ? false :
|
||||||
|
m_IsDir && !Other.m_IsDir ? true : !m_IsDir && Other.m_IsDir ? false :
|
||||||
|
str_comp_filenames(m_aFilename, Other.m_aFilename) < 0; }
|
||||||
|
};
|
||||||
|
sorted_array<CFilelistItem> m_FileList;
|
||||||
int m_FilesStartAt;
|
int m_FilesStartAt;
|
||||||
int m_FilesCur;
|
int m_FilesCur;
|
||||||
int m_FilesStopAt;
|
int m_FilesStopAt;
|
||||||
|
@ -643,7 +655,7 @@ public:
|
||||||
void RenderMenubar(CUIRect Menubar);
|
void RenderMenubar(CUIRect Menubar);
|
||||||
void RenderFileDialog();
|
void RenderFileDialog();
|
||||||
|
|
||||||
void AddFileDialogEntry(const char *pName, CUIRect *pView);
|
void AddFileDialogEntry(const CFilelistItem *pItem, CUIRect *pView);
|
||||||
void SortImages();
|
void SortImages();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -372,7 +372,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName)
|
||||||
{
|
{
|
||||||
CDataFileReader DataFile;
|
CDataFileReader DataFile;
|
||||||
//DATAFILE *df = datafile_load(filename);
|
//DATAFILE *df = datafile_load(filename);
|
||||||
if(!DataFile.Open(pStorage, pFileName))
|
if(!DataFile.Open(pStorage, pFileName, IStorage::TYPE_ALL))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
Clean();
|
Clean();
|
||||||
|
@ -411,7 +411,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName)
|
||||||
|
|
||||||
// load external
|
// load external
|
||||||
CEditorImage ImgInfo(m_pEditor);
|
CEditorImage ImgInfo(m_pEditor);
|
||||||
if(m_pEditor->Graphics()->LoadPNG(&ImgInfo, aBuf))
|
if(m_pEditor->Graphics()->LoadPNG(&ImgInfo, aBuf, IStorage::TYPE_ALL))
|
||||||
{
|
{
|
||||||
*pImg = ImgInfo;
|
*pImg = ImgInfo;
|
||||||
pImg->m_TexId = m_pEditor->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, CImageInfo::FORMAT_AUTO, 0);
|
pImg->m_TexId = m_pEditor->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, CImageInfo::FORMAT_AUTO, 0);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <engine/shared/linereader.h>
|
#include <engine/shared/linereader.h>
|
||||||
#include <engine/console.h>
|
#include <engine/console.h>
|
||||||
|
#include <engine/storage.h>
|
||||||
|
|
||||||
const char *Localize(const char *pStr)
|
const char *Localize(const char *pStr)
|
||||||
{
|
{
|
||||||
|
@ -40,7 +41,7 @@ void CLocalizationDatabase::AddString(const char *pOrgStr, const char *pNewStr)
|
||||||
m_Strings.add(s);
|
m_Strings.add(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CLocalizationDatabase::Load(const char *pFilename, IConsole *pConsole)
|
bool CLocalizationDatabase::Load(const char *pFilename, IStorage *pStorage, IConsole *pConsole)
|
||||||
{
|
{
|
||||||
// empty string means unload
|
// empty string means unload
|
||||||
if(pFilename[0] == 0)
|
if(pFilename[0] == 0)
|
||||||
|
@ -50,7 +51,7 @@ bool CLocalizationDatabase::Load(const char *pFilename, IConsole *pConsole)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOHANDLE IoHandle = io_open(pFilename, IOFLAG_READ);
|
IOHANDLE IoHandle = pStorage->OpenFile(pFilename, IOFLAG_READ, IStorage::TYPE_ALL);
|
||||||
if(!IoHandle)
|
if(!IoHandle)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ class CLocalizationDatabase
|
||||||
public:
|
public:
|
||||||
CLocalizationDatabase();
|
CLocalizationDatabase();
|
||||||
|
|
||||||
bool Load(const char *pFilename, class IConsole *pConsole);
|
bool Load(const char *pFilename, class IStorage *pStorage, class IConsole *pConsole);
|
||||||
|
|
||||||
int Version() { return m_CurrentVersion; }
|
int Version() { return m_CurrentVersion; }
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ int main(int argc, const char **argv)
|
||||||
|
|
||||||
str_format(aFileName, sizeof(aFileName), "maps/%s", argv[2]);
|
str_format(aFileName, sizeof(aFileName), "maps/%s", argv[2]);
|
||||||
|
|
||||||
if(!DataFile.Open(pStorage, argv[1]))
|
if(!DataFile.Open(pStorage, argv[1], IStorage::TYPE_ALL))
|
||||||
return -1;
|
return -1;
|
||||||
if(!df.Open(pStorage, aFileName))
|
if(!df.Open(pStorage, aFileName))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
31
storage.cfg
Normal file
31
storage.cfg
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
####
|
||||||
|
# This specifies where and in which order Teeworlds looks
|
||||||
|
# for its data (sounds, skins, ...). The search goes top
|
||||||
|
# down which means the first path has the highest priority.
|
||||||
|
# Furthermore the top entry also defines the save path where
|
||||||
|
# all data (settings.cfg, screenshots, ...) are stored.
|
||||||
|
# There are 3 special paths available:
|
||||||
|
# $USERDIR
|
||||||
|
# - ~/.appname on UNIX based systems
|
||||||
|
# - ~/Library/Applications Support/appname on Mac OS X
|
||||||
|
# - %APPDATA%/Appname on Windows based systems
|
||||||
|
# $DATADIR
|
||||||
|
# - the 'data' directory which is part of an official
|
||||||
|
# release
|
||||||
|
# $CURRENTDIR
|
||||||
|
# - current working directory
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# The default file has the following entries:
|
||||||
|
# add_path $USERDIR
|
||||||
|
# add_path $DATADIR
|
||||||
|
# add_path $CURRENTDIR
|
||||||
|
#
|
||||||
|
# A customised one could look like this:
|
||||||
|
# add_path user
|
||||||
|
# add_path mods/mymod
|
||||||
|
####
|
||||||
|
|
||||||
|
add_path $USERDIR
|
||||||
|
add_path $DATADIR
|
||||||
|
add_path $CURRENTDIR
|
Loading…
Reference in a new issue