Exemplo n.º 1
0
    bool SDLPlatform::concatenateFilePath( const FilePath & _folder, const FilePath & _fileName, WChar * _filePath, size_t _capacity )
    {
        size_t folderSize = _folder.size();
        size_t dirSize = _fileName.size();

        size_t filePathSize = folderSize + dirSize;

        if( filePathSize >= MENGINE_MAX_PATH )
        {
            return false;
        }

        Char filePath[MENGINE_MAX_PATH];
        stdex::memorycopy( filePath, 0, _folder.c_str(), folderSize );
        stdex::memorycopy( filePath, folderSize, _fileName.c_str(), dirSize );

        filePath[filePathSize] = '\0';
        //filePathSize += 1; //Null

        if( UNICODE_SERVICE( m_serviceProvider )
            ->utf8ToUnicode( filePath, filePathSize, _filePath, _capacity, nullptr ) == false )
        {
            return false;
        }

        return true;
    }
Exemplo n.º 2
0
    bool PosixFileInputStream::concatenateFilePath( const FilePath & _folder, const FilePath & _fileName, Char * _filePath, size_t _capacity ) const
    {
        size_t folderSize = _folder.size();
        size_t fileNameSize = _fileName.size();

        if( folderSize + fileNameSize > _capacity )
        {
            return false;
        }

        strcpy( _filePath, _folder.c_str() );
        strcat( _filePath, _fileName.c_str() );

        return true;
    }
Exemplo n.º 3
0
// determines the icon data; this could be either a path on disk (if we have
// a suitable icon locally), base64-encoded icon data (if the icon is embedded
// in an R package), or nothing (if we cannot determine an icon at all)
std::string iconData(const std::string& iconGroup, 
      const std::string& iconName,
      const std::string& iconPath)
{
   if (iconPath.empty())
   {
      // convert the icon name into the format of our shipped icons, which is
      // all lowercase with no whitespace (e.g. "SQL Server" => "sqlserver.png")
      std::string iconFilename(string_utils::toLower(iconName));
      iconFilename = boost::regex_replace(iconFilename,
            boost::regex("\\s"), "") + ".png";

      // the package did not supply an icon; see if there's one baked in
      FilePath path = options().rResourcesPath().childPath("connections")
         .childPath(iconGroup)
         .childPath(iconFilename);
      if (path.exists())
         return std::string("connections/") + iconGroup + "/" + iconFilename;

      if (iconGroup == "drivers")
         return std::string("connections/drivers/odbc.png");

      // didn't find anything
      return std::string();
   }

   // expand the path 
   FilePath icon = module_context::resolveAliasedPath(iconPath);
   std::string iconData;

   // ensure that the icon file exists and is a small GIF, JPG, or PNG image
   if (icon.exists() && icon.size() < kMaxIconSize &&
       (icon.hasExtensionLowerCase(".gif") ||
        icon.hasExtensionLowerCase(".png") ||
        icon.hasExtensionLowerCase(".jpg") ||
        icon.hasExtensionLowerCase(".jpeg")))
   {
      Error error = base64::encode(icon, &iconData);
      if (error)
         LOG_ERROR(error);
      else
      {
         iconData = "data:" + icon.mimeContentType("image/png") + 
                    ";base64," + iconData;
      }
   }
   return iconData;
}