mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
Support for XCA as portable App
On Windows XCA goes in portable mode if no XCA registry entry is found. On Mac and Unix it checks the XCA_PORTABLE environment to be non-empty. In portable mode: - The current working directory is not written to the database - The configured language and history of opened databases is forgotten after a restart of XCA - No registry entry is required nor written. - No unexpected files are written to disk, except exported items. - Portable mode is displayed in the "About" dialog If setup.exe or "make install" are not used, - XCA is not assigned as app for any file types
This commit is contained in:
parent
6f8ca8dd65
commit
00bd36f19b
22
lib/func.cpp
22
lib/func.cpp
@ -51,7 +51,7 @@ QPixmap *loadImg(const char *name )
|
||||
QStringList getLibExtensions()
|
||||
{
|
||||
QStringList l;
|
||||
#if defined(_WIN32) || defined(USE_CYGWIN)
|
||||
#if defined(Q_OS_WIN32)
|
||||
l << QString("*.dll") << QString("*.DLL");
|
||||
#elif defined(Q_OS_MAC)
|
||||
l << QString("*.dylib") << QString("*.so");
|
||||
@ -61,6 +61,22 @@ QStringList getLibExtensions()
|
||||
return l;
|
||||
}
|
||||
|
||||
int portable_app()
|
||||
{
|
||||
static int portable = -1;
|
||||
if (portable == -1) {
|
||||
#if defined(Q_OS_WIN32)
|
||||
HKEY hKey;
|
||||
portable = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\xca",
|
||||
0, KEY_READ, &hKey) != ERROR_SUCCESS;
|
||||
#else
|
||||
const char *p = getenv("XCA_PORTABLE");
|
||||
portable = p && *p;
|
||||
#endif
|
||||
}
|
||||
return portable;
|
||||
}
|
||||
|
||||
/* returns e.g. /usr/local/share/xca for unix systems
|
||||
* or HKEY_LOCAL_MACHINE->Software->xca for WIN32
|
||||
* (e.g. c:\Program Files\xca )
|
||||
@ -86,6 +102,8 @@ QString getPrefix()
|
||||
*p = '\0';
|
||||
return QString(inst_dir);
|
||||
}
|
||||
if (portable_app())
|
||||
return QString(inst_dir);
|
||||
p = inst_dir;
|
||||
*p = '\0';
|
||||
lRc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\xca", 0, KEY_READ, &hKey);
|
||||
@ -150,7 +168,7 @@ QString getLibDir()
|
||||
|
||||
QString getDocDir()
|
||||
{
|
||||
#if defined(WIN32) || defined (Q_OS_MAC)
|
||||
#if defined(Q_OS_WIN32) || defined (Q_OS_MAC)
|
||||
return getPrefix();
|
||||
#else
|
||||
return QString(DOCDIR);
|
||||
|
||||
@ -21,6 +21,7 @@ class Validity;
|
||||
extern QString currentDB;
|
||||
|
||||
QPixmap *loadImg(const char *name);
|
||||
int portable_app();
|
||||
QString getPrefix();
|
||||
QString getHomeDir();
|
||||
QString getLibDir();
|
||||
|
||||
@ -135,6 +135,9 @@ void XCA_application::switchLanguage(QAction* a)
|
||||
QLocale lang = a->data().toLocale();
|
||||
setupLanguage(lang);
|
||||
|
||||
if (portable_app())
|
||||
return;
|
||||
|
||||
QFile file(defaultlang());
|
||||
|
||||
if (lang == QLocale::system()) {
|
||||
|
||||
@ -462,7 +462,7 @@ void pki_temp::fload(QString fname)
|
||||
try {
|
||||
try_fload(fname, "rb");
|
||||
} catch (errorEx &err) {
|
||||
#if defined(_WIN32)
|
||||
#if defined(Q_OS_WIN32)
|
||||
/* Try again in ascii mode on Windows
|
||||
* to support pre 1.1.0 template exports */
|
||||
try_fload(fname, "r");
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include "widgets/hashBox.h"
|
||||
#include "widgets/NewKey.h"
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
settings Settings;
|
||||
@ -69,6 +70,9 @@ void settings::setAction(const QString &key, const QString &value)
|
||||
}
|
||||
TransCommit();
|
||||
return;
|
||||
} else if (key == "workingdir") {
|
||||
if (!QFile::exists(value))
|
||||
return;
|
||||
}
|
||||
values[key] = value;
|
||||
}
|
||||
@ -103,9 +107,11 @@ void settings::set(QString key, QString value)
|
||||
XSqlQuery q;
|
||||
load_settings();
|
||||
|
||||
if (key == "workingdir")
|
||||
if (key == "workingdir") {
|
||||
if (portable_app())
|
||||
return;
|
||||
value = QDir::toNativeSeparators(value);
|
||||
|
||||
}
|
||||
if (db_keys.contains(key) && values[key] == value)
|
||||
return;
|
||||
|
||||
|
||||
@ -422,6 +422,9 @@ int MainWindow::open_default_db()
|
||||
|
||||
void MainWindow::default_database()
|
||||
{
|
||||
if (portable_app())
|
||||
return;
|
||||
|
||||
QFile file(defaultdb());
|
||||
QFileInfo fi(currentDB);
|
||||
|
||||
@ -558,6 +561,11 @@ void MainWindow::update_history(QString fname)
|
||||
while (history.size() > 10)
|
||||
history.removeLast();
|
||||
|
||||
update_history_menu();
|
||||
|
||||
if (portable_app())
|
||||
return;
|
||||
|
||||
file.setFileName(dbhistory());
|
||||
if (!file.open(QIODevice::ReadWrite))
|
||||
return;
|
||||
@ -569,5 +577,4 @@ void MainWindow::update_history(QString fname)
|
||||
break;
|
||||
}
|
||||
file.close();
|
||||
update_history_menu();
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ void MainWindow::about()
|
||||
}
|
||||
Entropy::seed_rng();
|
||||
cont = QString(
|
||||
"<p><h3><center><u>XCA</u></center></h3>"
|
||||
"<p><h3><center><u>XCA%8</u></center></h3>"
|
||||
"<p>Copyright 2001 - 2018 by Christian Hohnstädt\n"
|
||||
"<p>Version: %4<p>%1<p>%2" /* commithash, Brainpool, OpenSSL & Qt Version */
|
||||
"<p>http://hohnstaedt.de/xca"
|
||||
@ -106,12 +106,13 @@ void MainWindow::about()
|
||||
"<tr><td><b>Croatian</b></td><td>Nevenko Bartolincic <nevenko.bartolincic@gmail.com></td></tr>"
|
||||
"<tr><td><b>Slovak</b></td><td>Slavko <linux@slavino.sk></td></tr>"
|
||||
"<tr><td><b>Polish</b></td><td>Jacek Tyborowski <jacek@tyborowski.pl></td></tr>"
|
||||
"<tr><td><b>Portugese (Brazil)</b></td><td>Vinicius Ocker <viniciusockerfagundes@yandex.com></td></tr>"
|
||||
"<tr><td><b>Portuguese (Brazil)</b></td><td>Vinicius Ocker <viniciusockerfagundes@yandex.com></td></tr>"
|
||||
"<tr><td><b>Spanish</b></td><td>Miguel Romera <mrmsoftdonation@gmail.com></td></tr>"
|
||||
"</table>").arg(brainpool).arg(version).arg(Entropy::strength())
|
||||
.arg(version_str(true)).arg(getPrefix())
|
||||
.arg(getUserSettingsDir())
|
||||
.arg(QString(Settings["workingdir"]));
|
||||
.arg(QString(Settings["workingdir"]))
|
||||
.arg(portable_app() ? " (Portable)" : "");
|
||||
|
||||
textbox->setHtml(cont);
|
||||
textbox->setReadOnly(true);
|
||||
|
||||
@ -101,8 +101,10 @@ void MainWindow::init_menu()
|
||||
this, SLOT(openRemoteSqlDB()))
|
||||
->setEnabled(OpenDb::hasRemoteDrivers());
|
||||
file->addMenu(historyMenu);
|
||||
file->addAction(tr("Set as default DataBase"), this,
|
||||
if (!portable_app()) {
|
||||
file->addAction(tr("Set as default DataBase"), this,
|
||||
SLOT(default_database()));
|
||||
}
|
||||
acList += file->addAction(tr("&Close DataBase"), this,
|
||||
SLOT(close_database()), QKeySequence(QKeySequence::Close));
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user