Kinoko
A reimplementation of Mario Kart Wii's physics engine in C++
Toggle main menu visibility
Loading...
Searching...
No Matches
File.cc
1
#include "File.hh"
2
3
#include <egg/core/Heap.hh>
4
5
#include <fstream>
6
7
namespace
Kinoko::Abstract::File {
8
9
u8 *Load(
const
char
*path,
size_t
&size) {
10
char
filepath[256];
11
12
if
(path[0] ==
'/'
) {
13
path++;
14
}
15
16
snprintf(filepath,
sizeof
(filepath),
"./%s"
, path);
17
std::ifstream file(filepath, std::ios::binary);
18
if
(!file) {
19
PANIC(
"File with provided path %s was not loaded correctly!"
, path);
20
}
21
22
file.seekg(0, std::ios::end);
23
size = file.tellg();
24
file.seekg(0, std::ios::beg);
25
26
u8 *buffer =
static_cast<
u8 *
>
(EGG::egg_alloc(size, 4));
27
file.read(
reinterpret_cast<
char
*
>
(buffer), size);
28
29
return
buffer;
30
}
31
32
void
Append(
const
char
*path,
const
char
*data,
size_t
size) {
33
std::ofstream stream;
34
stream.open(path, std::ios::app | std::ios::binary);
35
stream.write(data, size);
36
}
37
38
int
Remove(
const
char
*path) {
39
return
std::remove(path);
40
}
41
42
}
// namespace Kinoko::Abstract::File
abstract
File.cc
Made by
Malleo
. Logo by
vabold
. Website generated by
Doxygen
1.17.0