acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
file_context.h
1#pragma once
2
3
4#include "acme/prototype/prototype/memory.h"
5#include "acme/filesystem/file/plain_text_file_options.h"
6#include "file_context_interface.h"
8//#include "acme/prototype/collection/string_array.h"
9
10
11class CLASS_DECL_ACME file_context :
12 virtual public file_context_interface
13{
14public:
15
16
17 ::pointer<::folder> m_pfolderResource;
18 bool m_bFolderResourceCalculated;
19 bool m_bMainResourceMemoryCalculated;
20 ::memory m_memoryMainResource;
21
22
23 file_context();
24 ~file_context() override;
25
26
27 void initialize(::particle * pparticle) override;
28
29
30 virtual void init_system();
31 virtual void init_context();
32
33 virtual void term_system();
34 virtual void term_context();
35
36
37 virtual void destroy() override;
38
39 //virtual void update_module_path();
40
41 virtual ::string get_configuration_text(const ::scoped_string & scopedConfigurationFile);
42
43 virtual void calculate_main_resource_memory();
44
45
46 virtual ::block get_main_resource_block();
47
48
49 virtual ::folder* resource_folder();
50 virtual ::memory_file_pointer create_resource_file(const ::file::path & path);
51 virtual ::memory get_resource_memory(const ::file::path & path);
52 virtual ::file::enum_type resource_get_type(const ::file::path & path, ::string * pstrLogNotFound = nullptr);
53
54
55 virtual void copy(::payload varTarget, ::payload varSource, bool bFailIfExists = false, enum_extract eextract = e_extract_first);
56 virtual void transfer(const ::file::path & pathNew, const ::file::path & path);
57 virtual void erase(const ::file::path & path);
58 virtual ::file::path duplicate(const ::file::path & path);
59 virtual ::file::path paste(const ::file::path & pathLocation, const ::file::path & path);
60 virtual void rename(const ::file::path & pathNew, const ::file::path & path);
61
62
63 virtual void trash_that_is_not_trash(const ::file::path & path);
64 virtual void trash_that_is_not_trash(::file::path_array_base & patha);
65
66
67 virtual ::file::path get_filesystem_file(const ::file::path& path);
68
69
70
71
72
73 virtual void get_status(::file::file_status & status, const ::file::path & path);
74 virtual void set_status(const ::file::path & path, const ::file::file_status & status);
75
76
77 virtual void replace_with(const ::file::path & pathContext, const ::scoped_string & scopedstrNew, const ::scoped_string & scopedstrOld);
78
79
80 virtual ::file::enum_type get_type(const ::file::path & path, ::payload * pvarQuery);
81 virtual ::file::enum_type get_type(const ::file::path & path);
82 virtual ::file::enum_type safe_get_type(const ::file::path& path, ::payload* pvarQuery);
83 virtual ::file::enum_type safe_get_type(const ::file::path& path);
84
85
86 virtual ::payload length(const ::file::path & path);
87
88
89 virtual ::payload length(const ::file::path & path, ::payload * pvarQuery);
90
91 virtual void truncate(const ::file::path & path, filesize size = 0);
92 virtual void set_length(const ::file::path & path, filesize size);
93
94 virtual ::file::path module();
95
96
97 ::file::path time(const ::file::path & pathBasePath, ::i32 iDepth = 0, const ::scoped_string & scopedstrPrefix = nullptr, const ::scoped_string & scopedstrSuffix = nullptr, bool bTryDelete = false);
98 ::file::path time_square(const ::scoped_string & scopedstrPrefix = nullptr, const ::scoped_string & scopedstrSuffix = nullptr);
99 ::file::path time_log(const ::scoped_string & scopedstr);
100
101
102 virtual file_pointer time_square_file(const ::scoped_string & scopedstrPrefix = nullptr, const ::scoped_string & scopedstrSuffix = nullptr);
103 virtual file_pointer get(const ::file::path & name);
104
105 virtual file_pointer get_temporary_upload_file(const ::file::path & pathCurrent);
106
107
108 //template < class T >
109 //string time_square(T * p, bool (T:: * pfnOutput)(::stream &, const ::file::path &), const ::file::path & pathSource)
110 //{
111
112 // string strTime = time_square(p);
113
114 // if (strTime.has_character())
115 // {
116
117 // if (!output(strTime, p, pfnOutput, pszSource))
118 // {
119
120 // return "";
121
122 // }
123
124 // }
125
126 // return strTime;
127
128 //}
129
130
131 //template < typename TYPE >
132 //inline void binary_get(const ::payload & payloadFile, TYPE & t)
133 //{
134
135 // auto preader = get_reader(payloadFile);
136
137 // binary_stream stream(preader);
138
139 // stream.defer_set_loading();
140
141 // stream >> t;
142
143 // //return stream.fail() ? ::error_failed : ::success;
144
145 //}
146
147
148 //template < typename TYPE >
149 //inline void binary_set(const ::payload & payloadFile, const TYPE & t)
150 //{
151
152 // auto pwriter = get_writer(payloadFile);
153
154 // binary_stream stream(pwriter);
155
156 // stream.defer_set_storing();
157
158 // stream << t;
159
160 // //return stream.fail() ? ::error_failed : ::success;
161
162 //}
163
164
165 virtual ::i32 filterex_time_square(const ::scoped_string & scopedstrPrefix, ::file::path_array_base & stra);
166 virtual bool try_create_file(const ::file::path & path, bool bTryDelete);
167
168
169 virtual ::payload as_network_payload(const ::payload & payloadFile);
170 virtual ::payload safe_get_network_payload(const ::payload & payloadFile);
171 virtual ::pointer_array<::string_array> as_comma_separated(const ::payload &payloadFile);
172 virtual ::memory _005SignedMemory(const ::payload & payloadFile);
173 virtual string _005SignedString(const ::payload & payloadFile);
174 virtual string as_string(const ::payload & payloadFile);
175 virtual void as_memory(const ::payload & payloadFile, memory_base & mem);
176 virtual ::memory as_memory(const ::payload & payloadFile);
177 virtual memsize read(const ::payload& payloadFile, void * p, filesize position, memsize size, bool bNoExceptionOnFail = true);
178 virtual memsize read_beginning(const ::payload& payloadFile, void * p, memsize size, bool bNoExceptionOnFail = true);
179 virtual memory beginning(const ::payload& payloadFile, memsize size, bool bNoExceptionOnFail = true);
180
181
182 inline string_array_base lines(const ::payload & payloadFile, bool bAddEmpty = true, bool bNoExceptionOnFail = true)
183 {
184
185 string_array_base straLines;
186
187 get_lines(straLines, payloadFile, bAddEmpty, bNoExceptionOnFail);
188
189 return ::transfer(straLines);
190
191 }
192
193
194 virtual void get_lines(string_array_base & stra, const ::payload & payloadFile, bool bAddEmpty = true, bool bNoExceptionOnFail = true);
195 virtual void put_lines(const ::payload& payloadFile, const string_array_base& stra, const plain_text_file_options& options = {});
196 //virtual void put_lines_utf8(const ::payload & payloadFile, const string_array_base & stra);
197
198
199 virtual ::memory _005Signature(const ::payload & payloadFile);
200
201
202 virtual void put_memory(const ::payload & payloadFile, ::file::file * pfile);
203 virtual void put_memory(const ::payload & payloadFile, const ::block & block);
204 virtual void _005PutSignedMemory(const ::payload & payloadFile, const ::block & block);
205 virtual void put_text(const ::payload& payloadFile, const ::scoped_string & scopedstr);
206 virtual void put_text_utf8(const ::payload & payloadFile, const ::scoped_string & scopedstr);
207 virtual void _005PutSignedText(const ::payload & payloadFile, const ::scoped_string & scopedstr);
208
209
210 //virtual void add_contents(const ::payload & payloadFile, const void * pvoidContents, ::collection::count count);
211 virtual void add_contents(const ::payload & payloadFile, const ::scoped_string & scopedstrContents);
212
213
214 virtual bool is_read_only(const ::file::path & path);
215
216 virtual file_pointer resource_get_file(const ::file::path & path);
217
218 virtual ::file::path sys_temp(const ::scoped_string & scopedstrName, const ::scoped_string & scopedstrExtension);
219 virtual ::file::path sys_temp_unique(const ::file::path & pszName);
220
221
222 virtual ::file::path replace_with_extension(const ::scoped_string & scopedstrExtension, const ::file::path & pathFile);
223 virtual void set_extension(::file::path & str, const ::scoped_string & scopedstrExtension);
224
225
226 //virtual ::file::path dropbox_client();
227
228
229 virtual void normalize(string & str);
230 virtual ::std::strong_ordering cmp(const ::file::path & path1, const ::file::path & path2);
231
232
233 virtual string get_hash(const ::payload & payloadFile, enum_hash ehash);
234
235
236 //virtual string md5(::file::file * pfile);
237 virtual string md5(const ::payload & payloadFile);
238
239 //virtual string nessie(::file::file * pfile);
240 virtual string nessie(const ::payload & payloadFile);
241
242 //virtual ::pointer < ::file::link > resolve_link(const ::file::path & path);
243
244 virtual bool is_link(const ::file::path & path);
245
246 virtual void get_last_write_time(file_time_t * pfile_time, const ::scoped_string & scopedstrFilename);
247
248 //virtual void dtf(const ::file::path & pathFile, const ::file::path & pathFolder);
249
250 //virtual void dtf(const ::file::path & pathFile, ::file::path_array_base & stra);
251
252 //virtual void ftd(const ::file::path & pathFolder, const ::file::path & pathFile);
253
254 // 'n' (natural) terminated ascii number, example: 245765487n
255 // pmd5ctx = openssl/md5.h's MD5_CTX
256 //virtual void write_n_number(::file::file * pfile, void * pmd5ctx, ::i64 iNumber);
257 //virtual void read_n_number(::file::file * pfile, void * pmd5ctx, ::i64 & iNumber);
258
259 //virtual void write_gen_string(::file::file * pfile, void * pmd5ctx, string & str);
260 //virtual void read_gen_string(::file::file * pfile, void * pmd5ctx, string & str);
261
262 virtual ::file_pointer file_get_file(::file::path path, ::file::e_open eopen);
263
264 virtual ::file_pointer data_get_file(const ::scoped_string & scopedstrData, ::file::e_open eopen = ::file::e_open_read | ::file::e_open_binary);
265
266 virtual ::folder_pointer get_folder(::file::file * pfile, const ::scoped_string & scopedstrImplementation, ::file::e_open eopen = ::file::e_open_read | ::file::e_open_binary);
267
268 virtual ::file_pointer http_get_file(const ::url::url & url, ::file::e_open eopen = ::file::e_open_read | ::file::e_open_binary, ::file::e_flag eflag = ::file::e_flag_none);
269
270 ::file_pointer get_file(const ::payload& payloadFile, ::file::e_open eopen, ::pointer < ::file::exception >* ppfileexception = nullptr) override;
271
272 virtual ::file_pointer _get_file(const ::payload & payloadFile, ::file::e_open eopen, ::pointer < ::file::exception > * ppfileexception = nullptr);
273
274 virtual ::file_pointer defer_get_protocol_file(const ::scoped_string & scopedstrProtocol, const ::file::path & path, ::file::e_open eopen, ::pointer < ::file::exception > * pfileexception = nullptr);
275
276 virtual ::file_pointer create_native_file(const ::file::path & path, ::file::e_open eopen, ::pointer < ::file::exception > * ppfileexception = nullptr);
277
278 virtual ::file_pointer get_reader(const ::payload & payloadFile, ::file::e_open eopen = ::file::e_open_read | ::file::e_open_binary);
279
280 virtual ::file_pointer shared_reader(const ::payload & payloadFile, ::file::e_open eopen = ::file::e_open_read | ::file::e_open_binary);
281
282 virtual ::file_pointer get_writer(const ::payload & payloadFile, ::file::e_open eopen = ::file::e_open_write | ::file::e_open_create | ::file::e_open_defer_create_directory | ::file::e_open_binary);
283
284 virtual void post_output(const ::file::path & pathOut, const ::file::path & pathDownloading);
285
286 template < typename T >
287 bool output(::file::file * pfileOut, T * p, bool (T:: * pfnOuput)(::file::file *, ::file::file *), ::file::file * pfileIn);
288
289 //virtual bool transfer(::file::file * pfileOut, ::file::file * pfileIn);
290
291 virtual void transfer(::file::file* pfileOut, ::file::file* pfileIn);
292
293 //virtual ::file::path dropbox_info_network_payload();
294
295
296 virtual ::file::path onedrive_global_ini();
297 virtual ::file::path onedrive_cid_ini();
298
299
300 virtual ::property_set get_ini(const ::payload& payloadFile);
301 virtual void set_ini(const ::payload& payloadFile, const ::property_set & set);
302
303
304 virtual ::property_set get_standard_configuration(const ::payload& payloadFile);
305
306
307// virtual ::extended::status copy(::payload varTarget, ::payload varSource, bool bFailIfExists = false, enum_extract eextract = e_extract_first);
308 //virtual ::extended::status transfer(const ::file::path & pathNew, const ::file::path & path);
309 //virtual ::extended::status del(const ::file::path & path);
310 //virtual ::extended::status rename(const ::file::path & pathNew, const ::file::path & path);
311
312
313 //virtual void trash_that_is_not_trash(const ::file::path & path);
314 //virtual void trash_that_is_not_trash(::file::path_array_base & stra);
315
316
317 //virtual ::extended::status replace(const ::file::path & pathContext, const ::scoped_string & scopedstrFind, const ::scoped_string & scopedstrReplace);
318
319 virtual bool exists(const ::file::path & path);
320
321
322 // virtual ::payload length(const ::file::path & path);
323
324
325 //::file::path time(const ::file::path & pathBasePath, ::i32 iDepth = 1, const ::scoped_string & scopedstrPrefix = nullptr, const ::scoped_string & scopedstrSuffix = nullptr);
326
327
328 //virtual file_pointer time_square_file(const ::scoped_string & scopedstrPrefix = nullptr, const ::scoped_string & scopedstrSuffix = nullptr);
329 //virtual file_pointer get(const ::file::path & name);
330
331
332
333// inline ::memory as_primitive_memory(const ::payload & payloadFile) { ::memory m; as_memory(payloadFile, m); return m; }
334// inline ::memory as_memory(const ::payload & payloadFile) { return as_primitive_memory(payloadFile); }
335
336
337 template < class OBJECT >
338 void put(const ::payload & payloadFile, OBJECT & a)
339 {
340
341 auto pwriter = get_writer(payloadFile);
342
343 pwriter->write(&a, sizeof(a));
344
345 }
346
347
348 void set(const ::payload & payloadFile, const ::memory_base & memory);
349
350
351 template < class OBJECT >
352 void as(OBJECT & a, const ::payload & payloadFile)
353 {
354
355 auto reader = get_reader(payloadFile);
356
357 *reader >> a;
358
359 }
360
361
362 //template < class ARRAY >
363 //void to_array(ARRAY & a, const ::payload & payloadFile)
364 //{
365
366 // auto pfile = get_reader(payloadFile);
367
368 // ::binary_stream s(pfile);
369
370 // __exchange_array(a, s);
371
372 // //return !s.fail();
373
374 //}
375
376
377 //virtual void lines(string_array_base & stra, const ::payload & payloadFile);
378 //virtual void put_lines(const ::payload & payloadFile, const string_array_base & stra);
379
380 //virtual bool put_contents(const ::payload & payloadFile, const void * pvoidContents, ::collection::count count);
381 //virtual bool put_contents(const ::payload & payloadFile, const ::scoped_string & scopedstrContents);
382
383 //virtual bool copy?(const ::payload & payloadFile, const ::stream & stream);
384 //virtual bool put_contents(const ::payload & payloadFile, memory & mem);
385 //virtual bool put_text_utf8(const ::payload & payloadFile, const ::scoped_string & scopedstrContents);
386
387
388 //virtual bool add_contents(const ::payload & payloadFile, const ::scoped_string & scopedstrContents);
389
390
391 string sys_temp(const_char_pointer pszName, const ::scoped_string & scopedstrExtension);
392
393
394 //virtual ::file_pointer get_file(const ::payload & payloadFile, ::u32 nOpenFlags);
395
396
397 //virtual bool is_read_only(const ::file::path & path);
398
399 inline auto open_for_reading(const ::payload & payloadFile, ::file::e_open eopen = ::file::e_open_binary)
400 {
401
402 return get_file(payloadFile, eopen | ::file::e_open_read);
403
404 }
405
406 inline auto create_for_writing(const ::payload & payloadFile, ::file::e_open eopen = ::file::e_open_binary | ::file::e_open_defer_create_directory)
407 {
408
409 return get_file(payloadFile, eopen | ::file::e_open_create | ::file::e_open_write);
410
411 }
412
413
414 // get a file and if there are exceptions, should show end user friendly messages
415 virtual ::file_pointer friendly_get_file(const ::payload & payloadFile, ::file::e_open eopen);
416
417
418 //void dtf(const ::file::path & pathFile, const ::file::path & pathFolder);
419 void dtf(const ::file::path & pathFile, ::file::path_array_base & stra, ::file::path_array_base & straRelative);
420 //void ftd(const ::file::path & pathFolder, const ::file::path & pathFile);
421
422
423 virtual void crypto_set(const ::payload & payloadFile, const ::scoped_string & scopedstrData, const ::scoped_string & scopedstrSalt);
424 virtual void crypto_get(const ::payload & payloadFile, string & str, const ::scoped_string & scopedstrSalt);
425
426
427 template < typename TYPE >
428 bool save(const ::payload & payloadFile, const TYPE & o)
429 {
430
431 return put(payloadFile, o);
432 }
433
434
435 template < typename TYPE >
436 inline bool load(TYPE & o, const ::payload & payloadFile)
437 {
438
439 return as(o, payloadFile);
440
441 }
442
443
444 virtual void save_lines(const ::payload & payloadFile, string_array_base & stra);
445 virtual void load_lines(string_array_base & stra, const ::payload & payloadFile);
446
447
448
449 virtual void touch(const ::file::path & path);
450
451 //virtual string md5(const ::payload & payloadFile);
452
453 //virtual string nessie(const ::payload & payloadFile);
454
455 //virtual ::file::path dropbox_info_network_payload();
456
457 //virtual ::file::path onedrive_global_ini();
458
459 //virtual ::file::path onedrive_cid_ini();
460
461
462 virtual void unzip_to_folder(const ::file::path& pathFolder, const ::file::path& pathZip, ::function<bool(const::scoped_string& scopedstr) > functionCallback = {});
463 virtual ::file::path unzip_exe(const ::file::path& pathZip);
464
465
466};
467
468
469
470CLASS_DECL_ACME void set_bypass_cache_if_empty(::payload & payloadFile);
471CLASS_DECL_ACME bool get_bypass_cache_if_empty(const ::payload & payloadFile);
472
473CLASS_DECL_ACME void set_bypass_cache(::payload & payloadFile);
474CLASS_DECL_ACME ::i32_boolean get_bypass_cache(const ::payload & payloadFile);
475
476
477
478
479
480
481
482template < class T >
483bool file_context::output(::file::file * pfileOut, T * p, bool (T:: * pfnOuput)(::file::file *, ::file::file *), ::file::file * pfileIn)
484{
485
486 ::file::path pathDownloading;
487
488 try
489 {
490
491 //stream outputstream(pparticle, FIRST_VERSION);
492
493 //if (!prepare_output(pparticle, outputstream, pathDownloading, os))
494 //{
495
496 // return false;
497
498 //}
499
500 //stream inputstream(pparticle, FIRST_VERSION);
501
502 //if (!prepare_input(pparticle, inputstream, is))
503 //{
504
505 // return false;
506
507 //}
508
509 if (!(p->*pfnOuput)(pfileOut, pfileIn))
510 {
511
512 return false;
513
514 }
515
516 }
517 catch (...)
518 {
519
520 return false;
521
522 }
523
524 //try
525 //{
526
527 // if (!post_output(pparticle, os.m_pfile->GetFilePath(), pathDownloading))
528 // {
529
530 // return false;
531
532 // }
533
534 //}
535 //catch (...)
536 //{
537
538 // return false;
539
540 //}
541
542 return true;
543
544}
545
Definition file.h:33
Definition path_array.h:19
Definition path.h:52
Definition file_context_interface.h:7
virtual void crypto_get(const ::payload &payloadFile, string &str, const ::scoped_string &scopedstrSalt)
Definition file_context.cpp:4467
virtual void crypto_set(const ::payload &payloadFile, const ::scoped_string &scopedstrData, const ::scoped_string &scopedstrSalt)
Definition file_context.cpp:4457
Definition _template_forward_declaration.h:297
Definition memory_base.h:92
Definition memory.h:33
virtual void destroy() override
Definition bbb_context_object.cpp:242
Definition particle.h:95
Definition payload.h:54
Definition plain_text_file_options.h:6
Definition status.h:15
Definition block.h:46
Definition status.h:12
Definition file_time.h:7