Working directory

master
rubenwardy 2014-07-01 20:27:07 +01:00
parent cb7e988ea9
commit 4690191703
5 changed files with 66 additions and 36 deletions

2
.gitignore vendored
View File

@ -8,7 +8,7 @@ Makefile
# Configuration/generated
editor.conf
common.hpp
conf_cmake.hpp
install_manifest.txt
#################

View File

@ -4,20 +4,13 @@ project(NodeBoxEditor)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
# Configuration
option (RUN_IN_PLACE
"Whether editor should run in place (see readme.md)" ON)
IF (RUN_IN_PLACE)
set (BOOL_RUN_IN_PLACE true)
ELSE (RUN_IN_PLACE)
set (BOOL_RUN_IN_PLACE false)
ENDIF (RUN_IN_PLACE)
set(NBE_MAJOR_VERSION 0)
set(NBE_MINOR_VERSION 6)
set(NBE_PATCH_VERSION 4)
set(NBE_DESCR_VERSION "\"0.6.4 - Stone\"")
configure_file (
src/common.hpp.in
src/common.hpp
src/conf_cmake.hpp.in
src/conf_cmake.hpp
)
# Dependancies
@ -86,27 +79,19 @@ set_target_properties(${PROJECT_NAME}
)
# Install DLLs
if (NOT RUN_IN_PLACE)
message ("WARNING: An install build is being created.")
message ("Use cmake . -DRUN_IN_PLACE=1 to make a portable build")
install (FILES media/fontlucida.png DESTINATION nbe/media)
install (FILES media/gui_scale.png DESTINATION nbe/media)
install (FILES media/icon_mode_node.png DESTINATION nbe/media)
install (FILES media/icon_mode_nodebox.png DESTINATION nbe/media)
install (FILES media/sky.jpg DESTINATION nbe/media)
install (FILES media/texture_box.png DESTINATION nbe/media)
install (FILES media/texture_terrain.png DESTINATION nbe/media)
install (FILES editor.conf.example DESTINATION nbe)
install (FILES README.md DESTINATION nbe)
install (TARGETS ${PROJECT_NAME} DESTINATION bin)
else (NOT RUN_IN_PLACE)
message ("WARNING: A portable build is being created. sudo make install will not work")
message ("Use cmake . -DRUN_IN_PLACE=0 to make an install build")
endif (NOT RUN_IN_PLACE)
install (FILES media/fontlucida.png DESTINATION share/nodeboxeditor/media)
install (FILES media/gui_scale.png DESTINATION share/nodeboxeditor/media)
install (FILES media/icon_mode_node.png DESTINATION share/nodeboxeditor/media)
install (FILES media/icon_mode_nodebox.png DESTINATION share/nodeboxeditor/media)
install (FILES media/sky.jpg DESTINATION share/nodeboxeditor/media)
install (FILES media/texture_box.png DESTINATION share/nodeboxeditor/media)
install (FILES media/texture_terrain.png DESTINATION share/nodeboxeditor/media)
install (FILES editor.conf.example DESTINATION share/nodeboxeditor)
install (FILES README.md DESTINATION share/nodeboxeditor)
install (TARGETS ${PROJECT_NAME} DESTINATION bin)
if(WIN32)
if(DEFINED IRRLICHT_DLL)
message(Installing irrlicht dll)
install(FILES ${IRRLICHT_DLL} DESTINATION bin)
endif()
endif()

View File

@ -25,9 +25,12 @@ enum FileParserType
EFPT_IMPORT = 4
};
// Whether the editor has been installed or not
// See main.cpp
static bool editor_is_installed = false;
// Defines
#define EDITOR_TEXT_VERSION @NBE_DESCR_VERSION@
#define RUN_IN_PLACE @BOOL_RUN_IN_PLACE@
#include "conf_cmake.hpp"
#define EDITOR_VERSION 1
#define EDITOR_PARSER 1

5
src/conf_cmake.hpp.in Normal file
View File

@ -0,0 +1,5 @@
#ifndef CONF_CMAKE_HPP_INCLUDED
#define EDITOR_TEXT_VERSION @NBE_DESCR_VERSION@
#endif

View File

@ -12,6 +12,25 @@
#endif
#endif
#ifdef _WIN32
#include <windows.h>
bool PathExists(const char* path)
{
return (GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES);
}
#else
#include <sys/stat.h>
bool PathExists(const char* path)
{
struct stat st;
return (stat(path, &st) == 0);
}
#endif
int main(int argc, char *argv[]) {
std::cerr <<
" _ _ _ ____ _____ _ _ _ \n"
@ -21,28 +40,43 @@ int main(int argc, char *argv[]) {
"|_| \\_|\\___/ \\__,_|\\___| |____/ \\___/_/\\_\\ |_____\\__,_|_|\\__\\___/|_| \n\n"
<< std::endl;
// Find the working directory
std::cerr << "Looking for the working directory..." << std::endl;
if (!PathExists("media/sky.jpg")) {
chdir("../");
if (!PathExists("media/sky.jpg")) {
chdir("share/nodeboxeditor");
if (!PathExists("media/sky.jpg")) {
std::cerr << "Can't find the working directory!" << std::endl;
} else {
std::cerr << "Setting" << std::endl;
editor_is_installed = true;
}
}
}
// Settings
Configuration* conf = new Configuration();
if (conf == NULL) {
return EXIT_FAILURE;
}
#if !RUN_IN_PLACE
system("cd ../nbe");
#endif
// Init Settings
conf->set("snapping", "true");
conf->set("limiting", "true");
conf->set("driver", "opengl");
conf->set("hide_sidebar", "false");
conf->set("save_directory", "");
conf->set("always_show_position_handle", "false");
conf->set("vsync", "true");
conf->set("use_sleep", "false");
conf->set("fullscreen", "false");
conf->set("width", "896");
conf->set("height", "520");
conf->load("editor.conf");
if (editor_is_installed)
conf->load("editor.conf");
else
conf->load("~/.config/nodeboxeditor.conf");
E_DRIVER_TYPE driv = irr::video::EDT_OPENGL;
@ -81,7 +115,10 @@ int main(int argc, char *argv[]) {
Editor* editor = new Editor();
editor->run(device, conf);
conf->save("editor.conf");
if (editor_is_installed)
conf->load("editor.conf");
else
conf->load("~/.config/nodeboxeditor.conf");
return 1;
}