Пример #1
0
bool Controller::construct() {
  MAExtent screenSize = maGetScrSize();
  _output = new AnsiWidget(this, EXTENT_X(screenSize), EXTENT_Y(screenSize));
  _output->construct();
  _initialFontSize = _output->getFontSize();

  _runMode = init_state;
  opt_ide = IDE_NONE;
  opt_graphics = true;
  opt_pref_bpp = 0;
  opt_nosave = true;
  opt_interactive = true;
  opt_verbose = false;
  opt_quiet = true;
  opt_command[0] = 0;
  opt_usevmt = 0;
  os_graphics = 1;

  // restore the selected font scale and path
  MAHandle data = maCreatePlaceholder();
  MAHandle store = maOpenStore(PACKAGE, 0);

  if (store != STERR_NONEXISTENT) {
    if (maReadStore(store, data) == RES_OK) {
      int offset = 0;
      int storeVersion;
      int pathLength;
      char path[FILENAME_MAX + 1];
      
      maReadData(data, &storeVersion, offset, sizeof(int));
      offset += sizeof(int);

      if (storeVersion == STORE_VERSION) {
        maReadData(data, &_fontScale, offset, sizeof(int));
        offset += sizeof(int);        

        if (_fontScale != 100) {
          int fontSize = (_initialFontSize * _fontScale / 100);
          _output->setFontSize(fontSize);
        }
        
        maReadData(data, &pathLength, offset, sizeof(int));
        maReadData(data, &path, offset+ sizeof(int), pathLength);
        if (pathLength > 1) {
          chdir(path);
        }
      }
    }
    maCloseStore(store, 0);
  }
  maDestroyPlaceholder(data);

  return true;
}
Пример #2
0
static MA_FILE* openReadWrite(const char *filename, int modeFlags) {
	MA_FILE *file;
	char sfilename[1024];
	MAHandle store;
	MAHandle data=0;
	int size = BUFFER_SIZE;
	int realLength = 0;

	filterStoreName(sfilename, 1024, filename);
	store = maOpenStore(sfilename, MAS_CREATE_IF_NECESSARY);
	if(!store) return NULL;

	file = (MA_FILE*) malloc(sizeof(MA_FILE));
	if(modeFlags&(MODE_READ|MODE_WRITE)) 
		file->type = TYPE_READWRITE;
	else 
		file->type = TYPE_WRITEONLY;
	file->modeFlags = modeFlags;
	
	if(modeFlags&(MODE_READ|MODE_APPEND)) {
		data = maCreatePlaceholder();
		maReadStore(store, data);
		realLength = size = maGetDataSize(data);
	}

	file->buffer = (unsigned char*) malloc(size);
	if(!file->buffer) {
		free(file->buffer);
		free(file);
		return NULL;
	}

	file->bufferStart = 0;
	file->bufferSize = size;
	file->volEntry = (VolumeEntry*) malloc(sizeof(VolumeEntry));
	file->filePtr = 0;
	file->volEntry->dataOffset = 0;
	file->volEntry->dataLength = realLength;
	file->resultFlags = 0;

	if(modeFlags&(MODE_READ|MODE_APPEND)) {
		maReadData(data, file->buffer, 0, size);
		maDestroyObject(data);
		if(modeFlags&MODE_APPEND) {
			file->filePtr = size;
		}
	}

	file->store = store;
	file->volEntry->type=VOL_TYPE_FILE;

	return file;
}
Пример #3
0
	//TestCase
	virtual void start() {
		printf("Testing stores.\n");
		//open, cin
		MAHandle store = maOpenStore("test.store", MAS_CREATE_IF_NECESSARY);
		TI(store);

		//write
		TI(maWriteStore(store, CLIENT_DATA));

		//close
		maCloseStore(store, 0);

		//open
		store = maOpenStore("test.store", 0);
		TI(store);

		//read
		MAHandle data = maCreatePlaceholder();
		maReadStore(store, data);

		//compare
		char storeBuf[DATA_SIZE], clientBuf[DATA_SIZE];
		maReadData(data, storeBuf, 0, DATA_SIZE);
		maReadData(CLIENT_DATA, clientBuf, 0, DATA_SIZE);
		if(memcmp(storeBuf, clientBuf, DATA_SIZE) != 0) {
			assert(name, false);
			suite->runNextCase();
			return;
		}

		//close, delete
		maCloseStore(store, true);
		maDestroyObject(data);

		//open, should fail
		store = maOpenStore("test.store", 0);
		if(store >= 0) {
			maCloseStore(store, true);
			assert(name, false);
			suite->runNextCase();
			return;
		}

		printf("Store test succeded!\n");

		//succeed
		assert(name, true);
		suite->runNextCase();
	}
Пример #4
0
void ImageCache::process(bool afterFin)
{
	//Check to see if the cache can process this request at this time
	if(mIsBusy) return;
	//Check to see if there are any outstanding requests
	if(mRequests.size() == 0)
	return;
	//Set the mIsBusy flag, so we don't try to do too much at once
	mIsBusy = true;
	//Get the next image request from the queue

    mNextRequest = mRequests[0];
    if(mHttp.isOpen()){
    	mHttp.close();
    }

    if (mNextRequest->getType() == 5) {
		MAHandle store = maOpenStore((FILE_PREFIX+mNextRequest->getSaveName()).c_str(), 0);
		if(store != STERR_NONEXISTENT) {
			MAHandle cacheimage = maCreatePlaceholder();
			maReadStore(store, cacheimage);
			maCloseStore(store, 0);

			if (maGetDataSize(cacheimage) > 0) {
				Util::returnImage(mNextRequest->getImage(), cacheimage, 64);
			}
			maDestroyObject(cacheimage);
			cacheimage = -1;
		}
		store = -1;
		finishedDownloading();
    } else {
		mHttp = HttpConnection(this);
		int res = mHttp.create(mNextRequest->getUrl().c_str(), HTTP_GET);
		if(res < 0) {
			finishedDownloading();
		} else {
			mHttp.finish();
		}
    }
}