Пример #1
0
Scene::Scene(uint32 _systemsMask /* = SCENE_SYSTEM_ALL_MASK */)
	: Entity()
    , mainCamera(0)
    , drawCamera(0)
	, imposterManager(0)
    , systemsMask(_systemsMask)
    , transformSystem(0)
    , renderUpdateSystem(0)
    , lodSystem(0)
    , debugRenderSystem(0)
    , particleEffectSystem(0)
    , updatableSystem(0)
    , lightUpdateSystem(0)
    , switchSystem(0)
    , soundSystem(0)
    , actionSystem(0)
    , skyboxSystem(0)
    , staticOcclusionSystem(0)
	, materialSystem(0)
    , foliageSystem(0)
    , windSystem(0)
    , staticOcclusionDebugDrawSystem(0)
	, sceneGlobalMaterial(0)
    , isDefaultGlobalMaterial(true)
    , clearBuffers(RenderManager::ALL_BUFFERS)
{   
	CreateComponents();
	CreateSystems();

    // this will force scene to create hidden global material
    SetGlobalMaterial(NULL);
    
    SceneCache::Instance()->InsertScene(this);
}
Пример #2
0
void CEntHost::Spawn()
{
    m_iDejectedTimes = 0;
    m_flHelpProgress = 0.0f;
    m_flClimbingHold = 0.0f;
    m_bUnderAttack = false;
    m_bOnCombat = false;

    m_Components.PurgeAndDeleteElements();
    m_Attributes.PurgeAndDeleteElements();

    m_LastDamageTimer.Invalidate();

    if ( GetState() == PLAYER_STATE_NONE ) {
        SetState( PLAYER_STATE_WELCOME );
    }
    else {
        SetState( PLAYER_STATE_ACTIVE );
    }

    CreateComponents();
    CreateAttributes();

    if ( GetBotController() ) {
        GetBotController()->Spawn();
    }

    SetSquad( (CSquad *)NULL );
    SetStatus( PLAYER_STATUS_NONE );
}
Пример #3
0
MainWindow::MainWindow(std::unique_ptr<BootParameters> boot_parameters) : QMainWindow(nullptr)
{
  setWindowTitle(QString::fromStdString(Common::scm_rev_str));
  setWindowIcon(Resources::GetAppIcon());
  setUnifiedTitleAndToolBarOnMac(true);
  setAcceptDrops(true);

  InitControllers();

  CreateComponents();

  ConnectGameList();
  ConnectHost();
  ConnectToolBar();
  ConnectRenderWidget();
  ConnectStack();
  ConnectMenuBar();
  ConnectHotkeys();

  InitCoreCallbacks();

  NetPlayInit();

  if (boot_parameters)
    StartGame(std::move(boot_parameters));
}
Пример #4
0
MainWindow::MainWindow() : QMainWindow(nullptr)
{
	setWindowTitle(tr("Dolphin"));
	setWindowIcon(QIcon(Resources::GetMisc(Resources::LOGO_SMALL)));

	CreateComponents();

	ConnectGameList();
	ConnectPathsDialog();
	ConnectToolBar();
	ConnectRenderWidget();
	ConnectStack();
	ConnectMenuBar();
}
Пример #5
0
Scene::Scene()
	:   Entity()
    ,   currentCamera(0)
    ,   clipCamera(0)
