Skip to content

Commit e93458f

Browse files
committed
Fix for app path on windows.
Works for double-click, bash shell, cmd shell, from current and other directory. Need to test on Mac.
1 parent 3f7edca commit e93458f

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

src/Core/Application/Application.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,13 @@ void Application::readCommandLine(int argc, const char* argv[])
121121
{
122122
ENSURE_NOT_NULL(private_, "Application internals are uninitialized!");
123123

124-
private_->app_filename_ = boost::filesystem::path( argv[0] );
125-
private_->app_filepath_ = private_->app_filename_.parent_path();
124+
private_->app_filename_ = boost::filesystem::path(argv[0]);
125+
126+
if (!private_->app_filename_.parent_path().empty())
127+
{
128+
private_->app_filepath_ = boost::filesystem::system_complete(private_->app_filename_.parent_path());
129+
}
130+
126131
private_->parameters_ = private_->parser.parse(argc, argv);
127132

128133
Logging::Log::get().setVerbose(parameters()->verboseMode());
@@ -160,7 +165,6 @@ void Application::executeCommandLineRequests(Commands::GlobalCommandFactoryHandl
160165
boost::filesystem::path Application::executablePath() const
161166
{
162167
ENSURE_NOT_NULL(private_, "Application internals are uninitialized!");
163-
164168
return private_->app_filepath_;
165169
}
166170

src/Interface/Modules/Render/ES/SRInterface.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,8 @@ namespace SCIRun {
10691069
//font texture
10701070
//read in the font data
10711071
bool success = true;
1072-
std::ifstream in("Assets/times_new_roman.font");
1072+
auto fontPath = SCIRun::Core::Application::Instance().executablePath() / "Assets" / "times_new_roman.font";
1073+
std::ifstream in(fontPath.string());
10731074
if (in.fail()) {
10741075
//try the MAC App location if the UNIX/Windows location didn't work.
10751076
in.open("SCIRun.app/Contents/MacOS/Assets/times_new_roman.font");

src/Main/scirunMain.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ int mainImpl(int argc, const char* argv[])
5555
#include <vector>
5656
#include <boost/algorithm/string.hpp>
5757

58+
static std::string&& stripQuotes(std::string& s)
59+
{
60+
if (s.front() == '"' && s.back() == '"')
61+
{
62+
s.erase(0, 1); // erase the first character
63+
s.erase(s.size() - 1); // erase the last character
64+
}
65+
return std::move(s);
66+
}
67+
5868
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
5969
{
6070
#ifdef SCIRUN_SHOW_CONSOLE
@@ -75,7 +85,7 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
7585

7686
// Put the individual arguments into the argv that will be passed.
7787
for(int i = 0; i < argc; i++)
78-
argv[i] = getArgv[i].c_str();
88+
argv[i] = stripQuotes(getArgv[i]).c_str();
7989

8090
return mainImpl(argc, argv);
8191
}

0 commit comments

Comments
 (0)