Merge pull request #90 from gizmo98/patch-2
[libretro-ppsspp.git] / Core / Loaders.h
blobc5dbbdc57954f4ff4b787d7bc35bf8dc9f35ad20
1 // Copyright (c) 2012- PPSSPP Project.
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0 or later versions.
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 2.0 for more details.
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
15 // Official git repository and contact information can be found at
16 // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
18 #pragma once
20 #include <string>
22 enum IdentifiedFileType {
23 FILETYPE_ERROR,
25 FILETYPE_PSP_PBP_DIRECTORY,
27 FILETYPE_PSP_PBP,
28 FILETYPE_PSP_ELF,
29 FILETYPE_PSP_ISO,
30 FILETYPE_PSP_ISO_NP,
32 FILETYPE_PSP_DISC_DIRECTORY,
34 FILETYPE_UNKNOWN_BIN,
35 FILETYPE_UNKNOWN_ELF,
37 // Try to reduce support emails...
38 FILETYPE_ARCHIVE_RAR,
39 FILETYPE_ARCHIVE_ZIP,
40 FILETYPE_ARCHIVE_7Z,
41 FILETYPE_PSP_PS1_PBP,
42 FILETYPE_ISO_MODE2,
44 FILETYPE_NORMAL_DIRECTORY,
46 FILETYPE_PSP_SAVEDATA_DIRECTORY,
47 FILETYPE_PPSSPP_SAVESTATE,
49 FILETYPE_UNKNOWN
52 class FileLoader {
53 public:
54 virtual ~FileLoader() {}
56 virtual bool Exists() = 0;
57 virtual bool IsDirectory() = 0;
58 virtual s64 FileSize() = 0;
59 virtual std::string Path() const = 0;
60 virtual std::string Extension() {
61 const std::string filename = Path();
62 size_t pos = filename.find_last_of('.');
63 if (pos == filename.npos) {
64 return "";
65 } else {
66 return filename.substr(pos);
70 virtual void Seek(s64 absolutePos) = 0;
71 virtual size_t Read(size_t bytes, size_t count, void *data) = 0;
72 virtual size_t Read(size_t bytes, void *data) {
73 return Read(1, bytes, data);
75 virtual size_t ReadAt(s64 absolutePos, size_t bytes, size_t count, void *data) = 0;
76 virtual size_t ReadAt(s64 absolutePos, size_t bytes, void *data) {
77 return ReadAt(absolutePos, 1, bytes, data);
81 FileLoader *ConstructFileLoader(const std::string &filename);
83 // This can modify the string, for example for stripping off the "/EBOOT.PBP"
84 // for a FILETYPE_PSP_PBP_DIRECTORY.
85 IdentifiedFileType Identify_File(FileLoader *fileLoader);
87 // Can modify the string filename, as it calls IdentifyFile above.
88 bool LoadFile(FileLoader **fileLoaderPtr, std::string *error_string);