Skip to content

pre release 1.0.0 #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 52 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
2f6708a
Make the node system polymorphic
May 16, 2024
bf0fba5
Adapt the loader for new MIME nodes
May 17, 2024
c0dec97
Исправь дублирование сообщения в результате
pavel-cpp May 18, 2024
c6750f4
Fix duplicate message as a result
pavel-cpp May 18, 2024
557280f
Merge remote-tracking branch 'origin/dev' into dev
pavel-cpp May 18, 2024
a7b7519
Add simple expressions support
pavel-cpp May 20, 2024
fdf1160
Add non case sensitive string support
pavel-cpp May 21, 2024
615995d
Add exceptions
May 21, 2024
1b958c3
Fix invalid operators on string and date
May 21, 2024
da37769
Small fixes
May 21, 2024
a3e9f13
Fix initializer list bug
pavel-cpp May 21, 2024
b133adf
Настрой систему сборки для библиотеки
pavel-cpp May 21, 2024
16f303f
Настрой систему сборки для примера
pavel-cpp May 21, 2024
6153a9f
Merge pull request #8 from pavel-cpp/main
pavel-cpp May 21, 2024
ce8ef65
Set up the build system for example
pavel-cpp May 21, 2024
44eafbc
Merge remote-tracking branch 'origin/dev' into dev
pavel-cpp May 21, 2024
a090a18
Set up the build system for the library
pavel-cpp May 21, 2024
0e937f0
Set up the build system for example
pavel-cpp May 21, 2024
efd436d
Merge remote-tracking branch 'origin/dev' into dev
pavel-cpp May 21, 2024
86753b6
Add tests
pavel-cpp May 22, 2024
b5b5f03
Create cmake-single-platform.yml
pavel-cpp May 22, 2024
08d948d
Update cmake-single-platform.yml
pavel-cpp May 22, 2024
4ac85ac
Update cmake-single-platform.yml
pavel-cpp May 22, 2024
a0ba8ad
Update cmake-single-platform.yml
pavel-cpp May 22, 2024
6445fa0
Fix bootstrap.bat
pavel-cpp May 22, 2024
766ea00
Merge remote-tracking branch 'origin/dev' into dev
pavel-cpp May 22, 2024
bb413af
Fix tests return value
pavel-cpp May 22, 2024
3cf8b13
Update cmake-single-platform.yml
pavel-cpp May 22, 2024
94ac41b
Update cmake-single-platform.yml
pavel-cpp May 22, 2024
c463448
Update cmake-single-platform.yml
pavel-cpp May 22, 2024
845f004
Separate the implementation and declaration of the node number
pavel-cpp May 23, 2024
94c9661
Merge remote-tracking branch 'origin/dev' into dev
pavel-cpp May 23, 2024
421ca1d
Update workflow
pavel-cpp May 23, 2024
870345d
Update workflow
pavel-cpp May 23, 2024
3b85af0
Update workflow
pavel-cpp May 23, 2024
26cda23
Update workflow
pavel-cpp May 23, 2024
686014c
Update workflow
pavel-cpp May 23, 2024
6e79001
Fix compiling errors for msvc2019
pavel-cpp May 23, 2024
1d64f6e
Update workflow add msvc2019 dependency
pavel-cpp May 23, 2024
7fbc0d0
Update workflow add msvc2019 dependency
pavel-cpp May 23, 2024
5276a64
Update workflow fixing msvc download
pavel-cpp May 23, 2024
a2ab3d5
Update workflow fixing msvc download
pavel-cpp May 23, 2024
0cb5cde
Fix msvc compiling error
pavel-cpp May 24, 2024
aacb48a
Fix msvc compiling error in windows tests
pavel-cpp May 24, 2024
ae6b6f5
Fix msvc compiling error in windows build
pavel-cpp May 24, 2024
bf7abc7
Fix msvc compiling error in windows build
pavel-cpp May 24, 2024
9b59750
Fix target naming
pavel-cpp Jun 11, 2024
4ad6718
Fix octal numbers parsing
pavel-cpp Jun 11, 2024
21df233
Update README
pavel-cpp Jun 11, 2024
64bfd47
Update README
pavel-cpp Jun 11, 2024
f54fecf
Update README
pavel-cpp Jun 11, 2024
9c13734
Fix configuring widows tests
pavel-cpp Jun 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 153 additions & 0 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
name: CMake Multi-Platform

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
BUILD_TYPE: Release

jobs:
build-ubuntu:
runs-on: ubuntu-latest
strategy:
matrix:
compiler: [gcc, clang]

