|
@@ -1,4 +1,7 @@
|
|
|
#include "legacyapplication.h"
|
|
|
+#include "models/lotrodatmanager.h"
|
|
|
+#include "models/patchlist.h"
|
|
|
+#include "widgets/mainwindow.h"
|
|
|
|
|
|
#include <QLockFile>
|
|
|
#include <QMessageBox>
|
|
@@ -6,6 +9,46 @@
|
|
|
#include <QFontDatabase>
|
|
|
#include <QMessageLogContext>
|
|
|
#include <QTextStream>
|
|
|
+#include <QTcpSocket>
|
|
|
+
|
|
|
+extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
|
|
|
+
|
|
|
+bool urlExists(QUrl theurl){
|
|
|
+ QTextStream out(stdout);
|
|
|
+ QTcpSocket socket;
|
|
|
+ QByteArray buffer;
|
|
|
+
|
|
|
+ socket.connectToHost(theurl.host(), 80);
|
|
|
+ if (socket.waitForConnected()) {
|
|
|
+
|
|
|
+ socket.write("GET / HTTP/1.1\r\n"
|
|
|
+ "host: " + theurl.host().toUtf8() + "\r\n\r\n");
|
|
|
+ if (socket.waitForReadyRead()) {
|
|
|
+ while(socket.bytesAvailable()){
|
|
|
+ buffer.append(socket.readAll());
|
|
|
+ int packetSize=buffer.size();
|
|
|
+ while(packetSize>0)
|
|
|
+ {
|
|
|
+
|
|
|
+ out << "[" << buffer.data() << "]" <<endl;
|
|
|
+
|
|
|
+
|
|
|
+ if (buffer.contains("200 OK") ||
|
|
|
+ buffer.contains("302 Found") ||
|
|
|
+ buffer.contains("301 Moved")) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ buffer.remove(0,packetSize);
|
|
|
+
|
|
|
+ packetSize=buffer.size();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+return false;
|
|
|
+}
|
|
|
|
|
|
void logMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
|
|
{
|
|
@@ -51,16 +94,17 @@ void logMessageHandler(QtMsgType type, const QMessageLogContext &context, const
|
|
|
|
|
|
LegacyApplication::LegacyApplication(int &argc, char **argv)
|
|
|
: QApplication(argc, argv)
|
|
|
- , lotro_dat_manager(nullptr)
|
|
|
- , lotro_dat_manager_thread(nullptr)
|
|
|
- , patch_list(nullptr)
|
|
|
- , gui(nullptr)
|
|
|
{
|
|
|
qInstallMessageHandler(logMessageHandler);
|
|
|
+
|
|
|
+ try_to_init_functional_modules_timer_.setInterval(1 * 1000);
|
|
|
+ connect(&try_to_init_functional_modules_timer_, &QTimer::timeout, this, &LegacyApplication::TryToInitFunctionalModules);
|
|
|
+ try_to_init_functional_modules_timer_.stop();
|
|
|
}
|
|
|
|
|
|
bool LegacyApplication::init()
|
|
|
{
|
|
|
+ qt_ntfs_permission_lookup++;
|
|
|
qDebug() << "Starting initialisation...";
|
|
|
|
|
|
QCoreApplication::setOrganizationName("LotroLegacy");
|
|
@@ -113,9 +157,127 @@ bool LegacyApplication::init()
|
|
|
qDebug() << "Starting GUI initialisation...";
|
|
|
|
|
|
gui = new MainWindow(patch_list);
|
|
|
- qDebug() << "Legacy Initialization finished!";
|
|
|
+ connect(this, &LegacyApplication::ErrorStatusChanged, gui, &MainWindow::onErrorStatusChanged);
|
|
|
+ connect(this, &LegacyApplication::SecondsToNextTryToInitChanged, gui, &MainWindow::onSecondsToNextTryToInitChanged);
|
|
|
+
|
|
|
+ qDebug() << "Starting functional modules initialisation...";
|
|
|
|
|
|
- patch_list->startAutoUpdate();
|
|
|
- patch_list->initialize();
|
|
|
+ TryToInitFunctionalModules();
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+LegacyApplication::ErrorStatus LegacyApplication::CheckErrorStatus()
|
|
|
+{
|
|
|
+ size_t status = E_NO_ERRORS;
|
|
|
+ QString game_folder_path = Settings::getValue("Lotro/game_path").toString();
|
|
|
+ QString locale_prefix = Settings::getValue("Lotro/original_locale").toString();
|
|
|
+
|
|
|
+
|
|
|
+ QFileInfo lotro_launcher_exe(game_folder_path + "/LotroLauncher.exe");
|
|
|
+ if (!lotro_launcher_exe.exists()) {
|
|
|
+ status |= E_WRONG_GAME_FOLDER;
|
|
|
+ } else {
|
|
|
+ if (!QFile::setPermissions(lotro_launcher_exe.absoluteFilePath(),
|
|
|
+ QFileDevice::ReadUser | QFileDevice::WriteUser | QFileDevice::ExeUser)) {
|
|
|
+ status |= E_WRONG_FILE_PERMISSIONS;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!patch_list->getManager()->Initialised() || !patch_list->getManager()->DatPathIsRelevant()) {
|
|
|
+ QString client_local_filepath = game_folder_path + "/client_local_" + locale_prefix + ".dat";
|
|
|
+ QString client_general_filepath = game_folder_path + "/client_general.dat";
|
|
|
+
|
|
|
+ QFileInfo client_local_file(client_local_filepath);
|
|
|
+ QFileInfo client_general_file(client_general_filepath);
|
|
|
+
|
|
|
+ if (!client_general_file.exists() || !client_local_file.exists()) {
|
|
|
+ status |= E_DAT_FILES_MISSING;
|
|
|
+ } else {
|
|
|
+ if (!QFile::setPermissions(client_general_filepath,
|
|
|
+ QFileDevice::ReadUser |
|
|
|
+ QFileDevice::WriteUser |
|
|
|
+ QFileDevice::ExeUser)) {
|
|
|
+ status |= E_WRONG_FILE_PERMISSIONS;
|
|
|
+ status |= E_CANNOT_ACCESS_DAT_FILES;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!QFile::setPermissions(client_local_filepath,
|
|
|
+ QFileDevice::ReadUser |
|
|
|
+ QFileDevice::WriteUser |
|
|
|
+ QFileDevice::ExeUser)) {
|
|
|
+ status |= E_WRONG_FILE_PERMISSIONS;
|
|
|
+ status |= E_CANNOT_ACCESS_DAT_FILES;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ LOTRO_DAT::DatFile test_file;
|
|
|
+ auto result = test_file.Initialise(client_local_filepath.toStdString(), 0);
|
|
|
+ if (!result.result) {
|
|
|
+ if (result.msg == "DATINIT: Error, cannot initialize dat due to internal IO error") {
|
|
|
+ status |= E_CANNOT_ACCESS_DAT_FILES;
|
|
|
+ } else {
|
|
|
+ status |= E_DAT_FILE_INCORRECT;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ result = test_file.Initialise(client_general_filepath.toStdString(), 0);
|
|
|
+ if (!result.result) {
|
|
|
+ if (result.msg == "DATINIT: Error, cannot initialize dat due to internal IO error") {
|
|
|
+ status |= E_CANNOT_ACCESS_DAT_FILES;
|
|
|
+ } else {
|
|
|
+ status |= E_DAT_FILE_INCORRECT;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!urlExists(QUrl(Settings::getValue("Network/patch_updates_url").toString()))) {
|
|
|
+ status |= E_NO_SERVER_CONNECTION;
|
|
|
+ }
|
|
|
+
|
|
|
+ qDebug() << "LegacyApplication: StatusCheck: " << ErrorStatus(status);
|
|
|
+ return ErrorStatus(status);
|
|
|
+}
|
|
|
+
|
|
|
+void LegacyApplication::TryToInitFunctionalModules()
|
|
|
+{
|
|
|
+ if (seconds_after_previous_try_to_init_ + 1 < try_to_init_timeout_) {
|
|
|
+ seconds_after_previous_try_to_init_++;
|
|
|
+ emit SecondsToNextTryToInitChanged(try_to_init_timeout_ - seconds_after_previous_try_to_init_);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try_to_init_functional_modules_timer_.stop();
|
|
|
+ seconds_after_previous_try_to_init_ = 0;
|
|
|
+ ErrorStatus status = CheckErrorStatus();
|
|
|
+ emit ErrorStatusChanged(status);
|
|
|
+
|
|
|
+ if (status == E_NO_ERRORS) {
|
|
|
+ patch_list->initialize();
|
|
|
+ patch_list->startAutoUpdate();
|
|
|
+ } else {
|
|
|
+ qWarning() << "LegacyApplication: Couldnt init functional modules!";
|
|
|
+ try_to_init_functional_modules_timer_.start();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+QDebug operator<<(QDebug dbg, const LegacyApplication::ErrorStatus &status)
|
|
|
+{
|
|
|
+ bool wrong_game_folder = (status & LegacyApplication::E_WRONG_GAME_FOLDER);
|
|
|
+ bool dat_files_missing = (status & LegacyApplication::E_DAT_FILES_MISSING);
|
|
|
+ bool wrong_file_permissions = (status & LegacyApplication::E_WRONG_FILE_PERMISSIONS);
|
|
|
+ bool cannot_access_dat_files = (status & LegacyApplication::E_CANNOT_ACCESS_DAT_FILES);
|
|
|
+ bool dat_file_incorrect = (status & LegacyApplication::E_DAT_FILE_INCORRECT);
|
|
|
+ bool no_server_connection = (status & LegacyApplication::E_NO_SERVER_CONNECTION);
|
|
|
+
|
|
|
+ dbg << "ErrorStatus( "
|
|
|
+ << (wrong_game_folder ? "Wrong game folder!" : "")
|
|
|
+ << (dat_files_missing ? "Dat files missing!" : "")
|
|
|
+ << (wrong_file_permissions ? "Wrong file permissions!" : "")
|
|
|
+ << (cannot_access_dat_files ? "Cannot access dat files!" : "")
|
|
|
+ << (dat_file_incorrect ? "Incorrect dat file!" : "")
|
|
|
+ << (no_server_connection ? "No server connection!" : "")
|
|
|
+ <<")";
|
|
|
+
|
|
|
+ return dbg;
|
|
|
+}
|