Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
ResourceBundle.cpp
Go to the documentation of this file.
1 
12 #include "stdafx.h"
13 #include "ResourceBundle.h"
14 
15 #include "MsppManager.h"
16 
17 
18 #include <boost/filesystem/path.hpp>
19 #include <boost/filesystem/operations.hpp>
20 
21 
22 using namespace kome::core;
23 
24 
25 #include <crtdbg.h>
26 #ifdef _DEBUG
27  #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
28  #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
29 #endif // _DEBUG
30 
31 
32 
33 // constructor
35 }
36 
37 // destructor
39 }
40 
41 // search resource
42 std::string ResourceBundle::searchResource( const char* name, const char* module, const char* ext ) {
43  // manager
45 
46  // return object
47 // std::string res = searchResource( msppMgr.getMsppDir(), name, module, ext );
48  std::string res = searchResource( getplugindir().c_str(), name, module, ext ); // @date 2013.06.25 <Mod> M.Izumi
49 
50  return res;
51 }
52 
54  const char* path,
55  const char* name,
56  const char* module,
57  const char* ext
58 ) {
59  // return object
60  std::string res;
61 
62  // create string object
63  std::string n = tolowercase( name );
64  std::string m = tolowercase( module );
65  std::string e = tolowercase( ext );
66 
67  if( path == NULL || n.empty() ) {
68  return res;
69  }
70 
71  // path object
72  boost::filesystem::path p( path, boost::filesystem::native );
73  boost::filesystem::directory_iterator end;
74 
75  // check path
76  if( !boost::filesystem::exists( p ) ) {
77  return res;
78  }
79 
80  // search
81  if( boost::filesystem::is_directory( p ) ) { // directory
82  for( boost::filesystem::directory_iterator it( p ); it != end && res.empty(); it++ ) {
83  boost::filesystem::path child = boost::filesystem::absolute( *it );
84  res = searchResource( child.string().c_str(), name, module, ext );
85  }
86  }
87  else { // file
88  std::string absPath = boost::filesystem::absolute( p ).string();
89 
90  std::string fileName = tolowercase( getfilename( absPath.c_str() ).c_str() );
91  std::string fileExt = tolowercase( getext( absPath.c_str() ).c_str() );
92  std::string fileDir = tolowercase( getdir( absPath.c_str() ).c_str() );
93 
94  // check
95  if( fileName.find( n ) != fileName.npos
96  && ( m.empty() || fileDir.find( m ) != fileDir.npos )
97  && ( e.empty() || fileExt.compare( e ) == 0 ) ) {
98  res = absPath;
99  }
100  }
101 
102  return res;
103 }
104 
105 // get instance
107  // create instance (This is the only object.)
108  static ResourceBundle rb;
109 
110  return rb;
111 }
std::string getfilename(const char *path)
get file name
static MsppManager & getInstance()
gets MsppManager object (This is the only object.)
Mass++ manager class.
Definition: MsppManager.h:28
#define NULL
Definition: CoreMacros.h:18
std::string tolowercase(const char *s)
convert all of the characters in the string given to lower case
implements of MsppManager class
static ResourceBundle & getInstance()
gets resource bundle object (This is the only object)
interfarces of ResourceBundle class
std::string getdir(const char *path)
get dir that the file exists
std::string getplugindir()
gets mspp plugin paths
std::string searchResource(const char *name, const char *module, const char *ext)
searches resource file
std::string getext(const char *path)
get the extension of the file
virtual ~ResourceBundle()
destructor
resource bundle class