Changeset 2259 for trunk


Ignore:
Timestamp:
Jan 22, 2013, 7:23:15 PM (7 years ago)
Author:
sam
Message:

sys: retrieve executable path if available.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lol/sys/init.h

    r2241 r2259  
    3535#endif
    3636
     37/*
     38 * System namespace. The platform-specific stuff in there makes the API
     39 * not as clean as the rest of the framework.
     40 */
     41
    3742namespace System
    3843{
    3944
    4045extern void Init(int argc, char *argv[],
    41                  char const *projectdir = LOL_CONFIG_PROJECTDIR,
    42                  char const *solutiondir = LOL_CONFIG_SOLUTIONDIR);
     46                 String const projectdir = LOL_CONFIG_PROJECTDIR,
     47                 String const solutiondir = LOL_CONFIG_SOLUTIONDIR);
    4348
    4449extern void SetDataDir(char const *dir);
  • trunk/src/sys/init.cpp

    r2241 r2259  
    1111#if defined HAVE_CONFIG_H
    1212#   include "config.h"
     13#endif
     14
     15#ifdef _WIN32
     16#   define WIN32_LEAN_AND_MEAN
     17#   include <direct.h>
    1318#endif
    1419
     
    2833
    2934void Init(int argc, char *argv[],
    30           char const *projectdir, char const *solutiondir)
     35          String const projectdir, String const solutiondir)
    3136{
     37    /*
     38     * Retrieve binary directory, defaulting to current dir.
     39     */
     40
     41#if defined _WIN32
     42    char const *cwd = _getcwd(NULL, 0);
     43    String binarydir = String(cwd ? cwd : ".") + SEPARATOR;
     44    free((void *)cwd);
     45#else
     46    String binarydir = String(getcwd()) + SEPARATOR;
     47#endif
     48    if (argc > 0)
     49    {
     50        char const *last_sep = strchr(argv[0], SEPARATOR);
     51        if (last_sep)
     52            binarydir = String(argv[0], last_sep - argv[0] + 1);
     53    }
     54
     55    /*
     56     * Find the common prefix between project dir and solution dir.
     57     */
     58
    3259    bool got_rootdir = false;
    33 
    34     /* Find the common prefix between project dir and solution dir. */
    3560    for (int i = 0; ; i++)
    3661    {
     
    5277    }
    5378
    54     /* Try to guess the data directory from the executable location. */
    55     if (!got_rootdir && argc > 0)
     79    /* If no rootdir found, use the executable location */
     80    if (!got_rootdir)
    5681    {
    57         char const *last_slash = strrchr(argv[0], SEPARATOR);
    58 
    59         if (last_slash)
    60         {
    61             String dir(argv[0], last_slash - argv[0] + 1);
    62             SetDataDir(&dir[0]);
    63             got_rootdir = true;
    64         }
     82        SetDataDir(&binarydir[0]);
     83        got_rootdir = true;
    6584    }
    6685}
Note: See TracChangeset for help on using the changeset viewer.