diff --git a/deploy/FortFirewall.iss b/deploy/FortFirewall.iss index 1023b32e..96740fe9 100644 --- a/deploy/FortFirewall.iss +++ b/deploy/FortFirewall.iss @@ -119,6 +119,9 @@ Type: files; Name: "{app}\curl*.*" Type: files; Name: "{app}\ChangeLog" Type: files; Name: "{app}\delay-start.bat" +[UninstallDelete] +Type: files; Name: "{app}\restart.bat" + [Registry] Root: HKLM; Subkey: "System\CurrentControlSet\Services\EventLog\System\fortfw"; Flags: uninsdeletekey Root: HKLM; Subkey: "System\CurrentControlSet\Services\EventLog\System\fortfw"; \ diff --git a/src/ui/FortFirewallUI.pro b/src/ui/FortFirewallUI.pro index d3e29a37..678a85a6 100644 --- a/src/ui/FortFirewallUI.pro +++ b/src/ui/FortFirewallUI.pro @@ -458,7 +458,8 @@ HEADERS += \ # Icons, README.* RESOURCES += \ fort_icons.qrc \ - fort_readme.qrc + fort_readme.qrc \ + fort_scripts.qrc # Database Migrations OTHER_FILES += \ diff --git a/src/ui/fort_scripts.qrc b/src/ui/fort_scripts.qrc new file mode 100644 index 00000000..11a9c555 --- /dev/null +++ b/src/ui/fort_scripts.qrc @@ -0,0 +1,5 @@ + + + scripts/restart.bat + + diff --git a/src/ui/fortmanager.cpp b/src/ui/fortmanager.cpp index fa1cf6e3..f75c8e2a 100644 --- a/src/ui/fortmanager.cpp +++ b/src/ui/fortmanager.cpp @@ -539,4 +539,5 @@ void FortManager::setupResources() Q_INIT_RESOURCE(stat_migrations); Q_INIT_RESOURCE(fort_icons); + Q_INIT_RESOURCE(fort_scripts); } diff --git a/src/ui/scripts/restart.bat b/src/ui/scripts/restart.bat new file mode 100644 index 00000000..50526f8e --- /dev/null +++ b/src/ui/scripts/restart.bat @@ -0,0 +1,20 @@ +@rem Restart the UI process after Installer + +@rem Timeout seconds +set timeout=30 + +:LOOP + +@rem Delay for 1 second +ping -n 2 127.0.0.1 >NUL + +@if not exist inst.tmp @goto END + +@set /a timeout=%timeout%-1 +@if "%timeout%" == "0" @goto END + +@goto LOOP + + +:END +start FortFirewall.exe --launch diff --git a/src/ui/util/osutil.cpp b/src/ui/util/osutil.cpp index 65e1e656..0dac7bd1 100644 --- a/src/ui/util/osutil.cpp +++ b/src/ui/util/osutil.cpp @@ -181,21 +181,39 @@ bool OsUtil::registerAppRestart() void OsUtil::beginRestartClients() { - FileUtil::writeFileData(FileUtil::appBinLocation() + "/inst.tmp", {}); + const auto appPath = FileUtil::pathSlash(FileUtil::appBinLocation()); + + FileUtil::writeFileData(appPath + "inst.tmp", {}); + + // Create a restart script + { + const auto restartScriptPath = appPath + "restart.bat"; + + FileUtil::removeFile(restartScriptPath); + FileUtil::copyFile(":/scripts/restart.bat", restartScriptPath); + QFile::setPermissions(restartScriptPath, QFile::WriteOwner); + } } void OsUtil::endRestartClients() { - FileUtil::removeFile(FileUtil::appBinLocation() + "/inst.tmp"); + const auto appPath = FileUtil::pathSlash(FileUtil::appBinLocation()); + + FileUtil::removeFile(appPath + "inst.tmp"); } void OsUtil::restartClient() { const QFileInfo fi(QCoreApplication::applicationFilePath()); - const auto command = QString("ping -n 4 127.0.0.1 >NUL" - " & if not exist inst.tmp start %1 --launch") - .arg(fi.fileName()); + QString command; + if (FileUtil::fileExists("restart.bat")) { + command = "restart.bat"; + } else { + command = QString("ping -n 4 127.0.0.1 >NUL" + " & if not exist inst.tmp start %1 --launch") + .arg(fi.fileName()); + } runCommand(command, /*workingDir=*/fi.path());