Exemplo n.º 1
0
void *getData(String file, uint &length)
{
	if (usePackFile)
		return getDataFromPackFile(file, length);
	else
		return getDataFromFile(file, length);
}
Exemplo n.º 2
0
Node* CCBReader::readNodeGraphFromFile(const char *pCCBFileName, Ref *pOwner, const Size &parentSize)
{
    if (nullptr == pCCBFileName || strlen(pCCBFileName) == 0)
    {
        return nullptr;
    }

    std::string strCCBFileName(pCCBFileName);
    std::string strSuffix(".ccbi");
    // Add ccbi suffix
    if (!CCBReader::endsWith(strCCBFileName.c_str(), strSuffix.c_str()))
    {
        strCCBFileName += strSuffix;
    }

    auto fileUtils = FileUtils::getInstance();
    std::string strPath = fileUtils->fullPathForFilename(strCCBFileName);
    if (strPath.empty()) {
        return nullptr;
    }

    auto dataPtr = std::make_shared<Data>(fileUtils->getDataFromFile(strPath));
    if (dataPtr->isNull()) {
        return nullptr;
    }

    Node *ret =  this->readNodeGraphFromData(dataPtr, pOwner, parentSize);

    return ret;
}
Exemplo n.º 3
0
//--------------------------------------------------------------
void testApp::resetToDefault()
{
    curList.open("RabbitDefaults.csv");
    vector<string> data = getDataFromFile("RabbitDefaults.csv");
    readCsvString(data);
    copyElementDataToInterface();
    
    savePrevious("RabbitDefaults.csv");
}
Exemplo n.º 4
0
std::string FileUtils::getStringFromFile(const std::string& filename)
{
	Data data = getDataFromFile(filename);
	if (data.isNull())
		return "";

	std::string ret((const char*)data.getBytes());
	return ret;
}
Exemplo n.º 5
0
void FileUtilsLayer::OnClickMenu3(Ref* pSender)
{
    auto sharedFileUtils = FileUtils::getInstance();
    std::string fullPathForFilename = sharedFileUtils->fullPathForFilename("test.txt");
    log("test.txt path = %s", fullPathForFilename.c_str());
    
    Data data = sharedFileUtils->getDataFromFile(fullPathForFilename);
    //Data构建string
    std::string content1 = std::string((const char*)data.getBytes(),0,data.getSize());
    log("content1 : %s",content1.c_str());
    std::string content2 = sharedFileUtils->getStringFromFile(fullPathForFilename);
    log("content2 : %s",content2.c_str());
}
Exemplo n.º 6
0
//--------------------------------------------------------------
void testApp::loadFromFile()
{
    ofFileDialogResult loadFileName = ofSystemLoadDialog("", FALSE);
    string filename = loadFileName.getName();
    string filepath = loadFileName.getPath();
    if(filename!="")
    {        
        curList.open(filepath);
        vector<string> data = getDataFromFile(filepath);        
        readCsvString(data);
        copyElementDataToInterface();
        
    }else
    {
        //ofSystemAlertDialog("No file was selected!"); //come on dude, you get this!
    }
    
    savePrevious(loadFileName.getPath());
    
}
Exemplo n.º 7
0
void FileUtilsLayer::OnClickMenu6(Ref* pSender)
{
    
    auto sharedFileUtils = FileUtils::getInstance();
    
    sharedFileUtils->purgeCachedEntries();
    
    std::vector<std::string> searchPaths = sharedFileUtils->getSearchPaths();
    std::string writablePath = sharedFileUtils->getWritablePath();
    
    searchPaths.insert(searchPaths.begin(), "dir1");
    searchPaths.insert(searchPaths.begin()+1, writablePath);
    sharedFileUtils->setSearchPaths(searchPaths);
    
    std::string fullPathForFilename = sharedFileUtils->fullPathForFilename("test.txt");
    log("test.txt 's fullPathForFilename is : %s",fullPathForFilename.c_str());
    
    Data data = sharedFileUtils->getDataFromFile(fullPathForFilename);
    std::string content = sharedFileUtils->getStringFromFile(fullPathForFilename);
    log("File content is : %s",content.c_str());
}
Exemplo n.º 8
0
bool ComponentLua::loadAndExecuteScript()
{
    // register native functions
    auto engine = LuaEngine::getInstance();
    lua_State *l = engine->getLuaStack()->getLuaState();
    
    // load script
    auto fileUtils = FileUtils::getInstance();
    std::string fullPathOfScript = fileUtils->fullPathForFilename(_scriptFileName);
    Data data = fileUtils->getDataFromFile(fullPathOfScript);
    int error = LUA_ERRFILE;
    if(data.getSize() > 0)
        error = engine->getLuaStack()->luaLoadBuffer(l, (const char*)data.getBytes(), (int)data.getSize(), fullPathOfScript.c_str());
    if (error)
    {
        CCLOG("ComponentLua::loadAndExecuteScript: %s", lua_tostring(l, -1));
        lua_pop(l, 1);
        return false;
    }
    
    // execute script
    error = lua_pcall(l, 0, 1, 0);
    if (error)
    {
        CCLOG("ComponentLua::loadAndExecuteScript: %s", lua_tostring(l, -1));
        lua_pop(l, 1);
        return false;
    }
    
    // check the return value from lua script is a table
    int type = lua_type(l, -1);
    if (type != LUA_TTABLE)
    {
        CCLOG("%s should return a table, or the script component can not work currectly", _scriptFileName.c_str());
        return false;
    }
    
    storeLuaTable();
    return true;
}
Exemplo n.º 9
0
void TestUnicodePath::onEnter()
{
    FileUtilsDemo::onEnter();
    auto s = Director::getInstance()->getWinSize();
    auto util = FileUtils::getInstance();
    
    int x = s.width/2,
    y = s.height/5;
    Label* label = nullptr;
    
    std::string dir = "中文路径/";
    std::string filename = "测试文件.test";

    std::string act;
    auto getMsg = [&act](bool b, const std::string& path)-> std::string
    {
        char msg[512];
        snprintf((char *)msg, 512, "%s for %s path: \"%s\"", b ? "success" : "failed", act.c_str(), path.c_str());
        return std::string(msg);
    };
    
    // Check whether unicode dir should be create or not
    std::string dirPath = util->getWritablePath() + dir;
    if (!util->isDirectoryExist(dirPath))
    {
        util->createDirectory(dirPath);
    }
    
    act = "create";
    bool isExist = util->isDirectoryExist(dirPath);
    label = Label::createWithSystemFont(getMsg(isExist, dirPath), "", 12, Size(s.width, 0));
    label->setPosition(x, y * 4);
    this->addChild(label);
    
    if (isExist)
    {
        // Check whether unicode file should be create or not
        std::string filePath = dirPath + filename;
        if (! util->isFileExist(filePath))
        {
            std::string writeDataStr = " 测试字符串.";
            Data writeData;
            writeData.copy((unsigned char *)writeDataStr.c_str(), writeDataStr.size());
            util->writeDataToFile(writeData, filePath);
        }
        
        isExist = util->isFileExist(filePath);
        label = Label::createWithSystemFont(getMsg(isExist, filePath), "", 12, Size(s.width, 0));
        label->setPosition(x, y * 3);
        this->addChild(label);
        
        act = "remove";
        if (isExist)
        {
            // read file content and log it
            unsigned char* buffer = nullptr;
            Data readData = util->getDataFromFile(filePath);
            buffer = (unsigned char*)malloc(sizeof(unsigned char) * (readData.getSize() + 1));
            memcpy(buffer, readData.getBytes(), readData.getSize());
            buffer[readData.getSize()] = '\0';
            // vc can't treat unicode string correctly, don't use unicode string in code
            log("The content of file from writable path: %s", buffer);
            free(buffer);
            
            // remove test file
            label = Label::createWithSystemFont(getMsg(util->removeFile(filePath), filePath), "", 12, Size(s.width, 0));
            label->setPosition(x, y * 2);
            this->addChild(label);
        }
        
        // remove test dir
        label = Label::createWithSystemFont(getMsg(util->removeDirectory(dirPath), dirPath), "", 12, Size(s.width, 0));
        label->setPosition(x, y * 1);
        this->addChild(label);
    }
}
Exemplo n.º 10
0
//--------------------------------------------------------------
void testApp::setup(){
    bool debug = true;
    ofSetFrameRate(60);
    
    ofSetDataPathRoot("../Resources/");
    ofEnableAlphaBlending();
    ofEnableSmoothing();
    
        
    
    numberOfSkins = 4;
    curSkin = 0;
    
    numberOfElements=22;
    e = new Element*[numberOfElements];
    
    //create the elements
    //user buttons
    e[0] = new Element("User Button 1",0,440,79,28,26);  //name, type, x, y, x2, y2
    e[1] = new Element("User Button 2",0,440,111,28,26);
    e[2] = new Element("User Button 3",0,440,159,28,26);
    e[3] = new Element("User Button 4",0,440,191,28,26);
    e[4] = new Element("User Button 5",0,440,239,28,26);
    e[5] = new Element("User Button 6",0,440,271,28,26);
    
    //rotaries
    e[6] = new Element("Rotary 1",1,185,493,48,48);
    e[7] = new Element("Rotary 2",1,272,485,48,48);
    e[8] = new Element("Rotary 3",1,360,493,48,48);
    
    //cut buttons
    e[9] = new Element("Cut Button 1",0,80,637,60,46);
    e[10] = new Element("Cut Button 2",0,451,637,60,46);

    //crossfader
    e[11] = new Element("Cross Fader",2,230,609,131,101);
    
    //masterfader
    e[12] = new Element("Master Fader",3,494,77,51,142);
    
    //keyer buttons
    e[13] = new Element("Center Button 1",0,219,404,48,50);
    e[14] = new Element("Center Button 2",0,272,404,48,50);
    e[15] = new Element("Center Button 3",0,325,404,48,50);
    
    //leftovers
    e[16] = new Element("Effect Button 1",0,52,416,28,26);
    e[17] = new Element("Effect Button 2",0,157,416,28,26);
    e[18] = new Element("Effect Button 3",0,231,350,28,26);
    e[19] = new Element("Effect Button 4",0,336,350,28,26);
    e[20] = new Element("Effect Button 5",0,408,416,28,26);
    e[21] = new Element("Effect Button 6",0,513,416,28,26);
    


    ib = new InputBox();
    d = new Dropdown();
    
    layout.loadImage("Layout.jpg");

    sys.loadImage("TabSystem.jpg");
    one.loadImage("Tab1.jpg");
    two.loadImage("Tab2.jpg");
    three.loadImage("Tab3.jpg");
    four.loadImage("Tab4.jpg");
    tabSkin.loadImage("SkinTabContent.jpg");
    tabSystem.loadImage("SystemTabContent.jpg");
    LCD.loadImage("System.jpg");
    
    //check for previous existing file
    ofBuffer buffer = ofBufferFromFile("previous.txt");
    if(buffer.size()) 
    {
        string tempfile = buffer.getNextLine();
        
        curList.open(tempfile);
        if (!curList.exists()) //if we can't find the previous file, open the default
        {
            tempfile="RabbitDefaults.csv";
            curList.open(tempfile);
            savePrevious(tempfile); //and write it to the file
        }
        
        vector<string> data = getDataFromFile(tempfile); 
        readCsvString(data);
    }
    
    //create the buttons
    numberOfButtons=19;
    b = new Knop*[numberOfButtons];
    
    b[0]=new Knop(770,238,210,20);//open rabbit list or open emulator one list
    b[1]=new Knop(770,174,210,20);//open element list or open resolution list
    b[2]=new Knop(770,437,210,20); //toggle or source loss list
    b[3]=new Knop(677,93,54,21); //skin 1
    b[4]=new Knop(762,93,54,21); //skin 2
    b[5]=new Knop(847,93,54,21); //skin 3
    b[6]=new Knop(922,93,54,21); //skin 4
    b[7]=new Knop(592,93,54,21); //system
    b[8]=new Knop(24,15,64,20); //save local CSV
    b[9]=new Knop(105,15,50,20); //load local CSV
    b[10]=new Knop(945,615,55,20); //save remote CSV
    b[11]=new Knop(885,615,50,20); //load remote CSV
    b[12]=new Knop(170,15,80,20); //reset
    b[13]=new Knop(780,730,150,10); //IP
    //b[13]=new Knop(780,640,150,10); //IP
    b[14]=new Knop(773,348,200,20); //change OSC
    b[15]=new Knop(770,260,210,20);//open emulator two list
    b[16]=new Knop(770,328,210,20);//dhcp output
    b[17]=new Knop(770,348,210,20);//dhcp input 1
    b[18]=new Knop(770,368,210,20);//dhcp input 2
    
    ib->mode=1;    
}
Exemplo n.º 11
0
        bool TextureMask::init(const std::string &maskFile)
        {
            if (maskFile.empty())
            {
                return false;
            }
            
            name = maskFile;
            
            auto fileUtils = cocos2d::FileUtils::getInstance();
            if (!fileUtils->isFileExist(maskFile))
            {
                return false;
            }
            
            auto byteToInt = [](unsigned char byte) -> int
            {
                int result = 0;
                
                int nextP2 = 1;
                for (int i=0; i<8; ++i)
                {
                    if (byte & nextP2)
                    {
                        result += nextP2;
                    }
                    nextP2 <<= 1;
                }
                
                return result;
            };
            
            cocos2d::Data data = fileUtils->getDataFromFile(maskFile);
            if (data.getSize() > 0)
            {
                unsigned char* bytes = data.getBytes();
                
                //32 bits for specifying the width and height (2+2 bytes)
                width = byteToInt(bytes[0])*256 + byteToInt(bytes[1]);
                height = byteToInt(bytes[2])*256 + byteToInt(bytes[3]);
                
                int byteIndex = 4;
                int bitIndex = 0;
                int bitWeight = 1;
                mask = new bool[width*height];
                
                for (int y = height-1; y >= 0; --y)
                {
                    for (int x = 0; x<width; ++x)
                    {
                        bool masked = ((*(bytes+byteIndex)) & bitWeight);
                        mask[y*width + x] = masked;
                        
                        bitWeight <<= 1;
                        bitIndex++;
                        
                        if (bitIndex == 8)
                        {
                            bitWeight = 1;
                            bitIndex = 0;
                            ++byteIndex;
                        }
                    }
                }
                
//                for (int y=getHeight()-1; y>=0; ++y)
//                {
//                    for (int x=0; x<getWidth(); ++x)
//                    {
//                        printf("%c ", isOpaqueAt(x, y) ? 'X' : '.');
//                    }
//                    printf("\n");
//                }
                
                return true;
            }
            
            return false;
        }