//    ,   forceLodLayer(-1)
	,	imposterManager(0)
	,	entityManager(0)
	,	referenceNodeSuffixChanged(false)
{   

//	entityManager = new EntityManager();

	CreateComponents();
	CreateSystems();
}
Пример #6
0
MainWindow::MainWindow() : QMainWindow(nullptr)
{
  setWindowTitle(QString::fromStdString(scm_rev_str));
  setWindowIcon(QIcon(Resources::GetMisc(Resources::LOGO_SMALL)));
  setUnifiedTitleAndToolBarOnMac(true);
  setAcceptDrops(true);

  CreateComponents();

  ConnectGameList();
  ConnectToolBar();
  ConnectRenderWidget();
  ConnectStack();
  ConnectMenuBar();

  InitControllers();
  InitCoreCallbacks();
}
void TacticsVictory::Start()
{
    gProfiler = GetSubsystem<Profiler>();
    PROFILER_FUNC_ENTER
    Application::Start();

    gTime = GetSubsystem<Time>();

    gLog = new Urho3D::Log(gContext);
    gLog->Open("log.txt");
    gLog->SetLevel(Urho3D::LOG_DEBUG);

    RegistrationFactories();

    CreateComponents();

    gCache->AddResourceDir(gFileSystem->GetProgramDir() + "../TVData");
    gFont = gCache->GetResource<Font>(SET::MENU::FONT::NAME);

    SetWindowTitleAndIcon();
    CreateConsoleAndDebugHud();

    XMLFile *style = gCache->GetResource<XMLFile>("UI/MainStyle.xml");
    gUIRoot->SetDefaultStyle(style);
    
    InitLocalizationSystem();

    gCamera = new lCamera();

    gGUI->Create();

    gFileSelector = new FileSelector(gContext);
    gFileSelector->GetWindow()->SetModal(false);
    gFileSelector->GetWindow()->SetVisible(false);

    SubscribeToEvents();

    CreateNewGame();

    PROFILER_FUNC_LEAVE
}
Пример #8
0
/// AddImg::Measure
double AddImg::Measure(class ImageLayout *src,class ImageLayout *sr2,double in)
{
  ULONG width  = (src->WidthOf()  > sr2->WidthOf()) ?(src->WidthOf()) :(sr2->WidthOf());
  ULONG height = (src->HeightOf() > sr2->HeightOf())?(src->HeightOf()):(sr2->HeightOf());
  UWORD d1     = src->DepthOf();
  UWORD d2     = sr2->DepthOf();
  UWORD depth  = src->DepthOf() + sr2->DepthOf();
  UWORD i;

  CreateComponents(width,height,depth);
  
  for(i = 0;i < d1;i++) {
    m_pComponent[i].m_ucBits  = src->BitsOf(i);
    m_pComponent[i].m_bSigned = src->isSigned(i);
    m_pComponent[i].m_bFloat  = src->isFloat(i);
    m_pComponent[i].m_ucSubX  = m_ulWidth  / src->WidthOf(i);
    m_pComponent[i].m_ucSubY  = m_ulHeight / src->HeightOf(i);
    m_pComponent[i].m_ulWidth = src->WidthOf(i);
    m_pComponent[i].m_ulHeight= src->HeightOf(i);
    m_pComponent[i].m_ulBytesPerPixel = src->BytesPerPixel(i);
    m_pComponent[i].m_ulBytesPerRow   = src->BytesPerRow(i);
    m_pComponent[i].m_pPtr            = const_cast<APTR>(src->DataOf(i));
  }
  for(i = 0;i < d2;i++) {
    m_pComponent[i+d1].m_ucBits  = sr2->BitsOf(i);
    m_pComponent[i+d1].m_bSigned = sr2->isSigned(i);
    m_pComponent[i+d1].m_bFloat  = sr2->isFloat(i);
    m_pComponent[i+d1].m_ucSubX  = m_ulWidth  / sr2->WidthOf(i);
    m_pComponent[i+d1].m_ucSubY  = m_ulHeight / sr2->HeightOf(i);
    m_pComponent[i+d1].m_ulWidth = sr2->WidthOf(i);
    m_pComponent[i+d1].m_ulHeight= sr2->HeightOf(i);
    m_pComponent[i+d1].m_ulBytesPerPixel = sr2->BytesPerPixel(i);
    m_pComponent[i+d1].m_ulBytesPerRow   = sr2->BytesPerRow(i);
    m_pComponent[i+d1].m_pPtr            = const_cast<APTR>(sr2->DataOf(i));
  }

  SaveImage(m_pcTargetFile,m_TargetSpecs);
  
  return in;
}
/// SimpleDPX::ParseHeader
// Parse the file header of a DPX file
void SimpleDPX::ParseHeader(FILE *file,struct ImgSpecs &specs)
{
  ULONG hdr;
  char version[9];
  ULONG encryption;
  UWORD orientation;
  UWORD depth,alpha;
  ULONG width,height;
  UWORD i;
  struct ComponentLayout *cl;

  m_bLittleEndian = false;

  hdr = GetLong(file);

  if (hdr == MakeID('S','D','P','X')) {
    // This is big-endian.
    m_bLittleEndian = false;
  } else if (hdr == MakeID('X','P','D','S')) {
    m_bLittleEndian = true;
  } else {
    PostError("input file %s is not a valid DPX file",m_pcFileName);
  }

  m_ulDataOffset = GetLong(file);
  
  version[8] = 0;
  GetString(file,version,8);

  if (strcmp(version,"V1.0") && strcmp(version,"V2.0"))
    PostError("unsupported DPX version detected, only V1.0 and V2.0 are supported");

  SkipBytes(file,8); // file size and ditto key are not really needed.
  //
  // Read sizes of data structures.
  m_ulGenericSize  = GetLong(file);
  m_ulIndustrySize = GetLong(file);
  m_ulUserSize     = GetLong(file);
  //
  // Skip over the bytes we do not care about.
  SkipBytes(file,100+24+100+200+200);
  //
  // Read the encyrption key.
  encryption       = GetLong(file);
  if (encryption  != ULONG(~0UL))
    fprintf(stderr,"Warning! - DPX file %s signals encryption, output may be wrong.\n",m_pcFileName);
  //
  // Skip over the rest of the header. not needed.
  SkipBytes(file,104);
  
  //
  // Read the image orientation
  orientation      = GetWord(file);
  if (orientation >= 8)
    PostError("unknown orientation specified in DPX file %s, must be between 0 and 7",m_pcFileName);
  m_bFlipX  = (orientation & 1)?true:false;
  m_bFlipY  = (orientation & 2)?true:false;
  m_bFlipXY = (orientation & 4)?true:false;

  m_usElements     = GetWord(file);
  if (m_usElements == 0 || m_usElements > 8)
    PostError("number of image elements must be between 1 and 8 in DPX file %s",m_pcFileName);

  width  = GetLong(file);
  height = GetLong(file);
  if (m_bFlipXY) {
    m_ulHeight       = width;
    m_ulWidth        = height;
  } else {
    m_ulWidth        = width;
    m_ulHeight       = height;
  } 
  specs.ASCII        = ImgSpecs::No;
  specs.Interleaved  = (m_usElements == 1)?(ImgSpecs::Yes):(ImgSpecs::No);
  specs.YUVEncoded   = ImgSpecs::No; // changed possibly to Yes later on.
  specs.Palettized   = ImgSpecs::No;
  specs.LittleEndian = (m_bLittleEndian)?(ImgSpecs::Yes):(ImgSpecs::No);
  //
  // Image elements. All eight are always present, though only the first m_usElements contain
  // valid data.
  for(i = 0;i < 8;i++) {
    if (i < m_usElements) {
      m_Elements[i].m_ulWidth  = width;
      m_Elements[i].m_ulHeight = height;
      if (ParseElementHeader(file,m_Elements + i))
	specs.YUVEncoded   = ImgSpecs::Yes;
    } else {
      // Skip over elements we do not need
      SkipBytes(file,4*5 + 1*4 + 2*2 + 4*3 + 32);
    }
  }
  //
  // The rest is junk we do not need.
  //
  // Now compute the depth of the image.
  depth = 0;
  alpha = 0;
  for (i = 0;i < m_usElements;i++) {
    depth += m_Elements[i].m_ucDepth;
    alpha += m_Elements[i].m_ucAlphaDepth;
  }
  CreateComponents(m_ulWidth,m_ulHeight,depth + alpha);
  //
  // Now create the planes and allocate memory.
  cl = m_pComponent;
  for(i = 0;i < m_usElements;i++) {
    struct ImageElement *el = m_Elements + i;
    struct ScanElement  *sl = el->m_pScanPattern;
    while(sl) {
      struct ComponentLayout *cll; 
      UBYTE bytesperpixel      = (el->m_ucBitDepth + 7) >> 3;
      UBYTE subx               = el->m_ucSubX;
      UBYTE suby               = el->m_ucSubY;
      UWORD k                  = sl->m_usTargetChannel;
      //
      // If flipXY is set, then X and Y change their role, so flip them now.
      if (m_bFlipXY) {
	subx = el->m_ucSubY;
	suby = el->m_ucSubX;
      }
      //
      // LUMA and alpha is always encoded without subsampling.
      if (k == 0 || k == 3) {
	subx = suby = 1;
      }
      //
      // Is this an alpha component or not?
      if (k == MAX_UWORD) {
	cll   = cl + el->m_ucDepth;
	k     = el->m_ucDepth;
      } else {
	cll   = cl + k;
      }
      cll->m_ucBits            = m_Elements[i].m_ucBitDepth;
      cll->m_bSigned           = m_Elements[i].m_bSigned;
      cll->m_bFloat            = m_Elements[i].m_bFloat;
      cll->m_ucSubX            = subx;
      cll->m_ucSubY            = suby;
      cll->m_ulWidth           = (m_ulWidth  + subx - 1) / subx;
      cll->m_ulHeight          = (m_ulHeight + suby - 1) / suby;
      cll->m_ulBytesPerPixel   = bytesperpixel;
      cll->m_ulBytesPerRow     = cll->m_ulWidth * bytesperpixel;
      // Check whether we have already data for this channel. If not, allocate now.
      // As a channel may appear multiple times in one scan pattern, make sure to
      // allocate only once.
      if (el->m_pData[k] == NULL) {
	el->m_pData[k] = new UBYTE[cll->m_ulWidth * bytesperpixel * cll->m_ulHeight];
	cll->m_pPtr    = el->m_pData[k];
	sl->m_bFirst   = true;
      }
      sl->m_pData      = cll->m_pPtr;
      sl->m_pComponent = cll;
      sl = sl->m_pNext;
    }
    // Adjust the components.
    cl += el->m_ucDepth + el->m_ucAlphaDepth;
  }
}
Пример #10
0
// Test a message send????
nsresult nsEudoraCompose::SendTheMessage(nsIFile *pMailImportLocation, nsIFile **pMsg)
{
  nsresult rv = CreateComponents();
  if (NS_SUCCEEDED( rv))
    rv = CreateIdentity();
  if (NS_FAILED( rv))
    return( rv);

  // IMPORT_LOG0( "Outlook Compose created necessary components\n");

  nsString bodyType;
  nsString charSet;
  nsString headerVal;
  GetHeaderValue( m_pHeaders, m_headerLen, "From:", headerVal);
  if (!headerVal.IsEmpty())
    m_pMsgFields->SetFrom( headerVal);
  GetHeaderValue( m_pHeaders, m_headerLen, "To:", headerVal);
  if (!headerVal.IsEmpty())
    m_pMsgFields->SetTo( headerVal);
  GetHeaderValue( m_pHeaders, m_headerLen, "Subject:", headerVal);
  if (!headerVal.IsEmpty())
    m_pMsgFields->SetSubject( headerVal);
  GetHeaderValue( m_pHeaders, m_headerLen, "Content-type:", headerVal);
  bodyType = headerVal;
  ExtractType( bodyType);
  ExtractCharset( headerVal);
  // Use platform charset as default if the msg doesn't specify one
  // (ie, no 'charset' param in the Content-Type: header). As the last
  // resort we'll use the mail default charset.
  // (ie, no 'charset' param in the Content-Type: header) or if the
  // charset parameter fails a length sanity check.
  // As the last resort we'll use the mail default charset.
  if ( headerVal.IsEmpty() || (headerVal.Length() > kContentTypeLengthSanityCheck) )
  {
    CopyASCIItoUTF16(nsMsgI18NFileSystemCharset(), headerVal);
    if (headerVal.IsEmpty())
    { // last resort
      if (m_defCharset.IsEmpty())
      {
        nsString defaultCharset;
        NS_GetLocalizedUnicharPreferenceWithDefault(nsnull, "mailnews.view_default_charset",
                                                    NS_LITERAL_STRING("ISO-8859-1"), defaultCharset);
        m_defCharset = defaultCharset;
      }
      headerVal = m_defCharset;
    }
  }
  m_pMsgFields->SetCharacterSet( NS_LossyConvertUTF16toASCII(headerVal).get() );
  charSet = headerVal;
  GetHeaderValue( m_pHeaders, m_headerLen, "CC:", headerVal);
  if (!headerVal.IsEmpty())
    m_pMsgFields->SetCc( headerVal);
  GetHeaderValue( m_pHeaders, m_headerLen, "Message-ID:", headerVal);
  if (!headerVal.IsEmpty())
    m_pMsgFields->SetMessageId( NS_LossyConvertUTF16toASCII(headerVal).get() );
  GetHeaderValue( m_pHeaders, m_headerLen, "Reply-To:", headerVal);
  if (!headerVal.IsEmpty())
    m_pMsgFields->SetReplyTo( headerVal);

  // what about all of the other headers?!?!?!?!?!?!
  char *pMimeType;
  if (!bodyType.IsEmpty())
    pMimeType = ToNewCString(bodyType);
  else
    pMimeType = ToNewCString(m_bodyType);

  // IMPORT_LOG0( "Outlook compose calling CreateAndSendMessage\n");
  nsMsgAttachedFile *pAttach = GetLocalAttachments();


  /*
    l10n - I have the body of the message in the system charset,
    I need to "encode" it to be the charset for the message
    *UNLESS* of course, I don't know what the charset of the message
    should be?  How do I determine what the charset should
    be if it doesn't exist?

  */

  nsString uniBody;
  NS_CopyNativeToUnicode( nsDependentCString(m_pBody), uniBody);

  nsCString body;

  rv = nsMsgI18NConvertFromUnicode( NS_LossyConvertUTF16toASCII(charSet).get(),
                                    uniBody, body);
  if (NS_FAILED( rv)) {
    // in this case, if we did not use the default compose
    // charset, then try that.
    if (!charSet.Equals( m_defCharset)) {
      body.Truncate();
      rv = nsMsgI18NConvertFromUnicode( NS_LossyConvertUTF16toASCII(charSet).get(),
                                        uniBody, body);
    }
  }
  uniBody.Truncate();


  // See if it's a draft msg (ie, no From: or no To: AND no Cc: AND no Bcc:).
  // Eudora saves sent and draft msgs in Out folder (ie, mixed) and it does
  // store Bcc: header in the msg itself.
  nsMsgDeliverMode mode = nsIMsgSend::nsMsgDeliverNow;
  nsAutoString from, to, cc, bcc;
  rv = m_pMsgFields->GetFrom(from);
  rv = m_pMsgFields->GetTo(to);
  rv = m_pMsgFields->GetCc(cc);
  rv = m_pMsgFields->GetBcc(bcc);
  if ( from.IsEmpty() || to.IsEmpty() && cc.IsEmpty() && bcc.IsEmpty() )
    mode = nsIMsgSend::nsMsgSaveAsDraft;

  // We only get the editor interface when there's embedded content.
  // Otherwise pEditor remains NULL. That way we only import with the pseudo
  // editor when it helps.
  nsRefPtr<nsEudoraEditor>  pEudoraEditor = new nsEudoraEditor(m_pBody, pMailImportLocation);
  nsCOMPtr<nsIEditor>       pEditor;

  if (pEudoraEditor->HasEmbeddedContent())
    // There's embedded content that we need to import, so query for the editor interface
    pEudoraEditor->QueryInterface( NS_GET_IID(nsIEditor), getter_AddRefs(pEditor) );

  if (NS_FAILED( rv)) {

    rv = m_pSendProxy->CreateAndSendMessage(
                          pEditor.get(),                // pseudo editor shell when there's embedded content
                          s_pIdentity,                  // dummy identity
                          nsnull,                       // account key
                          m_pMsgFields,                 // message fields
                          PR_FALSE,                     // digest = NO
                          PR_TRUE,                      // dont_deliver = YES, make a file
                          mode,                         // mode
                          nsnull,                       // no message to replace
                          pMimeType,                    // body type
                          m_pBody,                      // body pointer
                          m_bodyLen,                    // body length
                          nsnull,                       // remote attachment data
                          pAttach,                      // local attachments
                          nsnull,                       // related part
                          nsnull,                       // parent window
                          nsnull,                       // progress listener
                          m_pListener,                  // listener
                          nsnull,                       // password
                          EmptyCString(),               // originalMsgURI
                          nsnull);                      // message compose type

  }
  else {
    rv = m_pSendProxy->CreateAndSendMessage(
                          pEditor.get(),                // pseudo editor shell when there's embedded content
                          s_pIdentity,                  // dummy identity
                          nsnull,                       // account key
                          m_pMsgFields,                 // message fields
                          PR_FALSE,                     // digest = NO
                          PR_TRUE,                      // dont_deliver = YES, make a file
                          mode,                         // mode
                          nsnull,                       // no message to replace
                          pMimeType,                    // body type
                          body.get(),                   // body pointer
                          body.Length(),                // body length
                          nsnull,                       // remote attachment data
                          pAttach,                      // local attachments
                          nsnull,                       // related part
                          nsnull,                       // parent window
                          nsnull,                       // progress listener
                          m_pListener,                  // listener
                          nsnull,                       // password
                          EmptyCString(),               // originalMsgURI
                          nsnull);                      // message compose type

  }

  // IMPORT_LOG0( "Returned from CreateAndSendMessage\n");

  if (pAttach)
    delete [] pAttach;

  EudoraSendListener *pListen = (EudoraSendListener *)m_pListener;
  if (NS_FAILED( rv)) {
    IMPORT_LOG1( "*** Error, CreateAndSendMessage FAILED: 0x%lx\n", rv);
    // IMPORT_LOG1( "Headers: %80s\n", m_pHeaders);
  }
  else {
    // wait for the listener to get done!
    PRInt32 abortCnt = 0;
    PRInt32 cnt = 0;
    PRInt32 sleepCnt = 1;
    while (!pListen->m_done && (abortCnt < kHungAbortCount)) {
      PR_Sleep( sleepCnt);
      cnt++;
      if (cnt > kHungCount) {
        abortCnt++;
        sleepCnt *= 2;
        cnt = 0;
      }
    }

    if (abortCnt >= kHungAbortCount) {
      IMPORT_LOG0( "**** Create and send message hung\n");
      IMPORT_LOG1( "Headers: %s\n", m_pHeaders);
      IMPORT_LOG1( "Body: %s\n", m_pBody);
      rv = NS_ERROR_FAILURE;
    }

  }

  if (pMimeType)
    NS_Free( pMimeType);

  if (pListen->m_location) {
    pListen->m_location->Clone(pMsg);
    rv = NS_OK;
  }
  else {
    rv = NS_ERROR_FAILURE;
    IMPORT_LOG0( "*** Error, Outlook compose unsuccessful\n");
  }

  pListen->Reset();

  return( rv);
}
Пример #11
0
// Test a message send????
nsresult nsEudoraCompose::SendTheMessage(nsIFile *pMailImportLocation, nsIFile **pMsg)
{
  nsresult rv = CreateComponents();
  if (NS_FAILED(rv))
    return rv;

  // IMPORT_LOG0("Outlook Compose created necessary components\n");

  nsString bodyType;
  nsString charSet;
  nsString headerVal;
  GetHeaderValue(m_pHeaders, m_headerLen, "From:", headerVal);
  if (!headerVal.IsEmpty())
    m_pMsgFields->SetFrom(headerVal);
  GetHeaderValue(m_pHeaders, m_headerLen, "To:", headerVal);
  if (!headerVal.IsEmpty())
    m_pMsgFields->SetTo(headerVal);
  GetHeaderValue(m_pHeaders, m_headerLen, "Subject:", headerVal);
  if (!headerVal.IsEmpty())
    m_pMsgFields->SetSubject(headerVal);
  GetHeaderValue(m_pHeaders, m_headerLen, "Content-type:", headerVal);
  bodyType = headerVal;
  ExtractType(bodyType);
  ExtractCharset(headerVal);
  // Use platform charset as default if the msg doesn't specify one
  // (ie, no 'charset' param in the Content-Type: header). As the last
  // resort we'll use the mail default charset.
  // (ie, no 'charset' param in the Content-Type: header) or if the
  // charset parameter fails a length sanity check.
  // As the last resort we'll use the mail default charset.
  if (headerVal.IsEmpty() || (headerVal.Length() > kContentTypeLengthSanityCheck))
  {
    headerVal.AssignASCII(nsMsgI18NFileSystemCharset());
    if (headerVal.IsEmpty())
    { // last resort
      if (m_defCharset.IsEmpty())
      {
        nsString defaultCharset;
        NS_GetLocalizedUnicharPreferenceWithDefault(nullptr, "mailnews.view_default_charset",
                                                    NS_LITERAL_STRING("ISO-8859-1"), defaultCharset);
        m_defCharset = defaultCharset;
      }
      headerVal = m_defCharset;
    }
  }
  m_pMsgFields->SetCharacterSet(NS_LossyConvertUTF16toASCII(headerVal).get());
  charSet = headerVal;
  GetHeaderValue(m_pHeaders, m_headerLen, "CC:", headerVal);
  if (!headerVal.IsEmpty())
    m_pMsgFields->SetCc(headerVal);
  GetHeaderValue(m_pHeaders, m_headerLen, "Message-ID:", headerVal);
  if (!headerVal.IsEmpty())
    m_pMsgFields->SetMessageId(NS_LossyConvertUTF16toASCII(headerVal).get());
  GetHeaderValue(m_pHeaders, m_headerLen, "Reply-To:", headerVal);
  if (!headerVal.IsEmpty())
    m_pMsgFields->SetReplyTo(headerVal);

  // what about all of the other headers?!?!?!?!?!?!
  char *pMimeType;
  if (!bodyType.IsEmpty())
    pMimeType = ToNewCString(NS_LossyConvertUTF16toASCII(bodyType));
  else
    pMimeType = ToNewCString(m_bodyType);

  nsCOMPtr<nsIArray> pAttach;
  GetLocalAttachments(getter_AddRefs(pAttach));
  nsEudoraEditor eudoraEditor(m_pBody, pMailImportLocation);
  nsCOMPtr<nsIArray> embeddedObjects;
  if (eudoraEditor.HasEmbeddedContent())
    eudoraEditor.GetEmbeddedObjects(getter_AddRefs(embeddedObjects));

  nsString uniBody;
  NS_CopyNativeToUnicode(nsDependentCString(m_pBody), uniBody);

  /*
    l10n - I have the body of the message in the system charset,
    I need to "encode" it to be the charset for the message
    *UNLESS* of course, I don't know what the charset of the message
    should be?  How do I determine what the charset should
    be if it doesn't exist?

  */

  nsCString body;

  rv = nsMsgI18NConvertFromUnicode(NS_LossyConvertUTF16toASCII(charSet).get(),
                                    uniBody, body);
  if (NS_FAILED(rv) && !charSet.Equals(m_defCharset)) {
    // in this case, if we did not use the default compose
    // charset, then try that.
    body.Truncate();
    rv = nsMsgI18NConvertFromUnicode(NS_LossyConvertUTF16toASCII(charSet).get(),
                                     uniBody, body);
  }
  uniBody.Truncate();


  // See if it's a draft msg (ie, no From: or no To: AND no Cc: AND no Bcc:).
  // Eudora saves sent and draft msgs in Out folder (ie, mixed) and it does
  // store Bcc: header in the msg itself.
  nsAutoString from, to, cc, bcc;
  rv = m_pMsgFields->GetFrom(from);
  rv = m_pMsgFields->GetTo(to);
  rv = m_pMsgFields->GetCc(cc);
  rv = m_pMsgFields->GetBcc(bcc);
  bool createAsDraft = from.IsEmpty() || (to.IsEmpty() && cc.IsEmpty() && bcc.IsEmpty());

  nsCOMPtr<nsIImportService> impService(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = impService->CreateRFC822Message(
                        s_pIdentity,                  // dummy identity
                        m_pMsgFields,                 // message fields
                        pMimeType,                    // body type
                        body,                         // body pointer
                        createAsDraft,
                        pAttach,                      // local attachments
                        embeddedObjects,
                        m_pListener);                 // listener

  EudoraSendListener *pListen = (EudoraSendListener *)m_pListener;
  if (NS_FAILED(rv)) {
    IMPORT_LOG1("*** Error, CreateAndSendMessage FAILED: 0x%lx\n", rv);
    // IMPORT_LOG1("Headers: %80s\n", m_pHeaders);
  }
  else {
    // wait for the listener to get done!
    int32_t abortCnt = 0;
    int32_t cnt = 0;
    int32_t sleepCnt = 1;
    while (!pListen->m_done && (abortCnt < kHungAbortCount)) {
      PR_Sleep(sleepCnt);
      cnt++;
      if (cnt > kHungCount) {
        abortCnt++;
        sleepCnt *= 2;
        cnt = 0;
      }
    }

    if (abortCnt >= kHungAbortCount) {
      IMPORT_LOG0("**** Create and send message hung\n");
      IMPORT_LOG1("Headers: %s\n", m_pHeaders);
      IMPORT_LOG1("Body: %s\n", m_pBody);
      rv = NS_ERROR_FAILURE;
    }

  }

  if (pMimeType)
    NS_Free(pMimeType);

  if (pListen->m_location) {
    pListen->m_location->Clone(pMsg);
    rv = NS_OK;
  }
  else {
    rv = NS_ERROR_FAILURE;
    IMPORT_LOG0("*** Error, Outlook compose unsuccessful\n");
  }

  pListen->Reset();

  return rv;
}
nsresult MailEwsMsgCompose::SendTheMessage(ews_msg_item * msg_item,
                                           nsIMsgSendListener *pListener)
{
    nsresult rv = CreateComponents();
    if (NS_FAILED(rv))
        return rv;

    IMPORT_LOG0("Outlook Compose created necessary components\n");
    nsString bodyType;
    nsString charSet;
    nsString headerVal;

    RecipientToString(&msg_item->from, headerVal);
    if (!headerVal.IsEmpty())
        m_pMsgFields->SetFrom(headerVal);
    else {
        RecipientToString(&msg_item->sender, headerVal);
        if (!headerVal.IsEmpty())
            m_pMsgFields->SetFrom(headerVal);
    }
  
    RecipientToString2(msg_item->to_recipients,
                       msg_item->to_recipients_count,
                       headerVal);
    if (!headerVal.IsEmpty())
        m_pMsgFields->SetTo(headerVal);

    if (msg_item->item.subject) {
        char * key = msg_item->item.subject;
        uint32_t l = strlen(key);

        /* strip "Re: " */
        nsCString modifiedSubject;
        if (mailews::NS_MsgStripRE((const char **) &key,
                          &l,
                          modifiedSubject)) {
            mailews::NS_GetLocalizedUnicharPreferenceWithDefault(nullptr,
                                                        "mailnews.localizedRe",
                                                        EmptyString(),
                                                        headerVal);
            if (headerVal.IsEmpty()) {
                headerVal.AppendLiteral("Re");
            }
            
            headerVal.AppendLiteral(": ");
        } else {
            headerVal.AssignLiteral("");
        }

        if (modifiedSubject.IsEmpty()) {
            headerVal.AppendLiteral(key);
        } else {
            headerVal.AppendLiteral(modifiedSubject.get());
        }
        
        m_pMsgFields->SetSubject(headerVal);
    }
  
    if (msg_item->item.body_type == EWS_BODY_TEXT)
        bodyType.AssignLiteral("text/plain");
    else
        bodyType.AssignLiteral("text/html");
    headerVal.AssignLiteral("UTF-8");

    // Use platform charset as default if the msg doesn't specify one
    // (ie, no 'charset' param in the Content-Type: header). As the last
    // resort we'll use the mail default charset.
    // (ie, no 'charset' param in the Content-Type: header) or if the
    // charset parameter fails a length sanity check.
    // As the last resort we'll use the mail default charset.
    if (headerVal.IsEmpty() || (headerVal.Length() > kContentTypeLengthSanityCheck))
    {
        headerVal.AssignASCII(mailews::MsgI18NFileSystemCharset());
        if (headerVal.IsEmpty())
        { // last resort
            if (m_defCharset.IsEmpty())
            {
                nsString defaultCharset;
                mailews::NS_GetLocalizedUnicharPreferenceWithDefault(nullptr, "mailnews.view_default_charset",
                                                            NS_LITERAL_STRING("ISO-8859-1"), defaultCharset);
                m_defCharset = defaultCharset;
            }
            headerVal = m_defCharset;
        }
    }
    m_pMsgFields->SetCharacterSet(NS_LossyConvertUTF16toASCII(headerVal).get());
    charSet = headerVal;

    RecipientToString2(msg_item->cc_recipients,
                       msg_item->cc_recipients_count,
                       headerVal);
    if (!headerVal.IsEmpty())
        m_pMsgFields->SetCc(headerVal);

    RecipientToString2(msg_item->bcc_recipients,
                       msg_item->bcc_recipients_count,
                       headerVal);
    if (!headerVal.IsEmpty())
        m_pMsgFields->SetBcc(headerVal);

    if (msg_item->internet_message_id)
        m_pMsgFields->SetMessageId(msg_item->internet_message_id);
  
    RecipientToString2(msg_item->reply_to,
                       msg_item->reply_to_count,
                       headerVal);
    if (!headerVal.IsEmpty())
        m_pMsgFields->SetReplyTo(headerVal);

    if (msg_item->references)
        m_pMsgFields->SetReferences(msg_item->references);
  
    // what about all of the other headers?!?!?!?!?!?!
    char *pMimeType;
    if (!bodyType.IsEmpty())
        pMimeType = ToNewCString(NS_LossyConvertUTF16toASCII(bodyType));
    else
        pMimeType = strdup("text/plain");

    nsCOMPtr<nsIArray> pAttach;
    GetLocalAttachments(getter_AddRefs(pAttach));

    nsString uniBody;
    NS_CopyNativeToUnicode(nsDependentCString(msg_item->item.body), uniBody);

    /*
      l10n - I have the body of the message in the system charset,
      I need to "encode" it to be the charset for the message
      *UNLESS* of course, I don't know what the charset of the message
      should be?  How do I determine what the charset should
      be if it doesn't exist?

    */

    nsCString body;

    rv = mailews::MsgI18NConvertFromUnicode(NS_LossyConvertUTF16toASCII(charSet).get(),
                                     uniBody, body);
    if (NS_FAILED(rv) && !charSet.Equals(m_defCharset)) {
        // in this case, if we did not use the default compose
        // charset, then try that.
        body.Truncate();
        rv = mailews::MsgI18NConvertFromUnicode(NS_LossyConvertUTF16toASCII(charSet).get(),
                                         uniBody, body);
    }
    uniBody.Truncate();


    // See if it's a draft msg (ie, no From: or no To: AND no Cc: AND no Bcc:).
    // MailEws saves sent and draft msgs in Out folder (ie, mixed) and it does
    // store Bcc: header in the msg itself.
    nsAutoString from, to, cc, bcc;
    rv = m_pMsgFields->GetFrom(from);
    rv = m_pMsgFields->GetTo(to);
    rv = m_pMsgFields->GetCc(cc);
    rv = m_pMsgFields->GetBcc(bcc);
    bool createAsDraft = from.IsEmpty() || (to.IsEmpty() && cc.IsEmpty() && bcc.IsEmpty());

    nsCOMPtr<nsIImportService> impService(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    rv = impService->CreateRFC822Message(
        s_pIdentity,                  // dummy identity
        m_pMsgFields,                 // message fields
        pMimeType,                    // body type
        body,                         // body pointer
        createAsDraft,
        pAttach,                      // local attachments
        nullptr, //embededObjects
        pListener);                 // listener

    if (NS_FAILED(rv)) {
        IMPORT_LOG1("*** Error, CreateAndSendMessage FAILED: 0x%lx\n", (int)rv);
    }

    if (pMimeType)
        NS_Free(pMimeType);
    return rv;
}
Пример #13
0
/// SimplePgx::LoadImage
// Load an image from an already open (binary) PPM or PGM file
// Throw in case the file should be invalid.
void SimplePgx::LoadImage(const char *basename,struct ImgSpecs &specs)
{
  struct ComponentName   *name;
  struct ComponentLayout *layout;
  ULONG w,h;
  UWORD depth = 0;
  char buffer[256 + 4];
  bool embedded = false; // if the header is embedded in the file and the file names are generated.
  bool single   = false;
  File file(basename,"r");
  //
  if (m_pComponent) {
    PostError("Image is already loaded.\n");
  }
  //
  // Read the names, one after another.
  do {
    size_t len;
    if (!embedded) {
      if (fgets(buffer,255,file) == NULL) {
	break;
      }
    }
    //
    // Is this probably not the header file but the first data file?
    if (depth == 0 && buffer[0] == 'P' && (buffer[1] == 'G' || buffer[1] == 'F') && buffer[2] == ' ') {
      const char *dot = strrchr(basename,'.');
      if (dot && !strcmp(dot,".pgx") && dot - 1 > basename && dot < basename + 256) {
	if (dot[-1] == '0') {
	  embedded = true;
	} else {
	  embedded = true;
	  single   = true;
	}
      }
    }
    // If embedded, try to algorithmically determine the next file name by replacing the digits before
    // the basename.
    if (embedded) {
      if (single) {
	if (depth != 0)
	  break;
	strcpy(buffer,basename);
      } else {
	FILE *tmp;
	const char *dot  = strrchr(basename,'.');
	int dotpos = dot - 1 - basename;
	memcpy(buffer,basename,dotpos);
	sprintf(buffer+dotpos,"%d.pgx",depth);
	tmp = fopen(buffer,"rb");
	if (!tmp)
	  break;
	fclose(tmp);
      }
    }
    //
    // Check for a terminating /n and remove it.
    len = strlen(buffer);
    while(len > 0) {
      if (isspace(buffer[len-1])) {
	buffer[--len] = '\0';
      } else break;
    }
    if (len > 0) {
      struct ComponentName **last = &m_pNameList;
      name  = new struct ComponentName(buffer);
      // Yup, there's really a file name left, attach it to the end.
      while(*last) {
	last = &((*last)->m_pNext);
      }
      *last = name;
      depth++;
    }
  } while(true);
  //
  if (ferror(file)) {
    PostError("failure on reading the pgx component list file %s\n",basename);
  }
  //
  // Now parse the headers.
  name = m_pNameList;
  while(name) {
    char *data,*last,*dptr;
    FILE *header;
	size_t len;
    int depth;
    // Copy the name over, and replace the .raw with .h.
    strncpy(buffer,name->m_pName,256);
    if (!embedded) {
      len = strlen(buffer);
      if (len > 4) {
	if (!strcmp(buffer + len - 4,".raw"))
	  buffer[len - 4] = 0;
      }
      strcat(buffer,".h");
    }
    header = fopen(buffer,"r");

    if (header == NULL) {
      PostError("cannot open the pgx header file %s\n",buffer);
    }
    //
    // Read the header into the file. This should be one
    // single stream.
    data = fgets(buffer,255,header);
    fclose(header);
    if (data == NULL) {
      PostError("failed to read the pgx header file.\n");
    }
    //
    // Check whether the file header is fine. We only
    // support big endian PGX files, this is enough for
    // part4 compliance. We could also support
    // little endian files.
    if (!memcmp(buffer,"PF LM ",6)) {
      name->m_bLE        = true;
      specs.LittleEndian = ImgSpecs::Yes;
      name->m_bFloat     = true;
    } else if (!memcmp(buffer,"PF ML ",6)) {
      specs.LittleEndian = ImgSpecs::No;
      name->m_bFloat     = true;
    } else if (!memcmp(buffer,"PG LM ",6)) {
      specs.LittleEndian = ImgSpecs::Yes;
      name->m_bLE        = true;
    } else if (!memcmp(buffer,"PG ML ",6)) {
      specs.LittleEndian = ImgSpecs::No;
    } else {
      PostError("invalid PGX file, PGX identifier %s broken",buffer);
    }
    // The next must be + or -, defining the sign.
    dptr = buffer + 7;
    if (buffer[6] == '+' || buffer[6] == ' ') {
      name->m_bSigned = false;
    } else if (buffer[6] == '-') {
      name->m_bSigned = true;
    } else if (buffer[6] >= '0' && buffer[6] <= '9') {
      // Signedness not indicated, this is the depth. Assume unsigned.
      name->m_bSigned = false;
      dptr--;
    } else {
      PostError("invalid PGX file, PGX signedness %c broken\n",buffer[6]);
    }
    // Get the bit depth of the component.
    depth = strtol(dptr,&last,10);
    // Currently, not more than 16bpp.
    if (last <= dptr || last[0] != ' ' || depth <= 0 || depth > 64) {
      PostError("invalid PGX file, bit depth invalid\n");
    }
    name->m_ucDepth = depth;
    //
    data = last + 1;
    name->m_ulWidth = strtol(data,&last,10);
    if (last <= data || last[0] != ' ') {
      PostError("invalid PGX file, width invalid\n");
    }
    data = last + 1;
    name->m_ulHeight = strtol(data,&last,10);
    if (last <= data || !isspace(last[0])) {
      PostError("invalid PGX file, height invalid\n");
    }
    //
    // All done with this file. Get the next.
    name = name->m_pNext;
  }
  //
  // Find the maximum width, height as base for the
  // subsampling. 
  name = m_pNameList;
  w    = 0;
  h    = 0;
  while(name) {
    if (name->m_ulWidth > w)
      w = name->m_ulWidth;
    if (name->m_ulHeight > h)
      h = name->m_ulHeight;
    //
    name = name->m_pNext;
  }
  //
  // Setup the component list and the subsampling.
  CreateComponents(w,h,depth);
  //
  specs.ASCII      = ImgSpecs::No;
  specs.Palettized = ImgSpecs::No;
  //
  // Fill in the subsampling.
  name   = m_pNameList;
  layout = m_pComponent;
  while(name) {
    ULONG size = name->m_ulWidth * name->m_ulHeight;
    UBYTE bypp = (name->m_ucDepth + 7) >> 3;
    FILE *raw;
    // Special hack for half-float: Store as float.
    if (name->m_ucDepth == 16 && name->m_bFloat)
      bypp = 4;
    //
    layout->m_ucBits          = name->m_ucDepth;
    layout->m_bSigned         = name->m_bSigned;
    layout->m_bFloat          = name->m_bFloat;
    // this is only an approximation. Urgh. We don't know the left edge...
    layout->m_ucSubX          = w / name->m_ulWidth;
    // ditto. Same problem.  
    layout->m_ucSubY          = h / name->m_ulHeight; 
    layout->m_ulWidth         = name->m_ulWidth;
    layout->m_ulHeight        = name->m_ulHeight;
    layout->m_ulBytesPerRow   = bypp * name->m_ulWidth;
    layout->m_ulBytesPerPixel = bypp;
    // allocate memory for this component.
    layout->m_pPtr            = name->m_pData = new UBYTE[name->m_ulWidth * name->m_ulHeight * bypp];
    //
    // Now read the data from the raw file.
    raw  = fopen(name->m_pName,"rb");
    if (raw == NULL) {
      PostError("unable to open the PGX raw data file %s\n",name->m_pName);
    }
    if (embedded) {
      int c;
      // Read off the first line.
      while((c = fgetc(raw)) != -1 && c != '\n'){}
      //
      if (c == -1) {
	fclose(raw);
	PostError("invalid data header in embedded PGX file %s\n",name->m_pName);
      }
    }
    // If we have here single bytes, we can parse off the file completely.
    if (name->m_ucDepth <= 8) {
      if (fread(name->m_pData,1,size,raw) != size) {
	fclose(raw);
	PostError("incomplete PGX data file %s\n",name->m_pName);
      }
    } else if (name->m_ucDepth == 16 && name->m_bFloat) {
      // The hacky case for half-float support.
      // We must read the data byte by byte due to endian issues.
      FLOAT *data = (FLOAT *)name->m_pData;
      while(size) {
	int in1,in2;
	in1 = fgetc(raw);
	in2 = fgetc(raw);
	if (in1 < 0 || in2 < 0) {
	  fclose(raw);
	  PostError("incomplete PGX data file %s\n",name->m_pName);
	}
	if (name->m_bLE) {
	  *data++ = H2F((in2 << 8) | in1); // is little endian
	} else {
	  *data++ = H2F((in1 << 8) | in2); // is big endian
	}
	size--;
      }
    } else if (name->m_ucDepth <= 16) {
      // We must read the data byte by byte due to endian issues.
      UWORD *data = (UWORD *)name->m_pData;
      while(size) {
	int in1,in2;
	in1 = fgetc(raw);
	in2 = fgetc(raw);
	if (in1 < 0 || in2 < 0) {
	  fclose(raw);
	  PostError("incomplete PGX data file %s\n",name->m_pName);
	}
	if (name->m_bLE) {
	  *data++ = (in2 << 8) | in1; // is little endian
	} else {
	  *data++ = (in1 << 8) | in2; // is big endian
	}
	size--;
      }
    } else if (name->m_ucDepth <= 32) { 
      ULONG *data = (ULONG *)name->m_pData;
      while(size) {
	int in1,in2,in3,in4;
	in1 = fgetc(raw);
	in2 = fgetc(raw);
	in3 = fgetc(raw);
	in4 = fgetc(raw);
	if (in1 < 0 || in2 < 0 || in3 < 0 || in4 < 0) {
	  fclose(raw);
	  PostError("incomplete PGX data file %s\n",name->m_pName);
	}
	if (name->m_bLE) {
	  *data++ = (ULONG(in4) << 24) | (ULONG(in3) << 16) | (ULONG(in2) << 8) | ULONG(in1); // is little endian
	} else {
	  *data++ = (ULONG(in1) << 24) | (ULONG(in2) << 16) | (ULONG(in3) << 8) | ULONG(in4); // is big endian
	}
	size--;
      }
    } else if (name->m_ucDepth <= 64) {  
      UQUAD *data = (UQUAD *)name->m_pData;
      while(size) {
	int in1,in2,in3,in4,in5,in6,in7,in8;
	in1 = fgetc(raw);
	in2 = fgetc(raw);
	in3 = fgetc(raw);
	in4 = fgetc(raw);
	in5 = fgetc(raw);
	in6 = fgetc(raw);
	in7 = fgetc(raw);
	in8 = fgetc(raw);
	if (in1 < 0 || in2 < 0 || in3 < 0 || in4 < 0 || in5 < 0 || in6 < 0 || in7 < 0 || in8 < 0) {
	  fclose(raw);
	  PostError("incomplete PGX data file %s\n",name->m_pName);
	}
	if (name->m_bLE) {
	  *data++ = (UQUAD(in8) << 56) | (UQUAD(in7) << 48) | (UQUAD(in6) << 40) | (UQUAD(in5) << 32) |
	    (UQUAD(in4) << 24) | (UQUAD(in3) << 16) | (UQUAD(in2) << 8) | UQUAD(in1); // is little endian
	} else {
	  *data++ = (UQUAD(in1) << 56) | (UQUAD(in2) << 48) | (UQUAD(in3) << 40) | (UQUAD(in4) << 32) |
	    (UQUAD(in5) << 24) | (UQUAD(in6) << 16) | (UQUAD(in7) << 8) | UQUAD(in8); // is big endian
	}
	size--;
      }
    }
    if (ferror(raw)) {
      fclose(raw);
      PostError("unable to read PGX data file %s\n",name->m_pName);
    }
    fclose(raw);
    name = name->m_pNext;
    layout++;
  }
}