Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
e9ea8c81
Commit
e9ea8c81
authored
Jul 13, 2010
by
Sebastian Eichelbaum
Browse files
[CHANGE] - now the application path is used as relative base path
parent
5888da12
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
16 deletions
+48
-16
src/common/WPreferences.cpp
src/common/WPreferences.cpp
+1
-0
src/common/WPreferences.h
src/common/WPreferences.h
+19
-2
src/gui/qt4/WQt4Gui.cpp
src/gui/qt4/WQt4Gui.cpp
+8
-1
src/kernel/WKernel.cpp
src/kernel/WKernel.cpp
+13
-12
src/kernel/WKernel.h
src/kernel/WKernel.h
+7
-1
No files found.
src/common/WPreferences.cpp
View file @
e9ea8c81
...
...
@@ -24,4 +24,5 @@
#include "WPreferences.h"
boost
::
filesystem
::
path
WPreferences
::
m_preferenceFile
=
boost
::
filesystem
::
path
(
"walnut.cfg"
);
WProperties
WPreferences
::
m_preferences
(
"Preferences"
);
src/common/WPreferences.h
View file @
e9ea8c81
...
...
@@ -29,9 +29,10 @@
#include <iostream>
#include <fstream>
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include "
../common/
WIOTools.h"
#include "WIOTools.h"
#include "WProperties.h"
#include "WLogger.h"
...
...
@@ -48,9 +49,25 @@ public:
* \return True if value could be found, false otherwise.
*/
template
<
typename
T
>
static
bool
getPreference
(
std
::
string
prefName
,
T
*
retVal
);
/**
* Sets the configuration file globally.
*
* \param cfg the config file to use.
*/
static
void
setPreferenceFile
(
boost
::
filesystem
::
path
cfg
)
{
m_preferenceFile
=
cfg
;
}
protected:
private:
static
WProperties
m_preferences
;
//!< Structure for caching the preferences.
/**
* The file containing the config options.
*/
static
boost
::
filesystem
::
path
m_preferenceFile
;
};
template
<
typename
T
>
bool
WPreferences
::
getPreference
(
std
::
string
prefName
,
T
*
retVal
)
...
...
@@ -76,7 +93,7 @@ template< typename T > bool WPreferences::getPreference( std::string prefName, T
configurationDescription
.
add_options
()
(
prefName
.
c_str
(),
po
::
value
<
T
>
()
);
std
::
string
cfgFileName
(
"walnut.cfg"
);
std
::
string
cfgFileName
=
m_preferenceFile
.
file_string
(
);
boost
::
program_options
::
variables_map
configuration
;
if
(
wiotools
::
fileExists
(
cfgFileName
)
)
...
...
src/gui/qt4/WQt4Gui.cpp
View file @
e9ea8c81
...
...
@@ -27,6 +27,7 @@
#include <string>
#include <vector>
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include <boost/shared_ptr.hpp>
...
...
@@ -133,13 +134,19 @@ int WQt4Gui::run()
WLogger
::
getLogger
()
->
run
();
wlog
::
info
(
"GUI"
)
<<
"Bringing up GUI"
;
// the call path of the application
boost
::
filesystem
::
path
walnutBin
=
boost
::
filesystem
::
path
(
std
::
string
(
m_argv
[
0
]
)
);
boost
::
filesystem
::
path
appPath
=
walnutBin
.
parent_path
();
// init preference system
WPreferences
::
setPreferenceFile
(
appPath
/
"walnut.cfg"
);
QApplication
appl
(
m_argc
,
m_argv
,
true
);
// startup graphics engine
m_ge
=
WGraphicsEngine
::
getGraphicsEngine
();
// and startup kernel
m_kernel
=
boost
::
shared_ptr
<
WKernel
>
(
new
WKernel
(
m_ge
,
shared_from_this
()
)
);
m_kernel
=
boost
::
shared_ptr
<
WKernel
>
(
new
WKernel
(
m_ge
,
shared_from_this
()
,
appPath
)
);
m_kernel
->
run
();
t_ModuleErrorSignalHandlerType
func
=
boost
::
bind
(
&
WQt4Gui
::
moduleError
,
this
,
_1
,
_2
);
m_kernel
->
getRootContainer
()
->
addDefaultNotifier
(
WM_ERROR
,
func
);
...
...
src/kernel/WKernel.cpp
View file @
e9ea8c81
...
...
@@ -67,14 +67,21 @@ boost::filesystem::path WKernel::m_appPath = boost::filesystem::path();
*/
boost
::
filesystem
::
path
WKernel
::
m_fontPath
=
boost
::
filesystem
::
path
();
/**
* Sets whether the above paths have been found already.
*/
bool
WKernel
::
m_pathsFound
=
false
;
/**
* The path for modules.
*/
boost
::
filesystem
::
path
WKernel
::
m_modulePath
=
boost
::
filesystem
::
path
();
WKernel
::
WKernel
(
boost
::
shared_ptr
<
WGraphicsEngine
>
ge
,
boost
::
shared_ptr
<
WGUI
>
gui
)
:
WKernel
::
WKernel
(
boost
::
shared_ptr
<
WGraphicsEngine
>
ge
,
boost
::
shared_ptr
<
WGUI
>
gui
,
boost
::
filesystem
::
path
progPath
)
:
WThreadedRunner
()
{
m_appPath
=
progPath
;
WLogger
::
getLogger
()
->
addLogMessage
(
"Initializing Kernel"
,
"Kernel"
,
LL_INFO
);
// init the singleton
...
...
@@ -197,33 +204,29 @@ void WKernel::threadMain()
void
WKernel
::
findAppPath
()
{
// only get the path if not already done
if
(
!
m_
appPath
.
empty
()
)
if
(
m_
pathsFound
)
{
return
;
}
// unified version with boost::filesystem
namespace
fs
=
boost
::
filesystem
;
fs
::
path
currentDir
(
fs
::
initial_path
<
fs
::
path
>
()
);
m_appPath
=
currentDir
;
WLogger
::
getLogger
()
->
addLogMessage
(
"Application path: "
+
m_appPath
.
file_string
(),
"Kernel"
,
LL_DEBUG
);
m_shaderPath
=
fs
::
path
(
currentDir
/
"shaders"
);
m_shaderPath
=
boost
::
filesystem
::
path
(
m_appPath
/
"shaders"
);
WLogger
::
getLogger
()
->
addLogMessage
(
"Shader path: "
+
m_shaderPath
.
file_string
(),
"Kernel"
,
LL_DEBUG
);
// NOTE: currently, OpenSceneGraph has hard-coded its search path for fonts. So we can't change it to somewhere else currently.
m_fontPath
=
fs
::
path
(
currentDir
/
"fonts"
);
m_fontPath
=
boost
::
filesystem
::
path
(
m_appPath
/
"fonts"
);
WLogger
::
getLogger
()
->
addLogMessage
(
"Font path: "
+
m_fontPath
.
file_string
(),
"Kernel"
,
LL_DEBUG
);
// the module path. use WSharedLib to find it basing on the bin- dir
std
::
string
libPath
=
""
;
if
(
!
WPreferences
::
getPreference
(
"modules.path"
,
&
libPath
)
)
{
m_modulePath
=
fs
::
path
(
currentDir
/
WSharedLib
::
getSystemLibPath
()
);
m_modulePath
=
boost
::
filesystem
::
path
(
m_appPath
/
WSharedLib
::
getSystemLibPath
()
);
}
WLogger
::
getLogger
()
->
addLogMessage
(
"Module path: "
+
m_modulePath
.
file_string
(),
"Kernel"
,
LL_DEBUG
);
m_pathsFound
=
true
;
}
const
WBoolFlag
&
WKernel
::
isFinishRequested
()
const
...
...
@@ -248,13 +251,11 @@ boost::shared_ptr< WModule > WKernel::applyModule( boost::shared_ptr< WModule >
boost
::
filesystem
::
path
WKernel
::
getAppPathObject
()
{
findAppPath
();
return
WKernel
::
m_appPath
;
}
std
::
string
WKernel
::
getAppPath
()
{
findAppPath
();
return
WKernel
::
m_appPath
.
file_string
();
}
...
...
src/kernel/WKernel.h
View file @
e9ea8c81
...
...
@@ -66,8 +66,9 @@ public:
*
* \param ge initialized graphics engine.
* \param gui initialized gui.
* \param progPath the path for the executable. Used later on to find resources and modules.
*/
WKernel
(
boost
::
shared_ptr
<
WGraphicsEngine
>
ge
,
boost
::
shared_ptr
<
WGUI
>
gui
);
WKernel
(
boost
::
shared_ptr
<
WGraphicsEngine
>
ge
,
boost
::
shared_ptr
<
WGUI
>
gui
,
boost
::
filesystem
::
path
progPath
);
/**
* Destructor.
...
...
@@ -258,6 +259,11 @@ private:
* The location of the modules.
*/
static
boost
::
filesystem
::
path
m_modulePath
;
/**
* True if the above paths have been initialized already.
*/
static
bool
m_pathsFound
;
};
#endif // WKERNEL_H
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment