diff --git a/3mfthumb b/3mfthumb index 61ec040..bee7e44 100755 Binary files a/3mfthumb and b/3mfthumb differ diff --git a/3mfthumb.cpp b/3mfthumb.cpp index 5df325c..07d61fe 100755 --- a/3mfthumb.cpp +++ b/3mfthumb.cpp @@ -18,19 +18,22 @@ /// MA 02110-1301, USA. #include +#ifdef WIN32 +#include +#endif #include "lib3mf_implicit.hpp" int main(int argc, char **argv) { - if (argc < 3){ + if (argc < 2){ std::cout << "Usage: 3mfthumb " << std::endl; return 1; } + // Get file names from command-line arguments + std::string filename = argv[1]; + std::string thumbnailFilename = argv[2]; try { auto wrapper = Lib3MF::CWrapper::loadLibrary(); - // Get file names as arguments - std::string filename = argv[1]; - std::string thumbnailFilename = argv[2]; // Read the 3MF file Lib3MF::PModel model = wrapper->CreateModel(); Lib3MF::PReader reader = model->QueryReader("3mf"); @@ -38,7 +41,17 @@ int main(int argc, char **argv) { // Get thumbnail attachment Lib3MF::PAttachment thumbnail; if (model->HasPackageThumbnailAttachment()) { - thumbnail = model->GetPackageThumbnailAttachment(); + thumbnail = model->GetPackageThumbnailAttachment(); + #ifdef WIN32 + if (argc == 2) { + // Get a location Windows expects + std::filesystem::path thumbnailPath = std::getenv("LOCALAPPDATA"); + thumbnailPath /= "Microsoft\\Windows\\Explorer\\" + thumbnail->GetRelationShipType(); + std::filesystem::create_directories(thumbnailPath); + thumbnailPath /= std::filesystem::path(filename).stem().string() + ".thumbnail"; + thumbnailFilename = thumbnailPath.string(); + } + #endif // Write thumbnail to file thumbnail->WriteToFile(thumbnailFilename); } diff --git a/3mfthumb.o b/3mfthumb.o deleted file mode 100644 index bcd999d..0000000 Binary files a/3mfthumb.o and /dev/null differ diff --git a/Makefile b/Makefile index c5d6acd..973af53 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,17 @@ NAME=3mfthumb CFLAGS=-g -Wall $(shell pkg-config --cflags lib3mf) -LDFLAGS=$(shell pkg-config --libs lib3mf) +LDFLAGS:=$(shell pkg-config --libs lib3mf) $(LIBS) -CPP=g++ +CXX?=g++ all: - ${CPP} ${CFLAGS} -c ${NAME}.cpp -o ${NAME}.o - ${CPP} ${NAME}.o -o ${NAME} ${LDFLAGS} + ${CXX} ${CFLAGS} -c ${NAME}.cpp -o ${NAME}.o + ${CXX} ${NAME}.o -o ${NAME} ${LDFLAGS} install: ln -sf "$(shell pwd)/3mfthumb" ~/.local/bin/ cp -lf 3mf.thumbnailer /home/k/.local/share/thumbnailers/ - rm -rf ~/.cache/thumbnails + rm -rf ~/.cache/thumbnails clean: rm -f *.o ${NAME} diff --git a/README.md b/README.md index 15dc586..69a1dfd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # 3mfthumbail -Extract thumbnail images from 3MF files. +Extract thumbnail images from 3MF files and display them in file managers. + +Preview images are great. As .3mf is supposed to be the universal 3D Printing standard, and adoption is expected to be rapid, we should be able to see embedded thumbnail image previews for them in file managers like `pcmanfm`, `nautilus`, or even Windows `explorer`. ![preview](preview.png) @@ -29,6 +31,8 @@ make make install ``` +Configure your file manager preferences to show previews for files > 1MB. + ## Developer logic The current version of the Lib3MF API uses the lib3mf_implicit.hpp header file instead of Lib3MF_Resources.hpp. This newer API provides a more simplified interface for working with the Lib3MF library. @@ -38,9 +42,52 @@ This code uses the CWrapper::loadLibrary() method to load the Lib3MF library and The `Makefile` uses `pkg-config --cflags --libs lib3mf` to obtain the compiler flags to use. If for some reason your system does not have pkg-config, you might be able to substitute these into the `Makefile`. `-I/usr/include/lib3mf -l3mf -lzip -lz` +## Cross compiling to Windows + +To cross compile to Windows, you must first install dependencies. Use +the package manager to install `mingw64-gcc-g++`, `mingw64-zlib`, and +`mingw64-libzip`. Now we need the `lib3mf.dll`. We got ours from https://github.com/3MFConsortium/lib3mf/releases like so. + +``` +wget https://github.com/3MFConsortium/lib3mf/releases/download/v2.2.0/lib3mf_sdk_v2.2.0.zip +unzip lib3mf_sdk_v2.2.0.zip +``` + +Now we can use `mingw64-make` to build the windows executable, `emfthumb.exe`. Set LIBS to the location of the extracted lib3mf/Lib dir, which should already contain a precompiled library `lib3mf.dll`. + +``` +LIBS=-L/home/k/Downloads/src/lib3mf/Lib mingw64-make +``` + +Now copy the resulting `3mfthumb.exe` along with `lib3mf.dll` to the Windows machine. + +Thumbnailers can be configured on Windows using the registry editor, `regedit`. + +Yes, you can set your thumbnail image extractor to be the default thumbnail image generator for .3mf files in Windows by creating a registry entry that associates your program with the .3mf file extension. + +Here are the steps you can follow to create this registry entry: + +1. Open the Windows Registry Editor by typing "regedit" in the Start menu search box and pressing Enter. + +2. Navigate to the following registry key: HKEY_CLASSES_ROOT\.3mf + +3. If there is no "Default" value in this key, create one by right-clicking on the right-hand pane, selecting "New > String Value", and naming the value "Default". + +4. Set the value of the "Default" key to a unique name for your thumbnail generator, such as "3mfthumb.exe". + +5. Navigate to the following registry key: `HKEY_CLASSES_ROOT\MyThumbnailGenerator\shell\open\command` + +6. Create a new "String Value" named "Default" in the right-hand pane and set its value to the path to `3mfthumb.exe`, followed by the "%1" parameter to pass the filename of the .3mf file being opened. For example: + +7. "C:\3mfthumb.exe" "%1" + +8. Save and close the Registry Editor. + +After making these changes, Windows should use `3mfthumb.exe` to generate thumbnails for `.3mf` files when they are viewed in Explorer or other file managers on Windows. + ## Issues -We are new to C++ development, so there are bound to be some problems. +We are new to C++ development, so there are bound to be some problems. Image previews have not been tested on Windows yet. But we're working on it. Discuss issues on the [GitHub issue tracker](https://github.com/themanyone/3mfthumb/issues). Copyright (C) 2023 Henry Kroll III, www.thenerdshow.com. See [LICENSE](LICENSE) for details. \ No newline at end of file