Ejemplo n.º 1
0
int fwt_open(const char *name, int flags, int mode) {
    if (!ignore_current_write) {
        return _Open(name, flags, mode);
    }
    current_write_ignored=1;
    return 255; // fake, invalid file descriptor
}
Ejemplo n.º 2
0
void
App::ArgvReceived(int32 argc, char* argv[])
{
    for (int i = 1; i < argc;) {
        if (0 == strcmp("--webappbaseurl", argv[i])) {
            if (i == argc-1) {
                fprintf(stderr, "unexpected end of arguments; missing web app base url\n");
                Quit();
            }

            if (WebAppInterface::SetBaseUrl(argv[i + 1]) != B_OK) {
                fprintf(stderr, "malformed web app base url; %s\n", argv[i + 1]);
                Quit();
            }
            else
                fprintf(stderr, "did configure the web base url; %s\n",argv[i + 1]);

            i += 2;
        } else {
            BEntry entry(argv[i], true);
            _Open(entry);
            i++;
        }
    }
}
Ejemplo n.º 3
0
/*int creat (const char *name, int flags)
{
    return _creat(name, flags);
}*/
int open (const char *name, int flags, int mode )
{
#ifdef CAM_DRYOS_2_3_R39
    if(name[0]!='A')return -1;
#endif
    return _Open(name, flags, mode);
}
Ejemplo n.º 4
0
WorkspacesSettings::WorkspacesSettings()
	:
	fAutoRaising(false),
	fAlwaysOnTop(false),
	fHasTitle(true),
	fHasBorder(true),
	fSwitchOnWheel(false),
	fLoaded(false)
{
	UpdateScreenFrame();

	BScreen screen;

	BFile file;
	if (_Open(file, B_READ_ONLY) == B_OK) {
		BMessage settings;
		if (settings.Unflatten(&file) == B_OK) {
			if (settings.FindRect("window", &fWindowFrame) == B_OK
				&& settings.FindRect("screen", &fScreenFrame) == B_OK)
				fLoaded = true;

			settings.FindBool("auto-raise", &fAutoRaising);
			settings.FindBool("always on top", &fAlwaysOnTop);

			if (settings.FindBool("has title", &fHasTitle) != B_OK)
				fHasTitle = true;
			if (settings.FindBool("has border", &fHasBorder) != B_OK)
				fHasBorder = true;
			if (settings.FindBool("switch on wheel", &fSwitchOnWheel) != B_OK)
				fSwitchOnWheel = false;
		}
	} else {
		// try reading BeOS compatible settings
		BPath path;
		if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
			path.Append(kOldSettingFile);
			BFile file(path.Path(), B_READ_ONLY);
			if (file.InitCheck() == B_OK
				&& file.Read(&fWindowFrame, sizeof(BRect)) == sizeof(BRect)) {
				// we now also store the frame of the screen to know
				// in which context the window frame has been chosen
				BRect frame;
				if (file.Read(&frame, sizeof(BRect)) == sizeof(BRect))
					fScreenFrame = frame;
				else
					fScreenFrame = screen.Frame();

				fLoaded = true;
			}
		}
	}

	if (fLoaded) {
		// if the current screen frame is different from the one
		// just loaded, we need to alter the window frame accordingly
		if (fScreenFrame != screen.Frame())
			UpdateFramesForScreen(screen.Frame());
	}
}
Ejemplo n.º 5
0
bool SFB::Audio::Output::Open()
{
	LOGGER_DEBUG("org.sbooth.AudioEngine.Output", "Opening output");

	if(_IsOpen())
		return true;

	return _Open();
}
Ejemplo n.º 6
0
bool BWrepFile::Load(const char* pszFileName, int options, void *rwaheader, int size)
{
	if (pszFileName == NULL)
		return false;

	// offset of RWA (if any)
	#ifdef USE_RWA_CODE
	m_rwaoffset=0;
	#endif

	bool bOk = _Open(pszFileName);
	if(bOk)
	{
		long nRepID;
		unpack_section(m_pFile, (byte*)&nRepID, sizeof(nRepID));

		bOk = (nRepID == kBWREP_ID);
		if (bOk)
		{
			// read header
			bOk = (unpack_section(m_pFile, (byte*)&m_oHeader, kBWREP_HEADER_SIZE)==0);
			m_oHeader.checkPlayerNameUnicity();

			// read actions
			#ifdef USE_ACTIONS_CODE
			if(bOk) bOk = _LoadActions(m_pFile,(options&ADDACTIONS)==0,(options&LOADACTIONS)!=0);

				// load map
				#ifdef USE_MAP_CODE
				if(bOk) 
				{
					bOk = _LoadMap(m_pFile, (options&LOADMAP)!=0);

					#ifdef USE_RWA_CODE
					if(bOk && rwaheader!=0)
					{
						// read audio header and return file pointer on audio data
						memset(rwaheader,0,size);
						unsigned long *headerSize; headerSize=(unsigned long *)rwaheader;
						if(fread(rwaheader,1,sizeof(long),m_pFile)==sizeof(long))
						{
							size_t readsize; readsize = min((unsigned long)size,*headerSize)-sizeof(long);
							fread(((char*)rwaheader)+sizeof(long),1,readsize,m_pFile);
							if(*headerSize>(unsigned long)size) fseek(m_pFile,(*headerSize)-size,SEEK_CUR);
							m_rwaoffset = ftell(m_pFile);
						}
					}
					#endif
				}
				#endif
			#endif
		}

		_Close();
	}
	return bOk;
}
Ejemplo n.º 7
0
// get offset in file of audio part (if any, 0 if none)
unsigned long BWrepFile::GetAudioOffset(const char* pszFileName, void *header, int size)
{
	unsigned long offset=0;

	bool bOk = _Open(pszFileName);
	if(!bOk) return 0;

	long nRepID;
	int res = unpack_section(m_pFile, (byte*)&nRepID, sizeof(nRepID));
	if(nRepID != kBWREP_ID) goto Exit;
	if(res!=0) goto Exit;
						
	// read header
	bOk = (unpack_section(m_pFile, (byte*)&m_oHeader, kBWREP_HEADER_SIZE)==0);
	if(!bOk) goto Exit;

	// get actions section size
	int cmdSize; cmdSize=0;
	res = unpack_section(m_pFile, (byte*)&cmdSize, sizeof(cmdSize));
	if(res!=0) goto Exit;

	// alloc buffer to read it
	byte *buffer; buffer = (byte *)malloc(cmdSize * sizeof(byte));
	if (buffer==0) goto Exit;

	// unpack cmd section in buffer
	res = unpack_section(m_pFile, buffer, cmdSize);
	if(res!=0) goto Exit;
	free(buffer);

	// get map section size
	int mapSize; mapSize=0;
	res = unpack_section(m_pFile, (byte*)&mapSize, sizeof(mapSize));
	if(res!=0) goto Exit;

	// alloc buffer to read it
	buffer = (byte *)malloc(mapSize * sizeof(byte));
	if (buffer==0) goto Exit;

	// unpack map section in buffer
	res = unpack_section(m_pFile, buffer, mapSize);
	if(res!=0) goto Exit;
	free(buffer);

	// read audio header and return file pointer on audio data
	unsigned long *headerSize; headerSize=(unsigned long *)header;
	if(fread(header,1,sizeof(long),m_pFile)!=sizeof(long)) goto Exit;
	size_t readsize; readsize = min((unsigned long)size,*headerSize)-sizeof(long);
	fread(((char*)header)+sizeof(long),1,readsize,m_pFile);
	if(*headerSize>(unsigned long)size) fseek(m_pFile,(*headerSize)-size,SEEK_CUR);
	offset = ftell(m_pFile);

Exit:
	_Close();
	return offset;
}
Ejemplo n.º 8
0
VMacResFile::VMacResFile(const VFilePath& inPath, FileAccess inFileAccess, Boolean inCreate)
{
	fUseResourceChain = false;
	fRefNum = -1;
	fReadOnly = true;
	fLastStringList = NULL;
	fLastStringListID = 0;
	
	_Open(inPath, inFileAccess, inCreate);
}
Ejemplo n.º 9
0
void
App::RefsReceived(BMessage* message)
{
    entry_ref ref;
    int32 index = 0;
    while (message->FindRef("refs", index++, &ref) == B_OK) {
        BEntry entry(&ref, true);
        _Open(entry);
    }
}
Ejemplo n.º 10
0
/////////////////////////////////////
// Name:	FSOpen
// Purpose:	this will open a file
//			relative to game paths
//			(maybe from pack files)
// Output:	file opened
// Return:	file handle
/////////////////////////////////////
hFILE FSOpen(const tCHAR *filepath, const tCHAR *mode)
{
	if(!filepath) return 0;

	hFILE fp=(hFILE)MemAlloc(sizeof(FSFile));

	if(fp)
	{
		wstring path;

		//if there are no paths
		if(!g_main || g_main->paths->size() == 0)
		{
			FSPath fsPath;
			fsPath.flag = 0;
			fsPath.uf = 0;
			fsPath.str = L"\0";

			//try to open the file
			if(_Open(fp, fsPath, filepath, mode) != TRUE)
			{ FSClose(fp); fp = 0; }
		}
		else
		{
			s8 ret = FALSE;

			//go through the list to find where this file is
			for(list<FSPath>::iterator i = g_main->paths->begin(); i != g_main->paths->end(); i++)
			{
				//try to open the file
				ret = _Open(fp, (*i), filepath, mode);

				if(ret != FALSE)
					break;
			}

			//failed to find the file
			if(ret == FALSE || ret == -1) { FSClose(fp); fp = 0; }
		}
	}

	return fp;
}
Ejemplo n.º 11
0
Settings::~Settings()
{
	if (!fUpdated)
		return;

	BFile file;
	if (_Open(&file, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY) != B_OK)
		return;

	fMessage.Flatten(&file);
}
Ejemplo n.º 12
0
bool SFB::InputSource::Open(CFErrorRef *error)
{
	if(IsOpen()) {
		LOGGER_WARNING("org.sbooth.AudioEngine.InputSource", "Open() called on an InputSource that is already open");
		return true;
	}

	bool result = _Open(error);
	if(result)
		mIsOpen = true;
	return result;
}
Ejemplo n.º 13
0
Settings::~Settings()
{
	// only save the settings if something has changed
	if (!fUpdated)
		return;

	BFile file;
	if (_Open(&file, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY) != B_OK)
		return;

	fMessage.Flatten(&file);
}
Ejemplo n.º 14
0
status_t
LocaleSettings::Load()
{
	BFile file;
	status_t err;
	err = _Open(&file, B_READ_ONLY);
   	if (err != B_OK)
		return err;
	err = fMessage.Unflatten(&file);
   	if (err == B_OK)
		fSaved = true;
	return err;
}
Ejemplo n.º 15
0
bool CXmlReader::OpenNode(LPCTSTR szPath)
{	
	if (!szPath)
	{
		m_pOpenElement = m_pXmlDoc->RootElement();
	}
	else
	{
		m_pOpenElement = _Open(TCharToUTF8(szPath));
	}

	return m_pOpenElement != NULL;
}
Ejemplo n.º 16
0
int _Fopen(const char *path,unsigned int smod,const char *mods){
    
    unsigned int acc;
    acc = (smode & (_MOPENR | _MOPENW)) == (_MOPENR | _MOPENW) ? 2: smode &
           _MOPENW ? 1: 0;
    if(smode & _MOPENA)
        acc |= 010;
    if(smode & _MTRUNC)
        acc |= 02000;
    if(smode & _MCREAT)
        acc |= 01000;
    return (_Open(path,acc,0666));
}
Ejemplo n.º 17
0
status_t
LocaleSettings::Save()
{
	BFile file;
	status_t err;
	err = _Open(&file, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY);
	if (err != B_OK)
		return err;

	err = fMessage.Flatten(&file);
   	if (err == B_OK)
		fSaved = true;
	return err;
}
Ejemplo n.º 18
0
Settings::Settings()
	:
	fMessage(kMsgLocaleSettings),
	fUpdated(false)
{
	BFile file;
	if (_Open(&file, B_READ_ONLY) != B_OK
		|| fMessage.Unflatten(&file) != B_OK) {
		// set default prefs
		fMessage.AddString("language", "en");
		fMessage.AddString("country", "en_US");
		return;
	}
}
Ejemplo n.º 19
0
void CRzLog::_NewLog(tm* atm)
{
	static  char_type sformat[7][24] = {_T("%Y"),_T("%Y%m"),_T("%Y%m%d"),_T("%Y%m%d_%H"),
		_T("%Y%m%d_%H_%M"),_T("%Y%m%d_%H_%M_%S")};

	char_type buffer[24] = {0};	
	DFn_strftime(buffer,24,sformat[_type],atm);

	if(DFn_strcmp(buffer,_timename) != 0)
	{
		DFn_strcpy_s(_timename,512,buffer);
		_Close();
		_Open();
	}
}
Ejemplo n.º 20
0
bool SFB::Audio::Decoder::Open(CFErrorRef *error)
{
	if(IsOpen()) {
		LOGGER_INFO("org.sbooth.AudioEngine.Decoder", "Open() called on a Decoder that is already open");
		return true;
	}

	// Ensure the input source is open
	if(!GetInputSource().IsOpen() && !GetInputSource().Open(error))
		return false;

	bool result = _Open(error);
	if(result)
		mIsOpen = true;
	return result;
}
Ejemplo n.º 21
0
WorkspacesSettings::~WorkspacesSettings()
{
	// write settings file
	BFile file;
	if (_Open(file, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE) != B_OK)
		return;

	BMessage settings('wksp');

	if (settings.AddRect("window", fWindowFrame) == B_OK
		&& settings.AddRect("screen", fScreenFrame) == B_OK
		&& settings.AddBool("auto-raise", fAutoRaising) == B_OK
		&& settings.AddBool("always on top", fAlwaysOnTop) == B_OK
		&& settings.AddBool("has title", fHasTitle) == B_OK
		&& settings.AddBool("has border", fHasBorder) == B_OK)
		settings.Flatten(&file);
}
Ejemplo n.º 22
0
SInt64 SFB::Audio::MODDecoder::_SeekToFrame(SInt64 frame)
{
	// DUMB cannot seek backwards, so the decoder must be reset
	if(frame < mCurrentFrame) {
		if(!_Close(nullptr) || !mInputSource->SeekToOffset(0) || !_Open(nullptr)) {
			LOGGER_ERR("org.sbooth.AudioEngine.Decoder.MOD", "Error reseting DUMB decoder");
			return -1;
		}

		mCurrentFrame = 0;
	}

	long framesToSkip = frame - mCurrentFrame;
	duh_sigrenderer_generate_samples(dsr.get(), 1, 65536.0f / DUMB_SAMPLE_RATE, framesToSkip, nullptr);
	mCurrentFrame += framesToSkip;

	return mCurrentFrame;
}
Ejemplo n.º 23
0
Settings::Settings()
	:
	fMessage(kMsgFileTypesSettings),
	fUpdated(false)
{
	_SetDefaults();

	BFile file;
	if (_Open(&file, B_READ_ONLY) != B_OK)
		return;

	BMessage settings;
	if (settings.Unflatten(&file) == B_OK) {
		// We don't unflatten into our default message to make sure
		// nothing is lost (because of old or corrupted on disk settings)
		UpdateFrom(&settings);
		fUpdated = false;
	}
}
Ejemplo n.º 24
0
/** 找开文件
@param   pszFileName:文件名
@param   
@return  
*/
bool CCsvReader::Open(const char* pszFileName, bool bEncrypt)
{
	if(pszFileName == NULL)
	{
		return false;
	}

	m_curStrName = pszFileName;

	// 取得文件系统
	FileSystem * pFileSystem = getFileSystem();
	if(pFileSystem == NULL)
	{
		return false;
	}

	// 读取文件
	Stream * pStream = pFileSystem->open(pszFileName);
	if(pStream == NULL)
	{
		return false;
	}

	// 解密文件
	char * pFileBuffer = NULL;
	MemoryStream memorystream;
	if(bEncrypt)
	{
		int nFileLength = pStream->getLength();
		pFileBuffer = new char [nFileLength + 1];
		if(!pStream->read(pFileBuffer, nFileLength))
		{
			return false;
		}
		pStream->close();
		pStream->release();

		if(!makeMap((uchar *)pFileBuffer, nFileLength, 'LAND'))
		{
			return false;
		}

		memorystream.attach((uchar *)pFileBuffer, nFileLength);
		pStream = &memorystream;
	}
	
	// 解析
	if(!_Open(pStream))
	{
		if(pFileBuffer != NULL)
		{
			delete [] pFileBuffer;
			pFileBuffer = NULL;
		}
		
		// 关闭文件
		pStream->close();
		pStream->release();
		return false;
	}
	// 关闭文件
	pStream->close();
	
	pStream->release();
	if(pFileBuffer != NULL)
	{
		delete [] pFileBuffer;
		pFileBuffer = NULL;
	}
	return true;
}
Ejemplo n.º 25
0
WorkspacesSettings::WorkspacesSettings()
	:
	fAutoRaising(false),
	fAlwaysOnTop(false),
	fHasTitle(true),
	fHasBorder(true)
{
	UpdateScreenFrame();

	bool loaded = false;
	BScreen screen;

	BFile file;
	if (_Open(file, B_READ_ONLY) == B_OK) {
		BMessage settings;
		if (settings.Unflatten(&file) == B_OK) {
			if (settings.FindRect("window", &fWindowFrame) == B_OK
				&& settings.FindRect("screen", &fScreenFrame) == B_OK)
				loaded = true;

			settings.FindBool("auto-raise", &fAutoRaising);
			settings.FindBool("always on top", &fAlwaysOnTop);

			if (settings.FindBool("has title", &fHasTitle) != B_OK)
				fHasTitle = true;
			if (settings.FindBool("has border", &fHasBorder) != B_OK)
				fHasBorder = true;
		}
	} else {
		// try reading BeOS compatible settings
		BPath path;
		if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
			path.Append(kOldSettingFile);
			BFile file(path.Path(), B_READ_ONLY);
			if (file.InitCheck() == B_OK
				&& file.Read(&fWindowFrame, sizeof(BRect)) == sizeof(BRect)) {
				// we now also store the frame of the screen to know
				// in which context the window frame has been chosen
				BRect frame;
				if (file.Read(&frame, sizeof(BRect)) == sizeof(BRect))
					fScreenFrame = frame;
				else
					fScreenFrame = screen.Frame();

				loaded = true;
			}
		}
	}

	if (loaded) {
		// if the current screen frame is different from the one
		// just loaded, we need to alter the window frame accordingly
		if (fScreenFrame != screen.Frame())
			UpdateFramesForScreen(screen.Frame());
	}

	if (!loaded
		|| !(screen.Frame().right + 5 >= fWindowFrame.right
			&& screen.Frame().bottom + 5 >= fWindowFrame.bottom
			&& screen.Frame().left - 5 <= fWindowFrame.left
			&& screen.Frame().top - 5 <= fWindowFrame.top)) {
		// set to some usable defaults
		float screenWidth = screen.Frame().Width();
		float screenHeight = screen.Frame().Height();
		float aspectRatio = screenWidth / screenHeight;

		uint32 columns, rows;
		BPrivate::get_workspaces_layout(&columns, &rows);

		// default size of ~1/10 of screen width
		float workspaceWidth = screenWidth / 10;
		float workspaceHeight = workspaceWidth / aspectRatio;

		float width = floor(workspaceWidth * columns);
		float height = floor(workspaceHeight * rows);

		float tabHeight = 20;
			// TODO: find tabHeight without being a window

		// shrink to fit more
		while (width + 2 * kScreenBorderOffset > screenWidth
			|| height + 2 * kScreenBorderOffset + tabHeight > screenHeight) {
			width = floor(0.95 * width);
			height = floor(0.95 * height);
		}

		fWindowFrame = fScreenFrame;
		fWindowFrame.OffsetBy(-kScreenBorderOffset, -kScreenBorderOffset);
		fWindowFrame.left = fWindowFrame.right - width;
		fWindowFrame.top = fWindowFrame.bottom - height;
	}
}
Ejemplo n.º 26
0
VError VMacResFile::Open(const VFilePath& inPath, FileAccess inFileAccess, Boolean inCreate)
{
	if (!testAssert(fRefNum == -1))
		return VE_STREAM_ALREADY_OPENED;
	return _Open(inPath, inFileAccess, inCreate);
}
Ejemplo n.º 27
0
void Open(void) {
    if (!g_gzFile) {
        _Open("trace");
        WriteUInt(TRACE_VERSION);
    }
}