Ejemplo n.º 1
0
bool
PythonFile::GetUnderlyingFile(File &file) const
{
    if (!IsValid())
        return false;

    file.Close();
    // We don't own the file descriptor returned by this function, make sure the
    // File object knows about that.
    file.SetDescriptor(PyObject_AsFileDescriptor(m_py_obj), false);
    PythonString py_mode = GetAttributeValue("mode").AsType<PythonString>();
    file.SetOptions(PythonFile::GetOptionsFromMode(py_mode.GetString()));
    return file.IsValid();
}
Ejemplo n.º 2
0
 int ls_main( int argc, char **argv )
 {
    char *node = NULL;
    if ( argc == 1 ) node = strdup("/");
    if ( argc == 2 ) node = strdup( argv[1] );
    if ( node == NULL ) return -1;

    Directory *dir = new Directory( node );
    if ( dir->Exists() == false ) 
    {
      printf("%s\n","directory does not exist.");
    }
  
	char *front = (char*)malloc( strlen(node) + 2 );
		  strcpy( front, node );
		  if ( front[strlen(front) - 1] != '/' ) 
				strcat( front, "/" );

	
     char *entry = NULL;
     while ((entry = dir->NextEntry()) != NULL )
     {
	   char *complete = (char*)malloc(strlen(front) + strlen(entry) + 5 );

		   strcpy( complete, front );
		   strcat( complete, entry );
		   
		   int size = -1;
		   File *temp = new File( complete );
		   if ( temp->Open() >= 0 )
		   {
		     size = temp->Size();
			 temp->Close();
		   }
		   delete temp;
			 
       printf("%5s%10i  %s\n", ". ", size, entry );

	   free( complete );
     }
 
	 free( front );

    printf("%i%s\n", dir->CountEntries(), " files.");
    delete dir;
    free( node );
   
   return 0;
 }
Ejemplo n.º 3
0
int close(int fd)
{
    File* f = fd_get(fd);

    if (f == NULL)
    {
        return EOF;
    }
    fd_remove(fd);

    f->Close();
    delete f;

    return 0;
}
Ejemplo n.º 4
0
int WINAPI GetNumberOfLinks(const wchar_t *Name)
{
	int NumberOfLinks=1;
	File file;
	if(file.Open(Name, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT))
	{
		BY_HANDLE_FILE_INFORMATION bhfi;
		if (file.GetInformation(bhfi))
		{
			NumberOfLinks=bhfi.nNumberOfLinks;
		}
		file.Close();
	}
	return NumberOfLinks;
}
Ejemplo n.º 5
0
int GetNumberOfLinks(const string& Name, bool negative_if_error)
{
	int NumberOfLinks = (negative_if_error ? -1 : +1);
	File file;
	if(file.Open(Name, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT))
	{
		BY_HANDLE_FILE_INFORMATION bhfi;
		if (file.GetInformation(bhfi))
		{
			NumberOfLinks=bhfi.nNumberOfLinks;
		}
		file.Close();
	}
	return NumberOfLinks;
}
Ejemplo n.º 6
0
   // PfmFormatterDispatch::Close
