acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
file_system.h
1// Create by camilo on 2021-08-09 03:02 <3ThomasBorregaardSorensen!!
2#pragma once
3
4
5#include "acme/platform/department.h"
6#include "acme/filesystem/filesystem/file_system_interface.h"
7
8
9class CLASS_DECL_ACME file_system :
10 virtual public ::platform::department,
11 virtual public ::file_system_interface
12{
13public:
14
15
16
17 //::file::path m_pathCa2Module;
18 ::file::path m_pathModule;
19 ::string_array m_straFileSystemItemSlot;
20 critical_section m_criticalsectionaFileSystemItemSlot[MAX_FILE_SYSTEM_ITEM_SLOT_COUNT];
21
22
23 ::IDENTIFIER_SUFFIX_OPERATING_SYSTEM(acme_)::file_system * m_pplatformfile;
24 ::directory_system * m_pdirectorysystem;
25 ::path_system * m_ppathsystem;
26
27 ::file::path m_pathExecutable;
28
29 ::pointer < ::mutex > m_pmutexFileSystemItem;
30 string_map_base < ::pointer < ::file_system_item > > m_mapFileSystemItem;
31
32
33 file_system();
34 ~file_system() override;
35
36
37 virtual void initialize(::particle* pparticle) override;
38
39 virtual void init_system();
40
41 virtual ::i32 file_system_item_slot_index(const ::scoped_string& scopedstrSlotName);
42
43
44 virtual void ensure_exists(const ::file::path & path);
45 virtual void touch(const ::file::path & path);
46 virtual void touch_app_cloud(const ::file::path & path, const_char_pointer pszContentIdentifier = nullptr);
47 virtual void clear_read_only(const ::file::path & path);
48
49
50 virtual void set_file_normal(const ::file::path & path);
51
52
53 virtual bool is_equal(const ::file::path & path1, const ::file::path & path2);
54 virtual void overwrite_if_different(const ::file::path & pathTarget, const ::file::path & pathSource);
55
56
57
58
59 // executable path
60 virtual ::file::path module();
61
62
63 file_pointer get_file(const ::payload& payloadFile, ::file::e_open eopen, ::pointer < ::file::exception >* pfileexception = nullptr) override;
64
65 virtual file_pointer get_reader(const ::payload& payloadFile, ::file::e_open eopen = ::file::e_open_read | ::file::e_open_binary, ::pointer < ::file::exception >* pfileexception = nullptr);
66
67 virtual file_pointer get_writer(const ::payload& payloadFile, ::file::e_open eopen = ::file::e_open_read_write | ::file::e_open_binary | ::file::e_open_defer_create_directory, ::pointer < ::file::exception >* pfileexception = nullptr);
68
69 //virtual string get_temp_name(const ::file::path & pathName, const ::scoped_string & scopedstrExtension);
70 virtual void append_wait(const ::file::path & pathFile, const block & block, const class time & time);
71 virtual void append(const ::file::path & pathFile, const block & block);
72 virtual ::filesize size(const ::file::path & pathFile);
73 virtual ::memory slice(const ::file::path & pathFile, memsize start, memsize count);
74 virtual ::memory beginning(const ::file::path & pathFile, memsize len);
75 virtual ::memory ending(const ::file::path & pathFile, memsize len);
76 virtual bool append_unique_line(const ::file::path & pathFile, const ::scoped_string & scopedstrLine);
77 virtual ::collection::count find_and_erase(const ::file::path & pathFile, const block & block);
78
79 virtual bool exists(const ::file::path & path);
80 virtual bool __exists(const ::file::path& path);
81
82 //virtual void put_contents(const ::file::path & path, const scoped_string & contents);
83 virtual filesize get_size(const ::file::path & path);
84 virtual filesize get_size_fd(::i32 iFile);
85
86
87 virtual void clear_application_data();
88
89
90 virtual void find_replace(const ::file::path & path, const ::property_set & set);
91
92
93 virtual void put_app_cloud_data(const ::file::path & path, const_char_pointer pszContentIdentifier, const ::block & block);
94
95 virtual ::memory get_app_cloud_data(const ::file::path & path, const_char_pointer pszContentIdentifier);
96
97 virtual void put_documents_cloud_data(const ::file::path & path, const ::block & block);
98
99 virtual ::memory get_documents_cloud_data(const ::file::path & path);
100
101 //virtual FILE * FILE_open(const ::file::path & path, const scoped_string & attrs, ::i32 iShare);
102 //virtual ::i32 FILE_printf(FILE * fp, const scoped_string & s, ...);
103 //virtual ::i32 FILE_close(FILE * fp);
104 //virtual ::i32 FILE_eof(FILE * fp);
105 //virtual filesize FILE_seek(FILE * str, filesize offset, ::i32 origin);
106 //virtual filesize FILE_tell(FILE * fp);
107 //virtual filesize FILE_read(void * buffer, memsize size, memsize count, FILE * str);
108 //virtual filesize FILE_write(const void * buffer, memsize size, memsize count, FILE * str);
109 //virtual char_pointer FILE_gets(char_pointer str, character_count n, FILE * s);
110 //virtual ::i32 FILE_getc(FILE * s);
111 //virtual ::i32 FILE_ungetc(::i32 c, FILE * s);
112 //virtual ::i32 FILE_error(FILE * s);
113 //virtual ::i32 FILE_flush(FILE * s);
114
115 //#ifdef WINDOWS
116 //virtual FILE *_wfopen_dup(const wide_character * path, const wide_character * attrs, ::i32 iShare);
117 //virtual ::i32 fwprintf_dup(FILE *fp, const wide_character * s, ...);
118 //virtual wide_character * fgetws_dup(wide_character * str, ::i32 n, FILE *s);
119 //virtual wint_t fgetwc_dup(FILE *s);
120 //virtual wint_t ungetwc_dup(wint_t w, FILE *s);
121 //#endif
122
123
124 //virtual filesize FILE_get_size(FILE * fp);
125
126 virtual bool is_true(const ::file::path & path);
127
128
129 virtual void set_size(const ::file::path & pathName, filesize iSize);
130 virtual void set_size(::i32 iFileDescriptor, filesize iSize);
131
132
133 virtual void transfer(const ::file::path & pathNewName, const ::file::path & pathOldName);
134
135 virtual void erase(const ::file::path & path);
136 virtual void defer_erase(const ::file::path& path);
137 virtual bool safe_erase(const ::file::path& path);
138
139 //virtual bool set_line(const ::file::path & path, ::collection::index iLine, const ::file::path & pathLine);
140
141 virtual void copy(const ::file::path & pathDup, const ::file::path & pathSrc, bool bOverwrite);
142 virtual void _copy(const ::file::path & pathDup, const ::file::path & pathSrc, bool bOverwrite);
143
144
145 virtual bool text_is_different(const ::file::path & path1, const ::file::path & path2, ::string * pstr1 = nullptr, ::string * pstr2 = nullptr);
146 virtual bool copy_if_text_is_different(const ::file::path & pathTarget, const ::file::path & pathSource, const ::procedure & procedureRunIfFilesAreDifferentAndAfterCopy = {});
147
148
149 virtual bool _memory_map_file_copy(const ::file::path & pathNew, const ::file::path & pathSrc);
150
151 virtual void _read_write_file_copy(const ::file::path & pathNew, const ::file::path & pathSrc, ::memsize buffer_size = 1_MiB);
152
153
154 virtual class ::time modification_time(const ::file::path & path);
155 virtual void set_modification_time(const ::file::path & path, const class ::time & time);
156 virtual void synchronize(const ::file::path & path1, const ::file::path & path2);
157
158
159 virtual void save_stra(const ::file::path & pathName, const string_array_base & stra);
160 virtual void load_stra(const ::file::path & pathName, string_array_base & stra, bool bAddEmpty = true);
161
162
163 virtual void put_contents(const ::file::path & path, const block & block);
164 // virtual void put_contents(const ::file::path& path, const scoped_string& contents);
165
166 template < typename CONTAINER >
167 inline void put_lines(const ::file::path & path, const CONTAINER & container)
168 {
169
170 ::string str;
171
172 for (auto & line : container)
173 {
174
175 str += line;
176
177#ifdef WINDOWS_DESKTOP
178
179 str += "\r\n";
180
181#else
182
183 str += "\n";
184
185#endif
186
187 }
188
189 put_block(path, str);
190
191 }
192
193 virtual void as_memory(memory_base & memory, const ::file::path & path, memsize iReadAtMostByteCount = -1, bool bNoExceptionOnOpen = true);
194 //virtual memsize as_memory(const ::file::path & path, void * p, memsize s);
195 virtual memory as_memory(const ::file::path & path, character_count iReadAtMostByteCount = -1, bool bNoExceptionOnOpen = true);
196 virtual memsize as_memory(const ::file::path & path, void * p, memsize s);
197 virtual memory safe_get_memory(const file::path & path, character_count iReadAtMostByteCount = -1, bool bNoExceptionOnOpen = true);
198 virtual memory __safe_get_memory(const file::path& path, character_count iReadAtMostByteCount = -1, bool bNoExceptionOnOpen = true);
199 virtual memsize __safe_find_string(const ::file::path& path, const_char_pointer psz);
200 virtual string as_string(const ::file::path & path, character_count iReadAtMostByteCount = -1, bool bNoExceptionOnOpen = true);
201 virtual string safe_get_string(const ::file::path & path, character_count iReadAtMostByteCount = -1, bool bNoExceptionOnOpen = true);
202 virtual string __safe_get_string(const ::file::path& path, character_count iReadAtMostByteCount = -1, bool bNoExceptionOnOpen = true);
203
204
205 virtual void put_block(const ::file::path & path, const block & block);
206
207 virtual void put_now(const ::file::path& path);
208 virtual void put_time(const ::file::path& path, const ::earth::time & time);
209 virtual ::earth::time as_time(const ::file::path& path);
210 virtual ::earth::time safe_time(const ::file::path& path);
211
212
213 virtual void as_block(block & block, const ::file::path & path);
214
215 // acme/filesystem/file.h
216 // partial excerpt of...
217 // on 2021-08-10 00:46
218
219
220 //virtual string_array_base file_as_lines(const ::file::path & path, character_count iReadAtMostByteCount = -1);
221 virtual string first_line(const ::file::path & path);
222 virtual string line(const ::file::path & path, ::collection::index iLine);
223 virtual string_array_base lines(const ::file::path & path);
224 virtual void set_line(const ::file::path & path, ::collection::index iLine, const ::scoped_string & scopedstrLine);
225 //virtual string file_extension_dup(const ::file::path & path);
226 virtual string get_temporary_file_name(const ::scoped_string & scopedstrName, const ::scoped_string & scopedstrExtension);
227
228 virtual void get_temporary_file_name_template(char_pointer szRet, character_count iBufferSize, const scoped_string & scopedstrName, const ::scoped_string & scopedstrExtension, const ::scoped_string & scopedstrTemplate);
229
230 //virtual string file_path_final_extension(const ::file::path & path);
231 //virtual string url_dir_name_for_relative(const ::file::path & path);
232 //virtual string solve_relative(const ::scoped_string & scopedstr, bool * pbUrl = nullptr);
233 //virtual bool solve_relative_inline(string & str, bool & bUrl, bool & bOnlyNativeFileSep, character_count * iaSlash, ::i32 * piSlashCount); // returns true if original string had trailing slash
234 //virtual string defer_solve_relative(const ::scoped_string & scopedstrRelative, const ::scoped_string & scopedstrCurrent);
235 virtual void append(const ::scoped_string & scopedstrFile, const block & block);
236 virtual void append_wait(const ::scoped_string & scopedstrFile, const block & block, const class time & timeWait = ::time::infinity());
237 //virtual bool file_append_wait(const ::scoped_string & scopedstrFile, const ::scoped_string & scopedstr, character_count s, const class ::time & millisTimeout = ::time::infinite());
238
239 //virtual void write(FILE * file, const void * pdata, memsize nCount, memsize * puiWritten);
240
241
242 virtual bool _exists(const ::file::path & path);
243 virtual void _erase(const ::file::path & path);
244
245
246
247 virtual ::file::path time_put_contents(const ::file::path& pathFolder, const ::scoped_string & scopedstrPrefix, const ::scoped_string & scopedstrExtension, const ::scoped_string & scopedstr);
248
249
250
251
252
253 //virtual void update_module_path();
254
255
256 //virtual ::file::path get_last_run_application_path_file(const ::scoped_string & scopedstrAppId);
257 //virtual ::file::path get_last_run_application_path(const ::scoped_string & scopedstrAppId);
258 //virtual bool set_last_run_application_path(const ::scoped_string & scopedstrAppId);
259
260
261 //bool _file_system_file_exists(const ::file_system_cache_item & pfilesystemcacheitem) override;
262 //bool _file_system_is_folder(const ::file_system_cache_item & pfilesystemcacheitem) override;
263 bool _file_system_has_script(const ::file_system_cache_item & pfilesystemcacheitem) override;
264 ::string _file_system_expanded_md5(const ::file_system_cache_item & pfilesystemcacheitem) override;
265
266
267 ::file_system_cache_item file_system_item(const ::scoped_string& scopedstrName, ::file_system_real_path_interface* pfilesystemrealpathinterface) override;
268
269 ::file_system_item * get_file_system_item(const ::scoped_string& scopedstrName, ::file_system_real_path_interface * pfilesystemrealpathinterface) override;
270
271
272};
273
274
275
Definition file_system_interface.h:15
Definition aaa_file_system.h:10
Definition department.h:13