Exemplo n.º 1
0
    static std::uint32_t getBinaryValue (const String& regValuePath, MemoryBlock& result, DWORD wow64Flags)
    {
        const RegistryKeyWrapper key (regValuePath, false, wow64Flags);

        if (key.key != 0)
        {
            for (unsigned long bufferSize = 1024; ; bufferSize *= 2)
            {
                result.setSize (bufferSize, false);
                DWORD type = REG_NONE;

                const LONG err = RegQueryValueEx (key.key, key.wideCharValueName, 0, &type,
                                                  (LPBYTE) result.getData(), &bufferSize);

                if (err == ERROR_SUCCESS)
                {
                    result.setSize (bufferSize, false);
                    return type;
                }

                if (err != ERROR_MORE_DATA)
                    break;
            }
        }

        return REG_NONE;
    }
String InputStream::readNextLine()
{
    MemoryBlock buffer (256);
    char* data = static_cast<char*> (buffer.getData());
    size_t i = 0;

    while ((data[i] = readByte()) != 0)
    {
        if (data[i] == '\n')
            break;

        if (data[i] == '\r')
        {
            const int64 lastPos = getPosition();

            if (readByte() != '\n')
                setPosition (lastPos);

            break;
        }

        if (++i >= buffer.getSize())
        {
            buffer.setSize (buffer.getSize() + 512);
            data = static_cast<char*> (buffer.getData());
        }
    }

    return String::fromUTF8 (data, (int) i);
}
Exemplo n.º 3
0
    //==============================================================================
    void getStateInformation (MemoryBlock& destData)
    {
        destData.setSize (sizeof (float) * getNumParameters());
        destData.fillWith (0);

        float* const p = (float*) ((char*) destData.getData());
        for (int i = 0; i < getNumParameters(); ++i)
            p[i] = getParameter(i);
    }
Exemplo n.º 4
0
var var::readFromStream (InputStream& input)
{
    const int numBytes = input.readCompressedInt();

    if (numBytes > 0)
    {
        switch (input.readByte())
        {
            case varMarker_Int:         return var (input.readInt());
            case varMarker_Int64:       return var (input.readInt64());
            case varMarker_BoolTrue:    return var (true);
            case varMarker_BoolFalse:   return var (false);
            case varMarker_Double:      return var (input.readDouble());
            case varMarker_String:
            {
                MemoryOutputStream mo;
                mo.writeFromInputStream (input, numBytes - 1);
                return var (mo.toUTF8());
            }

            case varMarker_Binary:
            {
                MemoryBlock mb (numBytes - 1);

                if (numBytes > 1)
                {
                    const int numRead = input.read (mb.getData(), numBytes - 1);
                    mb.setSize (numRead);
                }

                return var (mb);
            }

            case varMarker_Array:
            {
                var v;
                Array<var>* const destArray = v.convertToArray();

                for (int i = input.readCompressedInt(); --i >= 0;)
                    destArray->add (readFromStream (input));

                return v;
            }

            default:
                input.skipNextBytes (numBytes - 1); break;
        }
    }

    return var::null;
}
String InputStream::readString()
{
    MemoryBlock buffer (256);
    char* data = static_cast<char*> (buffer.getData());
    size_t i = 0;

    while ((data[i] = readByte()) != 0)
    {
        if (++i >= buffer.getSize())
        {
            buffer.setSize (buffer.getSize() + 512);
            data = static_cast<char*> (buffer.getData());
        }
    }

    return String::fromUTF8 (data, (int) i);
}
void FileLogger::trimFileSize (int maxFileSizeBytes) const
{
    if (maxFileSizeBytes <= 0)
    {
        logFile.deleteFile();
    }
    else
    {
        const int64 fileSize = logFile.getSize();

        if (fileSize > maxFileSizeBytes)
        {
            ScopedPointer <FileInputStream> in (logFile.createInputStream());
            jassert (in != nullptr);

            if (in != nullptr)
            {
                in->setPosition (fileSize - maxFileSizeBytes);
                String content;

                {
                    MemoryBlock contentToSave;
                    contentToSave.setSize ((size_t) maxFileSizeBytes + 4);
                    contentToSave.fillWith (0);

                    in->read (contentToSave.getData(), maxFileSizeBytes);
                    in = nullptr;

                    content = contentToSave.toString();
                }

                int newStart = 0;

                while (newStart < fileSize
                        && content[newStart] != '\n'
                        && content[newStart] != '\r')
                    ++newStart;

                logFile.deleteFile();
                logFile.appendText (content.substring (newStart), false, false);
            }
        }
    }
}
Exemplo n.º 7
0
    static void create (MemoryBlock& block, const StringPairArray& values)
    {
        if (values.getAllKeys().contains ("MidiUnityNote", true))
        {
            block.setSize ((sizeof (InstChunk) + 3) & ~3, true);
            InstChunk* const inst = static_cast <InstChunk*> (block.getData());

            inst->baseNote      = (int8) values.getValue ("MidiUnityNote", "60").getIntValue();
            inst->detune        = (int8) values.getValue ("Detune", "0").getIntValue();
            inst->lowNote       = (int8) values.getValue ("LowNote", "0").getIntValue();
            inst->highNote      = (int8) values.getValue ("HighNote", "127").getIntValue();
            inst->lowVelocity   = (int8) values.getValue ("LowVelocity", "1").getIntValue();
            inst->highVelocity  = (int8) values.getValue ("HighVelocity", "127").getIntValue();
            inst->gain          = (int16) ByteOrder::swapIfLittleEndian ((uint16) values.getValue ("Gain", "0").getIntValue());

            inst->sustainLoop.type              = ByteOrder::swapIfLittleEndian ((uint16) values.getValue ("Loop0Type", "0").getIntValue());
            inst->sustainLoop.startIdentifier   = ByteOrder::swapIfLittleEndian ((uint16) values.getValue ("Loop0StartIdentifier", "0").getIntValue());
            inst->sustainLoop.endIdentifier     = ByteOrder::swapIfLittleEndian ((uint16) values.getValue ("Loop0EndIdentifier", "0").getIntValue());
            inst->releaseLoop.type              = ByteOrder::swapIfLittleEndian ((uint16) values.getValue ("Loop1Type", "0").getIntValue());
            inst->releaseLoop.startIdentifier   = ByteOrder::swapIfLittleEndian ((uint16) values.getValue ("Loop1StartIdentifier", "0").getIntValue());
            inst->releaseLoop.endIdentifier     = ByteOrder::swapIfLittleEndian ((uint16) values.getValue ("Loop1EndIdentifier", "0").getIntValue());
        }
    }
