| 1 | /** |
| 2 | * Copyright (c) 2006-2023 LOVE Development Team |
| 3 | * |
| 4 | * This software is provided 'as-is', without any express or implied |
| 5 | * warranty. In no event will the authors be held liable for any damages |
| 6 | * arising from the use of this software. |
| 7 | * |
| 8 | * Permission is granted to anyone to use this software for any purpose, |
| 9 | * including commercial applications, and to alter it and redistribute it |
| 10 | * freely, subject to the following restrictions: |
| 11 | * |
| 12 | * 1. The origin of this software must not be misrepresented; you must not |
| 13 | * claim that you wrote the original software. If you use this software |
| 14 | * in a product, an acknowledgment in the product documentation would be |
| 15 | * appreciated but is not required. |
| 16 | * 2. Altered source versions must be plainly marked as such, and must not be |
| 17 | * misrepresented as being the original software. |
| 18 | * 3. This notice may not be removed or altered from any source distribution. |
| 19 | **/ |
| 20 | |
| 21 | #ifndef LOVE_FILESYSTEM_DROPPED_FILE_H |
| 22 | #define LOVE_FILESYSTEM_DROPPED_FILE_H |
| 23 | |
| 24 | // LOVE |
| 25 | #include "common/config.h" |
| 26 | #include "File.h" |
| 27 | |
| 28 | // C |
| 29 | #include <cstdio> |
| 30 | |
| 31 | namespace love |
| 32 | { |
| 33 | namespace filesystem |
| 34 | { |
| 35 | |
| 36 | /** |
| 37 | * File which is created when a user drags and drops an actual file onto the |
| 38 | * LOVE game. Uses C's stdio. Filenames are system-dependent full paths. |
| 39 | **/ |
| 40 | class DroppedFile : public File |
| 41 | { |
| 42 | public: |
| 43 | |
| 44 | static love::Type type; |
| 45 | |
| 46 | DroppedFile(const std::string &filename); |
| 47 | virtual ~DroppedFile(); |
| 48 | |
| 49 | // Implements File. |
| 50 | using File::read; |
| 51 | using File::write; |
| 52 | bool open(Mode mode) override; |
| 53 | bool close() override; |
| 54 | bool isOpen() const override; |
| 55 | int64 getSize() override; |
| 56 | int64 read(void *dst, int64 size) override; |
| 57 | bool write(const void *data, int64 size) override; |
| 58 | bool flush() override; |
| 59 | bool isEOF() override; |
| 60 | int64 tell() override; |
| 61 | bool seek(uint64 pos) override; |
| 62 | bool setBuffer(BufferMode bufmode, int64 size) override; |
| 63 | BufferMode getBuffer(int64 &size) const override; |
| 64 | Mode getMode() const override; |
| 65 | const std::string &getFilename() const override; |
| 66 | |
| 67 | private: |
| 68 | |
| 69 | static const char *getModeString(Mode mode); |
| 70 | |
| 71 | std::string filename; |
| 72 | |
| 73 | FILE *file; |
| 74 | |
| 75 | Mode mode; |
| 76 | |
| 77 | BufferMode bufferMode; |
| 78 | int64 bufferSize; |
| 79 | |
| 80 | }; // DroppedFile |
| 81 | |
| 82 | } // filesystem |
| 83 | } // love |
| 84 | |
| 85 | #endif // LOVE_FILESYSTEM_DROPPED_FILE_H |
| 86 | |