~ubuntu-branches/ubuntu/wily/hedgewars/wily

« back to all changes in this revision

Viewing changes to misc/quazip/qioapi.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry E. Oboukhov
  • Date: 2011-09-23 10:16:55 UTC
  • mfrom: (1.2.11 upstream)
  • Revision ID: package-import@ubuntu.com-20110923101655-3977th2gc5n0a3pv
Tags: 0.9.16-1
* New upstream version.
 + Downloadable content! Simply click to install any content.
   New voices, hats, maps, themes, translations, music, scripts...
   Hedgewars is now more customisable than ever before! As time goes
   by we will be soliciting community content to feature on this page,
   so remember to check it from time to time. If you decide you want
   to go back to standard Hedgewars, just remove the Data directory
   from your Hedgewars config directory.
 + 3-D rendering! Diorama-like rendering of the game in a variety
   of 3D modes. Let us know which ones work best for you, we didn't
   really have the equipment to test them all.
 + Resizable game window.
 + New utilities! The Time Box will remove one of your hedgehogs
   from the game for a while, protecting from attack until it returns,
   somewhere else on the map. Land spray will allow you to build bridges,
   seal up holes, or just make life unpleasant for your enemies.
 + New single player: Bamboo Thicket, That Sinking Feeling, Newton and
   the Tree and multi-player: The Specialists, Space Invaders,
   Racer - scripts! And a ton more script hooks for scripters
 + New twists on old weapons. Drill strike, seduction and fire have
   been adjusted. Defective mines have been added, rope can attach to
   hogs/crates/barrels again, grenades now have variable bounce (use
   precise key + 1-5). Portal gun is now more usable in flight and
   all game actions are a lot faster.
 + New theme - Golf, dozens of new community hats and a new
   localised Default voice, Ukranian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ioapi.c -- IO base function header for compress/uncompress .zip
 
2
   files using zlib + zip or unzip API
 
3
 
 
4
   Version 1.01e, February 12th, 2005
 
5
 
 
6
   Copyright (C) 1998-2005 Gilles Vollant
 
7
 
 
8
   Modified by Sergey A. Tachenov to integrate with Qt.
 
9
*/
 
10
 
 
11
#include <stdio.h>
 
12
#include <stdlib.h>
 
13
#include <string.h>
 
14
 
 
15
#include "zlib.h"
 
16
#include "ioapi.h"
 
17
#include "quazip_global.h"
 
18
#include <QIODevice>
 
19
 
 
20
 
 
21
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
 
22
 
 
23
#ifndef SEEK_CUR
 
24
#define SEEK_CUR    1
 
25
#endif
 
26
 
 
27
#ifndef SEEK_END
 
28
#define SEEK_END    2
 
29
#endif
 
30
 
 
31
#ifndef SEEK_SET
 
32
#define SEEK_SET    0
 
33
#endif
 
34
 
 
35
voidpf ZCALLBACK qiodevice_open_file_func (
 
36
   voidpf opaque UNUSED,
 
37
   voidpf file,
 
38
   int mode)
 
39
{
 
40
    QIODevice *iodevice = reinterpret_cast<QIODevice*>(file);
 
41
    if(iodevice->isSequential())
 
42
        return NULL;
 
43
    if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
 
44
        iodevice->open(QIODevice::ReadOnly);
 
45
    else
 
46
    if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
 
47
        iodevice->open(QIODevice::ReadWrite);
 
48
    else
 
49
    if (mode & ZLIB_FILEFUNC_MODE_CREATE)
 
50
        iodevice->open(QIODevice::WriteOnly);
 
51
 
 
52
    if(iodevice->isOpen())
 
53
        return iodevice;
 
54
    else
 
55
        return NULL;
 
56
}
 
57
 
 
58
 
 
59
uLong ZCALLBACK qiodevice_read_file_func (
 
60
   voidpf opaque UNUSED,
 
61
   voidpf stream,
 
62
   void* buf,
 
63
   uLong size)
 
64
{
 
65
    uLong ret;
 
66
    ret = (uLong)((QIODevice*)stream)->read((char*)buf,size);
 
67
    return ret;
 
68
}
 
69
 
 
70
 
 
71
uLong ZCALLBACK qiodevice_write_file_func (
 
72
   voidpf opaque UNUSED,
 
73
   voidpf stream,
 
74
   const void* buf,
 
75
   uLong size)
 
76
{
 
77
    uLong ret;
 
78
    ret = (uLong)((QIODevice*)stream)->write((char*)buf,size);
 
79
    return ret;
 
80
}
 
81
 
 
82
uLong ZCALLBACK qiodevice_tell_file_func (
 
83
   voidpf opaque UNUSED,
 
84
   voidpf stream)
 
85
{
 
86
    uLong ret;
 
87
    ret = ((QIODevice*)stream)->pos();
 
88
    return ret;
 
89
}
 
90
 
 
91
int ZCALLBACK qiodevice_seek_file_func (
 
92
   voidpf opaque UNUSED,
 
93
   voidpf stream,
 
94
   uLong offset,
 
95
   int origin)
 
96
{
 
97
    uLong qiodevice_seek_result=0;
 
98
    int ret;
 
99
    switch (origin)
 
100
    {
 
101
    case ZLIB_FILEFUNC_SEEK_CUR :
 
102
        qiodevice_seek_result = ((QIODevice*)stream)->pos() + offset;
 
103
        break;
 
104
    case ZLIB_FILEFUNC_SEEK_END :
 
105
        qiodevice_seek_result = ((QIODevice*)stream)->size() - offset;
 
106
        break;
 
107
    case ZLIB_FILEFUNC_SEEK_SET :
 
108
        qiodevice_seek_result = offset;
 
109
        break;
 
110
    default: return -1;
 
111
    }
 
112
    ret = !((QIODevice*)stream)->seek(qiodevice_seek_result);
 
113
    return ret;
 
114
}
 
115
 
 
116
int ZCALLBACK qiodevice_close_file_func (
 
117
   voidpf opaque UNUSED,
 
118
   voidpf stream)
 
119
{
 
120
    ((QIODevice*)stream)->close();
 
121
    return 0;
 
122
}
 
123
 
 
124
int ZCALLBACK qiodevice_error_file_func (
 
125
   voidpf opaque UNUSED,
 
126
   voidpf stream)
 
127
{
 
128
    return !((QIODevice*)stream)->errorString().isEmpty();
 
129
}
 
130
 
 
131
void fill_qiodevice_filefunc (
 
132
  zlib_filefunc_def* pzlib_filefunc_def)
 
133
{
 
134
    pzlib_filefunc_def->zopen_file = qiodevice_open_file_func;
 
135
    pzlib_filefunc_def->zread_file = qiodevice_read_file_func;
 
136
    pzlib_filefunc_def->zwrite_file = qiodevice_write_file_func;
 
137
    pzlib_filefunc_def->ztell_file = qiodevice_tell_file_func;
 
138
    pzlib_filefunc_def->zseek_file = qiodevice_seek_file_func;
 
139
    pzlib_filefunc_def->zclose_file = qiodevice_close_file_func;
 
140
    pzlib_filefunc_def->zerror_file = qiodevice_error_file_func;
 
141
    pzlib_filefunc_def->opaque = NULL;
 
142
}