Beispiel #1
0
int getArchivePathInfo(char *path, uint64_t *size, uint32_t *folders, uint32_t *files) {
	if (!uf)
		return -1;

	SceIoStat stat;
	memset(&stat, 0, sizeof(SceIoStat));
	if (archiveFileGetstat(path, &stat) < 0) {
		FileList list;
		memset(&list, 0, sizeof(FileList));
		fileListGetArchiveEntries(&list, path, SORT_NONE);

		FileListEntry *entry = list.head->next; // Ignore ..

		int i;
		for (i = 0; i < list.length - 1; i++) {
			char *new_path = malloc(strlen(path) + strlen(entry->name) + 2);
			snprintf(new_path, MAX_PATH_LENGTH, "%s%s", path, entry->name);

			getArchivePathInfo(new_path, size, folders, files);

			free(new_path);

			entry = entry->next;
		}

		if (folders)
			(*folders)++;

		fileListEmpty(&list);
	} else {
		if (size)
			(*size) += stat.st_size;

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

	return 0;
}
Beispiel #2
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);
}