Add option to allow real portable builds

master
Unknown 2019-03-24 08:30:40 +01:00
parent 328eef4673
commit 4ec78a2e48
6 changed files with 101 additions and 104 deletions

View File

@ -19,6 +19,8 @@ else()
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
option(BUILD_PORTABLE "To create a MinetestMapperGUI that uses only the current directory." OFF)
set(SOURCES
main.cpp
mainwindow.cpp
@ -104,6 +106,10 @@ endif()
target_compile_definitions(MinetestMapperGUI PRIVATE GIT_VERSION="${PROJECT_VERSION}")
if(BUILD_PORTABLE)
target_compile_definitions(MinetestMapperGUI PRIVATE PORTABLE)
endif(BUILD_PORTABLE)
if(WIN32)
# Get the location of the qmake exe
get_target_property(qmake_executable Qt5::qmake IMPORTED_LOCATION)

View File

@ -18,22 +18,7 @@ int main(int argc, char *argv[])
// Setup the translators
Translator t(QLocale::system());
// Init commandline parser
QCommandLineParser parser;
parser.setApplicationDescription("This program provides a graphical user interface for minetestmapper. \n"
"If you are looking for the command line interface of minetesmapper please execute minetestmapper directly.");
parser.addHelpOption();
parser.addVersionOption();
QCommandLineOption startPortableOption(QStringList() << "p" << "portable",
"Starts in portable mode which reads and writes settings and profiles relative to current directory");
parser.addOption(startPortableOption);
parser.process(a.arguments());
bool portable = parser.isSet(startPortableOption);
MainWindow w(portable, &t);
MainWindow w(&t);
w.show();
return a.exec();

View File

@ -8,28 +8,28 @@
#include <QStringList>
MainWindow::MainWindow(bool portable, Translator *translator, QWidget *parent) :
MainWindow::MainWindow(Translator *translator, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
translator(translator)
{
if(portable){
//Attention: This paths could be non writable locations!
pathAppData = qApp->applicationDirPath(); //use the Applications directory
pathProfiles = pathAppData + "/profiles/";
#ifdef PORTABLE
//Attention: This paths could be non writable locations!
pathAppData = qApp->applicationDirPath(); //use the Applications directory
pathProfiles = pathAppData + "/profiles/";
//manipulate settingsfile on portable mode
settings = new QSettings(pathAppData+"/MinetestMapperGui.ini",QSettings::IniFormat);
}
else{
QSettings dummySettings(QSettings::IniFormat, QSettings::UserScope,qApp->organizationName(),"dummy");
pathAppData = QFileInfo(dummySettings.fileName()).path();
pathProfiles = pathAppData + "/profiles/";
dummySettings.deleteLater();
//manipulate settingsfile on portable mode
settings = new QSettings(pathAppData + "/MinetestMapperGui.ini", QSettings::IniFormat);
#else
QSettings dummySettings(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), "dummy");
pathAppData = QFileInfo(dummySettings.fileName()).path();
pathProfiles = pathAppData + "/profiles/";
dummySettings.deleteLater();
//non portable use OS defaults
settings = new QSettings();
#endif // PORTABLE
//non portable use OS defaults
settings = new QSettings();
}
ui->setupUi(this);
finishUiInitialisation();
//profile = new ProfileSettings(ui, portable);
@ -560,12 +560,15 @@ void MainWindow::slotProfileChanged(QAction* action)
void MainWindow::writeSettings()
{
if(portable && !settings->isWritable()){
QMessageBox::warning(this, tr("Can not save settings"),
tr("Minetest Mapper GUI could not save the settings to %1.\n"
"Please make shure Minetest Mapper Gui can access to the file/directory").arg(settings->fileName()));
#ifdef PORTABLE
if (!settings->isWritable())
{
QMessageBox::warning(this, tr("Can not save settings"),
tr("Minetest Mapper GUI could not save the settings to %1.\n"
"Please make shure Minetest Mapper Gui can access to the file/directory").arg(settings->fileName()));
}
#endif // PORTABLE
}
settings->beginGroup("MainWindow");
if(isMaximized()){
settings->setValue("maximized", true);
@ -585,11 +588,15 @@ void MainWindow::writeSettings()
void MainWindow::writeProfile()
{
if(portable && !profile->isWritable()){
QMessageBox::warning(this, tr("Can not save profile"),
tr("Minetest Mapper GUI could not save the current Profile '%1' to %2.\n"
"Please make shure Minetest Mapper Gui can access to the file/directory").arg(currentProfile).arg(profile->fileName()));
}
#ifdef PORTABLE
if (!profile->isWritable())
{
QMessageBox::warning(this, tr("Can not save profile"),
tr("Minetest Mapper GUI could not save the current Profile '%1' to %2.\n"
"Please make shure Minetest Mapper Gui can access to the file/directory").arg(currentProfile).arg(profile->fileName()));
}
#endif // PORTABLE
qDebug()<<"Write profile" << currentProfile << "to" << profile->fileName();
profile->beginGroup("Mapper");

View File

@ -36,7 +36,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
explicit MainWindow(bool portable, Translator *translator, QWidget *parent = 0);
explicit MainWindow(Translator *translator, QWidget *parent = 0);
~MainWindow();
enum class GeometryGranularity {
@ -130,7 +130,6 @@ private slots:
void on_actionOpen_Terminal_triggered();
private:
bool portable;
Ui::MainWindow *ui;
QProgressBar *progressBar;
QProcess *myProcess;

View File

@ -1290,7 +1290,7 @@ Nodes higher than this level will not be drawn. This can be used to avoid floati
</message>
<message>
<location filename="../mainwindow.ui" line="2373"/>
<location filename="../mainwindow.cpp" line="999"/>
<location filename="../mainwindow.cpp" line="1006"/>
<source>Cancel</source>
<translation>Abbrechen</translation>
</message>
@ -1323,7 +1323,7 @@ Nodes higher than this level will not be drawn. This can be used to avoid floati
</message>
<message>
<location filename="../mainwindow.ui" line="2649"/>
<location filename="../mainwindow.cpp" line="841"/>
<location filename="../mainwindow.cpp" line="848"/>
<source>About MinetestMapper</source>
<translation>Über MinetestMapper</translation>
</message>
@ -1367,7 +1367,7 @@ Nodes higher than this level will not be drawn. This can be used to avoid floati
</message>
<message>
<location filename="../mainwindow.ui" line="2786"/>
<location filename="../mainwindow.cpp" line="863"/>
<location filename="../mainwindow.cpp" line="870"/>
<source>New Profile</source>
<translation>Neues Profil</translation>
</message>
@ -1397,7 +1397,7 @@ Nodes higher than this level will not be drawn. This can be used to avoid floati
</message>
<message>
<location filename="../mainwindow.ui" line="2745"/>
<location filename="../mainwindow.cpp" line="827"/>
<location filename="../mainwindow.cpp" line="834"/>
<source>About MinetestMapper GUI</source>
<translation>Über MinetestMapperGUI</translation>
</message>
@ -1544,92 +1544,92 @@ Bitte ein Ausgabebild wählen</translation>
<translation type="vanished">Konnte die Einstellungen nicht migrieren</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="564"/>
<location filename="../mainwindow.cpp" line="566"/>
<source>Can not save settings</source>
<translation>Kann die Einstellungen nicht speichern</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="565"/>
<location filename="../mainwindow.cpp" line="567"/>
<source>Minetest Mapper GUI could not save the settings to %1.
Please make shure Minetest Mapper Gui can access to the file/directory</source>
<translation>Minetest Mapper GUI konnte die Einstellungen nicht nach %1 speichern.
Bitte stelle sicher, dass Minetest Mapper GUI auf die Datei/ den Ordner zugreifen darf.</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="589"/>
<location filename="../mainwindow.cpp" line="594"/>
<source>Can not save profile</source>
<translation>Konnte das Profil nicht speichern</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="590"/>
<location filename="../mainwindow.cpp" line="595"/>
<source>Minetest Mapper GUI could not save the current Profile &apos;%1&apos; to %2.
Please make shure Minetest Mapper Gui can access to the file/directory</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="785"/>
<location filename="../mainwindow.cpp" line="792"/>
<source>Open Minetest World</source>
<translation>Minetest Welt-Ordner öffnen</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="795"/>
<location filename="../mainwindow.cpp" line="802"/>
<source>Save generated map to...</source>
<translation>Karte speichern nach...</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="795"/>
<location filename="../mainwindow.cpp" line="802"/>
<source>png image (*.png)</source>
<translation>png Grafik (*.png)</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="802"/>
<location filename="../mainwindow.cpp" line="809"/>
<source>Open HeightmapNodes File</source>
<translation>Öffne HeightmapNodes Datei</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="804"/>
<location filename="../mainwindow.cpp" line="812"/>
<location filename="../mainwindow.cpp" line="820"/>
<location filename="../mainwindow.cpp" line="811"/>
<location filename="../mainwindow.cpp" line="819"/>
<location filename="../mainwindow.cpp" line="827"/>
<source>TXT File (*.txt)</source>
<translation>TXT Datei (*.txt)</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="810"/>
<location filename="../mainwindow.cpp" line="817"/>
<source>Open HeightmapColors File</source>
<translation>Öffne Höhenkarte Farbdefinitionsdatei</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="818"/>
<location filename="../mainwindow.cpp" line="825"/>
<source>Open colors.txt File</source>
<translation>Öffne colors.txt Datei</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="828"/>
<location filename="../mainwindow.cpp" line="835"/>
<source>&lt;h1&gt;About MinetestMapperGUI&lt;/h1&gt;The &lt;b&gt;MinetestMapper Gui&lt;/b&gt; is written by addi.&lt;br /&gt;It is licensed under a &lt;a href=&quot;http://creativecommons.org/licenses/by/3.0/&quot;&gt;Creative Commons Attribution 3.0 Unported License&lt;/a&gt;.&lt;br&gt;The current version is %1. &lt;br&gt;The sourcecode is aviable on &lt;a href=&apos;https://bitbucket.org/adrido/minetestmappergui/&apos;&gt;Bitbucket&lt;/a&gt;.&lt;br&gt;You may also want to read the &lt;a href=&apos;https://forum.minetest.net/viewtopic.php?f=14&amp;t=12139&apos;&gt;Minetest forum thread&lt;/a&gt;.&lt;br&gt;&lt;br&gt;&lt;b&gt;Thanks to:&lt;/b&gt;&lt;br&gt;McKrustenkaese for his great icon</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="842"/>
<location filename="../mainwindow.cpp" line="849"/>
<source>&lt;h1&gt;About MinetestMapper&lt;/h1&gt;The &lt;b&gt;MinetestMapper&lt;/b&gt; is written by:&lt;br&gt;Miroslav Bendík &lt;miroslav.bendik@gmail.com&gt;&lt;br&gt;ShadowNinja &lt;shadowninja@minetest.net&gt;&lt;br&gt;sfan5 &lt;sfan5@live.de&gt;&lt;br&gt;Rogier &lt;rogier777@gmail.com&gt;&lt;br&gt;&lt;br&gt;&lt;u&gt;Version:&lt;/u&gt; %1 (%2)&lt;br&gt;&lt;u&gt;License:&lt;/u&gt; LGPLv2.1+ and BSD 2-clause.&lt;br&gt;&lt;u&gt;Source Code:&lt;/u&gt; &lt;a href=&apos;https://github.com/Rogier-5/minetest-mapper-cpp&apos;&gt;Github&lt;/a&gt;&lt;br&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="923"/>
<location filename="../mainwindow.cpp" line="930"/>
<source>map center</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="928"/>
<location filename="../mainwindow.cpp" line="935"/>
<source>map origin (top left)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="978"/>
<location filename="../mainwindow.cpp" line="985"/>
<source>Create a colors.txt</source>
<translation>Erstelle eine colors.txt Datei</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="979"/>
<location filename="../mainwindow.cpp" line="986"/>
<source>There is a nodes.txt but no colors.txt in the world directory
Do you want to generate one?
If you select &apos;No&apos; the default colors.txt will be used.</source>
@ -1638,29 +1638,29 @@ Möchtest du eine erstellen?
Wenn du auf &apos;Nein&apos; clickst, wird eine standard colors.txt Datei verwendet.</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="996"/>
<location filename="../mainwindow.cpp" line="1003"/>
<source>No colors.txt file</source>
<translation>Keine colors.txt Datei</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="997"/>
<location filename="../mainwindow.cpp" line="1004"/>
<source>ERROR: Still no colors.txt file found inside world directory.
Do you want to cancel or proceed with default colors.txt file?</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="1000"/>
<location filename="../mainwindow.cpp" line="1007"/>
<source>Proceed with default</source>
<translation>Mit standard Datei fortfahren</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="1072"/>
<location filename="../mainwindow.cpp" line="1079"/>
<source>Could not open Terminal</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="1073"/>
<location filename="../mainwindow.cpp" line="1080"/>
<source>Error: Could not open scriptfile (%1) for Terminal</source>
<translation type="unfinished"></translation>
</message>
@ -1695,12 +1695,12 @@ Bitte erneut eine gültige minetestmapper Anwendung auswählen. (Bearbeiten-&gt;
Möchten Sie die Einstellungen jetzt öffnen? </translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="856"/>
<location filename="../mainwindow.cpp" line="863"/>
<source>preview: %1</source>
<translation>Vorschau: %1</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="864"/>
<location filename="../mainwindow.cpp" line="871"/>
<source>Name of the new Profile:</source>
<translation>Name des Neuen Profils:</translation>
</message>

View File

@ -978,7 +978,7 @@ Nodes higher than this level will not be drawn. This can be used to avoid floati
</message>
<message>
<location filename="../mainwindow.ui" line="2373"/>
<location filename="../mainwindow.cpp" line="999"/>
<location filename="../mainwindow.cpp" line="1006"/>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
@ -1036,7 +1036,7 @@ Nodes higher than this level will not be drawn. This can be used to avoid floati
</message>
<message>
<location filename="../mainwindow.ui" line="2649"/>
<location filename="../mainwindow.cpp" line="841"/>
<location filename="../mainwindow.cpp" line="848"/>
<source>About MinetestMapper</source>
<translation type="unfinished"></translation>
</message>
@ -1072,7 +1072,7 @@ Nodes higher than this level will not be drawn. This can be used to avoid floati
</message>
<message>
<location filename="../mainwindow.ui" line="2745"/>
<location filename="../mainwindow.cpp" line="827"/>
<location filename="../mainwindow.cpp" line="834"/>
<source>About MinetestMapper GUI</source>
<translation type="unfinished"></translation>
</message>
@ -1123,7 +1123,7 @@ Nodes higher than this level will not be drawn. This can be used to avoid floati
</message>
<message>
<location filename="../mainwindow.ui" line="2786"/>
<location filename="../mainwindow.cpp" line="863"/>
<location filename="../mainwindow.cpp" line="870"/>
<source>New Profile</source>
<translation type="unfinished"></translation>
</message>
@ -1277,130 +1277,130 @@ Please select a output image</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="564"/>
<location filename="../mainwindow.cpp" line="566"/>
<source>Can not save settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="565"/>
<location filename="../mainwindow.cpp" line="567"/>
<source>Minetest Mapper GUI could not save the settings to %1.
Please make shure Minetest Mapper Gui can access to the file/directory</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="589"/>
<location filename="../mainwindow.cpp" line="594"/>
<source>Can not save profile</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="590"/>
<location filename="../mainwindow.cpp" line="595"/>
<source>Minetest Mapper GUI could not save the current Profile &apos;%1&apos; to %2.
Please make shure Minetest Mapper Gui can access to the file/directory</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="785"/>
<location filename="../mainwindow.cpp" line="792"/>
<source>Open Minetest World</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="795"/>
<location filename="../mainwindow.cpp" line="802"/>
<source>Save generated map to...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="795"/>
<location filename="../mainwindow.cpp" line="802"/>
<source>png image (*.png)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="802"/>
<location filename="../mainwindow.cpp" line="809"/>
<source>Open HeightmapNodes File</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="804"/>
<location filename="../mainwindow.cpp" line="812"/>
<location filename="../mainwindow.cpp" line="820"/>
<location filename="../mainwindow.cpp" line="811"/>
<location filename="../mainwindow.cpp" line="819"/>
<location filename="../mainwindow.cpp" line="827"/>
<source>TXT File (*.txt)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="810"/>
<location filename="../mainwindow.cpp" line="817"/>
<source>Open HeightmapColors File</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="818"/>
<location filename="../mainwindow.cpp" line="825"/>
<source>Open colors.txt File</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="828"/>
<location filename="../mainwindow.cpp" line="835"/>
<source>&lt;h1&gt;About MinetestMapperGUI&lt;/h1&gt;The &lt;b&gt;MinetestMapper Gui&lt;/b&gt; is written by addi.&lt;br /&gt;It is licensed under a &lt;a href=&quot;http://creativecommons.org/licenses/by/3.0/&quot;&gt;Creative Commons Attribution 3.0 Unported License&lt;/a&gt;.&lt;br&gt;The current version is %1. &lt;br&gt;The sourcecode is aviable on &lt;a href=&apos;https://bitbucket.org/adrido/minetestmappergui/&apos;&gt;Bitbucket&lt;/a&gt;.&lt;br&gt;You may also want to read the &lt;a href=&apos;https://forum.minetest.net/viewtopic.php?f=14&amp;t=12139&apos;&gt;Minetest forum thread&lt;/a&gt;.&lt;br&gt;&lt;br&gt;&lt;b&gt;Thanks to:&lt;/b&gt;&lt;br&gt;McKrustenkaese for his great icon</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="842"/>
<location filename="../mainwindow.cpp" line="849"/>
<source>&lt;h1&gt;About MinetestMapper&lt;/h1&gt;The &lt;b&gt;MinetestMapper&lt;/b&gt; is written by:&lt;br&gt;Miroslav Bendík &lt;miroslav.bendik@gmail.com&gt;&lt;br&gt;ShadowNinja &lt;shadowninja@minetest.net&gt;&lt;br&gt;sfan5 &lt;sfan5@live.de&gt;&lt;br&gt;Rogier &lt;rogier777@gmail.com&gt;&lt;br&gt;&lt;br&gt;&lt;u&gt;Version:&lt;/u&gt; %1 (%2)&lt;br&gt;&lt;u&gt;License:&lt;/u&gt; LGPLv2.1+ and BSD 2-clause.&lt;br&gt;&lt;u&gt;Source Code:&lt;/u&gt; &lt;a href=&apos;https://github.com/Rogier-5/minetest-mapper-cpp&apos;&gt;Github&lt;/a&gt;&lt;br&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="923"/>
<location filename="../mainwindow.cpp" line="930"/>
<source>map center</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="928"/>
<location filename="../mainwindow.cpp" line="935"/>
<source>map origin (top left)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="978"/>
<location filename="../mainwindow.cpp" line="985"/>
<source>Create a colors.txt</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="979"/>
<location filename="../mainwindow.cpp" line="986"/>
<source>There is a nodes.txt but no colors.txt in the world directory
Do you want to generate one?
If you select &apos;No&apos; the default colors.txt will be used.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="996"/>
<location filename="../mainwindow.cpp" line="1003"/>
<source>No colors.txt file</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="997"/>
<location filename="../mainwindow.cpp" line="1004"/>
<source>ERROR: Still no colors.txt file found inside world directory.
Do you want to cancel or proceed with default colors.txt file?</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="1000"/>
<location filename="../mainwindow.cpp" line="1007"/>
<source>Proceed with default</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="1072"/>
<location filename="../mainwindow.cpp" line="1079"/>
<source>Could not open Terminal</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="1073"/>
<location filename="../mainwindow.cpp" line="1080"/>
<source>Error: Could not open scriptfile (%1) for Terminal</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="856"/>
<location filename="../mainwindow.cpp" line="863"/>
<source>preview: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="864"/>
<location filename="../mainwindow.cpp" line="871"/>
<source>Name of the new Profile:</source>
<translation type="unfinished"></translation>
</message>