/*
* simple program to check implanted md5sum in an iso 9660 image
*
* Copyright (C) 2001, 2005 Red Hat, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Author(s): Michael Fulbright
* Dustin Kirkland
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "lang.h"
#include "log.h"
struct progressCBdata {
newtComponent scale;
newtComponent label;
};
static void readCB(void *co, long long pos, long long total) {
struct progressCBdata *data = co;
char tickmark[2] = "-";
char * ticks = "-\\|/";
newtScaleSet(data->scale, pos * 100.0 / total);
*tickmark = ticks[(total / (pos + 1)) % 5];
newtLabelSetText(data->label, tickmark);
newtRefresh();
}
int doMediaCheck(char *file, char *descr) {
struct progressCBdata data;
newtComponent t, f, scale, label;
int rc;
int dlen;
int llen;
char tmpstr[1024];
if (access(file, R_OK) < 0) {
newtWinMessage(_("Error"), _("OK"), _("Unable to find install image "
"%s"), file);
return -1;
}
if (descr)
snprintf(tmpstr, sizeof(tmpstr), _("Checking \"%s\"..."), descr);
else
snprintf(tmpstr, sizeof(tmpstr), _("Checking media now..."));
dlen = strlen(tmpstr);
if (dlen > 65)
dlen = 65;
newtCenteredWindow(dlen+8, 6, _("Media Check"));
t = newtTextbox(1, 1, dlen+4, 3, NEWT_TEXTBOX_WRAP);
newtTextboxSetText(t, tmpstr);
llen = strlen(tmpstr);
label = newtLabel(llen+1, 1, "-");
f = newtForm(NULL, NULL, 0);
newtFormAddComponent(f, t);
scale = newtScale(3, 3, dlen, 100);
newtFormAddComponent(f, scale);
newtDrawForm(f);
newtRefresh();
data.scale = scale;
data.label = label;
rc = mediaCheckFile(file, readCB, &data);
newtFormDestroy(f);
newtPopWindow();
if (rc == -1) {
logMessage(WARNING, "mediacheck: %s (%s) has no checksum info", file, descr);
newtWinMessage(_("Error"), _("OK"),
_("Unable to read the disc checksum from the "
"primary volume descriptor. This probably "
"means the disc was created without adding the "
"checksum."));
} else if (rc == 0) {
logMessage(ERROR, "mediacheck: %s (%s) FAILED", file, descr);
newtWinMessage(_("Error"), _("OK"),
_("The image which was just tested has errors. "
"This could be due to a "
"corrupt download or a bad disc. "
"If applicable, please clean the disc "
"and try again. If this test continues to fail you "
"should not continue the install."));
} else if (rc > 0) {
logMessage(INFO, "mediacheck: %s (%s) PASSED", file, descr);
newtWinMessage(_("Success"), _("OK"),
_("The image which was just tested was successfully "
"verified. It should be OK to install from this "
"media. Note that not all media/drive errors can "
"be detected by the media check."));
}
return rc;
}