1 /*****************************************************************************
2  * Copyright (c) 2014-2020 OpenRCT2 developers
3  *
4  * For a complete list of all authors, please refer to contributors.md
5  * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
6  *
7  * OpenRCT2 is licensed under the GNU General Public License version 3.
8  *****************************************************************************/
9 
10 #pragma once
11 
12 #include "../common.h"
13 
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 struct FileInfo
19 {
20     const utf8* Name;
21     uint64_t Size;
22     uint64_t LastModified;
23 };
24 
25 struct IFileScanner
26 {
27     virtual ~IFileScanner() = default;
28 
29     virtual const FileInfo* GetFileInfo() const abstract;
30     virtual const utf8* GetPath() const abstract;
31     virtual const utf8* GetPathRelative() const abstract;
32 
33     virtual void Reset() abstract;
34     virtual bool Next() abstract;
35 };
36 
37 struct QueryDirectoryResult
38 {
39     uint32_t TotalFiles;
40     uint64_t TotalFileSize;
41     uint32_t FileDateModifiedChecksum;
42     uint32_t PathChecksum;
43 };
44 
45 namespace Path
46 {
47     /**
48      * Scans a directory and optionally sub directories for files that matches the
49      * given pattern and returns an enumerator.
50      * @param pattern The path followed by a semi-colon delimited list of wildcard patterns.
51      * @param recurse Whether to scan sub directories or not.
52      * @returns A new FileScanner, this must be deleted when no longer needed.
53      */
54     [[nodiscard]] std::unique_ptr<IFileScanner> ScanDirectory(const std::string& pattern, bool recurse);
55 
56     /**
57      * Scans a directory and all sub directories
58      * @param result The query result to modify.
59      * @param pattern The path followed by a semi-colon delimited list of wildcard patterns.
60      */
61     void QueryDirectory(QueryDirectoryResult* result, const std::string& pattern);
62 
63     [[nodiscard]] std::vector<std::string> GetDirectories(const std::string& path);
64 } // namespace Path
65