Windows: deal with non-ASCII user login, non-ascii paths in confdir etc.

This commit is contained in:
Jean-Francois Dockes
2020-04-15 14:03:04 +01:00
parent 7c39eff719
commit 12ebb7ac6e
10 changed files with 201 additions and 92 deletions
+6 -6
View File
@@ -18,6 +18,7 @@
#include <utility>
#include <memory>
#include <fstream>
#include <stdlib.h>
#include <qapplication.h>
@@ -1071,16 +1072,15 @@ void RclMain::exportSimpleSearchHistory()
}
string path = qs2utf8s(dialog.selectedFiles().value(0));
LOGDEB("Chosen path: " << path << "\n");
FILE *fp = fopen(path.c_str(), "wb");
if (fp == 0) {
QMessageBox::warning(0, "Recoll",
tr("Could not open/create file"));
std::fstream fp = path_open(path, std::ios::out | std::ios::trunc);
if (!fp.is_open()) {
QMessageBox::warning(0, "Recoll", tr("Could not open/create file"));
return;
}
for (int i = 0; i < prefs.ssearchHistory.count(); i++) {
fprintf(fp, "%s\n", qs2utf8s(prefs.ssearchHistory[i]).c_str());
fp << qs2utf8s(prefs.ssearchHistory[i]) << "\n";
}
fclose(fp);
fp.close();
}
// Called when the uiprefs dialog is ok'd
+10 -12
View File
@@ -24,6 +24,7 @@
#include <algorithm>
#include <memory>
#include <fstream>
#include <Qt>
#include <QShortcut>
@@ -418,7 +419,7 @@ QVariant RecollModel::data(const QModelIndex& index, int role) const
return QString::fromUtf8(lr.front().c_str());
}
void RecollModel::saveAsCSV(FILE *fp)
void RecollModel::saveAsCSV(std::fstream& fp)
{
if (!m_source)
return;
@@ -433,7 +434,7 @@ void RecollModel::saveAsCSV(FILE *fp)
}
string csv;
stringsToCSV(tokens, csv);
fprintf(fp, "%s\n", csv.c_str());
fp << csv << "\n";
tokens.clear();
for (int row = 0; row < rows; row++) {
@@ -445,7 +446,7 @@ void RecollModel::saveAsCSV(FILE *fp)
tokens.push_back(m_getters[col](m_fields[col], doc));
}
stringsToCSV(tokens, csv);
fprintf(fp, "%s\n", csv.c_str());
fp << csv << "\n";
tokens.clear();
}
}
@@ -785,22 +786,19 @@ void ResTable::saveAsCSV()
LOGDEB("ResTable::saveAsCSV\n");
if (!m_model)
return;
QString s =
QFileDialog::getSaveFileName(this, //parent
tr("Save table to CSV file"),
QString::fromLocal8Bit(path_home().c_str())
);
QString s = QFileDialog::getSaveFileName(
this, tr("Save table to CSV file"), path2qs(path_home()));
if (s.isEmpty())
return;
const char *tofile = s.toLocal8Bit();
FILE *fp = fopen(tofile, "w");
if (fp == 0) {
std::string tofile = qs2path(s);
std::fstream fp = path_open(tofile, std::ios::out|std::ios::trunc);
if (!fp.is_open()) {
QMessageBox::warning(0, "Recoll",
tr("Can't open/create file: ") + s);
return;
}
m_model->saveAsCSV(fp);
fclose(fp);
fp.close();
}
// This is called when the sort order is changed from another widget
+2 -1
View File
@@ -24,6 +24,7 @@
#include <map>
#include <vector>
#include <memory>
#include <fstream>
#include "ui_restable.h"
#include "docseq.h"
@@ -47,7 +48,7 @@ public:
int role = Qt::DisplayRole ) const;
virtual QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole ) const;
virtual void saveAsCSV(FILE *fp);
virtual void saveAsCSV(std::fstream& fp);
virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
// Specific methods
virtual void readDocSource();
+10 -6
View File
@@ -20,6 +20,7 @@
#include <stdio.h>
#include <string>
#include <fstream>
#include <QPushButton>
#include <QMessageBox>
@@ -42,18 +43,21 @@ void WinSchedToolW::init()
connect(startPB, SIGNAL(clicked()), this, SLOT(startWinScheduler()));
// thisexecpath returns the directory
// Use a short path on Windows if possible to avoid issues with
// accented characters
string confdir = path_shortpath(theconfig->getConfDir());
// path_thisexecpath() returns the directory
string recollindex = path_cat(path_thisexecpath(), "recollindex.exe");
LOGDEB("WinSchedTool: recollindex: " << recollindex << endl);
string batchfile = path_cat(theconfig->getConfDir(), "winsched.bat");
string batchfile = path_cat(confdir, "winsched.bat");
LOGDEB("WinSchedTool: batch file " << batchfile << endl);
if (!path_exists(batchfile)) {
FILE *fp = fopen(batchfile.c_str(), "w");
fprintf(fp, "\"%s\" -c \"%s\"\n", recollindex.c_str(),
theconfig->getConfDir().c_str());
fclose(fp);
std::fstream fp = path_open(batchfile, ios::out|ios::trunc);
fp << "\"" << recollindex << "\" -c \"" << confdir << "\"\n";
fp.close();
}
QString blurb = tr(
"<h3>Recoll indexing batch scheduling</h3>"