mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-09 03:20:42 +02:00
wip
This commit is contained in:
parent
083aeb200d
commit
47ab9ff1ec
@ -234,7 +234,7 @@ int verifyChecksumFromFile(char *mess, char *clientChecksum, char *fname) {
|
|||||||
fclose(fp);
|
fclose(fp);
|
||||||
return verifyChecksum(mess, clientChecksum, &c, "copied program");
|
return verifyChecksum(mess, clientChecksum, &c, "copied program");
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname,
|
int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname,
|
||||||
ssize_t fsize) {
|
ssize_t fsize) {
|
||||||
LOG(logINFO, ("\tVerifying FlashChecksum...\n"));
|
LOG(logINFO, ("\tVerifying FlashChecksum...\n"));
|
||||||
@ -331,17 +331,71 @@ int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname,
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// last null character (if size does not match)
|
LOG(logINFO, ("\tRead %lu bytes to calculate checksum\n", totalBytesRead));
|
||||||
/*if (fsize == totalBytesRead + 1) {
|
fclose(fp);
|
||||||
bytes = 1;
|
fclose(flashfp);
|
||||||
totalBytesRead += bytes;
|
return verifyChecksum(mess, clientChecksum, &c, "flash");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname,
|
||||||
|
ssize_t fsize) {
|
||||||
|
LOG(logINFO, ("\tVerifying FlashChecksum...\n"));
|
||||||
|
|
||||||
|
FILE *fp = fopen(fname, "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
sprintf(mess, "Unable to open %s in read mode to get checksum\n",
|
||||||
|
fname);
|
||||||
|
LOG(logERROR, (mess));
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *flashfp = fopen(FLASH_CONVERTED_NAME, "w");
|
||||||
|
if (flashfp == NULL) {
|
||||||
|
sprintf(mess, "Unable to open %s in write mode to write checksum\n",
|
||||||
|
FLASH_CONVERTED_NAME);
|
||||||
|
LOG(logERROR, (mess));
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
MD5_CTX c;
|
||||||
|
if (!MD5_Init(&c)) {
|
||||||
|
fclose(fp);
|
||||||
|
strcpy(mess, "Unable to calculate checksum (MD5_Init)\n");
|
||||||
|
LOG(logERROR, (mess));
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
const int readUnitSize = 128;
|
||||||
|
char buf[readUnitSize];
|
||||||
|
ssize_t bytes = fread(buf, 1, readUnitSize, fp);
|
||||||
|
ssize_t totalBytesRead = bytes;
|
||||||
|
int oldProgress = 0;
|
||||||
|
|
||||||
|
while (bytes > 0) {
|
||||||
|
int progress = (int)(((double)(totalBytesRead) / fsize) * 100);
|
||||||
|
if (oldProgress != progress) {
|
||||||
|
printf("%d%%\r", progress);
|
||||||
|
fflush(stdout);
|
||||||
|
oldProgress = progress;
|
||||||
|
}
|
||||||
|
|
||||||
if (!MD5_Update(&c, buf, bytes)) {
|
if (!MD5_Update(&c, buf, bytes)) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
strcpy(mess, "Unable to calculate checksum (MD5_Update)\n");
|
strcpy(mess, "Unable to calculate checksum (MD5_Update)\n");
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
}*/
|
if (fwrite((void *)buf, sizeof(char), bytes, flashfp) != bytes) {
|
||||||
|
LOG(logERROR, ("Could not write to flash fp file\n"));
|
||||||
|
}
|
||||||
|
// read only until a particular size (drive)
|
||||||
|
if (fsize != 0 && totalBytesRead >= fsize) {
|
||||||
|
LOG(logINFOBLUE, ("\tReached %lu bytes. Not reading more\n", totalBytesRead));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
bytes = fread(buf, 1, readUnitSize, fp);
|
||||||
|
totalBytesRead += bytes;
|
||||||
|
}
|
||||||
|
|
||||||
LOG(logINFO, ("\tRead %lu bytes to calculate checksum\n", totalBytesRead));
|
LOG(logINFO, ("\tRead %lu bytes to calculate checksum\n", totalBytesRead));
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
fclose(flashfp);
|
fclose(flashfp);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user