void FilesystemBinding::CreateTempDirectory(const ValueList& args, KValueRef result)
	{
		try
		{
			Poco::TemporaryFile tempDir;
			tempDir.keepUntilExit();
			tempDir.createDirectory();

			ti::File* jsFile = new ti::File(tempDir.path());
			result->SetObject(jsFile);
		}
		catch (Poco::Exception& exc)
		{
			throw ValueException::FromString(exc.displayText());
		}
	}
Exemple #2
0
    static std::string& BlankURLToFilePath()
    {
        static std::string path;
        if (path.empty())
        {
            Poco::TemporaryFile temp;
            temp.keepUntilExit();
            path = temp.path();

            std::string contents("<html><body></body></html>");
            Poco::FileStream stream;
            stream.open(path, std::ios::out);
            stream.write(contents.c_str(), contents.size());
            stream.close();
        }
        return path;
    }
Exemple #3
0
bool File::load(string path) {
	//load the blend file into the stream
	if(file.is_open())
		file.close();
	file.open(ofToDataPath(path, true).c_str(), ios::binary);
	//info should contain blender now, if not it is compressed
	string info = readString(7);

	//check if the file is gzipped
	if(info != "BLENDER") {
		seek(0);

		//unzip the blend file to a temp file and reload
		Poco::InflatingInputStream inflater(file, Poco::InflatingStreamBuf::STREAM_GZIP);

		Poco::TemporaryFile tempFile;
		tempFile.keepUntilExit();
		std::ofstream out(tempFile.path().c_str(), ios::binary);
		Poco::StreamCopier::copyStream( inflater, out);
		out.close();

		file.close();
		file.open(tempFile.path().c_str(), ios::binary);
		info = readString(7);

		if(info != "BLENDER") {
			ofLogWarning(OFX_BLENDER) << "Could not read blend file " << path;
		} else {
			ofLogVerbose(OFX_BLENDER) << "Blend file is gzipped, temporarily decompressed contents to " << tempFile.path();
		}
	}

	//now extract the rest of the header data
	string tempString = readString(1);

	if(tempString == "-")
		pointerSize = 8;
	else if(tempString == "_")
		pointerSize = 4;
	//ofLogVerbose(OFX_BLENDER) << "Pointer Size is " << pointerSize;

	if(pointerSize == 4) {
		readPointer = std::bind(&File::read<unsigned int>, this);
	} else {
		readPointer = std::bind(&File::read<unsigned long>, this);
	}

	bool littleEndianness;
	char structPre = ' ';
	tempString = readString(1);
	if(tempString == "v") {
		littleEndianness = true;
		structPre = '<';
	} else if(tempString == "V") {
		littleEndianness = false;
		structPre = '>';
	}
	//ofLogVerbose(OFX_BLENDER) << "Struct pre is " << structPre;
	//ofLogVerbose(OFX_BLENDER) << "Little Endianness is " << littleEndianness;

	//version
	version = readString(3);

	//now go through all them blocks
	blocks.push_back(Block(this));

	//read the first block
	readHeader(blocks.back());

	while(blocks.back().code != "DNA1" && blocks.back().code != "SDNA") {

		//skip the block data
		file.seekg(file.tellg() + streamoff(blocks.back().size));

		//read a new block
		blocks.push_back(Block(this));
		readHeader(blocks.back());
	}

	//advance
	readString(4);
	readString(4);

	//NAMES
	unsigned int numNames = read<unsigned int>();
	for(unsigned int i=0; i<numNames; i++) {
		catalog.names.push_back(DNAName(readString(0)));
	}
	align(file);

	//TYPES
	readString(4);
	unsigned int numTypes = read<unsigned int>();
	//cout << "FOUND TYPES " << numTypes << endl;
	for(unsigned int i=0; i<numTypes; i++) {
		catalog.types.push_back(DNAType(readString(0), i));
	}
	align(file);

	//TYPE LENGTHS
	readString(4);;
	for(unsigned int i=0; i<numTypes; i++) {
		catalog.types[i].size = read<unsigned short>();
		if(catalog.types[i].size == 0) //assume it is a pointer
			catalog.types[i].size = pointerSize;
	}
	align(file);

	//STRUCTURES
	readString(4);
	unsigned int numStructs = read<unsigned int>();
	//cout << "FOUND STRUCTURES " << numStructs << endl;
	for(unsigned int i=0; i<numStructs; i++) {
		//get the type
		unsigned int index = read<unsigned short>();
		DNAType* type = &catalog.types[index];
		catalog.structures.push_back(DNAStructure(type));
		DNAStructure& structure = catalog.structures.back();

		//get the fields for the structure
		unsigned short numFields = read<unsigned short>();
		unsigned int curOffset = 0;
		for(unsigned int j=0; j<numFields; j++) {
			unsigned short typeIndex = read<unsigned short>();
			unsigned short nameIndex = read<unsigned short>();
			DNAType* type = &catalog.types[typeIndex];
			DNAName* name = &catalog.names[nameIndex];
			structure.fields.push_back(DNAField(type, name, curOffset));

			//if the field is a pointer, then only add the pointer size to offset
			bool offsetSet = false;
			if(structure.fields.back().isPointer) {
				int amount = 0;
				if(structure.fields.back().isArray) {
					amount = structure.fields.back().arraySizes[0];
				}
				if(amount == 0)
					amount = 1;
				curOffset += (pointerSize * amount);
				offsetSet = true;
			} else if(structure.fields.back().isArray) { //arrays add n times the size to offset
				float multi = 0;
				for(int s: structure.fields.back().arraySizes) {
					if(s!=-1) {
						if(multi == 0)
							multi += s;
						else
							multi *= s;
					}
				}

				if(multi != 0)
					offsetSet = true;

				curOffset += type->size * multi;
			}
			if(!offsetSet) {
				curOffset += type->size;
			}
		}
	}
	align(file);

	//now link all structures with the File Blocks
	vector<Block>::iterator it = blocks.begin();
	while(it != blocks.end()) {
		(*it).structure = &catalog.structures[(*it).SDNAIndex];
		it++;
	}

	ofLogVerbose(OFX_BLENDER) << "Loaded \"" << path << "\" - Blender version is " <<  version;

	return true;
}