Skip to content

Commit

Permalink
Added option to pause updates
Browse files Browse the repository at this point in the history
  • Loading branch information
LFriede committed Apr 12, 2020
1 parent ed3f077 commit 9120b01
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 16 deletions.
22 changes: 22 additions & 0 deletions settingsform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ SettingsForm::SettingsForm(QWidget *parent) :
void SettingsForm::showEvent(QShowEvent *event) {
ui->cbAutoCheck->setChecked(globalSettings.autoCheck);
ui->leManagerPath->setText(globalSettings.managerPath);
ui->spinDelay->setValue(globalSettings.updateDelayValue);

switch (globalSettings.updateDelayFactor) {
case 0: {
ui->rbHours->setChecked(true);
break;
}
case 1: {
ui->rbDays->setChecked(true);
break;
}
case 2: {
ui->rbWeeks->setChecked(true);
break;
}
}
}

SettingsForm::~SettingsForm()
Expand All @@ -32,9 +48,15 @@ void SettingsForm::on_pbSave_clicked()
{
globalSettings.autoCheck = ui->cbAutoCheck->isChecked();
strcpy_s(globalSettings.managerPath, MAX_SETTING_SIZE, ui->leManagerPath->text().toStdString().c_str());
globalSettings.updateDelayValue = ui->spinDelay->value();
if (ui->rbHours->isChecked()) { globalSettings.updateDelayFactor = 0; }
if (ui->rbDays->isChecked()) { globalSettings.updateDelayFactor = 1; }
if (ui->rbWeeks->isChecked()) { globalSettings.updateDelayFactor = 2; }

BridgeSettingSetUint("UpdaterPlugin", "AutocheckOnStartup", globalSettings.autoCheck);
BridgeSettingSet("UpdaterPlugin", "PluginManagerPath", globalSettings.managerPath);
BridgeSettingSetUint("UpdaterPlugin", "DelayValue", globalSettings.updateDelayValue);
BridgeSettingSetUint("UpdaterPlugin", "DelayFactor", globalSettings.updateDelayFactor);

this->close();
}
61 changes: 53 additions & 8 deletions settingsform.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>167</height>
<height>270</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>167</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>400</width>
<height>167</height>
<height>270</height>
</size>
</property>
<property name="windowTitle">
Expand All @@ -33,6 +27,57 @@
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="grpPause">
<property name="title">
<string>Minimum timespan between automatic update checks</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QSpinBox" name="spinDelay">
<property name="value">
<number>1</number>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QRadioButton" name="rbHours">
<property name="text">
<string>Hours</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbDays">
<property name="text">
<string>Days</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbWeeks">
<property name="text">
<string>Weeks</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="lblTimeHint">
<property name="text">
<string>Enter zero to check on every startup.</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down
6 changes: 5 additions & 1 deletion updateform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,14 @@ UpdateForm::UpdateForm(QWidget *parent) :
foundCommitDate = false;

manager = new QNetworkAccessManager(this);
updaterProcess = new QProcess;
updaterProcess = new QProcess(this);
}

void UpdateForm::checkUpdate() {
// Save the date ;)
globalSettings.updateDelayTimestamp = QDateTime::currentDateTimeUtc().toTime_t();
BridgeSettingSetUint("UpdaterPlugin", "DelayTimestamp", globalSettings.updateDelayTimestamp);

// Let PluginManager update the server list
disconnect(updaterProcess, SIGNAL(finished(int, QProcess::ExitStatus)), 0, 0);
connect(updaterProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(plgmgrUpdateServerListFinished(int, QProcess::ExitStatus)));
Expand Down
35 changes: 28 additions & 7 deletions x64dbg_updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ void updateAll(bool restart) {
QString param = "\"" + QDir(globalSettings.managerPath).filePath("x64plgmnrc.exe").append(ArchValue("\" x32 ", "\" x64 ") + QString::number(restart));

ShellExecuteW(0, L"open", (updaterPath + "_update.bat").toStdWString().c_str(), param.toStdWString().c_str(), updaterPath.toStdWString().c_str(), SW_SHOWDEFAULT);
_plugin_logputs((updaterPath + "_update.bat").toStdString().c_str());
_plugin_logputs(param.toStdString().c_str());
_plugin_logputs(updaterPath.toStdString().c_str());
}


Expand Down Expand Up @@ -116,11 +113,15 @@ PLUG_EXPORT void plugsetup(PLUG_SETUPSTRUCT* setupStruct)
myDlg = new UpdateForm();
settingsDlg = new SettingsForm();

BridgeSettingGetUint("UpdaterPlugin", "DelayTimestamp", &globalSettings.updateDelayTimestamp);

// Show settings dialog to user if there is something to configure first
duint chk = 0;
duint chk = 1;
if (
BridgeSettingGetUint("UpdaterPlugin", "AutocheckOnStartup", &chk) == false ||
BridgeSettingGet("UpdaterPlugin", "PluginManagerPath", globalSettings.managerPath) == false
BridgeSettingGet("UpdaterPlugin", "PluginManagerPath", globalSettings.managerPath) == false ||
BridgeSettingGetUint("UpdaterPlugin", "DelayValue", &globalSettings.updateDelayValue) == false ||
BridgeSettingGetUint("UpdaterPlugin", "DelayFactor", &globalSettings.updateDelayFactor) == false
) {
globalSettings.autoCheck = chk == 1;
settingsDlg->show();
Expand Down Expand Up @@ -193,8 +194,28 @@ PLUG_EXPORT void plugsetup(PLUG_SETUPSTRUCT* setupStruct)

myDlg->currentCommitHash = commithash;


if (globalSettings.autoCheck) {
myDlg->checkUpdate();
QDateTime testTime;
testTime.setTime_t(globalSettings.updateDelayTimestamp);
switch (globalSettings.updateDelayFactor) {
case 0: {
testTime = testTime.addSecs(globalSettings.updateDelayValue * 60 * 60);
break;
}
case 1: {
testTime = testTime.addDays(globalSettings.updateDelayValue);
break;
}
case 2: {
testTime = testTime.addDays(globalSettings.updateDelayValue * 7);
break;
}
}

if (QDateTime::currentDateTimeUtc() > testTime) {
myDlg->checkUpdate();
} else {
_plugin_logputs((QString("x64dbg Updater: Autocheck delayed until -> ") + testTime.toString(Qt::SystemLocaleShortDate)).toStdString().c_str());
}
}
}
3 changes: 3 additions & 0 deletions x64dbg_updater_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ struct MY_PLUGIN_SETTINGS {
bool autoCheck = false;
char managerPath[MAX_SETTING_SIZE];
bool updateOnExit = false;
duint updateDelayValue = 1;
duint updateDelayFactor = 1; // 0 = hours, 1 = days, 2 = weeks
duint updateDelayTimestamp = 0;
};
extern MY_PLUGIN_SETTINGS globalSettings;

Expand Down

0 comments on commit 9120b01

Please sign in to comment.