File: BaseReader.h

package info (click to toggle)
onscripter 20230825-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 1,412 kB
  • sloc: cpp: 32,593; xml: 114; sh: 105; makefile: 93; python: 10
file content (128 lines) | stat: -rw-r--r-- 3,629 bytes parent folder | download
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* -*- C++ -*-
 *
 *  BaseReader.h - Base class of archive reader
 *
 *  Copyright (c) 2001-2022 Ogapee. All rights reserved.
 *
 *  ogapee@aqua.dti2.ne.jp
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __BASE_READER_H__
#define __BASE_READER_H__

#include <stdio.h>
#ifdef ANDROID
extern "C" int fseek_ons(FILE* stream, long offset, int whence);
#define fseek fseek_ons
extern "C" long ftell_ons(FILE* stream);
#define ftell ftell_ons
extern "C" int fgetc_ons(FILE* stream);
#define fgetc fgetc_ons
extern "C" char* fgets_ons(char* s, int size, FILE* stream);
#define fgets fgets_ons
extern "C" size_t fread_ons(void* ptr, size_t size, size_t nmemb, FILE* stream);
#define fread fread_ons
extern "C" FILE* fopen_ons(const char* str, const char* mode);
#define fopen fopen_ons
extern "C" int mkdir_ons(const char* pathname, mode_t mode);
#define mkdir mkdir_ons
#endif

#ifndef SEEK_END
#define SEEK_END 2
#endif

#if defined(LINUX) || defined(MACOSX)
#define DELIMITER '/'
#elif defined(WIN32)
#define DELIMITER '\\'
#elif defined(MACOS9)
#define DELIMITER ':'
#define RELATIVEPATH ":"
#define RELATIVEPATHLENGTH 1
#else
#define DELIMITER '/'
#endif
#ifndef RELATIVEPATH
#define RELATIVEPATH ""
#define RELATIVEPATHLENGTH 0
#endif

struct BaseReader {
    enum {
        NO_COMPRESSION = 0,
        SPB_COMPRESSION = 1,
        LZSS_COMPRESSION = 2,
        NBZ_COMPRESSION = 4
    };

    enum {
        ARCHIVE_TYPE_NONE = 0,
        ARCHIVE_TYPE_SAR = 1,
        ARCHIVE_TYPE_NSA = 2,
        ARCHIVE_TYPE_NS2 = 4 // new format since NScr2.91, uses ext ".ns2"
    };

    struct FileInfo {
        char name[256];
        int compression_type;
        size_t offset;
        size_t length;
        size_t original_length;
    };

    struct ArchiveInfo {
        ArchiveInfo* next;
        FILE* file_handle;
        int power_resume_number; // currently only for PSP
        char* file_name;
        FileInfo* fi_list;
        unsigned int num_of_files;
        unsigned long base_offset;

        ArchiveInfo()
        {
            next = NULL;
            file_handle = NULL;
            power_resume_number = 0;
            file_name = NULL;
            fi_list = NULL;
            num_of_files = 0;
        }
        ~ArchiveInfo()
        {
            if (file_handle) fclose(file_handle);
            if (file_name) delete[] file_name;
            if (fi_list) delete[] fi_list;
        }
    };

    virtual ~BaseReader(){};

    virtual int open(const char* name = NULL) = 0;
    virtual int close() = 0;

    virtual const char* getArchiveName() const = 0;
    virtual int getNumFiles() = 0;
    virtual void registerCompressionType(const char* ext, int type) = 0;

    virtual FileInfo getFileByIndex(unsigned int index) = 0;
    virtual size_t getFileLength(const char* file_name) = 0;
    virtual size_t getFile(const char* file_name, unsigned char* buffer, int* location = NULL) = 0;
};

#endif // __BASE_READER_H__