Skip to content

Commit

Permalink
Fixup for #548: fix detection of portable app
Browse files Browse the repository at this point in the history
Don't call getHomeDir() in global constructor before main()
  • Loading branch information
chris2511 committed Sep 8, 2024
1 parent d256da3 commit 418b78c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
1 change: 1 addition & 0 deletions lib/func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ static QString registryInstallDir()
int portable_app()
{
static int portable = -1;
qDebug() << "portable" << portable;
QString f1, f2;
if (portable == -1) {
#if defined(Q_OS_WIN32)
Expand Down
45 changes: 26 additions & 19 deletions lib/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ QString svalue::get() const
{
return setting ? setting->get(key) : QString();
}

void svalue::set(const QString &val)
{
if (setting)
Expand All @@ -36,31 +37,37 @@ void svalue::set(const QString &val)

settings::settings()
{
defaul["mandatory_dn"] = "";
defaul["explicit_dn"] = "C,ST,L,O,OU,CN,emailAddress";
defaul["string_opt"] = "MASK:0x2002";
defaul["workingdir"] = getHomeDir() + "/";
defaul["default_hash"] = digest::getDefault().name();
defaul["pkcs12_enc_algo"] = encAlgo::getDefault().name();
defaul["ical_expiry"] = "1W";
defaul["cert_expiry"] = "80%";
defaul["serial_len"] = "64";
defaul["fp_separator"] = ":";
defaul["fp_digits"] = "2";
defaul["hide_unusable"] = "no";
defaul["KeyFormat"] = QString::number(DEFAULT_KEY_CLIPBOARD_TYPE);
defaul["CertFormat"] = QString::number(DEFAULT_CERT_CLIPBOARD_TYPE);

hostspecific << "pkcs11path" << "workingdir" << "mw_geometry";
hostspecific = QStringList({ "pkcs11path", "workingdir", "mw_geometry" });
}

const QMap<QString, QString> settings::defaults() const
{
return QMap<QString, QString> {
{ "mandatory_dn", "" },
{ "explicit_dn", "C,ST,L,O,OU,CN,emailAddress" },
{ "string_opt", "MASK:0x2002" },
{ "workingdir", getHomeDir() + "/" },
{ "default_hash", digest::getDefault().name() },
{ "pkcs12_enc_algo", encAlgo::getDefault().name() },
{ "ical_expiry", "1W" },
{ "cert_expiry", "80%" },
{ "serial_len", "64" },
{ "fp_separator", ":" },
{ "fp_digits", "2" },
{ "hide_unusable", "no" },
{ "KeyFormat", QString::number(DEFAULT_KEY_CLIPBOARD_TYPE) },
{ "CertFormat", QString::number(DEFAULT_CERT_CLIPBOARD_TYPE) },
};
}

void settings::clear()
{
loaded = false;
values.clear();
db_keys.clear();
foreach(QString key, defaul.keys())
setAction(key, defaul[key]);
const QMap<QString, QString> def = defaults();
for(QString key : def.keys())
setAction(key, def[key]);
}

void settings::setAction(const QString &key, const QString &value)
Expand Down Expand Up @@ -93,7 +100,7 @@ void settings::setAction(const QString &key, const QString &value)

QString settings::defaults(const QString &key)
{
return defaul[key];
return defaults()[key];
}

void settings::load_settings()
Expand Down
2 changes: 1 addition & 1 deletion lib/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ class settings
bool loaded{};
QStringList db_keys{}, hostspecific{};
QMap<QString, QString> values{};
QMap<QString, QString> defaul{};
void load_settings();
QString get(QString key);
void set(QString key, QString value);
void setAction(const QString &key, const QString &value);
const QMap<QString, QString> defaults() const;

public:
settings();
Expand Down

0 comments on commit 418b78c

Please sign in to comment.