Ship tera templates in a crate without embedding them into the binary - templates

I am using tera and want to make a CLI that acts as a new project generator (think rails scaffold). There will be quite a few templates and I would like to ship them in my crate as an asset file and read from disk instead of using include_str! and embedding the strings directly in the resulting binary.
Are there any crates that use this strategy that I could maybe reference? Is it possible to ship non-rust assets in a crate and have the referenced on disk later?

Related

Using the UE4 headers/classes in a separate C++ project without the editor

I'm working on a C++ .dll plugin that gets passed UE4 classes like FName, UClass, FPlatformTime, etc for a game that I do not have the source code of. I would like to access the passed objects and view/modify their class members in my plugin.
Adding UnrealEngine\UE_4.25\Engine\Source\Runtime\Core\Public as additional include directory and then including #include "UObject/NameTypes.h" in my source file results in a seemingly endless amount of missing defines in headers like Build.h, Platform.h.
What is the correct way to include the UE4 classes in a simple Visual Studio C++ project without using the editor?
I've compiled a small UE4 project and I'm currently using the UE4 class headers extracted from its .pdb as the output is simple enough but I'd like to use the proper UE4 headers.
Inside the UE4 solution, take a look at various programs, such as "BlankProgram" and "SlateViewer". These use UE4 modules and are built using UnrealBuildTool, but you could create your own program and only link to the UE4 modules that you need. This will effectively let you create a lightweight program without unneeded stuff such as UMG or media players, for example.
One downside to this is that, due to how UnrealBuildTool works, your program must reside inside the engine's "Source/Programs" folder and follow a simple, but non-negotiable template (i.e. it needs to have a <YourProgram.Target.cs> file where its type is set to "Program").
Best of luck!
Unreal Engine types are meant to be used with Unreal Engine, they are not designed to be used in a pure C++ project outside of the Unreal Engine ecosystem.

Is it possible to convert a .Sketch file to an .SVG?

Is it possible to convert a Sketch file to an SVG without actually having Sketch or DrawIt? I know it's theoretically possible since they're both vector, but I use Windows and Linux, so I don't have a Mac to open the files with.
Figma is currently free for anyone to sign up and supports both Sketch import and SVG export. It's a fully-featured design tool that's browser-based so it should work on all three major platforms (OS X, Windows, and Linux). File import from Sketch isn't a perfect 1-to-1 mapping with Figma because both apps have slightly different feature sets, but it should get you 99% of the way there.
There's no "magic" about "Sketch using a lot of technology that is exclusive to OS X" or not. That statement on Sketch makers' website is in the context that they do not intend to make Sketch app available on linux and on windows.
The real problem you have is as follows:-
The sketch file is an sqlite3 file and in it there are (currently at this time of writing) two tables, meta and payload. The payload table is a single key-value store, storing main and and BLOB value. So that's where you get stuck - you will have to figure out how to reverse engineer the BLOB if you do not have a Sketch program.
On the other hand, if you do have a Sketch program, you do not need to reverse engineer anything, you can query information from your Sketch file using Sketch Plugin APIs, which are well documented here - http://bohemiancoding.com/sketch/support/developer/ - which will allow you to automate a lot of the tasks if you have a complicated design workflow. http://zeplin.io is an example of a simple Sketch plugin that pulls out relevant "spec" information for a developer from a designer-created sketch artboard.
But back to your original question, Sketch itself allows you to export SVG files but that assumes you have the Sketch app. Long story short, unless you reverse engineer the BLOB binary in the sketch file (or use a tool that someone else created that can), you can't programmatically translate sketch files into SVG files without having a Sketch app.

How to embed resources into a single executable?

