Ejemplo n.º 1
0
bool DownloadUpdate()
{
	bool result = false;

	if(updateURL[0] == 0 || appPath[0] == 0 || !ChangeInterface(appPath, NOTSILENT))
	{
		ErrorPrompt("Update failed!");
		updateFound = false; // updating is finished (successful or not!)
		return false;
	}

	// stop checking if devices were removed/inserted
	// since we're saving a file
	HaltDeviceThread();

	int device;
	FindDevice(appPath, &device);

	char updateFile[50];
	sprintf(updateFile, "%s%s Update.zip", pathPrefix[device], APPNAME);

	FILE * hfile = fopen (updateFile, "wb");

	if (hfile)
	{
		if(http_request(updateURL, hfile, NULL, (1024*1024*10), NOTSILENT) > 0)
		{
			fclose (hfile);
			result = unzipArchive(updateFile, (char *)pathPrefix[device]);
		}
		else
		{
			fclose (hfile);
		}
		remove(updateFile); // delete update file
	}

	// go back to checking if devices were inserted/removed
	ResumeDeviceThread();

	if(result)
		InfoPrompt("Update successful!");
	else
		ErrorPrompt("Update failed!");

	updateFound = false; // updating is finished (successful or not!)
	return result;
}
Ejemplo n.º 2
0
bool DownloadUpdate()
{
	bool result = false;
	if(strlen(updateURL) > 0)
	{
		// stop checking if devices were removed/inserted
		// since we're saving a file
		LWP_SuspendThread (devicethread);

		FILE * hfile;
		char updateFile[50];
		sprintf(updateFile, "sd:/%s Update.zip", APPNAME);
		hfile = fopen (updateFile, "wb");

		if (hfile > 0)
		{
			int retval;
			retval = http_request(updateURL, hfile, NULL, (1024*1024*5));
			fclose (hfile);
		}

		bool unzipResult = unzipArchive(updateFile, (char *)"sd:/");
		remove(updateFile); // delete update file

		if(unzipResult)
		{
			result = true;
			WaitPrompt("Update successful!");
		}
		else
		{
			result = false;
			WaitPrompt("Update failed!");
		}

		updateFound = false; // updating is finished (successful or not!)

		// go back to checking if devices were inserted/removed
		LWP_ResumeThread (devicethread);
	}
	return result;
}
Ejemplo n.º 3
0
bool
aBackup::importData(const QString& rcfile, const QString &archfile, bool dropBase, bool replaceTemplates)
{


	int prg=0;
	int totalSteps=10;
	QString tmpDirName;
	QString filename = archfile;

	QDir dir;
        QString temp;
	QStringList templatesName;

#ifndef _Windows
	temp = getenv("TMPDIR");
	if(temp=="" || temp.isEmpty())
		temp = P_tmpdir;
#else
	temp = getenv("TEMP");
#endif
	tmpDirName = QString(temp+"/%1").arg(QDateTime::currentDateTime().toTime_t());
	tmpDirName = QDir::convertSeparators(tmpDirName);
	//printf("tmp dir name = %s\n",tmpDirName.ascii());
	if(!dir.mkdir(tmpDirName))
	{
		setLastError(tr("Can't create temporary directory"));
		aLog::print(aLog::Error, "aBackup create temporary directory %1");
		return true;
	}
	else
	{
		aLog::print(aLog::Debug, tr("aBackup create temporary directory %1").arg(tmpDirName));
	}
	if(unzipArchive(archfile, tmpDirName)==true)
	{
		cleanupTmpFiles(tmpDirName, &templatesName);

		//printf("unzip error!\n");
		aLog::print(aLog::Error, tr("aBackup import data: unzip"));
		return true;
	}
	else
	{
		aLog::print(aLog::Debug, tr("aBackup unzip"));
	}


	QString srcDirName = QDir::convertSeparators(tmpDirName + "/templates/");
	dir.setPath(srcDirName);
	templatesName = dir.entryList("templ_*.odt;templ_*.ods");


	qApp->processEvents();
	emit(progress(++prg,totalSteps));

	filename.truncate( filename.length() - QString(".bsa").length() );
	aLog::print(aLog::Debug, tr("aBackup filename = %1").arg(filename));

	//printf("filename = %s\n",filename.ascii());
	changeRC(rcfile, tmpDirName + "/busines-schema.cfg");

	QFile f(tmpDirName+"/content.xml");
	QDomDocument xml;
	xml.setContent(&f);
//	printf("%s\n",xml.toString(4).ascii());
	aDatabase db;
	if(db.init(rcfile))
	{
		emit(progress(++prg,totalSteps));
		if(!dropBase)
		{
			db.done();
			cleanupTmpFiles(tmpDirName, &templatesName);
			return false;
		}
		db.drop(db.cfg->rc->value("dbname"));
		emit(progress(++prg,totalSteps));
		db.create();

		emit(progress(++prg,totalSteps));

		db.exchangeDataSystables ( xml, true);
		emit(progress(++prg,totalSteps));
		db.exchangeDataCatalogues( xml, true );
		emit(progress(++prg,totalSteps));
		db.exchangeDataDocuments ( xml, true );
		emit(progress(++prg,totalSteps));
		db.exchangeDataJournals ( xml, true );
		db.exchangeDataInfoRegisters ( xml, true );
		emit(progress(++prg,totalSteps));
		db.exchangeDataAccumulationRegisters ( xml, true );
		emit(progress(++prg,totalSteps));
		db.exchangeDataUniques ( xml, true );
	}
	else
	{
		setLastError(tr("Can't connect to database"));
		cleanupTmpFiles(tmpDirName, &templatesName);
		return true;
	}
	qApp->processEvents();

	QString destDirName = QDir::convertSeparators(db.cfg->rc->value("workdir"));

	//create template directory
	QDir destDir;
//	destDir.setPath(destDirName);
	if(!destDir.exists(destDirName))
	{
		aLog::print(aLog::Debug, tr("aBackup template dir `%1' not exists, try create").arg(destDirName));
		if(!destDir.mkdir(destDirName,true))
		{
			aLog::print(aLog::Error, tr("aBackup create template dir `%1' fail").arg(destDirName));
		}
		else
		{
			aLog::print(aLog::Debug, tr("aBackup create template dir `%1'").arg(destDirName));
		}
	}
	else
	{
		aLog::print(aLog::Debug, tr("aBackup template dir `%1' exists").arg(destDirName));
	}

	for(uint i=0; i<templatesName.count(); i++)
	{
	//	aTests::print2log("f:\\ERROR.log", "aBackup", tmpDirName + "/templates/"+templatesName[i]);
		aService::copyFile(QDir::convertSeparators(srcDirName+templatesName[i]), QDir::convertSeparators(destDirName +"/"+templatesName[i]), replaceTemplates);
	}

	db.done();

//	printf("copy %s to %s\n", QDir::convertSeparators(tmpDirName+"/busines-schema.cfg").ascii(), QDir::convertSeparators(filename+".cfg").ascii());
	if(!aService::copyFile( QDir::convertSeparators(tmpDirName+"/busines-schema.cfg"), QDir::convertSeparators(filename+".cfg"), true))
	{
		setLastError(tr("Can't copy .cfg file"));
		aLog::print(aLog::Error, tr("aBackup copy unzipped business schema file"));
		cleanupTmpFiles(tmpDirName, &templatesName);
		return true;
	}
	else
	{
		aLog::print(aLog::Debug, tr("aBackup copy business schema file"));
	}
	emit(progress(++prg,totalSteps));
//	printf("filename =%s\n",filename.ascii());
	changeRC(rcfile, filename+".cfg");
	cleanupTmpFiles(tmpDirName, &templatesName);
	setLastError(tr("Database import without errors"));
	aLog::print(aLog::Info, tr("aBackup import data ok"));
	return false;
}
Ejemplo n.º 4
0
bool DownloadUpdate()
{
	bool result = false;

	if(updateURL[0] == 0 || appPath[0] == 0 || !ChangeInterface(appPath, NOTSILENT))
	{
		ErrorPrompt("Did you unplug your SD/USB?");
		return false;
	}

	// stop checking if devices were removed/inserted
	// since we're saving a file
	HaltDeviceThread();

	int device;
	FindDevice(appPath, &device);

	char updateFile[50];
	sprintf(updateFile, "%s%sUpdate.zip", pathPrefix[device], APPNAME);

	FILE * hfile = fopen (updateFile, "wb");

	if (hfile)
	{
		if(http_request(updateURL, hfile, NULL, (1024*1024*10), NOTSILENT, 0) > 0)
		{
			ShowAction("Extracting update...");
			fclose (hfile);
			CSHA1 sha1;
			if(sha1.HashFile(updateFile)){
				char fileHash[41]="";
				sha1.Final();
				sha1.ReportHash(fileHash, 0);
				if(!strcasecmp(fileHash, updateHash)){
					char destPath[256];
					sprintf(destPath, "%sapps", pathPrefix[device]);
					result = unzipArchive(updateFile, destPath);
				}else{
					ErrorPrompt("Corrupted file!");
				}
			}else{
				ErrorPrompt("Could not verify file!");
			}
		}
		else
		{
			ErrorPrompt("Unable to download!");
			fclose (hfile);
		}
		remove(updateFile); // delete update file
	}else{
		ErrorPrompt("Unable to write to SD/USB!");
	}

	// go back to checking if devices were inserted/removed
	ResumeDeviceThread();

	if(result){
		InfoPrompt("Update successful!");
	}

	CancelAction();
	return result;
}