Subversion Repositories svn1-original

Rev

Rev 181 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 181 Rev 222
Line 14... Line 14...
14
    if (instance)
14
    if (instance)
15
    {
15
    {
16
        qFatal("Multiple instances of TeamData not allowed");
16
        qFatal("Multiple instances of TeamData not allowed");
17
    }
17
    }
18
    instance = this;
18
    instance = this;
-
 
19
    writable = false;
19
}
20
}
20
 
21
 
21
void QmTeamData::initTeamData( const QString &filen)
22
void QmTeamData::initTeamData( const QString &filen)
22
{
23
{
23
    // Default: Base filename on the config name
24
    // Default: Base filename on the config name
Line 48... Line 49...
48
        {
49
        {
49
            qFatal("Cancel to bad team data");
50
            qFatal("Cancel to bad team data");
50
        }
51
        }
51
    }
52
    }
52
 
53
 
-
 
54
    writable = false;
53
    if ( ! file.open(QIODevice::ReadWrite|QIODevice::Unbuffered) )
55
    if ( ! file.open(QIODevice::ReadWrite|QIODevice::Unbuffered) )
54
    {
56
    {
-
 
57
        qDebug ("Cannot create/open team data file for writing");
-
 
58
        if ( ! file.open(QIODevice::ReadOnly|QIODevice::Unbuffered) )
-
 
59
        {
-
 
60
 
55
        qFatal ("Cannot create/open team data file");
61
            qDebug ("Cannot create/open team data file at all");
-
 
62
        }
-
 
63
        else
-
 
64
        {
-
 
65
            MainWindow::showMessage("Data File is Read Only");
-
 
66
        }
-
 
67
    }
-
 
68
    else
-
 
69
    {
-
 
70
        writable = true;
56
    }
71
    }
57
}
72
}
58
 
73
 
59
 
74
 
60
void QmTeamData::closeTeamData(void)
75
void QmTeamData::closeTeamData(void)
Line 73... Line 88...
73
 *
88
 *
74
 *      The function will return FALSE if the record was not on disk
89
 *      The function will return FALSE if the record was not on disk
75
 *      otherwise TRUE
90
 *      otherwise TRUE
76
 *
91
 *
77
 *  Parameters:
92
 *  Parameters:
78
 *      int_team        Team record required
93
 *      team            Team record required
79
 *      data            Area to return record
94
 *      data            Area to return record
80
 *
95
 *
81
 *  Returns:
96
 *  Returns:
82
 *      FALSE : No data available
97
 *      FALSE : No data available
83
 *
98
 *
84
 *========================================================================*/
99
 *========================================================================*/
85
bool g_record( int _team, team_type * data )
100
bool g_record( int team, team_type * data )
86
{
101
{
87
    int         len;                             /* length of record read in */
102
    int         len;                             /* length of record read in */
88
    long        pos;                             /* File pointer */
103
    long        pos;                             /* File pointer */
89
 
104
 
90
    if (!instance)
105
    if (!instance)
91
    {
106
    {
92
        qFatal("Attempt to read team data before initialised");
107
        qFatal("Attempt to read team data before initialised");
93
    }
108
    }
94
 
109
 
95
    pos = _team;
110
    pos = team;
96
    pos *= sizeof( team_type );
111
    pos *= sizeof( team_type );
97
    if (instance->file.seek( pos ))
112
    if (instance->file.seek( pos ))
98
    {
113
    {
99
        len = instance->file.read( ( char * ) data, sizeof( team_type ) );
114
        len = instance->file.read( ( char * ) data, sizeof( team_type ) );
100
        if( ( len == sizeof( team_type ) ) && ( _team == data->numb ) )
115
        if( ( len == sizeof( team_type ) ) && ( team == data->numb ) )
101
        {
116
        {
102
            return ( data->flags.valid );
117
            return ( data->flags.valid );
103
        }
118
        }
104
    }
119
    }
105
    else
120
    else
106
    {
121
    {
107
        qDebug("Bad Seek for team:%d", _team);
122
        qDebug("Bad Seek for team:%d", team);
108
    }
123
    }
109
    clr_team( _team, data );
124
    clr_team( team, data );
110
    return ( FALSE );
125
    return ( FALSE );
111
}
126
}
112
 
127
 
113
/*========================================================================
128
/*========================================================================
114
 *
129
 *
Line 153... Line 168...
153
 *
168
 *
154
 *  Purpose:
169
 *  Purpose:
155
 *      This function is called to save team record to disk
170
 *      This function is called to save team record to disk
156
 *
171
 *
157
 *  Parameters:
172
 *  Parameters:
158
 *      _team       Team number
173
 *      team       Team number
159
 *      data        Pointer to the data
174
 *      data        Pointer to the data
160
 *
175
 *
161
 *  Returns:
176
 *  Returns:
162
 *      FALSE : Error in save
177
 *      FALSE : Error in save
163
 *
178
 *
164
 *========================================================================*/
179
 *========================================================================*/
165
bool put_team_record( int _team, team_type * data )
180
bool put_team_record( int team, team_type * data )
166
{
181
{
167
    int         len;                             /* length of record read in */
182
    int         len;                             /* length of record read in */
168
    long        pos;                             /* file pointer */
183
    long        pos;                             /* file pointer */
169
 
184
 
170
    if (!instance)
185
    if (!instance)
171
    {
186
    {
172
        qFatal("Attempt to read team data before initialised");
187
        qFatal("Attempt to read team data before initialised");
173
    }
188
    }
174
 
189
 
-
 
190
    if ( !instance->writable)
-
 
191
    {
-
 
192
        qDebug("Attempt to write ReadOnly data:%d", team);
-
 
193
        MainWindow::showMessage("Cannot save data. Team Data is read only");
-
 
194
        return false;
-
 
195
    }
-
 
196
 
175
    pos = _team;
197
    pos = team;
176
    pos *= sizeof( team_type );
198
    pos *= sizeof( team_type );
177
    if (instance->file.seek( pos ))
199
    if (instance->file.seek( pos ))
178
    {
200
    {
179
        len = instance->file.write( ( char * ) data, sizeof( team_type ) );
201
        len = instance->file.write( ( char * ) data, sizeof( team_type ) );
180
        if( len != sizeof( team_type ) )
202
        if( len != sizeof( team_type ) )
181
        {
203
        {
182
            qDebug("Error writing team data:%d", _team);
204
            qDebug("Error writing team data:%d", team);
183
            MainWindow::showMessage("Error Team record write");
205
            MainWindow::showMessage("Error Team record write");
184
            return false;
206
            return false;
185
        }
207
        }
186
        return true;
208
        return true;
187
    }
209
    }
188
 
210
 
189
    qDebug("Bad Seek for writing team:%d", _team);
211
    qDebug("Bad Seek for writing team:%d", team);
190
    return false;
212
    return false;
191
}
213
}
192
 
214
 
193
 
215
 
194
 
216