forked from twig33/ynoclient
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfileext_guesser.h
96 lines (81 loc) · 3.16 KB
/
fileext_guesser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* This file is part of EasyRPG Player.
*
* EasyRPG Player is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EasyRPG Player is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EP_FILEEXTGUESSER_H
#define EP_FILEEXTGUESSER_H
#include <string>
#include <unordered_map>
#include <utility>
#include "filesystem.h"
class Meta;
/**
* FileExtGuesser contains helper methods for guessing the extensions used on non-standard RPG Projects.
*/
namespace FileExtGuesser {
// Bookkeeping structures for use with GuessAndAddLmuExtension()
struct RPG2KFileExtRemap {
/**
* Construct a filename from a given prefix and suffix.
* Performs extension substitution based on the values stored in extMap
*
* @param prefix The prefix (e.g., 'Map0001')
* @param suffix The suffix (e.g., 'lmu')
* @return The joined filename (e.g., 'Map0001.lmu', OR 'Map0001.xyz')
*/
std::string MakeFilename(StringView prefix, StringView suffix);
std::unordered_map<std::string, std::string> extMap;
};
/**
* Attempts to determine the LMU extension for non-standard projects.
*
* @param fs The filesystem of the project in question
* @param meta The meta object, which can be used to directly specify the extension
* @param mapping The resultant mapping, if any, is stored in this lookup.
*/
void GuessAndAddLmuExtension(const FilesystemView& fs, Meta const& meta, RPG2KFileExtRemap& mapping);
// Bookkeeping structure for use with GetRPG2kProjectWithRenames()
struct RPG2KNonStandardFilenameGuesser {
struct ExtAndSize {
ExtAndSize(std::string fname = "", std::string ext = "", int64_t sz = 0) : fname(std::move(fname)), ext(std::move(ext)), sz(sz) {}
std::string fname;
std::string ext;
int64_t sz;
};
// This contains the LMT and LDB files, in no particular order.
std::pair<ExtAndSize,ExtAndSize> rpgRTs;
/**
* Is this struct 'empty' --i.e., does it contain no useful information?
*
* @return true if both rpgTRs's 'ext' properties are empty; false otherwise
*/
bool Empty() const;
/**
* Perform a series of heuristical guesses to determine what the LDB/LMT extensions are.
*
* @param meta A Meta object loaded from the INI file
* @return A mapping for the LDB and LMT extensions (may be empty if no guess could be made).
*/
RPG2KFileExtRemap guessExtensions(Meta& meta);
};
/**
* Scans a directory tree and tries to identify the LMT/LDB files, but with non-standard extensions.
*
* @param fs The filesystem of the project in question
* @return An object that contains the candidates (check with .Empty())
*/
RPG2KNonStandardFilenameGuesser GetRPG2kProjectWithRenames(const FilesystemView& fs);
}
#endif