Initial commit
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
* Copyright (c) 2016 tomykaira
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace macaron {
|
||||
class Base64 {
|
||||
public:
|
||||
static std::string Encode(const char* data, size_t length) {
|
||||
static constexpr char sEncodingTable[] = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
||||
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
|
||||
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
||||
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
|
||||
'w', 'x', 'y', 'z', '0', '1', '2', '3',
|
||||
'4', '5', '6', '7', '8', '9', '+', '/'
|
||||
};
|
||||
|
||||
size_t out_len = 4 * ((length + 2) / 3);
|
||||
std::string ret(out_len, '\0');
|
||||
size_t i;
|
||||
char* p = const_cast<char*>(ret.c_str());
|
||||
|
||||
for (i = 0; i < length - 2; i += 3) {
|
||||
*p++ = sEncodingTable[(data[i] >> 2) & 0x3F];
|
||||
*p++ = sEncodingTable[((data[i] & 0x3) << 4) | ((int)(data[i + 1] & 0xF0) >> 4)];
|
||||
*p++ = sEncodingTable[((data[i + 1] & 0xF) << 2) | ((int)(data[i + 2] & 0xC0) >> 6)];
|
||||
*p++ = sEncodingTable[data[i + 2] & 0x3F];
|
||||
}
|
||||
if (i < length) {
|
||||
*p++ = sEncodingTable[(data[i] >> 2) & 0x3F];
|
||||
if (i == (length - 1)) {
|
||||
*p++ = sEncodingTable[((data[i] & 0x3) << 4)];
|
||||
*p++ = '=';
|
||||
}
|
||||
else {
|
||||
*p++ = sEncodingTable[((data[i] & 0x3) << 4) | ((int)(data[i + 1] & 0xF0) >> 4)];
|
||||
*p++ = sEncodingTable[((data[i + 1] & 0xF) << 2)];
|
||||
}
|
||||
*p++ = '=';
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
#include <MSFS\MSFS.h>
|
||||
#include <MSFS\Legacy\gauges.h>
|
||||
#include <MSFS\MSFS_CommBus.h>
|
||||
|
||||
#include "rapidjson/document.h"
|
||||
#include "rapidjson/stringbuffer.h"
|
||||
#include "rapidjson/writer.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iterator>
|
||||
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "Base64.hpp"
|
||||
#include "Module.h"
|
||||
|
||||
#define COMMANDS "KHOFMANN_PDF_READER_COMMANDS"
|
||||
#define DATA "KHOFMANN_PDF_READER_DATA"
|
||||
|
||||
FILE* logFile;
|
||||
|
||||
static void CommandWasmCallback(const char* args, unsigned int size, void* ctx);
|
||||
void log(FILE *file, const char *format, void* optionalElement = NULL);
|
||||
std::string readFile(const char* path);
|
||||
|
||||
extern "C" MSFS_CALLBACK void module_init(void)
|
||||
{
|
||||
log(stdout, "[PDF-Reader Module] Starting init\n");
|
||||
|
||||
logFile = fopen("\\work\\log.txt", "w");
|
||||
if (logFile == NULL)
|
||||
{
|
||||
log(stderr, "[PDF-Reader Module] Error creating logfile\n");
|
||||
}
|
||||
|
||||
if (!fsCommBusRegister(COMMANDS, CommandWasmCallback))
|
||||
{
|
||||
log(stderr, "[PDF-Reader Module] Error registering command CommBus\n");
|
||||
}
|
||||
|
||||
log(stdout, "[PDF-Reader Module] Inited\n");
|
||||
}
|
||||
|
||||
extern "C" MSFS_CALLBACK void module_deinit(void)
|
||||
{
|
||||
log(stdout, "[PDF-Reader Module] Starting deinit\n");
|
||||
|
||||
int c = fsCommBusUnregister(COMMANDS, CommandWasmCallback);
|
||||
log(stdout, "%i unregistered", &c);
|
||||
|
||||
log(stdout, "[PDF-Reader Module] Deinited\n");
|
||||
}
|
||||
|
||||
static void CommandWasmCallback(const char* args, unsigned int size, void* ctx)
|
||||
{
|
||||
if (strcmp(args, "LIST") == 0)
|
||||
{
|
||||
rapidjson::Document jsonDoc;
|
||||
rapidjson::Document::AllocatorType& allocator = jsonDoc.GetAllocator();
|
||||
|
||||
jsonDoc.SetObject();
|
||||
jsonDoc.AddMember("id", "LIST", allocator);
|
||||
|
||||
rapidjson::Value files;
|
||||
files.SetArray();
|
||||
|
||||
DIR* d;
|
||||
struct dirent* dir;
|
||||
d = opendir("\\work\\Files");
|
||||
if (d)
|
||||
{
|
||||
log(stdout, "Found files:\n");
|
||||
while ((dir = readdir(d)) != NULL)
|
||||
{
|
||||
if (dir->d_type == DT_DIR && strcmp(dir->d_name, ".") && strcmp(dir->d_name, ".."))
|
||||
{
|
||||
log(stdout, "%s\n", dir->d_name);
|
||||
|
||||
std::string path("\\work\\Files\\");
|
||||
path += dir->d_name;
|
||||
|
||||
int count = 0;
|
||||
DIR* s;
|
||||
struct dirent* dir_s;
|
||||
s = opendir(path.c_str());
|
||||
if (s)
|
||||
{
|
||||
while ((dir_s = readdir(s)) != NULL)
|
||||
{
|
||||
if (dir_s->d_type == DT_REG)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
closedir(s);
|
||||
|
||||
std::string thumb(dir->d_name);
|
||||
thumb += "\\thumb.png";
|
||||
|
||||
rapidjson::Value name(dir->d_name, allocator);
|
||||
rapidjson::Value _thumb(readFile(thumb.c_str()).c_str(), allocator);
|
||||
|
||||
rapidjson::Value entry;
|
||||
entry.SetObject();
|
||||
entry.AddMember("name", name.Move(), allocator);
|
||||
entry.AddMember("thumb", _thumb.Move(), allocator);
|
||||
entry.AddMember("pages", count - 1, allocator);
|
||||
|
||||
files.PushBack(entry.Move(), allocator);
|
||||
}
|
||||
}
|
||||
|
||||
jsonDoc.AddMember("data", files, allocator);
|
||||
|
||||
rapidjson::StringBuffer strbuf;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer(strbuf);
|
||||
jsonDoc.Accept(writer);
|
||||
|
||||
fsCommBusCall(DATA, strbuf.GetString(), strbuf.GetSize(), FsCommBusBroadcast_JS);
|
||||
|
||||
closedir(d);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rapidjson::Document inDoc;
|
||||
inDoc.Parse(args);
|
||||
|
||||
const char* cmd = inDoc["cmd"].GetString();
|
||||
|
||||
if (strcmp(cmd, "LOAD") == 0) {
|
||||
const char* data = inDoc["file"].GetString();
|
||||
|
||||
log(stdout, "Loading file %s\n", (void*)data);
|
||||
|
||||
rapidjson::Document outDoc;
|
||||
rapidjson::Document::AllocatorType& allocator = outDoc.GetAllocator();
|
||||
|
||||
outDoc.SetObject();
|
||||
outDoc.AddMember("id", "LOAD", allocator);
|
||||
outDoc.AddMember("data", rapidjson::Value(readFile(data).c_str(), allocator).Move(), allocator);
|
||||
|
||||
rapidjson::StringBuffer strbuf;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer(strbuf);
|
||||
outDoc.Accept(writer);
|
||||
|
||||
fsCommBusCall(DATA, strbuf.GetString(), strbuf.GetSize(), FsCommBusBroadcast_JS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string readFile(const char* path)
|
||||
{
|
||||
std::string _path;
|
||||
_path += "\\work\\Files\\";
|
||||
_path += path;
|
||||
|
||||
FILE* file = fopen(_path.c_str(), "r");
|
||||
if (file) {
|
||||
fseek(file, 0, SEEK_END);
|
||||
long fsize = ftell(file);
|
||||
fseek(file, 0, SEEK_SET); /* same as rewind(f); */
|
||||
|
||||
char* string = (char*)calloc(sizeof(char), fsize + 1);
|
||||
fread(string, fsize, 1, file);
|
||||
fclose(file);
|
||||
|
||||
return macaron::Base64::Encode(string, fsize);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
void log(FILE* file, const char* format, void* optionalElement)
|
||||
{
|
||||
if (logFile != NULL)
|
||||
{
|
||||
fprintf(logFile, format, optionalElement);
|
||||
fflush(logFile);
|
||||
}
|
||||
fprintf(file, format, optionalElement);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
#pragma once
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.29806.167
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PDF-Reader", "PDF-Reader.vcxproj", "{691392AC-AECF-4197-8F7F-37B7AEB41D4B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|MSFS = Debug|MSFS
|
||||
Release|MSFS = Release|MSFS
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{691392AC-AECF-4197-8F7F-37B7AEB41D4B}.Debug|MSFS.ActiveCfg = Debug|MSFS
|
||||
{691392AC-AECF-4197-8F7F-37B7AEB41D4B}.Debug|MSFS.Build.0 = Debug|MSFS
|
||||
{691392AC-AECF-4197-8F7F-37B7AEB41D4B}.Release|MSFS.ActiveCfg = Release|MSFS
|
||||
{691392AC-AECF-4197-8F7F-37B7AEB41D4B}.Release|MSFS.Build.0 = Release|MSFS
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {C85F0220-E6FA-45B8-AA53-16165653C28C}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,127 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|MSFS">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>MSFS</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|MSFS">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>MSFS</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{691392AC-AECF-4197-8F7F-37B7AEB41D4B}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>PDF-Reader</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
<ProjectName>PDF-Reader</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|MSFS'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>MSFS</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|MSFS'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>MSFS</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|MSFS'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|MSFS'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|MSFS'">
|
||||
<TargetName>$(ProjectName)</TargetName>
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<TargetExt>.wasm</TargetExt>
|
||||
<IncludePath>$(MSFS_IncludePath)</IncludePath>
|
||||
<OutDir>$(SolutionDir)$(Platform)\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|MSFS'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<TargetExt>.wasm</TargetExt>
|
||||
<IncludePath>$(MSFS_IncludePath)</IncludePath>
|
||||
<OutDir>$(SolutionDir)$(Platform)\</OutDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|MSFS'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>
|
||||
_DEBUG;_MSFS_WASM;_STRING_H_CPLUSPLUS_98_CONFORMANCE_;_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_;_LIBCPP_NO_EXCEPTIONS;_LIBCPP_HAS_NO_THREADS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>
|
||||
</AdditionalIncludeDirectories>
|
||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||
<ExceptionHandling>false</ExceptionHandling>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<SupportJustMyCode />
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<LanguageStandard>stdcpp14</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<NoEntryPoint>true</NoEntryPoint>
|
||||
<OutputFile>$(OutDir)$(TargetName)-$(Configuration)$(TargetExt)</OutputFile>
|
||||
</Link>
|
||||
<PostBuildEvent />
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|MSFS'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>
|
||||
NDEBUG;_MSFS_WASM;_STRING_H_CPLUSPLUS_98_CONFORMANCE_;_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_;_LIBCPP_NO_EXCEPTIONS;_LIBCPP_HAS_NO_THREADS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>
|
||||
</AdditionalIncludeDirectories>
|
||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||
<ExceptionHandling>false</ExceptionHandling>
|
||||
<DebugInformationFormat />
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<LanguageStandard>stdcpp14</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<NoEntryPoint>true</NoEntryPoint>
|
||||
<OutputFile>$(OutDir)$(TargetName)-$(Configuration)$(TargetExt)</OutputFile>
|
||||
</Link>
|
||||
<PostBuildEvent />
|
||||
<PostBuildEvent>
|
||||
<Command>
|
||||
</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Module.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Base64.hpp" />
|
||||
<ClInclude Include="Module.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Module.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Module.h" />
|
||||
<ClInclude Include="Base64.h" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|
||||
Reference in New Issue
Block a user