make the associate button use the user's settings for loading demos/saves
authornemo
Tue, 17 May 2011 19:05:13 -0400
changeset 5213 a86768368309
parent 5212 eaffb02f0053
child 5214 d2ad737891b0
make the associate button use the user's settings for loading demos/saves
QTfrontend/game.cpp
QTfrontend/game.h
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/hwmap.cpp
QTfrontend/hwmap.h
QTfrontend/tcpBase.cpp
QTfrontend/tcpBase.h
--- a/QTfrontend/game.cpp	Mon May 16 22:04:59 2011 +0400
+++ b/QTfrontend/game.cpp	Tue May 17 19:05:13 2011 -0400
@@ -287,7 +287,7 @@
     }
 }
 
-QStringList HWGame::setArguments()
+QStringList HWGame::getArguments()
 {
     QStringList arguments;
     QRect resolution = config->vid_Resolution();
--- a/QTfrontend/game.h	Mon May 16 22:04:59 2011 +0400
+++ b/QTfrontend/game.h	Tue May 17 19:05:13 2011 -0400
@@ -59,7 +59,7 @@
     bool netSuspend;
 
  protected:
-    virtual QStringList setArguments();
+    virtual QStringList getArguments();
     virtual void onClientRead();
     virtual void onClientDisconnect();
 
--- a/QTfrontend/hwform.cpp	Mon May 16 22:04:59 2011 +0400
+++ b/QTfrontend/hwform.cpp	Tue May 17 19:05:13 2011 -0400
@@ -1210,10 +1210,29 @@
         ui.pageCampaign->CBSelect->addItem(QString(entries[i]).replace(QRegExp("^(\\d+)#(.+)\\.lua"), QComboBox::tr("Mission") + " \\1: \\2").replace("_", " "), QString(entries[i]).replace(QRegExp("^(.*)\\.lua"), "\\1"));
 }
 
+// used for --set-everything [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]
+QString HWForm::getDemoArguments()
+{
+    QRect resolution = config->vid_Resolution();
+    return QString(QString::number(resolution.width()) + " "
+     + QString::number(resolution.height()) + " "
+     + QString::number(config->bitDepth()) + " " // bpp
+     + QString::number(config->volume()) + " " // sound volume
+     + (config->isMusicEnabled() ? "1" : "0") + " "
+     + (config->isSoundEnabled() ? "1" : "0") + " "
+     + config->language() + ".txt "
+     + (config->vid_Fullscreen() ? "1" : "0") + " "
+     + (config->isShowFPSEnabled() ? "1" : "0") + " "
+     + (config->isAltDamageEnabled() ? "1" : "0") + " "
+     + QString::number(config->timerInterval()) + " "
+     + QString::number(config->translateQuality()));
+}
+
 void HWForm::AssociateFiles()
 {
     bool success = true;
 #ifdef _WIN32
+    QString arguments = getDemoArguments();
     QSettings registry_hkcr("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
     registry_hkcr.setValue(".hwd/Default", "Hedgewars.Demo");
     registry_hkcr.setValue(".hws/Default", "Hedgewars.Save");
@@ -1221,13 +1240,14 @@
     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\"");
+    registry_hkcr.setValue("Hedgewars.Demo/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"" + datadir->absolutePath().replace("/", "\\") + "\" \"%1\" --set-everything "+arguments);
+    registry_hkcr.setValue("Hedgewars.Save/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"" + datadir->absolutePath().replace("/", "\\") + "\" \"%1\" --set-everything "+arguments);
 #elif defined __APPLE__
     success = false;
     // TODO; also enable button in pages.cpp and signal in hwform.cpp
 #else
     // this is a little silly due to all the system commands below anyway - just use mkdir -p ?  Does have the advantage of the alert I guess
+    QString arguments = getDemoArguments();
     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local");
     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share");
     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share/mime");
@@ -1243,5 +1263,7 @@
 #endif
     if (success) QMessageBox::information(0, "", QMessageBox::tr("All file associations have been set."));
     else QMessageBox::information(0, "", QMessageBox::tr("File association failed."));
+//  hack to add user's settings to hwengine. might be better at this point to read in the file, append it, and write it out to its new home
+    if (success) success = system(("sed -i 's/^\\(Exec=.*\\)/\\1 --set-everything "+arguments+"/' "+QDir::home().absolutePath()+"/.local/share/applications/hwengine.desktop").toLocal8Bit().constData())==0;
 }
 
--- a/QTfrontend/hwform.h	Mon May 16 22:04:59 2011 +0400
+++ b/QTfrontend/hwform.h	Tue May 17 19:05:13 2011 -0400
@@ -71,6 +71,7 @@
     void GoToNewScheme();
     void GoToPage(int id);
     void GoBack();
+    QString getDemoArguments();
     void AssociateFiles();
     void btnExitPressed();
     void btnExitClicked();
--- a/QTfrontend/hwmap.cpp	Mon May 16 22:04:59 2011 +0400
+++ b/QTfrontend/hwmap.cpp	Tue May 17 19:05:13 2011 -0400
@@ -39,7 +39,7 @@
     Start();
 }
 
-QStringList HWMap::setArguments()
+QStringList HWMap::getArguments()
 {
     QStringList arguments;
     arguments << cfgdir->absolutePath();
--- a/QTfrontend/hwmap.h	Mon May 16 22:04:59 2011 +0400
+++ b/QTfrontend/hwmap.h	Tue May 17 19:05:13 2011 -0400
@@ -44,7 +44,7 @@
   void getImage(const QString & seed, int templateFilter, MapGenerator mapgen, int maze_size, const QByteArray & drawMapData);
 
  protected:
-  virtual QStringList setArguments();
+  virtual QStringList getArguments();
   virtual void onClientDisconnect();
   virtual void SendToClientFirst();
 
--- a/QTfrontend/tcpBase.cpp	Mon May 16 22:04:59 2011 +0400
+++ b/QTfrontend/tcpBase.cpp	Tue May 17 19:05:13 2011 -0400
@@ -72,7 +72,7 @@
   QProcess * process;
   process = new QProcess;
   connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(StartProcessError(QProcess::ProcessError)));
-  QStringList arguments=setArguments();
+  QStringList arguments=getArguments();
 
   // redirect everything written on stdout/stderr
   if(isDevBuild)
--- a/QTfrontend/tcpBase.h	Mon May 16 22:04:59 2011 +0400
+++ b/QTfrontend/tcpBase.h	Tue May 17 19:05:13 2011 -0400
@@ -57,7 +57,7 @@
   void SendIPC(const QByteArray & buf);
   void RawSendIPC(const QByteArray & buf);
 
-  virtual QStringList setArguments()=0;
+  virtual QStringList getArguments()=0;
   virtual void onClientRead();
   virtual void onClientDisconnect();
   virtual void SendToClientFirst();