-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.hh
53 lines (49 loc) · 1.8 KB
/
io.hh
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
#ifndef IO_HH
#define IO_HH
#include "teg.hh"
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <iostream>
#include <string>
#include <memory>
#ifdef TEG_USE_SN
#include "sn.hh"
#endif
namespace IO {
/* Only use these two for tools! */
std::unique_ptr<std::istream>
OpenRawPathForRead(const std::string& path, bool log_error = true);
std::unique_ptr<std::ostream>
OpenRawPathForWrite(const std::string& path, bool log_error = true);
std::unique_ptr<std::iostream>
OpenRawPathForUpdate(const std::string& path, bool log_error = true);
/* Use this to read data files; FS virtualization may be in effect
Always prints an error on failure */
std::unique_ptr<std::istream> OpenDataFileForRead(const std::string& path);
/* Use these to read/write configuration files
Sequence for writing a config file:
OpenConfigFileForWrite, (write stuff), fclose, UpdateConfigFile
If you don't UpdateConfigFile, the configuration file will not be saved */
std::unique_ptr<std::istream>
OpenConfigFileForRead(const std::string& filename);
std::unique_ptr<std::ostream>
OpenConfigFileForWrite(const std::string& filename);
void UpdateConfigFile(const std::string& filename);
/* Use this for, say, an sqlite config database
Returns a UTF-8 absolute path to a config file with the given name. */
std::string GetConfigFilePath(const std::string& filename);
/* Returns `nullptr` if the file already existed. Use this to save a
screenshot or the like. */
std::unique_ptr<std::ostream>
OpenDesktopFileForWrite(const std::string& filename);
/* Use this, say, if SQLITE_CANTOPEN is returned for a database */
void TryCreateConfigDirectory();
#if __WIN32__
void DoRedirectOutput();
#endif
#ifdef TEG_USE_SN
std::unique_ptr<SN::CatSource> GetSNCatSource();
#endif
};
#endif