void CCALL Volume::Close( PfmMarshallerCloseOp* op, void* formatterUse)
{
   int64_t openId = op->OpenId();
   int64_t openSequence = op->OpenSequence();
   int perr;
   File* file;

   perr = FindOpenFile( openId, &file);
   if (!perr)
   {
      file->Close( openSequence);
   }

   op->Complete( perr);
}
Ejemplo n.º 7
0
void ExtractStreams(Archive &Arc,const wchar *FileName,bool TestMode)
{
  wchar FullName[NM+2];
  if (FileName[0]!=0 && FileName[1]==0)
  {
    wcscpy(FullName,L".\\");
    wcsncpyz(FullName+2,FileName,ASIZE(FullName)-2);
  }
  else
    wcsncpyz(FullName,FileName,ASIZE(FullName));

  byte *Data=&Arc.SubHead.SubData[0];
  size_t DataSize=Arc.SubHead.SubData.Size();

  wchar StreamName[NM];
  GetStreamNameNTFS(Arc,StreamName,ASIZE(StreamName));
  if (*StreamName!=':')
  {
    uiMsg(UIERROR_STREAMBROKEN,Arc.FileName,FileName);
    ErrHandler.SetErrorCode(RARX_CRC);
    return;
  }

  if (TestMode)
  {
    Arc.ReadSubData(NULL,NULL);
    return;
  }

  wcsncatz(FullName,StreamName,ASIZE(FullName));

  FindData fd;
  bool Found=FindFile::FastFind(FileName,&fd);

  if ((fd.FileAttr & FILE_ATTRIBUTE_READONLY)!=0)
    SetFileAttr(FileName,fd.FileAttr & ~FILE_ATTRIBUTE_READONLY);
  File CurFile;
  if (CurFile.WCreate(FullName) && Arc.ReadSubData(NULL,&CurFile))
    CurFile.Close();
  File HostFile;
  if (Found && HostFile.Open(FileName,FMF_OPENSHARED|FMF_UPDATE))
    SetFileTime(HostFile.GetHandle(),&fd.ftCreationTime,&fd.ftLastAccessTime,
                &fd.ftLastWriteTime);

  // Restoring original file attributes. Important if file was read only
  // or did not have "Archive" attribute
  SetFileAttr(FileName,fd.FileAttr);
}
Ejemplo n.º 8
0
	bool FontLibrary::LoadFallbackFont()
	{
		bool success = true;

		// Load fallback font
		File file;
		if(!file.OpenRead("fonts/fallbackfont.otf"))
			return false;
		loadedFallbackFont.resize(file.GetSize());
		file.Read(loadedFallbackFont.data(), loadedFallbackFont.size());
		file.Close();

		success = success && FT_New_Memory_Face(library, loadedFallbackFont.data(), (uint32)loadedFallbackFont.size(), 0, &fallbackFont) == 0;
		success = success && FT_Select_Charmap(fallbackFont, FT_ENCODING_UNICODE) == 0;
		return success;
	}
Ejemplo n.º 9
0
void FilterLibrary::SaveAs( const String& _filePath )
{
   File f;
   f.CreateForWriting( _filePath );
   if ( !filters.IsEmpty() )
      for ( filter_list::const_iterator i = filters.Begin(); ; )
      {
         f.OutText( i->ToSource() );
         if ( ++i == filters.End() )
            break;
         f.OutTextLn( IsoString() );
      }
   f.Close();

   filePath = _filePath;
}
Ejemplo n.º 10
0
torch::Data File::GetBytes(const std::string &path, size_t length)
{
    bool ok = true;
    
    // read data from disk
    File fstream;
    ok = fstream.Open(path, "rb");
    if (!ok) {
        return Data::Null;
    }
    
    Data buffer = fstream.GetBytes(length);
    fstream.Close();

    return std::move(buffer);
}
Ejemplo n.º 11
0
 int cat_main( int argc, char **argv )
 {
    if ( argc != 2 ) return -1;

    File *file = new File( argv[1] );
    if ( file->Open() < 0 )
     {
       delete file;
       printf("%s%s\n","Unable to open file: ", argv[1] );
       return -1;
     }

     char *buffer = (char*)malloc(16384);
     
	int size = file->Size();
	while ( size > 0 )
	{
	   int len = 16384;
	   if ( size < len ) len = size;
	   if ( file->Read( buffer, len ) != len )
	    {
	      printf("%s\n", "Error reading file. ");
	      break;
	    }
	    
	   for ( int i = 0; i < len; i++ )
	   {
	    if ( isprint( buffer[i] ) != 0 )
	      printf("%c", buffer[i] );
	     else 
	      printf("%c", '.' );

	    if ( buffer[i] == '\n' ) printf("%s\n","" );
	   }
	      
	   size -= len; 
	}
	
     free( buffer );	

    file->Close();
    delete file;
   
    printf("\n");
   
   return 0;
 }
