Datei.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #ifndef Datei_H
  2. #define Datei_H
  3. #include <fstream>
  4. #include "Array.h"
  5. #include "Reader.h"
  6. #include "Writer.h"
  7. namespace Framework
  8. {
  9. class Text; //! Text.h
  10. class Zeit; //! Zeit.h
  11. namespace Encryption
  12. {
  13. class Key; //! Key.h
  14. }
  15. class Datei; //! from this file
  16. //! Reads and writes to a file
  17. class Datei : public Reader,
  18. public Writer,
  19. public virtual ReferenceCounter
  20. {
  21. public:
  22. class Style
  23. {
  24. public:
  25. static const int lesen = 0x01; //! file is opened for reading
  26. static const int schreiben
  27. = 0x02; //! file is opened for writing
  28. static const int ende
  29. = 0x04; //! sets file pointer to the end of the file
  30. };
  31. private:
  32. std::fstream* stream;
  33. Text* pfad;
  34. __int64 gr;
  35. char tmpLByte;
  36. char tmpLBPos;
  37. char tmpSByte;
  38. char tmpSBPos;
  39. Encryption::Key* key;
  40. public:
  41. //! Constructor
  42. DLLEXPORT Datei();
  43. //! Constructor
  44. DLLEXPORT Datei(const char* pfad);
  45. //! Constructor
  46. DLLEXPORT Datei(Text* pfad);
  47. //! Destructor
  48. DLLEXPORT virtual ~Datei();
  49. //! Sets the path to the file
  50. //! \param pfad The path
  51. DLLEXPORT void setDatei(const char* pfad);
  52. //! Sets the path to the file
  53. //! \param pfad The path
  54. DLLEXPORT void setDatei(Text* pfad);
  55. //! Renames or moves the file
  56. //! \param pfad The new path to the file. If only the name changes,
  57. //! it is only renamed
  58. //! \return 1 if the renaming was successful. 0 otherwise
  59. DLLEXPORT bool umbenennen(const char* pfad);
  60. //! Renames or moves the file
  61. //! \param pfad The new path to the file. If only the name changes,
  62. //! it is only renamed
  63. //! \return 1 if the renaming was successful. 0 otherwise
  64. DLLEXPORT bool umbenennen(Text* pfad);
  65. //! Deletes the file
  66. //! \return 1 if the deletion was successful. 0 otherwise
  67. DLLEXPORT bool remove();
  68. //! Creates the file anew. If the path contains folders that don't
  69. //! exist, they will be created
  70. //! return 1 if the creation was successful. 0 otherwise
  71. DLLEXPORT bool erstellen();
  72. //! Opens the file
  73. //! \param style Specifies whether the file is opened for reading and/or
  74. //! writing. All elements from Datei::Style:: are possible
  75. //! return 1 if the file was opened successfully. 0 otherwise
  76. DLLEXPORT bool open(int style);
  77. //! Sets the position of the byte to be read next
  78. //! \param pos The index of the byte
  79. //! \param ende 1 if the index counts from the end of the file. 0 if the
  80. //! index counts from the beginning of the file
  81. DLLEXPORT void setLPosition(__int64 pos, bool ende) override;
  82. //! Sets the position of the byte to be overwritten next
  83. //! \param pos The index of the byte
  84. //! \param ende 1 if the index counts from the end of the file. 0 if the
  85. //! index counts from the beginning of the file
  86. DLLEXPORT void setSPosition(__int64 pos, bool ende) override;
  87. //! Writes to the file
  88. //! \param bytes An array of bytes to be written
  89. //! \param len How many bytes should be written to the file
  90. DLLEXPORT void schreibe(const char* bytes, int len) override;
  91. //! Writes all temporary bytes to the file
  92. DLLEXPORT void flush();
  93. //! Reads from the file
  94. //! \param bytes An array to be filled with bytes from the file
  95. //! \param len How many bytes should be read from the file
  96. DLLEXPORT void lese(char* bytes, int len) override;
  97. //! Reads the next line of the file
  98. //! \return The read line as Text with line break
  99. DLLEXPORT Text* leseZeile() override;
  100. //! Closes the file
  101. DLLEXPORT void close();
  102. //! Sets the encryption key for the file
  103. DLLEXPORT void setKey(char* s, int l);
  104. #ifdef WIN32
  105. //! Sets the timestamp of the last modification of the file (Windows only)
  106. //! \param zeit The timestamp of the last modification
  107. //! \return 1 if the timestamp was set. 0 otherwise
  108. DLLEXPORT bool setLetzteÄnderung(Zeit* zeit);
  109. #endif
  110. //! Reads the next bit from the file
  111. //! \param bit A reference to a bool where the bit will be stored
  112. //! return 1 if the read was successful. 0 otherwise
  113. DLLEXPORT bool getNextBit(bool& bit);
  114. //! Stores a single bit in the file
  115. //! \param bit The bit to be stored
  116. //! return 1 if the storage was successful
  117. DLLEXPORT bool setNextBit(bool bit);
  118. //! Checks whether the file is a directory
  119. //! return 1 if the file is a directory. 0 otherwise
  120. DLLEXPORT bool istOrdner() const;
  121. //! Checks whether the file has been opened
  122. //! \return 1 if the file is open. 0 otherwise
  123. DLLEXPORT bool istOffen() const;
  124. //! Returns the number of sub-files in the directory
  125. //! \return 0 if the file is not a directory. Otherwise the number
  126. //! of sub-files
  127. DLLEXPORT int getUnterdateiAnzahl() const;
  128. //! Returns a list of sub-files
  129. //! return 0 if the file is not a directory. A list with the
  130. //! names of the sub-files
  131. DLLEXPORT RCArray<Text>* getDateiListe() const;
  132. //! Returns the size of the file
  133. //! return -1 if the file is a directory or an error occurred.
  134. //! Otherwise the size of the file
  135. DLLEXPORT __int64 getSize() const;
  136. //! Returns the timestamp of the last modification
  137. //! \return 0 if an error occurred. The timestamp of the
  138. //! last modification otherwise
  139. DLLEXPORT Zeit* getLastChange() const;
  140. //! Checks whether the file exists
  141. //! \return 1 if the file exists. 0 otherwise
  142. DLLEXPORT bool existiert() const;
  143. //! Returns the index of the byte from the file that would be read next
  144. //! return -1 if an error occurred.
  145. //! Otherwise the position of the read pointer
  146. DLLEXPORT __int64 getLPosition() const override;
  147. //! Returns the index of the byte from the file that would be overwritten next
  148. //! return -1 if an error occurred.
  149. //! Otherwise the position of the write pointer
  150. DLLEXPORT __int64 getSPosition() const override;
  151. //! Checks whether the file has been fully read
  152. //! return 1 if the file has been fully read. 0 otherwise
  153. DLLEXPORT bool istEnde() const override;
  154. //! Returns the path to the file
  155. DLLEXPORT Text* getPfad() const;
  156. //! Returns the path to the file without increasing the reference counter
  157. DLLEXPORT Text* zPfad() const;
  158. };
  159. //! File Functions
  160. //! Searches for an unused filename
  161. //! \param zPfad A pointer to the path in which an unused filename
  162. //! should be found. Without increased reference counter.
  163. //! Also used as return value
  164. DLLEXPORT void GetFreePfad(Text* zPfad);
  165. //! Creates the complete path including file
  166. //! \param pfad The path to the file
  167. //! \return 1 if the creation was successful.
  168. DLLEXPORT bool DateiPfadErstellen(Text* pfad);
  169. //! Deletes the specified file
  170. //! \param pfad The path to the file
  171. //! \return 1 if the file was deleted
  172. DLLEXPORT bool DateiRemove(Text* pfad);
  173. //! Renames or moves a file
  174. //! pfad_alt: The path to the file to be renamed.
  175. //! pfad_neu: The new path to the file. If only the name changes,
  176. //! it is only renamed
  177. //! \return 1 if the renaming was successful. 0 otherwise
  178. DLLEXPORT bool DateiUmbenennen(Text* pfad_alt, Text* pfad_neu);
  179. //! Checks whether a file exists
  180. //! \param pfad The path to the file
  181. //! \return 1 if the file exists. 0 if the file was not found
  182. DLLEXPORT bool DateiExistiert(Text* pfad);
  183. //! Checks whether a path is a directory
  184. //! \param pfad The path to the file
  185. //! \return 1 if the file is a directory. 0 otherwise
  186. DLLEXPORT bool DateiIstVerzeichnis(Text* pfad);
  187. //! Creates the complete path including file
  188. //! \param pfad The path to the file
  189. //! \return 1 if the creation was successful.
  190. DLLEXPORT bool DateiPfadErstellen(const char* pfad);
  191. //! Deletes the specified file
  192. //! \param pfad The path to the file
  193. //! \return 1 if the file was deleted
  194. DLLEXPORT bool DateiRemove(const char* pfad);
  195. //! Renames or moves a file
  196. //! pfad_alt: The path to the file to be renamed.
  197. //! pfad_neu: The new path to the file. If only the name changes,
  198. //! it is only renamed
  199. //! \return 1 if the renaming was successful. 0 otherwise
  200. DLLEXPORT bool DateiUmbenennen(const char* pfad_alt, const char* pfad_neu);
  201. //! Checks whether a file exists
  202. //! \param pfad The path to the file
  203. //! \return 1 if the file exists. 0 if the file was not found
  204. DLLEXPORT bool DateiExistiert(const char* pfad);
  205. //! Checks whether a path is a directory
  206. //! \param pfad The path to the file
  207. //! \return 1 if the file is a directory. 0 otherwise
  208. DLLEXPORT bool DateiIstVerzeichnis(const char* pfad);
  209. } // namespace Framework
  210. #endif