예제 #1
0
파일: file.c 프로젝트: Bulkman/VitaShell
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;
}
예제 #2
0
//! flatten a path and file name for example: "/you/me/../." becomes "/you"
FilePath FilePath::flattenFilename( const FilePath& root ) const
{
  std::string directory = addEndSlash().toString();
  directory = StringHelper::replace( directory, "\\", "/" );
  
  FilePath dir;
  FilePath subdir;

  int lastpos = 0;
  std::string::size_type pos = 0;
  bool lastWasRealDir=false;

  while( ( pos = directory.find( '/', lastpos) ) != std::string::npos )
  {
    subdir = FilePath( directory.substr(lastpos, pos - lastpos + 1) );

    if( subdir.toString() == "../" )
    {
      if (lastWasRealDir)
      {
        dir = dir.getUpDir();
        dir = dir.getUpDir();
        lastWasRealDir=( dir.toString().size()!=0);
      }
      else
      {
        dir = FilePath( dir.toString() + subdir.toString() );
        lastWasRealDir=false;
      }
    }
    else if( subdir.toString() == "/")
    {
      dir = root;
    }
    else if( subdir.toString() != "./" )
    {
      dir = FilePath( dir.toString() + subdir.toString() );
      lastWasRealDir=true;
    }

    lastpos = pos + 1;
  }

  return dir;
}
예제 #3
0
FilePath FileDir::find( const FilePath& fileName ) const
{
    _OC3_DEBUG_BREAK_IF( !isExist() );
    if( !fileName.toString().size() )
    {
        return "";
    }

    if( fileName.isExist() )
    {
        return fileName;
    }

    FilePath finalPath( addEndSlash().toString() + fileName.toString() );
    if( finalPath.isExist() )
    {
        return finalPath;
    }

    return fileName;
}
예제 #4
0
Path Directory::operator/(const Path& filename) const
{
  std::string dr = addEndSlash().toString();
  std::string fn = filename.removeBeginSlash().toString();
  return Path( dr + fn );
}
예제 #5
0
Directory Directory::operator/(const Directory& dir) const
{
  std::string dr = addEndSlash().toString();
  return Directory( dr + dir.toString() );
}
예제 #6
0
Path Directory::getFilePath( const Path& fileName )
{
  std::string ret = addEndSlash().toString();
  ret.append( fileName.removeBeginSlash().toString() );
  return Path( ret );
}
예제 #7
0
파일: archive.c 프로젝트: henkaku/VitaShell
int fileListGetArchiveEntries(FileList *list, char *path, int sort) {
	int res;

	if (!uf)
		return -1;

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

	char *archive_path = path + archive_path_start;
	int name_length = strlen(archive_path);

	FileListEntry *archive_entry = archive_list.head;

	int i;
	for (i = 0; i < archive_list.length; i++) {
		if (archive_entry->name_length >= name_length && strncasecmp(archive_entry->name, archive_path, name_length) == 0) { // Needs a / at end
			char *p = strchr(archive_entry->name + name_length, '/'); // it's a sub-directory if it has got a slash

			if (p)
				*p = '\0';

			char name[MAX_PATH_LENGTH];
			strcpy(name, archive_entry->name + name_length);
			if (p) {
				addEndSlash(name);
			}

			if (strlen(name) > 0 && !fileListFindEntry(list, name)) {
				FileListEntry *entry = malloc(sizeof(FileListEntry));

				strcpy(entry->name, archive_entry->name + name_length);

				if (p) {
					addEndSlash(entry->name);
					entry->is_folder = 1;
					entry->type = FILE_TYPE_UNKNOWN;
					list->folders++;
				} else {
					entry->is_folder = 0;
					entry->type = getFileType(entry->name);
					list->files++;
				}

				entry->name_length = strlen(entry->name);
				entry->size = archive_entry->size;
				entry->size2 = archive_entry->size2;

				memcpy(&entry->ctime, &archive_entry->ctime, sizeof(SceDateTime));
				memcpy(&entry->mtime, &archive_entry->mtime, sizeof(SceDateTime));
				memcpy(&entry->atime, &archive_entry->atime, sizeof(SceDateTime));

				fileListAddEntry(list, entry, sort);
			}

			if (p)
				*p = '/';
		}

		// Next
		archive_entry = archive_entry->next;
	}

	return 0;
}
예제 #8
0
int copy_thread(SceSize args_size, CopyArguments *args) {
	SceUID thid = -1;

	// Set progress to 0%
	sceMsgDialogProgressBarSetValue(SCE_MSG_DIALOG_PROGRESSBAR_TARGET_BAR_DEFAULT, 0);
	sceKernelDelayThread(DIALOG_WAIT); // Needed to see the percentage

	char src_path[MAX_PATH_LENGTH], dst_path[MAX_PATH_LENGTH];
	FileListEntry *copy_entry = NULL;

	if (args->copy_mode == COPY_MODE_MOVE) { // Move
		// Update thread
		thid = createStartUpdateThread(args->copy_list->length);

		copy_entry = args->copy_list->head;

		int i;
		for (i = 0; i < args->copy_list->length; i++) {
			snprintf(src_path, MAX_PATH_LENGTH, "%s%s", args->copy_list->path, copy_entry->name);
			snprintf(dst_path, MAX_PATH_LENGTH, "%s%s", args->file_list->path, copy_entry->name);

			int res = sceIoRename(src_path, dst_path);
			// TODO: if (res == SCE_ERROR_ERRNO_EEXIST) if folder
			if (res < 0) {
				closeWaitDialog();
				errorDialog(res);
				goto EXIT;
			}

			SetProgress(i + 1, args->copy_list->length);

			copy_entry = copy_entry->next;
		}

		// Set progress to 100%
		sceMsgDialogProgressBarSetValue(SCE_MSG_DIALOG_PROGRESSBAR_TARGET_BAR_DEFAULT, 100);
		sceKernelDelayThread(COUNTUP_WAIT);

		// Close
		sceMsgDialogClose();

		dialog_step = DIALOG_STEP_MOVED;
	} else { // Copy
		if (args->copy_mode == COPY_MODE_EXTRACT)
			archiveOpen(args->archive_path);

		// Get src paths info
		uint32_t size = 0, folders = 0, files = 0;

		copy_entry = args->copy_list->head;

		int i;
		for (i = 0; i < args->copy_list->length; i++) {
			disableAutoSuspend();

			snprintf(src_path, MAX_PATH_LENGTH, "%s%s", args->copy_list->path, copy_entry->name);

			if (args->copy_mode == COPY_MODE_EXTRACT) {
				addEndSlash(src_path);
				getArchivePathInfo(src_path, &size, &folders, &files);
			} else {
				removeEndSlash(src_path);
				getPathInfo(src_path, &size, &folders, &files);
			}

			copy_entry = copy_entry->next;
		}

		// Update thread
		thid = createStartUpdateThread(size + folders);

		// Copy process
		uint32_t value = 0;

		copy_entry = args->copy_list->head;

		for (i = 0; i < args->copy_list->length; i++) {
			snprintf(src_path, MAX_PATH_LENGTH, "%s%s", args->copy_list->path, copy_entry->name);
			snprintf(dst_path, MAX_PATH_LENGTH, "%s%s", args->file_list->path, copy_entry->name);

			if (args->copy_mode == COPY_MODE_EXTRACT) {
				addEndSlash(src_path);
				addEndSlash(dst_path);

				int res = extractArchivePath(src_path, dst_path, &value, size + folders, SetProgress);
				if (res < 0) {
					closeWaitDialog();
					errorDialog(res);
					goto EXIT;
				}
			} else {
				removeEndSlash(src_path);
				removeEndSlash(dst_path);

				int res = copyPath(src_path, dst_path, &value, size + folders, SetProgress);
				if (res < 0) {
					closeWaitDialog();
					errorDialog(res);
					goto EXIT;
				}
			}

			copy_entry = copy_entry->next;
		}

		// Set progress to 100%
		sceMsgDialogProgressBarSetValue(SCE_MSG_DIALOG_PROGRESSBAR_TARGET_BAR_DEFAULT, 100);
		sceKernelDelayThread(COUNTUP_WAIT);

		// Close
		sceMsgDialogClose();

		dialog_step = DIALOG_STEP_COPIED;
	}

EXIT:
	if (thid >= 0)
		sceKernelWaitThreadEnd(thid, NULL, NULL);

	return sceKernelExitDeleteThread(0);
}