changeset 648:bcf5c9a767a9

use filenames with 8 characters in ZIP files for maximum compatibility
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 30 Oct 2013 09:34:21 +0100
parents a9ea5e311ec5
children 7446a8ae2fad
files NEWS OrthancServer/OrthancRestApi.cpp
diffstat 2 files changed, 36 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Wed Oct 30 09:05:41 2013 +0100
+++ b/NEWS	Wed Oct 30 09:34:21 2013 +0100
@@ -2,9 +2,10 @@
 ===============================
 
 
-* Use ZIP64 only when it is required (depending on file count and size)
+* Use ZIP64 only when required to improve compatibility (cf. issue #7)
+* Refactoring of the CMake options
 * Fix for big-endian architectures (RedHat bug #985748)
-* Refactoring of the CMake options
+* Use filenames with 8 characters in ZIP files for maximum compatibility
 * Possibility to build Orthanc inplace (in the source directory)
 
 
--- a/OrthancServer/OrthancRestApi.cpp	Wed Oct 30 09:05:41 2013 +0100
+++ b/OrthancServer/OrthancRestApi.cpp	Wed Oct 30 09:34:21 2013 +0100
@@ -531,7 +531,8 @@
 
   static bool ArchiveInstance(HierarchicalZipWriter& writer,
                               ServerContext& context,
-                              const std::string& instancePublicId)
+                              const std::string& instancePublicId,
+                              const char* filename)
   {
     Json::Value instance;
     if (!context.GetIndex().LookupResource(instance, instancePublicId, ResourceType_Instance))
@@ -539,8 +540,7 @@
       return false;
     }
 
-    std::string filename = instance["MainDicomTags"]["SOPInstanceUID"].asString() + ".dcm";
-    writer.OpenFile(filename.c_str());
+    writer.OpenFile(filename);
 
     std::string dicom;
     context.ReadFile(dicom, instancePublicId, FileContentType_Dicom);
@@ -594,14 +594,43 @@
         break;
 
       case ResourceType_Series:
+      {
+        // Create a filename prefix, depending on the modality
+        char format[16] = "%08d";
+
+        if (resource["MainDicomTags"].isMember("Modality"))
+        {
+          std::string modality = resource["MainDicomTags"]["Modality"].asString();
+
+          if (modality.size() == 1)
+          {
+            snprintf(format, sizeof(format) - 1, "%c%%07d", toupper(modality[0]));
+          }
+          else if (modality.size() >= 2)
+          {
+            snprintf(format, sizeof(format) - 1, "%c%c%%06d", toupper(modality[0]), toupper(modality[1]));
+          }
+        }
+
+        char filename[16];
+
         for (Json::Value::ArrayIndex i = 0; i < resource["Instances"].size(); i++)
         {
-          if (!ArchiveInstance(writer, context, resource["Instances"][i].asString()))
+          snprintf(filename, sizeof(filename) - 1, format, i);
+
+          std::string publicId = resource["Instances"][i].asString();
+
+          // This was the implementation up to Orthanc 0.7.0:
+          // std::string filename = instance["MainDicomTags"]["SOPInstanceUID"].asString() + ".dcm";
+
+          if (!ArchiveInstance(writer, context, publicId, filename))
           {
             return false;
           }
         }
+
         break;
+      }
 
       default:
         throw OrthancException(ErrorCode_InternalError);