Changeset 329


Ignore:
Timestamp:
08/15/13 09:07:39 (6 years ago)
Author:
jls17
Message:
  • finished ResourceFileLocatorAndExtractor::ExtractTo? implementation
  • added some more error handling to UntarStream? class
  • now zlib is always needed to compile ARInside
  • added ExtractResource? method to CARInside class
  • the resources tar.gz archive is created by cmake
Location:
branches/work_304
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/work_304/ARInside.cpp

    r326 r329  
    5252 
    5353#include "scan/ScanMain.h" 
     54 
     55#include "util/ResourceFileLocatorAndExtractor.h" 
    5456 
    5557///////// 
     
    21102112void CARInside::DoWork(int nMode) 
    21112113{        
    2112         FileSystemUtil fsUtil(appConfig); 
    2113          
    2114         string directory = FileSystemUtil::GetExecutableDirectory(NULL); 
    2115  
    2116         // first step is to create directory structure and resources (images, css and js) 
     2114        // first step is to create directory structure 
    21172115        Prepare(); 
    2118         fsUtil.Load(); 
     2116 
     2117        // now extract resources (images, css, js and so on) 
     2118        ExtractResources(); 
    21192119 
    21202120        // now load the object either from server or from file 
     
    24972497#endif 
    24982498} 
     2499 
     2500void CARInside::ExtractResources() 
     2501{ 
     2502        try 
     2503        { 
     2504                ResourceFileLocatorAndExtractor resExtractor("arires.tgz"); 
     2505                resExtractor.ExtractTo(appConfig.targetFolder); 
     2506        } 
     2507        catch (std::exception &ex) 
     2508        { 
     2509                cerr << "Error while extracting resources: " << ex.what() << endl; 
     2510        } 
     2511} 
  • branches/work_304/ARInside.h

    r308 r329  
    9090        bool InBlacklist(int refType, const string &objName) {  return blackList.Contains(refType, objName.c_str()); } 
    9191        void Prepare(void);              
     92        void ExtractResources(void); 
    9293        void Documentation(void); 
    9394 
  • branches/work_304/CMakeLists.txt

    r327 r329  
    4848 
    4949# configurable variables for cmakegui 
    50 IF(NOT DEFINED ARINSIDE_ENABLE_ZLIB_SUPPORT) 
    51         SET(ARINSIDE_ENABLE_ZLIB_SUPPORT CACHE BOOL "Enables zlib-compression support. See documentation for more details") 
    52 ENDIF(NOT DEFINED ARINSIDE_ENABLE_ZLIB_SUPPORT) 
    53  
    5450IF(NOT DEFINED ARINSIDE_BETA) 
    5551        SET(ARINSIDE_BETA CACHE BOOL "When enabled, appends 'Beta' to the version string.") 
     
    6662 
    6763if (NOT DEFINED ZLIB_INCLUDE_PATH) 
    68   SET(ZLIB_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../libs/zlib" CACHE PATH "Path to the zlib directory. Only used if ARINSIDE_ENABLE_ZLIB_SUPPORT ist enabled.") 
     64  SET(ZLIB_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../libs/zlib" CACHE PATH "Path to the zlib include/lib directories.") 
    6965ENDIF(NOT DEFINED ZLIB_INCLUDE_PATH) 
    7066 
     
    8379 
    8480ADD_DEFINITIONS(-DAR_STRICT_ANSI -D_CRT_SECURE_NO_DEPRECATE) 
    85 IF(ARINSIDE_ENABLE_ZLIB_SUPPORT) 
    86         ADD_DEFINITIONS(-DARINSIDE_ENABLE_ZLIB_SUPPORT) 
    87 ENDIF(ARINSIDE_ENABLE_ZLIB_SUPPORT) 
    8881IF(ARINSIDE_BETA) 
    8982        ADD_DEFINITIONS(-D_ARINSIDE_BETA) 
     
    129122 tinyxml/tinyxml.cpp tinyxml/tinystr.cpp tinyxml/tinyxmlerror.cpp tinyxml/tinyxmlparser.cpp 
    130123 util/AppTimer.cpp util/BlackListItem.cpp util/CommandLineValidator.cpp util/RefItem.cpp  
    131  util/ResourceFileLocatorAndExtractor.h util/UntarStream.cpp util/Util.cpp  
     124 util/ResourceFileLocatorAndExtractor.cpp util/UntarStream.cpp util/Util.cpp  
    132125 AppConfig.cpp AppConfigReader.cpp ARInside.cpp ConfigFile.cpp FileSystemUtil.cpp gzstream.cpp Main.cpp 
    133126) 
     
    249242ENDIF (NOT ARS_API_LIB) 
    250243 
    251 IF (ARINSIDE_ENABLE_ZLIB_SUPPORT AND NOT ZLIB_LIB) 
     244IF (NOT ZLIB_LIB) 
    252245        MESSAGE(FATAL_ERROR "Could not find ${ZLIB_LIBNAMES} in '${ZLIB_LIB_PATH}'! Please check or specify ZLIB_INCLUDE_PATH variable") 
    253 ENDIF (ARINSIDE_ENABLE_ZLIB_SUPPORT AND NOT ZLIB_LIB) 
     246ENDIF (NOT ZLIB_LIB) 
    254247 
    255248MESSAGE(STATUS "icudatabmc: (${ARINSIDE_ARAPI_ICUDATABMC_LIBNAME}) -- ${ARS_API_ICUDATABMC_LIB}") 
     
    310303ENDIF(UNIX) 
    311304 
     305ADD_CUSTOM_TARGET(arinsideresdir ALL 
     306        COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/img 
     307        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/active_link.gif ${CMAKE_BINARY_DIR}/img 
     308        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/al_guide.gif ${CMAKE_BINARY_DIR}/img 
     309        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/application.gif ${CMAKE_BINARY_DIR}/img 
     310        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/ars_edit.gif ${CMAKE_BINARY_DIR}/img 
     311        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/chapter.gif ${CMAKE_BINARY_DIR}/img 
     312        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/disabled.gif ${CMAKE_BINARY_DIR}/img 
     313        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/doc.gif ${CMAKE_BINARY_DIR}/img 
     314        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/down.gif ${CMAKE_BINARY_DIR}/img 
     315        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/edit.gif ${CMAKE_BINARY_DIR}/img 
     316        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/empty_list.gif ${CMAKE_BINARY_DIR}/img 
     317        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/escalation.gif ${CMAKE_BINARY_DIR}/img 
     318        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/filter.gif ${CMAKE_BINARY_DIR}/img 
     319        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/filter_guide.gif ${CMAKE_BINARY_DIR}/img 
     320        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/folder.gif ${CMAKE_BINARY_DIR}/img 
     321        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/group.gif ${CMAKE_BINARY_DIR}/img 
     322        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/hidden.gif ${CMAKE_BINARY_DIR}/img 
     323        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/image.gif ${CMAKE_BINARY_DIR}/img 
     324        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/info.gif ${CMAKE_BINARY_DIR}/img 
     325        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/menu.gif ${CMAKE_BINARY_DIR}/img 
     326        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/next.gif ${CMAKE_BINARY_DIR}/img 
     327        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/packing_list.gif ${CMAKE_BINARY_DIR}/img 
     328        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/prev.gif ${CMAKE_BINARY_DIR}/img 
     329        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/schema.gif ${CMAKE_BINARY_DIR}/img 
     330        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/search.gif ${CMAKE_BINARY_DIR}/img 
     331        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/server.gif ${CMAKE_BINARY_DIR}/img 
     332        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/sort_asc.gif ${CMAKE_BINARY_DIR}/img 
     333        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/sort_desc.gif ${CMAKE_BINARY_DIR}/img 
     334        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/up.gif ${CMAKE_BINARY_DIR}/img 
     335        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/user.gif ${CMAKE_BINARY_DIR}/img 
     336        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/visible.gif ${CMAKE_BINARY_DIR}/img 
     337        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/webservice.gif ${CMAKE_BINARY_DIR}/img 
     338        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/script.js ${CMAKE_BINARY_DIR}/img 
     339        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/sortscript.js ${CMAKE_BINARY_DIR}/img 
     340        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/tabscript.js ${CMAKE_BINARY_DIR}/img 
     341        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/schema_page.js ${CMAKE_BINARY_DIR}/img 
     342        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/arshelper.js ${CMAKE_BINARY_DIR}/img 
     343        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/jquery/jquery-ui-custom.css ${CMAKE_BINARY_DIR}/img 
     344        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/jquery/jquery-ui.js ${CMAKE_BINARY_DIR}/img 
     345        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/jquery/jquery.address.min.js ${CMAKE_BINARY_DIR}/img 
     346        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/jquery/jquery.js ${CMAKE_BINARY_DIR}/img 
     347        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/jquery/jquery.timers.js ${CMAKE_BINARY_DIR}/img 
     348        COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/img/images 
     349        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/jquery/images/ui-bg_glass_75_e6e6e6_1x400.png ${CMAKE_BINARY_DIR}/img/images 
     350        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/jquery/images/ui-bg_glass_65_ffffff_1x400.png ${CMAKE_BINARY_DIR}/img/images 
     351) 
     352 
     353ADD_CUSTOM_TARGET(arinsideres ALL  
     354        COMMAND ${CMAKE_COMMAND} -E tar "czf" "${arinside_BINARY_DIR}/arires.tgz" img WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" DEPENDS arinsideresdir 
     355) 
     356 
    312357ADD_MSVC_PRECOMPILED_HEADER("stdafx.h" "stdafx.cpp" ARINSIDE_SRCS) 
    313358 
     
    360405# dependencies 
    361406ADD_DEPENDENCIES(arinsidetest arinsidelib googletest) 
    362 ADD_DEPENDENCIES(arinside arinsidelib) 
     407ADD_DEPENDENCIES(arinside arinsidelib arinsideres) 
    363408 
    364409# reference the needed libraries 
  • branches/work_304/gzstream.cpp

    r194 r329  
    2828 
    2929#include "stdafx.h" 
    30  
    31 // <ARINSIDE> 
    32 // JLS17: ARInside uses gzstream only if ARINSIDE_ENABLE_ZLIB_SUPPORT is defined. 
    33 //        So, if it's not defined, dont compile this file. 
    34 #ifdef ARINSIDE_ENABLE_ZLIB_SUPPORT 
    35 // </ARINSIDE> 
    3630 
    3731#include <gzstream.h> 
     
    170164#endif 
    171165 
    172 //// <ARINSIDE> 
    173 #endif // ARINSIDE_ENABLE_ZLIB_SUPPORT 
    174 //// </ARINSIDE> 
    175  
    176166// ============================================================================ 
    177167// EOF // 
  • branches/work_304/gzstream.h

    r194 r329  
    2929#ifndef GZSTREAM_H 
    3030#define GZSTREAM_H 1 
    31  
    32 // <ARINSIDE> 
    33 // JLS17: ARInside uses gzstream only if ARINSIDE_ENABLE_ZLIB_SUPPORT is defined. 
    34 //        So, if it's not defined, dont compile this file. 
    35 #if defined(ARINSIDE_ENABLE_ZLIB_SUPPORT) 
    36 // </ARINSIDE> 
    3731 
    3832// standard C++ with new header file names and std:: namespace 
     
    122116#endif 
    123117 
    124 #endif // ARINSIDE_ENABLE_ZLIB_SUPPORT 
    125  
    126118#endif // GZSTREAM_H 
    127119// ============================================================================ 
  • branches/work_304/util/ResourceFileLocatorAndExtractor.cpp

    r326 r329  
    1717#include "stdafx.h" 
    1818#include "ResourceFileLocatorAndExtractor.h" 
     19#include "UntarStream.h" 
     20#include "../AppException.h" 
    1921#include "../FileSystemUtil.h" 
     22#include "../gzstream.h" 
     23 
    2024 
    2125ResourceFileLocatorAndExtractor::ResourceFileLocatorAndExtractor(const std::string &resourceFilename) 
     
    3034bool ResourceFileLocatorAndExtractor::ExtractTo(const std::string &targetDir) 
    3135{ 
    32         string directory = FileSystemUtil::GetExecutableDirectory(NULL); 
    33         directory = FileSystemUtil::GetRealPathName(directory); 
     36        char* envInstallDir = getenv("ARINSIDE_INSTALL_DIR"); 
    3437 
     38        string directory; 
     39 
     40        // if the environment var is set, use it and check if it is a real path 
     41        if (envInstallDir != NULL && envInstallDir[0] != 0) 
     42        { 
     43                directory = FileSystemUtil::GetRealPathName(envInstallDir); 
     44        } 
     45         
     46        // if the directory variable is still empty, try to use the path to the current executable 
    3547        if (directory.empty()) 
    3648        { 
    37                 return false; 
     49                directory = FileSystemUtil::GetRealPathName(FileSystemUtil::GetExecutableDirectory(NULL)); 
    3850        } 
    3951 
     52        // still empty, then we don't know where to look 
     53        if (directory.empty()) 
     54        { 
     55                throw AppException("Couldn't detect directory of resource file!"); 
     56        } 
    4057 
    41         return false; 
     58        // check if the file to extract exists 
     59        string resourceFile = FileSystemUtil::CombinePath(directory, resFile); 
     60        if (!FileSystemUtil::FileExistsAndReadable(resourceFile)) 
     61        { 
     62                throw untar_exception(untar_exception::READ); 
     63        } 
     64 
     65        // now extract the content 
     66        igzstream unzipStrm(resourceFile.c_str()); 
     67        UntarStream untarStrm(unzipStrm); 
     68        untarStrm.ExtractAllTo(targetDir, UntarStream::REPLACE); 
     69 
     70        return true; 
    4271} 
  • branches/work_304/util/UntarStream.cpp

    r328 r329  
    5656        input.read(reinterpret_cast<char*>(&header), sizeof(tar_header)); 
    5757         
    58         if (input.fail()) return false; 
     58        if (input.fail()) 
     59        { 
     60                throw untar_exception(untar_exception::READ, 0); 
     61                return false; 
     62        } 
    5963 
    6064        if ((header.typeflag == REGTYPE || header.typeflag == AREGTYPE) && header.name[0] == 0) 
Note: See TracChangeset for help on using the changeset viewer.