forked from aya/aya
Initial commit
This commit is contained in:
14
tools/cef-subprocess/CMakeLists.txt
Normal file
14
tools/cef-subprocess/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
add_executable(CefSubprocess src/main.cpp)
|
||||
|
||||
if(AYA_OS_WINDOWS)
|
||||
target_sources(CefSubprocess PRIVATE
|
||||
resources/winrc.h
|
||||
resources/script.rc
|
||||
)
|
||||
|
||||
set_target_properties(CefSubprocess PROPERTIES WIN32_EXECUTABLE TRUE)
|
||||
endif()
|
||||
|
||||
target_include_directories(CefSubprocess PRIVATE src resources)
|
||||
set_target_properties(CefSubprocess PROPERTIES OUTPUT_NAME "${AYA_PROJECT_NAME}.CefSubprocess")
|
||||
target_link_libraries(CefSubprocess PRIVATE ${CEF_LIBRARIES})
|
||||
BIN
tools/cef-subprocess/resources/icon.ico
Normal file
BIN
tools/cef-subprocess/resources/icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 183 KiB |
49
tools/cef-subprocess/resources/script.rc
Normal file
49
tools/cef-subprocess/resources/script.rc
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "winrc.h"
|
||||
|
||||
#if defined(__MINGW64__) || defined(__MINGW32__)
|
||||
// MinGW-w64, MinGW
|
||||
#if defined(__has_include) && __has_include(<winres.h>)
|
||||
#include <winres.h>
|
||||
#else
|
||||
#include <afxres.h>
|
||||
#include <winresrc.h>
|
||||
#endif
|
||||
#else
|
||||
// MSVC, Windows SDK
|
||||
#include <winres.h>
|
||||
#endif
|
||||
|
||||
IDI_ICON1 ICON APP_ICON
|
||||
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION VERSION_RESOURCE
|
||||
PRODUCTVERSION VERSION_RESOURCE
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x4L
|
||||
FILETYPE 0x1L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", APP_ORGANIZATION
|
||||
VALUE "FileDescription", APP_DESCRIPTION
|
||||
VALUE "FileVersion", VERSION_RESOURCE_STR
|
||||
VALUE "LegalCopyright", APP_COPYRIGHT
|
||||
VALUE "ProductName", APP_NAME
|
||||
VALUE "ProductVersion", VERSION_RESOURCE_STR
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", PRODUCT_LANGUAGE, PRODUCT_CHARSET
|
||||
END
|
||||
END
|
||||
24
tools/cef-subprocess/resources/winrc.h
Normal file
24
tools/cef-subprocess/resources/winrc.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#define VERSION_MAJOR_MINOR_STR AYA_VERSION_MAJOR_STR "." AYA_VERSION_MINOR_STR
|
||||
#define VERSION_MAJOR_MINOR_PATCH_STR VERSION_MAJOR_MINOR_STR "." AYA_VERSION_PATCH_STR
|
||||
#ifdef AYA_VERSION_TYPE
|
||||
#define VERSION_FULL_STR VERSION_MAJOR_MINOR_PATCH_STR "-" AYA_VERSION_TYPE
|
||||
#else
|
||||
#define VERSION_FULL_STR VERSION_MAJOR_MINOR_PATCH_STR
|
||||
#endif
|
||||
#define VERSION_RESOURCE AYA_VERSION_MAJOR, AYA_VERSION_MINOR, AYA_VERSION_PATCH, 0
|
||||
#define VERSION_RESOURCE_STR VERSION_FULL_STR "\0"
|
||||
|
||||
/*
|
||||
* These properties are part of VarFileInfo.
|
||||
* For more information, please see: https://learn.microsoft.com/en-us/windows/win32/menurc/varfileinfo-block
|
||||
*/
|
||||
#define PRODUCT_LANGUAGE 0x0409 // en-US
|
||||
#define PRODUCT_CHARSET 1200 // Unicode
|
||||
|
||||
#define APP_ICON "icon.ico"
|
||||
#define APP_NAME AYA_PROJECT_NAME "\0"
|
||||
#define APP_DESCRIPTION AYA_PROJECT_NAME " CEF Subprocess\0"
|
||||
#define APP_ORGANIZATION AYA_PROJECT_NAME "\0"
|
||||
#define APP_COPYRIGHT AYA_PROJECT_NAME " License\0"
|
||||
75
tools/cef-subprocess/src/main.cpp
Normal file
75
tools/cef-subprocess/src/main.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include <include/base/cef_bind.h>
|
||||
#include <include/cef_app.h>
|
||||
#include <include/cef_base.h>
|
||||
#include <include/cef_browser.h>
|
||||
#include <include/cef_client.h>
|
||||
#include <include/cef_frame_handler.h>
|
||||
#include <include/cef_render_process_handler.h>
|
||||
#include <include/wrapper/cef_closure_task.h>
|
||||
|
||||
class AyaCefApp : public CefApp
|
||||
{
|
||||
public:
|
||||
AyaCefApp() {};
|
||||
|
||||
private:
|
||||
IMPLEMENT_REFCOUNTING(AyaCefApp);
|
||||
};
|
||||
|
||||
class AyaCefSubprocess
|
||||
: public AyaCefApp
|
||||
, public CefRenderProcessHandler
|
||||
, public CefV8Handler
|
||||
{
|
||||
|
||||
public:
|
||||
virtual CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() override
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
void OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) override
|
||||
{
|
||||
CefRefPtr<CefV8Value> global = context->GetGlobal();
|
||||
CefRefPtr<CefV8Value> func = CefV8Value::CreateFunction("sendResultToEngine", this);
|
||||
global->SetValue("sendResultToEngine", func, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
}
|
||||
|
||||
bool Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception) override
|
||||
{
|
||||
if (name == "sendResultToEngine" && arguments.size() == 1)
|
||||
{
|
||||
CefRefPtr<CefProcessMessage> msg = CefProcessMessage::Create("resultMessage");
|
||||
|
||||
CefRefPtr<CefListValue> args = msg->GetArgumentList();
|
||||
args->SetString(0, arguments[0]->GetStringValue());
|
||||
|
||||
CefRefPtr<CefBrowser> browser = CefV8Context::GetCurrentContext()->GetBrowser();
|
||||
CefRefPtr<CefFrame> frame = browser->GetMainFrame();
|
||||
|
||||
frame->SendProcessMessage(PID_BROWSER, msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
IMPLEMENT_REFCOUNTING(AyaCefSubprocess);
|
||||
};
|
||||
|
||||
#ifdef WIN32
|
||||
int CALLBACK WinMain(_In_ HINSTANCE hInstance, _In_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow)
|
||||
{
|
||||
CefMainArgs args(hInstance);
|
||||
return CefExecuteProcess(args, new AyaCefSubprocess(), nullptr);
|
||||
}
|
||||
#else
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
CefMainArgs args(argc, argv);
|
||||
return CefExecuteProcess(args, new AyaCefSubprocess(), nullptr);
|
||||
}
|
||||
#endif
|
||||
38
tools/core-script-compiler/CMakeLists.txt
Normal file
38
tools/core-script-compiler/CMakeLists.txt
Normal file
@@ -0,0 +1,38 @@
|
||||
add_executable(CoreScriptCompiler src/main.cpp)
|
||||
|
||||
target_link_libraries(CoreScriptCompiler
|
||||
3D
|
||||
AppServer
|
||||
Core
|
||||
RakNet
|
||||
BulletPhysics
|
||||
NetworkServer
|
||||
Graphics
|
||||
)
|
||||
|
||||
if(AYA_OS_WINDOWS)
|
||||
target_sources(CoreScriptCompiler PRIVATE resources/winrc.h resources/script.rc)
|
||||
endif()
|
||||
|
||||
target_include_directories(CoreScriptCompiler PRIVATE src resources)
|
||||
set_target_properties(CoreScriptCompiler PROPERTIES OUTPUT_NAME "Aya.CoreScriptCompiler")
|
||||
|
||||
add_custom_target(CompileCoreScripts
|
||||
$<TARGET_FILE:CoreScriptCompiler> --source "${CLIENT_DIR}/common/content/scripts" --output "${ENGINE_DIR}/app/src/Script/LuaGenCS.inl"
|
||||
DEPENDS CoreScriptCompiler
|
||||
COMMENT "Compiling CoreScript bytecode"
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
|
||||
)
|
||||
|
||||
add_custom_target(CompileShaders
|
||||
python ${CLIENT_DIR}/common/shaders/compile_shaders.py --packs glsl3 glsles3 --bgfx-include "${CMAKE_BINARY_DIR}/vcpkg_installed/x64-windows/include"
|
||||
COMMENT "Compiling shaders"
|
||||
WORKING_DIRECTORY "${CLIENT_DIR}/common/shaders"
|
||||
)
|
||||
|
||||
add_custom_command(TARGET CompileCoreScripts POST_BUILD
|
||||
COMMENT "Copying runtime files to build directory"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"${RUNTIME_FILES}"
|
||||
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
|
||||
)
|
||||
BIN
tools/core-script-compiler/resources/icon.ico
Normal file
BIN
tools/core-script-compiler/resources/icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
49
tools/core-script-compiler/resources/script.rc
Normal file
49
tools/core-script-compiler/resources/script.rc
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "winrc.h"
|
||||
|
||||
#if defined(__MINGW64__) || defined(__MINGW32__)
|
||||
// MinGW-w64, MinGW
|
||||
#if defined(__has_include) && __has_include(<winres.h>)
|
||||
#include <winres.h>
|
||||
#else
|
||||
#include <afxres.h>
|
||||
#include <winresrc.h>
|
||||
#endif
|
||||
#else
|
||||
// MSVC, Windows SDK
|
||||
#include <winres.h>
|
||||
#endif
|
||||
|
||||
IDI_ICON1 ICON APP_ICON
|
||||
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION VERSION_RESOURCE
|
||||
PRODUCTVERSION VERSION_RESOURCE
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x4L
|
||||
FILETYPE 0x1L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", APP_ORGANIZATION
|
||||
VALUE "FileDescription", APP_DESCRIPTION
|
||||
VALUE "FileVersion", VERSION_RESOURCE_STR
|
||||
VALUE "LegalCopyright", APP_COPYRIGHT
|
||||
VALUE "ProductName", APP_NAME
|
||||
VALUE "ProductVersion", VERSION_RESOURCE_STR
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", PRODUCT_LANGUAGE, PRODUCT_CHARSET
|
||||
END
|
||||
END
|
||||
24
tools/core-script-compiler/resources/winrc.h
Normal file
24
tools/core-script-compiler/resources/winrc.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#define VERSION_MAJOR_MINOR_STR AYA_VERSION_MAJOR_STR "." AYA_VERSION_MINOR_STR
|
||||
#define VERSION_MAJOR_MINOR_PATCH_STR VERSION_MAJOR_MINOR_STR "." AYA_VERSION_PATCH_STR
|
||||
#ifdef AYA_VERSION_TYPE
|
||||
#define VERSION_FULL_STR VERSION_MAJOR_MINOR_PATCH_STR "-" AYA_VERSION_TYPE
|
||||
#else
|
||||
#define VERSION_FULL_STR VERSION_MAJOR_MINOR_PATCH_STR
|
||||
#endif
|
||||
#define VERSION_RESOURCE AYA_VERSION_MAJOR, AYA_VERSION_MINOR, AYA_VERSION_PATCH, 0
|
||||
#define VERSION_RESOURCE_STR VERSION_FULL_STR "\0"
|
||||
|
||||
/*
|
||||
* These properties are part of VarFileInfo.
|
||||
* For more information, please see: https://learn.microsoft.com/en-us/windows/win32/menurc/varfileinfo-block
|
||||
*/
|
||||
#define PRODUCT_LANGUAGE 0x0409 // en-US
|
||||
#define PRODUCT_CHARSET 1200 // Unicode
|
||||
|
||||
#define APP_ICON "icon.ico"
|
||||
#define APP_NAME AYA_PROJECT_NAME "\0"
|
||||
#define APP_DESCRIPTION AYA_PROJECT_NAME " Core Script Compiler\0"
|
||||
#define APP_ORGANIZATION AYA_PROJECT_NAME "\0"
|
||||
#define APP_COPYRIGHT AYA_PROJECT_NAME " License\0"
|
||||
214
tools/core-script-compiler/src/main.cpp
Normal file
214
tools/core-script-compiler/src/main.cpp
Normal file
@@ -0,0 +1,214 @@
|
||||
#include <boost/program_options.hpp>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
|
||||
#include "Script/LuaVM.hpp"
|
||||
#include "Utility/Utilities.hpp"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
namespace po = boost::program_options;
|
||||
|
||||
bool verbose;
|
||||
|
||||
struct CoreScriptFile
|
||||
{
|
||||
std::string name;
|
||||
fs::path file;
|
||||
bool module;
|
||||
};
|
||||
|
||||
static int fatal(const char* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
fprintf(stderr, "FATAL: ");
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
exit(1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
char* hexa(unsigned char ch)
|
||||
{
|
||||
static const char sym[] = "0123456789abcdef";
|
||||
static char buf[8];
|
||||
|
||||
buf[0] = '0';
|
||||
buf[1] = 'x';
|
||||
buf[2] = sym[(ch >> 4) & 0xf];
|
||||
buf[3] = sym[(ch) & 0xf];
|
||||
buf[4] = 0;
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
void rdfile(std::string* result, const fs::path& filepath)
|
||||
{
|
||||
#if _MSC_VER
|
||||
FILE* vf = _wfopen(filepath.native().c_str(), L"rb");
|
||||
#else
|
||||
FILE* vf = fopen(filepath.native().c_str(), "rb");
|
||||
#endif
|
||||
|
||||
vf || fatal("could not open '%s'\n", filepath.native().c_str());
|
||||
|
||||
// no better portable way to get file size
|
||||
fseek(vf, 0, SEEK_END);
|
||||
long size = ftell(vf);
|
||||
fseek(vf, 0, SEEK_SET);
|
||||
|
||||
result->resize(size);
|
||||
fread((char*)result->data(), 1, size, vf);
|
||||
fclose(vf);
|
||||
}
|
||||
|
||||
void buildFileList(std::vector<CoreScriptFile>& files, fs::path dir, fs::path parent = fs::path())
|
||||
{
|
||||
for (fs::directory_iterator it(dir), e; it != e; ++it)
|
||||
{
|
||||
const fs::directory_entry& dirent = *it;
|
||||
const fs::path& filepath = dirent.path();
|
||||
fs::file_status st = dirent.status();
|
||||
|
||||
if (st.type() == fs::file_type::directory)
|
||||
{
|
||||
// Recursively process subdirectories
|
||||
buildFileList(files, filepath, parent / filepath.filename());
|
||||
}
|
||||
else if (st.type() == fs::file_type::regular && filepath.extension() == ".lua")
|
||||
{
|
||||
fs::path name = parent / filepath.filename();
|
||||
|
||||
CoreScriptFile script;
|
||||
script.name = name.replace_extension().string();
|
||||
|
||||
std::replace(script.name.begin(), script.name.end(), '\\', '/');
|
||||
|
||||
script.file = filepath;
|
||||
script.module = script.name.find("Modules") == 0;
|
||||
if (script.module)
|
||||
script.name = script.name.substr(8);
|
||||
|
||||
files.push_back(script);
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
printf(" %s: %s\n", script.name.c_str(), filepath.native().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void printBuffer(std::ostream& os, const std::string& name, const std::string& data)
|
||||
{
|
||||
os << "static const unsigned char " << name << "[] = {";
|
||||
|
||||
for (int i = 0, j = data.size(); i < j; ++i)
|
||||
{
|
||||
if (!(i % 32))
|
||||
os << "\n ";
|
||||
|
||||
os << hexa(data[i]) << ", ";
|
||||
}
|
||||
|
||||
os << "\n };\n\n";
|
||||
}
|
||||
|
||||
void processMacro(std::string* source, const std::string& macro, const std::string& value)
|
||||
{
|
||||
size_t pos = 0;
|
||||
std::string find = "${" + macro + "}";
|
||||
|
||||
while ((pos = source->find(find, pos)) != std::string::npos)
|
||||
{
|
||||
source->replace(pos, find.size(), value);
|
||||
pos += value.size();
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
// Parse arguments
|
||||
std::string outputPath;
|
||||
std::vector<std::string> sourcePaths;
|
||||
|
||||
po::options_description desc("Aya.CoreScriptCompiler options");
|
||||
|
||||
desc.add_options()("help,?", "Usage help")("output,o", po::value<std::string>(&outputPath)->required(),
|
||||
"Path to the output file where compiled CoreScript bytecode shall be kept")("source,s",
|
||||
po::value<std::vector<std::string>>(&sourcePaths)->required(),
|
||||
"CoreScript source paths")("verbose", po::value<bool>(&verbose)->default_value(false), "Enable verbose logging");
|
||||
|
||||
po::variables_map vm;
|
||||
po::store(po::parse_command_line(argc, argv, desc), vm);
|
||||
po::notify(vm);
|
||||
|
||||
if (vm.count("help"))
|
||||
{
|
||||
std::cout << desc << "\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<CoreScriptFile> files;
|
||||
fs::path source = fs::current_path() / sourcePaths[0];
|
||||
buildFileList(files, source);
|
||||
|
||||
for (int i = 1; i < sourcePaths.size(); i++)
|
||||
{
|
||||
fs::path source = fs::current_path() / sourcePaths[i];
|
||||
buildFileList(files, source);
|
||||
}
|
||||
|
||||
// Got all the files, go ahead and compile
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> startTime, endTime;
|
||||
|
||||
std::stringstream arrays, scripts, modules; // 3 main sections
|
||||
|
||||
scripts << "static const CoreScriptBytecode gCoreScripts[] = {\n";
|
||||
modules << "static const CoreScriptBytecode gCoreModuleScripts[] = {\n";
|
||||
|
||||
printf("-- Running CoreScript compiler\n");
|
||||
|
||||
startTime = std::chrono::high_resolution_clock::now();
|
||||
|
||||
for (unsigned i = 0; i < files.size(); ++i)
|
||||
{
|
||||
std::string source;
|
||||
CoreScriptFile& script = files[i];
|
||||
rdfile(&source, script.file);
|
||||
|
||||
processMacro(&source, "PROJECT_NAME", AYA_PROJECT_NAME);
|
||||
// processMacro(&source, "CURRENCY_NAME", AYA_CURRENCY_NAME);
|
||||
|
||||
std::string bytecode = LuaVM::compileCore(source);
|
||||
|
||||
std::string encname = script.name;
|
||||
std::string arrayName = Aya::format("a%04u", i);
|
||||
encname = Aya::rot13(encname);
|
||||
|
||||
printBuffer(arrays, arrayName, bytecode);
|
||||
|
||||
(script.module ? modules : scripts) << " { \"" << encname << "\", " << arrayName << ", " << bytecode.size() << " },\n";
|
||||
}
|
||||
|
||||
endTime = std::chrono::high_resolution_clock::now();
|
||||
|
||||
scripts << "};\n\n";
|
||||
modules << "};\n\n";
|
||||
|
||||
auto elapsedTime = endTime - startTime;
|
||||
printf("-- Compiled %u CoreScripts in %.2f seconds\n", files.size(), std::chrono::duration<double>(elapsedTime).count());
|
||||
|
||||
// Write the file
|
||||
fs::path outputFile = fs::current_path() / outputPath;
|
||||
std::ofstream output(outputFile.c_str());
|
||||
|
||||
output << arrays.str() << scripts.str() << modules.str();
|
||||
|
||||
if (output.rdstate() & output.failbit)
|
||||
fatal("could not write to '%s'", outputFile.c_str());
|
||||
|
||||
printf("-- Built CoreScript bytecode file available at '%s'\n", outputFile.c_str());
|
||||
return 0;
|
||||
}
|
||||
11
tools/thumbnail-helper/CMakeLists.txt
Normal file
11
tools/thumbnail-helper/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
add_library(ThumbnailHelper SHARED
|
||||
src/thumb_win32.cc
|
||||
src/thumb_win32_dll.cc
|
||||
src/thumb_win32.def
|
||||
resources/winrc.h
|
||||
resources/script.rc
|
||||
)
|
||||
|
||||
target_include_directories(ThumbnailHelper PRIVATE src resources)
|
||||
target_link_libraries(ThumbnailHelper dbghelp.lib Version.lib)
|
||||
set_target_properties(ThumbnailHelper PROPERTIES OUTPUT_NAME "Aya.ThumbnailHelper")
|
||||
339
tools/thumbnail-helper/LICENSE.txt
Normal file
339
tools/thumbnail-helper/LICENSE.txt
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
11
tools/thumbnail-helper/README.txt
Normal file
11
tools/thumbnail-helper/README.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
Aya.ThumbnailHelper
|
||||
===================
|
||||
Thumbnail provider for Aya level files (.ayal)
|
||||
`regsvr32 Aya.ThumbnailHelper.dll`
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
This project is licensed under the GPLv2:
|
||||
https://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
|
||||
Fork of blendthumb.
|
||||
47
tools/thumbnail-helper/resources/script.rc
Normal file
47
tools/thumbnail-helper/resources/script.rc
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "winrc.h"
|
||||
|
||||
#if defined(__MINGW64__) || defined(__MINGW32__)
|
||||
// MinGW-w64, MinGW
|
||||
#if defined(__has_include) && __has_include(<winres.h>)
|
||||
#include <winres.h>
|
||||
#else
|
||||
#include <afxres.h>
|
||||
#include <winresrc.h>
|
||||
#endif
|
||||
#else
|
||||
// MSVC, Windows SDK
|
||||
#include <winres.h>
|
||||
#endif
|
||||
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION VERSION_RESOURCE
|
||||
PRODUCTVERSION VERSION_RESOURCE
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x4L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", APP_ORGANIZATION
|
||||
VALUE "FileDescription", APP_DESCRIPTION
|
||||
VALUE "FileVersion", VERSION_RESOURCE_STR
|
||||
VALUE "LegalCopyright", APP_COPYRIGHT
|
||||
VALUE "ProductName", APP_NAME
|
||||
VALUE "ProductVersion", VERSION_RESOURCE_STR
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", PRODUCT_LANGUAGE, PRODUCT_CHARSET
|
||||
END
|
||||
END
|
||||
23
tools/thumbnail-helper/resources/winrc.h
Normal file
23
tools/thumbnail-helper/resources/winrc.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#define VERSION_MAJOR_MINOR_STR AYA_VERSION_MAJOR_STR "." AYA_VERSION_MINOR_STR
|
||||
#define VERSION_MAJOR_MINOR_PATCH_STR VERSION_MAJOR_MINOR_STR "." AYA_VERSION_PATCH_STR
|
||||
#ifdef AYA_VERSION_TYPE
|
||||
#define VERSION_FULL_STR VERSION_MAJOR_MINOR_PATCH_STR "-" AYA_VERSION_TYPE
|
||||
#else
|
||||
#define VERSION_FULL_STR VERSION_MAJOR_MINOR_PATCH_STR
|
||||
#endif
|
||||
#define VERSION_RESOURCE AYA_VERSION_MAJOR, AYA_VERSION_MINOR, AYA_VERSION_PATCH, 0
|
||||
#define VERSION_RESOURCE_STR VERSION_FULL_STR "\0"
|
||||
|
||||
/*
|
||||
* These properties are part of VarFileInfo.
|
||||
* For more information, please see: https://learn.microsoft.com/en-us/windows/win32/menurc/varfileinfo-block
|
||||
*/
|
||||
#define PRODUCT_LANGUAGE 0x0409 // en-US
|
||||
#define PRODUCT_CHARSET 1200 // Unicode
|
||||
|
||||
#define APP_NAME AYA_PROJECT_NAME "\0"
|
||||
#define APP_DESCRIPTION AYA_PROJECT_NAME " Thumbnail Helper\0"
|
||||
#define APP_ORGANIZATION AYA_PROJECT_NAME "\0"
|
||||
#define APP_COPYRIGHT AYA_PROJECT_NAME " License\0"
|
||||
228
tools/thumbnail-helper/src/thumb_win32.cc
Normal file
228
tools/thumbnail-helper/src/thumb_win32.cc
Normal file
@@ -0,0 +1,228 @@
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <new>
|
||||
#include <shlwapi.h>
|
||||
#include <string>
|
||||
#include <thumbcache.h> /* for #IThumbnailProvider */
|
||||
#include <vector>
|
||||
|
||||
#include "Wincodec.h"
|
||||
|
||||
#pragma comment(lib, "shlwapi.lib")
|
||||
|
||||
struct Thumbnail
|
||||
{
|
||||
std::vector<uint8_t> data;
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
/**
|
||||
* This thumbnail provider implements #IInitializeWithStream to enable being
|
||||
* hosted in an isolated process for robustness.
|
||||
*/
|
||||
class CAyaThumb
|
||||
: public IInitializeWithStream
|
||||
, public IThumbnailProvider
|
||||
{
|
||||
public:
|
||||
CAyaThumb()
|
||||
: _cRef(1)
|
||||
, _pStream(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~CAyaThumb()
|
||||
{
|
||||
if (_pStream)
|
||||
{
|
||||
_pStream->Release();
|
||||
}
|
||||
}
|
||||
|
||||
IFACEMETHODIMP QueryInterface(REFIID riid, void** ppv)
|
||||
{
|
||||
static const QITAB qit[] = {
|
||||
QITABENT(CAyaThumb, IInitializeWithStream),
|
||||
QITABENT(CAyaThumb, IThumbnailProvider),
|
||||
{0},
|
||||
};
|
||||
return QISearch(this, qit, riid, ppv);
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) AddRef()
|
||||
{
|
||||
return InterlockedIncrement(&_cRef);
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) Release()
|
||||
{
|
||||
ULONG cRef = InterlockedDecrement(&_cRef);
|
||||
if (!cRef)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
return cRef;
|
||||
}
|
||||
|
||||
/** IInitializeWithStream */
|
||||
IFACEMETHODIMP Initialize(IStream* pStream, DWORD grfMode);
|
||||
|
||||
/** IThumbnailProvider */
|
||||
IFACEMETHODIMP GetThumbnail(UINT cx, HBITMAP* phbmp, WTS_ALPHATYPE* pdwAlpha);
|
||||
|
||||
private:
|
||||
long _cRef;
|
||||
IStream* _pStream; /* provided in Initialize(). */
|
||||
};
|
||||
|
||||
HRESULT CAyaThumb_CreateInstance(REFIID riid, void** ppv)
|
||||
{
|
||||
CAyaThumb* pNew = new (std::nothrow) CAyaThumb();
|
||||
HRESULT hr = pNew ? S_OK : E_OUTOFMEMORY;
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = pNew->QueryInterface(riid, ppv);
|
||||
pNew->Release();
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP CAyaThumb::Initialize(IStream* pStream, DWORD)
|
||||
{
|
||||
if (_pStream != nullptr)
|
||||
{
|
||||
/* Can only be initialized once. */
|
||||
return E_UNEXPECTED;
|
||||
}
|
||||
/* Take a reference to the stream. */
|
||||
return pStream->QueryInterface(&_pStream);
|
||||
}
|
||||
|
||||
IFACEMETHODIMP CAyaThumb::GetThumbnail(UINT cx, HBITMAP* phbmp, WTS_ALPHATYPE* pdwAlpha)
|
||||
{
|
||||
HRESULT hr = S_FALSE;
|
||||
|
||||
std::vector<char> buffer;
|
||||
ULONG bytesRead;
|
||||
char chunk[4096];
|
||||
do
|
||||
{
|
||||
hr = _pStream->Read(chunk, sizeof(chunk), &bytesRead);
|
||||
if (SUCCEEDED(hr) && bytesRead > 0)
|
||||
{
|
||||
buffer.insert(buffer.end(), chunk, chunk + bytesRead);
|
||||
}
|
||||
} while (SUCCEEDED(hr) && bytesRead > 0);
|
||||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
return hr;
|
||||
}
|
||||
|
||||
// Find the </roblox> closing tag
|
||||
const std::string endTag = "</roblox>";
|
||||
auto it = std::search(buffer.begin(), buffer.end(), endTag.begin(), endTag.end());
|
||||
if (it == buffer.end())
|
||||
{
|
||||
return E_FAIL; // Closing tag not found
|
||||
}
|
||||
|
||||
// Move iterator past the closing tag and the null byte
|
||||
std::advance(it, endTag.length() + 1);
|
||||
|
||||
if (it >= buffer.end())
|
||||
{
|
||||
return E_FAIL; // No data after the closing tag
|
||||
}
|
||||
|
||||
// The rest is JPEG data
|
||||
std::vector<unsigned char> jpegData(it, buffer.end());
|
||||
|
||||
// Create a WIC factory
|
||||
IWICImagingFactory* pFactory = nullptr;
|
||||
hr = CoCreateInstance(CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFactory));
|
||||
if (FAILED(hr))
|
||||
{
|
||||
return hr;
|
||||
}
|
||||
|
||||
// Create a stream from the JPEG data
|
||||
IWICStream* pStream = nullptr;
|
||||
hr = pFactory->CreateStream(&pStream);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
pFactory->Release();
|
||||
return hr;
|
||||
}
|
||||
|
||||
hr = pStream->InitializeFromMemory(jpegData.data(), jpegData.size());
|
||||
if (FAILED(hr))
|
||||
{
|
||||
pStream->Release();
|
||||
pFactory->Release();
|
||||
return hr;
|
||||
}
|
||||
|
||||
// Create a decoder
|
||||
IWICBitmapDecoder* pDecoder = nullptr;
|
||||
hr = pFactory->CreateDecoderFromStream(pStream, nullptr, WICDecodeMetadataCacheOnDemand, &pDecoder);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
pStream->Release();
|
||||
pFactory->Release();
|
||||
return hr;
|
||||
}
|
||||
|
||||
// Get the first frame of the image from the decoder
|
||||
IWICBitmapFrameDecode* pFrame = nullptr;
|
||||
hr = pDecoder->GetFrame(0, &pFrame);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
pDecoder->Release();
|
||||
pStream->Release();
|
||||
pFactory->Release();
|
||||
return hr;
|
||||
}
|
||||
|
||||
// Get the size of the image
|
||||
UINT width, height;
|
||||
hr = pFrame->GetSize(&width, &height);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
pFrame->Release();
|
||||
pDecoder->Release();
|
||||
pStream->Release();
|
||||
pFactory->Release();
|
||||
return hr;
|
||||
}
|
||||
|
||||
UINT stride = (width * 3 + 3) & ~3;
|
||||
|
||||
// Create a bitmap and copy the pixels
|
||||
Thumbnail thumb;
|
||||
thumb.width = width;
|
||||
thumb.height = height;
|
||||
thumb.data.resize(height * stride);
|
||||
hr = pFrame->CopyPixels(nullptr, stride, thumb.data.size(), thumb.data.data());
|
||||
|
||||
pFrame->Release();
|
||||
pDecoder->Release();
|
||||
pStream->Release();
|
||||
pFactory->Release();
|
||||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
return hr;
|
||||
}
|
||||
|
||||
*phbmp = CreateBitmap(thumb.width, thumb.height, 1, 24, thumb.data.data());
|
||||
if (!*phbmp)
|
||||
{
|
||||
return E_FAIL;
|
||||
}
|
||||
*pdwAlpha = WTSAT_RGB;
|
||||
|
||||
hr = S_OK;
|
||||
return hr;
|
||||
}
|
||||
5
tools/thumbnail-helper/src/thumb_win32.def
Normal file
5
tools/thumbnail-helper/src/thumb_win32.def
Normal file
@@ -0,0 +1,5 @@
|
||||
EXPORTS
|
||||
DllGetClassObject PRIVATE
|
||||
DllCanUnloadNow PRIVATE
|
||||
DllRegisterServer PRIVATE
|
||||
DllUnregisterServer PRIVATE
|
||||
262
tools/thumbnail-helper/src/thumb_win32_dll.cc
Normal file
262
tools/thumbnail-helper/src/thumb_win32_dll.cc
Normal file
@@ -0,0 +1,262 @@
|
||||
#include <new>
|
||||
#include <objbase.h>
|
||||
#include <shlobj.h> /* For #SHChangeNotify */
|
||||
#include <shlwapi.h>
|
||||
#include <thumbcache.h> /* For IThumbnailProvider */
|
||||
|
||||
extern HRESULT CAyaThumb_CreateInstance(REFIID riid, void** ppv);
|
||||
|
||||
#define SZ_CLSID_AYATHUMBHANDLER L"{8ABA9ABD-829D-4E87-AC2C-4A628AB78236}"
|
||||
#define SZ_AYATHUMBHANDLER L"Aya Thumbnail Handler"
|
||||
const CLSID CLSID_AyaThumbHandler = {0x8ABA9ABD, 0x829D, 0x4E87, {0xAC, 0x2C, 0x4A, 0x62, 0x8A, 0xB7, 0x82, 0x36}};
|
||||
|
||||
typedef HRESULT (*PFNCREATEINSTANCE)(REFIID riid, void** ppvObject);
|
||||
struct CLASS_OBJECT_INIT
|
||||
{
|
||||
const CLSID* pClsid;
|
||||
PFNCREATEINSTANCE pfnCreate;
|
||||
};
|
||||
|
||||
/* Add classes supported by this module here. */
|
||||
const CLASS_OBJECT_INIT c_rgClassObjectInit[] = {{&CLSID_AyaThumbHandler, CAyaThumb_CreateInstance}};
|
||||
|
||||
long g_cRefModule = 0;
|
||||
|
||||
/** Handle the DLL's module */
|
||||
HINSTANCE g_hInst = nullptr;
|
||||
|
||||
/** Standard DLL functions. */
|
||||
STDAPI_(BOOL) DllMain(HINSTANCE hInstance, DWORD dwReason, void*)
|
||||
{
|
||||
if (dwReason == DLL_PROCESS_ATTACH)
|
||||
{
|
||||
g_hInst = hInstance;
|
||||
DisableThreadLibraryCalls(hInstance);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
STDAPI DllCanUnloadNow()
|
||||
{
|
||||
/* Only allow the DLL to be unloaded after all outstanding references have
|
||||
* been released. */
|
||||
return (g_cRefModule == 0) ? S_OK : S_FALSE;
|
||||
}
|
||||
|
||||
void DllAddRef()
|
||||
{
|
||||
InterlockedIncrement(&g_cRefModule);
|
||||
}
|
||||
|
||||
void DllRelease()
|
||||
{
|
||||
InterlockedDecrement(&g_cRefModule);
|
||||
}
|
||||
|
||||
class CClassFactory : public IClassFactory
|
||||
{
|
||||
public:
|
||||
static HRESULT CreateInstance(REFCLSID clsid, const CLASS_OBJECT_INIT* pClassObjectInits, size_t cClassObjectInits, REFIID riid, void** ppv)
|
||||
{
|
||||
*ppv = nullptr;
|
||||
HRESULT hr = CLASS_E_CLASSNOTAVAILABLE;
|
||||
for (size_t i = 0; i < cClassObjectInits; i++)
|
||||
{
|
||||
if (clsid == *pClassObjectInits[i].pClsid)
|
||||
{
|
||||
IClassFactory* pClassFactory = new (std::nothrow) CClassFactory(pClassObjectInits[i].pfnCreate);
|
||||
hr = pClassFactory ? S_OK : E_OUTOFMEMORY;
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = pClassFactory->QueryInterface(riid, ppv);
|
||||
pClassFactory->Release();
|
||||
}
|
||||
/* Match found. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
CClassFactory(PFNCREATEINSTANCE pfnCreate)
|
||||
: _cRef(1)
|
||||
, _pfnCreate(pfnCreate)
|
||||
{
|
||||
DllAddRef();
|
||||
}
|
||||
|
||||
/** #IUnknown */
|
||||
IFACEMETHODIMP QueryInterface(REFIID riid, void** ppv)
|
||||
{
|
||||
static const QITAB qit[] = {QITABENT(CClassFactory, IClassFactory), {0}};
|
||||
return QISearch(this, qit, riid, ppv);
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) AddRef()
|
||||
{
|
||||
return InterlockedIncrement(&_cRef);
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) Release()
|
||||
{
|
||||
long cRef = InterlockedDecrement(&_cRef);
|
||||
if (cRef == 0)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
return cRef;
|
||||
}
|
||||
|
||||
/** #IClassFactory */
|
||||
IFACEMETHODIMP CreateInstance(IUnknown* punkOuter, REFIID riid, void** ppv)
|
||||
{
|
||||
return punkOuter ? CLASS_E_NOAGGREGATION : _pfnCreate(riid, ppv);
|
||||
}
|
||||
|
||||
IFACEMETHODIMP LockServer(BOOL fLock)
|
||||
{
|
||||
if (fLock)
|
||||
{
|
||||
DllAddRef();
|
||||
}
|
||||
else
|
||||
{
|
||||
DllRelease();
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
~CClassFactory()
|
||||
{
|
||||
DllRelease();
|
||||
}
|
||||
|
||||
long _cRef;
|
||||
PFNCREATEINSTANCE _pfnCreate;
|
||||
};
|
||||
|
||||
STDAPI DllGetClassObject(REFCLSID clsid, REFIID riid, void** ppv)
|
||||
{
|
||||
return CClassFactory::CreateInstance(clsid, c_rgClassObjectInit, ARRAYSIZE(c_rgClassObjectInit), riid, ppv);
|
||||
}
|
||||
|
||||
/**
|
||||
* A struct to hold the information required for a registry entry.
|
||||
*/
|
||||
struct REGISTRY_ENTRY
|
||||
{
|
||||
HKEY hkeyRoot;
|
||||
PCWSTR pszKeyName;
|
||||
PCWSTR pszValueName;
|
||||
DWORD dwValueType;
|
||||
/** These two fields could/should have been a union, but C++ */
|
||||
PCWSTR pszData;
|
||||
/** Only lets you initialize the first field in a union. */
|
||||
DWORD dwData;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a registry key (if needed) and sets the default value of the key.
|
||||
*/
|
||||
HRESULT CreateRegKeyAndSetValue(const REGISTRY_ENTRY* pRegistryEntry)
|
||||
{
|
||||
HKEY hKey;
|
||||
HRESULT hr = HRESULT_FROM_WIN32(RegCreateKeyExW(pRegistryEntry->hkeyRoot, pRegistryEntry->pszKeyName, 0, nullptr, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, nullptr, &hKey, nullptr));
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
/* All this just to support #REG_DWORD. */
|
||||
DWORD size;
|
||||
DWORD data;
|
||||
BYTE* lpData = (LPBYTE)pRegistryEntry->pszData;
|
||||
switch (pRegistryEntry->dwValueType)
|
||||
{
|
||||
case REG_SZ:
|
||||
size = ((DWORD)wcslen(pRegistryEntry->pszData) + 1) * sizeof(WCHAR);
|
||||
break;
|
||||
case REG_DWORD:
|
||||
size = sizeof(DWORD);
|
||||
data = pRegistryEntry->dwData;
|
||||
lpData = (BYTE*)&data;
|
||||
break;
|
||||
default:
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, pRegistryEntry->pszValueName, 0, pRegistryEntry->dwValueType, lpData, size));
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers this COM server.
|
||||
*/
|
||||
STDAPI DllRegisterServer()
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
WCHAR szModuleName[MAX_PATH];
|
||||
|
||||
if (!GetModuleFileNameW(g_hInst, szModuleName, ARRAYSIZE(szModuleName)))
|
||||
{
|
||||
hr = HRESULT_FROM_WIN32(GetLastError());
|
||||
}
|
||||
else
|
||||
{
|
||||
const REGISTRY_ENTRY rgRegistryEntries[] = {
|
||||
/* `RootKey KeyName ValueName ValueType Data` */
|
||||
{HKEY_CURRENT_USER, L"Software\\Classes\\CLSID\\" SZ_CLSID_AYATHUMBHANDLER, nullptr, REG_SZ, SZ_AYATHUMBHANDLER},
|
||||
{HKEY_CURRENT_USER,
|
||||
L"Software\\Classes\\CLSID"
|
||||
L"\\" SZ_CLSID_AYATHUMBHANDLER L"\\InProcServer32",
|
||||
nullptr, REG_SZ, szModuleName},
|
||||
{HKEY_CURRENT_USER,
|
||||
L"Software\\Classes\\CLSID"
|
||||
L"\\" SZ_CLSID_AYATHUMBHANDLER L"\\InProcServer32",
|
||||
L"ThreadingModel", REG_SZ, L"Apartment"},
|
||||
{HKEY_CURRENT_USER, L"Software\\Classes\\.ayal\\", L"Treatment", REG_DWORD, 0, 0}, /* This doesn't appear to do anything. */
|
||||
{HKEY_CURRENT_USER,
|
||||
L"Software\\Classes\\.ayal\\ShellEx\\{e357fccd-a995-4576-b01f-"
|
||||
L"234630154e96}",
|
||||
nullptr, REG_SZ, SZ_CLSID_AYATHUMBHANDLER},
|
||||
};
|
||||
|
||||
hr = S_OK;
|
||||
for (int i = 0; i < ARRAYSIZE(rgRegistryEntries) && SUCCEEDED(hr); i++)
|
||||
{
|
||||
hr = CreateRegKeyAndSetValue(&rgRegistryEntries[i]);
|
||||
}
|
||||
}
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
/* This tells the shell to invalidate the thumbnail cache.
|
||||
* This is important because any `.ayal` files viewed before registering
|
||||
* this handler would otherwise show cached blank thumbnails. */
|
||||
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nullptr, nullptr);
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters this COM server
|
||||
*/
|
||||
STDAPI DllUnregisterServer()
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
const PCWSTR rgpszKeys[] = {L"Software\\Classes\\CLSID\\" SZ_CLSID_AYATHUMBHANDLER, L"Software\\Classes\\.ayal\\ShellEx\\{e357fccd-a995-4576-b01f-"
|
||||
L"234630154e96}"};
|
||||
|
||||
/* Delete the registry entries. */
|
||||
for (int i = 0; i < ARRAYSIZE(rgpszKeys) && SUCCEEDED(hr); i++)
|
||||
{
|
||||
hr = HRESULT_FROM_WIN32(RegDeleteTreeW(HKEY_CURRENT_USER, rgpszKeys[i]));
|
||||
if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
|
||||
{
|
||||
/* If the registry entry has already been deleted, say S_OK. */
|
||||
hr = S_OK;
|
||||
}
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
Reference in New Issue
Block a user