From c4e426d70ba253dc119cdce014c6b763474a2a8d Mon Sep 17 00:00:00 2001 From: Hleb Valoshka <375gnu@gmail.com> Date: Mon, 5 Jul 2021 11:37:17 +0400 Subject: [PATCH] wip --- src/celcompat/fs.cpp | 2 +- src/celestia/celestiacore.cpp | 4 ++++ src/celestia/celestiacore.h | 2 ++ src/celestia/win32/winmain.cpp | 23 +++-------------------- 4 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/celcompat/fs.cpp b/src/celcompat/fs.cpp index fedc7a686..a496da6e2 100644 --- a/src/celcompat/fs.cpp +++ b/src/celcompat/fs.cpp @@ -622,7 +622,7 @@ path current_path(std::error_code& ec) return buffer.substr(0, pos); #else std::string buffer(256, 0); - char *r = getcwd(&buffer[0], p.size()); + char *r = getcwd(&buffer[0], buffer.size()); if (r == nullptr) { ec = std::error_code(errno, std::system_category()); diff --git a/src/celestia/celestiacore.cpp b/src/celestia/celestiacore.cpp index 909a57f29..8e991d6bd 100644 --- a/src/celestia/celestiacore.cpp +++ b/src/celestia/celestiacore.cpp @@ -1916,6 +1916,10 @@ void CelestiaCore::setStartURL(const string &url) } } +std::string_view CelestiaCore::getStartURL() const +{ + return startURL; +} void CelestiaCore::tick() { diff --git a/src/celestia/celestiacore.h b/src/celestia/celestiacore.h index fecbb7fb9..7ab974deb 100644 --- a/src/celestia/celestiacore.h +++ b/src/celestia/celestiacore.h @@ -20,6 +20,7 @@ #include #include // #include +#include #include #include #include @@ -206,6 +207,7 @@ class CelestiaCore // : public Watchable // URLs and history navigation void setStartURL(const std::string& url); + std::string_view getStartURL() const; bool goToUrl(const std::string& urlStr); void addToHistory(); void back(); diff --git a/src/celestia/win32/winmain.cpp b/src/celestia/win32/winmain.cpp index c84ffa8b2..6e319005a 100644 --- a/src/celestia/win32/winmain.cpp +++ b/src/celestia/win32/winmain.cpp @@ -3058,7 +3058,8 @@ int APIENTRY WinMain(HINSTANCE hInstance, // If there's an existing instance and we've been given a // URL on the command line, send the URL to the running instance // of Celestia before terminating. - if (startURL != "") + auto startURL = appCore.getStartURL(); + if (!startURL().empty()) { COPYDATASTRUCT cd; cd.dwData = 0; @@ -3072,11 +3073,6 @@ int APIENTRY WinMain(HINSTANCE hInstance, } } - // If a start directory was given on the command line, switch to it - // now. - if (startDirectory != "") - SetCurrentDirectory(startDirectory.c_str()); - s_splash = new SplashWindow(SPLASH_DIR "\\" "splash.png"); s_splash->setMessage(_("Loading data files...")); if (!skipSplashScreen) @@ -3191,8 +3187,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, if (!skipSplashScreen) progressNotifier = new WinSplashProgressNotifier(s_splash); - bool initSucceeded = appCore->initSimulation(configFileName, extrasDirectories, progressNotifier); - + bool initSucceeded = appCore->initSimulation(progressNotifier); delete progressNotifier; // Close the splash screen after all data has been loaded @@ -3207,9 +3202,6 @@ int APIENTRY WinMain(HINSTANCE hInstance, if (!initSucceeded) return 1; - if (startURL != "") - appCore->setStartURL(startURL); - menuBar = CreateMenuBar(); acceleratorTable = LoadAccelerators(hRes, MAKEINTRESOURCE(IDR_ACCELERATORS)); @@ -3373,15 +3365,6 @@ int APIENTRY WinMain(HINSTANCE hInstance, appCore->start(); - if (startURL != "") - { - COPYDATASTRUCT cd; - cd.dwData = 0; - cd.cbData = startURL.length(); - cd.lpData = reinterpret_cast(const_cast(startURL.c_str())); - SendMessage(mainWindow, WM_COPYDATA, 0, reinterpret_cast(&cd)); - } - // Initial tick required before first frame is rendered; this gives // start up scripts a chance to run. appCore->tick();