-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4361a4a
commit 7a7fa4c
Showing
9 changed files
with
767 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,75 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
# This file is used to ignore files which are generated | ||
# ---------------------------------------------------------------------------- | ||
|
||
*~ | ||
*.autosave | ||
*.a | ||
*.core | ||
*.moc | ||
*.o | ||
*.obj | ||
*.orig | ||
*.rej | ||
*.so | ||
*.so.* | ||
*_pch.h.cpp | ||
*_resource.rc | ||
*.qm | ||
.#* | ||
*.*# | ||
core | ||
!core/ | ||
tags | ||
.DS_Store | ||
.directory | ||
*.debug | ||
Makefile* | ||
*.prl | ||
*.app | ||
moc_*.cpp | ||
ui_*.h | ||
qrc_*.cpp | ||
Thumbs.db | ||
*.res | ||
*.rc | ||
/.qmake.cache | ||
/.qmake.stash | ||
|
||
# qtcreator generated files | ||
*.pro.user* | ||
|
||
# xemacs temporary files | ||
*.flc | ||
|
||
# Vim temporary files | ||
.*.swp | ||
|
||
# Visual Studio generated files | ||
*.ib_pdb_index | ||
*.idb | ||
*.ilk | ||
*.pdb | ||
*.sln | ||
*.suo | ||
*.vcproj | ||
*vcproj.*.*.user | ||
*.ncb | ||
*.sdf | ||
*.opensdf | ||
*.vcxproj | ||
*vcxproj.* | ||
|
||
# MinGW generated files | ||
*.Debug | ||
*.Release | ||
|
||
# Python byte code | ||
*.pyc | ||
|
||
# Binaries | ||
# -------- | ||
*.dll | ||
*.exe | ||
|
||
# Third-party libraries | ||
/thirdparty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
QT += core gui | ||
|
||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | ||
|
||
CONFIG += c++11 | ||
|
||
# You can make your code fail to compile if it uses deprecated APIs. | ||
# In order to do so, uncomment the following line. | ||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 | ||
|
||
SOURCES += \ | ||
main.cpp \ | ||
mainwindow.cpp \ | ||
utils.cpp | ||
|
||
HEADERS += \ | ||
mainwindow.h \ | ||
utils.h | ||
|
||
FORMS += \ | ||
mainwindow.ui | ||
|
||
# Default rules for deployment. | ||
qnx: target.path = /tmp/$${TARGET}/bin | ||
else: unix:!android: target.path = /opt/$${TARGET}/bin | ||
!isEmpty(target.path): INSTALLS += target | ||
|
||
# QuaZIP | ||
DEFINES += QUAZIP_STATIC | ||
INCLUDEPATH += $$[QT_INSTALL_HEADERS]/QtZlib | ||
include(thirdparty/quazip-0.9.1/quazip.pri) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include "mainwindow.h" | ||
|
||
#include <QApplication> | ||
|
||
int main(int argc, char *argv[]) { | ||
QApplication a(argc, argv); | ||
MainWindow w; | ||
w.show(); | ||
return a.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
#include "mainwindow.h" | ||
#include "ui_mainwindow.h" | ||
#include "utils.h" | ||
|
||
#include <QSettings> | ||
#include <QMessageBox> | ||
#include <QDialogButtonBox> | ||
#include <QFileDialog> | ||
#include <QDateTime> | ||
|
||
QSettings *mySettings; | ||
|
||
MainWindow::MainWindow(QWidget *parent) | ||
: QMainWindow(parent) | ||
, ui(new Ui::MainWindow) { | ||
ui->setupUi(this); | ||
|
||
// Load settings. | ||
mySettings = new QSettings("stevenlafl", "empyrionsave"); | ||
this->loadSettings(); | ||
} | ||
|
||
MainWindow::~MainWindow() { | ||
delete mySettings; | ||
if (timer.isActive()) { | ||
timer.stop(); | ||
} | ||
delete ui; | ||
} | ||
|
||
void MainWindow::loadSettings() { | ||
int x = mySettings->value("timerSlider").toInt(); | ||
|
||
// Trigger slider move. | ||
ui->timerSlider->setValue(x); | ||
this->on_timerSlider_sliderMoved(x); | ||
|
||
ui->backupEdit->setText(mySettings->value("backupFolder").toString()); | ||
ui->saveEdit->setText(mySettings->value("saveFolder").toString()); | ||
ui->saveZipCheck->setChecked(mySettings->value("saveAsZip").toBool()); | ||
|
||
ui->statusbar->showMessage("Settings loaded", 1 * 1000); | ||
} | ||
|
||
void MainWindow::saveSettings() { | ||
mySettings->setValue("timerSlider", ui->timerSlider->value()); | ||
mySettings->setValue("backupFolder", ui->backupEdit->text()); | ||
mySettings->setValue("saveFolder", ui->saveEdit->text()); | ||
mySettings->setValue("saveAsZip", ui->saveZipCheck->isChecked()); | ||
|
||
ui->statusbar->showMessage("Settings saved", 1 * 1000); | ||
} | ||
|
||
void MainWindow::backupSave() { | ||
|
||
QString backupDir = ui->backupEdit->text(); | ||
QString saveDir = ui->saveEdit->text(); | ||
|
||
QString timeString = QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss"); | ||
QString fileName = QDir(saveDir).dirName() + "_" + timeString; | ||
QString fullPath = backupDir + "/" + fileName; | ||
|
||
if (ui->saveZipCheck->isChecked()) { | ||
fullPath += ".zip"; | ||
fileName += ".zip"; | ||
if (Utils::archive(fullPath, saveDir)) { | ||
ui->statusbar->showMessage("Backup saved: " + fileName, 1 * 1000); | ||
} | ||
else { | ||
ui->statusbar->showMessage("Backup failed: " + fileName, 1 * 1000); | ||
} | ||
} | ||
else { | ||
if (Utils::copyPath(saveDir, fullPath, true)) { | ||
ui->statusbar->showMessage("Backup saved: " + fileName, 1 * 1000); | ||
} | ||
else { | ||
ui->statusbar->showMessage("Backup failed: " + fileName, 1 * 1000); | ||
} | ||
} | ||
|
||
ui->textEdit->setText(saveDir + " ---> " + fullPath); | ||
} | ||
|
||
void MainWindow::closeEvent(QCloseEvent *event) { | ||
QMessageBox::StandardButton resBtn = QMessageBox::question( this, "Empyrion Save", | ||
"Are you sure you want to exit?", | ||
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, | ||
QMessageBox::Yes); | ||
if (resBtn != QMessageBox::Yes) { | ||
event->ignore(); | ||
} else { | ||
event->accept(); | ||
} | ||
} | ||
|
||
void MainWindow::timerEvent(QTimerEvent *event) { | ||
if (event->timerId() == timer.timerId()) { | ||
timerCounter++; | ||
|
||
if (timerCounter > timerMax) { | ||
timerCounter = 0; | ||
this->backupSave(); | ||
} | ||
else { | ||
ui->statusbar->showMessage("Last saved " + this->getMinuteString(timerCounter) + " ago", 1 * 1000); | ||
} | ||
} else { | ||
QWidget::timerEvent(event); | ||
} | ||
} | ||
|
||
QString MainWindow::getMinuteString(int seconds) { | ||
int min = seconds / 60; | ||
int sec = seconds % 60; | ||
QString time = ""; | ||
|
||
time += QString("%1m%2s").arg( | ||
QVariant(min).toString().rightJustified(2, '0'), | ||
QVariant(sec).toString().rightJustified(2, '0')); | ||
|
||
return time; | ||
} | ||
|
||
void MainWindow::on_timerSlider_sliderMoved(int position) { | ||
ui->intervalLabel->setText(this->getMinuteString(position)); | ||
} | ||
|
||
void MainWindow::on_saveBrowse_clicked() { | ||
QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), | ||
ui->saveEdit->text(), | ||
QFileDialog::ShowDirsOnly | ||
| QFileDialog::DontResolveSymlinks); | ||
if (!dir.isEmpty()) | ||
{ | ||
ui->saveEdit->setText(dir); | ||
} | ||
} | ||
|
||
void MainWindow::on_backupBrowse_clicked() { | ||
QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), | ||
ui->backupEdit->text(), | ||
QFileDialog::ShowDirsOnly | ||
| QFileDialog::DontResolveSymlinks); | ||
if (!dir.isEmpty()) { | ||
ui->backupEdit->setText(dir); | ||
} | ||
} | ||
|
||
void MainWindow::on_saveButton_clicked() { | ||
this->saveSettings(); | ||
} | ||
|
||
void MainWindow::on_startButton_clicked() { | ||
if (!timer.isActive()) { | ||
timerCounter = 0; | ||
timerMax = ui->timerSlider->value(); | ||
timer.start(1 * 1000, this); | ||
ui->startButton->setText("Stop"); | ||
} | ||
else { | ||
timerCounter = 0; | ||
ui->startButton->setText("Start"); | ||
timer.stop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#ifndef MAINWINDOW_H | ||
#define MAINWINDOW_H | ||
|
||
#include <QMainWindow> | ||
#include <QBasicTimer> | ||
#include <QCloseEvent> | ||
|
||
QT_BEGIN_NAMESPACE | ||
namespace Ui { class MainWindow; } | ||
QT_END_NAMESPACE | ||
|
||
class MainWindow : public QMainWindow { | ||
Q_OBJECT | ||
|
||
public: | ||
MainWindow(QWidget *parent = nullptr); | ||
~MainWindow(); | ||
|
||
void closeEvent(QCloseEvent (*event)); | ||
QString getMinuteString(int seconds); | ||
|
||
private slots: | ||
void on_timerSlider_sliderMoved(int position); | ||
|
||
void on_saveBrowse_clicked(); | ||
|
||
void on_backupBrowse_clicked(); | ||
|
||
void on_saveButton_clicked(); | ||
|
||
void on_startButton_clicked(); | ||
|
||
private: | ||
Ui::MainWindow *ui; | ||
QBasicTimer timer; | ||
int timerCounter = 0; | ||
int timerMax = 0; | ||
|
||
protected: | ||
void timerEvent(QTimerEvent *event) override; | ||
void loadSettings(); | ||
void saveSettings(); | ||
|
||
void backupSave(); | ||
}; | ||
#endif // MAINWINDOW_H |
Oops, something went wrong.