2016-03-11 14:57:17 +01:00
|
|
|
/* Copyright (c) 2002-2012 Croteam Ltd. All rights reserved. */
|
|
|
|
|
|
|
|
#ifndef SE_INCL_FILENAME_H
|
|
|
|
#define SE_INCL_FILENAME_H
|
|
|
|
#ifdef PRAGMA_ONCE
|
|
|
|
#pragma once
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <Engine/Base/CTString.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Special kind of string, dedicated to storing filenames.
|
|
|
|
*/
|
|
|
|
class ENGINE_API CTFileName : public CTString {
|
|
|
|
public:
|
2016-03-29 03:03:54 +02:00
|
|
|
static const char *convertFromWin32(const char *str);
|
|
|
|
static const char *convertToWin32(const char *src);
|
|
|
|
|
2016-03-11 14:57:17 +01:00
|
|
|
class CSerial *fnm_pserPreloaded; // pointer to already loaded object if available
|
|
|
|
private:
|
2016-03-29 03:03:54 +02:00
|
|
|
|
2016-03-11 14:57:17 +01:00
|
|
|
/* Constructor from character string. */
|
2016-03-29 03:03:54 +02:00
|
|
|
inline CTFileName(const char *pString) : CTString(convertFromWin32(pString)), fnm_pserPreloaded(NULL) {}
|
2016-03-11 14:57:17 +01:00
|
|
|
public:
|
|
|
|
/* Default constructor. */
|
|
|
|
inline CTFileName(void) : fnm_pserPreloaded(NULL) {};
|
|
|
|
/* Copy constructor. */
|
2016-03-29 03:03:54 +02:00
|
|
|
inline CTFileName(const CTString &strOriginal) : CTString(convertFromWin32(strOriginal)), fnm_pserPreloaded(NULL) {}
|
2016-03-11 14:57:17 +01:00
|
|
|
/* Constructor from character string for insertion in exe-file. */
|
2016-03-29 03:03:54 +02:00
|
|
|
inline CTFileName(const char *pString, int i) : CTString(convertFromWin32(pString+i)), fnm_pserPreloaded(NULL) {}
|
2016-03-11 14:57:17 +01:00
|
|
|
|
2016-04-01 03:53:54 +02:00
|
|
|
void SetAbsolutePath(void) {} // !!! FIXME
|
|
|
|
|
2016-03-11 14:57:17 +01:00
|
|
|
/* Assignment. */
|
|
|
|
CTFileName &operator=(const char *strCharString);
|
|
|
|
inline void operator=(const CTString &strOther) {
|
2016-03-29 03:03:54 +02:00
|
|
|
CTString::operator=(convertFromWin32(strOther));
|
2016-03-11 14:57:17 +01:00
|
|
|
fnm_pserPreloaded = NULL;
|
|
|
|
};
|
|
|
|
|
2016-03-29 03:03:54 +02:00
|
|
|
/* Get CTString with win32-style dir separators for string compares. */
|
|
|
|
CTString Win32FmtString(void) const;
|
|
|
|
|
2016-03-11 14:57:17 +01:00
|
|
|
/* Get directory part of a filename. */
|
|
|
|
CTFileName FileDir(void) const;
|
|
|
|
/* Get name part of a filename. */
|
|
|
|
CTFileName FileName(void) const;
|
|
|
|
/* Get extension part of a filename. */
|
|
|
|
CTFileName FileExt(void) const;
|
|
|
|
/* Get path and file name without extension. */
|
|
|
|
CTFileName NoExt(void) const;
|
|
|
|
/* Remove application path from a file name. */
|
2016-03-29 03:03:54 +02:00
|
|
|
void RemoveApplicationPath_t(void); // throw char *
|
2016-03-11 14:57:17 +01:00
|
|
|
|
|
|
|
// filename is its own name (used for storing in nametable)
|
|
|
|
inline const CTFileName &GetName(void) { return *this; };
|
|
|
|
|
|
|
|
void ReadFromText_t(CTStream &strmStream, const CTString &strKeyword=""); // throw char *
|
|
|
|
|
|
|
|
/* Read from stream. */
|
|
|
|
ENGINE_API friend CTStream &operator>>(CTStream &strmStream, CTFileName &fnmFileName);
|
|
|
|
/* Write to stream. */
|
|
|
|
ENGINE_API friend CTStream &operator<<(CTStream &strmStream, const CTFileName &fnmFileName);
|
|
|
|
};
|
|
|
|
|
|
|
|
// macro for defining a literal filename in code (EFNM = exe-filename)
|
|
|
|
#define CTFILENAME(string) CTFileName("EFNM" string, 4)
|
|
|
|
#define DECLARE_CTFILENAME(name, string) CTFileName name("EFNM" string, 4)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* include-once check. */
|
|
|
|
|