Exemplo n.º 1
0
/*
 * Method:    DoCameraExport()
 * Purpose:   export the setup of a given camera
 * Comments:  none
 */
bool CMainWindow::ExportCamera(tPvHandle aHandle,const wxString& aFilename)
{
  FILE* lFile = fopen(aFilename.mb_str(wxConvUTF8),"w+");

    if(lFile)
    {
        bool            lRet = true;
        tPvAttrListPtr  lAttrs;
        tPvUint32       lCount;

        if(!PvAttrList(aHandle,&lAttrs,&lCount))
        {
            for(tPvUint32 i=0;i<lCount;i++)
                WriteAttribute(aHandle,lAttrs[i],lFile);
        }
        else
            lRet = false;

        fclose(lFile);

        return lRet;
    }
    else
        return false;
}
Exemplo n.º 2
0
// save the setup of a camera from the given file
bool SetupSave(tPvHandle aCamera,const char* aFile)
{
    FILE* lFile = fopen(aFile,"w+");
    
    if(lFile)
    {
        bool            lRet = true;
        tPvAttrListPtr  lAttrs; 
        tPvUint32       lCount;    
        
        if(!PvAttrList(aCamera,&lAttrs,&lCount))
        {
            for(tPvUint32 i=0;i<lCount;i++)
                WriteAttribute(aCamera,lAttrs[i],lFile);
        }     
        else
            lRet = false;   
        
        fclose(lFile);
        
        return lRet;
    }
    else
        return false;    
}
Exemplo n.º 3
0
void EC_DynamicComponent::SerializeTo(QDomDocument& doc, QDomElement& base_element) const
{
    QDomElement comp_element = BeginSerialization(doc, base_element);

    AttributeVector::const_iterator iter = attributes_.begin();
    while(iter != attributes_.end())
    {
        WriteAttribute(doc, comp_element, (*iter)->GetNameString().c_str(), (*iter)->ToString().c_str(), (*iter)->TypeName().c_str());
        iter++;
    }
}
Exemplo n.º 4
0
  void XmlWriter::WriteDeclaration(const Declaration& rDeclaration)
  {
    m_rStream << "<?xml";
    WriteAttribute(Attribute("version", rDeclaration.GetVersion()));

    if (!rDeclaration.GetEncoding().empty())
    {
      WriteAttribute(Attribute("encoding", rDeclaration.GetEncoding()));
    }

    if (rDeclaration.GetStandalone() == Declaration::StandaloneYes)
    {
      WriteAttribute(Attribute("standalone", "yes"));
    }
    else
    if (rDeclaration.GetStandalone() == Declaration::StandaloneNo)
    {
      WriteAttribute(Attribute("standalone", "no"));
    }

    m_rStream << " ?>";
  }
Exemplo n.º 5
0
      /// <summary>Writes a revision</summary>
      /// <param name="r">Revision.</param>
      /// <param name="parent">root node.</param>
      /// <exception cref="Logic::ArgumentNullException">Parent is nullptr</exception>
      void  BackupFileWriter::WriteRevision(const ScriptRevision& r, XmlElementPtr& parent)
      {
         REQUIRED(parent);

         // <revision title="third revision" date="2013-03-12 18:00:00" path="D:\X3 Albion Prelude\scripts\plugin.piracy.lib.logic.xml">  
         auto node = WriteElement(parent, L"revision");
         WriteAttribute(node, L"title", r.Title);
         WriteAttribute(node, L"date", (LPCWSTR)r.Date.Format(L"%Y-%m-%d %H:%M:%S"));  // yyyy-mm-dd hh:mm:ss
         WriteAttribute(node, L"path", r.FullPath.c_str());

         //  <scriptname>plugin.piracy.lib.logic</scriptname>
         //  <version>102</version>
         //  <game>X3TC</game>
         //  <description>Piracy logic library</description>
         //  <command>1019</command>
         //  <text>* Validate Parameters...</text>
         WriteElement(node, L"scriptname", r.ScriptName);
         WriteElement(node, L"version", VString(L"%d", r.Version));
         WriteElement(node, L"game", VersionString(r.Game, true));
         WriteElement(node, L"description", r.Description);
         WriteElement(node, L"command", VString(L"%d", r.CommandID));
         WriteElement(node, L"text", r.Content);
      }
Exemplo n.º 6
0
      /// <summary>Writes a Backup file</summary>
      /// <param name="f">The file</param>
      /// <exception cref="Logic::ComException">COM Error</exception>
      /// <exception cref="Logic::IOException">An I/O error occurred</exception>
      void  BackupFileWriter::WriteFile(const BackupFile& f)
      {
         // Header
         WriteInstruction(L"version='1.0' encoding='UTF-8'");
         WriteComment(L"Written by X-Studio II");

         // Root: File type
         auto root = WriteRoot(L"backups");
         WriteAttribute(root, L"type", GetString(f.Type));

         // Write revision (newest -> oldest)
         for (auto& rev : f.Revisions)
            WriteRevision(rev, root);
      }