If you've ever used the tool Game Maker, it's a bit like that. I want to be able to take all my sounds, images, and everything else of the like and embed them into a single C++ executable. Game Maker would have a built-in editor, and would have the images embedded into the .gmk file, and when you'd open it it would read the images, and display them in the game. I'm thinking he had the images saved not as images, but as pure data stored in the .gmk file and interpreted by the editor or by some interpreter written into the .exe. How would I go about making something similar?
The windows resource system works like this, so if you make a WinAPI or MFC application, you can use this. Also, Qt provides the same functionality, but in a platform independent way. They just write the files in raw binary format into a byte array in a normal C++ file, so they get compiled as data into the exe. Then they provide functions for accessing these data blocks like normal files, although I don't know how they really work. Probably a special implementation of their file class which just accesses those byte array variables.
For images only, a very simple approach is to use the XPM format.
This format is a valid C/C++ header, so you can include it directly into a C++ source file and use it directly.
The main issue with this approach is that XPM is not a compressed format, so uses a lot of storage.
In consequence, in practice I only seen this used for icons and small graphical objects, but in principle you could do more.
The other cool thing about XPM is that it's human readable - again great for designing small and simple icons.
To generalize this idea to other formats, what you could do is to create a compile chain that:
Encodes the target file as ASCII (Uuencode or such)
Turns that into a single named C String in a source file.
Create a header just declaring the name
Define a function recovering the binary form from the string
For the Windows OS I have a solution if you are willing to use another tool and possibly framework. Try the "peresembed" tool. It embeds files into PE image sections so you can have all your images, sounds and configuration files in just one EXE file. Supports compression too, although you do need a ZIP in-memory reading framework then. Can even embed files into the PE resource tree based on their relative file paths.
Example usage:
peresembed -file content.txt _export_to_resolve input.exe output.exe
In your C++ file you have:
struct embedded_data
{
void *dataloc;
size_t datasize;
};
extern "C" __declspec(dllexport) const volatile embedded_data _export_to_resolve = { 0 };
Get peresembed from: https://osdn.net/projects/pefrm-units/releases/70746
Showcase video: https://www.youtube.com/watch?v=1uYdjiZc5XI

C++ file container (e.g. zip) for easy access

I have a lot of small files I need to ship with an application I build and I want to put this files into an archive to make copying and redistributing more easy.
I also really like the idea of having them all in one place so I need to compare the md5 of one file only in case something goes wrong.
I'm thinking about a class which can load the archive and return a list of files within the archive and load a file into memory if I need to access it.
I already searched the Internet for different methods of achieving what I want and found out about zlib and the lzma sdk.
Both didn't really appeal to me because I don't really found out how portable zlib is and I didn't like the lzma sdk as it is just to much and I don't want to blow up the application because of this problem. Another downside with zlib is that I don't have the C/C++ experience (I'm really new to C++) to get everything explained in the manual.
I also have to add that this is a time critical problem. I though some time about implementing a simple format like tar in a way I can easy access the files within my application but I just didn't find the time to do that yet.
So what I'm searching for is a library that allows me to access the files within an archive. I'd be glad if anybody could point me in the right direction here.
Thanks in advance,
Robin.
Edit: I need the archive to be accessed under linux and windows. Sorry I didn't mention that in the beginning.
For zipping, I've always been partial to ZipUtils, which makes the process easy and is built on top of the zlib and info-zip libraries.
The answer depends on whether you plan to modify the archive via code after the archive is initially built.
If you don't need to modify it, you can use TAR - it's a handy and simple format. If you want compression, you can implement tar.gz reader or find some library that does this (I believe there are some available, including open-source ones).
If your application needs random access to the data or it needs to modify the archive, then regular TAR or ZIP archives are not good. Virtual file system such as our SolFS or CodeBase file system will fit much better: virtual file systems are suited for frequent modifications of the storage, while archives target mainly write-once-read-many usage scenarios.
zlib is highly portable and very widely used. if you can't make sense of the C++ interface, there are alternatives for many other languages - see 'Related External Links' here.
Take another look before you search for something different.
If you're using Qt or Windows you can also pack data into the executable's resource area. You would only have to distribute the executable file using this technique. There's a well defined API already written and tested to access that data.
The zlib API is the way to go. Simple and portable. Lookat unzip.h header for APIs that access archive files. It is in C and very easy.
If the files are small, you can dump them into string literals (search for bin2h utility) and include in your project. Then change the code that read the files. If all files are currently read using ifstream class, simply changing it to istringstream class and recompile the code.
Try using Quazip - it's quite simple to use. You can use it as a stream from which you read the compressed file on the fly.

xsd-based code generator to build xml?

I have a schema (xsd), and I want to create xml files that conform to it.
I've found code generators that generate classes which can be loaded from an xml file (CodeSynthesis). But I'm looking to go the other direction.
I want to generate code that will let me build an object which can easily be written out as an xml file. In C++. I might be able to use Java for this, but C++ would be preferable. I'm on solaris, so a VisualStudio plugin won't help me (such as xsd2code).
Is there a code generator that lets me do this?
To close this out: I did wind up using CodeSynthesis. It worked very well, as long as I used a single xsd as its source. Since I actually had two xsds (one imported the other), I had to manually merge them (they did some weird inheritance that needed manual massaging).
But yes, Code Synthesis was the way to go.