2
3
4
5
18 struct _stat buffer {};
19 return _stat (path, &buffer) == 0;
32 mode_str = binary ?
"w+b" :
"w+";
36 mode_str = binary ?
"rb" :
"r";
40 mode_str = binary ?
"wb" :
"w";
44 SPICES_CORE_INFO(
"Invalid mode passed while trying to open file")
49 auto state = fopen_s(&file, path, mode_str);
54 ss <<
"Error opening file: " << path;
56 SPICES_CORE_WARN(ss.str().c_str())
72 auto state = fclose(
static_cast<FILE*>(handle
->handle));
84 auto state = fseek(
static_cast<FILE*>(handle
->handle), 0, SEEK_END);
85 *out_size = ftell(
static_cast<FILE*>(handle
->handle));
86 rewind(
static_cast<FILE*>(handle
->handle));
98 *out_bytes_read = fread(out_data, 1, data_size,
static_cast<FILE*>(handle->handle));
99 if (*out_bytes_read != data_size)
112 if (handle
->handle && line_buf && out_line_length && max_length > 0)
114 if (fgets(line_buf,
static_cast<
int>(max_length),
static_cast<FILE*>(handle
->handle)) !=
nullptr)
116 *out_line_length = strlen(line_buf);
127 if (handle
->handle && out_bytes && out_bytes_read)
135 *out_bytes_read = fread(out_bytes, 1, size,
static_cast<FILE*>(handle->handle));
136 return *out_bytes_read == size;
147 *out_bytes_written = fwrite(data, 1, data_size,
static_cast<FILE*>(handle->handle));
148 if (*out_bytes_written != data_size)
152 auto state = fflush(
static_cast<FILE*>(handle
->handle));
164 int result = fputs(text,
static_cast<FILE*>(handle
->handle));
167 result = fputc(
'\n',
static_cast<FILE*>(handle
->handle));
172 auto state = fflush(
static_cast<FILE*>(handle
->handle));
173 return result != EOF;
178 std::string
FileLibrary::FileLibrary_OpenInExplore(
const char* filter, HWND hwnd)
183 CHAR szFile[260] = { 0 };
185 ZeroMemory(&ofn,
sizeof(OPENFILENAMEA));
186 ofn.lStructSize =
sizeof(OPENFILENAMEA);
187 ofn.hwndOwner = hwnd;
188 ofn.lpstrFile = szFile;
189 ofn.nMaxFile =
sizeof(szFile);
190 ofn.lpstrFilter = filter;
191 ofn.nFilterIndex = 1;
192 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
193 if (GetOpenFileNameA(&ofn) == TRUE)
195 return ofn.lpstrFile;
200 std::string
FileLibrary::FileLibrary_SaveInExplore(
const char* filter, HWND hwnd)
205 CHAR szFile[260] = { 0 };
207 ZeroMemory(&ofn,
sizeof(OPENFILENAMEA));
208 ofn.lStructSize =
sizeof(OPENFILENAMEA);
209 ofn.hwndOwner = hwnd;
210 ofn.lpstrFile = szFile;
211 ofn.nMaxFile =
sizeof(szFile);
212 ofn.lpstrFilter = filter;
213 ofn.nFilterIndex = 1;
214 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
215 if (GetSaveFileNameA(&ofn) == TRUE)
217 return ofn.lpstrFile;
228 std::stringstream ss;
229 ss <<
"File path: " << srcFilePath <<
" was not found.";
231 SPICES_CORE_WARN(ss.str())
235 std::ifstream src(srcFilePath, std::ios::binary);
236 std::ofstream dst(dstFilePath, std::ios::binary);
249 if (remove(filePath) != 0)
251 std::stringstream ss;
252 ss <<
"File path: " << filePath <<
" delete failed.";
254 SPICES_CORE_WARN(ss.str())
#define SPICES_PROFILE_ZONE
static bool FileLibrary_Size(const FileHandle *handle, uint64_t *out_size)
Calculate The file size.
static bool FileLibrary_Read(const FileHandle *handle, uint64_t data_size, void *out_data, uint64_t *out_bytes_read)
Read Specific size of data form the current file handle pointer, and move pointer the same size.
static bool FileLibrary_Write_Line(const FileHandle *handle, const char *text)
Write one line data to the file handle pointer.
static bool FileLibrary_Write(const FileHandle *handle, uint64_t data_size, const void *data, uint64_t *out_bytes_written)
Write given data to the file handle pointer.
static bool FileLibrary_Open(const char *path, FileModes mode, bool binary, FileHandle *out_handle)
Open the file using given string.
static void FileLibrary_Close(FileHandle *handle)
Close the file by the file handle.
static bool FileLibrary_Delete(const char *filePath)
Delete a file from disk.
static bool FileLibrary_CopyFile(std::string srcFilePath, std::string dstFilePath)
Copy a file to dst path.
static bool FileLibrary_Read_Line(const FileHandle *handle, uint64_t max_length, char *line_buf, uint64_t *out_line_length)
Read one line from the current file handle pointer, and move pointer the same size.
static bool FileLibrary_Exists(const char *path)
Determine whether the given string is existing a file.
static bool FileLibrary_Read_all_bytes(const FileHandle *handle, char *out_bytes, uint64_t *out_bytes_read)
Read all data form the current file handle pointer.
File Static Function Library.
@ FILE_MODE_READ
model : read
@ FILE_MODE_WRITE
model : write
void * handle
FILE* handle. Need cast while use.
bool is_valid
Is this handle Valid.
This Struct is FILE* handle pointer Wrapper.