Mercurial > hg > orthanc
changeset 680:571583642ce2
Tool to recover compressed files
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 29 Jan 2014 16:20:05 +0100 |
parents | 3e4c2433f12b |
children | efc4928be6fb |
files | NEWS Resources/Samples/Tools/CMakeLists.txt Resources/Samples/Tools/RecoverCompressedFile.cpp |
diffstat | 3 files changed, 97 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Mon Jan 13 16:29:09 2014 +0100 +++ b/NEWS Wed Jan 29 16:20:05 2014 +0100 @@ -1,6 +1,7 @@ Pending changes in the mainline =============================== +* Maintenance tool to recover DICOM files compressed by Orthanc Version 0.7.2 (2013/11/08)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Samples/Tools/CMakeLists.txt Wed Jan 29 16:20:05 2014 +0100 @@ -0,0 +1,40 @@ +cmake_minimum_required(VERSION 2.8) + +project(OrthancTools) + +if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + # Linking with "pthread" is necessary, otherwise the software crashes + # http://sourceware.org/bugzilla/show_bug.cgi?id=10652#c17 + link_libraries(pthread dl) +endif() + +set(STATIC_BUILD ON) +set(ALLOW_DOWNLOADS ON) + +set(ORTHANC_ROOT ${CMAKE_SOURCE_DIR}/../../..) + +include(CheckIncludeFiles) +include(CheckIncludeFileCXX) +include(CheckLibraryExists) +include(${ORTHANC_ROOT}/Resources/CMake/Compiler.cmake) +include(${ORTHANC_ROOT}/Resources/CMake/DownloadPackage.cmake) +include(${ORTHANC_ROOT}/Resources/CMake/BoostConfiguration.cmake) +include(${ORTHANC_ROOT}/Resources/CMake/ZlibConfiguration.cmake) + +add_library(CommonLibraries + ${BOOST_SOURCES} + ${THIRD_PARTY_SOURCES} + ${ORTHANC_ROOT}/Core/OrthancException.cpp + ${ORTHANC_ROOT}/Core/Toolbox.cpp + ${ORTHANC_ROOT}/Core/Uuid.cpp + ${ORTHANC_ROOT}/Resources/md5/md5.c + ${ORTHANC_ROOT}/Resources/base64/base64.cpp + ) + +add_executable(RecoverCompressedFile + RecoverCompressedFile.cpp + ${ORTHANC_ROOT}/Core/Compression/BufferCompressor.cpp + ${ORTHANC_ROOT}/Core/Compression/ZlibCompressor.cpp + ) + +target_link_libraries(RecoverCompressedFile CommonLibraries)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Samples/Tools/RecoverCompressedFile.cpp Wed Jan 29 16:20:05 2014 +0100 @@ -0,0 +1,56 @@ +#include "../../../Core/Compression/ZlibCompressor.h" +#include "../../../Core/Toolbox.h" +#include "../../../Core/OrthancException.h" + +#include <stdio.h> + +int main(int argc, const char* argv[]) +{ + if (argc != 2 && argc != 3) + { + fprintf(stderr, "Maintenance tool to recover a DICOM file that was compressed by Orthanc.\n\n"); + fprintf(stderr, "Usage: %s <input> [output]\n", argv[0]); + fprintf(stderr, "If \"output\" is not given, the data will be output to stdout\n"); + return -1; + } + + try + { + fprintf(stderr, "Reading the file into memory...\n"); + fflush(stderr); + + std::string content; + Orthanc::Toolbox::ReadFile(content, argv[1]); + + fprintf(stderr, "Decompressing the content of the file...\n"); + fflush(stderr); + + Orthanc::ZlibCompressor compressor; + std::string uncompressed; + compressor.Uncompress(uncompressed, content); + + fprintf(stderr, "Writing the uncompressed data...\n"); + fflush(stderr); + + if (argc == 3) + { + Orthanc::Toolbox::WriteFile(uncompressed, argv[2]); + } + else + { + if (uncompressed.size() > 0) + { + fwrite(&uncompressed[0], uncompressed.size(), 1, stdout); + } + } + + fprintf(stderr, "Done!\n"); + } + catch (Orthanc::OrthancException& e) + { + fprintf(stderr, "Error: %s\n", e.What()); + return -1; + } + + return 0; +}