Mercurial > hg > orthanc
annotate Resources/Samples/Tools/RecoverCompressedFile.cpp @ 680:571583642ce2
Tool to recover compressed files
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 29 Jan 2014 16:20:05 +0100 |
parents | |
children | 44382c8bcd15 |
rev | line source |
---|---|
680
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 #include "../../../Core/Compression/ZlibCompressor.h" |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 #include "../../../Core/Toolbox.h" |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 #include "../../../Core/OrthancException.h" |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 #include <stdio.h> |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 int main(int argc, const char* argv[]) |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 { |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 if (argc != 2 && argc != 3) |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 { |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 fprintf(stderr, "Maintenance tool to recover a DICOM file that was compressed by Orthanc.\n\n"); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 fprintf(stderr, "Usage: %s <input> [output]\n", argv[0]); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 fprintf(stderr, "If \"output\" is not given, the data will be output to stdout\n"); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 return -1; |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 } |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 try |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 { |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 fprintf(stderr, "Reading the file into memory...\n"); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 fflush(stderr); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 std::string content; |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 Orthanc::Toolbox::ReadFile(content, argv[1]); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 fprintf(stderr, "Decompressing the content of the file...\n"); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 fflush(stderr); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 Orthanc::ZlibCompressor compressor; |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 std::string uncompressed; |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 compressor.Uncompress(uncompressed, content); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 fprintf(stderr, "Writing the uncompressed data...\n"); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 fflush(stderr); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 if (argc == 3) |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 { |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 Orthanc::Toolbox::WriteFile(uncompressed, argv[2]); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 } |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 else |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 { |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 if (uncompressed.size() > 0) |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 { |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 fwrite(&uncompressed[0], uncompressed.size(), 1, stdout); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 } |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 } |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 fprintf(stderr, "Done!\n"); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 } |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 catch (Orthanc::OrthancException& e) |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 { |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 fprintf(stderr, "Error: %s\n", e.What()); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 return -1; |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 } |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 return 0; |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 } |