void BinaryResources::loadFromCpp (const File& cppFileLocation, const String& cppFile)
{
    StringArray cpp;
    cpp.addLines (cppFile);

    clear();

    for (int i = 0; i < cpp.size(); ++i)
    {
        if (cpp[i].contains ("JUCER_RESOURCE:"))
        {
            StringArray tokens;
            tokens.addTokens (cpp[i].fromFirstOccurrenceOf (":", false, false), ",", "\"'");
            tokens.trim();
            tokens.removeEmptyStrings();

            const String resourceName (tokens[0]);
            const int resourceSize = tokens[1].getIntValue();
            const String originalFileName (cppFileLocation.getSiblingFile (tokens[2].unquoted()).getFullPathName());

            jassert (resourceName.isNotEmpty() && resourceSize > 0);

            if (resourceName.isNotEmpty() && resourceSize > 0)
            {
                const int firstLine = i;

                while (i < cpp.size())
                    if (cpp [i++].contains ("}"))
                        break;

                const String dataString (cpp.joinIntoString (" ", firstLine, i - firstLine)
                                            .fromFirstOccurrenceOf ("{", false, false));

                MemoryOutputStream out;
                String::CharPointerType t (dataString.getCharPointer());
                int n = 0;

                while (! t.isEmpty())
                {
                    const juce_wchar c = t.getAndAdvance();

                    if (c >= '0' && c <= '9')
                        n = n * 10 + (c - '0');
                    else if (c == ',')
                    {
                        out.writeByte ((char) n);
                        n = 0;
                    }
                    else if (c == '}')
                        break;
                }

                jassert (resourceSize < (int) out.getDataSize() && resourceSize > (int) out.getDataSize() - 2);

                MemoryBlock mb (out.getData(), out.getDataSize());
                mb.setSize ((size_t) resourceSize);

                add (resourceName, originalFileName, mb);
            }
        }
    }
}
void FileManager::loadData(const std::string & formatFile)
{
  std::ifstream pageFormat(formatFile.c_str());
  std::string tableName;
  int bufferLoc = 0;
  std::string pgSize;
  std::getline(pageFormat, pgSize);
  m_pageSize = atoi(pgSize.c_str());
  while(!std::getline(pageFormat, tableName).eof())
  {
    std::string numPartitions;
    std::string numFields;
    std::string numRecords;
    std::string numBytesPerRecord;
    std::getline(pageFormat, numPartitions, '|');
    std::getline(pageFormat, numFields, '|');
    std::getline(pageFormat, numRecords, '|');
    std::getline(pageFormat, numBytesPerRecord);
    int nPartitions = atoi(numPartitions.c_str());
    int nFields = atoi(numFields.c_str());
    int nRecords = atoi(numRecords.c_str());
    int nBytesPerRecord = atoi(numBytesPerRecord.c_str());
    int recordsPerPage = m_pageSize/nBytesPerRecord;
    int currentStart = 0;
    int* startPositions = new int[nPartitions];
    int* currentPositions = new int[nPartitions];
    int* FtoPMap = new int[nFields];
    int* FtoBMap = new int[nFields];
    int* FtoLMap = new int[nFields];
    int* PtoBMap = new int[nPartitions];
    int* PtoLMap = new int[nPartitions];
    for (int i = 0; i < nPartitions; i++)
    {
      int fLoc = 0;
      startPositions[i] = currentStart;
      currentPositions[i] = currentStart;
      std::string numFtoP;
      std::string numPBytes;
      std::getline(pageFormat, numFtoP, '|');
      int nFtoP = atoi(numFtoP.c_str());
      std::getline(pageFormat, numPBytes);
      int nPBytes = atoi(numPBytes.c_str());
      PtoLMap[i] = currentStart;
      currentStart += nPBytes*recordsPerPage;
      PtoBMap[i] = nPBytes;
      for (int j = 0; j < nFtoP; j++)
      {
	std::string field;
        std::string bytes;
        std::getline(pageFormat,field, '|');
        std::getline(pageFormat,bytes);
        int fieldNum = atoi(field.c_str());
        int fieldBytes = atoi(bytes.c_str());
        FtoPMap[fieldNum] = i;
        FtoBMap[fieldNum] = fieldBytes;
        FtoLMap[fieldNum] = fLoc;
        fLoc += fieldBytes;
      }
    }

    
    PageLayout * a = new PageLayout(nPartitions, nFields, nBytesPerRecord, FtoPMap, FtoBMap, FtoLMap, PtoLMap, PtoBMap);
    
    std::ifstream table(tableName.c_str(), std::ios::in | std::ios::binary);
    int nRecs = 0;
    std::list<int> * pages = new std::list<int>();
    MemoryBlock * data = new MemoryBlock(m_pageSize);
    char * holder = new char[recordsPerPage*nBytesPerRecord];

    for(int k = 0; k < nRecords;)
    {
      int recordsRead = 0;
      if ((nRecords - k) < recordsPerPage)
      {
        recordsRead = nRecords-k;
      }
      else
      {
        recordsRead = recordsPerPage;
      }
    
      table.read(holder,recordsRead*nBytesPerRecord);
      k+= recordsRead;
      
      int hOffset = 0;
      for (int r = 0; r < recordsRead; r++)
      {
        for (int z = 0; z < nFields; z++)
        {
	 
          int fB = FtoBMap[z];
          int currentPartition = FtoPMap[z];
          int writeLocation = currentPositions[currentPartition];
	
 
          data->put((byte*)holder + hOffset, writeLocation, fB);
	
	  currentPositions[currentPartition] = writeLocation + fB;

          hOffset += fB;
        }	
      }
      
      for(int l = 0; l < nPartitions; l++)
      {
        currentPositions[l] = startPositions[l];
      }
      pages->push_back(bufferLoc);
      data->setSize(recordsRead);
      DiskPage *dp = new DiskPage(a, data, tableName);
      bufferLoc++;
      m_files.push_back(dp);
      data = new MemoryBlock(m_pageSize);
    }
    m_namePagesMap[tableName] = pages;
    table.close();

    /*for (int k = 0; k < nRecords; k++)
    {
      if(nRecs == recordsPerPage)
      {
        pages->push_back(bufferLoc);
        bufferLoc++;
        for(int l = 0; l < nPartitions; l++)
	{
           currentPositions[l] = startPositions[l];
        }
	DiskPage * dp = new DiskPage(a,data,tableName);
	data->setSize(nRecs);
	nRecs = 0;
	data = new MemoryBlock(m_pageSize);
        m_files.push_back(dp);
      }
      
      for (int z = 0; z < nFields; z++)
      {
	
        int fB = FtoBMap[z];
        int currentPartition = FtoPMap[z];
        int writeLocation = currentPositions[currentPartition];
	
	
	char * wrt = new char[fB];
	
        table.read(wrt,fB);
        data->put((byte*)wrt, writeLocation, fB);
        delete [] wrt;
	
	currentPositions[currentPartition] = writeLocation + fB;
	
      }
      nRecs++;
    }
    pages->push_back(bufferLoc);
    data->setSize(nRecs);
    DiskPage *dp = new DiskPage(a, data, tableName);
    bufferLoc++;
    m_files.push_back(dp);
    m_namePagesMap[tableName] = pages;
    table.close();
    */    
  }
  pageFormat.close();
}