1 /*
2  * Copyright (C) 2018 Matthieu Gautier <mgautier@kymeria.fr>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
11  * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
12  * NON-INFRINGEMENT.  See the GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17  *
18  */
19 
20 #ifndef ZIM_FS_WINDOWS_H_
21 #define ZIM_FS_WINDOWS_H_
22 
23 #include "zim_types.h"
24 
25 #include <stdexcept>
26 #include <memory>
27 
28 typedef void* HANDLE;
29 
30 namespace zim {
31 
32 namespace windows {
33 
34 using path_t = const std::string&;
35 
36 struct ImplFD;
37 
38 class FD {
39   public:
40     typedef HANDLE fd_t;
41   private:
42     std::unique_ptr<ImplFD> mp_impl;
43 
44   public:
45     FD();
46     FD(fd_t handle);
47     FD(int fd);
48     FD(const FD& o) = delete;
49     FD(FD&& o);
50     FD& operator=(FD&& o);
51     FD& operator=(const FD& o) = delete;
52     ~FD();
53     zsize_t readAt(char* dest, zsize_t size, offset_t offset) const;
54     zsize_t getSize() const;
55     int     release();
56     bool    seek(offset_t offset);
57     bool    close();
58 };
59 
60 struct FS {
61     using FD = zim::windows::FD;
62     static std::string join(path_t base, path_t name);
63     static std::unique_ptr<wchar_t[]> toWideChar(path_t path);
64     static FD   openFile(path_t filepath);
65     static bool makeDirectory(path_t path);
66     static void rename(path_t old_path, path_t new_path);
67     static bool remove(path_t path);
68     static bool removeDir(path_t path);
69     static bool removeFile(path_t path);
70 };
71 
72 }; // windows namespace
73 
74 }; // zim namespace
75 
76 #endif //ZIM_FS_WINDOWS_H_
77