/* saveToFile method * * @param filename -- saved file name * @param type -- upgrade type * @param upgrade -- upgrade batch file name * @return 0 - OK: otherwise Error */ int LdMagic::saveToFile(char*filename, int type, char* upgrade) { FILE *out = NULL; int rtn = -1; if (upgrade != NULL) setUpgrade(upgrade); else if (m_upgrade == NULL) setUpgrade(UPGRADE); m_size = getFileSize(m_upgrade); if (m_size > 0 && type >= U_DATA && type <= U_SYS) { m_type = type; m_cksum = getCheckSum(m_upgrade); out = fopen(filename, "w"); if (out) { fwrite((char*)&m_magic, sizeof(int), 1, out); fwrite((char*)&m_size, sizeof(int), 1, out); fwrite((char*)&m_type, sizeof(int), 1, out); fwrite((char*)&m_cksum, sizeof(int), 1, out); fprintf(out, "%s", m_upgrade); fclose(out); rtn = 0; } } return rtn; }
void PackageWidget::actOnPackages(QApt::Package::State action) { const QApt::PackageList packages = selectedPackages(); if (packages.isEmpty()) return; QApplication::setOverrideCursor(Qt::WaitCursor); saveState(); m_backend->setCompressEvents(true); m_stop = false; for (QApt::Package *package : packages) { if (m_stop) { m_backend->setCompressEvents(false); QApplication::restoreOverrideCursor(); break; } switch (action) { case QApt::Package::ToInstall: setInstall(package); break; case QApt::Package::ToRemove: setRemove(package); break; case QApt::Package::ToUpgrade: setUpgrade(package); break; case QApt::Package::ToReInstall: if (package->isInstalled()) setReInstall(package); break; case QApt::Package::ToKeep: setKeep(package); break; case QApt::Package::ToPurge: setPurge(package); break; default: break; } } emit packageChanged(); m_backend->setCompressEvents(false); QApplication::restoreOverrideCursor(); checkChanges(); }
/* loadFromFile method * * @param filename * @return 0 - OK: otherwise Error */ int LdMagic::loadFromFile(char* filename) { int rtn = -1; char line[1024]; FILE *in = NULL; // printf("Load File %s\n", filename); in = fopen(filename, "r"); if (in) { fread((char*)&m_magic, sizeof(int), 1, in); if (m_magic == MAGICNUM) { fread((char*)&m_size, sizeof(int), 1, in); fread((char*)&m_type, sizeof(int), 1, in); fread((char*)&m_cksum, sizeof(int), 1, in); if(fgets(line, 1023, in)) { setUpgrade(line); rtn = 0; } else rtn = -3; } else rtn = -2; fclose(in); } return rtn; }