mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2025-04-28 13:27:58 +03:00
Move first party tools to tools folder.
This commit is contained in:
parent
611454126e
commit
578d9d052b
16 changed files with 14 additions and 14 deletions
3
thirdparty/CMakeLists.txt
vendored
3
thirdparty/CMakeLists.txt
vendored
|
@ -3,8 +3,5 @@ set(MSDF_ATLAS_USE_SKIA OFF)
|
|||
set(MSDF_ATLAS_NO_ARTERY_FONT ON)
|
||||
set(MSDFGEN_DISABLE_PNG ON)
|
||||
|
||||
add_subdirectory(${SWA_THIRDPARTY_ROOT}/PowerRecomp)
|
||||
add_subdirectory(${SWA_THIRDPARTY_ROOT}/ShaderRecomp)
|
||||
add_subdirectory(${SWA_THIRDPARTY_ROOT}/o1heap)
|
||||
add_subdirectory(${SWA_THIRDPARTY_ROOT}/fshasher)
|
||||
add_subdirectory(${SWA_THIRDPARTY_ROOT}/msdf-atlas-gen)
|
||||
|
|
1
thirdparty/PowerRecomp
vendored
1
thirdparty/PowerRecomp
vendored
|
@ -1 +0,0 @@
|
|||
Subproject commit 847842cd28a2427b9db520d2aaa7416e5dec3822
|
1
thirdparty/ShaderRecomp
vendored
1
thirdparty/ShaderRecomp
vendored
|
@ -1 +0,0 @@
|
|||
Subproject commit 12b38144b9ff5d131e0d30af22bd38607d07d9fd
|
7
thirdparty/fshasher/CMakeLists.txt
vendored
7
thirdparty/fshasher/CMakeLists.txt
vendored
|
@ -1,7 +0,0 @@
|
|||
project("fshasher")
|
||||
|
||||
add_executable(fshasher "fshasher.cpp")
|
||||
|
||||
find_package(xxhash CONFIG REQUIRED)
|
||||
|
||||
target_link_libraries(fshasher PRIVATE xxHash::xxhash)
|
203
thirdparty/fshasher/fshasher.cpp
vendored
203
thirdparty/fshasher/fshasher.cpp
vendored
|
@ -1,203 +0,0 @@
|
|||
//
|
||||
// fshasher - CLI tool to generate a hash map from a file system.
|
||||
//
|
||||
// This is free and unencumbered software released into the public domain.
|
||||
//
|
||||
// Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
// distribute this software, either in source code form or as a compiled
|
||||
// binary, for any purpose, commercial or non-commercial, and by any
|
||||
// means.
|
||||
//
|
||||
// In jurisdictions that recognize copyright laws, the author or authors
|
||||
// of this software dedicate any and all copyright interest in the
|
||||
// software to the public domain. We make this dedication for the benefit
|
||||
// of the public at large and to the detriment of our heirs and
|
||||
// successors. We intend this dedication to be an overt act of
|
||||
// relinquishment in perpetuity of all present and future rights to this
|
||||
// software under copyright law.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#include <cstdio>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
#include <xxh3.h>
|
||||
|
||||
#include "plainargs.h"
|
||||
|
||||
void showHelp() {
|
||||
std::cout << "fshasher --directory <directory1 directory2 ...> --source <source file> --header <header file> --variable <variable name>" << std::endl;
|
||||
}
|
||||
|
||||
int process(const std::list<std::filesystem::path> &searchDirectories, std::ofstream &outputSourceStream, std::ofstream &outputHeaderStream, const std::string &variableName) {
|
||||
auto writeExterns = [&](std::ofstream &outputStream)
|
||||
{
|
||||
outputStream << "extern const uint64_t " << variableName << "Hashes[];" << std::endl;
|
||||
outputStream << "extern const std::pair<const char *, uint32_t> " << variableName << "Files[];" << std::endl;
|
||||
outputStream << "extern const size_t " << variableName << "FilesSize;" << std::endl << std::endl;
|
||||
};
|
||||
|
||||
// Generate header.
|
||||
outputHeaderStream << "// File automatically generated by fshasher" << std::endl << std::endl;
|
||||
outputHeaderStream << "#pragma once" << std::endl << std::endl;
|
||||
outputHeaderStream << "#include <utility>" << std::endl << std::endl;
|
||||
writeExterns(outputHeaderStream);
|
||||
|
||||
if (outputHeaderStream.bad())
|
||||
{
|
||||
std::cerr << "Failed to write to output header." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
outputSourceStream << "// File automatically generated by fshasher" << std::endl << std::endl;
|
||||
outputSourceStream << "#include <utility>" << std::endl << std::endl;
|
||||
writeExterns(outputSourceStream);
|
||||
|
||||
std::map<std::u8string, std::set<uint64_t>> fileHashSets;
|
||||
char fileData[65536];
|
||||
XXH3_state_t xxh3;
|
||||
for (const std::filesystem::path &searchDirectory : searchDirectories)
|
||||
{
|
||||
if (!std::filesystem::is_directory(searchDirectory))
|
||||
{
|
||||
std::cerr << "Specified directory " << searchDirectory << " does not exist." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (const std::filesystem::directory_entry &entry : std::filesystem::recursive_directory_iterator(searchDirectory))
|
||||
{
|
||||
if (!entry.is_regular_file())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
std::filesystem::path entryPath = entry.path();
|
||||
std::filesystem::path entryRelative = std::filesystem::relative(entryPath, searchDirectory);
|
||||
std::ifstream entryStream(entryPath, std::ios::binary);
|
||||
if (!entryStream.is_open())
|
||||
{
|
||||
std::cerr << "Could not open " << entryPath << " for reading." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "Reading " << entryRelative << "." << std::endl;
|
||||
XXH3_64bits_reset(&xxh3);
|
||||
while (!entryStream.eof() && !entryStream.bad())
|
||||
{
|
||||
entryStream.read(fileData, sizeof(fileData));
|
||||
XXH3_64bits_update(&xxh3, fileData, entryStream.gcount());
|
||||
}
|
||||
|
||||
if (entryStream.bad())
|
||||
{
|
||||
std::cerr << "Could not read " << entryPath << " successfully." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::u8string entryRelativeU8 = entryRelative.u8string();
|
||||
std::replace(entryRelativeU8.begin(), entryRelativeU8.end(), '\\', '/');
|
||||
fileHashSets[entryRelativeU8].insert(XXH3_64bits_digest(&xxh3));
|
||||
}
|
||||
}
|
||||
|
||||
outputSourceStream << "const uint64_t " << variableName << "Hashes[] = {" << std::endl;
|
||||
|
||||
for (auto &it : fileHashSets)
|
||||
{
|
||||
for (uint64_t hash : it.second)
|
||||
{
|
||||
outputSourceStream << " " << hash << "ULL," << std::endl;
|
||||
}
|
||||
|
||||
if (outputSourceStream.bad())
|
||||
{
|
||||
std::cerr << "Failed to write to output source." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
outputSourceStream << "};" << std::endl << std::endl;
|
||||
outputSourceStream << "const std::pair<const char *, uint32_t> " << variableName << "Files[] = {" << std::endl;
|
||||
|
||||
for (const auto &it : fileHashSets)
|
||||
{
|
||||
outputSourceStream << " { \"" << (const char *)(it.first.c_str()) << "\", " << it.second.size() << " }," << std::endl;
|
||||
if (outputSourceStream.bad())
|
||||
{
|
||||
std::cerr << "Failed to write to output source." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
outputSourceStream << "};" << std::endl << std::endl;
|
||||
outputSourceStream << "const size_t " << variableName << "FilesSize = std::size(" << variableName << "Files);" << std::endl;
|
||||
|
||||
if (outputSourceStream.bad())
|
||||
{
|
||||
std::cerr << "Failed to write to output source." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
plainargs::Result argsResult = plainargs::parse(argc, argv);
|
||||
std::vector<std::string> directories = argsResult.getValues("directory", "d");
|
||||
std::string variable = argsResult.getValue("variable", "v");
|
||||
std::string source = argsResult.getValue("source", "s");
|
||||
std::string header = argsResult.getValue("header", "h");
|
||||
if (directories.empty() || variable.empty() || source.empty() || header.empty())
|
||||
{
|
||||
showHelp();
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::filesystem::path sourcePath(source);
|
||||
std::ofstream sourceStream(sourcePath);
|
||||
if (!sourceStream.is_open())
|
||||
{
|
||||
std::cerr << "Could not open " << sourcePath << " for writing." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::filesystem::path headerPath(header);
|
||||
std::ofstream headerStream(headerPath);
|
||||
if (!headerStream.is_open())
|
||||
{
|
||||
std::cerr << "Could not open " << headerPath << " for writing." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::list<std::filesystem::path> searchDirectories;
|
||||
for (std::string &directory : directories)
|
||||
{
|
||||
searchDirectories.emplace_back(directory);
|
||||
}
|
||||
|
||||
int resultCode = process(searchDirectories, sourceStream, headerStream, variable);
|
||||
sourceStream.close();
|
||||
headerStream.close();
|
||||
|
||||
if (resultCode != 0)
|
||||
{
|
||||
std::cerr << "Failed to generate " << sourcePath << "and" << headerPath << "." << std::endl;
|
||||
std::filesystem::remove(sourcePath);
|
||||
std::filesystem::remove(headerPath);
|
||||
}
|
||||
|
||||
return resultCode;
|
||||
}
|
147
thirdparty/fshasher/plainargs.h
vendored
147
thirdparty/fshasher/plainargs.h
vendored
|
@ -1,147 +0,0 @@
|
|||
//
|
||||
// plainargs - A very plain CLI arguments parsing header-only library.
|
||||
//
|
||||
// This is free and unencumbered software released into the public domain.
|
||||
//
|
||||
// Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
// distribute this software, either in source code form or as a compiled
|
||||
// binary, for any purpose, commercial or non-commercial, and by any
|
||||
// means.
|
||||
//
|
||||
// In jurisdictions that recognize copyright laws, the author or authors
|
||||
// of this software dedicate any and all copyright interest in the
|
||||
// software to the public domain. We make this dedication for the benefit
|
||||
// of the public at large and to the detriment of our heirs and
|
||||
// successors. We intend this dedication to be an overt act of
|
||||
// relinquishment in perpetuity of all present and future rights to this
|
||||
// software under copyright law.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace plainargs {
|
||||
class Result {
|
||||
private:
|
||||
struct Option {
|
||||
uint32_t keyIndex;
|
||||
uint32_t valueCount;
|
||||
};
|
||||
|
||||
std::string directory;
|
||||
std::vector<std::string> arguments;
|
||||
std::vector<Option> options;
|
||||
std::unordered_map<std::string, uint32_t> shortKeyMap;
|
||||
std::unordered_map<std::string, uint32_t> longKeyMap;
|
||||
public:
|
||||
// Arguments are the same as main().
|
||||
Result(int argc, char *argv[]) {
|
||||
if (argc < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
directory = argv[0];
|
||||
|
||||
arguments.resize(size_t(argc - 1));
|
||||
for (uint32_t i = 1; i < uint32_t(argc); i++) {
|
||||
std::string &argument = arguments[i - 1];
|
||||
argument = std::string(argv[i]);
|
||||
|
||||
if (!argument.empty()) {
|
||||
bool shortKey = (argument.size() > 1) && (argument[0] == '-');
|
||||
bool longKey = (argument.size() > 2) && (argument[0] == '-') && (argument[1] == '-');
|
||||
if (longKey) {
|
||||
longKeyMap[argument.substr(2)] = uint32_t(options.size());
|
||||
options.emplace_back(Option{ i - 1, 0 });
|
||||
}
|
||||
else if (shortKey) {
|
||||
shortKeyMap[argument.substr(1)] = uint32_t(options.size());
|
||||
options.emplace_back(Option{ i - 1, 0 });
|
||||
}
|
||||
else if (!options.empty()) {
|
||||
options.back().valueCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return all the values associated to the long key or the short key in order.
|
||||
std::vector<std::string> getValues(const std::string &longKey, const std::string &shortKey = "", uint32_t maxValues = 0) const {
|
||||
std::vector<std::string> values;
|
||||
auto optionIt = options.end();
|
||||
if (!longKey.empty()) {
|
||||
auto it = longKeyMap.find(longKey);
|
||||
if (it != longKeyMap.end()) {
|
||||
optionIt = options.begin() + it->second;
|
||||
}
|
||||
}
|
||||
|
||||
if ((optionIt == options.end()) && !shortKey.empty()) {
|
||||
auto it = shortKeyMap.find(shortKey);
|
||||
if (it != shortKeyMap.end()) {
|
||||
optionIt = options.begin() + it->second;
|
||||
}
|
||||
}
|
||||
|
||||
if (optionIt != options.end()) {
|
||||
uint32_t valueCount = optionIt->valueCount;
|
||||
if ((maxValues > 0) && (valueCount > maxValues)) {
|
||||
valueCount = maxValues;
|
||||
}
|
||||
|
||||
values.resize(valueCount);
|
||||
for (uint32_t i = 0; i < valueCount; i++) {
|
||||
values[i] = arguments[optionIt->keyIndex + i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
std::string getValue(const std::string &longKey, const std::string &shortKey = "") const {
|
||||
std::vector<std::string> values = getValues(longKey, shortKey, 1);
|
||||
return !values.empty() ? values.front() : std::string();
|
||||
}
|
||||
|
||||
// Return whether an option with the long key or short key was specified.
|
||||
bool hasOption(const std::string &longKey, const std::string &shortKey = "") const {
|
||||
if (!longKey.empty() && (longKeyMap.find(longKey) != longKeyMap.end())) {
|
||||
return true;
|
||||
}
|
||||
else if (!shortKey.empty() && (shortKeyMap.find(shortKey) != shortKeyMap.end())) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Corresponds to argv[0].
|
||||
const std::string &getDirectory() const {
|
||||
return directory;
|
||||
}
|
||||
|
||||
// No bounds checking, must be a valid index.
|
||||
const std::string getArgument(uint32_t index) const {
|
||||
return arguments[index];
|
||||
}
|
||||
|
||||
// Will be one less than argc.
|
||||
uint32_t getArgumentCount() const {
|
||||
return arguments.size();
|
||||
}
|
||||
};
|
||||
|
||||
// Parse and return the arguments in a structure that can be queried easily. Does not perform any validation of the arguments.
|
||||
Result parse(int argc, char *argv[]) {
|
||||
return Result(argc, argv);
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue