SpiecsEngine
 
Loading...
Searching...
No Matches

◆ FileLibrary_Open()

bool Spices::FileLibrary::FileLibrary_Open ( const char * path,
FileModes mode,
bool binary,
FileHandle * out_handle )
static

Open the file using given string.

Parameters
[in]pathThe file path.
[in]modeThe file mode.
[in]binaryThe file is a binary file ro not.
[out]out_handleOut The file handle pointer.
Returns
true if open the file succeed.

Definition at line 22 of file FileLibrary.cpp.

23 {
25
26 out_handle->is_valid = false;
27 out_handle->handle = nullptr;
28 const char* mode_str;
29
30 if ((mode & FILE_MODE_READ) != 0 && (mode & FILE_MODE_WRITE) != 0)
31 {
32 mode_str = binary ? "w+b" : "w+";
33 }
34 else if ((mode & FILE_MODE_READ) != 0 && (mode & FILE_MODE_WRITE) == 0)
35 {
36 mode_str = binary ? "rb" : "r";
37 }
38 else if ((mode & FILE_MODE_READ) == 0 && (mode & FILE_MODE_WRITE) != 0)
39 {
40 mode_str = binary ? "wb" : "w";
41 }
42 else
43 {
44 SPICES_CORE_INFO("Invalid mode passed while trying to open file")
45 return false;
46 }
47
48 FILE* file;
49 auto state = fopen_s(&file, path, mode_str);
50
51 if (!file)
52 {
53 std::stringstream ss;
54 ss << "Error opening file: " << path;
55
56 SPICES_CORE_WARN(ss.str().c_str())
57 return false;
58 }
59
60 out_handle->handle = file;
61 out_handle->is_valid = true;
62
63 return true;
64 }
#define SPICES_PROFILE_ZONE
@ FILE_MODE_READ
model : read
Definition FileLibrary.h:37
@ FILE_MODE_WRITE
model : write
Definition FileLibrary.h:42

References Spices::FILE_MODE_READ, Spices::FILE_MODE_WRITE, Spices::FileHandle::handle, and Spices::FileHandle::is_valid.

Referenced by Spices::MeshLoader::LoadFromSASSET(), Spices::MaterialLoader::LoadFromSASSET(), SpicesTest::TEST(), SpicesTest::TEST(), SpicesTest::TEST(), SpicesTest::TEST(), SpicesTest::TEST(), SpicesTest::TEST(), SpicesTest::TEST(), SpicesTest::TEST(), SpicesTest::TEST(), SpicesTest::TEST(), Spices::VulkanShaderModule::VulkanShaderModule(), and Spices::MeshLoader::WriteSASSET().