mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
Refactor native separators / and \ on windows.
Always only use forward slash / Drop all "QDir::separator()" and "nativeSeparator()" functions. Only use it where filenames are displayed for the user.
This commit is contained in:
parent
66a85497b7
commit
b41d322069
@ -14,6 +14,7 @@
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QMimeData>
|
||||
#include <QFileInfo>
|
||||
#include "widgets/MainWindow.h"
|
||||
#include "widgets/ImportMulti.h"
|
||||
#include "widgets/XcaDialog.h"
|
||||
@ -385,11 +386,11 @@ pki_base *db_base::insert(pki_base *item)
|
||||
|
||||
void db_base::dump(const QString &dir) const
|
||||
{
|
||||
QString dirname = dir + QDir::separator() + class_name;
|
||||
QString dirname = dir + "/" + class_name;
|
||||
QDir d(dirname);
|
||||
if (!d.exists() && !d.mkdir(dirname)) {
|
||||
throw errorEx(tr("Could not create directory %1")
|
||||
.arg(dirname));
|
||||
.arg(nativeSeparator(dirname)));
|
||||
}
|
||||
|
||||
try {
|
||||
@ -654,8 +655,7 @@ void db_base::load_default(load_base &load)
|
||||
if (!slist.count())
|
||||
return;
|
||||
|
||||
QString fn = slist[0];
|
||||
Settings["workingdir"] = fn.mid(0, fn.lastIndexOf("/"));
|
||||
update_workingdir(slist[0]);
|
||||
|
||||
ImportMulti *dlgi = new ImportMulti(mainwin);
|
||||
foreach(s, slist) {
|
||||
@ -691,14 +691,14 @@ void db_base::store(QModelIndexList indexes)
|
||||
return;
|
||||
}
|
||||
|
||||
QString fn = Settings["workingdir"] + QDir::separator() + "export.pem";
|
||||
QString s = QFileDialog::getSaveFileName(mainwin,
|
||||
tr("Save %1 items in one file as").arg(indexes.size()), fn,
|
||||
tr("Save %1 items in one file as").arg(indexes.size()),
|
||||
Settings["workingdir"] + "export.pem",
|
||||
tr("PEM files ( *.pem );; All files ( * )"));
|
||||
if (s.isEmpty())
|
||||
return;
|
||||
s = nativeSeparator(s);
|
||||
Settings["workingdir"] = s.mid(0, s.lastIndexOf(QRegExp("[/\\\\]")));
|
||||
|
||||
update_workingdir(s);
|
||||
try {
|
||||
QString pem = pem2QString(indexes);
|
||||
XFile file(s);
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
#include <QAction>
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QFileInfo>
|
||||
|
||||
db_temp::db_temp(MainWindow *mw)
|
||||
:db_x509name(mw)
|
||||
@ -40,8 +41,7 @@ db_temp::db_temp(MainWindow *mw)
|
||||
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
QFileInfo fileInfo = list.at(i);
|
||||
QString name = getPrefix() + QDir::separator() +
|
||||
fileInfo.fileName();
|
||||
QString name = getPrefix() + "/" + fileInfo.fileName();
|
||||
if (!name.endsWith(".xca", Qt::CaseInsensitive))
|
||||
continue;
|
||||
try {
|
||||
@ -51,7 +51,8 @@ db_temp::db_temp(MainWindow *mw)
|
||||
predefs << tmpl;
|
||||
}
|
||||
} catch(errorEx &err) {
|
||||
XCA_WARN(tr("Bad template: %1").arg(name));
|
||||
XCA_WARN(tr("Bad template: %1")
|
||||
.arg(nativeSeparator(name)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -130,15 +131,15 @@ void db_temp::store(QModelIndex index)
|
||||
|
||||
pki_temp *temp = static_cast<pki_temp*>(index.internalPointer());
|
||||
|
||||
QString fn = Settings["workingdir"] + QDir::separator() +
|
||||
QString fn = Settings["workingdir"] +
|
||||
temp->getUnderlinedName() + ".xca";
|
||||
QString s = QFileDialog::getSaveFileName(mainwin,
|
||||
tr("Save template as"), fn,
|
||||
tr("XCA templates ( *.xca );; All files ( * )"));
|
||||
if (s.isEmpty())
|
||||
return;
|
||||
s = nativeSeparator(s);
|
||||
Settings["workingdir"] = s.mid(0, s.lastIndexOf(QRegExp("[/\\\\]")));
|
||||
|
||||
update_workingdir(s);
|
||||
try {
|
||||
XFile file(s);
|
||||
file.open_key();
|
||||
|
||||
@ -287,7 +287,6 @@ void db_x509::writeIndex(const QString &fname, bool hierarchy) const
|
||||
{
|
||||
if (hierarchy) {
|
||||
QString dir = fname + "/";
|
||||
dir = nativeSeparator(dir);
|
||||
QList<pki_x509*> issuers = sqlSELECTpki<pki_x509>(
|
||||
"SELECT DISTINCT issuer FROM certs WHERE issuer != item");
|
||||
foreach(pki_x509 *ca, issuers) {
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#include "widgets/XcaDialog.h"
|
||||
#include "oid.h"
|
||||
#include <QMessageBox>
|
||||
#include <QFileInfo>
|
||||
|
||||
db_x509name::db_x509name(MainWindow *mw)
|
||||
:db_base(mw)
|
||||
@ -151,15 +152,14 @@ void db_x509super::extractPubkey(QModelIndex index)
|
||||
void db_x509super::toOpenssl(QModelIndex index) const
|
||||
{
|
||||
pki_x509super *pki = static_cast<pki_x509super*>(index.internalPointer());
|
||||
QString fn = Settings["workingdir"] + QDir::separator() +
|
||||
pki->getUnderlinedName() + ".conf";
|
||||
QString fn = Settings["workingdir"] + pki->getUnderlinedName() + ".conf";
|
||||
QString fname = QFileDialog::getSaveFileName(mainwin,
|
||||
tr("Save as OpenSSL config"), fn,
|
||||
tr("Config files ( *.conf *.cnf);; All files ( * )"));
|
||||
if (fname.isEmpty())
|
||||
return;
|
||||
fname = nativeSeparator(fname);
|
||||
Settings["workingdir"] = fname.mid(0, fname.lastIndexOf(QRegExp("[/\\\\]")));
|
||||
|
||||
update_workingdir(fname);
|
||||
pki->opensslConf(fname);
|
||||
}
|
||||
|
||||
|
||||
@ -157,7 +157,7 @@ Entropy::Entropy()
|
||||
{
|
||||
timer.start();
|
||||
|
||||
rnd = getUserSettingsDir() + QDir::separator() + ".rnd";
|
||||
rnd = getUserSettingsDir() + "/.rnd";
|
||||
random_from_file(rnd, 1024, 128);
|
||||
QFile::remove(rnd); // don't use it again
|
||||
|
||||
|
||||
21
lib/func.cpp
21
lib/func.cpp
@ -78,7 +78,7 @@ static QString xcaExeDir()
|
||||
int bslash = dir.lastIndexOf("\\");
|
||||
if (bslash > 0)
|
||||
dir = dir.mid(0, bslash);
|
||||
return QDir::toNativeSeparators(QFileInfo(dir).canonicalFilePath());
|
||||
return QFileInfo(dir).canonicalFilePath();
|
||||
}
|
||||
|
||||
static QString registryInstallDir()
|
||||
@ -96,7 +96,7 @@ static QString registryInstallDir()
|
||||
len /= sizeof inst_dir[0];
|
||||
/* "len" includes the trailing \0\0 */
|
||||
dir = QString::fromWCharArray(inst_dir, len -1);
|
||||
return QDir::toNativeSeparators(QFileInfo(dir).canonicalFilePath());
|
||||
return QFileInfo(dir).canonicalFilePath();
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -172,8 +172,8 @@ static QString specialFolder(int csidl)
|
||||
if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, csidl, &pidl)))
|
||||
SHGetPathFromIDList(pidl, buf);
|
||||
|
||||
qDebug() << "Special Folder" << csidl << QDir::toNativeSeparators(buf);
|
||||
return QDir::toNativeSeparators(buf);
|
||||
qDebug() << "Special Folder" << csidl << buf;
|
||||
return QFileInfo(buf).canonicalFilePath();
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -194,8 +194,8 @@ QString relativePath(QString path)
|
||||
QFileInfo fi_path(path);
|
||||
QFileInfo fi_home(getHomeDir());
|
||||
|
||||
QString prefix = QDir::toNativeSeparators(fi_home.canonicalFilePath());
|
||||
path = QDir::toNativeSeparators(fi_path.canonicalFilePath());
|
||||
QString prefix = fi_home.canonicalFilePath();
|
||||
path = fi_path.canonicalFilePath();
|
||||
|
||||
if (portable_app()) {
|
||||
if (path.startsWith(prefix))
|
||||
@ -236,7 +236,7 @@ const QString getLibDir()
|
||||
break;
|
||||
}
|
||||
}
|
||||
return QDir::toNativeSeparators(hd);
|
||||
return QFileInfo(hd).canonicalFilePath();
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -275,7 +275,7 @@ const QString getUserSettingsDir()
|
||||
#else
|
||||
rv = QDir::homePath() + "/.xca";
|
||||
#endif
|
||||
return QDir::toNativeSeparators(rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
const QString getI18nDir()
|
||||
@ -582,6 +582,11 @@ QString fingerprint(const QByteArray &data, const EVP_MD *type)
|
||||
Settings["fp_separator"], Settings["fp_digits"]);
|
||||
}
|
||||
|
||||
void update_workingdir(const QString &file)
|
||||
{
|
||||
Settings["workingdir"] = QFileInfo(file).absolutePath();
|
||||
}
|
||||
|
||||
void inc_progress_bar(int, int, void *p)
|
||||
{
|
||||
QProgressBar *bar = (QProgressBar *)p;
|
||||
|
||||
@ -46,6 +46,7 @@ ASN1_STRING *QStringToAsn1(QString s, int nid);
|
||||
|
||||
QByteArray Digest(const QByteArray &data, const EVP_MD *type);
|
||||
QString fingerprint(const QByteArray &data, const EVP_MD *type);
|
||||
void update_workingdir(const QString &file);
|
||||
|
||||
const char *OBJ_ln2sn(const char *ln);
|
||||
const char *OBJ_sn2ln(const char *sn);
|
||||
|
||||
@ -42,7 +42,7 @@ bool XCA_application::languageAvailable(QLocale l)
|
||||
|
||||
static QString defaultlang()
|
||||
{
|
||||
return getUserSettingsDir() + QDir::separator() + "defaultlang";
|
||||
return getUserSettingsDir() + "/defaultlang";
|
||||
}
|
||||
|
||||
XCA_application::XCA_application(int &argc, char *argv[])
|
||||
|
||||
@ -173,28 +173,27 @@ static NIDlist readNIDlist(const QString &fname)
|
||||
static NIDlist read_nidlist(const QString &name)
|
||||
{
|
||||
NIDlist nl;
|
||||
QString sep = QDir::separator();
|
||||
|
||||
/* first try $HOME/xca/ */
|
||||
nl = readNIDlist(getUserSettingsDir() + sep + name);
|
||||
nl = readNIDlist(getUserSettingsDir() + "/" + name);
|
||||
#if !defined(Q_OS_WIN32)
|
||||
#if !defined(Q_OS_MAC)
|
||||
if (nl.count() == 0){
|
||||
/* next is /etx/xca/... */
|
||||
nl = readNIDlist(QString(ETC) + sep + name);
|
||||
nl = readNIDlist(QString(ETC) + "/" + name);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
if (nl.count() == 0) {
|
||||
/* look at /usr/(local/)share/xca/ */
|
||||
nl = readNIDlist(getPrefix() + sep + name);
|
||||
nl = readNIDlist(getPrefix() + "/" + name);
|
||||
}
|
||||
return nl;
|
||||
}
|
||||
|
||||
void initOIDs()
|
||||
{
|
||||
QString oids = QString(QDir::separator()) + "oids.txt";
|
||||
QString oids("/oids.txt");
|
||||
QString dir = getPrefix();
|
||||
|
||||
first_additional_oid = OBJ_new_nid(0);
|
||||
|
||||
@ -371,7 +371,7 @@ QString pki_base::get_dump_filename(const QString &dir,
|
||||
QString ctr = "", fn;
|
||||
int count = 0;
|
||||
while (count++ < 1000) {
|
||||
fn = dir +QDir::separator() +getUnderlinedName() +ctr +ext;
|
||||
fn = dir + "/" + getUnderlinedName() + ctr + ext;
|
||||
if (!QFile::exists(fn))
|
||||
return fn;
|
||||
ctr = QString("_%1").arg(count);
|
||||
|
||||
@ -94,8 +94,12 @@ void settings::load_settings()
|
||||
QStringList l = key.split(":");
|
||||
if (l.size() == 2 && l[1] != hostId())
|
||||
continue; // Skip key with non-matching host ID
|
||||
if (l[0] == "workingdir" && !QDir(value).exists())
|
||||
continue; // Skip non-existing working-dir
|
||||
if (l[0] == "workingdir") {
|
||||
if (!QDir(value).exists())
|
||||
continue; // Skip non-existing working-dir
|
||||
if (!value.isEmpty() && !value.endsWith("/"))
|
||||
value += "/";
|
||||
}
|
||||
db_keys << key; // Key with host ID
|
||||
setAction(l[0], value); // Key without host ID
|
||||
}
|
||||
@ -104,7 +108,6 @@ void settings::load_settings()
|
||||
|
||||
QString settings::get(QString key)
|
||||
{
|
||||
// const QString schema = "schema";
|
||||
load_settings();
|
||||
if (key == "schema" && QSqlDatabase::database().isOpen()) {
|
||||
XSqlQuery q("SELECT value FROM settings WHERE key_='schema'");
|
||||
@ -124,6 +127,8 @@ void settings::set(QString key, QString value)
|
||||
if (!QDir(value).exists())
|
||||
return;
|
||||
value = relativePath(value);
|
||||
if (!value.isEmpty() && !value.endsWith("/"))
|
||||
value += "/";
|
||||
}
|
||||
if (hostspecific.contains(key))
|
||||
key += QString(":%1").arg(hostId());
|
||||
|
||||
@ -77,6 +77,14 @@ class svalue
|
||||
{
|
||||
return get() == "yes" ? Qt::Checked : Qt::Unchecked;
|
||||
}
|
||||
QString operator +(const QString &other)
|
||||
{
|
||||
return get() + other;
|
||||
}
|
||||
QString operator +(const char *other)
|
||||
{
|
||||
return get() + other;
|
||||
}
|
||||
};
|
||||
|
||||
class settings
|
||||
|
||||
@ -29,9 +29,9 @@ ExportDialog::ExportDialog(QWidget *w, const QString &title, const QString &filt
|
||||
image->setPixmap(img);
|
||||
label->setText(title);
|
||||
if (pki) {
|
||||
QString fn = Settings["workingdir"] + QDir::separator() +
|
||||
QString fn = Settings["workingdir"] +
|
||||
pki->getUnderlinedName() + "." + types[0].extension;
|
||||
filename->setText(fn);
|
||||
filename->setText(nativeSeparator(fn));
|
||||
}
|
||||
filter = filt + ";;" + tr("All files ( * )");
|
||||
|
||||
@ -99,10 +99,8 @@ void ExportDialog::on_fileBut_clicked()
|
||||
filename->text(), filter, NULL,
|
||||
QFileDialog::DontConfirmOverwrite);
|
||||
|
||||
if (!s.isEmpty()) {
|
||||
nativeSeparator(s);
|
||||
filename->setText(s);
|
||||
}
|
||||
if (!s.isEmpty())
|
||||
filename->setText(nativeSeparator(s));
|
||||
}
|
||||
|
||||
void ExportDialog::on_exportFormat_activated(int selected)
|
||||
@ -153,8 +151,7 @@ void ExportDialog::accept()
|
||||
return;
|
||||
}
|
||||
if (mayWriteFile(fn)) {
|
||||
Settings["workingdir"] = fn.mid(0, fn.lastIndexOf(
|
||||
QRegExp("[/\\\\]")));
|
||||
update_workingdir(fn);
|
||||
QDialog::accept();
|
||||
}
|
||||
}
|
||||
|
||||
@ -446,7 +446,7 @@ void MainWindow::undelete()
|
||||
|
||||
static QString defaultdb()
|
||||
{
|
||||
return getUserSettingsDir() +QDir::separator() + "defaultdb";
|
||||
return getUserSettingsDir() + "/defaultdb";
|
||||
}
|
||||
|
||||
int MainWindow::open_default_db()
|
||||
@ -548,7 +548,7 @@ void MainWindow::close_database()
|
||||
|
||||
static QString dbhistory()
|
||||
{
|
||||
return getUserSettingsDir() + QDir::separator() + "dbhistory";
|
||||
return getUserSettingsDir() + "/dbhistory";
|
||||
}
|
||||
|
||||
void MainWindow::load_history()
|
||||
|
||||
@ -181,7 +181,7 @@ int MainWindow::changeDB(QString fname)
|
||||
return 1;
|
||||
close_database();
|
||||
if (!OpenDb::isRemoteDB(fname))
|
||||
homedir = fname.mid(0, fname.lastIndexOf(QDir::separator()));
|
||||
homedir = QFileInfo(fname).canonicalPath();
|
||||
return init_database(fname);
|
||||
}
|
||||
|
||||
@ -193,7 +193,7 @@ void MainWindow::update_history_menu()
|
||||
QString txt = history[i];
|
||||
if (!QFile::exists(txt) && !OpenDb::isRemoteDB(txt))
|
||||
continue;
|
||||
txt = txt.remove(0, txt.lastIndexOf(QDir::separator()) +1);
|
||||
txt = QFileInfo(txt).fileName();
|
||||
if (txt.size() > 20)
|
||||
txt = QString("...") + txt.mid(txt.size() - 20);
|
||||
a = historyMenu->addAction(QString("%1 %2").arg(j++).arg(txt));
|
||||
|
||||
@ -202,7 +202,7 @@ void Options::on_removeButton_clicked(void)
|
||||
void Options::on_searchPkcs11_clicked(void)
|
||||
{
|
||||
if (!searchP11) {
|
||||
searchP11 = new SearchPkcs11(this, QString());
|
||||
searchP11 = new SearchPkcs11(this, getLibDir());
|
||||
connect(searchP11, SIGNAL(addLib(QString)),
|
||||
this, SLOT(addLib(QString)));
|
||||
}
|
||||
|
||||
@ -19,14 +19,13 @@
|
||||
#include <QStringList>
|
||||
#include <QFile>
|
||||
|
||||
SearchPkcs11::SearchPkcs11(QWidget *parent, QString fname)
|
||||
SearchPkcs11::SearchPkcs11(QWidget *parent, const QString &fname)
|
||||
:QDialog(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
filename->setText(fname);
|
||||
filename->setText(nativeSeparator(fname));
|
||||
setWindowTitle(XCA_TITLE);
|
||||
|
||||
filename->setText(getLibDir());
|
||||
searching = NULL;
|
||||
}
|
||||
|
||||
@ -41,10 +40,8 @@ void SearchPkcs11::on_fileBut_clicked()
|
||||
QString s = QFileDialog::getExistingDirectory(this, QString(XCA_TITLE),
|
||||
filename->text());
|
||||
|
||||
if (!s.isEmpty()) {
|
||||
nativeSeparator(s);
|
||||
filename->setText(s);
|
||||
}
|
||||
if (!s.isEmpty())
|
||||
filename->setText(nativeSeparator(s));
|
||||
}
|
||||
|
||||
void SearchPkcs11::on_search_clicked()
|
||||
@ -111,6 +108,7 @@ void SearchPkcs11::loadItem(QListWidgetItem *lib)
|
||||
|
||||
void SearchPkcs11::updateCurrFile(QString f)
|
||||
{
|
||||
f = nativeSeparator(f);
|
||||
int len = f.length();
|
||||
QString reduced = f;
|
||||
QFontMetrics fm(currFile->font());
|
||||
@ -171,7 +169,7 @@ void searchThread::search(QString mydir)
|
||||
QString file = files.takeFirst();
|
||||
if (file.isEmpty())
|
||||
continue;
|
||||
file = mydir + QDir::separator() + file;
|
||||
file = mydir + "/" + file;
|
||||
emit updateCurrFile(file);
|
||||
if (checkLib(file))
|
||||
emit updateLibs(file);
|
||||
@ -184,7 +182,7 @@ void searchThread::search(QString mydir)
|
||||
foreach(d, dirs) {
|
||||
if (!keepOnRunning)
|
||||
break;
|
||||
QString s = mydir +QDir::separator() +d;
|
||||
QString s = mydir + "/" + d;
|
||||
emit updateCurrFile(s);
|
||||
search(s);
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ class SearchPkcs11: public QDialog, public Ui::SearchPkcs11
|
||||
searchThread *searching;
|
||||
|
||||
public:
|
||||
SearchPkcs11(QWidget *parent, QString fname);
|
||||
SearchPkcs11(QWidget *parent, const QString &fname);
|
||||
~SearchPkcs11();
|
||||
|
||||
public slots:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user