#include "mainwindow.h"
#include <QSqlDatabase>
#include <QDebug>
#include <QSqlQuery>
#include <QSqlError>
#include <QSqlTableModel>
#include <QTableView>
#include <QString>
#include <QDir>
#include <QFileDialog>
#include <QMessageBox>
#include <QSqlRecord>
#include <QLabel>
#include <QProgressBar>
#include <QLayout>
#include <QVBoxLayout>
#include <QTimer>
MainWindow
::MainWindow(QWidget *parent
){
QString dir
= QFileDialog::getOpenFileName(this, tr
("Open Directory"),
"");
//,tr("SQLite (*.*)")); //qDebug()<<dir;
//path.append(QDir::separator()).append("dbpass");
path
= QDir::toNativeSeparators(path
);
//qDebug()<<path;
//db.setDatabaseName(path);
//db.setDatabaseName("thomsonkeysDB");
db.setDatabaseName(path);
if (db.open()) {
// Try to locate the contacts database.
// If it is not available create it.
if (db.tables().indexOf("thomsonkeys") == -1) {
query.prepare("CREATE TABLE thomsonkeys (ssid VARCHAR(6), pass VARCHAR(10))");
if (!query.exec())
qCritical() << query.lastError();
}
} else {
qCritical() << db.lastError();
}
progresso->setMaximum(174680046);
layout->addWidget(progresso);
w->setLayout(layout);
this->setCentralWidget(w);
QTimer::singleShot(100,
this,
SLOT(teste
()));
}
MainWindow::~MainWindow()
{
}
void MainWindow::teste(){
QString dir
= QFileDialog::getOpenFileName(this, tr
("Open Directory"),
"",tr
("Texto (*.txt)"));
if(f.isOpen())
{
int step=174680046/100;
int bytesProcessed=0;
progresso->setValue(bytesProcessed);
while (not f.atEnd()){
linha = f.readLine().data();
bytesProcessed+= linha.size();
list = linha.split(":");
query.exec("insert into thomsonkeys values('"+list.at(0)+"', '"+list.at(1)+"')");
if (bytesProcessed%step<=10){
qDebug()<<"bytesProcessed:"<<bytesProcessed;
progresso->setValue(bytesProcessed);
}
}
progresso->setValue(bytesProcessed);
}
else
{
QMessageBox::warning(this,
"Erro",
"Sem ficheiro com as passwords!");
}
}
#include "mainwindow.h"
#include <QSqlDatabase>
#include <QDebug>
#include <QSqlQuery>
#include <QSqlError>
#include <QSqlTableModel>
#include <QTableView>
#include <QString>
#include <QDir>
#include <QFileDialog>
#include <QMessageBox>
#include <QSqlRecord>
#include <QLabel>
#include <QProgressBar>
#include <QLayout>
#include <QVBoxLayout>
#include <QTimer>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QString dir = QFileDialog::getOpenFileName(this, tr("Open Directory"),"");//,tr("SQLite (*.*)"));
//qDebug()<<dir;
QString path(dir);
//path.append(QDir::separator()).append("dbpass");
path = QDir::toNativeSeparators(path);
//qDebug()<<path;
//db.setDatabaseName(path);
db = QSqlDatabase::addDatabase("QSQLITE");
//db.setDatabaseName("thomsonkeysDB");
db.setDatabaseName(path);
if (db.open()) {
// Try to locate the contacts database.
// If it is not available create it.
if (db.tables().indexOf("thomsonkeys") == -1) {
QSqlQuery query(db);
query.prepare("CREATE TABLE thomsonkeys (ssid VARCHAR(6), pass VARCHAR(10))");
if (!query.exec())
qCritical() << query.lastError();
}
} else {
qCritical() << db.lastError();
}
QVBoxLayout *layout = new QVBoxLayout;
progresso = new QProgressBar;
progresso->setMaximum(174680046);
layout->addWidget(progresso);
QWidget *w=new QWidget();
w->setLayout(layout);
this->setCentralWidget(w);
QTimer::singleShot(100, this, SLOT(teste()));
}
MainWindow::~MainWindow()
{
}
void MainWindow::teste(){
QString dir = QFileDialog::getOpenFileName(this, tr("Open Directory"),"",tr("Texto (*.txt)"));
QFile f(dir);
f.open(QIODevice::ReadOnly);
if(f.isOpen())
{
QSqlQuery query(db);
int step=174680046/100;
int bytesProcessed=0;
QString linha;
QStringList list;
progresso->setValue(bytesProcessed);
while (not f.atEnd()){
linha = f.readLine().data();
bytesProcessed+= linha.size();
list = linha.split(":");
query.exec("insert into thomsonkeys values('"+list.at(0)+"', '"+list.at(1)+"')");
if (bytesProcessed%step<=10){
qDebug()<<"bytesProcessed:"<<bytesProcessed;
progresso->setValue(bytesProcessed);
}
}
progresso->setValue(bytesProcessed);
}
else
{
QMessageBox::warning(this,"Erro","Sem ficheiro com as passwords!");
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks