# Dehydrate

## Installation

Automated system-wide installation:
```
curl -fsSL https://gitea.jde.nz/public/dehydrate/releases/download/latest/install.sh | bash
```
To download just the dehydrate executable:
```
curl -fsSL -o dehydrate https://gitea.jde.nz/public/dehydrate/releases/download/latest/dehydrate.amd64 && chmod a+x bb64
```

## How it Works


Given a source file or folder, creates c++ code to recreate that file/folder.
If it's a folder, it recreates the entire tree (all subfolders and files within).

Use:
```
Usage:
    dehydrate [-s] SOURCEFILE DESTFOLDER      Creates _SOURCEFILE.CPP and _SOURCEFILE.HPP in DESTFOLDER
    dehydrate [-s] SOURCEFOLDER DESTFOLDER    Creates _SOURCEFOLDER.CPP and _SOURCEFOLDER.HPP in DESTFOLDER

    -s = silent (no output)
```

All c++ code produced is in namespace `recreate_{SOURCEFILE|SOURCEFOLDER}`

When the source is a file, the C++ function created is:
```
    bool recreate_file(std::string destination_folder);
```
The path is the full path to the destination folder, excluding the filename. The original filename is used.
If a file exists at that location:
   The hash of the content is compared, and the file is overwritten if the hash is different, otherwise
   left unchanged.
If there is no file:
   SOURCEFILE is written in destination_folder.


When the source is a folder, the C++ function created is:
```
    bool recreate_tree(std::string destination_folder);
```
The destination_folder (and any needed subfolders) are created if they don't exist. 
The contents of the original SOURCEFOLDER are recreated inside destination_folder, 
overwriting any existing content in that folder if the hash of the individual file 
is different than existing content, or if the file doesn't exist.

In both cases, unless in silent mode, confirmation is displayed for each file, showing
the existing and new hash, and whether the file was updated or not.
