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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
|
/* cavernlog.cc
* Run cavern inside an Aven window
*
* Copyright (C) 2005-2024 Olly Betts
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include "aven.h"
#include "cavernlog.h"
#include "filename.h"
#include "mainfrm.h"
#include "message.h"
#include "osalloc.h"
#include <algorithm>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <wx/process.h>
#define GVIM_COMMAND "gvim +'call cursor($l,$c)' $f"
#define VIM_COMMAND "x-terminal-emulator -e vim +'call cursor($l,$c)' $f"
#define NVIM_COMMAND "x-terminal-emulator -e nvim +'call cursor($l,$c)' $f"
#define GEDIT_COMMAND "gedit $f +$l:$c"
// Pluma currently ignores the column, but include it assuming some future
// version will add support.
#define PLUMA_COMMAND "pluma +$l:$c $f"
#define EMACS_COMMAND "x-terminal-emulator -e emacs +$l:$c $f"
#define NANO_COMMAND "x-terminal-emulator -e nano +$l,$c $f"
#define JED_COMMAND "x-terminal-emulator -e jed $f -g $l"
#define KATE_COMMAND "kate -l $l -c $c $f"
#ifdef __WXMSW__
# define DEFAULT_EDITOR_COMMAND "notepad $f"
#elif defined __WXMAC__
# define DEFAULT_EDITOR_COMMAND "open -t $f"
#else
# define DEFAULT_EDITOR_COMMAND VIM_COMMAND
#endif
enum { LOG_REPROCESS = 1234, LOG_SAVE = 1235 };
// New event type for signalling cavern output to process.
wxDEFINE_EVENT(EVT_CAVERN_OUTPUT, wxCommandEvent);
void
CavernLogWindow::CheckForOutput(bool immediate)
{
timer.Stop();
if (cavern_out == NULL) return;
wxInputStream * in = cavern_out->GetInputStream();
if (!in->CanRead()) {
timer.StartOnce();
return;
}
size_t real_size = log_txt.size();
size_t allow = 1024;
log_txt.resize(real_size + allow);
in->Read(&log_txt[real_size], allow);
size_t n = in->LastRead();
log_txt.resize(real_size + n);
if (n) {
if (immediate) {
ProcessCavernOutput();
} else {
QueueEvent(new wxCommandEvent(EVT_CAVERN_OUTPUT));
}
}
}
int
CavernLogWindow::OnPaintButton(wxButton* b, int x)
{
if (b) {
x -= 4;
const wxSize& bsize = b->GetSize();
x -= bsize.x;
b->SetSize(x, 4, bsize.x, bsize.y);
x -= 4;
}
return x;
}
void
CavernLogWindow::OnPaint(wxPaintEvent&)
{
wxPaintDC dc(this);
wxFont font = dc.GetFont();
wxFont bold_font = font.Bold();
wxFont underlined_font = font.Underlined();
const wxRegion& region = GetUpdateRegion();
const wxRect& rect = region.GetBox();
int scroll_x = 0, scroll_y = 0;
GetViewStart(&scroll_x, &scroll_y);
int fsize = dc.GetFont().GetPixelSize().GetHeight();
int limit = min((rect.y + rect.height + fsize - 1) / fsize + scroll_y, int(line_info.size()) - 1);
for (int i = max(rect.y / fsize, scroll_y); i <= limit ; ++i) {
LineInfo& info = line_info[i];
// Leave a small margin to the left.
int x = fsize / 2 - scroll_x * fsize;
int y = (i - scroll_y) * fsize;
unsigned offset = info.start_offset;
unsigned len = info.len;
if (info.link_len) {
dc.SetFont(underlined_font);
dc.SetTextForeground(wxColour(192, 0, 192));
wxString link = wxString::FromUTF8(&log_txt[offset], info.link_len);
offset += info.link_len;
len -= info.link_len;
dc.DrawText(link, x, y);
x += info.link_pixel_width;
dc.SetFont(font);
}
if (info.colour_len) {
dc.SetTextForeground(dark_mode ? *wxWHITE : *wxBLACK);
{
size_t s_len = info.start_offset + info.colour_start - offset;
wxString s = wxString::FromUTF8(&log_txt[offset], s_len);
offset += s_len;
len -= s_len;
dc.DrawText(s, x, y);
x += dc.GetTextExtent(s).GetWidth();
}
switch (info.colour) {
case LOG_ERROR:
dc.SetTextForeground(*wxRED);
break;
case LOG_WARNING:
dc.SetTextForeground(wxColour(0xf2, 0x8C, 0x28));
break;
case LOG_INFO:
dc.SetTextForeground(*wxBLUE);
break;
}
dc.SetFont(bold_font);
wxString d = wxString::FromUTF8(&log_txt[offset], info.colour_len);
offset += info.colour_len;
len -= info.colour_len;
dc.DrawText(d, x, y);
x += dc.GetTextExtent(d).GetWidth();
dc.SetFont(font);
}
dc.SetTextForeground(dark_mode ? *wxWHITE : *wxBLACK);
dc.DrawText(wxString::FromUTF8(&log_txt[offset], len), x, y);
}
int x = GetClientSize().x;
x = OnPaintButton(ok_button, x);
x = OnPaintButton(reprocess_button, x);
OnPaintButton(save_button, x);
}
BEGIN_EVENT_TABLE(CavernLogWindow, wxScrolledWindow)
EVT_BUTTON(LOG_REPROCESS, CavernLogWindow::OnReprocess)
EVT_BUTTON(LOG_SAVE, CavernLogWindow::OnSave)
EVT_BUTTON(wxID_OK, CavernLogWindow::OnOK)
EVT_COMMAND(wxID_ANY, EVT_CAVERN_OUTPUT, CavernLogWindow::OnCavernOutput)
EVT_IDLE(CavernLogWindow::OnIdle)
EVT_TIMER(wxID_ANY, CavernLogWindow::OnTimer)
EVT_PAINT(CavernLogWindow::OnPaint)
EVT_MOTION(CavernLogWindow::OnMouseMove)
EVT_LEFT_UP(CavernLogWindow::OnLinkClicked)
EVT_END_PROCESS(wxID_ANY, CavernLogWindow::OnEndProcess)
END_EVENT_TABLE()
wxString escape_for_shell(wxString s, bool protect_dash)
{
#ifdef __WXMSW__
// Correct quoting rules are insane:
//
// http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/everyone-quotes-arguments-the-wrong-way.aspx
//
// Thankfully wxExecute passes the command string to CreateProcess(), so
// at least we don't need to quote for cmd.exe too.
if (protect_dash && !s.empty() && s[0u] == '-') {
// If the filename starts with a '-', protect it from being
// treated as an option by prepending ".\".
s.insert(0, wxT(".\\"));
}
if (s.empty() || s.find_first_of(wxT(" \"\t\n\v")) != s.npos) {
// Need to quote.
s.insert(0, wxT('"'));
for (size_t p = 1; p < s.size(); ++p) {
size_t backslashes = 0;
while (s[p] == wxT('\\')) {
++backslashes;
if (++p == s.size()) {
// Escape all the backslashes, since they're before
// the closing quote we add below.
s.append(backslashes, wxT('\\'));
goto done;
}
}
if (s[p] == wxT('"')) {
// Escape any preceding backslashes and this quote.
s.insert(p, backslashes + 1, wxT('\\'));
p += backslashes + 1;
}
}
done:
s.append(wxT('"'));
}
#else
size_t p = 0;
if (protect_dash && !s.empty() && s[0u] == '-') {
// If the filename starts with a '-', protect it from being
// treated as an option by prepending "./".
s.insert(0, wxT("./"));
p = 2;
}
while (p < s.size()) {
// Exclude a few safe characters which are common in filenames
if (!isalnum((unsigned char)s[p]) && strchr("/._-", s[p]) == NULL) {
s.insert(p, 1, wxT('\\'));
++p;
}
++p;
}
#endif
return s;
}
wxString get_command_path(const wxChar * command_name)
{
#ifdef __WXMSW__
wxString cmd;
{
DWORD len = 256;
wchar_t *buf = NULL;
while (1) {
DWORD got;
buf = (wchar_t*)osrealloc(buf, len * 2);
got = GetModuleFileNameW(NULL, buf, len);
if (got < len) break;
len += len;
}
/* Strange Win32 nastiness - strip prefix "\\?\" if present */
wchar_t *start = buf;
if (wcsncmp(start, L"\\\\?\\", 4) == 0) start += 4;
wchar_t * slash = wcsrchr(start, L'\\');
if (slash) {
cmd.assign(start, slash - start + 1);
}
free(buf);
}
#else
wxString cmd = wxString::FromUTF8(msg_exepth());
#endif
cmd += command_name;
return cmd;
}
CavernLogWindow::CavernLogWindow(MainFrm * mainfrm_, const wxString & survey_, wxWindow * parent)
: wxScrolledWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
wxFULL_REPAINT_ON_RESIZE),
mainfrm(mainfrm_),
survey(survey_),
timer(this)
{
if (wxSystemSettings::GetAppearance().IsDark()) {
SetOwnBackgroundColour(*wxBLACK);
dark_mode = true;
return;
}
SetOwnBackgroundColour(*wxWHITE);
}
CavernLogWindow::~CavernLogWindow()
{
timer.Stop();
if (cavern_out) {
wxEndBusyCursor();
cavern_out->Detach();
}
}
void
CavernLogWindow::OnMouseMove(wxMouseEvent& e)
{
const auto& pos = e.GetPosition();
int fsize = GetFont().GetPixelSize().GetHeight();
int scroll_x = 0, scroll_y = 0;
GetViewStart(&scroll_x, &scroll_y);
unsigned line = pos.y / fsize + scroll_y;
unsigned x = pos.x + scroll_x * fsize - fsize / 2;
if (line < line_info.size() && x <= line_info[line].link_pixel_width) {
SetCursor(wxCursor(wxCURSOR_HAND));
} else {
SetCursor(wxNullCursor);
}
}
void
CavernLogWindow::OnLinkClicked(wxMouseEvent& e)
{
const auto& pos = e.GetPosition();
int fsize = GetFont().GetPixelSize().GetHeight();
int scroll_x = 0, scroll_y = 0;
GetViewStart(&scroll_x, &scroll_y);
unsigned line = pos.y / fsize + scroll_y;
unsigned x = pos.x + scroll_x * fsize - fsize / 2;
if (!(line < line_info.size() && x <= line_info[line].link_pixel_width))
return;
const char* cur = &log_txt[line_info[line].start_offset];
size_t link_len = line_info[line].link_len;
size_t colon = link_len;
while (colon > 1 && (unsigned)(cur[--colon] - '0') <= 9) { }
size_t colon2 = colon;
while (colon > 1 && (unsigned)(cur[--colon] - '0') <= 9) { }
if (cur[colon] != ':') {
colon = colon2;
colon2 = link_len;
}
wxString cmd;
wxChar * p = wxGetenv(wxT("SURVEXEDITOR"));
if (p) {
cmd = p;
if (!cmd.find(wxT("$f"))) {
cmd += wxT(" $f");
}
} else {
p = wxGetenv(wxT("VISUAL"));
if (!p) p = wxGetenv(wxT("EDITOR"));
if (!p) {
cmd = wxT(DEFAULT_EDITOR_COMMAND);
} else {
cmd = p;
if (cmd == "gvim") {
cmd = wxT(GVIM_COMMAND);
} else if (cmd == "vim") {
cmd = wxT(VIM_COMMAND);
} else if (cmd == "nvim") {
cmd = wxT(NVIM_COMMAND);
} else if (cmd == "gedit") {
cmd = wxT(GEDIT_COMMAND);
} else if (cmd == "pluma") {
cmd = wxT(PLUMA_COMMAND);
} else if (cmd == "emacs") {
cmd = wxT(EMACS_COMMAND);
} else if (cmd == "nano") {
cmd = wxT(NANO_COMMAND);
} else if (cmd == "jed") {
cmd = wxT(JED_COMMAND);
} else if (cmd == "kate") {
cmd = wxT(KATE_COMMAND);
} else {
// Escape any $.
cmd.Replace(wxT("$"), wxT("$$"));
cmd += wxT(" $f");
}
}
}
size_t i = 0;
while ((i = cmd.find(wxT('$'), i)) != wxString::npos) {
if (++i >= cmd.size()) break;
switch ((int)cmd[i]) {
case wxT('$'):
cmd.erase(i, 1);
break;
case wxT('f'): {
wxString f = escape_for_shell(wxString(cur, colon), true);
cmd.replace(i - 1, 2, f);
i += f.size() - 1;
break;
}
case wxT('l'): {
wxString l = escape_for_shell(wxString(cur + colon + 1, colon2 - colon - 1));
cmd.replace(i - 1, 2, l);
i += l.size() - 1;
break;
}
case wxT('c'): {
wxString l;
if (colon2 == link_len)
l = wxT("0");
else
l = escape_for_shell(wxString(cur + colon2 + 1, link_len - colon2 - 1));
cmd.replace(i - 1, 2, l);
i += l.size() - 1;
break;
}
default:
++i;
}
}
if (wxExecute(cmd, wxEXEC_ASYNC|wxEXEC_MAKE_GROUP_LEADER) >= 0)
return;
wxString m;
// TRANSLATORS: %s is replaced by the command we attempted to run.
m.Printf(wmsg(/*Couldn’t run external command: “%s”*/17), cmd.c_str());
m += wxT(" (");
m += wxString::FromUTF8(strerror(errno));
m += wxT(')');
wxGetApp().ReportError(m);
}
void
CavernLogWindow::process(const wxString &file)
{
timer.Stop();
if (cavern_out) {
cavern_out->Detach();
cavern_out = NULL;
} else {
wxBeginBusyCursor();
}
SetFocus();
filename = file;
info_count = 0;
link_count = 0;
log_txt.resize(0);
line_info.resize(0);
// Reserve enough that we won't need to grow the allocations in normal cases.
log_txt.reserve(16384);
line_info.reserve(256);
ptr = 0;
save_button = nullptr;
reprocess_button = nullptr;
ok_button = nullptr;
DestroyChildren();
SetVirtualSize(0, 0);
#ifdef __WXMSW__
SetEnvironmentVariable(wxT("SURVEX_UTF8"), wxT("1"));
#else
setenv("SURVEX_UTF8", "1", 1);
#endif
wxString escaped_file = escape_for_shell(file, true);
wxString cmd = get_command_path(L"cavern");
cmd = escape_for_shell(cmd, false);
cmd += wxT(" -o ");
cmd += escaped_file;
cmd += wxT(' ');
cmd += escaped_file;
cavern_out = wxProcess::Open(cmd);
if (!cavern_out) {
wxString m;
m.Printf(wmsg(/*Couldn’t run external command: “%s”*/17), cmd.c_str());
m += wxT(" (");
m += wxString::FromUTF8(strerror(errno));
m += wxT(')');
wxGetApp().ReportError(m);
return;
}
// We want to receive the wxProcessEvent when cavern exits.
cavern_out->SetNextHandler(this);
// Check for output after 500ms if we don't get an idle event sooner.
timer.StartOnce(500);
}
void
CavernLogWindow::ProcessCavernOutput()
{
// ptr gives the start of the first line we've not yet processed.
size_t nl;
while ((nl = log_txt.find('\n', ptr)) != std::string::npos) {
if (nl == ptr || (nl - ptr == 1 && log_txt[ptr] == '\r')) {
// Don't show empty lines in the window.
ptr = nl + 1;
continue;
}
size_t line_len = nl - ptr - (log_txt[nl - 1] == '\r');
// FIXME: Avoid copy, use string_view?
string cur(log_txt, ptr, line_len);
if (log_txt[ptr] == ' ') {
if (expecting_caret_line) {
// FIXME: Check the line is only space, `^` and `~`?
// Otherwise an error without caret info followed
// by an error which contains a '^' gets
// mishandled...
size_t caret = cur.rfind('^');
if (caret != wxString::npos) {
size_t tilde = cur.rfind('~');
if (tilde == wxString::npos || tilde < caret) {
tilde = caret;
}
line_info.back().colour = line_info[line_info.size() - 2].colour;
line_info.back().colour_start = caret;
line_info.back().colour_len = tilde - caret + 1;
expecting_caret_line = false;
ptr = nl + 1;
continue;
}
}
expecting_caret_line = true;
}
line_info.emplace_back(ptr);
line_info.back().len = line_len;
size_t colon = cur.find(": ");
if (colon != wxString::npos) {
size_t link_len = colon;
while (colon > 1 && (unsigned)(cur[--colon] - '0') <= 9) { }
if (cur[colon] == ':') {
line_info.back().link_len = link_len;
static string info_marker = string(msg(/*info*/485)) + ':';
static string warning_marker = string(msg(/*warning*/106)) + ':';
static string error_marker = string(msg(/*error*/93)) + ':';
size_t offset = link_len + 2;
if (cur.compare(offset, info_marker.size(), info_marker) == 0) {
// Show "info" marker in blue.
++info_count;
line_info.back().colour = LOG_INFO;
line_info.back().colour_start = offset;
line_info.back().colour_len = info_marker.size() - 1;
} else if (cur.compare(offset, warning_marker.size(), warning_marker) == 0) {
// Show "warning" marker in orange.
line_info.back().colour = LOG_WARNING;
line_info.back().colour_start = offset;
line_info.back().colour_len = warning_marker.size() - 1;
} else if (cur.compare(offset, error_marker.size(), error_marker) == 0) {
// Show "error" marker in red.
line_info.back().colour = LOG_ERROR;
line_info.back().colour_start = offset;
line_info.back().colour_len = error_marker.size() - 1;
}
++link_count;
}
}
int fsize = GetFont().GetPixelSize().GetHeight();
SetScrollRate(fsize, fsize);
auto& info = line_info.back();
info.link_pixel_width = GetTextExtent(wxString(&log_txt[ptr], info.link_len)).GetWidth();
auto rest_pixel_width = GetTextExtent(wxString(&log_txt[ptr + info.link_len], info.len - info.link_len)).GetWidth();
int width = max(GetVirtualSize().GetWidth(),
int(fsize + info.link_pixel_width + rest_pixel_width));
int height = line_info.size();
SetVirtualSize(width, height * fsize);
if (!link_count) {
// Auto-scroll until the first diagnostic.
int scroll_x = 0, scroll_y = 0;
GetViewStart(&scroll_x, &scroll_y);
int xs, ys;
GetClientSize(&xs, &ys);
Scroll(scroll_x, line_info.size() * fsize - ys);
}
ptr = nl + 1;
}
}
void
CavernLogWindow::OnEndProcess(wxProcessEvent & evt)
{
bool cavern_success = evt.GetExitCode() == 0;
// Read and process any remaining buffered output.
wxInputStream* in = cavern_out->GetInputStream();
while (!in->Eof()) {
CheckForOutput(true);
}
wxEndBusyCursor();
delete cavern_out;
cavern_out = NULL;
// Initially place buttons off the right of the window - they get moved to
// the desired position by OnPaintButton().
wxPoint off_right(GetSize().x, 0);
/* TRANSLATORS: Label for button in aven’s cavern log window which
* allows the user to save the log to a file. */
save_button = new wxButton(this, LOG_SAVE, wmsg(/*&Save Log*/446), off_right);
/* TRANSLATORS: Label for button in aven’s cavern log window which
* causes the survey data to be reprocessed. */
reprocess_button = new wxButton(this, LOG_REPROCESS, wmsg(/*&Reprocess*/184), off_right);
if (cavern_success) {
ok_button = new wxButton(this, wxID_OK, wxString(), off_right);
ok_button->SetDefault();
}
Refresh();
if (!cavern_success) {
return;
}
init_done = false;
{
wxString file3d(filename, 0, filename.length() - 3);
file3d.append(wxT("3d"));
if (!mainfrm->LoadData(file3d, survey)) {
return;
}
}
// Don't stay on log if there there are only "info" diagnostics.
if (link_count == info_count) {
wxCommandEvent dummy;
OnOK(dummy);
}
}
void
CavernLogWindow::OnReprocess(wxCommandEvent &)
{
process(filename);
}
void
CavernLogWindow::OnSave(wxCommandEvent &)
{
wxString filelog(filename, 0, filename.length() - 3);
#ifdef __WXMSW__
// We need to consistently use `\` here.
filelog.Replace("/", "\\");
#endif
filelog += wxT("log");
#ifdef __WXMOTIF__
wxString ext(wxT("*.log"));
#else
/* TRANSLATORS: Log files from running cavern (extension .log) */
wxString ext = wmsg(/*Log files*/447);
ext += wxT("|*.log");
#endif
wxFileDialog dlg(this, wmsg(/*Select an output filename*/319),
wxString(), filelog, ext,
wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (dlg.ShowModal() != wxID_OK) return;
filelog = dlg.GetPath();
FILE * fh_log = wxFopen(filelog, wxT("w"));
if (!fh_log) {
wxGetApp().ReportError(wxString::Format(wmsg(/*Error writing to file “%s”*/7), filelog.c_str()));
return;
}
FWRITE_(log_txt.data(), log_txt.size(), 1, fh_log);
fclose(fh_log);
}
void
CavernLogWindow::OnOK(wxCommandEvent &)
{
if (init_done) {
mainfrm->HideLog(this);
} else {
mainfrm->InitialiseAfterLoad(filename, survey);
init_done = true;
}
}
|