Ejemplo n.º 12
0
bool Texture::Create(const wchar_t* path,unsigned long width,unsigned long height,unsigned long mipmaps,Usage usage,Format format,Pool pool)
{
	ASSERT(!mCreated);

	File file;

	if(!file.Open(path,File::AccessModeRead,File::ShareModeRead,File::OpenModeExisting))
	{
		TRACE(L"Texture failed to open file.\n");
		return false;
	}

	unsigned long size = file.GetSize();
	if(!size)
	{
		TRACE(L"Texture file size mismatch.\n");
		return false;
	}

	unsigned char* buffer = new unsigned char[size];
	if(!buffer)
	{
		TRACE(L"Texture failed to allocate file buffer %u bytes.\n",size);
		return false;
	}

	ZeroMemory(buffer,size);

	if(file.Read(buffer,size) != size)
	{
		delete[] buffer;
		TRACE(L"Texture file read mismatch %u bytes.\n",size);
		return false;
	}

	file.Close();

	if(!Create(buffer,size,width,height,mipmaps,usage,format,pool))
	{
		delete[] buffer;
		return false;
	}

	delete[] buffer;

	return true;
}
Ejemplo n.º 13
0
//---------------------------------------------------------------------------
// Load CSV
bool ZtringListListF::CSV_Charger ()
{
    //Read file
    File F;
    if (!F.Open(Name))
        return false;

    int8u* Buffer=new int8u[(size_t)F.Size_Get()+1];
    size_t BytesCount=F.Read(Buffer, (size_t)F.Size_Get());
    F.Close();
    if (BytesCount==Error)
    {
        delete[] Buffer; //Buffer=NULL;
        return false;
    }
    Buffer[(int32u)BytesCount]=(int8u)'\0';

    //Convert file in UTF-8 or Local
    Ztring File;
    if (!Local)
    {
        //UTF-8
        File.From_UTF8((char*)Buffer, 0, BytesCount);
        #ifdef _DEBUG
        if (File.size()==0)
             File.From_Local((char*)Buffer, 0, BytesCount);
        #endif //_DEBUG
    }
    if (File.size()==0)
        //Local of UTF-8 failed
        File.From_Local((char*)Buffer, 0, BytesCount);

    //Separators
    if (Separator[0]==__T("(Default)"))
            Separator[0]=EOL;
    Ztring SeparatorT=Separator[1];
    Separator[1]=__T(";");

    //Writing
    Write(File);

    //Separators
    Separator[1]=SeparatorT;

    delete[] Buffer; //Buffer=NULL;
    return true;
}
Ejemplo n.º 14
0
void UserMenu::SaveMenu(const string& MenuFileName)
{
	if (MenuModified)
	{
		DWORD FileAttr=apiGetFileAttributes(MenuFileName);

		if (FileAttr != INVALID_FILE_ATTRIBUTES)
		{
			if (FileAttr & FILE_ATTRIBUTE_READONLY)
			{
				int AskOverwrite;
				AskOverwrite=Message(MSG_WARNING,2,MSG(MUserMenuTitle),LocalMenuFileName,MSG(MEditRO),MSG(MEditOvr),MSG(MYes),MSG(MNo));

				if (!AskOverwrite)
					apiSetFileAttributes(MenuFileName,FileAttr & ~FILE_ATTRIBUTE_READONLY);
			}

			if (FileAttr & (FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM))
				apiSetFileAttributes(MenuFileName,FILE_ATTRIBUTE_NORMAL);
		}

		// Don't use CreationDisposition=CREATE_ALWAYS here - it kills alternate streams
		File MenuFile;
		if (MenuFile.Open(MenuFileName,GENERIC_WRITE, FILE_SHARE_READ, nullptr, FileAttr==INVALID_FILE_ATTRIBUTES?CREATE_NEW:TRUNCATE_EXISTING))
		{
			CachedWrite CW(MenuFile);
			WCHAR Data = SIGN_UNICODE;
			CW.Write(&Data, 1*sizeof(WCHAR));
			MenuListToFile(&Menu, CW);
			CW.Flush();
			UINT64 Size = 0;
			MenuFile.GetSize(Size);
			MenuFile.Close();

			// если файл FarMenu.ini пуст, то удалим его
			if (Size<3) // 2 for BOM
			{
				apiDeleteFile(MenuFileName);
			}
			else if (FileAttr!=INVALID_FILE_ATTRIBUTES)
			{
				apiSetFileAttributes(MenuFileName,FileAttr);
			}
		}
	}
}
Ejemplo n.º 15
0
int open(char const* name)
{
    File* f = directory_service->OpenFile(name, true, true, false, false, false);
    if (f == NULL)
    {
        return EOF;
    }

    int fd = fd_put(f);
    if (fd == EOF)
    {
        f->Close();
        delete f;
    }

    return fd;
}
Ejemplo n.º 16
0
bool WINAPI DeleteReparsePoint(const wchar_t *Object)
{
	bool Result=false;
	DWORD ReparseTag;
	string strTmp;
	GetReparsePointInfo(Object,strTmp,&ReparseTag);
	File fObject;
	if (fObject.Open(Object, GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT))
	{
		REPARSE_GUID_DATA_BUFFER rgdb={ReparseTag};
		DWORD dwBytes;
		Result=fObject.IoControl(FSCTL_DELETE_REPARSE_POINT,&rgdb,REPARSE_GUID_DATA_BUFFER_HEADER_SIZE,nullptr,0,&dwBytes);
		fObject.Close();
	}

	return Result;
}
Ejemplo n.º 17
0
Archivo: Layout.cpp Proyecto: Eynx/R3D
    Bool Resource::Layout::Create(const Description& description)
    {
        // Prepare the D3D11 input layout
        D3D11_INPUT_ELEMENT_DESC* inputLayout = new D3D11_INPUT_ELEMENT_DESC[description.Elements.Count];

        // Fill in all of the elements
        for(UInt i = 0; i < description.Elements.Count; ++i)
        {
            inputLayout[i].SemanticName = description.Elements[i].Name.c_str();
            inputLayout[i].SemanticIndex = description.Elements[i].Index;
            inputLayout[i].Format = (DXGI_FORMAT)description.Elements[i].Format;
            inputLayout[i].InputSlot = description.Elements[i].Slot;
            inputLayout[i].AlignedByteOffset = description.Elements[i].Offset;
            // No support for instancing yet
            inputLayout[i].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; //description.Elements[i].Classification;
            inputLayout[i].InstanceDataStepRate = 0; //description.Elements[i].InstanceStepRate;
        }

        // Get the device handle
        Graphics::Device& device = Graphics::Manager::Singleton->Device;

        File shaderFile;
        // Open the shader associated with this input layout to retrieve its input signature
        Bool result = shaderFile.Open(description.Shader, File::Mode::Read);
        if(FAILED(result)) {
            return false;
        }

        // Load the shader data
        shaderFile.Allocate(shaderFile.FileSize + 1);
        shaderFile.Load(shaderFile.FileSize);

        Log::Singleton->Write("Creating input layout with (" + description.Shader + ") vertex shader");
        // Create the vertex input layout
        HRESULT hresult = device->CreateInputLayout(inputLayout, description.Elements.Count, shaderFile.Data, shaderFile.Size, &Handle);
        if(FAILED(hresult)) {
            return false;
        }

        // We're done with the file for now
        shaderFile.Close();

        // Success!
        return true;
    }
