~qcumber-some/widelands/spice-up-cmake

« back to all changes in this revision

Viewing changes to src/wlapplication.cc

  • Committer: Jens Beyer (Qcumber-some)
  • Date: 2010-05-28 14:51:37 UTC
  • mfrom: (5149.1.226 trunk)
  • Revision ID: qcumber-some@buerotiger.de-20100528145137-0pyil9qw7szyztsw
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
195
195
        g_fs->PutRightVersionOnTop();
196
196
}
197
197
void WLApplication::setup_homedir() {
198
 
        std::string path = FileSystem::GetHomedir();
199
 
 
200
198
        //If we don't have a home directory don't do anything
201
 
        if (path.size()) {
202
 
                RealFSImpl(path).EnsureDirectoryExists(".widelands");
203
 
                path += "/.widelands";
 
199
        if (m_homedir.size()) {
 
200
                //assume some dir exists
204
201
                try {
205
 
                        log ("Set home directory: %s\n", path.c_str());
206
 
                        g_fs->SetHomeFileSystem(FileSystem::Create(path.c_str()));
207
 
                } catch (FileNotFound_error     const & e) {
208
 
                } catch (FileAccessDenied_error const & e) {
209
 
                        log("Access denied on %s. Continuing.\n", e.m_filename.c_str());
210
 
                } catch (FileType_error         const & e) {
211
 
                        //TODO: handle me
 
202
                        log ("Set home directory: %s\n", m_homedir.c_str());
 
203
 
 
204
                        std::auto_ptr<FileSystem> home(new RealFSImpl(m_homedir));
 
205
                        home->EnsureDirectoryExists(".");
 
206
                        g_fs->SetHomeFileSystem(*home.release());
 
207
                } catch (const std::exception & e) {
 
208
                        log("Failed to add home directory: %s\n", e.what());
212
209
                }
213
210
        } else {
214
211
                //TODO: complain
268
265
#if HAS_OPENGL
269
266
m_gfx_opengl           (false),
270
267
#endif
271
 
m_default_datadirs     (true)
 
268
m_default_datadirs     (true),
 
269
m_homedir(FileSystem::GetHomedir() + "/.widelands")
272
270
{
273
271
        g_fs = new LayeredFileSystem();
274
272
        UI::g_fh = new UI::Font_Handler();
535
533
                while (SDL_PollEvent(&ev)) {
536
534
                        switch (ev.type) {
537
535
                        case SDL_KEYDOWN:
538
 
                                if (ev.key.keysym.sym == SDLK_F10) // TEMP - get out of here quick
 
536
                                // get out of here quickly, overriding playback;
 
537
                                // since this is the only key event that works, we don't guard
 
538
                                // it by requiring Ctrl to be pressed.
 
539
                                if (ev.key.keysym.sym == SDLK_F10)
539
540
                                        m_should_die = true;
540
541
                                break;
541
542
                        case SDL_QUIT:
559
560
                switch (ev.type) {
560
561
                case SDL_KEYDOWN:
561
562
                case SDL_KEYUP:
562
 
                        if (ev.key.keysym.sym == SDLK_F10) { //  TEMP - get out of here quick
 
563
                        if (ev.key.keysym.sym == SDLK_F10 &&
 
564
                                (get_key_state(SDLK_LCTRL) || get_key_state(SDLK_RCTRL))) { //  get out of here quick
563
565
                                if (ev.type == SDL_KEYDOWN)
564
566
                                        m_should_die = true;
565
567
                                break;
620
622
                        break;
621
623
 
622
624
                case SDL_MOUSEMOTION:
623
 
                        // All the interesting stuff is now in Sys_PollEvent()
624
 
 
625
625
                        m_mouse_position = Point(ev.motion.x, ev.motion.y);
626
626
 
627
627
                        if ((ev.motion.xrel or ev.motion.yrel) and cb and cb->mouse_move)
859
859
                char buffer[buffersize];
860
860
                int32_t check = _NSGetExecutablePath(buffer,&buffersize);
861
861
                if (check != 0) {
862
 
                        throw wexception ("[OSX] dyld could not find the path of the main executable");
 
862
                        throw wexception (_("could not find the path of the main executable"));
863
863
                }
864
864
                std::string executabledir = buffer;
865
865
                executabledir.resize(executabledir.find_last_of('/') + 1);
866
866
                executabledir+= localedir;
867
 
                std::cout << "localedir : " << executabledir << std::endl;
 
867
                log ("localedir: %s\n", executabledir.c_str());
 
868
                return executabledir;
 
869
        }
 
870
#elif linux
 
871
        if (localedir[0] != '/') {
 
872
                char buffer[PATH_MAX];
 
873
                size_t size = readlink("/proc/self/exe", buffer, PATH_MAX);
 
874
                if (size <= 0) {
 
875
                        throw wexception (_("could not find the path of the main executable"));
 
876
                }
 
877
                std::string executabledir(buffer, size);
 
878
                executabledir.resize(executabledir.find_last_of('/') + 1);
 
879
                executabledir += localedir;
 
880
                log ("localedir : %s\n", executabledir.c_str());
868
881
                return executabledir;
869
882
        }
870
883
#endif
1132
1145
                m_default_datadirs = false;
1133
1146
                m_commandline.erase("datadir");
1134
1147
        }
 
1148
        if (m_commandline.count("homedir")) {
 
1149
                log ("Adding home directory: %s\n", m_commandline["homedir"].c_str());
 
1150
                m_homedir = m_commandline["homedir"];
 
1151
                m_commandline.erase("homedir");
 
1152
        }
1135
1153
 
1136
1154
        if (m_commandline.count("double")) {
1137
1155
#ifdef DEBUG
1276
1294
                         "                      terminal output\n"
1277
1295
                         " --datadir=DIRNAME    Use specified direction for the widelands\n"
1278
1296
                         "                      data files\n"
1279
 
                         " --record=FILENAME    Record all events to the given filename for\n"
 
1297
                         " --homedir=DIRNAME    Use specified directory for widelands config\n"
 
1298
                         "                      files, savegames and replays\n")
 
1299
#ifdef linux
 
1300
                << _("                      Default is ~/.widelands\n")
 
1301
#endif
 
1302
                << _
 
1303
                        (" --record=FILENAME    Record all events to the given filename for\n"
1280
1304
                         "                      later playback\n"
1281
1305
                         " --playback=FILENAME  Playback given filename (see --record)\n\n"
1282
1306
                         " --coredump=[yes|no]  Generates a core dump on segfaults instead\n"