steps:
- uses: actions/checkout@v4

- name: Set up compiler
run: |
if [ "${{ matrix.compiler }}" == "gcc" ]; then
sudo apt-get update
sudo apt-get install -y g++
elif [ "${{ matrix.compiler }}" == "clang" ]; then
sudo apt-get update
sudo apt-get install -y clang
fi
shell: bash

- name: Configure CMake
run: cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -B build
shell: bash

- name: Build with CMake
run: cmake --build build
shell: bash

- name: Install Library
run: cmake --install build --prefix ${{ github.workspace }}/mime_magic
shell: bash

- name: Upload Build Artifacts
uses: actions/upload-artifact@v3
with:
name: build-artifacts-ubuntu-${{ matrix.compiler }}
path: ${{ github.workspace }}/mime_magic

test-ubuntu:
runs-on: ubuntu-latest
needs: build-ubuntu
strategy:
matrix:
compiler: [gcc, clang]

steps:
- uses: actions/checkout@v4

- name: Download Build Artifacts
uses: actions/download-artifact@v3
with:
name: build-artifacts-ubuntu-${{ matrix.compiler }}
path: ${{ github.workspace }}/mime_magic

- name: Configure Tests
working-directory: ${{ github.workspace }}/tests
run: cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -B build
shell: bash

- name: Build Tests
working-directory: ${{ github.workspace }}/tests
run: cmake --build build
shell: bash

- name: Run Tests
working-directory: ${{ github.workspace }}/tests/build
run: ./tests
shell: bash

build-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4

- name: Set up MSBuild
uses: microsoft/[email protected]

- name: Install Visual Studio Build Tools
run: |
choco install visualstudio2019buildtools --package-parameters "--add Microsoft.VisualStudio.Workload.VCTools --includeRecommended --includeOptional --quiet --norestart"
shell: cmd

- name: Configure CMake
run: cmake -G "Visual Studio 16 2019" -B ${{ github.workspace }}/build
shell: cmd

- name: Build with CMake
run: cmake --build ${{ github.workspace }}/build --config ${{ env.BUILD_TYPE }}
shell: cmd

- name: Install Library
run: cmake --install ${{ github.workspace }}/build --config ${{ env.BUILD_TYPE }} --prefix ${{ github.workspace }}/mime_magic
shell: cmd

- name: Upload Build Artifacts
uses: actions/upload-artifact@v3
with:
name: build-artifacts-windows
path: ${{ github.workspace }}/mime_magic

test-windows:
runs-on: windows-latest
needs: build-windows
steps:
- uses: actions/checkout@v4

- name: Download Build Artifacts
uses: actions/download-artifact@v3
with:
name: build-artifacts-windows
path: ${{ github.workspace }}/mime_magic

- name: Configure Tests
working-directory: ${{ github.workspace }}/tests
run: cmake -G "Visual Studio 16 2019" -B build
shell: cmd

- name: Build Tests
working-directory: ${{ github.workspace }}/tests
run: cmake --build build --config ${{ env.BUILD_TYPE }}
shell: cmd

- name: Run Tests
working-directory: ${{ github.workspace }}/tests/build
run: ./tests
shell: cmd

send_message:
runs-on: ubuntu-latest
needs: [test-ubuntu, test-windows]
steps:
- name: Send telegram message
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
message: |
mime_magic ready to merge
Выполнил: ${{ github.actor }}
Сообщение коммита: ${{ github.event.commits[0].message }}
Ссылка на коммит: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
57 changes: 39 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,47 @@
cmake_minimum_required(VERSION 3.23)
project(mime_magic)
project(mime_magic VERSION 1.0.1 LANGUAGES CXX)

