Esempio n. 1
0
/* Returns number of files successfully read; negative number if error */
int pl_file_get_file_list(pl_file_list *list,
                          const char *path,
                          const char **filter)
{
  SceUID fd = sceIoDopen(path);
  if (fd < 0) return -1;

  SceIoDirent dir;
  memset(&dir, 0, sizeof(dir));

  pl_file *file, *last = NULL;
  list->files = NULL;

  const char **pext;
  int loop;
  int count = 0;

  while (sceIoDread(fd, &dir) > 0)
  {
    if (filter && !(SCE_S_ISDIR(dir.d_stat.st_mode)))
    {
      /* Loop through the list of allowed extensions and compare */
      for (pext = filter, loop = 1; *pext; pext++)
      {
        if (pl_file_is_of_type(dir.d_name, *pext))
        {
          loop = 0;
          break;
        }
      }

      if (loop) continue;
    }

    /* Create a new file entry */
    if (!(file = (pl_file*)malloc(sizeof(pl_file))))
    {
      pl_file_destroy_file_list(list);
      return -1;
    }

    file->name = strdup(dir.d_name);
    file->next = NULL;
    file->attrs = (SCE_S_ISDIR(dir.d_stat.st_mode))
                  ? PL_FILE_DIRECTORY : 0;

    /* Update preceding element */
    if (last) last->next = file;
    else list->files = file;

    last = file;
    count++;
  }

  sceIoDclose(fd);

  /* Sort the files by name */
  sort_file_list(list, count);
  return count;
}
Esempio n. 2
0
static enum VFSType _vdesceType(struct VDirEntry* vde) {
	struct VDirEntrySce* vdesce = (struct VDirEntrySce*) vde;
	if (SCE_S_ISDIR(vdesce->ent.d_stat.st_mode)) {
		return VFS_DIRECTORY;
	}
	return VFS_FILE;
}
Esempio n. 3
0
static int mkdir_recursive(const char *path)
{
  int exit_status = 1;
  SceIoStat stat;
  if (sceIoGetstat(path, &stat) == 0){
    /* If not a directory, cannot continue; otherwise success */
    exit_status = SCE_S_ISDIR(stat.st_mode);
    return exit_status;
  }

  /* First, try creating its parent directory */
  char *slash_pos = strrchr(path, '/');
  if (!slash_pos); /* Top level */
  else if (slash_pos != path && slash_pos[-1] == ':'); /* Top level */
  else
  {
    char *parent = strdup(path);
    parent[slash_pos - path] = '\0';
    exit_status = mkdir_recursive(parent);

    free(parent);
  }
  if (exit_status && slash_pos[1] != '\0')
  {
    int status = sceIoMkdir(path, 0777);
    if (status != 0)
      exit_status = 0;
  }

  return exit_status;
}
Esempio n. 4
0
/**
 *
 * retro_dirent_is_dir:
 * @rdir         : pointer to the directory entry.
 * @path         : path to the directory entry.
 *
 * Is the directory listing entry a directory?
 *
 * Returns: true if directory listing entry is
 * a directory, false if not.
 */
