MCPcopy Create free account
hub / github.com/Parchive/par2cmdline / ComputeBlockCount

Method ComputeBlockCount

src/par2creator.cpp:265–309  ·  view source on GitHub ↗

Compute block size from block count or vice versa depending on which was specified on the command line

Source from the content-addressed store, hash-verified

263// Compute block size from block count or vice versa depending on which was
264// specified on the command line
265bool Par2Creator::ComputeBlockCount(const std::vector<std::string> &extrafiles)
266{
267 FileSizeCache filesize_cache;
268
269 largestfilesize = 0;
270 for (std::vector<std::string>::const_iterator i=extrafiles.begin(); i!=extrafiles.end(); i++)
271 {
272 u64 filesize = filesize_cache.get(*i);
273 if (largestfilesize < filesize)
274 {
275 largestfilesize = filesize;
276 }
277 }
278
279
280 if (blocksize == 0)
281 {
282 serr << "ERROR: Block size was zero!" << std::endl;
283 return false;
284 }
285
286 if (blocksize % 4 != 0)
287 {
288 serr << "ERROR: Block size was not a multiple of 4 bytes!" << std::endl;
289 return false;
290 }
291
292
293 u64 count = 0;
294
295 for (std::vector<std::string>::const_iterator i=extrafiles.begin(); i!=extrafiles.end(); i++)
296 {
297 count += (filesize_cache.get(*i) + blocksize-1) / blocksize;
298 }
299
300 if (count > 32768)
301 {
302 serr << "Block size is too small. It would require " << count << "blocks." << std::endl;
303 return false;
304 }
305
306 sourceblockcount = (u32)count;
307
308 return true;
309}
310
311
312

Callers

nothing calls this directly

Calls 1

getMethod · 0.80

Tested by

no test coverage detected