43 lines
1,012 B
C++
43 lines
1,012 B
C++
#include "Common.hpp"
|
|
|
|
#include <print>
|
|
|
|
namespace Toolchain
|
|
{
|
|
FileType DetectFileType(std::string_view file)
|
|
{
|
|
if (std::size_t pos = file.find_last_of("?"); pos != std::string_view::npos) {
|
|
file = file.substr(0, pos);
|
|
}
|
|
|
|
if (std::size_t pos = file.find_last_of("#"); pos != std::string_view::npos) {
|
|
file = file.substr(0, pos);
|
|
}
|
|
|
|
if (std::size_t pos = file.find_last_of("/"); pos != std::string_view::npos) {
|
|
file = file.substr(pos + 1);
|
|
}
|
|
|
|
if (file.ends_with(".zip")) {
|
|
return FileType::Zip;
|
|
}
|
|
|
|
if (file.contains(".tar")) {
|
|
return FileType::Tar;
|
|
}
|
|
|
|
return FileType::Unknown;
|
|
}
|
|
|
|
std::string_view ToString(FileType fileType)
|
|
{
|
|
switch (fileType) {
|
|
case FileType::Unknown:
|
|
return "Unknown";
|
|
case FileType::Zip:
|
|
return "zip";
|
|
case FileType::Tar:
|
|
return "tar";
|
|
}
|
|
}
|
|
}
|