source: trunk/src/sys/init.cpp @ 2237

Last change on this file since 2237 was 2237, checked in by sam, 7 years ago

system: try to autodetect the data directory from the executable path;
currently works for images (SDL and GDI+ loaders) and sound samples.

  • Property svn:keywords set to Id
File size: 1.1 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://www.wtfpl.net/ for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include "core.h"
16
17namespace lol
18{
19
20namespace System
21{
22
23void Init(Array<char const *> &args)
24{
25    /* Try to guess the data directory from the executable location. */
26    if (args.Count() > 0)
27    {
28#if defined _WIN32
29#   define SEPARATOR '\\'
30#else
31#   define SEPARATOR '/'
32#endif
33        char const *last_slash = strrchr(args[0], SEPARATOR);
34
35        if (last_slash)
36        {
37            String dir;
38            dir.Resize(last_slash - args[0] + 1);
39            memcpy(&dir[0], args[0], last_slash - args[0] + 1);
40
41            SetDataDir(&dir[0]);
42        }
43    }
44}
45
46/*
47 * Data directory handling
48 */
49
50String data_dir = "";
51
52void SetDataDir(char const *dir)
53{
54    data_dir = dir;
55}
56
57char const *GetDataDir()
58{
59    return &data_dir[0];
60}
61
62
63} /* namespace System */
64
65} /* namespace lol */
66
Note: See TracBrowser for help on using the repository browser.