Engine:
authorsmaxx
Wed, 06 Oct 2010 22:36:41 +0200
changeset 3932 2fc211f60015
parent 3929 9a4bbc1f67a2
child 3934 8cdbc0505f18
Engine: * Temporary fix to log file writing when running from command line (standalone demo/savegame playback) Frontend: * Added a button to the settings menu to associate demos and savegames (.hwd/.hws) with the engine in Windows Explorer and other programs such as web browsers (Win32 only)
QTfrontend/hwconsts.cpp.in
QTfrontend/hwconsts.h
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/main.cpp
QTfrontend/pages.cpp
QTfrontend/pages.h
bin/hwdfile.ico
bin/hwsfile.ico
hedgewars/uMisc.pas
--- a/QTfrontend/hwconsts.cpp.in	Wed Oct 06 15:37:56 2010 -0400
+++ b/QTfrontend/hwconsts.cpp.in	Wed Oct 06 22:36:41 2010 +0200
@@ -30,6 +30,9 @@
 QStringList * Themes;
 QStringList * mapList;
 
+bool custom_config = false;
+bool custom_data = false;
+
 int cMaxTeams = 6;
 
 QString * cDefaultAmmoStore = new QString(
--- a/QTfrontend/hwconsts.h	Wed Oct 06 15:37:56 2010 -0400
+++ b/QTfrontend/hwconsts.h	Wed Oct 06 22:36:41 2010 +0200
@@ -31,6 +31,9 @@
 extern QDir * cfgdir;
 extern QDir * datadir;
 
+extern bool custom_config;
+extern bool custom_data;
+
 extern int cMaxTeams;
 
 extern QStringList * Themes;
--- a/QTfrontend/hwform.cpp	Wed Oct 06 15:37:56 2010 -0400
+++ b/QTfrontend/hwform.cpp	Wed Oct 06 22:36:41 2010 +0200
@@ -141,6 +141,9 @@
     connect(ui.pageOptions->BtnDeleteTeam, SIGNAL(clicked()), this, SLOT(DeleteTeam()));
     connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions()));
     connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), this, SLOT(GoBack()));
+#ifdef _WIN32
+    connect(ui.pageOptions->BtnAssociateFiles, SIGNAL(clicked()), this, SLOT(AssociateFiles()));
+#endif
 
     connect(ui.pageOptions->WeaponEdit, SIGNAL(clicked()), this, SLOT(GoToSelectWeapon()));
     connect(ui.pageOptions->WeaponsButt, SIGNAL(clicked()), this, SLOT(GoToSelectNewWeapon()));
@@ -1110,3 +1113,17 @@
     for(int i = 0; (i < entries.count()) && (i <= team.CampaignProgress); i++)
         ui.pageCampaign->CBSelect->addItem(QString(entries[i]).replace(QRegExp("^(\\d+)#(.+)\\.lua"), QComboBox::tr("Mission") + " \\1: \\2"), QString(entries[i]).replace(QRegExp("^(.*)\\.lua"), "\\1"));
 }
+
+void HWForm::AssociateFiles()
+{
+    QSettings registry_hkcr("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
+    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"));
+    registry_hkcr.setValue("Hedgewars.Save/Default", tr("Hedgewars Save File", "File Types"));
+    registry_hkcr.setValue("Hedgewars.Demo/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwdfile.ico\",0");
+    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\" \"" + datadir->absolutePath().replace("/", "\\") + "\" \"%1\"");
+    registry_hkcr.setValue("Hedgewars.Save/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"" + datadir->absolutePath().replace("/", "\\") + "\" \"%1\"");
+    QMessageBox::information(0, "", QMessageBox::tr("All file associations have been set."));
+}
--- a/QTfrontend/hwform.h	Wed Oct 06 15:37:56 2010 -0400
+++ b/QTfrontend/hwform.h	Wed Oct 06 22:36:41 2010 +0200
@@ -78,6 +78,7 @@
     void GoToAdmin();
     void GoToPage(quint8 id);
     void GoBack();
+    void AssociateFiles();
     void btnExitPressed();
     void btnExitClicked();
     void IntermediateSetup();
--- a/QTfrontend/main.cpp	Wed Oct 06 15:37:56 2010 -0400
+++ b/QTfrontend/main.cpp	Wed Oct 06 22:36:41 2010 +0200
@@ -73,11 +73,13 @@
             qWarning() << "WARNING: Cannot open DATA_PATH=" << f.absoluteFilePath();
         }
         *cDataDir = f.absoluteFilePath();
