Changeset 2381


Ignore:
Timestamp:
Feb 8, 2013, 3:05:28 AM (10 years ago)
Author:
sam
Message:

sys: cycle through all possible directories to load resource files.

Location:
trunk/src
Files:
5 edited

Legend:

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

    r2241 r2381  
    4141
    4242private:
    43     Gdiplus::Bitmap *bitmap;
    44     Gdiplus::BitmapData bdata;
     43    Gdiplus::Bitmap *m_bitmap;
     44    Gdiplus::BitmapData m_bdata;
    4545};
    4646
     
    6363    }
    6464
    65     String fullpath = String(System::GetDataDir()) + String(path);
    66     size_t len;
    67     len = mbstowcs(NULL, &fullpath[0], 0);
    68     wchar_t *wpath = new wchar_t[len + 1];
    69     if (mbstowcs(wpath, &fullpath[0], len + 1) == (size_t)-1)
     65    Array<String> pathlist = System::GetPathList(path);
     66    m_bitmap = NULL;
     67    for (int i = 0; i < pathlist.Count(); ++i)
    7068    {
     69        size_t len;
     70        len = mbstowcs(NULL, pathlist[i].C(), 0);
     71        wchar_t *wpath = new wchar_t[len + 1];
     72        if (mbstowcs(wpath, pathlist[i].C(), len + 1) == (size_t)-1)
     73        {
    7174#if !LOL_RELEASE
    72         Log::Error("invalid image name %s\n", &fullpath[0]);
     75            Log::Error("invalid image name %s\n", pathlist[i].C());
    7376#endif
     77            delete[] wpath;
     78            continue;
     79        }
     80
     81        status = Gdiplus::Ok;
     82        m_bitmap = Gdiplus::Bitmap::FromFile(wpath, 0);
     83
     84        if (m_bitmap)
     85        {
     86            status = m_bitmap->GetLastStatus();
     87            if (status != Gdiplus::Ok)
     88            {
     89#if !LOL_RELEASE
     90                if (status != Gdiplus::InvalidParameter)
     91                    Log::Error("error %d loading %s\n",
     92                               status, pathlist[i].C());
     93#endif
     94                delete m_bitmap;
     95                m_bitmap = NULL;
     96            }
     97        }
     98
    7499        delete[] wpath;
    75         return false;
     100        if (m_bitmap)
     101            break;
    76102    }
    77103
    78     bitmap = NULL;
    79     status = Gdiplus::Ok;
    80     bitmap = Gdiplus::Bitmap::FromFile(wpath, 0);
    81     if (bitmap)
    82     {
    83         status = bitmap->GetLastStatus();
    84         if (status != Gdiplus::Ok)
    85         {
    86 #if !LOL_RELEASE
    87             if (status != Gdiplus::InvalidParameter)
    88                 Log::Error("error %d loading %s\n",
    89                            status, &fullpath[0]);
    90 #endif
    91             delete bitmap;
    92             bitmap = NULL;
    93         }
    94     }
    95 
    96     delete[] wpath;
    97     if (!bitmap)
     104    if (!m_bitmap)
    98105    {
    99106#if !LOL_RELEASE
     
    103110    }
    104111
    105     size = ivec2(bitmap->GetWidth(), bitmap->GetHeight());
     112    size = ivec2(m_bitmap->GetWidth(), m_bitmap->GetHeight());
    106113    format = Image::FORMAT_RGBA;
    107114
    108115    Gdiplus::Rect rect(0, 0, size.x, size.y);
    109     if(bitmap->LockBits(&rect, Gdiplus::ImageLockModeRead,
    110                         PixelFormat32bppARGB, &bdata) != Gdiplus::Ok)
     116    if(m_bitmap->LockBits(&rect, Gdiplus::ImageLockModeRead,
     117                          PixelFormat32bppARGB, &m_bdata) != Gdiplus::Ok)
    111118    {
    112119#if !LOL_RELEASE
    113120        Log::Error("could not lock bits in %s\n", path);
    114121#endif
    115         delete bitmap;
     122        delete m_bitmap;
    116123        return false;
    117124    }
     
    120127     * know about ARGB, only RGBA. So we swap bytes. We could also fix
    121128     * this in the shader. */
    122     uint8_t *p = static_cast<uint8_t *>(bdata.Scan0);
     129    uint8_t *p = static_cast<uint8_t *>(m_bdata.Scan0);
    123130    for (int y = 0; y < size.y; y++)
    124131        for (int x = 0; x < size.x; x++)
     
    135142bool GdiPlusImageData::Close()
    136143{
    137     bitmap->UnlockBits(&bdata);
    138     delete bitmap;
     144    m_bitmap->UnlockBits(&m_bdata);
     145    delete m_bitmap;
    139146
    140147    return true;
     
    143150void * GdiPlusImageData::GetData() const
    144151{
    145     return bdata.Scan0;
     152    return m_bdata.Scan0;
    146153}
    147154
  • trunk/src/image/codec/sdl-image.cpp

    r2237 r2381  
    5858bool SdlImageData::Open(char const *path)
    5959{
    60     String fullpath = String(System::GetDataDir()) + String(path);
    61     m_img = IMG_Load(&fullpath[0]);
     60    Array<String> pathlist = System::GetPathList(path);
     61    for (int i = 0; i < pathlist.Count(); i++)
     62    {
     63        m_img = IMG_Load(pathlist[i].C());
     64        if (m_img)
     65            break;
     66    }
     67
    6268    if (!m_img)
    6369    {
    6470#if !LOL_RELEASE
    65         Log::Error("could not load %s\n", &fullpath[0]);
     71        Log::Error("could not load image %s\n", path);
    6672#endif
    6773        return false;
  • trunk/src/lol/sys/init.h

    r2358 r2381  
    4747                 String const &solutiondir = LOL_CONFIG_SOLUTIONDIR);
    4848
    49 extern void SetDataDir(String const &dir);
    50 extern String const &GetDataDir();
     49extern void AddDataDir(String const &dir);
     50extern Array<String> GetPathList(String const &file);
    5151
    5252} /* namespace System */
  • trunk/src/sample.cpp

    r2237 r2381  
    6464
    6565#if defined USE_SDL_MIXER
    66     String fullpath = String(System::GetDataDir()) + String(path);
    67     data->chunk = Mix_LoadWAV(&fullpath[0]);
     66    Array<String> pathlist = System::GetPathList(path);
     67    for (int i = 0; i < pathlist.Count(); ++i)
     68    {
     69        data->chunk = Mix_LoadWAV(pathlist[0].C());
     70        if (data->chunk)
     71            break;
     72    }
    6873    if (!data->chunk)
    6974    {
    7075#if !LOL_RELEASE
    71         Log::Error("could not load %s\n", &fullpath[0]);
     76        Log::Error("could not load sample %s\n", path);
    7277#endif
    7378        SDL_Quit();
  • trunk/src/sys/init.cpp

    r2358 r2381  
    3535#   define SEPARATOR '/'
    3636#endif
     37
     38static Array<String> data_dir;
    3739
    3840void Init(int argc, char *argv[],
     
    7880                if (rootdir.Last() != SEPARATOR)
    7981                    rootdir += SEPARATOR;
    80                 SetDataDir(&rootdir[0]);
     82                AddDataDir(rootdir);
    8183                got_rootdir = true;
    8284            }
     
    8890    if (!got_rootdir)
    8991    {
    90         SetDataDir(&binarydir[0]);
     92        AddDataDir(binarydir);
    9193        got_rootdir = true;
    9294    }
    9395
    94     Log::Debug("binary dir: %s\n", &binarydir[0]);
    95     Log::Debug("root dir: %s\n", &GetDataDir()[0]);
     96    Log::Debug("binary dir: %s\n", binarydir.C());
     97    for (int i = 0; i < data_dir.Count(); ++i)
     98        Log::Debug("data dir %d/%d: %s\n", i + 1, data_dir.Count(),
     99                   data_dir[i].C());
    96100}
    97101
     
    100104 */
    101105
    102 String data_dir = "";
    103 
    104 void SetDataDir(String const &dir)
     106void AddDataDir(String const &dir)
    105107{
    106     data_dir = dir;
     108    data_dir << dir;
    107109}
    108110
    109 String const &GetDataDir()
     111Array<String> GetPathList(String const &file)
    110112{
    111     return data_dir;
     113    Array<String> ret;
     114
     115    for (int i = 0; i < data_dir.Count(); ++i)
     116        ret << data_dir[0] + file;
     117
     118    if (ret.Count() == 0)
     119        ret << file;
     120
     121    return ret;
    112122}
    113123
Note: See TracChangeset for help on using the changeset viewer.