Changeset 2241 for trunk/src/sys


Ignore:
Timestamp:
Jan 21, 2013, 2:11:58 PM (7 years ago)
Author:
sam
Message:

core: pass the project directory to the binary build and get rid of
that 2-year old "temporary Win32 hack".

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sys/init.cpp

    r2237 r2241  
    2121{
    2222
    23 void Init(Array<char const *> &args)
    24 {
    25     /* Try to guess the data directory from the executable location. */
    26     if (args.Count() > 0)
    27     {
    2823#if defined _WIN32
    2924#   define SEPARATOR '\\'
     
    3126#   define SEPARATOR '/'
    3227#endif
    33         char const *last_slash = strrchr(args[0], SEPARATOR);
     28
     29void Init(int argc, char *argv[],
     30          char const *projectdir, char const *solutiondir)
     31{
     32    bool got_rootdir = false;
     33
     34    /* Find the common prefix between project dir and solution dir. */
     35    for (int i = 0; ; i++)
     36    {
     37        if (projectdir[i] != solutiondir[i] || projectdir[i] == '\0')
     38        {
     39            /* FIXME: at this point we should check whether the binary
     40             * was launched from this subdirectory; from now we just
     41             * assume it was. */
     42            if (i)
     43            {
     44                String rootdir = projectdir;
     45                if (rootdir.Last() != SEPARATOR)
     46                    rootdir += SEPARATOR;
     47                SetDataDir(&rootdir[0]);
     48                got_rootdir = true;
     49            }
     50            break;
     51        }
     52    }
     53
     54    /* Try to guess the data directory from the executable location. */
     55    if (!got_rootdir && argc > 0)
     56    {
     57        char const *last_slash = strrchr(argv[0], SEPARATOR);
    3458
    3559        if (last_slash)
    3660        {
    37             String dir;
    38             dir.Resize(last_slash - args[0] + 1);
    39             memcpy(&dir[0], args[0], last_slash - args[0] + 1);
    40 
     61            String dir(argv[0], last_slash - argv[0] + 1);
    4162            SetDataDir(&dir[0]);
     63            got_rootdir = true;
    4264        }
    4365    }
Note: See TracChangeset for help on using the changeset viewer.