Changeset 2241 for trunk/src


Ignore:
Timestamp:
Jan 21, 2013, 2:11:58 PM (8 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".

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/image/codec/gdiplus-image.cpp

    r2237 r2241  
    8686#if !LOL_RELEASE
    8787            if (status != Gdiplus::InvalidParameter)
    88                 Log::Error("error %d loading %s\n", status, path);
     88                Log::Error("error %d loading %s\n",
     89                           status, &fullpath[0]);
    8990#endif
    9091            delete bitmap;
  • trunk/src/lol/sys/init.h

    r2237 r2241  
    2222{
    2323
     24/*
     25 * Module-specific macros. These can be overridden by the build process,
     26 * typically with compiler command-line flags.
     27 */
     28
     29#if !defined LOL_CONFIG_PROJECTDIR
     30#   define LOL_CONFIG_PROJECTDIR ""
     31#endif
     32
     33#if !defined LOL_CONFIG_SOLUTIONDIR
     34#   define LOL_CONFIG_SOLUTIONDIR ""
     35#endif
     36
    2437namespace System
    2538{
    2639
    27 extern void Init(Array<char const *> &args);
     40extern void Init(int argc, char *argv[],
     41                 char const *projectdir = LOL_CONFIG_PROJECTDIR,
     42                 char const *solutiondir = LOL_CONFIG_SOLUTIONDIR);
     43
    2844extern void SetDataDir(char const *dir);
    2945extern char const *GetDataDir();
    30 
    31 static inline void Init(int argc, char *argv[])
    32 {
    33     Array<char const *> args;
    34 
    35     for (int i = 0; i < argc; i++)
    36         args << argv[i];
    37 
    38     Init(args);
    39 }
    4046
    4147} /* namespace System */
  • 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.