+        custom_data = true;
     }
 
     if(parsedArgs.contains("config-dir")) {
         QFileInfo f(parsedArgs["config-dir"]);
         *cConfigDir = f.absoluteFilePath();
+        custom_config = true;
     }
 
     app.setStyle(new QPlastiqueStyle);
@@ -410,12 +412,11 @@
 
     // Win32 registry setup (used for xfire detection etc. - don't set it if we're running in "portable" mode with a custom config dir)
 #ifdef _WIN32
-    if(cConfigDir->length() == 0)
+    if(!custom_config)
     {
-        QSettings registry(QSettings::NativeFormat, QSettings::UserScope, "Hedgewars Project", "Hedgewars");
-        QFileInfo f(argv[0]);
-        registry.setValue("file", f.absoluteFilePath());
-        registry.setValue("path", f.absolutePath());
+        QSettings registry_hklm("HKEY_LOCAL_MACHINE", QSettings::NativeFormat);
+        registry_hklm.setValue("Software/Hedgewars/Frontend", bindir->absolutePath().replace("/", "\\") + "\\hedgewars.exe");
+        registry_hklm.setValue("Software/Hedgewars/Path", bindir->absolutePath().replace("/", "\\"));
     }
 #endif
 
--- a/QTfrontend/pages.cpp	Wed Oct 06 15:37:56 2010 -0400
+++ b/QTfrontend/pages.cpp	Wed Oct 06 22:36:41 2010 +0200
@@ -147,6 +147,7 @@
         //Tips << tr("", "Tips");
 #ifdef _WIN32
         Tips << tr("You can find your Hedgewars configuration files under \"My Documents\\Hedgewars\". Create backups or take the files with you, but don't edit them by hand.", "Tips");
+        Tips << tr("You're able to associate Hedgewars related files (savegames and demo recordings) with the game to launch them right from your favorite file or internet browser.", "Tips");
 #else
         Tips << tr("You can find your Hedgewars configuration files under \"Hedgewars\" in your home directory. Create backups or take the files with you, but don't edit them by hand.", "Tips");
 #endif
@@ -610,7 +611,12 @@
             CBAutoUpdate->setText(QCheckBox::tr("Check for updates at startup"));
             MiscLayout->addWidget(CBAutoUpdate, 4, 0, 1, 2);
 #endif
-
+#ifdef _WIN32
+            BtnAssociateFiles = new QPushButton(groupMisc);
+            BtnAssociateFiles->setText(QPushButton::tr("Associate file extensions"));
+            BtnAssociateFiles->setEnabled(!custom_data && !custom_config);
+            MiscLayout->addWidget(BtnAssociateFiles, 4, 0, 1, 2);
+#endif
             gbTBLayout->addWidget(groupMisc, 2, 0);
         }
 
@@ -735,6 +741,8 @@
     BtnBack->setFixedHeight(BtnSaveOptions->height());
     BtnBack->setFixedWidth(BtnBack->width()+2);
     BtnBack->setStyleSheet("QPushButton{margin: 22px 0 9px 2px;}");
+
+//    BtnAssociateFiles = addButton("");
 }
 
 PageNet::PageNet(QWidget* parent) : AbstractPage(parent)
--- a/QTfrontend/pages.h	Wed Oct 06 15:37:56 2010 -0400
+++ b/QTfrontend/pages.h	Wed Oct 06 22:36:41 2010 +0200
@@ -216,6 +216,7 @@
     QPushButton *BtnNewTeam;
     QPushButton *BtnEditTeam;
     QPushButton *BtnDeleteTeam;
+    QPushButton *BtnAssociateFiles;
     QLabel *LblNoEditTeam;
     QComboBox *CBTeamName;
     IconedGroupBox *AGGroupBox;
Binary file bin/hwdfile.ico has changed
Binary file bin/hwsfile.ico has changed
--- a/hedgewars/uMisc.pas	Wed Oct 06 15:37:56 2010 -0400
+++ b/hedgewars/uMisc.pas	Wed Oct 06 22:36:41 2010 +0200
@@ -822,7 +822,7 @@
         begin
             for i:= 0 to 7 do
             begin
-                assign(f, ExtractFileDir(ParamStr(2)) + '/Logs/' + cLogfileBase + inttostr(i) + '.log');
+                assign(f, ExtractFileDir(ParamStr(2)) + '/' + cLogfileBase + inttostr(i) + '.log');
                 rewrite(f);
                 if IOResult = 0 then break;
             end;