# HG changeset patch # User Sebastien Jodogne # Date 1383122061 -3600 # Node ID bcf5c9a767a9ee423c6f4c455478f3b1a958e85e # Parent a9ea5e311ec56aa916423022444e93de29306804 use filenames with 8 characters in ZIP files for maximum compatibility diff -r a9ea5e311ec5 -r bcf5c9a767a9 NEWS --- 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) diff -r a9ea5e311ec5 -r bcf5c9a767a9 OrthancServer/OrthancRestApi.cpp --- 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);