bool retro_dirent_is_dir(struct RDIR *rdir, const char *path)
{
#if defined(_WIN32)
   const WIN32_FIND_DATA *entry = (const WIN32_FIND_DATA*)&rdir->entry;
   return entry->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
#elif defined(PSP) || defined(VITA)
   const SceIoDirent *entry = (const SceIoDirent*)&rdir->entry;
#if defined(PSP)
   return (entry->d_stat.st_attr & FIO_SO_IFDIR) == FIO_SO_IFDIR;
#elif defined(VITA)
   return SCE_S_ISDIR(entry->d_stat.st_mode);
#endif
#elif defined(__CELLOS_LV2__)
   CellFsDirent *entry = (CellFsDirent*)&rdir->entry;
   return (entry->d_type == CELL_FS_TYPE_DIRECTORY);
#elif defined(DT_DIR)
   const struct dirent *entry = (const struct dirent*)rdir->entry;
   if (entry->d_type == DT_DIR)
      return true;
   /* This can happen on certain file systems. */
   if (entry->d_type == DT_UNKNOWN || entry->d_type == DT_LNK)
      return path_is_directory(path);
   return false;
#else
   /* dirent struct doesn't have d_type, do it the slow way ... */
   return path_is_directory(path);
#endif
}
Esempio n. 5
0
int removePath(char *path, uint32_t *value, uint32_t max, void (* SetProgress)(uint32_t value, uint32_t max)) {
	SceUID dfd = sceIoDopen(path);
	if (dfd >= 0) {
		int res = 0;

		do {
			SceIoDirent dir;
			memset(&dir, 0, sizeof(SceIoDirent));

			res = sceIoDread(dfd, &dir);
			if (res > 0) {
				if (strcmp(dir.d_name, ".") == 0 || strcmp(dir.d_name, "..") == 0)
					continue;

				char *new_path = malloc(strlen(path) + strlen(dir.d_name) + 2);
				snprintf(new_path, MAX_PATH_LENGTH, "%s/%s", path, dir.d_name);

				if (SCE_S_ISDIR(dir.d_stat.st_mode)) {
					removePath(new_path, value, max, SetProgress);
				} else {
					sceIoRemove(new_path);

					if (value)
						(*value)++;

					if (SetProgress)
						SetProgress(value ? *value : 0, max);
				}

				free(new_path);
			}
		} while (res > 0);

		sceIoDclose(dfd);

		int ret = sceIoRmdir(path);
		if (ret < 0)
			return ret;

		if (value)
			(*value)++;

		if (SetProgress)
			SetProgress(value ? *value : 0, max);
	} else {
		int ret = sceIoRemove(path);
		if (ret < 0)
			return ret;

		if (value)
			(*value)++;

		if (SetProgress)
			SetProgress(value ? *value : 0, max);
	}

	return 0;
}
Esempio n. 6
0
void openSettingsMenu() {
  settings_menu.status = SETTINGS_MENU_OPENING;
  settings_menu.entry_sel = 0;
  settings_menu.option_sel = 0;

  // Get current theme
  if (theme_name)
    free(theme_name);

  readConfig("ux0:VitaShell/theme/theme.txt", theme_entries, sizeof(theme_entries) / sizeof(ConfigEntry));

  // Get theme index in main tab
  int theme_index = -1;

  int i;
  for (i = 0; i < (sizeof(main_settings) / sizeof(SettingsMenuOption)); i++) {
    if (main_settings[i].name == VITASHELL_SETTINGS_THEME) {
      theme_index = i;
      break;
    }
  }

  // Find all themes
  if (theme_index >= 0) {
    SceUID dfd = sceIoDopen("ux0:VitaShell/theme");
    if (dfd >= 0) {
      theme_count = 0;
      theme = 0;

      int res = 0;

      do {
        SceIoDirent dir;
        memset(&dir, 0, sizeof(SceIoDirent));

        res = sceIoDread(dfd, &dir);
        if (res > 0) {
          if (SCE_S_ISDIR(dir.d_stat.st_mode)) {
            if (theme_name && strcasecmp(dir.d_name, theme_name) == 0)
              theme = theme_count;
            
            strncpy(theme_options[theme_count], dir.d_name, MAX_THEME_LENGTH);
            theme_count++;
          }
        }
      } while (res > 0 && theme_count < MAX_THEMES);
      
      sceIoDclose(dfd);
      
      main_settings[theme_index].options = theme_options;
      main_settings[theme_index].n_options = theme_count;
      main_settings[theme_index].value = &theme;
    }
  }

  changed = 0;
}
Esempio n. 7
0
int getPathInfo(char *path, uint32_t *size, uint32_t *folders, uint32_t *files) {
	SceUID dfd = sceIoDopen(path);
	if (dfd >= 0) {
		int res = 0;

		do {
			SceIoDirent dir;
			memset(&dir, 0, sizeof(SceIoDirent));

			res = sceIoDread(dfd, &dir);
			if (res > 0) {
				if (strcmp(dir.d_name, ".") == 0 || strcmp(dir.d_name, "..") == 0)
					continue;

				char *new_path = malloc(strlen(path) + strlen(dir.d_name) + 2);
				snprintf(new_path, MAX_PATH_LENGTH, "%s/%s", path, dir.d_name);

				if (SCE_S_ISDIR(dir.d_stat.st_mode)) {
					getPathInfo(new_path, size, folders, files);
				} else {
					if (size)
						(*size) += dir.d_stat.st_size;

					if (files)
						(*files)++;
				}

				free(new_path);
			}
		} while (res > 0);

		sceIoDclose(dfd);

		if (folders)
			(*folders)++;
	} else {
		if (size) {
			SceIoStat stat;
			memset(&stat, 0, sizeof(SceIoStat));

			int res = sceIoGetstat(path, &stat);
			if (res < 0)
				return res;

			(*size) += stat.st_size;
		}

		if (files)
			(*files)++;
	}

	return 0;
}
Esempio n. 8
0
int fileListGetDirectoryEntries(FileList *list, char *path) {
	SceUID dfd = sceIoDopen(path);
	if (dfd < 0)
		return dfd;

	FileListEntry *entry = malloc(sizeof(FileListEntry));
	strcpy(entry->name, DIR_UP);
	entry->is_folder = 1;
	entry->type = FILE_TYPE_UNKNOWN;
	fileListAddEntry(list, entry, SORT_BY_NAME_AND_FOLDER);

	int res = 0;

	do {
		SceIoDirent dir;
		memset(&dir, 0, sizeof(SceIoDirent));

		res = sceIoDread(dfd, &dir);
		if (res > 0) {
			if (strcmp(dir.d_name, ".") == 0 || strcmp(dir.d_name, "..") == 0)
				continue;

			FileListEntry *entry = malloc(sizeof(FileListEntry));

			strcpy(entry->name, dir.d_name);

			entry->is_folder = SCE_S_ISDIR(dir.d_stat.st_mode);
			if (entry->is_folder) {
				addEndSlash(entry->name);
				entry->type = FILE_TYPE_UNKNOWN;
			} else {
/*
				char file[MAX_PATH_LENGTH];
				snprintf(file, MAX_PATH_LENGTH, "%s%s", path, entry->name);
				entry->type = getFileType(file);
*/
				entry->type = FILE_TYPE_UNKNOWN;
			}

			memcpy(&entry->time, (SceRtcTime *)&dir.d_stat.st_mtime, sizeof(SceRtcTime));

			entry->size = dir.d_stat.st_size;

			fileListAddEntry(list, entry, SORT_BY_NAME_AND_FOLDER);
		}
	} while (res > 0);

	sceIoDclose(dfd);

	return 0;
}
Esempio n. 9
0
static int file_list_build(const char *path, file_list *list, const char *supported_ext[])
{
	SceUID dir;
	SceIoDirent dirent;

	//dir = sceIoDopen(path);
	dir = psp2LinkIoDopen(path);
	
	if (dir < 0) {
		return 0;
	}

	memset(&dirent, 0, sizeof(dirent));
	memset(list, 0, sizeof(*list));

	while (psp2LinkIoDread(dir, &dirent) > 0) {

		file_list_entry *entry = (file_list_entry *)malloc(sizeof(*entry));

		strcpy(entry->name, dirent.d_name);
		entry->is_dir = SCE_S_ISDIR(dirent.d_stat.st_mode);
		if (!entry->is_dir) {
			entry->supported = file_supported(entry->name, supported_ext);
		}

		file_list_add_entry(list, entry);

		memset(&dirent, 0, sizeof(dirent));
	}

	psp2LinkIoDclose(dir);

	//file_list_entry *up = (file_list_entry *)malloc(sizeof(*up));
	//strcpy(up->name, "..");
	//up->is_dir = 1;
	//up->next = NULL;
	//file_list_add_entry(list, up);

	return 0;
}
Esempio n. 10
0
File: ftp.c Progetto: cy33hc/FTPVita
static void send_LIST(ClientInfo *client, const char *path)
{
	char buffer[512];
	SceUID dir;
	SceIoDirent dirent;

	dir = sceIoDopen(path);
	if (dir < 0) {
		client_send_ctrl_msg(client, "550 Invalid directory.\n");
		return;
	}

	client_send_ctrl_msg(client, "150 Opening ASCII mode data transfer for LIST.\n");

	client_open_data_connection(client);

	memset(&dirent, 0, sizeof(dirent));

	while (sceIoDread(dir, &dirent) > 0) {
		gen_list_format(buffer, sizeof(buffer),
			SCE_S_ISDIR(dirent.d_stat.st_mode),
			dirent.d_stat.st_size,
			dirent.d_stat.st_ctime.month,
			dirent.d_stat.st_ctime.day,
			dirent.d_stat.st_ctime.hour,
			dirent.d_stat.st_ctime.minute,
			dirent.d_name);

		client_send_data_msg(client, buffer);
		memset(&dirent, 0, sizeof(dirent));
		memset(buffer, 0, sizeof(buffer));
	}

	sceIoDclose(dir);

	DEBUG("Done sending LIST\n");

	client_close_data_connection(client);
	client_send_ctrl_msg(client, "226 Transfer complete.\n");
}
Esempio n. 11
0
int copyPath(char *src_path, char *dst_path, uint32_t *value, uint32_t max, void (* SetProgress)(uint32_t value, uint32_t max)) {
	// The source and destination paths are identical
	if (strcmp(src_path, dst_path) == 0) {
		return -1;
	}

	// The destination is a subfolder of the source folder
	int len = strlen(src_path);
	if (strncmp(src_path, dst_path, len) == 0 && dst_path[len] == '/') {
		return -1;
	}

	SceUID dfd = sceIoDopen(src_path);
	if (dfd >= 0) {
		int ret = sceIoMkdir(dst_path, 0777);
		if (ret < 0 && ret != SCE_ERROR_ERRNO_EEXIST) {
			sceIoDclose(dfd);
			return ret;
		}

		if (value)
			(*value)++;

		if (SetProgress)
			SetProgress(value ? *value : 0, max);

		int res = 0;

		do {
			SceIoDirent dir;
			memset(&dir, 0, sizeof(SceIoDirent));

			res = sceIoDread(dfd, &dir);
			if (res > 0) {
				if (strcmp(dir.d_name, ".") == 0 || strcmp(dir.d_name, "..") == 0)
					continue;

				char *new_src_path = malloc(strlen(src_path) + strlen(dir.d_name) + 2);
				snprintf(new_src_path, MAX_PATH_LENGTH, "%s/%s", src_path, dir.d_name);

				char *new_dst_path = malloc(strlen(dst_path) + strlen(dir.d_name) + 2);
				snprintf(new_dst_path, MAX_PATH_LENGTH, "%s/%s", dst_path, dir.d_name);

				if (SCE_S_ISDIR(dir.d_stat.st_mode)) {
					copyPath(new_src_path, new_dst_path, value, max, SetProgress);
				} else {
					copyFile(new_src_path, new_dst_path, value, max, SetProgress);
				}

				free(new_dst_path);
				free(new_src_path);
			}
		} while (res > 0);

		sceIoDclose(dfd);
	} else {
		copyFile(src_path, dst_path, value, max, SetProgress);
	}

	return 0;
}
Esempio n. 12
0
void MOD_SelectModMenu(char *basedir){

	SceCtrlData pad, oldpad;
	sceCtrlPeekBufferPositive(0, &pad, 1);

	// Ch0wW: Enable the mod menu once the R trigger is hold on startup.
	if (!(pad.buttons & SCE_CTRL_RTRIGGER))
	{
		// Reading current used mod
		char cur_mod[64];
		modname = malloc(64);
		FILE* f;
		if ((f = fopen( va("%s/%s", basedir, MOD_FILE), "r")) != NULL) {
			char tmp[256];
			fseek(f, 0, SEEK_END);
			int len = ftell(f);
			fseek(f, 0, SEEK_SET);
			fread(tmp, 1, len, f);
			fclose(f);
			tmp[len] = 0;
			sprintf(modname, "%s", tmp);
		}
		else
			modname = NULL;
		return;
	}

	// Initializing empty ModList
	ModsList* mods = NULL;
	int i = 0;
	int max_idx = -1;
	
	// Scanning main folder in search of mods
	int dd = sceIoDopen(basedir);
	SceIoDirent entry;
	int res;
	while (sceIoDread(dd, &entry) > 0){
		if (SCE_S_ISDIR(entry.d_stat.st_mode)){
			if (CheckForMod( va("%s/%s", basedir, entry.d_name))){
				mods = addMod(entry.d_name, mods);
				max_idx++;
			}
		}
	}
	sceIoDclose(dd);
	
	// Reading current used mod
	char cur_mod[64];
	modname = malloc(64);
	FILE* f;
	if ((f = fopen(va("%s/%s", basedir, MOD_FILE), "r")) != NULL) {
		char tmp[256];
		fseek(f, 0, SEEK_END);
		int len = ftell(f);
		fseek(f, 0, SEEK_SET);
		fread(tmp, 1, len, f);
		fclose(f);
		tmp[len] = 0;
		sprintf(modname, "%s", tmp);
		sprintf(cur_mod, "Current in use mod: %s - Press START to launch vitaQuake core", tmp);
	}else strcpy(cur_mod,"Current in use mod: id1 - Press START to launch vitaQuake core");
	
	// Initializing graphics stuffs
	vita2d_set_clear_color(RGBA8(0x00, 0x00, 0x00, 0xFF));
	vita2d_pgf* debug_font = vita2d_load_default_pgf();
	uint32_t white = RGBA8(0xFF, 0xFF, 0xFF, 0xFF);
	uint32_t green = RGBA8(0x00, 0xFF, 0x00, 0xFF);
	uint32_t red = RGBA8(0xFF, 0x00, 0x00, 0xFF);
	
	// Main loop
	while (max_idx >= 0){
		vita2d_start_drawing();
		vita2d_clear_screen();
		vita2d_pgf_draw_text(debug_font, 2, 20, red, 1.0, cur_mod);
		
		// Drawing menu
		int y = 40;
		int d = 0;
		ModsList* ptr = mods;
		while (ptr != NULL && y < 540){
			uint32_t color = white;
			if (d++ == i) color = green;
			vita2d_pgf_draw_text(debug_font, 2, y, color, 1.0, ptr->name);
			ptr = ptr->next;
			y += 20;
		}
		
		// Controls checking
		sceCtrlPeekBufferPositive(0, &pad, 1);
		if ((pad.buttons & SCE_CTRL_CROSS) && (!(oldpad.buttons & SCE_CTRL_CROSS))){
			int z = 0;
			ModsList* tmp = mods;
			while (z < i){
				tmp = tmp->next;
				z++;
			}
			sprintf(cur_mod,"Current in use mod: %s - Press START to launch vitaQuake core", tmp->name);
			if (!strcmp(tmp->name, "id1"))
			{
				sceIoRemove( va("%s/%s", basedir, MOD_FILE) );
				modname = NULL;
			}
			else{
				f = fopen(va("%s/%s", basedir, MOD_FILE), "w");
				fwrite(tmp->name,1,strlen(tmp->name),f);
				fclose(f);
				strcpy(modname, tmp->name);	// Refresh the mod directory.
			}
		}else if ((pad.buttons & SCE_CTRL_UP) && (!(oldpad.buttons & SCE_CTRL_UP))){
			i--;
			if (i < 0) i = max_idx;
		}else if ((pad.buttons & SCE_CTRL_DOWN) && (!(oldpad.buttons & SCE_CTRL_DOWN))){
			i++;
			if (i > max_idx) i = 0;
		}else if (pad.buttons & SCE_CTRL_START) break;
		oldpad = pad;
		
		vita2d_end_drawing();
		vita2d_wait_rendering_done();
		vita2d_swap_buffers();
	}
	
	// Freeing stuffs
	ModsList* tmp = mods;
	ModsList* tmp2;
	while (tmp != NULL){
		tmp2 = tmp->next;
		free(tmp);
		tmp = tmp2;
	}

	return;
}