summaryrefslogtreecommitdiff
path: root/src/nw4r/ut/ut_FileStream.cpp
blob: d230b627ca250f41d3209739a23512d3248558f2 (plain)
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
54
55
// Ported from https://github.com/kiwi515/ogws/blob/master/src/nw4r/ut/ut_FileStream.cpp

#include "nw4r/ut.h"

namespace nw4r {
namespace ut {

NW4R_UT_RTTI_DEF_DERIVED(FileStream, IOStream);

void FileStream::Cancel() {}

bool FileStream::CancelAsync(AsyncCallback callback, void *arg) {
#pragma unused(callback)
#pragma unused(arg)
    return true;
}

u32 FileStream::FilePosition::Skip(s32 offset) {
    if (offset != 0) {
        s64 newOffset = mFileOffset + offset;
        mFileOffset = Clamp<s64>(newOffset, 0, mFileSize);
    }

    return mFileOffset;
}

u32 FileStream::FilePosition::Append(s32 offset) {
    s64 newOffset = mFileOffset + offset;

    if (newOffset < 0) {
        mFileOffset = 0;
    } else {
        mFileOffset = newOffset;
        mFileSize = Max(mFileOffset, mFileSize);
    }

    return mFileOffset;
}

void FileStream::FilePosition::Seek(s32 offset, u32 origin) {
    switch (origin) {
        case SEEKORG_BEG: mFileOffset = 0; break;
        case SEEKORG_END: mFileOffset = mFileSize; break;
        case SEEKORG_CUR:
        default:          break;
    }

    Skip(offset);
}

// TODO: This should not be necessary. Because of nw4r::snd? still the case for ss
DECOMP_FORCEACTIVE(ut_FileStream_cpp, FileStream::GetRuntimeTypeInfo);

} // namespace ut
} // namespace nw4r