示例#1
0
// ==================================================
Result FS_filesysInit(Handle* sdHandle, Handle* saveHandle, FS_archive* sdArchive, FS_archive* saveArchive)
// --------------------------------------------------
{
	Result ret;
	printf("  Getting SD Card handle\n");
	ret = srvGetServiceHandle(sdHandle, "fs:USER");
	if (ret) return ret;

	printf("  Opening SD Card archive\n");
	*sdArchive = (FS_archive){0x9, (FS_path){PATH_EMPTY, 1, (u8*)""}, 0, 0};
	ret = FSUSER_OpenArchive(sdHandle, sdArchive);
	if (ret) return ret;

	printf("  Getting save handle\n");
	ret = _srvGetServiceHandle(saveHandle, "fs:USER");
	if (ret) return ret;

	printf("  Initializing save handle\n");
	ret = FSUSER_Initialize(saveHandle);
	if (ret) return ret;

	printf("  Opening save archive\n");
	*saveArchive = (FS_archive){0x4, (FS_path){PATH_EMPTY, 0, NULL}, 0, 0};
	ret = FSUSER_OpenArchive(saveHandle, saveArchive);
	return ret;
}
示例#2
0
文件: fs.c 项目: gocario/PHBankGB
Result FSCIA_Init(u64 titleid, FS_MediaType mediatype)
{
	Result ret = 1;

	debug_print("FSCIA_Init:\n");

	if (!saveInitialized)
	{
		lowPath[0] = mediatype;
		lowPath[1] = titleid; /// titleid & 0xFFFFFFFF
		lowPath[2] = titleid >> 32; // (titleid >> 32) & 0xFFFFFFFF

		debug_print(" > [0]: 0x%016lx\n", lowPath[0]);
		debug_print(" > [1]: 0x%016lx\n", lowPath[1]);
		debug_print(" > [2]: 0x%016lx\n", lowPath[2]);

		ret = FSUSER_OpenArchive(&saveArchive, ARCHIVE_USER_SAVEDATA, (FS_Path) { PATH_BINARY, 12, lowPath });
		r(" > FSUSER_OpenArchive: %lx\n", ret);

		saveInitialized = R_SUCCEEDED(ret); // true

		if (!saveInitialized)
		{
			ret = FSUSER_OpenArchive(&saveArchive, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, NULL));
			r(" > FSUSER_OpenArchive: %lx\n", ret);

			saveInitialized = R_SUCCEEDED(ret); // true
		}
	}
