mirror of
https://github.com/jakcron/nstool.git
synced 2024-12-22 18:55:29 +00:00
Remove usage of PathUtil from FsProcess
This commit is contained in:
parent
acf0d3d785
commit
eb09024456
|
@ -93,46 +93,36 @@ void nstool::FsProcess::processArchiveJobs()
|
|||
{
|
||||
for (auto itr = mArchiveJobs.begin(); itr != mArchiveJobs.end(); itr++)
|
||||
{
|
||||
/*
|
||||
std::string archive_path_str, extract_base_path_str;
|
||||
tc::io::PathUtil::pathToUnixUTF8(itr->archive_path, archive_path_str);
|
||||
tc::io::PathUtil::pathToUnixUTF8(itr->extract_base_path, extract_base_path_str);
|
||||
*/
|
||||
|
||||
// Qualify Archive Path
|
||||
tc::io::Path qualified_archive_path;
|
||||
bool is_dir = false, is_file = false;
|
||||
if (!qualifyArchivePath(itr->archive_path, qualified_archive_path, is_dir, is_file))
|
||||
{
|
||||
std::string archive_path_str;
|
||||
tc::io::PathUtil::pathToUnixUTF8(itr->archive_path, archive_path_str);
|
||||
fmt::print("Path \"{}\" did not exist for this archive.\n", archive_path_str);
|
||||
|
||||
fmt::print("[FsJob] Path \"{}\" did not exist for this archive.\n", itr->archive_path.to_string());
|
||||
continue;
|
||||
}
|
||||
|
||||
// print
|
||||
{
|
||||
std::string qualified_archive_path_str;
|
||||
tc::io::PathUtil::pathToUnixUTF8(qualified_archive_path, qualified_archive_path_str);
|
||||
fmt::print("Path \"{}\" was valid, is_dir={}, is_file={}.\n", qualified_archive_path_str, is_dir, is_file);
|
||||
fmt::print("[FsJob] Path \"{}\" was valid, is_dir={}, is_file={}.\n", qualified_archive_path.to_string(), is_dir, is_file);
|
||||
}
|
||||
|
||||
|
||||
if (itr->job_action == ArchiveJob::JobAction::DoNothing)
|
||||
{
|
||||
fmt::print("DoNothing\n");
|
||||
fmt::print("[FsJob] DoNothing\n");
|
||||
continue;
|
||||
}
|
||||
else if (itr->job_action == ArchiveJob::JobAction::ListFileTree)
|
||||
{
|
||||
fmt::print("ListFileTree\n");
|
||||
fmt::print("[FsJob] ListFileTree\n");
|
||||
|
||||
|
||||
}
|
||||
else if (itr->job_action == ArchiveJob::JobAction::Extract)
|
||||
{
|
||||
fmt::print("Extract\n");
|
||||
fmt::print("[FsJob] Extract\n");
|
||||
mExtractJobs.push_back({itr->archive_path, itr->extract_base_path});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -205,15 +195,12 @@ void nstool::FsProcess::extractFs()
|
|||
|
||||
for (auto itr = mExtractJobs.begin(); itr != mExtractJobs.end(); itr++)
|
||||
{
|
||||
std::string path_str;
|
||||
tc::io::PathUtil::pathToUnixUTF8(itr->virtual_path, path_str);
|
||||
|
||||
// check if root path (legacy case)
|
||||
if (itr->virtual_path == tc::io::Path("/"))
|
||||
{
|
||||
visitDir(tc::io::Path("/"), itr->extract_path, true, false);
|
||||
|
||||
//fmt::print("Root Dir Virtual Path: \"{:s}\"\n", path_str);
|
||||
//fmt::print("Root Dir Virtual Path: \"{:s}\"\n", itr->virtual_path.to_string());
|
||||
|
||||
// root directory extract successful, continue to next job
|
||||
continue;
|
||||
|
@ -224,7 +211,7 @@ void nstool::FsProcess::extractFs()
|
|||
std::shared_ptr<tc::io::IStream> file_stream;
|
||||
mInputFs->openFile(itr->virtual_path, tc::io::FileMode::Open, tc::io::FileAccess::Read, file_stream);
|
||||
|
||||
//fmt::print("Valid File Path: \"{:s}\"\n", path_str);
|
||||
//fmt::print("Valid File Path: \"{:s}\"\n", itr->virtual_path.to_string());
|
||||
|
||||
// the output path for this file will depend on the user specified extract path
|
||||
std::shared_ptr<tc::io::IFileSystem> local_fs = std::make_shared<tc::io::LocalFileSystem>(tc::io::LocalFileSystem());
|
||||
|
@ -239,10 +226,7 @@ void nstool::FsProcess::extractFs()
|
|||
|
||||
tc::io::Path file_extract_path = itr->extract_path + itr->virtual_path.back();
|
||||
|
||||
std::string file_extract_path_str;
|
||||
tc::io::PathUtil::pathToUnixUTF8(file_extract_path, file_extract_path_str);
|
||||
|
||||
fmt::print("Saving {:s}...\n", file_extract_path_str);
|
||||
fmt::print("Saving {:s}...\n", file_extract_path.to_string());
|
||||
|
||||
writeStreamToFile(file_stream, itr->extract_path + itr->virtual_path.back(), mDataCache);
|
||||
|
||||
|
@ -257,24 +241,18 @@ void nstool::FsProcess::extractFs()
|
|||
// method: since this checks n-1 elements, it implies a path with more than one element, so that must be accounted for, as relative paths are valid and single element paths aren't always root
|
||||
|
||||
try {
|
||||
std::string test_path_str;
|
||||
|
||||
// get path to parent directory
|
||||
tc::io::Path parent_dir_path = itr->extract_path;
|
||||
|
||||
// replace final path element with the current directory alias
|
||||
parent_dir_path.pop_back(); // remove filename
|
||||
parent_dir_path.push_back("."); // replace with the current dir name alias
|
||||
tc::io::PathUtil::pathToUnixUTF8(parent_dir_path, test_path_str);
|
||||
|
||||
// test parent directory exists
|
||||
tc::io::sDirectoryListing dir_listing;
|
||||
local_fs->getDirectoryListing(parent_dir_path, dir_listing);
|
||||
|
||||
std::string file_extract_path_str;
|
||||
tc::io::PathUtil::pathToUnixUTF8(itr->extract_path, file_extract_path_str);
|
||||
|
||||
fmt::print("Saving {:s} as {:s}...\n", path_str, file_extract_path_str);
|
||||
fmt::print("Saving {:s} as {:s}...\n", itr->virtual_path.to_string(), itr->extract_path.to_string());
|
||||
|
||||
writeStreamToFile(file_stream, itr->extract_path, mDataCache);
|
||||
|
||||
|
@ -285,9 +263,7 @@ void nstool::FsProcess::extractFs()
|
|||
|
||||
|
||||
// extract path could not be determined, inform the user and skip this job
|
||||
std::string literal_extract_path_str;
|
||||
tc::io::PathUtil::pathToUnixUTF8(itr->extract_path, literal_extract_path_str);
|
||||
fmt::print("[WARNING] Extract path was invalid, and was skipped: {:s}\n", literal_extract_path_str);
|
||||
fmt::print("[WARNING] Extract path was invalid, and was skipped: {:s}\n", itr->extract_path.to_string());
|
||||
continue;
|
||||
} catch (tc::io::FileNotFoundException&) {
|
||||
// acceptable exception, just means file didn't exist
|
||||
|
@ -298,10 +274,9 @@ void nstool::FsProcess::extractFs()
|
|||
tc::io::sDirectoryListing dir_listing;
|
||||
mInputFs->getDirectoryListing(itr->virtual_path, dir_listing);
|
||||
|
||||
|
||||
visitDir(itr->virtual_path, itr->extract_path, true, false);
|
||||
|
||||
//fmt::print("Valid Directory Path: \"{:s}\"\n", path_str);
|
||||
//fmt::print("Valid Directory Path: \"{:s}\"\n", itr->virtual_path.to_string());
|
||||
|
||||
// directory extract successful, continue to next job
|
||||
continue;
|
||||
|
@ -310,7 +285,7 @@ void nstool::FsProcess::extractFs()
|
|||
// acceptable exception, just means directory didn't exist
|
||||
}
|
||||
|
||||
fmt::print("[WARNING] Failed to extract virtual path: \"{:s}\"\n", path_str);
|
||||
fmt::print("[WARNING] Failed to extract virtual path: \"{:s}\"\n", itr->virtual_path.to_string());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -339,7 +314,6 @@ void nstool::FsProcess::visitDir(const tc::io::Path& v_path, const tc::io::Path&
|
|||
// iterate thru child files
|
||||
size_t cache_read_len;
|
||||
tc::io::Path out_path;
|
||||
std::string out_path_str;
|
||||
std::shared_ptr<tc::io::IStream> in_stream;
|
||||
std::shared_ptr<tc::io::IStream> out_stream;
|
||||
for (auto itr = info.file_list.begin(); itr != info.file_list.end(); itr++)
|
||||
|
@ -354,9 +328,8 @@ void nstool::FsProcess::visitDir(const tc::io::Path& v_path, const tc::io::Path&
|
|||
{
|
||||
// build out path
|
||||
out_path = l_path + *itr;
|
||||
tc::io::PathUtil::pathToUnixUTF8(out_path, out_path_str);
|
||||
|
||||
fmt::print("Saving {:s}...\n", out_path_str);
|
||||
fmt::print("Saving {:s}...\n", out_path.to_string());
|
||||
|
||||
// begin export
|
||||
mInputFs->openFile(v_path + *itr, tc::io::FileMode::Open, tc::io::FileAccess::Read, in_stream);
|
||||
|
|
Loading…
Reference in a new issue