CFileInfo.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * CFileInfo.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "CResourceLoader.h"
  12. /**
  13. * A class which holds information about a file.
  14. */
  15. class DLL_LINKAGE CFileInfo
  16. {
  17. public:
  18. /**
  19. * Default ctor.
  20. */
  21. CFileInfo();
  22. /**
  23. * Ctor.
  24. *
  25. * @param name The path and name of the file.
  26. */
  27. explicit CFileInfo(const std::string & name);
  28. /**
  29. * Checks if the file exists.
  30. *
  31. * @return true if the file exists, false if not.
  32. */
  33. bool exists() const;
  34. /**
  35. * Checks if the file is a directory.
  36. *
  37. * @return true if the file is a directory, false if not.
  38. */
  39. bool isDirectory() const;
  40. /**
  41. * Sets the name.
  42. *
  43. * @param name The name of the file
  44. */
  45. void setName(const std::string & name);
  46. /**
  47. * Gets the name of the file.
  48. *
  49. * @return the path and name of the file. E.g. ./dir/file.ext
  50. */
  51. std::string getName() const;
  52. /**
  53. * Gets the path to the file only.
  54. *
  55. * @return the path to the file only. E.g. ./dir/
  56. */
  57. std::string getPath() const;
  58. /**
  59. * Gets the file extension.
  60. *
  61. * @return the file extension. E.g. .ext
  62. */
  63. std::string getExtension() const;
  64. /**
  65. * Returns the name of the file.
  66. *
  67. * @return the name of the file. E.g. foo.txt
  68. */
  69. std::string getFilename() const;
  70. /**
  71. * Gets the file name exclusive the extension of the file.
  72. *
  73. * @return the file name exclusive the extension of the file. E.g. foo
  74. */
  75. std::string getStem() const;
  76. /**
  77. * Gets the extension type as a EResType enumeration.
  78. *
  79. * @return the extension type as a EResType enumeration.
  80. */
  81. EResType getType() const;
  82. /**
  83. * Gets the timestamp of the file.
  84. *
  85. * @return the timestamp of the file, 0 if no timestamp was set
  86. */
  87. std::time_t getDate() const;
  88. /**
  89. * Returns a list of pathnames denoting the files in the directory denoted by this pathname.
  90. *
  91. * If the pathname of this directory is absolute, then the file info pathnames are absolute as well. If the pathname of this directory is relative
  92. * then the file info pathnames are relative to the basedir as well.
  93. *
  94. * @param extensionFilter Filters files by the given extension. Optional. Empty string if all files and directories in the directory should be listed.
  95. * @return a list of pathnames denoting the files and directories in the directory denoted by this pathname as a unique ptr.
  96. * The array will be empty if the directory is empty. Ptr is null if the directory doesn't exist or if it isn't a directory.
  97. */
  98. std::unique_ptr<std::list<CFileInfo> > listFiles(const std::string & extensionFilter = "") const;
  99. private:
  100. /** Contains the original URI(not modified) e.g. ./dir/foo.txt */
  101. std::string name;
  102. };