71
std::string CPCIDSKSegment::GetMetadataValue( std::string key )
74
/************************************************************************/
75
/* GetMetadataValue() */
76
/************************************************************************/
77
std::string CPCIDSKSegment::GetMetadataValue( const std::string &key ) const
73
79
return metadata->GetMetadataValue(key);
76
void CPCIDSKSegment::SetMetadataValue( std::string key, std::string value )
82
/************************************************************************/
83
/* SetMetadataValue() */
84
/************************************************************************/
85
void CPCIDSKSegment::SetMetadataValue( const std::string &key, const std::string &value )
78
87
metadata->SetMetadataValue(key,value);
81
std::vector<std::string> CPCIDSKSegment::GetMetadataKeys()
90
/************************************************************************/
91
/* GetMetdataKeys() */
92
/************************************************************************/
93
std::vector<std::string> CPCIDSKSegment::GetMetadataKeys() const
83
95
return metadata->GetMetadataKeys();
103
115
/************************************************************************/
104
116
/* LoadSegmentHeader() */
105
117
/************************************************************************/
107
119
void CPCIDSKSegment::LoadSegmentHeader()
110
122
header.SetSize(1024);
112
124
file->ReadFromFile( header.buffer, data_offset, 1024 );
114
// parse out history, etc
126
// Read the history from the segment header. PCIDSK supports
127
// 8 history entries per segment.
128
std::string hist_msg;
130
for (unsigned int i = 0; i < 8; i++)
132
header.Get(384 + i * 80, 80, hist_msg);
134
// Some programs seem to push history records with a trailing '\0'
135
// so do some extra processing to cleanup. FUN records on segment
136
// 3 of eltoro.pix are an example of this.
137
size_t size = hist_msg.size();
139
&& (hist_msg[size-1] == ' ' || hist_msg[size-1] == '\0') )
142
hist_msg.resize(size);
144
history_.push_back(hist_msg);
148
/************************************************************************/
151
/* This is used primarily after this class or subclasses have */
152
/* modified the header buffer and need it pushed back to disk. */
153
/************************************************************************/
155
void CPCIDSKSegment::FlushHeader()
158
file->WriteToFile( header.buffer, data_offset, 1024 );
117
161
/************************************************************************/
167
211
std::string CPCIDSKSegment::GetDescription()
215
header.Get( 0, 64, target );
220
/************************************************************************/
221
/* SetDescription() */
222
/************************************************************************/
224
void CPCIDSKSegment::SetDescription( const std::string &description )
226
header.Put( description.c_str(), 0, 64);
228
file->WriteToFile( header.buffer, data_offset, 1024 );
172
231
/************************************************************************/
243
/************************************************************************/
244
/* GetHistoryEntries() */
245
/************************************************************************/
247
std::vector<std::string> CPCIDSKSegment::GetHistoryEntries() const
252
/************************************************************************/
253
/* SetHistoryEntries() */
254
/************************************************************************/
256
void CPCIDSKSegment::SetHistoryEntries(const std::vector<std::string> &entries)
259
for( unsigned int i = 0; i < 8; i++ )
261
const char *msg = "";
262
if( entries.size() > i )
263
msg = entries[i].c_str();
265
header.Put( msg, 384 + i * 80, 80 );
270
// Force reloading of history_
274
/************************************************************************/
276
/************************************************************************/
278
void CPCIDSKSegment::PushHistory( const std::string &app,
279
const std::string &message )
282
#define MY_MIN(a,b) ((a<b) ? a : b)
284
char current_time[17];
287
GetCurrentDateTime( current_time );
289
memset( history, ' ', 80 );
292
memcpy( history + 0, app.c_str(), MY_MIN(app.size(),7) );
295
memcpy( history + 8, message.c_str(), MY_MIN(message.size(),56) );
296
memcpy( history + 64, current_time, 16 );
298
std::vector<std::string> history_entries = GetHistoryEntries();
300
history_entries.insert( history_entries.begin(), history );
301
history_entries.resize(8);
303
SetHistoryEntries( history_entries );
307
/************************************************************************/
310
/* Move a chunk of data within a segment. Overlapping source */
311
/* and destination are permitted. */
312
/************************************************************************/
314
void CPCIDSKSegment::MoveData( uint64 src_offset, uint64 dst_offset,
315
uint64 size_in_bytes )
318
bool copy_backwards = false;
320
// We move things backwards if the areas overlap and the destination
321
// is further on in the segment.
322
if( dst_offset > src_offset
323
&& src_offset + size_in_bytes > dst_offset )
324
copy_backwards = true;
327
// Move the segment data to the new location.
328
uint8 copy_buf[16384];
331
bytes_to_go = size_in_bytes;
333
while( bytes_to_go > 0 )
335
uint64 bytes_this_chunk = sizeof(copy_buf);
336
if( bytes_to_go < bytes_this_chunk )
337
bytes_this_chunk = bytes_to_go;
341
ReadFromFile( copy_buf,
342
src_offset + bytes_to_go - bytes_this_chunk,
344
WriteToFile( copy_buf,
345
dst_offset + bytes_to_go - bytes_this_chunk,
350
ReadFromFile( copy_buf, src_offset, bytes_this_chunk );
351
WriteToFile( copy_buf, dst_offset, bytes_this_chunk );
353
src_offset += bytes_this_chunk;
354
dst_offset += bytes_this_chunk;
357
bytes_to_go -= bytes_this_chunk;