Mercurial > hg > orthanc
annotate Resources/Samples/Tools/RecoverCompressedFile.cpp @ 3808:7f083dfae62b
new REST route: /modalities/{id}/store-straight
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 03 Apr 2020 14:06:13 +0200 |
parents | 94f4a18a79cc |
children |
rev | line source |
---|---|
747
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
680
diff
changeset
|
1 /** |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
680
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
747
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
747
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
680
diff
changeset
|
6 * |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
680
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
680
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
680
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
680
diff
changeset
|
10 * License, or (at your option) any later version. |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
680
diff
changeset
|
11 * |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
680
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
680
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
680
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
680
diff
changeset
|
15 * General Public License for more details. |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
680
diff
changeset
|
16 * |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
680
diff
changeset
|
17 * You should have received a copy of the GNU General Public License |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
680
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
680
diff
changeset
|
19 **/ |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
680
diff
changeset
|
20 |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
680
diff
changeset
|
21 |
680
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 #include "../../../Core/Compression/ZlibCompressor.h" |
2143
fd5875662670
creation of namespace SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2140
diff
changeset
|
23 #include "../../../Core/SystemToolbox.h" |
680
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include "../../../Core/OrthancException.h" |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 #include <stdio.h> |
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 int main(int argc, const char* argv[]) |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 { |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 if (argc != 2 && argc != 3) |
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, "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
|
33 fprintf(stderr, "Usage: %s <input> [output]\n", argv[0]); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 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
|
35 return -1; |
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 |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 try |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 { |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 fprintf(stderr, "Reading the file into memory...\n"); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 fflush(stderr); |
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 std::string content; |
2140 | 44 Orthanc::SystemToolbox::ReadFile(content, argv[1]); |
680
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 fprintf(stderr, "Decompressing the content of the file...\n"); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 fflush(stderr); |
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 Orthanc::ZlibCompressor compressor; |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 std::string uncompressed; |
2034
07f2ba3677df
Fix of Debian bug #823139 ("orthanc: Please provide RecoverCompressedFile.cpp")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
51 compressor.Uncompress(uncompressed, |
07f2ba3677df
Fix of Debian bug #823139 ("orthanc: Please provide RecoverCompressedFile.cpp")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
52 content.empty() ? NULL : content.c_str(), |
07f2ba3677df
Fix of Debian bug #823139 ("orthanc: Please provide RecoverCompressedFile.cpp")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
53 content.size()); |
680
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 fprintf(stderr, "Writing the uncompressed data...\n"); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 fflush(stderr); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 if (argc == 3) |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 { |
2140 | 60 Orthanc::SystemToolbox::WriteFile(uncompressed, argv[2]); |
680
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 } |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 else |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 { |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 if (uncompressed.size() > 0) |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 { |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 fwrite(&uncompressed[0], uncompressed.size(), 1, stdout); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 } |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 } |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 fprintf(stderr, "Done!\n"); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 } |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 catch (Orthanc::OrthancException& e) |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 { |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 fprintf(stderr, "Error: %s\n", e.What()); |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 return -1; |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 } |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 return 0; |
571583642ce2
Tool to recover compressed files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 } |