Imported Upstream version 1.9.8
[platform/upstream/doxygen.git] / src / resourcemgr.cpp
index c6db5d3..a6f4a5c 100644 (file)
 
 #include <map>
 #include <string.h>
-#include <fstream>
+#include <cstdint>
 
 #include "resourcemgr.h"
 #include "util.h"
 #include "version.h"
 #include "message.h"
 #include "config.h"
+#include "portable.h"
 
 class ResourceMgr::Private
 {
@@ -53,13 +54,12 @@ void ResourceMgr::registerResources(std::initializer_list<Resource> resources)
 
 bool ResourceMgr::writeCategory(const QCString &categoryName,const QCString &targetDir) const
 {
-  for (auto &kv : p->resources)
+  for (auto &[name,res] : p->resources)
   {
-    Resource &res = kv.second;
     if (res.category==categoryName)
     {
-      std::string pathName = targetDir.str()+"/"+res.name;
-      std::ofstream f(pathName,std::ofstream::out | std::ofstream::binary);
+      QCString pathName = targetDir+"/"+res.name;
+      std::ofstream f = Portable::openOutputStream(pathName);
       bool ok=false;
       if (f.is_open())
       {
@@ -78,9 +78,7 @@ bool ResourceMgr::writeCategory(const QCString &categoryName,const QCString &tar
 
 bool ResourceMgr::copyResourceAs(const QCString &name,const QCString &targetDir,const QCString &targetName,bool append) const
 {
-  std::string pathName = targetDir.str()+"/"+targetName.str();
-  std::ios_base::openmode mode = std::ofstream::out | std::ofstream::binary;
-  if (append) mode |= std::ofstream::app;
+  QCString pathName = targetDir+"/"+targetName;
   const Resource *res = get(name);
   if (res)
   {
@@ -88,7 +86,7 @@ bool ResourceMgr::copyResourceAs(const QCString &name,const QCString &targetDir,
     {
       case Resource::Verbatim:
         {
-          std::ofstream f(pathName,mode);
+          std::ofstream f = Portable::openOutputStream(pathName,append);
           bool ok=false;
           if (f.is_open())
           {
@@ -105,9 +103,9 @@ bool ResourceMgr::copyResourceAs(const QCString &name,const QCString &targetDir,
         {
           QCString n = name;
           n = n.left(n.length()-4)+".png"; // replace .lum by .png
-          const uchar *data = res->data;
-          ushort width   = (data[0]<<8)+data[1];
-          ushort height  = (data[2]<<8)+data[3];
+          const uint8_t *data = res->data;
+          uint16_t width   = (data[0]<<8)+data[1];
+          uint16_t height  = (data[2]<<8)+data[3];
           ColoredImgDataItem images[2];
           images[0].name    = n.data();
           images[0].width   = width;
@@ -123,9 +121,9 @@ bool ResourceMgr::copyResourceAs(const QCString &name,const QCString &targetDir,
         {
           QCString n = name;
           n = n.left(n.length()-5)+".png"; // replace .luma by .png
-          const uchar *data = res->data;
-          ushort width   = (data[0]<<8)+data[1];
-          ushort height  = (data[2]<<8)+data[3];
+          const uint8_t *data = res->data;
+          uint16_t width   = (data[0]<<8)+data[1];
+          uint16_t height  = (data[2]<<8)+data[3];
           ColoredImgDataItem images[2];
           images[0].name    = n.data();
           images[0].width   = width;
@@ -139,7 +137,7 @@ bool ResourceMgr::copyResourceAs(const QCString &name,const QCString &targetDir,
         break;
       case Resource::CSS:
         {
-          std::ofstream t(pathName,mode);
+          std::ofstream t = Portable::openOutputStream(pathName,append);
           if (t.is_open())
           {
             QCString buf(res->size+1);
@@ -159,7 +157,7 @@ bool ResourceMgr::copyResourceAs(const QCString &name,const QCString &targetDir,
         break;
       case Resource::SVG:
         {
-          std::ofstream t(pathName,mode);
+          std::ofstream t = Portable::openOutputStream(pathName,append);
           if (t.is_open())
           {
             QCString buf(res->size+1);