Skip to content

Commit

Permalink
windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
themanyone committed May 7, 2023
1 parent 02eb28d commit cd25c9b
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 12 deletions.
Binary file modified 3mfthumb
Binary file not shown.
23 changes: 18 additions & 5 deletions 3mfthumb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,40 @@
/// MA 02110-1301, USA.

#include <iostream>
#ifdef WIN32
#include <filesystem>
#endif
#include "lib3mf_implicit.hpp"

int main(int argc, char **argv) {
if (argc < 3){
if (argc < 2){
std::cout << "Usage: 3mfthumb <file.3mf> <output.png>" << 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");
reader->ReadFromFile(filename);
// 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);
}
Expand Down
Binary file removed 3mfthumb.o
Binary file not shown.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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}
51 changes: 49 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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.
Expand All @@ -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.

0 comments on commit cd25c9b

Please sign in to comment.