Skip to content

Commit 5431cf5

Browse files
authored
Merge pull request #268 from dmpas/feature/fix-filepath-encoding
Кодировки в путях
2 parents 56d1cad + 3996708 commit 5431cf5

File tree

9 files changed

+38
-15
lines changed

9 files changed

+38
-15
lines changed

src/gtool1cd/BlobViewer/blob_viewer.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,14 @@ void BlobViewer::on_treeView_doubleClicked(const QModelIndex &index)
146146
auto as_stream = static_cast<StreamDevice*>(data.value<QIODevice*>());
147147
if (as_stream != nullptr) {
148148
QString elementName = model->data(index, Qt::DisplayRole).toString();
149-
BlobViewer *new_window = new BlobViewer(nullptr);
149+
BlobViewer *new_window;
150+
auto found_widget = widgets.find(elementName);
151+
if (found_widget == widgets.end()) {
152+
new_window = new BlobViewer(nullptr);
153+
widgets[elementName] = new_window;
154+
} else {
155+
new_window = static_cast<BlobViewer *>(*found_widget);
156+
}
150157
new_window->setStream(as_stream->get_stream(), rootName + QString(" / ") + elementName);
151158
new_window->show();
152159
}

src/gtool1cd/BlobViewer/blob_viewer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <QWidget>
55
#include <TStream.hpp>
6+
#include <QMap>
67

78
namespace Ui {
89
class BlobViewer;
@@ -29,6 +30,7 @@ private slots:
2930

3031
private:
3132
QString rootName;
33+
QMap<QString, QWidget *> widgets;
3234
Ui::BlobViewer *ui;
3335
};
3436

src/gtool1cd/configurations_window.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ConfigurationsWindow::ConfigurationsWindow(T_1CD *db, QWidget *parent) :
1111
db(db)
1212
{
1313
ui->setupUi(this);
14-
setWindowTitle(QString::fromStdString(db->get_filename()));
14+
setWindowTitle(QString::fromStdWString(db->get_filepath().wstring()));
1515
ui->vendorsTable->setModel(new VendorConfigurationsTableModel(db));
1616
}
1717

@@ -27,7 +27,7 @@ void ConfigurationsWindow::on_saveConfigButton_clicked()
2727
return;
2828
}
2929

30-
db->save_configsave(targetFileName.toStdString());
30+
db->save_configsave(boost::filesystem::path(targetFileName.toStdWString()));
3131
}
3232

3333
void ConfigurationsWindow::on_saveDbConfigButton_clicked()
@@ -37,7 +37,7 @@ void ConfigurationsWindow::on_saveDbConfigButton_clicked()
3737
return;
3838
}
3939

40-
db->save_config(targetFileName.toStdString());
40+
db->save_config(boost::filesystem::path(targetFileName.toStdWString()));
4141
}
4242

4343
void ConfigurationsWindow::on_saveVendorConfigButton_clicked()

src/gtool1cd/container_form.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ ContainerForm::~ContainerForm()
1818
void ContainerForm::open(const QString &filename)
1919
{
2020
QFileInfo finfo(filename);
21-
auto stream = new TFileStream(filename.toStdString(), fmOpenRead);
21+
boost::filesystem::path filepath(filename.toStdWString());
22+
auto stream = new TFileStream(filepath, fmOpenRead);
2223
ui->widget->setStream(stream, finfo.baseName());
2324
setWindowTitle(filename);
2425
}

src/gtool1cd/mainwindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void MainWindow::open(T_1CD *database)
4242
{
4343
db = database;
4444
ui->tableListView->setModel(new TablesListModel(db));
45-
setWindowTitle(QString::fromStdString(db->get_filename()));
45+
setWindowTitle(QString::fromStdWString(db->get_filepath().wstring()));
4646
// refresh data
4747
}
4848

src/gtool1cd/models/vendor_configurations_table_model.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ void VendorConfigurationsTableModel::saveSupplierConfigToFile(const QModelIndex
6969
return;
7070
}
7171
auto config = db->supplier_configs().at(index.row());
72-
config->save_to_file(filename.toStdString());
72+
config->save_to_file(boost::filesystem::path(filename.toStdWString()));
7373
}
7474