示例#3
0
//All the information used here was found on 3dbrew.org
//thank them too.
bool openSaveArch(FS_Archive *out, const titleData dat, bool showError)
{
    //binary path
    u32 path[3];
    //first is mediaType
    path[0] = dat.media;
    //low id
    path[1] = dat.low;
    //high id. this is usually 0x00040000
    path[2] = dat.high;

    //setup archive info
    Handle fs;
    *out = (FS_Archive){ARCHIVE_USER_SAVEDATA, (FS_Path){PATH_BINARY, 12, path}};
    Result res = FSUSER_OpenArchive(out);
    if(res)
    {
        if(showError)
            showMessage("Error opening save archive!");
        logWriteError("Error opening save archive", res);
        return false;
    }

    return true;
}
示例#4
0
文件: FileSystem.c 项目: St4rk/3DNES
void NES_LOADROMLIST() {
	Handle romHandle;
	
	FS_dirent dirStruct;
	FS_path dirPath = FS_makePath(PATH_CHAR, "/3DNES/ROMS");

	// init SDMC archive
	sdmcArchive = (FS_archive){0x9, (FS_path){PATH_EMPTY, 1, (u8*)""}};
	FSUSER_OpenArchive(NULL, &sdmcArchive);
	FSUSER_OpenDirectory(NULL, &romHandle, sdmcArchive, dirPath);

	// Get number of files in directory
	fileSystem.totalFiles = 0
	while(1) {
		u32 dataRead = 0;
		FSDIR_Read(romHandle, &dataRead, 1, &dirStruct);
		if(dataRead == 0) break;
		fileSystem.totalFiles++;
	}

	fileSystem.fileList = linearAlloc(MAX_FILENAME_SIZE * fileSystem.totalFiles);

	FSUSER_OpenDirectory(NULL, &romHandle, sdmcArchive, dirPath);

	fileSystem.totalFiles = 0;
	while(1) {
		u32 dataRead = 0;
		FSDIR_Read(romHandle, &dataRead, 1, &dirStruct);
		if(dataRead == 0) break;
		unicodeToChar(&fileSystem.fileList[MAX_FILENAME_SIZE * fileSystem.totalFiles), dirStruct.name);
		fileSystem.totalFiles++;
	}

	FSDIR_Close(romHandle);
}
示例#5
0
bool arnMigrate() {
	const static FS_Path aurei = fsMakePath(PATH_ASCII, "/aurei");
	const static FS_Path luma = fsMakePath(PATH_ASCII, "/luma");
	FS_Archive sdmcArchive = { 0x00000009,{ PATH_EMPTY, 1, (u8*) "" } };

	if (FSUSER_OpenArchive(&sdmcArchive) != 0) {
		std::printf("\nCould not access SD Card (?)\n\n");
		return false;
	}

	// Check if /luma already existsHandle directory = { 0 };
	if (FSUSER_OpenDirectory(NULL, sdmcArchive, luma) == 0) {
		std::printf("Luma directory already exists, skipping migration..\n");
		return true;
	}

	if (!renameRecursive(sdmcArchive, "/aurei", "/luma")) {
		FSUSER_CloseArchive(&sdmcArchive);
		return false;
	}

	// Delete the source directory and check if it succeeds
	Result res = FSUSER_DeleteDirectoryRecursively(sdmcArchive, aurei);
	if (res != 0) {
		std::printf("\nWARN: Could not delete original /aurei (%ld)!\n\n",  res);
	}
	
	FSUSER_CloseArchive(&sdmcArchive);
	return true;
}
示例#6
0
Result backupByConfig(u8 *filebuffer, size_t bufsize) {
	memset(filebuffer, 0, bufsize);
	
	FILE *configfile = fopen("config.txt", "r");
	if (configfile==NULL) return errno;

	char source_path[1000], sd_destination[1000];
	u32 source_archive;
	mediatypes_enum mtype;
	FS_archiveIds atype;
	int buf2size = 0x10000;
	u8 *buf2 = malloc(buf2size);
	if (buf2==NULL)
	{
		printf("malloc failed\n");
		gfxFlushBuffers();
		gfxSwapBuffers();
		return -1;
	}
	memset(buf2, 0, buf2size);
	
	while (fgets((char*) buf2, buf2size, configfile) != NULL) {
		if (sscanf((const char*) buf2, "DUMP \"%x:%999[^\"]\" \"%999[^\"]\"", (unsigned int*) &source_archive, source_path, sd_destination) == 3) {
			if (source_archive >= 0x80000000) {
				mtype = mediatype_NAND;
				atype = ARCH_SHARED_EXTDATA;
			}
			else {
				mtype = mediatype_SDMC;
				atype = ARCH_EXTDATA;
			}
			u32 extdata_archive_lowpathdata[3] = {mtype, source_archive, 0};
			extdata_archive = (FS_archive){atype, (FS_path){PATH_BINARY, 0xC, (u8*)extdata_archive_lowpathdata}};
			Result ret = FSUSER_OpenArchive(NULL, &extdata_archive);
			if(ret!=0)
			{
				printf("could not open archive\n");
				gfxFlushBuffers();
				gfxSwapBuffers();
				continue;
			}
			printf("Dumping from %s\n", source_path);
			gfxFlushBuffers();
			gfxSwapBuffers();
			ret = archive_copyfile(Extdata_Archive, SDArchive, source_path, sd_destination, filebuffer, 0, bufsize, source_path);
			if (ret) {
				printf("Copying failed!\n");
			} else {
				printf("Success.\n");
			}
			gfxFlushBuffers();
			gfxSwapBuffers();
			FSUSER_CloseArchive(NULL, &extdata_archive);
		}
	}
	free(buf2);
	fclose(configfile);
	
	return 0;
}
示例#7
0
/*! Initialize SDMC device */
Result sdmcInit(void)
{
  Result rc;


  rc = FSUSER_OpenArchive(NULL, &sdmcArchive);


  if(rc == 0)
  {

    int dev = AddDevice(&sdmc_devoptab);

    if (__system_argc != 0 && __system_argv[0] != NULL)
    {
      if (FindDevice(__system_argv[0]) == dev)
      {
        strncpy(__fixedpath,__system_argv[0],PATH_MAX);
        char *last_slash = strrchr(__fixedpath,'/');
        if (last_slash != NULL) {
          last_slash[0] = 0;
          chdir(__fixedpath);
        }
      }
    }
  }

  return rc;
}
示例#8
0
Result filesystemInit()
{
  Result ret;
 
  fsInit(); 
  if (R_FAILED(ret = srvGetServiceHandleDirect(&fsHandle, "fs:USER"))) return ret;
  if (R_FAILED(ret = FSUSER_Initialize(fsHandle))) return ret;
  
  fsUseSession(fsHandle, false);

  sdmcArchive = (FS_Archive){ARCHIVE_SDMC, (FS_Path){PATH_EMPTY, 1, (u8*)""}, 0};
  if (R_FAILED(ret = FSUSER_OpenArchive(&sdmcArchive))) return ret;

  saveGameArchive = (FS_Archive){ARCHIVE_SAVEDATA, (FS_Path){PATH_EMPTY, 1, (u8*)""}, 0};
  if (R_FAILED(ret = FSUSER_OpenArchive(&saveGameArchive))) return ret;

  return ret;
}
示例#9
0
Result restoreFromSd(u8 *buf, size_t bufsize) {
    memset(buf, 0, bufsize);

    FILE *configfile = fopen("config.txt", "r");
    if (configfile==NULL) return errno;

    char sd_source[1000], destination_path[1000];
    u32 destination_archive;
    mediatypes_enum mtype;
    FS_archiveIds atype;
    u8 *filebuffer2 = malloc(bufsize);
    memset(filebuffer2, 0, bufsize);

    while (fgets((char*) buf, bufsize, configfile) != NULL) {
        if (sscanf((const char*) buf, "RESTORE \"%999[^\"]\" \"%x:%999[^\"]\"", sd_source, (unsigned int*) &destination_archive, destination_path) == 3) {
            if (destination_archive >= 0x80000000) {
                mtype = mediatype_NAND;
                atype = ARCH_SHARED_EXTDATA;
            }
            else {
                mtype = mediatype_SDMC;
                atype = ARCH_EXTDATA;
            }
            u32 extdata_archive_lowpathdata[3] = {mtype, destination_archive, 0};
            extdata_archive = (FS_archive) {
                atype, (FS_path) {
                    PATH_BINARY, 0xC, (u8*)extdata_archive_lowpathdata
                }
            };
            Result ret = FSUSER_OpenArchive(NULL, &extdata_archive);
            if(ret!=0)
            {
                printf("could not open archive\n");
                gfxFlushBuffers();
                gfxSwapBuffers();
                continue;
            }
            printf("Restoring to %s\n", destination_path);
            gfxFlushBuffers();
            gfxSwapBuffers();
            ret = archive_copyfile(SDArchive, Extdata_Archive, sd_source, destination_path, filebuffer2, 0, bufsize, destination_path);
            if (ret) {
                printf("Copying failed!\n");
            } else {
                printf("Success.\n");
            }
            gfxFlushBuffers();
            gfxSwapBuffers();
            FSUSER_CloseArchive(NULL, &extdata_archive);
        }
    }
    free(filebuffer2);
    fclose(configfile);

    return 0;
}
示例#10
0
// Opens the SD card so files can be opened from it.
int sdmcArchiveInit() {
  Result response;
  
  sdmcArchive = (FS_Archive) {ARCHIVE_SDMC, (FS_Path) {PATH_EMPTY, 1, (u8 *) ""}};
  if(R_FAILED(response = FSUSER_OpenArchive(&sdmcArchive))) {
    return(-1);
  }
  
  return(0);
}
示例#11
0
Result initFS() {
	u32 extdata_archive_lowpathdata[3] = { MEDIATYPE_NAND, 0xf000000e, 0 };
	extdata_archive = (FS_Archive ) { ARCHIVE_SHARED_EXTDATA,
					(FS_Path ) { PATH_BINARY, 0xC,
									(u8*) extdata_archive_lowpathdata } };

	verListPath = fsMakePath(PATH_ASCII, "/versionList.dat");

	return FSUSER_OpenArchive(&extdata_archive);
}
示例#12
0
文件: files.c 项目: masterhou/FBI
void files_open(FS_ArchiveID archiveId, FS_Path archivePath) {
    files_data* data = (files_data*) calloc(1, sizeof(files_data));
    if(data == NULL) {
        error_display(NULL, NULL, NULL, "Failed to allocate files data.");

        return;
    }

    data->populateData.recursive = false;
    data->populateData.includeBase = false;
    data->populateData.dirsFirst = true;

    data->populateData.filter = files_filter;
    data->populateData.filterData = data;

    data->populateData.finished = true;

    data->populated = false;

    data->showDirectories = true;
    data->showCias = true;
    data->showTickets = true;
    data->showMisc = true;

    data->archiveId = archiveId;
    data->archivePath.type = archivePath.type;
    data->archivePath.size = archivePath.size;
    if(archivePath.data != NULL) {
        data->archivePath.data = calloc(1, data->archivePath.size);
        if(data->archivePath.data == NULL) {
            error_display(NULL, NULL, NULL, "Failed to allocate files data.");

            files_free_data(data);
            return;
        }

        memcpy((void*) data->archivePath.data, archivePath.data, data->archivePath.size);
    } else {
        data->archivePath.data = NULL;
    }

    snprintf(data->currDir, FILE_PATH_MAX, "/");
    data->dirItem = NULL;

    Result res = 0;
    if(R_FAILED(res = FSUSER_OpenArchive(&data->archive, archiveId, archivePath))) {
        error_display_res(NULL, NULL, NULL, res, "Failed to open file listing archive.");

        files_free_data(data);
        return;
    }

    list_display("Files", "A: Select, B: Back, X: Refresh, Y: Dir, Select: Filter", data, files_update, files_draw_top);
}
示例#13
0
bool openCartArch(FS_Archive *out)
{
    *out = (FS_Archive){ARCHIVE_GAMECARD_SAVEDATA, (FS_Path){PATH_EMPTY, 0, ""}};
    Result res = FSUSER_OpenArchive(out);
    if(res)
    {
        return false;
    }

    return true;
}
示例#14
0
Result filesystemInit()
{
  Result ret;
  
  ret = _srvGetServiceHandle(&saveGameFsHandle, "fs:USER");
  if(ret)return ret;
  
  ret = FSUSER_Initialize(&saveGameFsHandle);
  if(ret)return ret;

  ret = srvGetServiceHandle(&sdmcFsHandle, "fs:USER");
  if(ret)return ret;

  saveGameArchive = (FS_archive){0x00000004, (FS_path){PATH_EMPTY, 1, (u8*)""}};
  ret = FSUSER_OpenArchive(&saveGameFsHandle, &saveGameArchive);

  sdmcArchive = (FS_archive){0x00000009, (FS_path){PATH_EMPTY, 1, (u8*)""}};
  ret = FSUSER_OpenArchive(&sdmcFsHandle, &sdmcArchive);

  return ret;
}
示例#15
0
Result write_savedata(const char* path, const void* data, size_t size)
{
    if(!path || !data || size == 0) return -1;

    Result ret = -1;
    int fail = 0;

    fsUseSession(save_session);
    ret = FSUSER_OpenArchive(&save_archive, ARCHIVE_SAVEDATA, (FS_Path){PATH_EMPTY, 1, (u8*)""});
    if(R_FAILED(ret))
    {
        fail = -1;
        goto writeFail;
    }

    // delete file
    FSUSER_DeleteFile(save_archive, fsMakePath(PATH_ASCII, path));
    FSUSER_ControlArchive(save_archive, ARCHIVE_ACTION_COMMIT_SAVE_DATA, NULL, 0, NULL, 0);

    Handle file = 0;
    ret = FSUSER_OpenFile(&file, save_archive, fsMakePath(PATH_ASCII, path), FS_OPEN_CREATE | FS_OPEN_WRITE, 0);
    if(R_FAILED(ret))
    {
        fail = -2;
        goto writeFail;
    }

    u32 bytes_written = 0;
    ret = FSFILE_Write(file, &bytes_written, 0, data, size, FS_WRITE_FLUSH | FS_WRITE_UPDATE_TIME);
    if(R_FAILED(ret))
    {
        fail = -3;
        goto writeFail;
    }

    ret = FSFILE_Close(file);
    if(R_FAILED(ret))
    {
        fail = -4;
        goto writeFail;
    }

    ret = FSUSER_ControlArchive(save_archive, ARCHIVE_ACTION_COMMIT_SAVE_DATA, NULL, 0, NULL, 0);
    if(R_FAILED(ret)) fail = -5;

writeFail:
    FSUSER_CloseArchive(save_archive);
    fsEndUseSession();
    if(fail) sprintf(status, "Failed to write to file: %d\n     %08lX %08lX", fail, ret, bytes_written);
    else sprintf(status, "Successfully wrote to file!\n     %08lX               ", bytes_written);

    return ret;
}
示例#16
0
void dumpTicket(void) {
    Result res = 0;
    Handle nandDir;
    u32 entryCount;
    FS_dirent dirent;

    printf("Opening NAND...\n");
    res = FSUSER_OpenArchive(NULL, &nandArchive);
    if(res != 0) {
        printf("%sError opening NAND!\n%.8lX%s\n", TEXT_RED, res, TEXT_RESET);
        return;
    }

    printf("Opening /...\n");
    nandPath.data = (u8 *)nandPathString;
    nandPath.size = (wcslen(nandPathString) + 1) * 2;
    res = FSUSER_OpenDirectory(NULL, &nandDir, nandArchive, nandPath);
    if(res != 0) {
        printf("%sError opening /!\n%.8lX%s\n", TEXT_RED, res, TEXT_RESET);
        return;
    }

    printf("Reading...\n");
    for(;;) {
        res = FSDIR_Read(nandDir, &entryCount, 1, &dirent);
        if(res != 0) {
            printf("%sError reading dir!\n%.8lX%s\n", TEXT_RED, res, TEXT_RESET);
            return;
        }

        if(entryCount == 0) {
            break;
        }

        utf16_to_utf8(utf8, dirent.name, 0x106);
        printf("/%s\n", utf8);
    }

    printf("Closing /...\n");
    res = FSDIR_Close(nandDir);
    if(res != 0) {
        printf("%sError closing /!\n%.8lX%s\n", TEXT_RED, res, TEXT_RESET);
        return;
    }

    printf("Closing NAND...\n");
    res = FSUSER_CloseArchive(NULL, &nandArchive);
    if(res != 0) {
        printf("%sError closing NAND!\n%.8lX%s\n", TEXT_RED, res, TEXT_RESET);
        return;
    }
}
示例#17
0
u8 internet_access(u8 upDown, int slot, t_stinf *state, u8 *dest, u8 timeout)
{
	Result ret;
	ret=fsInit();
	sdmcArchive=(FS_archive){0x00000009, (FS_path){PATH_EMPTY, 1, (u8*)""}};
	FSUSER_OpenArchive(NULL, &sdmcArchive);
	ret=SOC_Initialize((u32*)memalign(0x1000, 0x100000), 0x100000);
	sprintf(currentPath, "/");
	currentIP=(u32)gethostid();
	listenfd=-1;
        u8 do1(u8 upDown, int slot, t_stinf *state, u8 *dest, u8 timeout);
        return do1(upDown, slot, state, dest, timeout);
}
示例#18
0
文件: clipboard.c 项目: 14923523/FBI
Result clipboard_set_contents(FS_ArchiveID archiveId, FS_Path* archivePath, const char* path, bool contentsOnly) {
    clipboard_clear();

    clipboard_has = true;
    clipboard_contents_only = contentsOnly;

    strncpy(clipboard_path, path, FILE_PATH_MAX);

    Result res = 0;
    if(R_FAILED(res = FSUSER_OpenArchive(&clipboard_archive, archiveId, *archivePath))) {
        clipboard_clear();
    }

    return res;
}
示例#19
0
bool openSysSave(FS_Archive *out, const titleData dat)
{
    u32 path[2];
    path[0] = MEDIATYPE_NAND;
    path[1] = (0x00020000 | dat.unique);

    *out = (FS_Archive){ARCHIVE_SYSTEM_SAVEDATA, (FS_Path){PATH_BINARY, 8, path}};
    Result res = FSUSER_OpenArchive(out);
    if(res)
    {
        showMessage("Error opening system save data! Title may not use it.");
        return false;
    }

    return true;
}
示例#20
0
bool openBossExt(FS_Archive *out, const titleData dat)
{
    u32 path[3];
    path[0] = MEDIATYPE_SD;
    path[1] = dat.extdata;
    path[2] = 0;

    *out = (FS_Archive){ARCHIVE_BOSS_EXTDATA, (FS_Path){PATH_BINARY, 12, path}};
    Result res = FSUSER_OpenArchive(out);
    if(res)
    {
        showMessage("Error opening Boss Extdata! Title may not use it.");
        return false;
    }

    return true;
}
示例#21
0
bool openSharedExt(FS_Archive *out, u32 id)
{
    u32 path[3];
    path[0] = MEDIATYPE_NAND;
    path[1] = id;
    path[2] = 0x00048000;

    *out = (FS_Archive){ARCHIVE_SHARED_EXTDATA, (FS_Path){PATH_BINARY, 12, path}};
    Result res = FSUSER_OpenArchive(out);
    if(res)
    {
        showMessage("Error opening Shared Extdata!");
        logWriteError("Error opening shared", res);
        return false;
    }

    return true;
}
示例#22
0
bool openExtdata(FS_Archive *out, const titleData dat, bool showError)
{
    u32 path[3];
    path[0] = MEDIATYPE_SD;//always sd for extdata
    path[1] = dat.extdata;
    path[2] = 0;

    *out = (FS_Archive){ARCHIVE_EXTDATA, (FS_Path){PATH_BINARY, 12, path}};
    Result res = FSUSER_OpenArchive(out);
    if(res)
    {
        if(showError)
            showMessage("Error opening ExtData! Title may not use it.");
        return false;
    }

    return true;
}
示例#23
0
void dumpArchive(mediatypes_enum mediatype, int i, FS_archiveIds archivetype, char *dirpath, u8 *filebuffer, size_t bufsize) {
	u32 extdata_archive_lowpathdata[3] = {mediatype, i, 0};
	extdata_archive = (FS_archive){archivetype, (FS_path){PATH_BINARY, 0xC, (u8*)extdata_archive_lowpathdata}};
	
	Result ret = FSUSER_OpenArchive(NULL, &extdata_archive);
	if(ret!=0)
	{
		return;
	}
	
	printf("Archive 0x%08x opened.\n", (unsigned int) i);
	gfxFlushBuffers();
	gfxSwapBuffers();
	mkdir(dirpath, 0777);
	dumpFolder("/", i, dirpath, filebuffer, bufsize);
	
	FSUSER_CloseArchive(NULL, &extdata_archive);
}
示例#24
0
void DumpSharedRomFS(u8* archive_binary_lowpath) {    
    std::string output_file = BuildSharedRomFSFilename(archive_binary_lowpath);
    
    // Read RomFS bin from SaveDataCheck...
    
    Handle romfs_handle;
    u64    romfs_size        = 0;
    u32    romfs_bytes_read  = 0;
    
    FS_archive savedatacheck_archive    = { 0x2345678a, { PATH_BINARY, 16, archive_binary_lowpath } };
    u8         file_binary_lowpath[20]  = {};
    FS_path    romfs_path               = { PATH_BINARY, 20, file_binary_lowpath };
    
    print(GFX_TOP, "Dumping SaveDataCheck RomFS (%s)... ", output_file.c_str());

    FSUSER_OpenFileDirectly(NULL, &romfs_handle, savedatacheck_archive, romfs_path, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
    FSFILE_GetSize(romfs_handle, &romfs_size);
    
    std::unique_ptr<u8> romfs_data_buffer(new u8[romfs_size]);
    FSFILE_Read(romfs_handle, &romfs_bytes_read, 0, romfs_data_buffer.get(), romfs_size);
    FSFILE_Close(romfs_handle);
    
    // Dump RomFS bin to SDMC...
    
    Handle     file_handle;
    u32        bytes_written = 0;
    FS_path    fs_path       = FS_makePath(PATH_CHAR, output_file.c_str());
    FS_archive sdmc_archive  = (FS_archive) { 0x00000009, { PATH_EMPTY, 1, (u8*) "" } };
    
    FSUSER_OpenArchive(NULL, &sdmc_archive);
    FSUSER_OpenFile(NULL, &file_handle, sdmc_archive, fs_path, FS_OPEN_CREATE | FS_OPEN_WRITE, FS_ATTRIBUTE_NONE);
    Result res = FSFILE_Write(file_handle, &bytes_written, 0x0, romfs_data_buffer.get(), romfs_size, FS_WRITE_FLUSH);
    FSFILE_Close(file_handle);
    FSUSER_CloseArchive(NULL, &sdmc_archive);
    
    // Check result...
    
    if (res == 0 && bytes_written == romfs_size)
        print(GFX_TOP, "Done!\n");
    else
        print(GFX_TOP, "Failed!\n");
}
示例#25
0
void get_config_path()
{
	if(strlen(config_base_path) == 0) {
        sdmcArchive = (FS_Archive){ARCHIVE_SDMC, (FS_Path){PATH_EMPTY, 1, (u8*)""}};
        FSUSER_OpenArchive(&sdmcArchive);
        
        sprintf(config_base_path, "/lynx");

        FS_Path dirPath = (FS_Path){PATH_ASCII, strlen(config_base_path)+1, (u8*)config_base_path};
        FSUSER_OpenDirectory(&dirHandle, sdmcArchive, dirPath);
        
        if(!dirHandle) sprintf(config_base_path, "/"); //!!
        FSDIR_Close(dirHandle);
		
		sprintf(config_roms_path, "%s/%s", config_base_path, "Roms");
		sprintf(config_bios_path, "%s/%s", config_base_path, "Bios");
		sprintf(config_skin_path, "%s/%s", config_base_path, "Skin");
		sprintf(config_save_path, "%s/%s", config_base_path, "Save");
	}

}
示例#26
0
文件: app.cpp 项目: 44670/BootNTR
App appGetCiaInfo(const std::string file, MediaType mediaType) {
    if(!serviceRequire("am")) {
        return {};
    }

    FS_archive archive = (FS_archive) {ARCH_SDMC, (FS_path) {PATH_EMPTY, 1, (u8*) ""}};
    Result archiveResult = FSUSER_OpenArchive(NULL, &archive);
    if(archiveResult != 0) {
        platformSetError(serviceParseError((u32) archiveResult));
        return {};
    }

    Handle handle = 0;
    Result openResult = FSUSER_OpenFile(NULL, &handle, archive, FS_makePath(PATH_CHAR, file.c_str()), FS_OPEN_READ, FS_ATTRIBUTE_NONE);
    if(openResult != 0) {
        platformSetError(serviceParseError((u32) openResult));
        return {};
    }

    TitleList titleInfo;
    Result infoResult = AM_GetCiaFileInfo(appMediatypeToByte(mediaType), &titleInfo, handle);
    if(infoResult != 0) {
        platformSetError(serviceParseError((u32) infoResult));
        return {};
    }

    FSFILE_Close(handle);
    FSUSER_CloseArchive(NULL, &archive);

    App app;
    app.titleId = titleInfo.titleID;
    app.uniqueId = ((u32*) &titleInfo.titleID)[0];
    strcpy(app.productCode, "<N/A>");
    app.mediaType = mediaType;
    app.platform = appPlatformFromId(((u16*) &titleInfo.titleID)[3]);
    app.category = appCategoryFromId(((u16*) &titleInfo.titleID)[2]);
    app.version = titleInfo.titleVersion;
    app.size = titleInfo.size;
    return app;
}
示例#27
0
std::vector<std::string> listPayloads() {
	std::vector<std::string> files = {};
	FS_Archive sdmcArchive;

	// Open SD card
	if (FSUSER_OpenArchive(&sdmcArchive, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, NULL)) != 0) {
		logPrintf("\nCould not access SD Card (?)\n\n");
		return files;
	}

	// Open source directory
	Handle directory = 0;
	if (FSUSER_OpenDirectory(&directory, sdmcArchive, fsMakePath(PATH_ASCII, "/luma/payloads")) != 0) {
		logPrintf("\nCould not open /luma/payloads\n\n");
		FSUSER_CloseArchive(sdmcArchive);
		return files;
	}

	u32 fileRead = 0;
	while (true) {
		FS_DirectoryEntry entry = {};
		FSDIR_Read(directory, &fileRead, 1, &entry);
		if (!fileRead) {
			break;
		}

		// Convert name to ASCII (just cut the other bytes) and compare with prefix
		char name8[262] = { 0 };
		for (size_t i = 0; i < 262; i++) {
			name8[i] = entry.name[i] % 0xff;
		}

		files.push_back(std::string(name8));
	}

	FSUSER_CloseArchive(sdmcArchive);
	return files;
}
示例#28
0
文件: z26.c 项目: nop90/z26-3ds
int main() 
{
	
	
//	isN3DS = 0;

//	aptOpenSession();
//	APT_SetAppCpuTimeLimit(NULL, 80); // enables syscore usage
//	aptCloseSession();

//	APT_CheckNew3DS(NULL, &isN3DS);
	
    sdmcArchive = (FS_archive){ARCH_SDMC, (FS_path){PATH_EMPTY, 1, (u8*)""}};
    FSUSER_OpenArchive(NULL, &sdmcArchive);

	z26_3ds_Init(); // !!
	
	chdir("sdmc://Atari2600") ;

	srand(time(0));
	def_LoadDefaults();
	LaunchedFromCommandline = 0;

	StartInGUI = 1;     
	GamePaused = 1;
	cli_ReadParms("z26.gui");

	c_emulator();		   /* call emulator */

	srv_sound_off();

	z26_3ds_quit();!

	fflush(parmfp);
	fclose(parmfp);
	
	return 0; //MessageCode;
}                                                         
示例#29
0
文件: files.c 项目: XeQMuK3K4/FBI
void files_open(FS_Archive archive) {
    files_data* data = (files_data*) calloc(1, sizeof(files_data));
    data->archive = archive;

    if(data->archive.lowPath.size > 0) {
        data->archivePath = calloc(1,  data->archive.lowPath.size);
        memcpy(data->archivePath,  data->archive.lowPath.data,  data->archive.lowPath.size);
        data->archive.lowPath.data = data->archivePath;
    }

    data->archive.handle = 0;

    Result res = 0;
    if(R_FAILED(res = FSUSER_OpenArchive(&data->archive))) {
        error_display_res(NULL, NULL, NULL, res, "Failed to open file listing archive.");

        if(data->archivePath != NULL) {
            free(data->archivePath);
        }

        free(data);
        return;
    }

    data->currDir.archive = &data->archive;
    snprintf(data->currDir.path, PATH_MAX, "/");
    util_get_path_file(data->currDir.name, data->currDir.path, NAME_MAX);
    data->currDir.isDirectory = true;
    data->currDir.containsCias = false;
    data->currDir.size = 0;
    data->currDir.isCia = false;

    memcpy(&data->parentDir, &data->currDir, sizeof(data->parentDir));

    list_display("Files", "A: Select, B: Back, X: Refresh, Y: Directory Action", data, files_update, files_draw_top);
}
示例#30
0
void openSDArchive() {
    sdmcArchive = (FS_archive) {0x00000009, (FS_path) {PATH_EMPTY, 1, (u8 *) ""}};
    FSUSER_OpenArchive(NULL, &sdmcArchive);
}