コード例 #1
0
int CDataBase::CreateDB()
{
	/// TODO: create and show wizard
	if (!CreateNewFile(DBFileSetting) ||
		  !CreateNewFile(DBFilePrivate))
		return EMKPRF_CREATEFAILED;

	return 0;
}
コード例 #2
0
ファイル: SingleTreeMaker.cpp プロジェクト: jrtomps/phdwork
////////// ////////// ////////// ////////// //////////
void 
SingleTreeMaker::CreateNewFileAndTree(const TString absolutePath, const TString fileName, const Int_t compression, const TString treeName )
{
  fMethodName = "CreateNewFileAndTree";

  CreateNewFile( absolutePath, fileName, compression );
  CreateNewTree( treeName );

}//END of CreateNewFileAndTree()
コード例 #3
0
ファイル: drvutil.c プロジェクト: KnowNo/test-code-backup
//
//	CreateDriverFile
//
//	Create a file (based on driver name) ready for driver to be written
//
HANDLE CreateDriverFile(LPCTSTR szDriverName, LPTSTR szPathName, UINT nLength)
{
	HANDLE hFile = INVALID_HANDLE_VALUE;
	TCHAR  szRoot[4];
	
	// try to drop driver in same directory as current exe
	if(!GetDriverFileName(szPathName, nLength, szDriverName))
		return INVALID_HANDLE_VALUE;

	lstrcpyn(szRoot, szPathName, 4);
	
	// if this is a harddisk, try to create file for driver
	if(GetDriveType(szRoot) == DRIVE_FIXED)
	{
		hFile = CreateNewFile(szPathName);
	}

	// otherwise we need a temporary location on a fixed-disk
	if(hFile == INVALID_HANDLE_VALUE)
	{
		// failed, so try temporary directory
		if(!GetDriverTempName(szPathName, nLength, szDriverName))
			return INVALID_HANDLE_VALUE;

		// try to create again
		hFile = CreateNewFile(szPathName);
	}

	// still can't create??? just use any temporary name
	if(hFile == INVALID_HANDLE_VALUE)
	{
		if(!GetDriverTempName2(szPathName, nLength))
			return INVALID_HANDLE_VALUE;

		// try to create one last time
		hFile = CreateNewFile(szPathName);
	}

	return hFile;
}
コード例 #4
0
int CDataBase::OpenDB()
{
  if (!PrivateFileExists())
	{
		// TODO WIZARD
		if (!CreateNewFile(DBFilePrivate))
			return -1;
	}

	int res = LoadFile(DBFileSetting);
	if ((res != 0) && (CLogger::logERROR <= CLogger::Instance().ShowMessage()))
	{
		return res;
	}

	res = LoadFile(DBFilePrivate);

	if ((res != 0) && (CLogger::logERROR <= CLogger::Instance().ShowMessage()))
	{
		return res;
	}
	if (CLogger::logERROR <= CLogger::Instance().ShowMessage())
		return -1;

	m_Entities = new CEntities(*m_BlockManager[DBFilePrivate],
													 m_Header[DBFilePrivate]->Pri.RootEntity,
													 m_Header[DBFilePrivate]->Pri.Entities,
													 m_Header[DBFilePrivate]->Pri.Virtuals);

	m_Entities->sigRootChanged().connect(this, &CDataBase::onEntitiesRootChanged);
	m_Entities->sigVirtualRootChanged().connect(this, &CDataBase::onVirtualsRootChanged);

	if (m_Entities->getRootEntity() != m_Header[DBFilePrivate]->Pri.RootEntity)
	{
		m_Header[DBFilePrivate]->Pri.RootEntity = m_Entities->getRootEntity();
		ReWriteHeader(DBFilePrivate);
	}

	m_Settings = new CSettings(*m_BlockManager[DBFileSetting],
		                         *m_BlockManager[DBFilePrivate],
														  m_Header[DBFileSetting]->Set.Settings,
														 *m_Entities);

	m_Settings->sigRootChanged().connect(this, &CDataBase::onSettingsRootChanged);

	m_Events = new CEvents(*m_BlockManager[DBFilePrivate],
		                     *m_EncryptionManager[DBFilePrivate],
												 *m_Entities,
												 *m_Settings);

	return 0;
}
コード例 #5
0
ファイル: IOMGR.C プロジェクト: AlexShiLucky/HelloX_STM32
//CreateFile,open a device or file given it's name.
static __COMMON_OBJECT* _CreateFile(__COMMON_OBJECT* lpThis,  //IOManager object.
									LPSTR            lpszFileName,
									DWORD            dwAccessMode,
									DWORD            dwShareMode,
									LPVOID           lpReserved)
{
	CHAR FileName[512];
	__COMMON_OBJECT*    pFileHandle = NULL;

	if(NULL == lpszFileName)
	{
		return NULL;
	}
	if(StrLen(lpszFileName) > 511)  //File name too long.
	{
		return NULL;
	}
	if((lpszFileName[0] == 0) || 
	   (lpszFileName[1] == 0) ||
	   (lpszFileName[2] == 0)) //Target file name should has
		                       //at lease 3 characters.
	{
		return NULL;
	}

	//strcpy(FileName,lpszFileName);
	StrCpy(lpszFileName,FileName);
	ToCapital(FileName);  //Convert to capital.
	if(IS_LETTER(FileName[0]))  //Maybe a file object.
	{
		if(FileName[1] != ':')  //Invalid file system name.
		{
			return NULL;
		}
		if(FileName[2] != '\\') //Third character should specify root directory.
		{
			return NULL;
		}
		//A valid file name specified,so try to open it.
		pFileHandle = __OpenFile(lpThis,FileName,dwAccessMode,dwShareMode);
		if(NULL == pFileHandle)
		{
			if(FILE_OPEN_ALWAYS & dwAccessMode)  //Try to create one.
			{
				if(CreateNewFile(lpThis,FileName))  //Can create it.
				{
					pFileHandle = __OpenFile(lpThis,FileName,dwAccessMode,dwShareMode); //Try to open again.
				}
			}
		}
		return pFileHandle;
	}
	//The target name is not a file name,check if a device name.
	if((FileName[0] == '\\') && //For device name,the first 2 character should be '\'.
	   (FileName[1] == '\\') &&
	   (FileName[2] == '.' ))   //The third character should be a dot.
	{
		if(FileName[3] != '\\') //The 4th character also must be '\'.
		{
			return NULL;
		}
		//The name is a device name,try to open ti.
		return __OpenDevice(lpThis,FileName,dwAccessMode,dwShareMode);
	}
	return NULL;
}
コード例 #6
0
ファイル: TRI.c プロジェクト: Daniel-Warner-X/Nintendont
u32 TRISetupGames(char *Path, u32 CurDICMD, u32 ISOShift)
{
	u32 res = 0;
	FILE *f = NULL;
	u32 DOLOffset = 0;
	if(CurDICMD)
	{
		ReadRealDisc((u8*)&DOLOffset, 0x420+ISOShift, 4, CurDICMD);
		DOLOffset+=ISOShift;
	}
	else
	{
		char FullPath[300];
		snprintf(FullPath, sizeof(FullPath), "%s:%s", GetRootDevice(), Path);
		f = fopen(FullPath, "rb");
		if(f != NULL)
		{
			fseek(f, 0x420+ISOShift, SEEK_SET);
			fread(&DOLOffset, 1, 4, f);
			DOLOffset+=ISOShift;
		}
		else
		{
			char FSTPath[300];
			snprintf(FSTPath, sizeof(FSTPath), "%ssys/main.dol", FullPath);
			f = fopen(FSTPath, "rb");
		}
		if(f == NULL)
			return 0;
	}

	char SaveFile[128];
	if(DOLRead32(0x210320, DOLOffset, f, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:Mario Kart GP1\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), CARD_NAME_GP1);
		CreateNewFile(SaveFile, 0x45);
	}
	else if(DOLRead32(0x25C0AC, DOLOffset, f, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:Mario Kart GP2\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), CARD_NAME_GP2);
		CreateNewFile(SaveFile, 0x45);
	}
	else if(DOLRead32(0x1821C4, DOLOffset, f, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:F-Zero AX (Unk)\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), CARD_NAME_AX);
		CreateNewFile(SaveFile, 0xCF);
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), SETTINGS_AX_UNK);
		CreateNewFile(SaveFile, 0x2A);
	}
	else if(DOLRead32(0x181E60, DOLOffset, f, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:F-Zero AX (Rev C)\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), CARD_NAME_AX);
		CreateNewFile(SaveFile, 0xCF);
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), SETTINGS_AX_RVC);
		CreateNewFile(SaveFile, 0x2A);
	}
	else if(DOLRead32(0x18275C, DOLOffset, f, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:F-Zero AX (Rev E)\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), CARD_NAME_AX);
		CreateNewFile(SaveFile, 0xCF);
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), SETTINGS_AX_RVE);
		CreateNewFile(SaveFile, 0x2A);
	}
	else if(DOLRead32(0x01C2DF4, DOLOffset, f, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:Virtua Striker 3 Ver 2002\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), SETTINGS_VS3V02);
		CreateNewFile(SaveFile, 0x12);
	}
	else if(DOLRead32(0x01CF1C4, DOLOffset, f, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:Virtua Striker 4 (Japan)\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), SETTINGS_VS4JAP);
		CreateNewFile(SaveFile, 0x2B);
	}
	else if(DOLRead32(0x1C5514, DOLOffset, f, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:Virtua Striker 4 (Export)\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), SETTINGS_VS4EXP);
		CreateNewFile(SaveFile, 0x2B);
	}
	else if(DOLRead32(0x24B248, DOLOffset, f, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:Virtua Striker 4 Ver 2006 (Japan)\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), SETTINGS_VS4V06JAP);
		CreateNewFile(SaveFile, 0x2E);
	}
	else if(DOLRead32(0x20D7E8, DOLOffset, f, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:Virtua Striker 4 Ver 2006 (Export)\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), SETTINGS_VS4V06EXP);
		CreateNewFile(SaveFile, 0x2B);
	}
	else if(DOLRead32(0x26B3F4, DOLOffset, f, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:Gekitou Pro Yakyuu (Rev B)\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), SETTINGS_YAKRVB);
		CreateNewFile(SaveFile, 0xF5);
	}
	else if(DOLRead32(0x26D9B4, DOLOffset, f, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:Gekitou Pro Yakyuu (Rev C)\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), SETTINGS_YAKRVC);
		CreateNewFile(SaveFile, 0x100);
	}

	if(f != NULL)
		fclose(f);
	return res;
}
コード例 #7
0
/*----------------------------------------------------------------------
|       main
+---------------------------------------------------------------------*/
int
main(int argc, char** argv)
{
    NPT_Result result;
    NPT_FileInfo info;

    NPT_ASSERT(NPT_File::GetInfo("foobar.doesnotexist", NULL) == NPT_ERROR_NO_SUCH_FILE);
    NPT_ASSERT(!NPT_File::Exists("foobar.doesnotexist"));

    // test special names
    NPT_File file(NPT_FILE_STANDARD_INPUT);
    NPT_ASSERT(NPT_SUCCEEDED(file.GetInfo(info)));
    NPT_ASSERT(info.m_Type == NPT_FileInfo::FILE_TYPE_SPECIAL);
    file = NPT_File(NPT_FILE_STANDARD_OUTPUT);

    NPT_ASSERT(NPT_SUCCEEDED(file.GetInfo(info)));
    NPT_ASSERT(info.m_Type == NPT_FileInfo::FILE_TYPE_SPECIAL);
    file = NPT_File(NPT_FILE_STANDARD_ERROR);
    NPT_ASSERT(NPT_SUCCEEDED(file.GetInfo(info)));
    NPT_ASSERT(info.m_Type == NPT_FileInfo::FILE_TYPE_SPECIAL);

    if (NPT_File::Exists("foobar.file1")) {
        result = NPT_File::DeleteFile("foobar.file1");
        NPT_ASSERT(NPT_SUCCEEDED(result));
    }

    result = CreateNewFile("foobar.file1", 9);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(NPT_File::Exists("foobar.file1"));
    result = NPT_File::GetInfo("foobar.file1", &info);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(info.m_Type == NPT_FileInfo::FILE_TYPE_REGULAR);
    NPT_ASSERT(info.m_Size == 9);

    {
        NPT_File f1("foobar.file1");
        result = f1.GetInfo(info);
        NPT_ASSERT(NPT_SUCCEEDED(result));
        NPT_ASSERT(info.m_Type == NPT_FileInfo::FILE_TYPE_REGULAR);
        NPT_ASSERT(info.m_Size == 9);
    }
    {
        NPT_File f1("foobar.file1");
        NPT_LargeSize size;
        result = f1.GetSize(size);
        NPT_ASSERT(NPT_SUCCEEDED(result));
        NPT_ASSERT(size == 9);
    }

    {
        NPT_File f1("foobar.file1");
        result = f1.Rename("foobar.file1-r");
        NPT_ASSERT(NPT_SUCCEEDED(result));
        NPT_ASSERT(f1.GetPath() == "foobar.file1-r");
    }
    NPT_ASSERT(NPT_File::Exists("foobar.file1-r"));
    result = NPT_File::GetInfo("foobar.file1-r", &info);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(info.m_Type == NPT_FileInfo::FILE_TYPE_REGULAR);
    NPT_ASSERT(info.m_Size == 9);

    // dirs
    NPT_ASSERT(!NPT_File::Exists("foobar.dir"));
    result = NPT_File::CreateDirectory("foobar.dir");
    NPT_ASSERT(NPT_SUCCEEDED(result));
    result = NPT_File::GetInfo("foobar.dir", &info);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(info.m_Type == NPT_FileInfo::FILE_TYPE_DIRECTORY);
    {
        NPT_File f1("foobar.dir");
        result = f1.GetInfo(info);
        NPT_ASSERT(NPT_SUCCEEDED(result));
        NPT_ASSERT(info.m_Type == NPT_FileInfo::FILE_TYPE_DIRECTORY);
    }

    NPT_String dirname = "foobar.dir";
    NPT_String fname;
    fname = dirname;
    fname += NPT_FilePath::Separator;
    fname += "file1";
    result = CreateNewFile(fname, 1);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    fname = dirname;
    fname += NPT_FilePath::Separator;
    fname += "file2";
    result = CreateNewFile(fname, 2);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    fname = dirname;
    fname += NPT_FilePath::Separator;
    fname += "file3";
    result = CreateNewFile(fname, 3);
    NPT_ASSERT(NPT_SUCCEEDED(result));

    NPT_List<NPT_String> entries;
    result = NPT_File::ListDirectory("foobar.dir", entries);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(entries.GetItemCount() == 3);

    result = NPT_File::DeleteFile("foobar.dir");
    NPT_ASSERT(NPT_FAILED(result));
    result = NPT_File::DeleteDirectory("foobar.dir");
    NPT_ASSERT(result == NPT_ERROR_DIRECTORY_NOT_EMPTY);

    result = NPT_File::Rename("foobar.dir", "foobar.dir-r");
    NPT_ASSERT(NPT_SUCCEEDED(result));

    dirname = "foobar.dir-r";
    fname = dirname;
    fname += NPT_FilePath::Separator;
    fname += "file1";
    result = NPT_File::DeleteFile(fname);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    fname = dirname;
    fname += NPT_FilePath::Separator;
    fname += "file2";
    result = NPT_File::DeleteFile(fname);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    fname = dirname;
    fname += NPT_FilePath::Separator;
    fname += "file3";
    result = NPT_File::DeleteFile(fname);
    NPT_ASSERT(NPT_SUCCEEDED(result));

    result = NPT_File::DeleteDirectory("foobar.dir-r");
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(!NPT_File::Exists("foobar.dir-r"));

    // paths
    NPT_String test;
    test = NPT_FilePath::BaseName("");
    NPT_ASSERT(test == "");
    test = NPT_FilePath::BaseName("a");
    NPT_ASSERT(test == "a");
    test = NPT_FilePath::BaseName("a"+NPT_FilePath::Separator+"b");
    NPT_ASSERT(test == "b");
    test = NPT_FilePath::BaseName("a"+NPT_FilePath::Separator+"b"+NPT_FilePath::Separator);
    NPT_ASSERT(test == "");
    test = NPT_FilePath::BaseName(NPT_FilePath::Separator+"a");
    NPT_ASSERT(test == "a");
    test = NPT_FilePath::BaseName(NPT_FilePath::Separator);
    NPT_ASSERT(test == "");

    test = NPT_FilePath::DirectoryName("");
    NPT_ASSERT(test == "");
    test = NPT_FilePath::DirectoryName("a");
    NPT_ASSERT(test == "");
    test = NPT_FilePath::DirectoryName("a"+NPT_FilePath::Separator+"b");
    NPT_ASSERT(test == "a");
    test = NPT_FilePath::DirectoryName("a"+NPT_FilePath::Separator+"b"+NPT_FilePath::Separator);
    NPT_ASSERT(test == "a"+NPT_FilePath::Separator+"b");
    test = NPT_FilePath::DirectoryName(NPT_FilePath::Separator+"a");
    NPT_ASSERT(test == NPT_FilePath::Separator);
    test = NPT_FilePath::DirectoryName(NPT_FilePath::Separator);
    NPT_ASSERT(test == NPT_FilePath::Separator);

    // large files
    if (argc == 2) {
        result = CreateNewFile(argv[1], 0x10000, 0x10007);
        NPT_ASSERT(NPT_SUCCEEDED(result));

        NPT_String new_name = argv[1];
        new_name += ".renamed";
        result = NPT_File::Rename(argv[1], new_name);
        NPT_ASSERT(NPT_SUCCEEDED(result));
        file = NPT_File(new_name);
        result = file.Open(NPT_FILE_OPEN_MODE_READ);
        NPT_ASSERT(NPT_SUCCEEDED(result));
        NPT_InputStreamReference input;
        file.GetInputStream(input);
        NPT_Position position;
        result = input->Tell(position);
        NPT_ASSERT(NPT_SUCCEEDED(result));
        NPT_ASSERT(position == 0);
        NPT_LargeSize large_size = (NPT_LargeSize)0x10007 * (NPT_LargeSize)0x10000;
        result = input->Seek(large_size-0x10007);
        NPT_ASSERT(NPT_SUCCEEDED(result));
        result = input->Tell(position);
        NPT_ASSERT(NPT_SUCCEEDED(result));
        NPT_ASSERT(position == large_size-0x10007);
        unsigned char* buffer = new unsigned char[0x10007];
        result = input->ReadFully(buffer, 0x10007);
        NPT_ASSERT(NPT_SUCCEEDED(result));
        result = input->Tell(position);
        NPT_ASSERT(NPT_SUCCEEDED(result));
        NPT_ASSERT(position == large_size);
        for (unsigned int i=0; i<0x10007; i++) {
            NPT_ASSERT(buffer[i] == (unsigned char)i);
        }
        file.Close();
        NPT_File::DeleteFile(new_name);
    }

    return 0;
}
コード例 #8
0
ファイル: BootMonFsOpenClose.c プロジェクト: Michell-Lee/edk2
/**
  Opens a file on the Nor Flash FS volume

  Calls BootMonFsGetFileFromAsciiFilename to search the list of tracked files.

  @param  This  The EFI_FILE_PROTOCOL parent handle.
  @param  NewHandle Double-pointer to the newly created protocol.
  @param  FileName The name of the image/metadata on flash
  @param  OpenMode Read,write,append etc
  @param  Attributes ?

  @return EFI_STATUS
  OUT_OF_RESOURCES
    Run out of space to keep track of the allocated structures
  DEVICE_ERROR
    Unable to locate the volume associated with the parent file handle
  NOT_FOUND
    Filename wasn't found on flash
  SUCCESS

**/
EFIAPI
EFI_STATUS
BootMonFsOpenFile (
  IN EFI_FILE_PROTOCOL  *This,
  OUT EFI_FILE_PROTOCOL **NewHandle,
  IN CHAR16             *FileName,
  IN UINT64             OpenMode,
  IN UINT64             Attributes
  )
{
  BOOTMON_FS_FILE     *Directory;
  BOOTMON_FS_FILE     *File;
  BOOTMON_FS_INSTANCE *Instance;
  CHAR8*               AsciiFileName;
  EFI_STATUS           Status;

  if ((FileName == NULL) || (NewHandle == NULL)) {
    return EFI_INVALID_PARAMETER;
  }

  // The only valid modes are read, read/write, and read/write/create
  if (!(OpenMode & EFI_FILE_MODE_READ) || ((OpenMode & EFI_FILE_MODE_CREATE)  && !(OpenMode & EFI_FILE_MODE_WRITE))) {
    return EFI_INVALID_PARAMETER;
  }

  Directory = BOOTMON_FS_FILE_FROM_FILE_THIS (This);
  if (Directory == NULL) {
    return EFI_DEVICE_ERROR;
  }

  Instance = Directory->Instance;

  // If the instance has not been initialized it yet then do it ...
  if (!Instance->Initialized) {
    Status = BootMonFsInitialize (Instance);
    if (EFI_ERROR (Status)) {
      return Status;
    }
  }

  // BootMonFs interface requires ASCII filenames
  AsciiFileName = AllocatePool ((StrLen (FileName) + 1) * sizeof (CHAR8));
  if (AsciiFileName == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }
  UnicodeStrToAsciiStr (FileName, AsciiFileName);

  if ((AsciiStrCmp (AsciiFileName, "\\") == 0) ||
      (AsciiStrCmp (AsciiFileName, "/")  == 0) ||
      (AsciiStrCmp (AsciiFileName, "")   == 0) ||
      (AsciiStrCmp (AsciiFileName, ".")  == 0))
  {
    //
    // Opening '/', '\', '.', or the NULL pathname is trying to open the root directory
    //

    *NewHandle = &Instance->RootFile->File;
    Instance->RootFile->Position = 0;
    Status = EFI_SUCCESS;
  } else {
    //
    // Open or Create a regular file
    //

    // Check if the file already exists
    Status = BootMonGetFileFromAsciiFileName (Instance, AsciiFileName, &File);
    if (Status == EFI_NOT_FOUND) {
      // The file doesn't exist.
      if (OpenMode & EFI_FILE_MODE_CREATE) {
        // If the file does not exist but is required then create it.
        if (Attributes & EFI_FILE_DIRECTORY) {
          // BootMonFS doesn't support subdirectories
          Status = EFI_UNSUPPORTED;
        } else {
          // Create a new file
          Status = CreateNewFile (Instance, AsciiFileName, &File);
          if (!EFI_ERROR (Status)) {
            File->OpenMode = OpenMode;
            *NewHandle = &File->File;
            File->Position = 0;
          }
        }
      }
    } else if (Status == EFI_SUCCESS) {
      // The file exists
      File->OpenMode = OpenMode;
      *NewHandle = &File->File;
      File->Position = 0;
    }
  }

  FreePool (AsciiFileName);

  return Status;
}
コード例 #9
0
ファイル: TRI.c プロジェクト: DankRank/Nintendont
u32 TRISetupGames(char *Path, u32 CurDICMD, u32 ISOShift)
{
	u32 res = 0;
	u32 DOLOffset = 0;
	FIL f;
	FIL *fp = NULL;
	UINT read;
	FRESULT fres = FR_DISK_ERR;

	if(CurDICMD)
	{
		ReadRealDisc((u8*)&DOLOffset, 0x420+ISOShift, 4, CurDICMD);
		DOLOffset+=ISOShift;
	}
	else
	{
		char FullPath[260];
		snprintf(FullPath, sizeof(FullPath), "%s:%s", GetRootDevice(), Path);
		fres = f_open_char(&f, FullPath, FA_READ|FA_OPEN_EXISTING);
		if (fres == FR_OK)
		{
			f_lseek(&f, 0x420+ISOShift);
			f_read(&f, &DOLOffset, 4, &read);
			DOLOffset+=ISOShift;
		}
		else
		{
			char FSTPath[260];
			snprintf(FSTPath, sizeof(FSTPath), "%ssys/main.dol", FullPath);
			fres = f_open_char(&f, FSTPath, FA_READ|FA_OPEN_EXISTING);
		}

		if (fres != FR_OK)
			return 0;
		fp = &f;
	}

	// Create the save file if it doesn't already exist.
	char SaveFile[128];
	if(DOLRead32(0x210320, DOLOffset, fp, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:Mario Kart Arcade GP (Feb 14 2006 13:09:48)\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), CARD_NAME_GP1);
		CreateNewFile(SaveFile, 0x45);
	}
	else if(DOLRead32(0x25C0AC, DOLOffset, fp, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:Mario Kart Arcade GP 2 (Feb 7 2007 02:47:24)\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), CARD_NAME_GP2);
		CreateNewFile(SaveFile, 0x45);
	}
	else if(DOLRead32(0x181E60, DOLOffset, fp, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:F-Zero AX (Rev C)\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), CARD_NAME_AX);
		CreateNewFile(SaveFile, 0xCF);
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), SETTINGS_AX_RVC);
		CreateNewFile(SaveFile, 0x2A);
	}
	else if(DOLRead32(0x1821C4, DOLOffset, fp, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:F-Zero AX (Rev D)\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), CARD_NAME_AX);
		CreateNewFile(SaveFile, 0xCF);
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), SETTINGS_AX_RVD);
		CreateNewFile(SaveFile, 0x2A);
	}
	else if(DOLRead32(0x18275C, DOLOffset, fp, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:F-Zero AX (Rev E)\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), CARD_NAME_AX);
		CreateNewFile(SaveFile, 0xCF);
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), SETTINGS_AX_RVE);
		CreateNewFile(SaveFile, 0x2A);
	}
	else if(DOLRead32(0x01C2DF4, DOLOffset, fp, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:Virtua Striker 3 Ver 2002\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), SETTINGS_VS3V02);
		CreateNewFile(SaveFile, 0x12);
	}
	else if(DOLRead32(0x01CF1C4, DOLOffset, fp, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:Virtua Striker 4 (Japan)\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), SETTINGS_VS4JAP);
		CreateNewFile(SaveFile, 0x2B);
	}
	else if(DOLRead32(0x1C5514, DOLOffset, fp, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:Virtua Striker 4 (Export)\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), SETTINGS_VS4EXP);
		CreateNewFile(SaveFile, 0x2B);
	}
	else if(DOLRead32(0x24B248, DOLOffset, fp, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:Virtua Striker 4 Ver 2006 (Japan)\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), SETTINGS_VS4V06JAP);
		CreateNewFile(SaveFile, 0x2E);
	}
	else if(DOLRead32(0x20D7E8, DOLOffset, fp, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:Virtua Striker 4 Ver 2006 (Export)\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), SETTINGS_VS4V06EXP);
		CreateNewFile(SaveFile, 0x2B);
	}
	else if(DOLRead32(0x26B3F4, DOLOffset, fp, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:Gekitou Pro Yakyuu (Rev B)\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), SETTINGS_YAKRVB);
		CreateNewFile(SaveFile, 0xF5);
	}
	else if(DOLRead32(0x26D9B4, DOLOffset, fp, CurDICMD) == 0x386000A8)
	{
		res = 1;
		gprintf("TRI:Gekitou Pro Yakyuu (Rev C)\r\n");
		snprintf(SaveFile, sizeof(SaveFile), "%s:%s", GetRootDevice(), SETTINGS_YAKRVC);
		CreateNewFile(SaveFile, 0x100);
	}

	if (fres == FR_OK)
		f_close(&f);
	return res;
}
コード例 #10
0
ファイル: FileTest1.cpp プロジェクト: AWilco/xbmc
/*----------------------------------------------------------------------
|       main
+---------------------------------------------------------------------*/
int
main(int argc, char** argv)
{
    NPT_Result result;
    NPT_FileInfo info;
    
    NPT_ASSERT(NPT_File::GetInfo("foobar.doesnotexist", NULL) == NPT_ERROR_NO_SUCH_FILE);
    NPT_ASSERT(!NPT_File::Exists("foobar.doesnotexist"));
    
    // test special names
    NPT_File file(NPT_FILE_STANDARD_INPUT);
    NPT_ASSERT(NPT_SUCCEEDED(file.GetInfo(info)));
    NPT_ASSERT(info.m_Type == NPT_FileInfo::FILE_TYPE_SPECIAL);
    file = NPT_File(NPT_FILE_STANDARD_OUTPUT);
    
    NPT_ASSERT(NPT_SUCCEEDED(file.GetInfo(info)));
    NPT_ASSERT(info.m_Type == NPT_FileInfo::FILE_TYPE_SPECIAL);
    file = NPT_File(NPT_FILE_STANDARD_ERROR);
    NPT_ASSERT(NPT_SUCCEEDED(file.GetInfo(info)));
    NPT_ASSERT(info.m_Type == NPT_FileInfo::FILE_TYPE_SPECIAL);

    if (NPT_File::Exists("foobar.file1")) {
        result = NPT_File::RemoveFile("foobar.file1");
        NPT_ASSERT(NPT_SUCCEEDED(result));
    }
    
    result = CreateNewFile("foobar.file1", 9);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(NPT_File::Exists("foobar.file1"));
    result = NPT_File::GetInfo("foobar.file1", &info);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(info.m_Type == NPT_FileInfo::FILE_TYPE_REGULAR);
    NPT_ASSERT(info.m_Size == 9);
    
    {
        NPT_File f1("foobar.file1");
        result = f1.GetInfo(info);
        NPT_ASSERT(NPT_SUCCEEDED(result));
        NPT_ASSERT(info.m_Type == NPT_FileInfo::FILE_TYPE_REGULAR);
        NPT_ASSERT(info.m_Size == 9);
    }
    {
        NPT_File f1("foobar.file1");
        NPT_LargeSize size;
        result = f1.GetSize(size);
        NPT_ASSERT(NPT_SUCCEEDED(result));
        NPT_ASSERT(size == 9);
    }
    
    {
        NPT_File f1("foobar.file1");
        result = f1.Rename("foobar.file1-r");
        NPT_ASSERT(NPT_SUCCEEDED(result));
        NPT_ASSERT(f1.GetPath() == "foobar.file1-r");
    }
    NPT_ASSERT(NPT_File::Exists("foobar.file1-r"));
    result = NPT_File::GetInfo("foobar.file1-r", &info);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(info.m_Type == NPT_FileInfo::FILE_TYPE_REGULAR);
    NPT_ASSERT(info.m_Size == 9);

    // dirs
    NPT_ASSERT(!NPT_File::Exists("foobar.dir"));
    result = NPT_File::CreateDir("foobar.dir");
    NPT_ASSERT(NPT_SUCCEEDED(result));
    result = NPT_File::GetInfo("foobar.dir", &info);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(info.m_Type == NPT_FileInfo::FILE_TYPE_DIRECTORY);
    {
        NPT_File f1("foobar.dir");
        result = f1.GetInfo(info);
        NPT_ASSERT(NPT_SUCCEEDED(result));
        NPT_ASSERT(info.m_Type == NPT_FileInfo::FILE_TYPE_DIRECTORY);
    }

    NPT_String dirname = "foobar.dir";
    NPT_String fname;
    fname = dirname;
    fname += NPT_FilePath::Separator;
    fname += "file1";
    result = CreateNewFile(fname, 1);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    fname = dirname;
    fname += NPT_FilePath::Separator;
    fname += "file2";
    result = CreateNewFile(fname, 2);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    fname = dirname;
    fname += NPT_FilePath::Separator;
    fname += "file3";
    result = CreateNewFile(fname, 3);
    NPT_ASSERT(NPT_SUCCEEDED(result));

    NPT_List<NPT_String> entries;
    result = NPT_File::ListDir("foobar.dir", entries);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(entries.GetItemCount() == 3);
    
    result = NPT_File::RemoveFile("foobar.dir");
    NPT_ASSERT(NPT_FAILED(result));
    result = NPT_File::RemoveDir("foobar.dir");
    NPT_ASSERT(result == NPT_ERROR_DIRECTORY_NOT_EMPTY);
    
    result = NPT_File::Rename("foobar.dir", "foobar.dir-r");
    NPT_ASSERT(NPT_SUCCEEDED(result));
    
    dirname = "foobar.dir-r";
    fname = dirname;
    fname += NPT_FilePath::Separator;
    fname += "file1";
    result = NPT_File::RemoveFile(fname);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    fname = dirname;
    fname += NPT_FilePath::Separator;
    fname += "file2";
    result = NPT_File::RemoveFile(fname);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    fname = dirname;
    fname += NPT_FilePath::Separator;
    fname += "file3";
    result = NPT_File::RemoveFile(fname);
    NPT_ASSERT(NPT_SUCCEEDED(result));

    result = NPT_File::RemoveDir("foobar.dir-r");
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(!NPT_File::Exists("foobar.dir-r"));

    // paths
    NPT_String test;
    test = NPT_FilePath::BaseName("");
    NPT_ASSERT(test == "");
    test = NPT_FilePath::BaseName("a");
    NPT_ASSERT(test == "a");
    test = NPT_FilePath::BaseName("a"+NPT_FilePath::Separator+"b");
    NPT_ASSERT(test == "b");
    test = NPT_FilePath::BaseName("a"+NPT_FilePath::Separator+"b"+NPT_FilePath::Separator);
    NPT_ASSERT(test == "");
    test = NPT_FilePath::BaseName(NPT_FilePath::Separator+"a");
    NPT_ASSERT(test == "a");
    test = NPT_FilePath::BaseName(NPT_FilePath::Separator);
    NPT_ASSERT(test == "");

    test = NPT_FilePath::DirName("");
    NPT_ASSERT(test == "");
    test = NPT_FilePath::DirName("a");
    NPT_ASSERT(test == "");
    test = NPT_FilePath::DirName("a"+NPT_FilePath::Separator+"b");
    NPT_ASSERT(test == "a");
    test = NPT_FilePath::DirName("a"+NPT_FilePath::Separator+"b"+NPT_FilePath::Separator);
    NPT_ASSERT(test == "a"+NPT_FilePath::Separator+"b");
    test = NPT_FilePath::DirName(NPT_FilePath::Separator+"a");
    NPT_ASSERT(test == NPT_FilePath::Separator);
    test = NPT_FilePath::DirName(NPT_FilePath::Separator);
    NPT_ASSERT(test == NPT_FilePath::Separator);
    
    // small files
    result = CreateNewFile("small.bin", 0x100, 0x107);
    NPT_ASSERT(NPT_SUCCEEDED(result));

    file = NPT_File("small.bin");
    result = file.Open(NPT_FILE_OPEN_MODE_READ);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_InputStreamReference input;
    file.GetInputStream(input);
    NPT_Position position;
    result = input->Tell(position);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(position == 0);
    NPT_LargeSize large_size = (NPT_LargeSize)0x107 * (NPT_LargeSize)0x100;
    result = input->Seek(large_size-0x107);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    result = input->Tell(position);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(position == large_size-0x107);        
    unsigned char* buffer = new unsigned char[0x107];
    result = input->ReadFully(buffer, 0x107);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    result = input->Tell(position);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(position == large_size);
    for (unsigned int i=0; i<0x107; i++) {
        NPT_ASSERT(buffer[i] == (unsigned char)i);
    }        
    file.Close();
    NPT_File::RemoveFile(file.GetPath());

    // large files
    if (argc == 2) {
        result = CreateNewFile(argv[1], 0x10000, 0x10007);
        NPT_ASSERT(NPT_SUCCEEDED(result));

        NPT_String new_name = argv[1];
        new_name += ".renamed";
        result = NPT_File::Rename(argv[1], new_name);
        NPT_ASSERT(NPT_SUCCEEDED(result));
        file = NPT_File(new_name);
        result = file.Open(NPT_FILE_OPEN_MODE_READ);
        NPT_ASSERT(NPT_SUCCEEDED(result));
        file.GetInputStream(input);
        result = input->Tell(position);
        NPT_ASSERT(NPT_SUCCEEDED(result));
        NPT_ASSERT(position == 0);
        large_size = (NPT_LargeSize)0x10007 * (NPT_LargeSize)0x10000;
        result = input->Seek(large_size-0x10007);
        NPT_ASSERT(NPT_SUCCEEDED(result));
        result = input->Tell(position);
        NPT_ASSERT(NPT_SUCCEEDED(result));
        NPT_ASSERT(position == large_size-0x10007);        
        buffer = new unsigned char[0x10007];
        result = input->ReadFully(buffer, 0x10007);
        NPT_ASSERT(NPT_SUCCEEDED(result));
        result = input->Tell(position);
        NPT_ASSERT(NPT_SUCCEEDED(result));
        NPT_ASSERT(position == large_size);
        for (unsigned int i=0; i<0x10007; i++) {
            NPT_ASSERT(buffer[i] == (unsigned char)i);
        }        
        file.Close();
        NPT_File::RemoveFile(new_name);
    }
    
    // test dynamic size
    //NPT_LargeSize             size;
    unsigned char             buff[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};  
    const char*               filename = "pi.\xCF\x80.test";
    NPT_TimeInterval          wait(2.0f);
    
    if (argc > 1) {
        filename = argv[1];
    }
    
    NPT_File                  file1(filename);
    NPT_OutputStreamReference output;

    NPT_ASSERT(NPT_SUCCEEDED(file1.Open(NPT_FILE_OPEN_MODE_CREATE | NPT_FILE_OPEN_MODE_WRITE | NPT_FILE_OPEN_MODE_READ | NPT_FILE_OPEN_MODE_TRUNCATE)));
    NPT_ASSERT(NPT_SUCCEEDED(file1.GetSize(size)));
    NPT_ASSERT(size == 0);
    NPT_ASSERT(NPT_SUCCEEDED(file1.GetOutputStream(output)));
    NPT_ASSERT(NPT_SUCCEEDED(file1.GetInputStream(input)));
    NPT_ASSERT(NPT_SUCCEEDED(output->Tell(position)));
    NPT_ASSERT(position == 0);
    NPT_ASSERT(NPT_SUCCEEDED(input->Tell(position)));
    NPT_ASSERT(position == 0);
    NPT_ASSERT(NPT_SUCCEEDED(output->WriteFully(buff, 16)));
    output->Flush();
    NPT_System::Sleep(wait);
    NPT_ASSERT(NPT_SUCCEEDED(file1.GetSize(size)));
    NPT_ASSERT(size == 16);
    NPT_ASSERT(NPT_SUCCEEDED(output->Tell(position)));
    NPT_ASSERT(NPT_SUCCEEDED(input->GetSize(size)));
    NPT_ASSERT(size == 16);
    NPT_ASSERT(position == 16);
    NPT_ASSERT(NPT_SUCCEEDED(input->Tell(position)));
    NPT_ASSERT(position == 16);
    NPT_ASSERT(NPT_SUCCEEDED(output->Seek(8)));
    NPT_ASSERT(NPT_SUCCEEDED(output->Tell(position)));
    NPT_ASSERT(position == 8);
    
    NPT_File                 file2(filename);
    NPT_InputStreamReference input2;

    NPT_ASSERT(NPT_SUCCEEDED(file2.Open(NPT_FILE_OPEN_MODE_READ)));
    NPT_ASSERT(NPT_SUCCEEDED(file2.GetSize(size)));
    NPT_ASSERT(size == 16);
    NPT_ASSERT(NPT_SUCCEEDED(file2.GetInputStream(input2)));
    NPT_ASSERT(NPT_SUCCEEDED(input2->GetSize(size)));
    NPT_ASSERT(size == 16);
    NPT_ASSERT(NPT_SUCCEEDED(input2->Tell(position)));
    NPT_ASSERT(position == 0);
    NPT_ASSERT(NPT_SUCCEEDED(input2->Seek(8)));
    NPT_ASSERT(NPT_SUCCEEDED(input2->Tell(position)));
    NPT_ASSERT(position == 8);
    
    NPT_ASSERT(NPT_SUCCEEDED(output->WriteFully(buff, 16)));
    output->Flush();
    NPT_System::Sleep(wait);
    NPT_ASSERT(NPT_SUCCEEDED(file2.GetSize(size)));
    NPT_ASSERT(size == 24);
    NPT_ASSERT(NPT_SUCCEEDED(output->Tell(position)));
    NPT_ASSERT(position == 24);
    NPT_ASSERT(NPT_SUCCEEDED(input->Tell(position)));
    NPT_ASSERT(position == 24);
    
    NPT_ASSERT(NPT_SUCCEEDED(input2->GetSize(size)));
    NPT_ASSERT(size == 24);
    NPT_ASSERT(NPT_SUCCEEDED(input2->Seek(20)));
    NPT_ASSERT(NPT_SUCCEEDED(input2->Read(buff, 4, NULL)));
    
    return 0;
}