src/gtool1cd/starter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ bool StarterWindow::openDatabase(const QString &filename)
108108
T_1CD *db = nullptr;
109109
try {
110110

111-
db = new T_1CD(filename.toStdString(), reg);
111+
db = new T_1CD(boost::filesystem::path(filename.toStdWString()), reg);
112112
if (!db->is_open()) {
113113
lw->show();
114114
return false;

src/tool1cd/Class_1CD.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,14 @@ T_1CD::~T_1CD()
207207
if(pagemap) delete[] pagemap;
208208
}
209209

210+
T_1CD::T_1CD(const boost::filesystem::path &_filename, MessageRegistrator *mess, bool _monopoly)
211+
{
212+
msreg_m.AddMessageRegistrator(mess);
213+
open(_filename, _monopoly);
214+
}
215+
210216
//---------------------------------------------------------------------------
211-
T_1CD::T_1CD(const string &_filename, MessageRegistrator *mess, bool _monopoly)
217+
void T_1CD::open(const boost::filesystem::path &_filename, bool _monopoly)
212218
{
213219
char* b = nullptr;
214220
uint32_t* table_blocks = nullptr;
@@ -217,17 +223,15 @@ T_1CD::T_1CD(const string &_filename, MessageRegistrator *mess, bool _monopoly)
217223
root_80* root80 = nullptr;
218224
root_81* root81 = nullptr;
219225

220-
msreg_m.AddMessageRegistrator(mess);
221-
222226
init();
223227

224-
filename = System::Ioutils::TPath::GetFullPath(_filename);
228+
filename = boost::filesystem::absolute(_filename).string();
225229

226230
std::shared_ptr<TFileStream> base_file;
227231
try
228232
{
229233
base_file.reset(
230-
new TFileStream(boost::filesystem::path(filename),
234+
new TFileStream(_filename,
231235
_monopoly ? (fmOpenReadWrite | fmShareDenyWrite)
232236
: (fmOpenRead | fmShareDenyNone)));
233237
}
@@ -2157,6 +2161,11 @@ bool T_1CD::test_block_by_template(uint32_t testblock, char* tt, uint32_t num, i
21572161
}
21582162

21592163
std::string T_1CD::get_filename() const
2164+
{
2165+
return filename.string();
2166+
}
2167+
2168+
const boost::filesystem::path &T_1CD::get_filepath() const
21602169
{
21612170
return filename;
21622171
}

src/tool1cd/Class_1CD.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "cfapi/TV8FileStream.h"
2121
#include "SupplierConfig.h"
2222
#include "TableRecord.h"
23+
#include <boost/filesystem.hpp>
2324

2425
//---------------------------------------------------------------------------
2526

@@ -186,9 +187,11 @@ class T_1CD
186187

187188
std::string ver;
188189

189-
T_1CD(const std::string &_filename, MessageRegistrator *mess = nullptr, bool monopoly = true);
190+
T_1CD(const boost::filesystem::path &_filename, MessageRegistrator *mess = nullptr, bool monopoly = true);
190191
T_1CD();
191192
~T_1CD();
193+
void open(const boost::filesystem::path &filename, bool monopoly);
194+
192195
bool is_open();
193196
bool is_infobase() const;
194197
int32_t get_numtables();
@@ -219,6 +222,7 @@ class T_1CD
219222
void restore_DATA_allocation_table(Table* tab);
220223
bool test_block_by_template(uint32_t testblock, char* tt, uint32_t num, int32_t rlen, int32_t len);
221224
std::string get_filename() const;
225+
const boost::filesystem::path &get_filepath() const;
222226
uint32_t get_pagesize() const;
223227

224228
SupplierConfigs& supplier_configs();
@@ -234,7 +238,7 @@ class T_1CD
234238
private:
235239
mutable Registrator msreg_m;
236240
mutable MemBlockManager memBlockManager;
237-
std::string filename;
241+
boost::filesystem::path filename;
238242
std::shared_ptr<TFileStream> fs;
239243

240244
db_ver version; // версия базы

0 commit comments

Comments
 (0)