示例#1
0
  virtual Bool Read(GeListNode* node, HyperFile* hf, LONG level) override
  {
    Bool result = super::Read(node, hf, level);
    if (!result) return result;

    // VERSION 0

    // Read the custom icon from the HyperFile.
    Bool hasImage;
    if (!hf->ReadBool(&hasImage)) return false;

    if (hasImage)
    {
      if (m_customIcon)
        m_customIcon->FlushAll();
      else
        m_customIcon = BaseBitmap::Alloc();
      if (!hf->ReadImage(m_customIcon)) return false;
    }
    else if (m_customIcon)
      BaseBitmap::Free(m_customIcon);

    // VERSION 1000

    if (level >= 1000)
    {
      if (!hf->ReadBool(&m_protected)) return false;
      if (m_protected)
      {
        if (!hf->ReadString(&m_protectionHash)) return false;
      }
    }

    return result;
  }
示例#2
0
  /// Called from Message() for MSG_DESCRIPTION_COMMAND.
  void OnDescriptionCommand(BaseObject* op, DescriptionCommand* cmdData)
  {
    BaseDocument* doc = op->GetDocument();
    const AutoUndo au(doc);
    const LONG id = cmdData->id[0].id;

    switch (id)
    {
      case NRCONTAINER_PACKUP:
        ToggleProtect(op);
        break;
      case NRCONTAINER_ICON_LOAD:
      {
        if (m_protected) break;

        // Ask the user for an image-file.
        Filename flname;
        flname.SetDirectory(GeGetC4DPath(C4D_PATH_DESKTOP));
        Bool ok = flname.FileSelect(FILESELECTTYPE_IMAGES, FILESELECT_LOAD,
            GeLoadString(IDS_SELECTICON));

        if (ok)
        {
          // Ensure the destination bitmap is allocated.
          if (!m_customIcon)
            m_customIcon = BaseBitmap::Alloc();
          else
            m_customIcon->FlushAll();

          // If it is still null here, allocation failed.
          if (!m_customIcon)
            MessageDialog(GeLoadString(IDS_INFO_OUTOFMEMORY));
          else
          {
            IMAGERESULT res = m_customIcon->Init(flname);
            if (res != IMAGERESULT_OK)
            {
              MessageDialog(IDS_INFO_INVALIDIMAGE);
              BaseBitmap::Free(m_customIcon);
            }
            else
            {
              // Scale the bitmap down to 64x64 pixels.
              BaseBitmap* dest = BaseBitmap::Alloc();
              const LONG size = CONTAINEROBJECT_ICONSIZE;
              dest->Init(size, size);
              m_customIcon->ScaleIt(dest, 256, true, true);
              BaseBitmap::Free(m_customIcon);
              m_customIcon = dest;
            }
          }
        }
        break;
      }
      case NRCONTAINER_ICON_CLEAR:
      {
        if (m_protected) break;
        if (m_customIcon)
        {
          // TODO: We possibly require a flag for removing the icon
          // on the next MSG_GETCUSTOMICON message, because Cinema
          // still references this bitmap.
          BaseBitmap::Free(m_customIcon);
        }
        break;
      }
    }
  }