Implement table saving functionality
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
|
||||
#include <utils.h>
|
||||
|
||||
int utils_file_exists(const wchar_t *filePath) {
|
||||
int utils_path_exists(const wchar_t *filePath) {
|
||||
return GetFileAttributesW(filePath) != INVALID_FILE_ATTRIBUTES;
|
||||
}
|
||||
|
||||
@ -33,6 +33,36 @@ uint32_t utils_file_crc32c(const wchar_t *filePath) {
|
||||
return crc;
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/a/16719260
|
||||
void utils_create_dir_recursively(const wchar_t *path) {
|
||||
wchar_t dir[MAX_PATH];
|
||||
ZeroMemory(dir, MAX_PATH * sizeof(wchar_t));
|
||||
|
||||
wchar_t *end = wcschr(path, L'\\');
|
||||
|
||||
while(end != NULL)
|
||||
{
|
||||
wcsncpy(dir, path, end - path + 1);
|
||||
|
||||
if (!utils_path_exists(dir) && !CreateDirectoryW(dir, NULL)) {
|
||||
msg_err_w(L"Failed to create directory: %ls", dir);
|
||||
}
|
||||
|
||||
end = wcschr(++end, L'\\');
|
||||
}
|
||||
}
|
||||
|
||||
void utils_save_to_file(const wchar_t *filePath, const void *buf, size_t length) {
|
||||
HANDLE file = CreateFileW(filePath, FILE_WRITE_ACCESS, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (!file) {
|
||||
msg_err_w(L"Could not open file: %ls", filePath);
|
||||
}
|
||||
|
||||
WriteFile(file, buf, length, NULL, FALSE);
|
||||
|
||||
CloseHandle(file);
|
||||
}
|
||||
|
||||
char utils_env_enabled(const char *env) {
|
||||
char *envText = getenv(env);
|
||||
return envText && *envText;
|
||||
|
||||
Reference in New Issue
Block a user