comparison Resources/EmbedResources.py @ 4030:100fbe970762

DANGEROUS commit: removing HAS_EMBEDDED_RESOURCES
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 09 Jun 2020 20:50:20 +0200
parents 94f4a18a79cc
children 78ee0155ec67
comparison
equal deleted inserted replaced
4029:156fece692e3 4030:100fbe970762
40 UPCASE_CHECK = True 40 UPCASE_CHECK = True
41 USE_SYSTEM_EXCEPTION = False 41 USE_SYSTEM_EXCEPTION = False
42 EXCEPTION_CLASS = 'OrthancException' 42 EXCEPTION_CLASS = 'OrthancException'
43 OUT_OF_RANGE_EXCEPTION = '::Orthanc::OrthancException(::Orthanc::ErrorCode_ParameterOutOfRange)' 43 OUT_OF_RANGE_EXCEPTION = '::Orthanc::OrthancException(::Orthanc::ErrorCode_ParameterOutOfRange)'
44 INEXISTENT_PATH_EXCEPTION = '::Orthanc::OrthancException(::Orthanc::ErrorCode_InexistentItem)' 44 INEXISTENT_PATH_EXCEPTION = '::Orthanc::OrthancException(::Orthanc::ErrorCode_InexistentItem)'
45 NAMESPACE = 'Orthanc' 45 NAMESPACE = 'Orthanc.EmbeddedResources'
46 46
47 ARGS = [] 47 ARGS = []
48 for i in range(len(sys.argv)): 48 for i in range(len(sys.argv)):
49 if not sys.argv[i].startswith('--'): 49 if not sys.argv[i].startswith('--'):
50 ARGS.append(sys.argv[i]) 50 ARGS.append(sys.argv[i])
164 164
165 #if defined(_MSC_VER) 165 #if defined(_MSC_VER)
166 # pragma warning(disable: 4065) // "Switch statement contains 'default' but no 'case' labels" 166 # pragma warning(disable: 4065) // "Switch statement contains 'default' but no 'case' labels"
167 #endif 167 #endif
168 168
169 namespace %s 169 """)
170 { 170
171 namespace EmbeddedResources 171
172 { 172 for ns in NAMESPACE.split('.'):
173 header.write('namespace %s {\n' % ns)
174
175
176 header.write("""
173 enum FileResourceId 177 enum FileResourceId
174 { 178 {
175 """ % NAMESPACE) 179 """)
176 180
177 isFirst = True 181 isFirst = True
178 for name in resources: 182 for name in resources:
179 if resources[name]['Type'] == 'File': 183 if resources[name]['Type'] == 'File':
180 if isFirst: 184 if isFirst:
209 const void* GetDirectoryResourceBuffer(DirectoryResourceId id, const char* path); 213 const void* GetDirectoryResourceBuffer(DirectoryResourceId id, const char* path);
210 size_t GetDirectoryResourceSize(DirectoryResourceId id, const char* path); 214 size_t GetDirectoryResourceSize(DirectoryResourceId id, const char* path);
211 void GetDirectoryResource(std::string& result, DirectoryResourceId id, const char* path); 215 void GetDirectoryResource(std::string& result, DirectoryResourceId id, const char* path);
212 216
213 void ListResources(std::list<std::string>& result, DirectoryResourceId id); 217 void ListResources(std::list<std::string>& result, DirectoryResourceId id);
214 } 218
215 } 219 """)
216 """) 220
221
222 for ns in NAMESPACE.split('.'):
223 header.write('}\n')
224
217 header.close() 225 header.close()
218 226
219 227
220 228
221 ##################################################################### 229 #####################################################################
277 285
278 cpp.write(""" 286 cpp.write("""
279 #include <stdint.h> 287 #include <stdint.h>
280 #include <string.h> 288 #include <string.h>
281 289
282 namespace %s 290 """)
283 { 291
284 namespace EmbeddedResources 292 for ns in NAMESPACE.split('.'):
285 { 293 cpp.write('namespace %s {\n' % ns)
286 """ % NAMESPACE)
287 294
288 295
289 for name in resources: 296 for name in resources:
290 if resources[name]['Type'] == 'File': 297 if resources[name]['Type'] == 'File':
291 WriteResource(cpp, resources[name]) 298 WriteResource(cpp, resources[name])
432 size_t size = GetDirectoryResourceSize(id, path); 439 size_t size = GetDirectoryResourceSize(id, path);
433 result.resize(size); 440 result.resize(size);
434 if (size > 0) 441 if (size > 0)
435 memcpy(&result[0], GetDirectoryResourceBuffer(id, path), size); 442 memcpy(&result[0], GetDirectoryResourceBuffer(id, path), size);
436 } 443 }
437 } 444 """)
438 } 445
439 """) 446
447 for ns in NAMESPACE.split('.'):
448 cpp.write('}\n')
449
440 cpp.close() 450 cpp.close()