예제 #1
0
파일: file.c 프로젝트: Bulkman/VitaShell
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;
}
예제 #2
0
bool createDir(const char * name)
{
	fileInfo info;

	if (getPathInfo(name, info))
		return info.isDir;

#ifdef WINDOWS
	return 0 == _mkdir(name);
#else
	return 0 == mkdir(name, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
#endif
}
예제 #3
0
bool fileExists(const std::string & name)
{
	fileInfo info;
	return getPathInfo(name.c_str(), info) && info.isFile;
}
예제 #4
0
bool fileExists(const char * name)
{
	fileInfo info;
	return getPathInfo(name, info) && info.isFile;
}
예제 #5
0
bool pathExists(const std::string & name)
{
	fileInfo info;
	return getPathInfo(name.c_str(), info);
}
예제 #6
0
int delete_thread(SceSize args_size, DeleteArguments *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

	FileListEntry *file_entry = fileListGetNthEntry(args->file_list, args->index);

	int count = 0;
	FileListEntry *head = NULL;
	FileListEntry *mark_entry_one = NULL;

	if (fileListFindEntry(args->mark_list, file_entry->name)) { // On marked entry
		count = args->mark_list->length;
		head = args->mark_list->head;
	} else {
		count = 1;
		mark_entry_one = malloc(sizeof(FileListEntry));
		strcpy(mark_entry_one->name, file_entry->name);
		head = mark_entry_one;
	}

	char path[MAX_PATH_LENGTH];
	FileListEntry *mark_entry = NULL;

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

	mark_entry = head;

	int i;
	for (i = 0; i < count; i++) {
		disableAutoSuspend();

		snprintf(path, MAX_PATH_LENGTH, "%s%s", args->file_list->path, mark_entry->name);
		removeEndSlash(path);

		getPathInfo(path, NULL, &folders, &files);

		mark_entry = mark_entry->next;
	}

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

	// Remove process
	uint32_t value = 0;

	mark_entry = head;

	for (i = 0; i < count; i++) {
		snprintf(path, MAX_PATH_LENGTH, "%s%s", args->file_list->path, mark_entry->name);
		removeEndSlash(path);

		int res = removePath(path, &value, folders + files, SetProgress);
		if (res < 0) {
			closeWaitDialog();
			errorDialog(res);
			goto EXIT;
		}

		mark_entry = mark_entry->next;
	}

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

	// Close
	sceMsgDialogClose();

	dialog_step = DIALOG_STEP_DELETED;

EXIT:
	if (mark_entry_one)
		free(mark_entry_one);

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

	return sceKernelExitDeleteThread(0);
}
예제 #7
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);
}
예제 #8
0
static bool accessPath(MprRomFileSystem *fileSystem, cchar *path, int omode)
{
    MprPath     info;

    return getPathInfo(fileSystem, path, &info) == 0 ? 1 : 0;
}