include_directories(
src
src/loader
srd/node
add_subdirectory(src)

add_custom_target(copy_docs
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/docs ${CMAKE_BINARY_DIR}/docs
COMMENT "Copying documentation"
)

add_custom_target(copy_examples
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/examples ${CMAKE_BINARY_DIR}/examples
COMMENT "Copying examples"
)

add_dependencies(${PROJECT_NAME}_shared copy_docs)
add_dependencies(${PROJECT_NAME}_shared copy_examples)
add_dependencies(${PROJECT_NAME}_static copy_docs)
add_dependencies(${PROJECT_NAME}_static copy_examples)

# Создание и установка конфигурационных файлов
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

add_library(
${PROJECT_NAME}
STATIC
src/node/mime_node.cpp
src/loader/mime_loader.cpp
configure_file(src/mime_magicConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
@ONLY
)

add_executable(
${PROJECT_NAME}_test
test/main.cpp
install(DIRECTORY ${CMAKE_BINARY_DIR}/docs DESTINATION ./)
install(DIRECTORY ${CMAKE_BINARY_DIR}/examples DESTINATION ./)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION lib/cmake/${PROJECT_NAME}
)

target_link_libraries(
${PROJECT_NAME}_test
PUBLIC
${PROJECT_NAME}
)
install(EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION lib/cmake/${PROJECT_NAME}
)
42 changes: 40 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
# cpp-mime-magic
A MIME magic parser for identifying file types.
# MIME Magic

## Overview
MIME magic is a cross-platform library that
is an implementation of the standard
and has a number of differences from the standard,
designed for parsing and executing magic files.

## Deployment
To deploy the library you need
follow these steps:

### Configure project
In the below command you are free to change CMAKE_BUILD_TYPE
if you want to configure the Debug version
and the build directory to your own.
```shell
cmake -DCMAKE_BUILD_TYPE=Release -B cmake_build_release
```
> [!IMPORTANT]
> If you are building a library for msbuild
> specifying BUILD_TYPE is not necessary.
###Building the project
```shell
Use the command below to build the library.
You can change the build directory.
cmake --build cmake_build_release
```
> [!IMPORTANT]
> If you are building a library for msbuild
> add `--config {BUILD_TYPE}`

### Installing the library
Use below command
```shell
cmake --install ./build --prefix ./mime_magic
```
> [!IMPORTANT]
> If you are building a library for msbuild
> add `--config {BUILD_TYPE}`
22 changes: 22 additions & 0 deletions bootstrap.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@echo off

REM Check if the installation path argument is passed
if "%~1"=="" (
set /p INSTALLATION_PATH="Enter the installation path (for example, C:\Program Files\MyApp): "
) else (
set INSTALLATION_PATH=%~1
)

REM Create a build directory
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -S . -B build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -S . -B build

REM Putting the project together
cmake --build build

REM Install the project
cmake --install build --prefix %INSTALLATION_PATH%

rmdir /s /q build

pause
12 changes: 12 additions & 0 deletions examples/basic_project/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.23)
project(test LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)

set(CMAKE_PREFIX_PATH ..\\mime_magic\\lib\\cmake\\MimeMagic)

find_package(MimeMagic REQUIRED)

add_executable(${PROJECT_NAME} main.cpp)

target_link_libraries(${PROJECT_NAME} MimeMagic::MimeMagic_static)
84 changes: 84 additions & 0 deletions examples/basic_project/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include <fstream>
#include <iostream>
#include <locale>
#include <vector>
#include <chrono>

#include "loader/mime_loader.h"

class Timer {
public:
Timer() {
start = std::chrono::high_resolution_clock::now();
}

~Timer() {
auto end = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
std::cout << "Time taken: " << duration.count() << " ms" << std::endl;
}

private:
std::chrono::time_point<std::chrono::high_resolution_clock> start;
};

int main() {
using namespace std;
boolalpha(cout);
system("chcp 1251");

magic::mime_list nodes;
// You can check how it fast
// {
// Timer t;
// nodes = std::move(magic::load("C:\\Sophus-NEW\\modules\\files.etl"));
// }

nodes = magic::load("magic.etl");

cout << nodes.size() << " node workers SUCCESSFULLY LOADED!" << endl;

vector<char> data;
data.resize(30);

{
ifstream png("image.png", ios::in | ios::binary);
png.read(data.data(), data.size());

cout << "PNG" << endl;
cout << std::string(80, '=') << endl << endl;
int i = 1;
for (const auto& node: nodes) {
auto response = node->process_data(data.data(), data.size());
if (response.has_value()) {
cout << dec << i << hex << ")\n" << response.value() << endl;
cout << endl << std::string(80, '=') << endl << endl;
break;
}
++i;
}
}
data.clear();
data.shrink_to_fit();
data.resize(30);

{
ifstream corrupt_png("corrupted-image.png", ios::in | ios::binary);
corrupt_png.read(data.data(), data.size());

cout << "CORRUPT PNG" << endl;
cout << std::string(80, '=') << endl << endl;
size_t i = 1;
for (const auto& node: nodes) {
auto response = node->process_data(data.data(), data.size());
if (response.has_value()) {
cout << dec << i << hex << ")\n" << response.value() << endl;
cout << endl << std::string(80, '=') << endl << endl;
break;
}
++i;
}
}

return 0;
}
Loading
Loading