Ejemplo n.º 18
0
bool data::load()
{
	bool loaded = false;
	
	initPeakNb       = 0;
	peakNb           = 0;
	parentMassRAW    = 0;
	parentMassM      = 0;
	charge           = 0;
	binsize          = 0;
	strcpy(title,      "");
	strcpy(seqSpec,    "");
	strcpy(seqAsInDtb, "");
	
	if (runManParam->FORMAT == FMT_MGF) {
		loaded = loadPeaksMGF(runManParam->FILEIN);
	}
	else if (runManParam->FORMAT == FMT_POP) {
		loaded = loadPeaksPOP(runManParam->FILEIN);
	}
	else if (runManParam->FORMAT == FMT_DTA) {
		loaded = loadPeaksDTA(runManParam->FILEIN);
	}
	
	if (!loaded) {
		return false;
	}
	
	preprocessPeaks();       
	putBins();
	
	// If in "CHECK" mode (typical mode is UNKNOWN)
	if (runManParam->r_CHECK) {
		char filename[256] = "";
		sprintf(filename, "%s%s", runManParam->OUTPUT_DIR, "SOURCE_SPECTRUM_FINAL.txt");
		File fp;
		fp.Open(filename, "w");
		write(fp);
		fp.Close();
	}
	
	specID++;
	
	return true;
}
Ejemplo n.º 19
0
bool File::WriteBytes(const std::string &path, const char *s, size_t length, WriteMode mode)
{
    std::string smode = "wb";
    if (mode == WriteMode::CreateOrAppend) {
        smode = "ab";
    }
    
    File fstream;
    bool ok = fstream.Open(path, smode);
    if (!ok) {
        return false;
    }
    
    size_t sz = fstream.Write(s, length);
    fstream.Close();
    
    return sz == length;
}
Ejemplo n.º 20
0
bool SetREPARSE_DATA_BUFFER(const wchar_t *Object,PREPARSE_DATA_BUFFER rdb)
{
	bool Result=false;
	if (IsReparseTagValid(rdb->ReparseTag))
	{
		Privilege CreateSymlinkPrivilege(SE_CREATE_SYMBOLIC_LINK_NAME);
		File fObject;

		bool ForceElevation=false;

		DWORD Attributes = apiGetFileAttributes(Object);
		if(Attributes&FILE_ATTRIBUTE_READONLY)
		{
			apiSetFileAttributes(Object, Attributes&~FILE_ATTRIBUTE_READONLY);
		}
		for(size_t i=0;i<2;i++)
		{
			if (fObject.Open(Object,GENERIC_WRITE,0,nullptr,OPEN_EXISTING,FILE_FLAG_OPEN_REPARSE_POINT,nullptr,ForceElevation))
			{
				DWORD dwBytesReturned;
				if (fObject.IoControl(FSCTL_SET_REPARSE_POINT,rdb,rdb->ReparseDataLength+REPARSE_DATA_BUFFER_HEADER_SIZE,nullptr,0,&dwBytesReturned))
				{
					Result=true;
				}
				fObject.Close();
				// Open() success, but IoControl() fails. We can't handle this automatically :(
				if(!i && !Result && ElevationRequired(ELEVATION_MODIFY_REQUEST))
				{
					ForceElevation=true;
					continue;
				}
				break;
			}
		}
		if(Attributes&FILE_ATTRIBUTE_READONLY)
		{
			apiSetFileAttributes(Object, Attributes);
		}

	}

	return Result;
}
Ejemplo n.º 21
0
static bool checkFileSize(File &file, unsigned long len) {
  if (!file.IsOpen()) {
    int nFileMode = File::modeReadOnly | File::modeBinary;
    file.Open(nFileMode);
  }
  unsigned long actual = file.GetLength();
  file.Close();
  if (actual < len) {
    LOG << file.full_pathname() << " too short (" << actual << "<"
      << len << ").";
    return false;
  }
  if (actual > len) {
    LOG << file.full_pathname() << " too long (" << actual << ">"
      << len << ").";
    LOG << "Attempting to continue.";
  }
  return true;
}
Ejemplo n.º 22
0
bool CommanderWindow::Refresh()
{
	cleanPath();
	list->Empty();
		
	const char *path = input->Text();

	Directory *dir = new Directory( path );
    if ( dir->Exists() == false )  
    {
	  delete dir;
	  Draw( Bounds() );
	  return false;
    }
  
     char *entry = NULL;
     while ((entry = dir->NextEntry()) != NULL )
     {

	   char *complete = (char*)malloc( strlen(path) + strlen(entry) + 2 );

		   strcpy( complete, path );
		   strcat( complete, entry );
		   
		   int size = -1;
		   File *temp = new File( complete );
		   if ( temp->Open() >= 0 )
		   {
		     size = temp->Size();
			 temp->Close();
		   }
		   delete temp;
			 

	   list->AddItem( new StringItem( entry ) );
	   free( complete );
     }

	Draw( Bounds() );
    delete dir;

	return true;
}
Ejemplo n.º 23
0
bool DeleteReparsePoint(const string& Object)
{
	bool Result=false;
	LPBYTE Buff=new BYTE[MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
	if(Buff)
	{
		PREPARSE_DATA_BUFFER rdb = reinterpret_cast<PREPARSE_DATA_BUFFER>(Buff);
		if (GetREPARSE_DATA_BUFFER(Object,rdb))
		{
			File fObject;
			if (fObject.Open(Object, FILE_WRITE_ATTRIBUTES, 0, 0, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT))
			{
				DWORD dwBytes;
				REPARSE_GUID_DATA_BUFFER rgdb = {rdb->ReparseTag};
				Result=fObject.IoControl(FSCTL_DELETE_REPARSE_POINT,&rgdb,REPARSE_GUID_DATA_BUFFER_HEADER_SIZE,nullptr,0,&dwBytes);
				fObject.Close();
			}
		}
	}
	return Result;
}
Ejemplo n.º 24
0
bool GetREPARSE_DATA_BUFFER(const wchar_t *Object,PREPARSE_DATA_BUFFER rdb)
{
	bool Result=false;
	const DWORD FileAttr = apiGetFileAttributes(Object);

	if (FileAttr!=INVALID_FILE_ATTRIBUTES && (FileAttr&FILE_ATTRIBUTE_REPARSE_POINT))
	{
		File fObject;
		if(fObject.Open(Object,0,0,nullptr,OPEN_EXISTING,FILE_FLAG_OPEN_REPARSE_POINT))
		{
			DWORD dwBytesReturned;
			if(fObject.IoControl(FSCTL_GET_REPARSE_POINT, nullptr, 0, rdb, MAXIMUM_REPARSE_DATA_BUFFER_SIZE, &dwBytesReturned) && IsReparseTagValid(rdb->ReparseTag))
			{
				Result=true;
			}
			fObject.Close();
		}
	}

	return Result;
}
Ejemplo n.º 25
0
Archivo: main.cpp Proyecto: yagi/satori
// filesには そのままオープン可能なフルパスが入っていること。
// updates2.dauにはbase_folderを差し引いた相対パスが格納される。
bool	makeUpdates2(string base_folder, const list<string>& files) {
	ofstream	o((base_folder+"\\updates2.dau").c_str());
	if ( !o.is_open() )
		return	false;

	for (list<string>::const_iterator i=files.begin(); i!=files.end() ; ++i ) {
		
		File	file;
		if ( !file.Open( i->c_str(), File::READ) )
			continue;
		DWORD	size;
		if ( !file.GetSize(&size) )
			continue;
		char*	p = new char[size];
		if ( p==NULL )
			continue;
		if ( !file.Read(p, size) ) {
			delete [] p;
			continue;
		}

		MyMD5	md5calc;
		char	md5[33];
		md5calc.MD5_String(p, size, md5);
		delete [] p;
		file.Close();

		string	filename(*i);
		replace(filename, "\\", "/");
		char	sep[2] = { 1, 0 };
		o << (filename.c_str()+base_folder.size()+1) << sep << md5 << sep << endl;
		if ( conf["morelog"]!="0" )
			sender << (filename.c_str()+base_folder.size()+1) << " " << md5 << endl;
	}
	o.close();
	
	return	true;
}
Ejemplo n.º 26
0
bool UpdateExistingShortName(char *Name,wchar *NameW)
{
  FindData fd;
  if (!FindFile::FastFind(Name,NameW,&fd))
    return(false);
  if (*fd.Name==0 || *fd.ShortName==0)
    return(false);
  if (stricomp(PointToName(fd.Name),fd.ShortName)==0 ||
      stricomp(PointToName(Name),fd.ShortName)!=0)
    return(false);

  char NewName[NM];
  for (int I=0;I<10000;I+=123)
  {
    strncpyz(NewName,Name,ASIZE(NewName));
    sprintf(PointToName(NewName),"rtmp%d",I);
    if (!FileExist(NewName))
      break;
  }
  if (FileExist(NewName))
    return(false);
  char FullName[NM];
  strncpyz(FullName,Name,ASIZE(FullName));
  strcpy(PointToName(FullName),PointToName(fd.Name));
  if (!MoveFile(FullName,NewName))
    return(false);
  File KeepShortFile;
  bool Created=false;
  if (!FileExist(Name))
    Created=KeepShortFile.Create(Name);
  MoveFile(NewName,FullName);
  if (Created)
  {
    KeepShortFile.Close();
    KeepShortFile.Delete();
  }
  return(true);
}
Ejemplo n.º 27
0
	//! returns an instance
	CacheFile* CacheFile::GetFile(const std::string& strPath)
	{
		std::map<std::string, CacheFile::Info>::iterator it = m_sCache.find(strPath);
		if(it != m_sCache.end())
		{
			return snew CacheFile(strPath.c_str(), it->second);
		}

		Info info;
		File* pNativeFile = File::CreateNative(strPath.c_str(), File::M_ReadBinary);
		pNativeFile->Open();
		pNativeFile->SetOffset(0, File::OT_End);	
		info.m_Size = pNativeFile->GetOffset();
		info.m_pData = snew u8[info.m_Size];
		pNativeFile->SetOffset(0, File::OT_Start);
		pNativeFile->Read(info.m_pData, info.m_Size);		
		pNativeFile->Close();
		delete pNativeFile;

		CacheFile* pFile = snew CacheFile(strPath.c_str(), info);
		m_sCache[strPath] = info;
		return pFile;
	}
Ejemplo n.º 28
0
bool FileSystem::MakeFile(const std::string &path)
{
    bool ok = false;
    File stream;
    
    // file exist
    ok = FileSystem::IsPathExist(path);
    if (ok) {
        return false;
    }
    
    // create empty file
    ok = stream.Open(path, "wb");
    if (!ok) {
        return false;
    }
    ok = stream.Close();
    if (!ok) {
        return false;
    }
    
    return true;
}
Ejemplo n.º 29
0
void BURGER_API Burger::Debug::String(const char *pString)
{
	// Allow multiple threads to call me!

	if (pString) {
		WordPtr i = StringLength(pString);
		if (i) {
			if (!IsDebuggerPresent()) {
				g_LockString.Lock();
				File MyFile;
				if (MyFile.Open("9:logfile.txt",File::APPEND)==File::OKAY) {
					MyFile.Write(pString,i);		// Send the string to the log file
					MyFile.Close();
				}
			} else {
				g_LockString.Lock();
				// Note: Windows only supports ASCII to the Visual Studio debug console.
				// It does NOT support unicode
				OutputDebugStringA(pString);		// Send to the developer studio console window
			}
			g_LockString.Unlock();
		}
	}
}
Ejemplo n.º 30
0
/*
================
CmdSystemEx::ExportToHTML
================
*/
bool CmdSystemEx::ExportToHTML( const char *filename, int flags ) const {
	if ( FS == OG_NULL )
		return false;

	byte *buffer = OG_NULL;
	FS->LoadFile("exportTemplate.html", &buffer);
	if ( !buffer ) 
		return false;

	String templateBuffer = reinterpret_cast<char *>(buffer);
	FS->FreeFile(buffer);

	File *file = FS->OpenWrite(filename);
	if ( !file )
		return false;

	String table = "<table width=\"900\">\r\n<tr><th width=\"30%\" style=\"text-align:left\"><b>Name</b></th><th style=\"text-align:left\"><b>Description</b></th></tr>\r\n";

	Format out("<tr><td>$*</td><td>$*</td></tr>\r\n");
	int num = cmdList.Num();
	for ( int i = 0; i<num; i++ ) {
		if ( cmdList[i].flags & flags ) {
			table += out << cmdList.GetKey(i) << cmdList[i].usage->strDescription;
			out.Reset();
		}
	}
	table += "</table>\r\n";
	String result;
	result.FromBitFlags( flags, cmdFlagNames );
	templateBuffer.Replace("{{TITLE}}", Format( "Exported Commands with flags ($*)" ) << result );
	templateBuffer.Replace("{{TABLE}}", table.c_str());

	file->Write( templateBuffer.c_str(), templateBuffer.ByteLength() );
	file->Close();
	return true;
}