Improve OS detection and add APPIMAGE support to pathing code (#1003)
* Added get_app_path, tweaked pathing to adjust itself for Linux, ... * Added get_app_path * This should be used instead of QCoreApplication::applicationDirPath() * Tweaked pathing to adjust itself for Linux * Append separator to base path * Moved headers where they are needed. (Dunno why they were here.) * Proper pathing for AppImage
This commit is contained in:
		
							parent
							
								
									a1e13f62fd
								
							
						
					
					
						commit
						03025119c4
					
				@ -1,5 +1,9 @@
 | 
				
			|||||||
#include "file_functions.h"
 | 
					#include "file_functions.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <QCoreApplication>
 | 
				
			||||||
 | 
					#include <QDir>
 | 
				
			||||||
 | 
					#include <QFileInfo>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool file_exists(QString file_path)
 | 
					bool file_exists(QString file_path)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  if (file_path.isEmpty())
 | 
					  if (file_path.isEmpty())
 | 
				
			||||||
@ -31,24 +35,47 @@ bool exists(QString p_path)
 | 
				
			|||||||
  return file.exists();
 | 
					  return file.exists();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QString get_base_path()
 | 
					QString get_app_path()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  QString base_path;
 | 
					  QString path = QCoreApplication::applicationDirPath();
 | 
				
			||||||
#ifdef ANDROID
 | 
					
 | 
				
			||||||
  QString sdcard_storage = getenv("SECONDARY_STORAGE");
 | 
					#ifdef Q_OS_ANDROID
 | 
				
			||||||
  if (dir_exists(sdcard_storage + "/base/"))
 | 
					  QString storage_path = qgetenv("SECONDARY_STORAGE");
 | 
				
			||||||
 | 
					  if (dir_exists(storage_path))
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    base_path = sdcard_storage + "/base/";
 | 
					    path = storage_path;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  else
 | 
					  else
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    QString external_storage = getenv("EXTERNAL_STORAGE");
 | 
					    QString external_path = qgetenv("EXTERNAL_STORAGE");
 | 
				
			||||||
    base_path = external_storage + "/base/";
 | 
					    if (dir_exists(external_path))
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      path = external_path;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
#elif defined(__APPLE__)
 | 
					 | 
				
			||||||
  base_path = QCoreApplication::applicationDirPath() + "/../../../base/";
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
  base_path = QCoreApplication::applicationDirPath() + "/base/";
 | 
					 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
  return base_path;
 | 
					
 | 
				
			||||||
 | 
					#ifdef Q_OS_LINUX
 | 
				
			||||||
 | 
					  QString app_path = qgetenv("APPIMAGE");
 | 
				
			||||||
 | 
					  if (!app_path.isEmpty())
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    path = QFileInfo(app_path).absoluteDir().path();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef Q_OS_MAC
 | 
				
			||||||
 | 
					  path += "/../../..";
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (path.endsWith(QDir::separator()))
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    path.chop(1);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return path;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QString get_base_path()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  return QDir(get_app_path()).absoluteFilePath("base") + "/";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,11 +1,10 @@
 | 
				
			|||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QCoreApplication>
 | 
					 | 
				
			||||||
#include <QDir>
 | 
					 | 
				
			||||||
#include <QFileInfo>
 | 
					 | 
				
			||||||
#include <QString>
 | 
					#include <QString>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool file_exists(QString file_path);
 | 
					bool file_exists(QString file_path);
 | 
				
			||||||
bool dir_exists(QString file_path);
 | 
					bool dir_exists(QString file_path);
 | 
				
			||||||
bool exists(QString p_path);
 | 
					bool exists(QString p_path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QString get_app_path();
 | 
				
			||||||
QString get_base_path();
 | 
					QString get_base_path();
 | 
				
			||||||
 | 
				
			|||||||
@ -425,7 +425,7 @@ void Lobby::on_demo_clicked(QTreeWidgetItem *item, int column)
 | 
				
			|||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  QString l_filepath = (QApplication::applicationDirPath() + "/logs/%1/%2").arg(item->data(0, Qt::DisplayRole).toString(), item->data(1, Qt::DisplayRole).toString());
 | 
					  QString l_filepath = (get_app_path() + "/logs/%1/%2").arg(item->data(0, Qt::DisplayRole).toString(), item->data(1, Qt::DisplayRole).toString());
 | 
				
			||||||
  ao_app->demo_server->start_server();
 | 
					  ao_app->demo_server->start_server();
 | 
				
			||||||
  ServerInfo demo_server;
 | 
					  ServerInfo demo_server;
 | 
				
			||||||
  demo_server.ip = "127.0.0.1";
 | 
					  demo_server.ip = "127.0.0.1";
 | 
				
			||||||
 | 
				
			|||||||
@ -133,7 +133,7 @@ bool AOApplication::append_to_file(QString p_text, QString p_file, bool make_dir
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
QMultiMap<QString, QString> AOApplication::load_demo_logs_list() const
 | 
					QMultiMap<QString, QString> AOApplication::load_demo_logs_list() const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  QString l_log_path = applicationDirPath() + "/logs/";
 | 
					  QString l_log_path = get_app_path() + "/logs/";
 | 
				
			||||||
  QDir l_log_folder(l_log_path);
 | 
					  QDir l_log_folder(l_log_path);
 | 
				
			||||||
  l_log_folder.setFilter(QDir::NoDotAndDotDot | QDir::Dirs);
 | 
					  l_log_folder.setFilter(QDir::NoDotAndDotDot | QDir::Dirs);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -436,12 +436,12 @@ void AOOptionsDialog::setupUI()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  FROM_UI(QPushButton, mount_add);
 | 
					  FROM_UI(QPushButton, mount_add);
 | 
				
			||||||
  connect(ui_mount_add, &QPushButton::clicked, this, [this] {
 | 
					  connect(ui_mount_add, &QPushButton::clicked, this, [this] {
 | 
				
			||||||
    QString path = QFileDialog::getExistingDirectory(this, tr("Select a base folder"), QApplication::applicationDirPath(), QFileDialog::ShowDirsOnly);
 | 
					    QString path = QFileDialog::getExistingDirectory(this, tr("Select a base folder"), get_app_path(), QFileDialog::ShowDirsOnly);
 | 
				
			||||||
    if (path.isEmpty())
 | 
					    if (path.isEmpty())
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    QDir dir(QApplication::applicationDirPath());
 | 
					    QDir dir(get_app_path());
 | 
				
			||||||
    QString relative = dir.relativeFilePath(path);
 | 
					    QString relative = dir.relativeFilePath(path);
 | 
				
			||||||
    if (!relative.contains("../"))
 | 
					    if (!relative.contains("../"))
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user