-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
183 lines (158 loc) · 7.82 KB
/
Source.cpp
File metadata and controls
183 lines (158 loc) · 7.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include <wx/wx.h>
#include <wx/fileconf.h>
#include <wx/filedlg.h>
#include <wx/dirdlg.h>
#include <wx/filename.h>
#include <wx/stdpaths.h>
#include "tsnsoft.xpm"
class MyFrame : public wxFrame {
public:
MyFrame() : wxFrame(nullptr, wxID_ANY, wxT("Update .dev Paths"), wxDefaultPosition, wxSize(500, 300)) {
// Инициализация пути к файлу конфигурации
CONFIG_FILE = wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath() + wxT("/config.ini");
SetIcon(tsnsoft_xpm); // Установка иконки
// Создаём основной сайзер
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
wxPanel* panel = new wxPanel(this);
wxBoxSizer* panelSizer = new wxBoxSizer(wxVERTICAL);
// Поля для путей
wxBoxSizer* wxWidgetsSizer = new wxBoxSizer(wxHORIZONTAL);
wxWidgetsLabel = new wxStaticText(panel, wxID_ANY, wxT("Путь к wxWidgets:"));
wxWidgetsText = new wxTextCtrl(panel, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(400, -1), wxTE_READONLY);
wxWidgetsButton = new wxButton(panel, wxID_ANY, wxT("Выбрать..."), wxDefaultPosition, wxSize(100, -1));
wxWidgetsSizer->Add(wxWidgetsLabel, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
wxWidgetsSizer->Add(wxWidgetsText, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5); // Пропорция 1 для растяжки
wxWidgetsSizer->Add(wxWidgetsButton, 0, wxALIGN_CENTER_VERTICAL);
panelSizer->Add(wxWidgetsSizer, 0, wxEXPAND | wxALL, 5); // Добавлен wxEXPAND
wxBoxSizer* devFileSizer = new wxBoxSizer(wxHORIZONTAL);
devFileLabel = new wxStaticText(panel, wxID_ANY, wxT("Файл .dev:"));
devFileText = new wxTextCtrl(panel, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(400, -1), wxTE_READONLY);
devFileButton = new wxButton(panel, wxID_ANY, wxT("Выбрать..."), wxDefaultPosition, wxSize(100, -1));
devFileSizer->Add(devFileLabel, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
devFileSizer->Add(devFileText, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5); // Пропорция 1 для растяжки
devFileSizer->Add(devFileButton, 0, wxALIGN_CENTER_VERTICAL);
panelSizer->Add(devFileSizer, 0, wxEXPAND | wxALL, 5); // Добавлен wxEXPAND
// Кнопка для обновления
updateButton = new wxButton(panel, wxID_ANY, wxT("Обновить файл .dev"));
panelSizer->Add(updateButton, 0, wxALIGN_CENTER | wxALL, 10);
// Установка сайзера панели
panel->SetSizer(panelSizer);
mainSizer->Add(panel, 1, wxEXPAND);
SetSizerAndFit(mainSizer);
// Загрузка конфигурации
LoadConfig();
// Привязка событий
wxWidgetsButton->Bind(wxEVT_BUTTON, &MyFrame::OnSelectWxWidgetsFolder, this);
devFileButton->Bind(wxEVT_BUTTON, &MyFrame::OnSelectDevFile, this);
updateButton->Bind(wxEVT_BUTTON, &MyFrame::OnUpdateDevFile, this);
}
private:
wxString CONFIG_FILE; // Член класса
wxStaticText* wxWidgetsLabel;
wxTextCtrl* wxWidgetsText;
wxButton* wxWidgetsButton;
wxStaticText* devFileLabel;
wxTextCtrl* devFileText;
wxButton* devFileButton;
wxButton* updateButton;
void LoadConfig() {
wxFileConfig config(wxEmptyString, wxEmptyString, CONFIG_FILE);
wxString wxWidgetsFolder, devFile;
if (config.Read(wxT("Paths/WxWidgetsFolder"), &wxWidgetsFolder) && wxFileName::DirExists(wxWidgetsFolder)) {
wxWidgetsText->SetValue(wxWidgetsFolder);
}
if (config.Read(wxT("Paths/DevFile"), &devFile) && wxFileName::FileExists(devFile)) {
devFileText->SetValue(devFile);
}
}
void SaveConfig() {
wxFileConfig config(wxEmptyString, wxEmptyString, CONFIG_FILE);
config.Write(wxT("Paths/WxWidgetsFolder"), wxWidgetsText->GetValue());
config.Write(wxT("Paths/DevFile"), devFileText->GetValue());
config.Flush();
}
void OnSelectWxWidgetsFolder(wxCommandEvent& event) {
wxDirDialog dlg(this, wxT("Выберите папку с wxWidgets"), wxWidgetsText->GetValue(),
wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);
if (dlg.ShowModal() == wxID_OK) {
wxWidgetsText->SetValue(dlg.GetPath());
}
}
void OnSelectDevFile(wxCommandEvent& event) {
wxFileDialog dlg(this, wxT("Выберите файл .dev"), wxEmptyString, wxEmptyString,
wxT("Dev files (*.dev)|*.dev"), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (!devFileText->GetValue().IsEmpty()) {
dlg.SetPath(devFileText->GetValue());
}
if (dlg.ShowModal() == wxID_OK) {
devFileText->SetValue(dlg.GetPath());
}
}
void OnUpdateDevFile(wxCommandEvent& event) {
// Проверка заполненности полей
if (wxWidgetsText->GetValue().IsEmpty()) {
wxMessageBox(wxT("Пожалуйста, выберите папку wxWidgets."), wxT("Ошибка"), wxOK | wxICON_ERROR);
return;
}
if (devFileText->GetValue().IsEmpty()) {
wxMessageBox(wxT("Пожалуйста, выберите файл .dev."), wxT("Ошибка"), wxOK | wxICON_ERROR);
return;
}
// Проверка существования путей
if (!wxFileName::DirExists(wxWidgetsText->GetValue())) {
wxMessageBox(wxT("Папка wxWidgets не существует."), wxT("Ошибка"), wxOK | wxICON_ERROR);
return;
}
if (!wxFileName::FileExists(devFileText->GetValue())) {
wxMessageBox(wxT("Файл .dev не существует."), wxT("Ошибка"), wxOK | wxICON_ERROR);
return;
}
// Формирование путей с прямыми слэшами
wxString wxInclude = wxWidgetsText->GetValue() + wxT("/include");
wxString wxLibMswud = wxWidgetsText->GetValue() + wxT("/lib/gcc_lib/mswud");
wxString wxLib = wxWidgetsText->GetValue() + wxT("/lib/gcc_lib");
wxInclude.Replace(wxT("\\"), wxT("/"));
wxLibMswud.Replace(wxT("\\"), wxT("/"));
wxLib.Replace(wxT("\\"), wxT("/"));
// Чтение и обновление файла .dev
wxTextFile file(devFileText->GetValue());
if (!file.Open()) {
wxMessageBox(wxT("Не удалось открыть файл .dev."), wxT("Ошибка"), wxOK | wxICON_ERROR);
return;
}
wxArrayString lines;
for (size_t i = 0; i < file.GetLineCount(); ++i) {
wxString line = file.GetLine(i);
if (line.StartsWith(wxT("Includes ="))) {
lines.Add(wxString::Format(wxT("Includes = %s;%s"), wxInclude, wxLibMswud));
} else if (line.StartsWith(wxT("Libs ="))) {
lines.Add(wxString::Format(wxT("Libs = %s"), wxLib));
} else {
lines.Add(line);
}
}
file.Clear();
for (const auto& line : lines) {
file.AddLine(line);
}
if (!file.Write()) {
wxMessageBox(wxT("Не удалось записать файл .dev."), wxT("Ошибка"), wxOK | wxICON_ERROR);
file.Close();
return;
}
file.Close();
// Сохранение конфигурации
SaveConfig();
wxMessageBox(wxT("Файл .dev успешно обновлён!"), wxT("Успех"), wxOK | wxICON_INFORMATION);
}
};
class MyApp : public wxApp {
public:
virtual bool OnInit() override {
MyFrame* frame = new MyFrame();
frame->Show(true);
frame->Centre();
return true;
}
};
wxIMPLEMENT_APP(MyApp);