Exemplo n.º 7
0
  void XmlWriter::WriteElement(const Element& rElement)
  {
    WriteIndent();
    m_rStream << "<" << rElement.GetPrefixName();

    // write namespaces
    for (const Namespace* pNamespace = rElement.GetFirstNamespace();
         pNamespace; pNamespace = pNamespace->GetNextSibling())
    {
      WriteNamespace(*pNamespace);
    }

    // write attributes
    for (const Attribute* pAttribute = rElement.GetFirstAttribute();
         pAttribute; pAttribute = pAttribute->GetNextSibling())
    {
      WriteAttribute(*pAttribute);
    }

    if (rElement.IsEmpty())
    {
      // end element
      m_rStream << "/>";
    }
    else
    {
      m_rStream << ">";

      if (rElement.IsLeaf())
      {
        WriteText(static_cast<const Text&>(*rElement.GetFirstChild()));
      }
      else
      {
        // write childs

        ++m_nIndent;
        for (const Node* pNode = rElement.GetFirstChild(); pNode; pNode = pNode->GetNextSibling())
        {
          WriteNode(*pNode);
        }
        --m_nIndent;
        WriteIndent();
      }
      m_rStream << "</" << rElement.GetPrefixName() << ">";
    }
  }
Exemplo n.º 8
0
/** 
* NtfsAllocateClusters 
* Allocates a run of clusters. The run allocated might be smaller than DesiredClusters.
*/
NTSTATUS
NtfsAllocateClusters(PDEVICE_EXTENSION DeviceExt,
                     ULONG FirstDesiredCluster,
                     ULONG DesiredClusters, 
                     PULONG FirstAssignedCluster, 
                     PULONG AssignedClusters)
{
    NTSTATUS Status;
    PFILE_RECORD_HEADER BitmapRecord;
    PNTFS_ATTR_CONTEXT DataContext;
    ULONGLONG BitmapDataSize;
    PUCHAR BitmapData;
    ULONGLONG FreeClusters = 0;
    RTL_BITMAP Bitmap;
    ULONG AssignedRun;
    ULONG LengthWritten;

    DPRINT1("NtfsAllocateClusters(%p, %lu, %lu, %p, %p)\n", DeviceExt, FirstDesiredCluster, DesiredClusters, FirstAssignedCluster, AssignedClusters);

    BitmapRecord = ExAllocateFromNPagedLookasideList(&DeviceExt->FileRecLookasideList);
    if (BitmapRecord == NULL)
    {
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    Status = ReadFileRecord(DeviceExt, NTFS_FILE_BITMAP, BitmapRecord);
    if (!NT_SUCCESS(Status))
    {
        ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, BitmapRecord);
        return Status;
    }

    Status = FindAttribute(DeviceExt, BitmapRecord, AttributeData, L"", 0, &DataContext, NULL);
    if (!NT_SUCCESS(Status))
    {
        ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, BitmapRecord);
        return Status;
    }

    BitmapDataSize = AttributeDataLength(DataContext->pRecord);
    BitmapDataSize = min(BitmapDataSize, 0xffffffff);
    ASSERT((BitmapDataSize * 8) >= DeviceExt->NtfsInfo.ClusterCount);
    BitmapData = ExAllocatePoolWithTag(NonPagedPool, ROUND_UP(BitmapDataSize, DeviceExt->NtfsInfo.BytesPerSector), TAG_NTFS);
    if (BitmapData == NULL)
    {
        ReleaseAttributeContext(DataContext);
        ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, BitmapRecord);
        return  STATUS_INSUFFICIENT_RESOURCES;
    }

    DPRINT1("Total clusters: %I64x\n", DeviceExt->NtfsInfo.ClusterCount);
    DPRINT1("Total clusters in bitmap: %I64x\n", BitmapDataSize * 8);
    DPRINT1("Diff in size: %I64d B\n", ((BitmapDataSize * 8) - DeviceExt->NtfsInfo.ClusterCount) * DeviceExt->NtfsInfo.SectorsPerCluster * DeviceExt->NtfsInfo.BytesPerSector);

    ReadAttribute(DeviceExt, DataContext, 0, (PCHAR)BitmapData, (ULONG)BitmapDataSize);

    RtlInitializeBitMap(&Bitmap, (PULONG)BitmapData, DeviceExt->NtfsInfo.ClusterCount);
    FreeClusters = RtlNumberOfClearBits(&Bitmap);

    if (FreeClusters < DesiredClusters)
    {
        ReleaseAttributeContext(DataContext);

        ExFreePoolWithTag(BitmapData, TAG_NTFS);
        ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, BitmapRecord);
        return STATUS_DISK_FULL;
    }
    
    // TODO: Observe MFT reservation zone

    // Can we get one contiguous run?
    AssignedRun = RtlFindClearBitsAndSet(&Bitmap, DesiredClusters, FirstDesiredCluster);

    if (AssignedRun != 0xFFFFFFFF)
    {
        *FirstAssignedCluster = AssignedRun;
        *AssignedClusters = DesiredClusters;
    }
    else
    {
        // we can't get one contiguous run
        *AssignedClusters = RtlFindNextForwardRunClear(&Bitmap, FirstDesiredCluster, FirstAssignedCluster);
        
        if (*AssignedClusters == 0)
        {
            // we couldn't find any runs starting at DesiredFirstCluster
            *AssignedClusters = RtlFindLongestRunClear(&Bitmap, FirstAssignedCluster);
        }
            
    }
                
    Status = WriteAttribute(DeviceExt, DataContext, 0, BitmapData, (ULONG)BitmapDataSize, &LengthWritten, BitmapRecord);
    
    ReleaseAttributeContext(DataContext);

    ExFreePoolWithTag(BitmapData, TAG_NTFS);
    ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, BitmapRecord);

    return Status;
}