this should supposedly add hwplay:// schemes to windows, after user presses file association
authorkoda
Tue, 12 Mar 2013 17:18:55 +0100
changeset 8722 2dead6b84bca
parent 8721 4cc2b2cd4184
child 8723 b08cc68a26a3
this should supposedly add hwplay:// schemes to windows, after user presses file association
QTfrontend/HWApplication.cpp
QTfrontend/HWApplication.h
QTfrontend/hwform.cpp
QTfrontend/main.cpp
--- a/QTfrontend/HWApplication.cpp	Tue Mar 12 02:30:36 2013 +0100
+++ b/QTfrontend/HWApplication.cpp	Tue Mar 12 17:18:55 2013 +0100
@@ -45,6 +45,25 @@
     for (int i = 1; i < argc; i++)
         qDebug("%d: %s", i, argv[i]);
 #endif
+    // on Windows, sending an event right away leads to a segfault
+    // so we use urlString to save the data and send the event just before the app.exec()
+    urlString = NULL;
+    if (argc > 1) {
+        urlString = new QString(argv[1]);
+        if (urlString->contains("//", Qt::CaseInsensitive) == false) {
+            delete urlString;
+            urlString = NULL;
+        }
+    }
+}
+
+void HWApplication::fakeEvent()
+{
+    QUrl parsedUrl(*urlString);
+    delete urlString;
+    urlString = NULL;
+    QFileOpenEvent *openEvent = new QFileOpenEvent(parsedUrl);
+    QCoreApplication::sendEvent(QCoreApplication::instance(), openEvent);
 }
 
 bool HWApplication::event(QEvent *event)
@@ -60,14 +79,14 @@
 
         QFile file(path);
         if (scheme == "file" && file.exists()) {
-            form->PlayDemoQuick(openEvent->file());
+            form->PlayDemoQuick(path);
             return true;
         } else if (scheme == "hwplay") {
             int port = openEvent->url().port(NETGAME_DEFAULT_PORT);
             form->NetConnectQuick(address, (quint16) port);
             return true;
         } else {
-            const QString errmsg = tr("Not yet implemented").arg(path);
+            const QString errmsg = tr("Scheme '%1' not supported").arg(scheme);
             MessageDialog::ShowErrorMessage(errmsg, form);
             return false;
         }
--- a/QTfrontend/HWApplication.h	Tue Mar 12 02:30:36 2013 +0100
+++ b/QTfrontend/HWApplication.h	Tue Mar 12 17:18:55 2013 +0100
@@ -41,6 +41,8 @@
         ~HWApplication() {};
 
         HWForm *form;
+        QString *urlString;
+        void fakeEvent();
     protected:
         bool event(QEvent *);
 };
--- a/QTfrontend/hwform.cpp	Tue Mar 12 02:30:36 2013 +0100
+++ b/QTfrontend/hwform.cpp	Tue Mar 12 17:18:55 2013 +0100
@@ -1916,6 +1916,8 @@
     QString arguments = getDemoArguments();
 #ifdef _WIN32
     QSettings registry_hkcr("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
+
+    // file extension(s)
     registry_hkcr.setValue(".hwd/Default", "Hedgewars.Demo");
     registry_hkcr.setValue(".hws/Default", "Hedgewars.Save");
     registry_hkcr.setValue("Hedgewars.Demo/Default", tr("Hedgewars Demo File", "File Types"));
@@ -1924,6 +1926,12 @@
     registry_hkcr.setValue("Hedgewars.Save/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwsfile.ico\",0");
     registry_hkcr.setValue("Hedgewars.Demo/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" " + arguments + " %1");
     registry_hkcr.setValue("Hedgewars.Save/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" " + arguments + " %1");
+
+    // custom url scheme(s)
+    registry_hkcr.setValue("hwplay/Default", "\"URL:Hedgewars ServerAccess Protocol\"");
+    registry_hkcr.setValue("hwplay/URL Protocol", "");
+    registry_hkcr.setValue("hwplay/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hedgewars.exe\",0");
+    registry_hkcr.setValue("hwplay/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hedgewars.exe\"  %1");
 #elif defined __APPLE__
     // only useful when other apps have taken precedence over our file extensions and you want to reset it
     system("defaults write com.apple.LaunchServices LSHandlers -array-add '<dict><key>LSHandlerContentTag</key><string>hwd</string><key>LSHandlerContentTagClass</key><string>public.filename-extension</string><key>LSHandlerRoleAll</key><string>org.hedgewars.desktop</string></dict>'");
--- a/QTfrontend/main.cpp	Tue Mar 12 02:30:36 2013 +0100
+++ b/QTfrontend/main.cpp	Tue Mar 12 17:18:55 2013 +0100
@@ -338,5 +338,7 @@
     app.form->show();
     if(splash)
         splash->close();
+    if (app.urlString)
+        app.fakeEvent();
     return app.exec();
 }